def test_saving_multiple_passwords(self): self.new_password.save_password() new_password = Locker("FaceBook", "fbUser", "fbUser21") new_password.save_password() self.assertEqual(len(Locker.locker_list), 2)
def main(): global l global user print("===============================================") print("Multi-User Password Locker - TUI Client - Login") print("===============================================") server = input("Server: ") port = input("Port: ") auth_correct = False while not auth_correct: username = input("Username: "******"Password: "******"localhost" port = 5000 # username = "******" # password = "******" l = Locker(server, int(port), username, password) auth_correct = l.check_auth() if not auth_correct: print("\nIncorrect username/password, please try again!") user = l.get_current_user() folder_list()
def test_delete_password(self): self.new_password.save_password() new_password = Locker("Test", "test", "passTest1") new_password.save_password() new_password.delete_password() #test if it has deleted the password self.assertEqual(len(Locker.locker_list), 1)
def __init__(self, mock=True, timeout=10000, use_rpc=False, server=False): self.quotes = {} if not mock: self._quote_server_conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._quote_server_conn.connect(('quoteserve.seng', 4444)) else: self._quote_server_conn = None self._mock = mock self._audit = AuditServer(use_rpc=use_rpc, server=False) self._lock = Locker(use_rpc=use_rpc, server=False) self._timeout = timeout # default timeout of 10 seconds.
def __init__(self, use_rpc=False, server=False): self._tables = {} self._timeout = 10000 # default timeout of 10 seconds. self.__init_tables() self._lock = Locker(use_rpc=use_rpc, server=False) self._my_lock = Lock() self.update_queue = Queue() self.__num_tables_to_keep = 10 t = Thread(target=self.poll_for_table_changes, args=(self.update_queue, )) t.start()
def __init__(self, num_threads, sleeping_time_in_seconds=1, queue_limit=500): self.num_threads = num_threads self.waiting_queue = [] self.working = {} self.lock = Locker() self.sleeping_time = sleeping_time_in_seconds self.should_terminate = False self.is_working = False self.threads = [] self.queue_limit = queue_limit # Note: the default value is just a magic number, better configure it after testing properly!
def test_locker(self): locks = Locker(0.25) locks["foo"] = "bar" self.assertTrue(locks["foo"]) with self.assertRaises(KeyError): c = locks["bar"] locks["foo"] = "baz" self.assertNotEquals(locks["foo"], "baz") self.assertEquals(locks["foo"], "bar") self.assertTrue("foo" in locks) self.assertFalse("foot" in locks) time.sleep(0.3) self.assertFalse(locks["foo"]) del locks["foo"] with self.assertRaises(KeyError): self.assertFalse(locks["foo"])
class ThreadPoolMixIn(SocketServer.ThreadingMixIn): pool_size = 10 #No. of threads in the pool student_id = "17303647" dir_current = DFS_ROOT_DIR cache = Cache() locker = Locker() initialized = False root_dir = None #Main server loop def serve_always(self): #Create the request queue self.request_queue = Queue.Queue(self.pool_size) for t in range(self.pool_size): t = threading.Thread(target = self.process_request_thread) #Initialize threads #print "Starting pool thread ", t.name t.start() while 1: self.handle_request() #Get the ball rolling #Start handling the requests sent to the server def handle_request(self): #requests are esentially socket objects request, client_address = self.get_request() #Place in the queue self.request_queue.put((request,client_address)) #Get a request from the queue def process_request_thread(self): while 1: #ThreadingMixIn.process_request_thread(self, self.request_queue.get()) try: request, client_address = self.request_queue.get() except Queue.Empty: pass #Fufill request self.finish_request(request, client_address)
def setUp(self): self.new_password = Locker("GitHub", "DuncanArani", "dunco254")
if __name__ == '__main__': from locker import Locker pw_manager = Locker() data = pw_manager.get_locker_data() pw_manager.print_options() selected_option = pw_manager.ask_option() while selected_option != 0: if selected_option == 1: pw_manager.print_data() elif selected_option == 2: pw_manager.add_password() elif selected_option == 3: pw_manager.edit_password() elif selected_option == 4: pw_manager.delete_password() elif selected_option == 5: pw_manager.print_options() selected_option = pw_manager.ask_option()
class ThreadPoolMixIn(SocketServer.ThreadingMixIn): pool_size = 10 #No. of threads in the pool student_id = "17303647" dir_current = DFS_ROOT_DIR cache = Cache() locker = Locker() servers = {} #fs1 = FileServer(("0.0.0.0", 2049), ThreadedRequestHandler) #fs2 = FileServer(("0.0.0.0", 2050), ThreadedRequestHandler) s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Connect to first file server and pass its directory address1 = ("0.0.0.0", 2049) s1.connect(address1) s1.send(FILE_SERVER1_DIR) data = s1.recv(512) print data servers[FILE_SERVER1_DIR] = s1 #Connect to second file server and pass its directory address2 = ("0.0.0.0", 2050) s2.connect(address2) s2.send(FILE_SERVER2_DIR) data = s2.recv(512) print data servers[FILE_SERVER2_DIR] = s2 socketToSend = s1 #Main server loop def serve_always(self): #Create the request queue self.request_queue = Queue.Queue(self.pool_size) for t in range(self.pool_size): t = threading.Thread( target=self.process_request_thread) #Initialize threads #print "Starting pool thread ", t.name t.start() while 1: self.handle_request() #Get the ball rolling #Start handling the requests sent to the server def handle_request(self): #requests are essentially socket objects request, client_address = self.get_request() #Place in the queue self.request_queue.put((request, client_address)) #Get a request from the queue def process_request_thread(self): while 1: #ThreadingMixIn.process_request_thread(self, self.request_queue.get()) try: request, client_address = self.request_queue.get() except Queue.Empty: pass #Fufill request self.finish_request(request, client_address) #Every time a directory is changed, check which socket we have to send from def resolve_socket(self, path): #path = os.path.expanduser(path) while path not in self.servers: #Go up one directory path = os.path.dirname(os.path.normpath(path)) self.socketToSend = self.servers[path] def dir_change(self, path): #if path == os.pardir: if path == "..": self.dir_current = os.path.dirname( os.path.normpath(self.dir_current)) elif os.path.exists(path): self.dir_current += path if not self.dir_current.endswith('/'): self.dir_current += '/' else: return -1 self.resolve_socket(self.dir_current) return self.dir_current def dir_list(self, path): path = os.path.expanduser(path) lst = os.listdir(path) dirlst = "" for i in lst: dirlst += i + '\n' return dirlst #This is where the work is done def finish_request(self, request, client_address): while 1: #Recieve data from client data = request.recv(8192) root_dir = os.path.expanduser(DFS_ROOT_DIR) os.chdir(root_dir) """ N/B: Requests will of the form <COMMAND> <DIR> <DATA> e.g. READ_FILE ~/DFS-FILES/loremipsum.txt <COMMANDS> : READ FILE <DIR> WRITE FILE <DIR> <DATA> CHDIR <DIR> PWDIR <DIR> LS """ if not data: response = "The directory server received nothing" request.sendto(response, client_address) else: if data.startswith("READ FILE"): r = re.compile("READ FILE (.*?)$") res = r.search(data) path = res.group(1) self.socketToSend.send(data) response = self.socketToSend.recv(8192) #response = self.read_file(path) request.sendto(response, client_address) if data.startswith("WRITE FILE"): #r = re.compile("WRITE FILE (.*?)$") #res = r.search(data) #s = res.group(1) #data = s.split(" ", 1) self.socketToSend.send(data) response = self.socketToSend.recv(8192) #response = self.write_file(data) request.sendto(response, client_address) if data.startswith("PWD"): response = self.dir_current request.sendto(response, client_address) if data.startswith("CD"): r = re.compile("CD (.*?)$") res = r.search(data) path = res.group(1) if self.dir_change(path) == -1: response = "Path or directory does not exist" request.sendto(response, client_address) else: #Have to send something, as the client expects a response request.sendto(" ", client_address) if data.startswith("LS"): response = self.dir_list(self.dir_current) request.sendto(response, client_address) if data.startswith("QUIT"): for key in self.servers: sock = self.servers[key] sock.send(data) print "Shutting down Directory Server" self.shutdown() def shutdown(self): server.server_close() #Force shutdown os._exit(os.EX_OK)
reset_apache_conf() restart_apache() # restart dockers for domain_name in data['domains']: start_docker(data['domains'][domain_name]['port'], domain_name) @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Headers', 'Keep-Alive,User-Agent,If-Modified-Since,Cache-Control,x-requested-with,Content-Type,origin,authorization,accept,client-security-token') response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') return response # One locker for project and domain project_lock = Locker() domain_lock = Locker() def _copy_from_hdfs(hdfs_path, local_path): import subprocess subprocess.call(['hadoop', 'fs', '-copyToLocal', hdfs_path, local_path]) def _get_project_dir_path(project_name): return os.path.join(config['repo']['local_path'], project_name) def _get_domain_dir_path(domain_name): return os.path.join(config['image']['base_domain_dir_path'], domain_name) # deprecated # def _submit_worfklow(start_ts, end_ts, table_sha1, table_update, domain):
def new_password(account, username, thepass): new_pass = Locker(account, username, thepass) return new_pass