コード例 #1
0
    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)
コード例 #2
0
ファイル: aubasys_server.py プロジェクト: geans/redes1
    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)
コード例 #3
0
 def __create_link(self, source, f_name):
     ret = MSG.OK
     link_name = self.directory_path + self.os_separator
     link_name += self.user_name + self.os_separator
     link_name += FOLDER_BACK + self.os_separator + f_name
     try:
         os.remove(link_name)
         myprint('Updating symbolic link')
     except Exception, e:
         myprint('Creating symbolic link')
コード例 #4
0
ファイル: aubasys_server.py プロジェクト: geans/redes1
 def __create_link(self, source, f_name):
     ret = MSG.OK
     link_name = self.directory_path + self.os_separator
     link_name += self.user_name + self.os_separator
     link_name += FOLDER_BACK + self.os_separator + f_name
     try:
         os.remove(link_name)
         myprint('Updating symbolic link')
     except Exception, e:
         myprint('Creating symbolic link')
コード例 #5
0
 def __save_file(self, content, f_name, f_occurred):
     ret = MSG.OK
     if (f_occurred == MSG.REMOVAL):
         myprint('Remove file: ' + f_name)
         link_name = self.directory_path + self.os_separator
         link_name += self.user_name + self.os_separator
         link_name += FOLDER_BACK + self.os_separator + f_name
         try:
             os.remove(link_name)
         except Exception, e:
             pass
コード例 #6
0
ファイル: aubasys_server.py プロジェクト: geans/redes1
 def __save_file(self, content, f_name, f_occurred):
     ret = MSG.OK
     if (f_occurred == MSG.REMOVAL):
         myprint('Remove file: ' + f_name)
         link_name = self.directory_path + self.os_separator
         link_name += self.user_name + self.os_separator
         link_name += FOLDER_BACK + self.os_separator + f_name
         try:
             os.remove(link_name)
         except Exception, e:
             pass
コード例 #7
0
ファイル: aubasys_server.py プロジェクト: geans/redes1
 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
コード例 #8
0
 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
コード例 #9
0
ファイル: aubasys_client.py プロジェクト: geans/redes1
 def send_updates(self):
     count_file = len(self.map_updates)
     myprint('Number of files to to send: ' + str(count_file))
     for file in self.map_updates.keys():
         occurred = self.map_updates[file][0]
         size_file = self.map_updates[file][1]
         datetime = self.map_updates[file][2]
         full_path_file = self.directory_path + os_separator + file
         try:
             f = open(full_path_file, 'r')
             content = f.read()
             f.close()
         except Exception, e:
             content = ''
             size_file = '0'
         header_file = self.construct.single_file_transmit(count_file, file, datetime,
                                                               occurred, size_file, content)
         count_file -= 1
         self.__send(header_file)
         recv = self.__recv()
         myprint('  File: "' + file + '", occurred: ' + occurred + ', status: ' + recv[:-1])
コード例 #10
0
ファイル: aubasys_client.py プロジェクト: geans/academico
 def send_updates(self):
     count_file = len(self.map_updates)
     myprint('Number of files to to send: ' + str(count_file))
     for file in self.map_updates.keys():
         occurred = self.map_updates[file][0]
         size_file = self.map_updates[file][1]
         datetime = self.map_updates[file][2]
         full_path_file = self.directory_path + os_separator + file
         try:
             f = open(full_path_file, 'r')
             content = f.read()
             f.close()
         except Exception, e:
             content = ''
             size_file = '0'
         header_file = self.construct.single_file_transmit(
             count_file, file, datetime, occurred, size_file, content)
         count_file -= 1
         self.__send(header_file)
         recv = self.__recv()
         myprint('  File: "' + file + '", occurred: ' + occurred +
                 ', status: ' + recv[:-1])
コード例 #11
0
ファイル: aubasys_server.py プロジェクト: geans/academico
 def run(self):
     status = self.__check_header()
     self.conn.send(status)
     if (status == MSG.REGISTER_OK):
         self.conn.send(status)
         myprint('Send register ok')
     else:
         while (status == MSG.OK and not self.finish_conection):
             myprint('Receiving files')
             status = self.__handle_file()
             self.conn.send(status)
         myprint('Finish receiver files, status: ' + status)
         if (status == MSG.OK):
             self.conn.send(MSG.COMPLETE_UPDATE)
         else:
             self.conn.send(MSG.ERROR_IN_UPDATE)
     return status
コード例 #12
0
ファイル: aubasys_server.py プロジェクト: geans/redes1
 def run(self):
     status = self.__check_header()
     self.conn.send(status)
     if (status == MSG.REGISTER_OK):
         self.conn.send(status)
         myprint('Send register ok')
     else:
         while (status == MSG.OK and not self.finish_conection):
             myprint('Receiving files')
             status = self.__handle_file()
             self.conn.send(status)
         myprint('Finish receiver files, status: ' + status)
         if (status == MSG.OK):
             self.conn.send(MSG.COMPLETE_UPDATE)
         else:
             self.conn.send(MSG.ERROR_IN_UPDATE)
     return status
コード例 #13
0
ファイル: aubasys_client.py プロジェクト: geans/academico
            count_file -= 1
            self.__send(header_file)
            recv = self.__recv()
            myprint('  File: "' + file + '", occurred: ' + occurred +
                    ', status: ' + recv[:-1])
        recv_finish_confirm = self.__recv()
        if (recv_finish_confirm == MSG.COMPLETE_UPDATE):
            # Save current map states
            update_last_state_file = open(self.last_state_path, 'w')
            update_last_state_file.write(json.dumps(self.map_last_state))
            update_last_state_file.close()
        return recv_finish_confirm


is_error = False
myprint('\nStart client AUBA ' + auba_version + '\n\n')
while not is_error:
    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')
コード例 #14
0
                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

            # Execute register
            if (request == MSG.REGISTER_ME):
                pw = parameter2
                myprint("User request register: " + self.user_name)
                if (pw == Config.PASSWD_SERVER):
                    reg_users = open(REG_USERS_FILE, 'a')
                    reg_users.write(self.user_name + LF)
                    new_directory = self.directory_path + self.os_separator
                    new_directory += self.user_name + self.os_separator
                    new_directory += FOLDER_BACK
                    if (not os.path.exists(new_directory)):
                        os.makedirs(new_directory)
                    ret = MSG.REGISTER_OK
                    myprint("User registered")

            # Execute backup
            elif (request == MSG.BACKUP_TO):
                if (not check_user):
                    check_user = self.__check_user_register()
コード例 #15
0
ファイル: aubasys_client.py プロジェクト: geans/redes1
                self.__send(header_file)
                recv = self.__recv()
                myprint('  File: "' + file + '", occurred: ' + occurred + ', status: ' + recv[:-1])
            else:
                del self.map_updates[file]
        recv_finish_confirm = self.__recv()
        if (recv_finish_confirm == MSG.COMPLETE_UPDATE):
            # Save current map states
            update_last_state_file = open(self.last_state_path, 'w')
            update_last_state_file.write(json.dumps(self.map_last_state, encoding = 'iso-8859-1'))
            update_last_state_file.close()
        return recv_finish_confirm

# Start operation
is_error = False
myprint('\nStart client AUBA ' + auba_version + '\n\n')
while not is_error:
    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')
コード例 #16
0
ファイル: aubasys_server.py プロジェクト: geans/redes1
 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
 
 # Execute register
 if (request == MSG.REGISTER_ME):
     pw = parameter2
     myprint("User request register: " + self.user_name)
     if (pw == Config.PASSWD_SERVER):
         reg_users = open(REG_USERS_FILE, 'a')
         reg_users.write(self.user_name + LF)
         new_directory = self.directory_path + self.os_separator
         new_directory += self.user_name + self.os_separator
         new_directory += FOLDER_BACK
         if (not os.path.exists(new_directory)):
             os.makedirs(new_directory)
         ret = MSG.REGISTER_OK
         myprint("User registered")
 
 # Execute backup
 elif (request == MSG.BACKUP_TO):
     if (not check_user):
         check_user = self.__check_user_register()