def reset(key, folder, client_handler, sym_key_filename): DriveManager.files_decrypt(key, folder) new_key = Encryptor.generate_key() with open(sym_key_filename, 'wb') as key_file: key_file.write(new_key) client_handler.change_key(new_key) DriveManager.files_encrypt(new_key, folder)
def main(): baseDir = 'C:/Users/Administrator/Documents/Individual Agreements/' filemanager = FileManager.fileManager(baseDir) Drive = DriveManager.driveManager() GS = GoogleSheet.googleSheet() ProcessedID = GS.ReadProcessedID() while True: ########################################################################### Gmail = MessageManager.gmail('2018/10/28','credentials_gmail1') ########################################################################### UnreadID = Gmail.getAllIDs() Process = set(UnreadID)-set(ProcessedID) for I in Process: print(I) mess = MessageManager.emailMessage(I,Gmail) try: ia = IndividualAgreement.individualAgreement( Gmail, filemanager, Drive,I) li= ia.ReportResult() except: try: ia = IndividualAgreement.individualAgreement( Gmail, filemanager, Drive,I) li= ia.ReportResult() except: li = [I,mess.getSubject(),mess.getFullName(),mess.getEmailAddress(),mess.getCountryName(), None, None, None,None,None,mess.getPlatform()] print('failed') print(li) GS.updateInformation([li]) ProcessedID.append(I)
def test_driveManager(self): DM = DriveManager.driveManager() # ============================================================================= print('get foldre ID') print(DM.getFolderID('MT5 Accounts')) print('get file id') print(DM.getFileID(' 323523>>Xin Liu>>ID translation')) print('get all folders in mt4 account') print(DM.getAllFolders('MT4 accounts')) print('get all files in the folder') print(DM.getAllFiles('705046 KAZUTAKA ARITOMI')) print('create folder') DM.CreateFolder('test') time.sleep(5) print('check existence of created folder') print(DM.CheckFolderExistence('test')) #DM.UploadFile('test','C:/Users/Intern/Desktop/','tradeview_logo.png') print('create the same folder') DM.CreateFolder('test') # ============================================================================= DM.CopyRiskMatrix('Munemichi Ishikawa')
def test_individualAgreement(self): baseDir = 'C:/Users/Administrator/Documents/Individual Agreements/' filemanager = FileManager.fileManager(baseDir) G = MessageManager.gmail('2018/10/22','credentials_gmail1') Drive = DriveManager.driveManager() ID = '166cc3673644d500' ia = IndividualAgreement.individualAgreement( G, filemanager, Drive,ID) print(ia.ReportResult())
def Communicate(self): i = 1 local_socket_obj = LocalPythonCommunication() local_socket_obj.StartClient() while True: print i self.gui_socket, self.addr = self.socket.accept() info = self.Recv() print "printed from engine: " + info if info != "": info = info.split("#") state = info[0] print "printed from engine: " + state # message = "none" if state == "login": username = info[1] password = info[2] local_socket_obj.Send("GETHASH#" + username) password_hash = local_socket_obj.Recv() print "printed from engine: " + password_hash if password_hash == password: local_socket_obj.Send("GETINFO#" + username) information = local_socket_obj.Recv() # fname#lname#uid optionaly it will end with '$' # depends if the user is the admin print "printed from engine: " + information if information.endswith("$"): self.Send("Signed in, admin#" + information) else: self.Send("Signed in#" + information) ack = self.Recv() if ack == "ok": local_socket_obj.Send("GETTHISUSERSAVAILABLEFILES@" + information.split('#')[1] + "#") available_files = local_socket_obj.Recv() # -> filename#filename#... self.Send(available_files) else: message = "Not#0" self.Send(message) local_socket_obj.Send("Reset") print "printed from engine: " + message elif state == "Unlock": uid = info[1] path = info[2] if path.endswith(".cb"): file_obj = fm.File_Manager(uid) file_id = file_obj.get_file_id(path) local_socket_obj.Send("GETKEYFOR#" + str(file_id)) original_key = local_socket_obj.Recv() print "original key from clientengine " + str(original_key) ack = file_obj.Strip_File(path, original_key) print "from clientengine: " + ack if ack == "File unlocked" or ack == "File unlocked, user can only read the file": self.Send(ack) elif ack == "The specified user is not allowed to open the file": self.Send(ack) else: self.Send("Path error, system can only unlock .cb files") elif state == "Lock": local_socket_obj.Send("GETALLUSERINFO#") print "printed from engine: sent request for user info" all_user_info = local_socket_obj.Recv() print "printed from engine: " + all_user_info self.Send(all_user_info) # sends to gui info = self.Recv() # info = LockReady#uid#path#otheruid@otheruid@...#rbac#optionality # received back from the gui print "printed from engine: " + info info = info.split("#") if info[0] == "LockReady": uid = info[1] path = info[2] uid_list = info[3].split("@") uid_list = uid_list[:-1] rbac = info[4] optionality = info[5] # 0 or 1 file_obj = fm.File_Manager(uid) if optionality == "1": second_uid_list = info[6].split("@") second_rbac = info[7] file_data = file_obj.Create_New_Format(path, uid_list, rbac, second_uid_list, second_rbac) else: file_data = file_obj.Create_New_Format(path, uid_list, rbac) local_socket_obj.Send("LOCKEDFILEDATA: " + str(file_data[0]) + "#" + str(file_data[1])) ack = local_socket_obj.Recv() if ack == "Locked": self.Send(ack) elif state == "Upload": # Upload#path#uid print info path = info[1] uid = info[2] file_data_tuple = dm.get_upload_file_data(uid, path) try: local_socket_obj.Send("UPLOAD#") ack = local_socket_obj.Recv() if ack == "ok": print "here---------------------------------------------------------" pickled_info = pickle.dumps(file_data_tuple) local_socket_obj.Send(pickled_info) ack = local_socket_obj.Recv() print "ack: " + ack if ack == "File Successfully Uploaded": os.remove(path) self.Send(ack) else: self.Send("An error has occurred, please try again.") else: self.Send("An error has occurred, please try again.") except: self.Send("An error has occurred, please try again.") elif state == "Download": file_name = info[1] uid = info[2] download_path = info[3] local_socket_obj.Send("DOWNLOAD#" + file_name + "#" + uid) file_info_tuple = pickle.loads(local_socket_obj.Recv()) self.Send(dm.Create(file_info_tuple, download_path)) elif state == "register": while state == "register": print info uid = info[1] firstname = info[2] lastname = info[3] username = info[4] password = info[5] local_socket_obj.Send("CHECKIFEXISTS#" + username) uname_exists = local_socket_obj.Recv() # 0 = does not exist, 1 = does exist if uname_exists == "0": print "sending the new user's data" local_socket_obj.Send(firstname + "#" + uid + "#" + lastname + "#" + username + "#" + password) message = local_socket_obj.Recv() self.Send(message) state = "" else: self.Send("Username already exists") state = "" # info = self.Recv() # info = info.split("#") # state = info[0] elif state == "Delete": local_socket_obj.Send("GETALLUSERINFO2#") all_user_info = local_socket_obj.Recv() self.Send(all_user_info) user_to_del = self.Recv() while user_to_del == "": user_to_del = self.Recv() try: user_to_del = int(user_to_del) except: self.Send("Reset") local_socket_obj.Send("DELETEUSER#" + str(user_to_del)) # user_info = dbm.ReadInfoByUID(user_to_del) ack = local_socket_obj.Recv() self.Send(ack) elif state == "Change": local_socket_obj.Send("GETALLUSERINFO3#") all_user_info = local_socket_obj.Recv() self.Send(all_user_info) change_str = self.Recv() while change_str == "": change_str = self.Recv() if change_str.split('#')[0] == "Change": what_to_change = change_str.split('#')[1] user_id = change_str.split('#')[2] new_item = change_str.split('#')[3] if what_to_change == "fname": local_socket_obj.Send("FNAME#" + new_item + "#" + user_id) ack = local_socket_obj.Recv() if ack == "1": self.Send("User info updated") else: self.Send("Could not Change...") elif what_to_change == "lname": local_socket_obj.Send("LNAME#" + new_item + "#" + user_id) ack = local_socket_obj.Recv() if ack == "1": self.Send("User info updated") else: self.Send("Could not Change...") elif what_to_change == "password": local_socket_obj.Send("PASS#" + new_item + "#" + user_id) ack = local_socket_obj.Recv() if ack == "1": self.Send("User info updated") else: self.Send("Could not Change...") i += 1 else: break
def run(self): try: # Wait message beginning of communication from client data = self.recv_buf() if not self.verify_hello(data): return self.clientSock.send(PROT_START + END_LINE) self.key = self.crypto.key_exchange(self.clientSock) # in Crypto if self.key: while True: request = self.recv() print "request " + request if request.split('#')[0] == "GETHASH": password_hash = dbm.GetPassHashByUname(request.split('#')[1]) self.send(password_hash) request = self.recv() if request.split('#')[0] == "GETINFO": if password_hash == "248f14d5b74dae0d2c317188f3d4484a52f0538aac05ba25d0b32c578b455b21" and \ request.split('#')[1] == "coby567": # means this is the admin self.send(dbm.GetLoginInfo(request.split('#')[1]) + "$") else: self.send(dbm.GetLoginInfo(request.split('#')[1])) else: print "from server: Reset" self.send("Reset") elif request.split('#')[0] == "CHECKIFEXISTS": username = request.split('#')[1] uname_exists = dbm.UnameExists(username)[0] if not uname_exists: # means it does not exist print "0" self.send("0") user_info = self.recv().split('#') dbm.AddInfo(user_info[0], user_info[1], user_info[2], user_info[3], user_info[4]) self.send("Signed up") dm.CheckifExists(user_info[1]) # creates a folder for the users drive elif request.split('#')[0] == "GETKEYFOR": print "GETKEYFOR " + str(request.split("#")[1]) self.send(dbm.GetKeyByID(str(request.split('#')[1]))) elif request.split('#')[0] == "GETALLUSERINFO": print dbm.GetInfoForLock() self.send(dbm.GetInfoForLock()) request = self.recv() if request.split(':')[0] == "LOCKEDFILEDATA": file_id = request.split(':')[1].split('#')[0] file_id = file_id[1:] file_key = request.split(':')[1].split('#')[1] dbm.AddFileInfo(file_id, file_key) self.send("Locked") else: print "from server: Reset after locked file data" self.send("Reset") elif request.split('#')[0] == "GETALLUSERINFO2": # for deleting a user self.send(dbm.GetInfoForLock()) user_to_del = self.recv().split('#')[1] user_info = dbm.ReadInfoByUID(user_to_del) if dbm.DeleteInfo(user_to_del): deleted_user_info = user_info.split('#')[1] + " " + user_info.split('#')[2] + \ " " + user_info.split('#')[3] dm.deletedir(user_to_del) self.send("User %s Deleted" % deleted_user_info) else: self.send("User %s can not be deleted, or does not exist" % user_to_del) elif request.split('#')[0] == "GETALLUSERINFO3": # for changing user info self.send(dbm.GetInfoForLock()) change_info = self.recv() what_to_change = change_info.split('#')[0] new_item = change_info.split('#')[1] user_id = change_info.split('#')[2] if what_to_change == "FNAME": if dbm.UpdateInfo(1, new_item, user_id): self.send("1") else: self.send("0") if what_to_change == "LNAME": if dbm.UpdateInfo(3, new_item, user_id): self.send("1") else: self.send("0") if what_to_change == "PASS": if dbm.UpdateInfo(5, new_item, user_id): self.send("1") else: self.send("0") elif request.split('#')[0] == "UPLOAD": # user uploading file to server self.send("ok") print "here" # file_info_tuple = pickle.loads(self.recv()) #(uid#file_name.ext, file_content) first = self.recv() self.send("ok") second = self.recv() print "stuck here" result = dm.Create((first, second)) print "from server: " + result self.send(result) elif request.split('#')[0].split('@')[0] == "GETTHISUSERSAVAILABLEFILES": requested_uid = request.split('#')[0].split('@')[1] users_path = "TheDrive\\" + requested_uid files_list = os.listdir(users_path) files_string = "" for saved_file in files_list: files_string += saved_file + "#" print files_string self.send(files_string) elif request.split('#')[0] == "DOWNLOAD": file_name = request.split('#')[1] uid = request.split('#')[2] file_info_tuple = dm.get_download_file_data(uid, file_name) print file_info_tuple print "here" self.send(pickle.dumps(file_info_tuple)) self.clientSock.close() except socket.error, e: print str(e) + END_LINE + ERROR_SOCKET + " from " + str(self.addr[0])
def main(): groupname = input("Enter the Cloud group name:\n") group_path = os.path.join("Groups",groupname) if not os.path.isdir(group_path): os.mkdir(group_path) user_filename = os.path.join(group_path,'UserList') try: infile = open(user_filename,'rb') user_list = pickle.load(infile) infile.close() except IOError: user_list = set() users_file = open(user_filename,'wb') pickle.dump(user_list,users_file) users_file.close() sym_key_filename = os.path.join(group_path,'Symmetric_Key.txt') try: with open(sym_key_filename, 'rb') as key_file: sym_key = key_file.read() except: sym_key = Encryptor.generate_key() with open(sym_key_filename, 'wb') as key_file: key_file.write(sym_key) gauth = GoogleAuth() gauth.LoadCredentialsFile("credentials.txt") if gauth.credentials is None or gauth.access_token_expired: gauth.LocalWebserverAuth() else: gauth.Authorize() gauth.SaveCredentialsFile("credentials.txt") drive = GoogleDrive(gauth) root_folder_id = #insert drive folder ID here root_folder = drive.ListFile({'q': "'" + root_folder_id + "' in parents and trashed=false"}).GetList() if DriveManager.find_folder(root_folder,groupname) is None: folder_id = DriveManager.create_folder(root_folder_id, groupname, drive) else: folder_id = DriveManager.find_folder(root_folder,groupname) folder = drive.ListFile({'q': "'" + folder_id + "' in parents and trashed=false"}).GetList() try: file_list = open("Drive Folders",'rb') drive_folders = pickle.load(file_list) file_list.close() except IOError: print("Could not read drive files:") drive_folders = dict() drive_folders[groupname] = folder_id file_list = open("Drive Folders",'wb') pickle.dump(drive_folders,file_list) file_list.close() address = ('localhost', 6000) listener = Listener(address, authkey=b'secret password') lock = threading.Lock() client_handler = CloudGroup(user_list, lock, listener, sym_key) client_handler.daemon = True client_handler.start() running = True print('Manage the group using the following commands:\n1. List all users: list\n2. To add a user: add <user>\n3. To remove a user: remove <user>\n4. Exit the program: quit\n') while running: command = input('Enter a command\n') argv = command.split(' ') lock.acquire() if argv[0] == 'list': print('Users in the group:') for x in user_list: print(x) print() elif argv[0] == 'add': user_list.add(argv[1]) print(argv[1],'has been successfully added to the group\n') elif argv[0] == 'remove': user_list.remove(argv[1]) reset(sym_key, folder, client_handler, sym_key_filename) print(argv[1], 'has been successfully removed from the group\n') elif argv[0] == 'quit': users = open(user_filename,'wb') pickle.dump(user_list,users) users.close() client_handler.close() running = False print('Goodbye\n') else: error_msg() lock.release()
def main(): groupname = raw_input("Enter group name:\n") group_path = os.path.join("Groups", groupname) if not os.path.isdir(group_path): os.mkdir(group_path) user_filename = os.path.join(group_path, 'UserList') # load users in CloudGroup try: infile = open(user_filename, 'rb') user_list = pickle.load(infile) infile.close() except IOError: print "Could not read file:", user_filename user_list = set() users_file = open(user_filename, 'wb') pickle.dump(user_list, users_file) users_file.close() # load Symmetric key sym_key_filename = os.path.join(group_path, 'Symmetric_Key.txt') try: with open(sym_key_filename, 'rb') as key_file: sym_key = key_file.read() except: print "Could not find symmetric key file:", sym_key_filename sym_key = Encryptor.generate_key() with open(sym_key_filename, 'wb') as key_file: key_file.write(sym_key) ''' - sets up local Google webserver to automatically receive authentication code from user and authorizes by itself. ''' gauth = GoogleAuth() gauth.LoadCredentialsFile("credentials.txt") if gauth.credentials is None or gauth.access_token_expired: # Creates local webserver and auto handles authentication. gauth.LocalWebserverAuth() else: gauth.Authorize() gauth.SaveCredentialsFile("credentials.txt") # Create GoogleDrive instance with authenticated GoogleAuth instance. drive = GoogleDrive(gauth) root_folder_id = "//drive folder id" root_folder = drive.ListFile({ 'q': "'" + root_folder_id + "' in parents and trashed=false" }).GetList() if DriveManager.find_folder(root_folder, groupname) is None: folder_id = DriveManager.create_folder(root_folder_id, groupname, drive) else: folder_id = DriveManager.find_folder(root_folder, groupname) folder = drive.ListFile({ 'q': "'" + folder_id + "' in parents and trashed=false" }).GetList() # store available groups in local files for user reference try: file_list = open("Drive Folders", 'rb') drive_folders = pickle.load(file_list) file_list.close() except IOError: print "Could not read drive files:" drive_folders = dict() drive_folders[groupname] = folder_id file_list = open("Drive Folders", 'wb') pickle.dump(drive_folders, file_list) file_list.close() ''' - Create listener to receive requests from users - attempting to establish connection with users to send symmetric key for encryption of files ''' address = ('localhost', 6000) # family is deduced to be 'AF_INET' listener = Listener(address, authkey=b'secret password') lock = threading.Lock() client_handler = CloudGroup(user_list, lock, listener, sym_key) client_handler.daemon = True client_handler.start() running = True while running: command = raw_input('How may I help you?\n') argv = command.split(' ') # use lock to prevent anyone contacting CloudGroup at during management lock.acquire() # add user to list if argv[0] == 'add': user_list.add(argv[1]) # remove user from list elif argv[0] == 'remove': user_list.remove(argv[1]) reset(sym_key, folder, client_handler, sym_key_filename) # shut down CloudGroup elif argv[0] == 'quit': #save user files users = open(user_filename, 'wb') pickle.dump(user_list, users) users.close() client_handler.close() running = False print 'Goodbye' # print valid users elif argv[0] == 'list': print 'Users:' for x in user_list: print(x) # print usage else: usage() lock.release()
# Initializing Xml configuration management XmlManager.primaryConfig = XmlManager.MainConfig() XmlManager.paths = XmlManager.PathManager() # Initializing logging logger = Log.initialize('BackupEngine') #### Initializations #### # Getting Identified filename logger.debug("Fetching the name of the identifier file name from xml configuration") identifier_file_name=XmlManager.primaryConfig["IdentifierFile"] logger.debug("Fetched the name of the identifier file name from xml configuration") # Checking all drives for identifier file logger.debug("Checking all drives for identifier file") drive = dm.get_usb_drive(identifier_file_name) if drive!="": # Backup drive successfully connected / Identifier file found logger.info("Backup drive successfully connected") logger.debug("Checking free space in backup drive") # Checking the free space available on the backup drive in bytes free_space_backup_drive = dm.getFreeSpaceOnBackupDrive(drive) # Checking the total diskspace required to write the Backup and if backup creation is possible if bdm.can_backup_be_created(free_space_backup_drive) is True: logger.info("Sufficient space in backup drive") paths = bdm.get_all_paths_to_backup() logger.debug("Fetched all paths to backup") logger.debug("Getting base directory for creating backups")