def initializeAuthentication(): #If no file use default but set filename anyway so the dump function will work for i in range(0,15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.usersdir) possibledir = os.path.join(directories.usersdir,name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): try: f = open(os.path.join(possibledir,'users.json')) temp = json.load(f) f.close() except: temp = {'users':{},'groups':{}} global Users Users = temp['users'] global Groups Groups = temp['groups'] global Tokens Tokens = {} for user in Users: #What an unreadable line! It turs all the dicts in Users into User() instances Users[user] = User(Users[user]) assignNewToken(user) generateUserPermissions() break #We sucessfully found the latest good users.json dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree(possibledir,os.path.join(directories.usersdir,name+"INCOMPLETE")) shutil.rmtree(possibledir)
def loadAll(): for i in range(0,15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.moduledir) possibledir = os.path.join(directories.moduledir,name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): loadModules(possibledir) auth.importPermissionsFromModules() break #We sucessfully found the latest good ActiveModules dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree(possibledir,os.path.join(directories.moduledir,name+"INCOMPLETE")) shutil.rmtree(possibledir)
def loadAll(): for i in range(0, 15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.moduledir) possibledir = os.path.join(directories.moduledir, name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): loadModules(possibledir) auth.importPermissionsFromModules() break #We sucessfully found the latest good ActiveModules dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree( possibledir, os.path.join(directories.moduledir, name + "INCOMPLETE")) shutil.rmtree(possibledir)
def loadAll(): for i in range(0,15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.persistdir) possibledir = os.path.join(directories.persistdir,name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): with persistance_dict_connection_lock: for i in util.get_files(possibledir): with open(os.path.join(directories.persistdir,i)) as f: persistancedict[util.unurl(i)] = _PersistanceFile(json.load(f)) break #We sucessfully found the latest good ActiveModules dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree(possibledir,os.path.join(directories.persistdir,name+"INCOMPLETE")) shutil.rmtree(possibledir)
def initializeAuthentication(): #If no file use default but set filename anyway so the dump function will work for i in range(0, 15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.usersdir) possibledir = os.path.join(directories.usersdir, name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): try: f = open(os.path.join(possibledir, 'users.json')) temp = json.load(f) f.close() except: p = "same" p2 = "different" while not p == p2: p = "same" p2 = "different" p = input( "No users list found. Account 'admin' created. Choose password:"******"Reenter Password:"******"password mismatch") m = hashlib.sha256() r = os.urandom(16) r64 = base64.b64encode(r) m.update(p) m.update(r) pwd = base64.b64encode(m) temp = { "groups": { "Administrators": { "permissions": [ "/admin/settings.edit", "/admin/logging.edit", "/admin/users.edit", "/users/pagelisting.view", "/admin/modules.edit", "/admin/settings.view", "/admin/mainpage.view", "/users/logs.view", "/admin/modules.view" ] } }, "users": { "admin": { "groups": ["Administrators"], "password": pwd, "username": "******", "salt": r64 } } } global Users Users = temp['users'] global Groups Groups = temp['groups'] global Tokens Tokens = {} for user in Users: #What an unreadable line! It turs all the dicts in Users into User() instances Users[user] = User(Users[user]) assignNewToken(user) generateUserPermissions() break #We sucessfully found the latest good users.json dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree( possibledir, os.path.join(directories.usersdir, name + "INCOMPLETE")) shutil.rmtree(possibledir)
def initializeAuthentication(): #If no file use default but set filename anyway so the dump function will work for i in range(0,15): #Gets the highest numbered of all directories that are named after floating point values(i.e. most recent timestamp) name = util.getHighestNumberedTimeDirectory(directories.usersdir) possibledir = os.path.join(directories.usersdir,name) #__COMPLETE__ is a special file we write to the dump directory to show it as valid if '''__COMPLETE__''' in util.get_files(possibledir): try: f = open(os.path.join(possibledir,'users.json')) temp = json.load(f) f.close() except: p = "same" p2 = "different" while not p == p2: p = "same" p2 = "different" p = input("No users list found. Account 'admin' created. Choose password:"******"Reenter Password:"******"password mismatch") m = hashlib.sha256() r = os.urandom(16) r64 = base64.b64encode(r) m.update(p) m.update(r) pwd = base64.b64encode(m) temp = { "groups": { "Administrators": { "permissions": [ "/admin/settings.edit", "/admin/logging.edit", "/admin/users.edit", "/users/pagelisting.view", "/admin/modules.edit", "/admin/settings.view", "/admin/mainpage.view", "/users/logs.view", "/admin/modules.view" ] } }, "users": { "admin": { "groups": [ "Administrators" ], "password": pwd, "username": "******", "salt": r64 } } } global Users Users = temp['users'] global Groups Groups = temp['groups'] global Tokens Tokens = {} for user in Users: #What an unreadable line! It turs all the dicts in Users into User() instances Users[user] = User(Users[user]) assignNewToken(user) generateUserPermissions() break #We sucessfully found the latest good users.json dump! so we break the loop else: #If there was no flag indicating that this was an actual complete dump as opposed #To an interruption, rename it and try again shutil.copytree(possibledir,os.path.join(directories.usersdir,name+"INCOMPLETE")) shutil.rmtree(possibledir)