|
|
@ -4,16 +4,20 @@ import configparser, logging, sqlite3, argparse, pwd
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Clear shell
|
|
|
|
# Clear shell
|
|
|
|
def clear():
|
|
|
|
def clear():
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# create dictionary out of sqlite results
|
|
|
|
# create dictionary out of sqlite results
|
|
|
|
def dict_factory(cursor, row):
|
|
|
|
def dict_factory(cursor, row):
|
|
|
|
d = {}
|
|
|
|
d = {}
|
|
|
|
for idx, col in enumerate(cursor.description):
|
|
|
|
for idx, col in enumerate(cursor.description):
|
|
|
|
d[col[0]] = row[idx]
|
|
|
|
d[col[0]] = row[idx]
|
|
|
|
return d
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# prints command(but doesnt execute them)
|
|
|
|
# prints command(but doesnt execute them)
|
|
|
|
# need this for work, just convenience
|
|
|
|
# need this for work, just convenience
|
|
|
|
def debugExec(commands):
|
|
|
|
def debugExec(commands):
|
|
|
@ -34,28 +38,28 @@ argparser.add_argument('-c', '--config', default = cwd,
|
|
|
|
type=str, help='Path to configuration file', required=False)
|
|
|
|
type=str, help='Path to configuration file', required=False)
|
|
|
|
args = argparser.parse_args()
|
|
|
|
args = argparser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CONF_FILE = args.config
|
|
|
|
CONF_FILE = args.config
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(CONF_FILE)
|
|
|
|
config.read(CONF_FILE)
|
|
|
|
logging.basicConfig(format="%(asctime)s: %(message)s",
|
|
|
|
logging.basicConfig(format="%(asctime)s: %(message)s",
|
|
|
|
level=int(config['LOG_LEVEL']['log_level'])
|
|
|
|
level=int(config['LOG_LEVEL']['log_level'])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
del(cwd)
|
|
|
|
del cwd
|
|
|
|
REG_FILE = config['DEFAULT']['applications_db']
|
|
|
|
REG_FILE = config['DEFAULT']['applications_db']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Does everything related to applicants, i.e. creating, manipulations...
|
|
|
|
# Does everything related to applicants, i.e. creating, manipulations...
|
|
|
|
class applicants():
|
|
|
|
class Applicants:
|
|
|
|
# User identifier
|
|
|
|
# User identifier
|
|
|
|
identifier = "username"
|
|
|
|
identifier = "username"
|
|
|
|
# SQLite DB Path
|
|
|
|
# SQLite DB Path
|
|
|
|
sourceDB = ""
|
|
|
|
sourceDB = ""
|
|
|
|
# another sqlite to batch-recreate users
|
|
|
|
# another sqlite to batch-recreate users
|
|
|
|
differentDB = ""
|
|
|
|
differentDB = ""
|
|
|
|
def __init__(self, lident, sourceDB=REG_FILE):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, lident, sourcedb=REG_FILE):
|
|
|
|
self.identifier = lident
|
|
|
|
self.identifier = lident
|
|
|
|
self.sourceDB = sourceDB
|
|
|
|
self.sourceDB = sourcedb
|
|
|
|
self.__connectToDB__("source")
|
|
|
|
self.__connectToDB__("source")
|
|
|
|
# all results shall be done with dict_factory! Makes everything so much simpler
|
|
|
|
# all results shall be done with dict_factory! Makes everything so much simpler
|
|
|
|
self.sdbCursor.row_factory = dict_factory
|
|
|
|
self.sdbCursor.row_factory = dict_factory
|
|
|
@ -75,16 +79,18 @@ class applicants():
|
|
|
|
self.ddbCursor = self.ddbConnection.cursor()
|
|
|
|
self.ddbCursor = self.ddbConnection.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
def __closeDB__(self, which):
|
|
|
|
def __closeDB__(self, which):
|
|
|
|
if(which == "source"):
|
|
|
|
if which == "source":
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.sdbConnection.close()
|
|
|
|
self.sdbConnection.close()
|
|
|
|
except sqlite3.Error as e:
|
|
|
|
except sqlite3.Error as e:
|
|
|
|
logging.exception("Couldn't close database! Error: %s" % e) # @TODO: Dump full db with query or just the executed querys to file
|
|
|
|
logging.exception(
|
|
|
|
|
|
|
|
"Couldn't close database! Error: %s" % e)
|
|
|
|
|
|
|
|
# @TODO: Dump full db with query or just the executed querys to file
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.ddbConnection.close() # @TODO: Evaluate getting rid of ddb(differentDB)?
|
|
|
|
self.ddbConnection.close() # @TODO: Evaluate getting rid of ddb(differentDB)?
|
|
|
|
|
|
|
|
|
|
|
|
# get List of all applications(not accepted yet)
|
|
|
|
# get List of all applications(not accepted yet)
|
|
|
|
def getApplicationsList(self):
|
|
|
|
def getapplicationslist(self):
|
|
|
|
query = "SELECT * FROM `applications` WHERE `status` = '0'"
|
|
|
|
query = "SELECT * FROM `applications` WHERE `status` = '0'"
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.sdbCursor.execute(query)
|
|
|
|
self.sdbCursor.execute(query)
|
|
|
@ -94,7 +100,7 @@ class applicants():
|
|
|
|
rows = []
|
|
|
|
rows = []
|
|
|
|
return rows
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
def getApprovedApplicantsList(self):
|
|
|
|
def getapprovedapplicantslist(self):
|
|
|
|
query = "SELECT * From `applications` WHERE `status` = '1'"
|
|
|
|
query = "SELECT * From `applications` WHERE `status` = '1'"
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.sdbCursor.execute(query)
|
|
|
|
self.sdbCursor.execute(query)
|
|
|
@ -105,22 +111,23 @@ class applicants():
|
|
|
|
return rows
|
|
|
|
return rows
|
|
|
|
|
|
|
|
|
|
|
|
# edit aproved users
|
|
|
|
# edit aproved users
|
|
|
|
def editApprovedApplicant(self, term, updaterow):
|
|
|
|
def editapprovedapplicants(self, term):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
# the fuck did i try here?
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
"UPDATE `applications` SET ? WHERE id=?",
|
|
|
|
"UPDATE `applications` WHERE id=?", (str(term),)
|
|
|
|
( str(term), )
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.sdbConnection.commit()
|
|
|
|
self.sdbConnection.commit()
|
|
|
|
except sqlite3.Error as e:
|
|
|
|
except sqlite3.Error as e:
|
|
|
|
logging.exception("Database Error: %s" % e)
|
|
|
|
logging.exception("Database Error: %s" % e)
|
|
|
|
|
|
|
|
|
|
|
|
# set user to aproved
|
|
|
|
# set user to aproved
|
|
|
|
def setApprovedApplication(self, selectterm):
|
|
|
|
def setapprovedapplication(self, selectterm):
|
|
|
|
query = "SELECT `username` FROM `applications` WHERE `username` = `{0!s}`".format(selectterm)
|
|
|
|
# query = "SELECT `username` FROM `applications` WHERE `username` = `{0!s}`".format(selectterm)
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# get applicants data
|
|
|
|
# get applicants data
|
|
|
|
def getApplicantsData(self, term):
|
|
|
|
def getapplicantsdata(self, term):
|
|
|
|
# @TODO: Use shorthand if for the correct query, directly into sqlite
|
|
|
|
# @TODO: Use shorthand if for the correct query, directly into sqlite
|
|
|
|
if self.identifier == "id":
|
|
|
|
if self.identifier == "id":
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -140,15 +147,15 @@ class applicants():
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
# @TODO: migrade just approved users to some new/another sqlitedb
|
|
|
|
# @TODO: migrade just approved users to some new/another sqlitedb
|
|
|
|
def migrateApprovedData(self, different_db):
|
|
|
|
def migrateapproveddata(self, different_db):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# @TODO: delete migrated data
|
|
|
|
# @TODO: delete migrated data
|
|
|
|
def deleteMigratedDataSet(self, selectterm):
|
|
|
|
def deletemigrateddata(self, selectterm):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Applicants whom doesnt got approved should get removed
|
|
|
|
# Applicants whom doesnt got approved should get removed
|
|
|
|
def removeApplicant(self, term):
|
|
|
|
def removeapplicant(self, term):
|
|
|
|
if self.identifier == "id":
|
|
|
|
if self.identifier == "id":
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
self.sdbCursor.execute(
|
|
|
@ -161,17 +168,17 @@ class applicants():
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
"DELETE FROM `applications` WHERE username = ?",
|
|
|
|
'DELETE FROM `applications` WHERE username = ?',
|
|
|
|
(str(term),)
|
|
|
|
(str(term),)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.sdbConnection.commit()
|
|
|
|
self.sdbConnection.commit()
|
|
|
|
|
|
|
|
|
|
|
|
# @TODO: Possibility to work without passing users manually
|
|
|
|
# @TODO: Possibility to work without passing users manually
|
|
|
|
def selectedUser(userid, username = False):
|
|
|
|
def selecteduser(userid, username=False):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Print out a list of aprovable users
|
|
|
|
# Print out a list of aprovable users
|
|
|
|
def printApprovableUsers(self, users):
|
|
|
|
def printapprovableusers(self, users):
|
|
|
|
i = 0
|
|
|
|
i = 0
|
|
|
|
for user in users:
|
|
|
|
for user in users:
|
|
|
|
print("ID: {0!s}, Status: {0!s}, Name: {0!s}".format(i, user["status"], user["username"]))
|
|
|
|
print("ID: {0!s}, Status: {0!s}, Name: {0!s}".format(i, user["status"], user["username"]))
|
|
|
@ -179,7 +186,8 @@ class applicants():
|
|
|
|
return i
|
|
|
|
return i
|
|
|
|
|
|
|
|
|
|
|
|
# Get List of users
|
|
|
|
# Get List of users
|
|
|
|
def userPrint(self, fetched, userid):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def userprint(fetched, userid):
|
|
|
|
print("ID: {0!s}".format(fetched[int(userid)]["id"]))
|
|
|
|
print("ID: {0!s}".format(fetched[int(userid)]["id"]))
|
|
|
|
print("Username: {0!s}".format(fetched[int(userid)]["username"]))
|
|
|
|
print("Username: {0!s}".format(fetched[int(userid)]["username"]))
|
|
|
|
print("Mail: {0!s}".format(fetched[int(userid)]["email"]))
|
|
|
|
print("Mail: {0!s}".format(fetched[int(userid)]["email"]))
|
|
|
@ -187,8 +195,8 @@ class applicants():
|
|
|
|
print("Registrated time: {0!s}".format(fetched[int(userid)]["timestamp"]))
|
|
|
|
print("Registrated time: {0!s}".format(fetched[int(userid)]["timestamp"]))
|
|
|
|
|
|
|
|
|
|
|
|
# Approve an applicant. Handles everything related, like create home dir, set flags blabla
|
|
|
|
# Approve an applicant. Handles everything related, like create home dir, set flags blabla
|
|
|
|
def approveApplicant(self, term):
|
|
|
|
def approveapplicant(self, term):
|
|
|
|
user = self.getApplicantsData(term)
|
|
|
|
user = self.getapplicantsdata(term)
|
|
|
|
ret = self.__execScript(user)
|
|
|
|
ret = self.__execScript(user)
|
|
|
|
if ret[0] != 0: # @DEBUG: Change to == 0
|
|
|
|
if ret[0] != 0: # @DEBUG: Change to == 0
|
|
|
|
print("Something went wrong in the user creation! Exiting without deleting users record in database!")
|
|
|
|
print("Something went wrong in the user creation! Exiting without deleting users record in database!")
|
|
|
@ -207,99 +215,96 @@ class applicants():
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
self.sdbCursor.execute(
|
|
|
|
"UPDATE `applications` SET `status`=1 WHERE `username`=?"
|
|
|
|
"UPDATE `applications` SET `status`=1 WHERE `username`=?",
|
|
|
|
(str(term), )
|
|
|
|
(str(term), )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.sdbConnection.commit()
|
|
|
|
self.sdbConnection.commit()
|
|
|
|
|
|
|
|
|
|
|
|
# Script execution, handles everything done with the shell/commands themselves
|
|
|
|
# Script execution, handles everything done with the shell/commands themselves
|
|
|
|
def __execScript(self, user):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def __execScript(user):
|
|
|
|
# @TODO: omfg just write some wrapper-class/lib... sucks hard!
|
|
|
|
# @TODO: omfg just write some wrapper-class/lib... sucks hard!
|
|
|
|
username = user["username"]
|
|
|
|
username = user["username"]
|
|
|
|
homeDir="/home/"+username+"/"
|
|
|
|
home_dir = "/home/" + username + "/"
|
|
|
|
sshDir=homeDir+".ssh/"
|
|
|
|
ssh_dir = home_dir + ".ssh/"
|
|
|
|
executed = []
|
|
|
|
executed = []
|
|
|
|
|
|
|
|
|
|
|
|
executed.append(["useradd", "-m", username])
|
|
|
|
executed.append(["useradd", "-m", username])
|
|
|
|
rcode = subprocess.call(executed[0])
|
|
|
|
returncode = subprocess.call(executed[0])
|
|
|
|
if rcode != 0:
|
|
|
|
if returncode != 0:
|
|
|
|
return [rcode,executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
executed.append(["usermod", "--lock", username])
|
|
|
|
executed.append(["usermod", "--lock", username])
|
|
|
|
rcode = subprocess.call(executed[1]) #empty pw
|
|
|
|
returncode = subprocess.call(executed[1]) # empty pw
|
|
|
|
if rcode != 0:
|
|
|
|
if returncode != 0:
|
|
|
|
return [rcode,executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
executed.append(["usermod", "-a", "-G", "tilde", username])
|
|
|
|
executed.append(["usermod", "-a", "-G", "tilde", username])
|
|
|
|
rcode = subprocess.call(executed[2]) # add to usergroup
|
|
|
|
returncode = subprocess.call(executed[2]) # add to usergroup
|
|
|
|
if rcode != 0:
|
|
|
|
if returncode != 0:
|
|
|
|
return [rcode,executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
executed.append(["mkdir", sshDir])
|
|
|
|
executed.append(["mkdir", ssh_dir])
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
# @TODO: use config variable(chmodPerms)
|
|
|
|
# @TODO: use config variable(chmodPerms)
|
|
|
|
ret = os.mkdir(sshDir, 0o777) #create sshdir
|
|
|
|
os.mkdir(ssh_dir, 0o777) # create sshdir
|
|
|
|
rcode = 0
|
|
|
|
returncode = 0
|
|
|
|
except OSError as e:
|
|
|
|
except OSError as e:
|
|
|
|
logging.exception(e.strerror)
|
|
|
|
logging.exception(e.strerror)
|
|
|
|
rcode = e.errno # False, couldn't create.
|
|
|
|
returncode = e.errno # False, couldn't create.
|
|
|
|
return [rcode,executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
executed.append(["write(sshkey) to", sshDir+"authorized_keys"])
|
|
|
|
executed.append(["write(sshkey) to", ssh_dir + "authorized_keys"])
|
|
|
|
with open(sshDir+"authorized_keys", "w") as f:
|
|
|
|
with open(ssh_dir + "authorized_keys", "w") as f:
|
|
|
|
f.write(user["pubkey"])
|
|
|
|
f.write(user["pubkey"])
|
|
|
|
if f.closed != True:
|
|
|
|
if not f.closed:
|
|
|
|
logging.exception("Could'nt write to authorized_keys!")
|
|
|
|
logging.exception("Could'nt write to authorized_keys!")
|
|
|
|
return [rcode,executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
executed.append(["chmod", "-Rv", "700", sshDir])
|
|
|
|
executed.append(["chmod", "-Rv", "700", ssh_dir])
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
os.chmod(sshDir+"authorized_keys", 0o700) # directory is already 700
|
|
|
|
os.chmod(ssh_dir + "authorized_keys", 0o700) # directory is already 700
|
|
|
|
rcode = 0
|
|
|
|
returncode = 0
|
|
|
|
except OSError as e:
|
|
|
|
except OSError as e:
|
|
|
|
logging.exception(e.strerror)
|
|
|
|
logging.exception(e.strerror)
|
|
|
|
rcode = e.errno
|
|
|
|
returncode = e.errno
|
|
|
|
return [rcode, executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
executed.append(["chown", "-Rv", username+":"+username, sshDir])
|
|
|
|
executed.append(["chown", "-Rv", username + ":" + username, ssh_dir])
|
|
|
|
os.chown(sshDir, pwd.getpwnam(username)[2], pwd.getpwnam(username)[3]) #2=>uid, 3=>gid
|
|
|
|
os.chown(ssh_dir, pwd.getpwnam(username)[2], pwd.getpwnam(username)[3]) # 2=>uid, 3=>gid
|
|
|
|
executed.append(["chown", "-v", username+":"+username, sshDir+"authorized_keys"])
|
|
|
|
executed.append(["chown", "-v", username + ":" + username, ssh_dir + "authorized_keys"])
|
|
|
|
os.chown(sshDir+"authorized_keys", pwd.getpwnam(username)[2], pwd.getpwnam(username)[3])
|
|
|
|
os.chown(ssh_dir + "authorized_keys", pwd.getpwnam(username)[2], pwd.getpwnam(username)[3])
|
|
|
|
rcode = 0
|
|
|
|
returncode = 0
|
|
|
|
except OSError as e:
|
|
|
|
except OSError as e:
|
|
|
|
logging.exception(e.strerror) # @TODO: maybe append strerror to executed instead of printing it
|
|
|
|
logging.exception(e.strerror) # @TODO: maybe append strerror to executed instead of printing it
|
|
|
|
rcode = e.errno
|
|
|
|
returncode = e.errno
|
|
|
|
return [rcode, executed,]
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
|
|
|
|
return [rcode,executed,]
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
{'id': 7, 'username': 'testuser47', 'email': '47test@testmail.com', 'name':
|
|
|
|
|
|
|
|
'test Name', 'pubkey': 'ssh-rsa [...]', 'timestamp': '2018-08-22 13:31:16', 'status': 0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
return [returncode, executed, ]
|
|
|
|
|
|
|
|
# {'id': 7, 'username': 'testuser47', 'email': '47test@testmail.com', 'name':
|
|
|
|
|
|
|
|
# 'test Name', 'pubkey': 'ssh-rsa [...]', 'timestamp': '2018-08-22 13:31:16', 'status': 0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
# how many times the Seperator/Delimiter?
|
|
|
|
# how many times the Separator/Delimiter?
|
|
|
|
delcount = 40
|
|
|
|
delcount = 40
|
|
|
|
# The seperator for the menu
|
|
|
|
# The separator for the menu
|
|
|
|
Seperator = "="*delcount
|
|
|
|
separator = "=" * delcount
|
|
|
|
Menu = Seperator+"\n\t\t Main-Menu:\n\n" \
|
|
|
|
menu = separator + "\n\t\t Main-Menu:\n\n" \
|
|
|
|
"\t 1) list and edit pending users\n" \
|
|
|
|
"\t 1) list and edit pending users\n" \
|
|
|
|
"\t 2) list applicants\n" \
|
|
|
|
"\t 2) list applicants\n" \
|
|
|
|
"\t 3) edit applicant\n" \
|
|
|
|
"\t 3) edit applicant\n" \
|
|
|
|
"\t 4) quit\n"+Seperator+"\n"
|
|
|
|
"\t 4) quit\n" + separator + "\n"
|
|
|
|
|
|
|
|
|
|
|
|
# Identify by ID
|
|
|
|
# Identify by ID
|
|
|
|
applications = applicants(lident = "id")
|
|
|
|
applications = Applicants(lident="id")
|
|
|
|
while 1 != 0:
|
|
|
|
while 1 != 0:
|
|
|
|
print(Menu)
|
|
|
|
print(menu)
|
|
|
|
|
|
|
|
|
|
|
|
command = input("Please select, what you want to do: \n -> ")
|
|
|
|
command = input("Please select, what you want to do: \n -> ")
|
|
|
|
# User shouldnt be able to type something in that isnt a number
|
|
|
|
# User shouldn't be able to type something in that isnt a number
|
|
|
|
if command.isalpha() or command == '':
|
|
|
|
if command.isalpha() or command == '':
|
|
|
|
clear()
|
|
|
|
clear()
|
|
|
|
print("!!! invalid input, please try again. !!!")
|
|
|
|
print("!!! invalid input, please try again. !!!")
|
|
|
@ -312,65 +317,66 @@ def main():
|
|
|
|
exit(0)
|
|
|
|
exit(0)
|
|
|
|
# Edit and list pending users/applicants @TODO Wording: Users or applicants?
|
|
|
|
# Edit and list pending users/applicants @TODO Wording: Users or applicants?
|
|
|
|
elif command == 1:
|
|
|
|
elif command == 1:
|
|
|
|
users = applications.getApplicationsList()
|
|
|
|
users = applications.getapplicationslist()
|
|
|
|
i=applications.printApprovableUsers(users)
|
|
|
|
i = applications.printapprovableusers(users)
|
|
|
|
|
|
|
|
|
|
|
|
if i == 0:
|
|
|
|
if i == 0:
|
|
|
|
print("No pending users")
|
|
|
|
print("No pending users")
|
|
|
|
# giving some time to aknowledge that something WRONG happened
|
|
|
|
# giving some time to acknowledge that something WRONG happened
|
|
|
|
input("Continue with Keypress...")
|
|
|
|
input("Continue with Keypress...")
|
|
|
|
clear()
|
|
|
|
clear()
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
usersel = 0
|
|
|
|
user_selection = 0
|
|
|
|
UserMax = i
|
|
|
|
user_max = i
|
|
|
|
print("Menu:\n r=>return to main")
|
|
|
|
print("Menu:\n r=>return to main")
|
|
|
|
|
|
|
|
|
|
|
|
# Edit Menue
|
|
|
|
# Edit Menu
|
|
|
|
while 1 != 0 or usersel != "r":
|
|
|
|
while 1 != 0 or user_selection != "r":
|
|
|
|
i = applications.printApprovableUsers(users)
|
|
|
|
i = applications.printapprovableusers(users)
|
|
|
|
if usersel == "r":
|
|
|
|
if user_selection == "r":
|
|
|
|
break # break when user presses r
|
|
|
|
break # break when user presses r
|
|
|
|
|
|
|
|
|
|
|
|
usersel = input("Which user( ID ) do you want to change? ->")
|
|
|
|
user_selection = input("Which user( ID ) do you want to change? ->")
|
|
|
|
if len(usersel) > 1 or usersel.isalpha():
|
|
|
|
if len(user_selection) > 1 or user_selection.isalpha():
|
|
|
|
usersel = ""
|
|
|
|
user_selection = ""
|
|
|
|
# convert to int if input isnt an r
|
|
|
|
# convert to int if input isnt an r
|
|
|
|
usersel = int(usersel) if usersel != '' and usersel != 'r' else 0
|
|
|
|
user_selection = int(user_selection) if user_selection != '' and user_selection != 'r' else 0
|
|
|
|
if usersel > UserMax - 1:
|
|
|
|
if user_selection > user_max - 1:
|
|
|
|
print("User {0!s} doesn't exist!".format(usersel))
|
|
|
|
print("User {0!s} doesn't exist!".format(user_selection))
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
# Show the user his chosen user and ask what to do
|
|
|
|
# Show the user his chosen user and ask what to do
|
|
|
|
applications.userPrint(users, usersel)
|
|
|
|
applications.userprint(users, user_selection)
|
|
|
|
print("You chosed ID No. {0!s}, what do you like to do?".format(usersel))
|
|
|
|
print("You chosed ID No. {0!s}, what do you like to do?".format(user_selection))
|
|
|
|
|
|
|
|
|
|
|
|
chosenUser = usersel
|
|
|
|
chosen_user = user_selection
|
|
|
|
usersel = ""
|
|
|
|
user_selection = ""
|
|
|
|
|
|
|
|
|
|
|
|
# Finally down the edit menue!
|
|
|
|
# Finally down the edit menu!
|
|
|
|
while usersel != "e":
|
|
|
|
while user_selection != "e":
|
|
|
|
usersel = input("User: {0!s}\n \t\t(A)ctivate \n\t\t(R)emove \n\t\tR(e)turn\n -> ".format(chosenUser))
|
|
|
|
user_selection = input(
|
|
|
|
if usersel == "A":
|
|
|
|
"User: {0!s}\n \t\t(A)ctivate \n\t\t(R)emove \n\t\tR(e)turn\n -> ".format(chosen_user))
|
|
|
|
applications.approveApplicant(users[chosenUser]['id'])
|
|
|
|
if user_selection == "A":
|
|
|
|
print("User {0!s} has been successfully approved!".format(users[chosenUser]['username']))
|
|
|
|
applications.approveapplicant(users[chosen_user]['id'])
|
|
|
|
|
|
|
|
print("User {0!s} has been successfully approved!".format(users[chosen_user]['username']))
|
|
|
|
input("waiting for input...")
|
|
|
|
input("waiting for input...")
|
|
|
|
clear()
|
|
|
|
clear()
|
|
|
|
usersel="e" # remove for being able to continue editing?
|
|
|
|
user_selection = "e" # remove for being able to continue editing?
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
elif usersel == "R":
|
|
|
|
elif user_selection == "R":
|
|
|
|
applications.removeApplicant(users[chosenUser]['id'])
|
|
|
|
applications.removeapplicant(users[chosen_user]['id'])
|
|
|
|
print("User {0!s} successfully deleted!".format(user[chosenUser]['username']))
|
|
|
|
print("User {0!s} successfully deleted!".format(user[chosen_user]['username']))
|
|
|
|
input("waiting for input...")
|
|
|
|
input("waiting for input...")
|
|
|
|
clear()
|
|
|
|
clear()
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
elif usersel == "e":
|
|
|
|
elif user_selection == "e":
|
|
|
|
clear()
|
|
|
|
clear()
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
elif int(command) == 2:
|
|
|
|
elif int(command) == 2:
|
|
|
|
users = applications.getApprovedApplicantsList()
|
|
|
|
users = applications.getapprovedapplicantslist()
|
|
|
|
|
|
|
|
|
|
|
|
if users == []:
|
|
|
|
if not users:
|
|
|
|
print("no activate users yet!")
|
|
|
|
print("no activate users yet!")
|
|
|
|
i = 0
|
|
|
|
i = 0
|
|
|
|
for user in users:
|
|
|
|
for user in users:
|
|
|
@ -381,6 +387,7 @@ def main():
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
exit(0)
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|