def __init__( self, username, password=None, fullname=None, group_uid=None, email=None, first_area_id=None, first_area_level=None, second_area_id=None, second_area_level=None ): self.username = username self.fullname = fullname self.password = encrypt(password) if password else self.reset_password() self.group_uid = group_uid self.email = email self.first_area_id=first_area_id self.first_area_level=first_area_level self.second_area_id=second_area_id self.second_area_level=second_area_level
def run(ftp): # First we must get the IP and port of the valid OneDir server server = raw_input('What is the IP Address of the server? ') try: port = int(raw_input('What is the port number to connect to? ')) except ValueError: print "The port must be an integer ... quitting" os._exit(0) # Connect to the server try: ftp.connect(server, port) except all_errors: print "Give a valid server and port number" os._exit(0) # This is our while loop to accept input from the user while True: command = raw_input('\nEnter a command (login, change password, create user, admin, forgot password, quit): ') # login the user if command == 'login': username = raw_input('Username: '******'Password: '******'OneDir'): os.mkdir('OneDir') event_handler = MyHandler(ftp) observer = Observer() observer.schedule(event_handler, 'OneDir', recursive=True) syncOption = raw_input('Do you want to do a client-default sync or server-default sync? (client/server): ') if syncOption.startswith('s') or syncOption.startswith('S'): try: syncOneDirServer(ftp, 'OneDir') except all_errors as e: if str(e) == '550 No such file or directory.': ftp.mkd('OneDir') syncOneDirServer(ftp, 'OneDir') elif syncOption.startswith('c') or syncOption.startswith('C'): try: syncOneDirClient(ftp, 'OneDir') except all_errors as e: if str(e) == '550 No such file or directory.': ftp.mkd('OneDir') syncOneDirClient(ftp, 'OneDir') else: print "Please try again and choose a valid client or server sync" continue time.sleep(1.5) logging.warning('Synchronization has started') observer.start() #watchDogThread.start() break except all_errors as e: print "FTP error: " + str(e) # print "Login failed, try again." # change the user's password elif command == 'change password': # do something to change the password username = raw_input('Enter the user: '******'root', adminpass) try: password1 = encrypt(pw1).hexdigest() password2 = encrypt(pw2).hexdigest() ftp.sendcmd('STAT ' + 'changepassword:'******':' + password2 + ':' + password1) if int(ftp.lastresp) == 215: print "User does not exist" except: pass # create a new user elif command == 'create user': # append to the pass.dat file probably ftp.login('root', adminpass) username = raw_input("Enter the new username: "******"Passwords do not match, please try again" continue try: pw = encrypt(password).hexdigest() ftp.sendcmd('STAT ' + "createuser:"******":" + pw + ':' + answer) if int(ftp.lastresp) == 214: print "User Already Exists, try again" except all_errors: pass if not os.path.isdir('OneDir'): os.mkdir('OneDir') # see if the user knows his/her security answer to change his/her password elif command == 'forgot password': user = raw_input('What is your username? ') pw = getpass('Enter a new password: '******'Enter your security word: ') ftp.login('root', adminpass) try: ftp.sendcmd('STAT ' + "forgot:" + user + ":" + password + ":" + answer) if int(ftp.lastresp) == 216: print "User does not exist or security word is incorrect" else: print "Password changed successfully" except all_errors as e: print "ftp error: " + str(e) pass # do admin commands elif command == 'admin': username = raw_input('\nPlease login as an admin\nUsername: '******'Password: '******'root' and password==adminpass: ftp.login('root', adminpass) # The admin while loop to do commands while True: command = raw_input('Enter a valid admin command (remove user, change password, get info, get users, see logs, go back): ') # go back to regular user input if command == 'go back': break # get information about users associated with the server if command == 'get info': try: ftp.sendcmd('STAT ' + "userinfo") except all_errors: pass getFile(ftp, 'root/userinfo.txt', 'userinfo.txt') with open('userinfo.txt', 'r') as f: for line in f: print line, # get the names of the users associated with the server if command == 'get users': try: ftp.sendcmd('STAT ' + "users") except all_errors: pass getFile(ftp, 'root/users.txt', 'users.txt') with open('users.txt', 'r') as f: for line in f: print line, # get the watchdog logs for each user if command == 'see logs': try: ftp.sendcmd('STAT ' + "seelogs") except all_errors: pass getFile(ftp, 'root/userlogs.txt', 'userlogs.txt') with open('userlogs.txt', 'r') as f: for line in f: print line, # remove a user, optionally removing their files if command == 'remove user': user = raw_input('Which user do you want to remove? ') cond = raw_input('Do you want to delete their files? ') if cond.startswith('Y') or cond.startswith('y'): try: ftp.sendcmd('STAT ' + "removeuser:"******"removeuser:"******"Type in their new password" pw = getpass() password = encrypt(pw).hexdigest() try: ftp.sendcmd('STAT ' + "changepassword:"******"If you want to pause syncing type ctrl-C" while True: time.sleep(1) except KeyboardInterrupt: observer.stop() # print "stopping the observer" print "\nSynchronization is turned off." print "Note: Answering the following means you are done editing files. Even if you are not exiting, you will be logged out, and your current files will be automatically synced to the server." resp = raw_input("\nDo you want to exit? (yes/no)") syncOneDirClient(ftp, 'OneDir') ftp.quit() ftp2 = FTP() ftp2.connect(server, port) observer.join() if resp.startswith('y') or resp.startswith('Y'): os._exit(0) else: run(ftp2)
def hash_code(self, input): if len(input) == 6: return encrypt((input.upper()).encode()).hexdigest() else: return None
def set_password(self, new_password): '''Sets and encrypts password''' self.password = encrypt(new_password)