-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_jail_users.py
35 lines (31 loc) · 959 Bytes
/
delete_jail_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import MySQLdb
import os
from server_info import server_info
import sys
userscript = """
userdel [username];
rm -rf /home/[username]/;
"""
groupscript = """
groupdel jailusers;
sed -i '/contest/d' /etc/security/limits.conf
"""
def main(argv):
if len(argv) != 1:
print "USAGE: python delete_jail_users.py"
return 0
connection = MySQLdb.connect(host = server_info["db_host"],
user = server_info["db_username"],
passwd = server_info["db_password"],
db = server_info["db_name"])
cursor = connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute("SELECT * FROM jail_users")
for user in cursor.fetchall():
command = userscript.replace("[username]", user["username"])
os.system(command)
cursor.execute("DELETE FROM jail_users")
cursor.close()
connection.close()
os.system(groupscript)
if __name__ == "__main__":
main(sys.argv)