def web_socket_transfer_data(request): logger.logInfo(NAME + "Server dostal zgloszenie") paramsDictionary = {} paramsDictionary["SOCKET"] = request.ws_stream paramsDictionary["HOME_PATH"] = request.get_options()["PROJECT_LOCATION"] methodMapping = {PREPARE: prepare, GLOBAL_COMMIT: globalCommit, GLOBAL_ABORT: globalAbort} configReader = ConfigurationReader( paramsDictionary["HOME_PATH"] + "ServerSide/config/database_config/database.conf" ) dbParamsDict = configReader.readConfigFile() paramsDictionary["DB_PARAMS"] = dbParamsDict paramsDictionary["CLIENT_ADDRESS"] = request.connection.remote_ip login = request.ws_stream.receive_message() password = request.ws_stream.receive_message() db = DatabaseConnector(login, password, dbParamsDict["DATABASE"], dbParamsDict["HOST"]) command = request.ws_stream.receive_message() lockFilePath = paramsDictionary["HOME_PATH"] + "ServerSide/config/database_config/dbLock.dat" lock = FileLock(lockFilePath, 2, 0.05) try: while command != EXIT: methodMapping[command](paramsDictionary, db, lock) command = request.ws_stream.receive_message() if lock.is_locked: lock.release() except Exception, e: logger.logError(NAME + e.message) if lock.is_locked: lock.release() return apache.HTTP_OK
def templates(sender): template_file = getattr(self.domain, '{}_templates'.format(sender)) if request.method == 'GET': templates_list = load_templates(template_file) return jsonify(templates_list) elif request.method == 'POST': request_body = request.json with FileLock(template_file): with open(template_file, 'r+') as f: new_template_lines = [] template_written = False template_lines = f.readlines() for line in template_lines: line = line.strip('\n') new_template_lines.append(line) if line.startswith('---'): template_group = line.rstrip(' ---').lstrip( '--- ') if request_body['group'] == template_group: template_written = True new_template_lines.append( request_body['template']) if not template_written: new_template_lines.append(request_body['template']) with open(template_file, 'w') as f: f.write('\n'.join(new_template_lines)) templates_list = load_templates(template_file) return jsonify(templates_list)
def execute(paramsDictionary, message): homePath = paramsDictionary["HOME_PATH"] if "LOCK" in paramsDictionary: lock = paramsDictionary["LOCK"] else: lockFilePath = paramsDictionary["HOME_PATH"]+"ServerSide/config/database_config/dbLock.dat" lock = FileLock(lockFilePath,2,.05) paramsDictionary["LOCK"] = lock try: lock.acquire() except Exception, e: logger.logError(NAME + e.message) if lock.is_locked: lock.release() return
def web_socket_transfer_data(request): logger.logInfo(NAME+ "Server dostal zgloszenie") paramsDictionary = {} socket = request.ws_stream paramsDictionary["HOME_PATH"] = request.get_options()["PROJECT_LOCATION"] configReader = ConfigurationReader(paramsDictionary["HOME_PATH"]+"ServerSide/config/database_config/database.conf") dbParamsDict = configReader.readConfigFile() login = dbParamsDict["DEFAULT_LOGIN"] password = dbParamsDict["DEFAULT_PASSWORD"] clientVersion = socket.receive_message() logger.logInfo(NAME + "client version " + clientVersion) lockFilePath = paramsDictionary["HOME_PATH"]+"ServerSide/config/database_config/dbLock.dat" lock = FileLock(lockFilePath,3,.05) try: lock.acquire() except Exception, e: logger.logError(NAME + e.message) socket.send_message(LOCK_ERROR) return apache.HTTP_OK
def web_socket_transfer_data(request): logger.logInfo(NAME+ "Server dostal zgloszenie od klienta") paramsDictionary = {} paramsDictionary["REQUEST"] = request paramsDictionary["CLIENT_ADDRESS"]= request.connection.remote_ip paramsDictionary["SOCKET"] = request.ws_stream paramsDictionary["HOME_PATH"] = request.get_options()["PROJECT_LOCATION"] configReader = ConfigurationReader(paramsDictionary["HOME_PATH"]+"ServerSide/config/database_config/database.conf") dbParamsDict = configReader.readConfigFile() paramsDictionary["DB_PARAMS"] = dbParamsDict login = request.ws_stream.receive_message() password = request.ws_stream.receive_message() paramsDictionary["LOGIN"] = login paramsDictionary["PASSWORD"] = password db = DatabaseConnector(login, password, dbParamsDict["DATABASE"], dbParamsDict["HOST"]) if db.initConnection() == ERROR: request.ws_stream.send_message("Invalid username or password") logger.logError(NAME + "Uzytkownik podal niewlasciwy login lub haslo, zamykanie polaczenia") return apache.HTTP_OK logger.logInfo(NAME + "polaczenie z baza nawiazane") lockFilePath = paramsDictionary["HOME_PATH"]+"ServerSide/config/database_config/dbLock.dat" lock = FileLock(lockFilePath) while(True): try: query = request.ws_stream.receive_message() if query == CLOSING_MESSAGE: db.closeConnection() return apache.HTTP_OK else: logger.logImportant(NAME + "Klient chce wykonac zapytanie " + query) lock.acquire() output = db.executeSQL(query, paramsDictionary) lock.release() logger.logImportant(NAME + str(output)) request.ws_stream.send_message(str(output)) except Exception, e: logger.logError(NAME + "ERROR w trakcie odbierania wiadomosci " + e.message) db.closeConnection() if lock.is_locked: lock.release() return apache.HTTP_OK