def __init__(self, conn, client): myprint("Init Single Connection") super(SingleConnection, self).__init__() self.directory_path = directory self.conn = conn self.client = client self.free_size = -1 self.user_name = '' self.last_folder = '' self.finish_conection = False self.os_separator = os_separator f = open(REG_USERS_FILE, 'a') f.close() if (system() != 'Linux' and system() != 'Windows'): debugme( "CRITICAL ERROR: system operation not supported. Availability: Unix, Windows" ) self.finish_conection = True exit() if (self.directory_path == ''): self.directory_path = 'automatic backup' if (not os.path.exists(self.directory_path)): os.mkdir(self.directory_path)
def __init__ (self, conn, client): myprint("Init Single Connection") super(SingleConnection, self).__init__() self.directory_path = directory self.conn = conn self.client = client self.free_size = -1 self.user_name = '' self.last_folder = '' self.finish_conection = False self.os_separator = os_separator f = open(REG_USERS_FILE, 'a') f.close() if (system() != 'Linux' and system() != 'Windows'): debugme("CRITICAL ERROR: system operation not identify, Availability: Unix, Windows") self.finish_conection = True exit() if (self.directory_path == ''): self.directory_path = 'automatic backup' if (not os.path.exists(self.directory_path)): os.mkdir(self.directory_path)
def __check_header(self): # read header header = self.conn.recv(1024).decode() header = header.split(LF) ret = MSG.I_DONT_KNOW_YOU try: auba, version = header[0].split(SEPARATOR) except Exception, e: debugme("Error: header not accepted.\n" + join(header, LF) + '\n' + str(e)) return MSG.CONTRACT_ERROR
def __has_update(self): ret = False map_current_state = {} map_updates = {} directory = self.directory_path if (directory == ''): debugme('Directory to backup has not setting') self.error = True return ret if (not os.path.exists(directory)): os.mkdir(directory) files = os.listdir(directory) if (not os.path.exists(self.last_state_path) and files != []): for file in files: full_path_file = directory + os_separator + file map_updates[file] = MSG.ADDITION, os.path.getsize( full_path_file), str( datetime.fromtimestamp( os.path.getmtime(full_path_file))) ret = True elif (os.path.exists(self.last_state_path)): last_state = open(self.last_state_path, 'r') map_last_state = json.load(last_state) last_state.close() for file in files: dt = datetime.fromtimestamp(os.path.getmtime(file)) map_current_state[file] = str(dt) if (map_last_state != map_current_state): ret = True for file in map_current_state.keys(): if (not map_last_state.has_key(file)): size_file = os.path.getsize(directory + os_separator + file) map_updates[ file] = MSG.ADDITION, size_file, map_current_state[ file] else: if (map_last_state[file] != map_current_state[file]): size_file = os.path.getsize(directory + os_separator + file) map_updates[ file] = MSG.CHANGES, size_file, map_current_state[ file] # Remove of map_last_state the intersection between: # map_last_state and map_current_state del (map_last_state[file]) for file in map_last_state: map_updates[file] = MSG.REMOVAL, None, '0 0' self.map_updates = map_updates self.map_last_state = map_current_state return ret
def __has_update(self): ret = False map_current_state = {} map_updates = {} directory = self.directory_path if (directory == ''): debugme('Directory to backup has not setting') self.error = True return ret if (not os.path.exists(directory)): os.makedirs(directory) files = os.listdir(directory) if (not os.path.exists(self.last_state_path) and files != []): for file in files: full_path_file = directory + os_separator + file f = open(full_path_file, 'r') content_file = f.read() f.close() map_updates[file] = MSG.ADDITION, len(content_file), str(datetime.fromtimestamp(os.path.getmtime(full_path_file))) ret = True elif (os.path.exists(self.last_state_path)): last_state = open(self.last_state_path, 'r') map_last_state = json.load(last_state, encoding = 'iso-8859-1') last_state.close() for file in files: full_path_file = directory + os_separator + file dt = datetime.fromtimestamp(os.path.getmtime(full_path_file)) map_current_state[file] = str(dt) if (map_last_state != map_current_state): ret = True for file in map_current_state.keys(): full_path_file = directory + os_separator + file if (not map_last_state.has_key(file)): f = open(full_path_file, 'r') content_file = f.read() f.close() map_updates[file] = MSG.ADDITION, len(content_file), map_current_state[file] else: if (map_last_state[file] != map_current_state[file]): f = open(full_path_file, 'r') content_file = f.read() f.close() map_updates[file] = MSG.CHANGES, len(content_file), map_current_state[file] # Remove of map_last_state the intersection between: # map_last_state and map_current_state del(map_last_state[file]) for file in map_last_state: map_updates[file] = MSG.REMOVAL, None, '0 0' self.map_updates = map_updates self.map_last_state = map_current_state return ret
def __handle_file(self): # read header file header_file = '' while True: block = self.conn.recv(block_size) header_file += block if ((not block) or len(block) < block_size): break header_file = header_file.split(LF) ret = MSG.OK try: auba, version = header_file[0].split(SEPARATOR) except Exception, e: debugme("Error: header not accepted" + join(header_file, LF) + '\n' + str(e)) return MSG.CONTRACT_ERROR
def __handle_file(self): # read header file header_file = '' while True: block = self.conn.recv(4096) if not block: break header_file += block header_file = header_file.split(LF) ret = MSG.OK try: auba, version = header_file[0].split(SEPARATOR) except Exception, e: debugme("Error: header not accepted" + join(header_file, LF) + '\n' + str(e)) return MSG.CONTRACT_ERROR
def __check_user_space(self): if (system() == 'Windows'): full_path_user = self.directory_path f = join(os.popen("dir " + full_path_user).readlines(),'') stats = split(f,'\n') self.free_size = join(split(split(stats[-2],' ')[-3],'.'),'') self.free_size = int(self.free_size) elif (system() == 'Linux'): full_path_user = self.directory_path myprint('Full path client ' + self.user_name + ': ' + full_path_user) f = os.popen("df " + full_path_user).read().split(' ')[-4] self.free_size = int(f) else: debugme("CRITICAL ERROR: system operation not supported. Availability: Unix, Windows") self.finish_conection = True self.free_size = -1 exit() return self.free_size
def __check_user_space(self): if (system() == 'Windows'): full_path_user = self.directory_path f = join(os.popen("dir " + full_path_user).readlines(),'') stats = split(f,'\n') self.free_size = join(split(split(stats[-2],' ')[-3],'.'),'') self.free_size = int(self.free_size) elif (system() == 'Linux'): full_path_user = self.directory_path myprint('Full path client ' + self.user_name + ': ' + full_path_user) f = os.popen("df " + full_path_user).read().split(' ')[-4] self.free_size = int(f) else: debugme("CRITICAL ERROR: system operation not identify, Availability: Unix, Windows") self.finish_conection = True self.free_size = -1 exit() return self.free_size
SEPARATOR = ' ' INTERFACE = socket.AF_INET # interface type TRANSPORT = socket.SOCK_STREAM # transport type: aka TCP FOLDER_BACK = 'current' # Folder with link to update files PREVIOUS = 'previous' # Folder with other folder that contains the previous files REG_USERS_FILE ='.reg-users.auba' # Name of file to register user. Default: reg-users.auba # Global variables hosts_accepts = Config.HOSTS port = Config.PORT number_of_users = Config.NUMBER_OF_USERS directory = Config.DIRECTORY_BACKUP_SERVER # Checking settings if (not directory): debugme('ERROR: directory to store backup not specified\n\t- Setting in settingsserver.py file') exit() # Checking platform if (system() == 'Windows'): os_separator = '\\' # backslash import ctypes # to create symbolic link elif (system() == 'Linux'): os_separator = '/' # slash else: debugme('CRITICAL ERROR: system operation not supported. Availability: Unix, Windows') exit() class SingleConnection(Thread): def __init__ (self, conn, client): myprint("Init Single Connection")
client = ClientAUBA() myprint('Wait for updates') client.wait_for_updates() is_error = client.is_error() if (not is_error): myprint('* Update detected\n') client.connect() recv = client.request_backup() myprint('Status for request backup: ' + recv[:-1]) if (recv == MSG.I_DONT_KNOW_YOU): myprint('Request register to: ' + Config.CLIENT_NAME) recv = client.request_register() if (recv == MSG.REGISTER_OK): myprint('Register success') myprint('* Request backup again\n\n') recv = client.request_backup() elif (recv == MSG.WRONG_PASSWD): debugme('Error (-1): invalid password for server: ' + client.get_server()) else: debugme('Error (-2): unknow message: ' + recv) elif (recv == MSG.OK): myprint('Start to send files') recv = client.send_updates() myprint('Result of send updates: ' + recv) else: debugme('Error: message from server unknow: ' + recv) client.close() myprint('* Finish operation\n\n') myprint('\nStop client AUBA ' + auba_version + '\n\n')
class SingleConnection(Thread): def __init__(self, conn, client): myprint("Init Single Connection") super(SingleConnection, self).__init__() self.directory_path = directory self.conn = conn self.client = client self.free_size = -1 self.user_name = '' self.last_folder = '' self.finish_conection = False self.os_separator = os_separator f = open(REG_USERS_FILE, 'a') f.close() if (system() != 'Linux' and system() != 'Windows'): debugme( "CRITICAL ERROR: system operation not supported. Availability: Unix, Windows" ) self.finish_conection = True exit() if (self.directory_path == ''): self.directory_path = 'automatic backup' if (not os.path.exists(self.directory_path)): os.mkdir(self.directory_path) def __check_user_space(self): if (system() == 'Windows'): full_path_user = self.directory_path f = join(os.popen("dir " + full_path_user).readlines(), '') stats = split(f, '\n') self.free_size = join(split(split(stats[-2], ' ')[-3], '.'), '') self.free_size = int(self.free_size) elif (system() == 'Linux'): full_path_user = self.directory_path myprint('Full path client ' + self.user_name + ': ' + full_path_user) f = os.popen("df " + full_path_user).read().split(' ')[-4] self.free_size = int(f) else: debugme( "CRITICAL ERROR: system operation not supported. Availability: Unix, Windows" ) self.finish_conection = True self.free_size = -1 exit() return self.free_size def __check_user_register(self): reg_users = open(REG_USERS_FILE, 'r') users_list = reg_users.read().split(LF) reg_users.close() return self.user_name in users_list def __check_header(self): # read header header = self.conn.recv(1024).decode() header = header.split(LF) ret = MSG.I_DONT_KNOW_YOU try: auba, version = header[0].split(SEPARATOR) except Exception, e: debugme("Error: header not accepted.\n" + join(header, LF) + '\n' + str(e)) return MSG.CONTRACT_ERROR if (auba != MSG.AUBA or len(header) != 3): ret = MSG.CONTRACT_ERROR else: try: request, self.user_name = header[1].split(SEPARATOR) parameter1, parameter2 = header[2].split(SEPARATOR) except Exception, e: debugme("Error: header not accepted.\n" + join(header, LF) + '\n' + str(e)) return MSG.CONTRACT_ERROR # Check user check_user = self.__check_user_register() if (request != MSG.REGISTER_ME and not check_user): self.conn.send(MSG.I_DONT_KNOW_YOU) debugme('Unknow user request backup') header = self.conn.recv(1024) header = header.split(LF) try: request, self.user_name = header[1].split(SEPARATOR) parameter1, parameter2 = header[2].split(SEPARATOR) except Exception, e: debugme("Error: header not accepted.\n" + join(header, LF) + '\n' + str(e)) return MSG.CONTRACT_ERROR
FOLDER_BACK = 'current' # Folder with link to update files PREVIOUS = 'previous' # Folder with other folder that contains the previous files REG_USERS_FILE = '.reg-users.auba' # Name of file to register user. Default: reg-users.auba hosts_accepts = Config.HOSTS port = Config.PORT number_of_users = Config.NUMBER_OF_USERS directory = Config.DIRECTORY_BACKUP_SERVER if (system() == 'Windows'): os_separator = '\\' # backslash import ctypes # to create symbolic link elif (system() == 'Linux'): os_separator = '/' # slash else: debugme( "CRITICAL ERROR: system operation not supported. Availability: Unix, Windows" ) exit() class SingleConnection(Thread): def __init__(self, conn, client): myprint("Init Single Connection") super(SingleConnection, self).__init__() self.directory_path = directory self.conn = conn self.client = client self.free_size = -1 self.user_name = ''
from datetime import datetime from headers import Construct from platform import system reload(sys) sys.setdefaultencoding('iso-8859-1') auba_version = MSG.auba_version INTERFACE = socket.AF_INET # interface type TRANSPORT = socket.SOCK_STREAM # transport type: aka TCP LF = '\n' # line feed # Checking settings if (not Config.DIRECTORY_TO_BACKUP): debugme('ERROR: directory to save backup not specified.\n\t- Setting in settingsclient.py file') exit() if (not Config.CLIENT_NAME): debugme('ERROR: name for client not specified.\n\t- Setting in settingsclient.py file') exit() # Checking platform if (system() == 'Windows'): os_separator = '\\' import ctypes # to create symbolic link elif (system() == 'Linux'): os_separator = '/' else: debugme("CRITICAL ERROR: system operation not supported. Availability: Unix, Windows") exit()
TRANSPORT = socket.SOCK_STREAM # transport type: aka TCP FOLDER_BACK = 'current' # Folder with link to update files PREVIOUS = 'previous' # Folder with other folder that contains the previous files REG_USERS_FILE='.reg-users.auba' # Name of file to register user. Default: reg-users.auba hosts_accepts = Config.HOSTS port = Config.PORT number_of_users = Config.NUMBER_OF_USERS directory = Config.DIRECTORY_BACKUP_SERVER if (system() == 'Windows'): os_separator = '\\' import ctypes # to create symbolic link elif (system() == 'Linux'): os_separator = '/' else: debugme("CRITICAL ERROR: system operation not identify, Availability: Unix, Windows") exit() class SingleConnection(Thread): def __init__ (self, conn, client): myprint("Init Single Connection") super(SingleConnection, self).__init__() self.directory_path = directory self.conn = conn self.client = client self.free_size = -1 self.user_name = '' self.last_folder = '' self.finish_conection = False
reload(sys) sys.setdefaultencoding('utf-8') auba_version = MSG.auba_version INTERFACE = socket.AF_INET # interface type TRANSPORT = socket.SOCK_STREAM # transport type: aka TCP LF = '\n' # line feed if (system() == 'Windows'): os_separator = '\\' import ctypes # to create symbolic link elif (system() == 'Linux'): os_separator = '/' else: debugme("CRITICAL ERROR: system operation not supported. Availability: Unix, Windows") exit() class ClientAUBA: def __init__(self): self.last_state_path = '.last-state.auba' self.map_updates_save = '.map-update-file.auba' self.size_buffer_recv = 1024 self.directory_path = Config.DIRECTORY_TO_BACKUP self.client_name = Config.CLIENT_NAME self.host = Config.HOST_SERVER self.port = Config.PORT self.user = Config.CLIENT_NAME self.passwd = Config.PASSWD_SERVER self.time_check = Config.TIME_CHECK
sys.setdefaultencoding('utf-8') auba_version = MSG.auba_version INTERFACE = socket.AF_INET # interface type TRANSPORT = socket.SOCK_STREAM # transport type: aka TCP LF = '\n' # line feed if (system() == 'Windows'): os_separator = '\\' import ctypes # to create symbolic link elif (system() == 'Linux'): os_separator = '/' else: debugme( "CRITICAL ERROR: system operation not supported. Availability: Unix, Windows" ) exit() class ClientAUBA: def __init__(self): self.last_state_path = '.last-state.auba' self.map_updates_save = '.map-update-file.auba' self.size_buffer_recv = 1024 self.directory_path = Config.DIRECTORY_TO_BACKUP self.client_name = Config.CLIENT_NAME self.host = Config.HOST_SERVER self.port = Config.PORT self.user = Config.CLIENT_NAME self.passwd = Config.PASSWD_SERVER