Exemple #1
0
    def ACCOUNT_ERROR(self,
                      event,
                      username,
                      password,
                      host,
                      port,
                      key,
                      sizer,
                      actiontype="login"):
        '''Connection errors when logging in or registering'''
        if self.CONNECT(host, port):
            if actiontype == "login":
                msg = LOGIN
            else:
                msg = REGISTER

            # Sending info and getting resonse
            SENDMSG(msg(username, password), self.clientsocket)
            response = RECVMSG(self.clientsocket)

            if response == "PROCEED":
                # keygen.join()
                self.ACCOUNT_FILES(key, username, password)  # Set up files
                if msg == REGISTER:
                    self.clientsocket.close()
                return False
            else:
                self.DEFAULT_ERROR(
                    response, sizer)  # Show error msg according to response
                self.clientsocket.close()
                return True
        else:
            return True
Exemple #2
0
 def CONNECT_LOGIN(self, host, port, username, password):
     '''Shortcut for connecting and logging in'''
     if self.CONNECT(host, port, False):
         SENDMSG(LOGIN(username, password), self.clientsocket)
         if RECVMSG(self.clientsocket) == "PROCEED":
             from windows.window_chat import ChatWindow
             ChatWindow(username, password, host, port, self.clientsocket)
Exemple #3
0
    def CONNECT_CORE(self, host, port):
        '''Core connection function - creating connection and checking for update'''
        self.clientsocket = socket()
        self.clientsocket = wrap_socket(self.clientsocket,
                                        ssl_version=PROTOCOL_TLSv1)
        self.clientsocket.connect((host, port))

        # Checking for new version
        version_current = datetime.strptime(RECVMSG(self.clientsocket),
                                            "%d-%m-%Y %H:%M:%S")
        version_local = datetime.strptime(
            FILE_READ(appdata + "\\last_update.txt"), "%d-%m-%Y %H:%M:%S")
        if version_current > version_local:
            SENDMSG(True, self.clientsocket)
            Popen("python \"" + getcwd() + "\\run_updater.py\"")
            kill(getpid(), SIGTERM)
        else:
            SENDMSG(False, self.clientsocket)
Exemple #4
0
 def reconnect_client(self):
     '''Function for reconnecting after losing connection to server'''
     try:
         self.clientsocket.shutdown(SHUT_RDWR)
         self.clientsocket.close()
         self.CONNECT_CORE(self.host, self.port)
         SENDMSG({
             "actiontype": "reconnect",
             "user": self.username
         }, self.clientsocket)
         return True
     except socketerror:
         return False
Exemple #5
0
    def mainfunc(self, event):
        '''Main function'''
        self.RESET_COLOR(*self.textboxes)

        field_oldpass, field_newpass, field_newpass_repeat = self.textboxes
        old_password = field_oldpass.GetValue()
        new_password = field_newpass.GetValue()

        # Error handling
        if len(old_password) == 0:
            self.SHOW_ERRORMSG("Please input a password.", field_oldpass)
        elif len(new_password) == 0:
            self.SHOW_ERRORMSG("Please input a new password.", field_newpass)
        elif field_newpass_repeat.GetValue() != new_password:
            self.SHOW_ERRORMSG("'New password' and 'Repeat new password'\nneed to be identical!", \
                               field_newpass, field_newpass_repeat)
        else:
            # Connect to server if no errors occured
            if self.CONNECT(self.host, self.port):
                SENDMSG({"actiontype": "changepass", "user": self.username, \
                         "old_pass": HASH(old_password), \
                         "new_pass": HASH(new_password)}, self.clientsocket)
                response = RECVMSG(self.clientsocket)

                if response == "PROCEED":
                    # Create files and start main window
                    userdir = appdata + "\\" + self.username + "\\"

                    self.keygen.join()
                    self.ACCOUNT_FILES(key_return(), self.username,
                                       new_password)
                    FILE_WRITE(userdir + "oldpass.txt", HASH(old_password))
                    FILE_WRITE(userdir + "newpass.txt", str(self.servers))

                    from window_chat import ChatWindow
                    ChatWindow(self.username, new_password, self.host,
                               self.port, self.clientsocket)
                    self.Destroy()
                else:
                    self.DEFAULT_ERROR(response, self.inputs)
Exemple #6
0
 def add_contact(self, event):
     contact = self.contact_name.GetValue()
     SENDMSG({
         "datatype": "contact-add",
         "contact": contact
     }, self.parent.clientsocket)
# Starting application
app = App()
if isfile(current_account) and isfile(current_key):
    while host != None and port != None:
        # Connecting
        if Connect.CONNECT(host, port, False):
            key = RSA.importKey(FILE_READ(current_key))
            username, password = eval(key.decrypt(b64decode(FILE_READ(current_account))))
            
            # Changing password when connecting
            oldpass = appdata + username + "\\oldpass.txt"
            newpass = appdata + username + "\\newpass.txt"
            if isfile(newpass) and host in eval(FILE_READ(newpass)):
                changepass = True
                SENDMSG({"actiontype": "changepass", "user": username, \
                         "old_pass": FILE_READ(oldpass), "new_pass": HASH(password)}, \
                        Connect.clientsocket)
            else:
                changepass = False
                msg = LOGIN(username, password, True)
                SENDMSG(msg, Connect.clientsocket)
            
            response = RECVMSG(Connect.clientsocket)
            
            # Opening window
            if response == "PROCEED":
                if changepass:
                    remain_hosts = eval(FILE_READ(newpass))
                    remain_hosts.remove(host)
                    if len(remain_hosts) == 0:
                        FILE_DELETE(oldpass)
Exemple #8
0
 def _try_send(self, msg):
     '''Try sending message until connection is re-established'''
     while self.reconnecting:
         sleep(0.02)
     SENDMSG(msg, self.clientsocket)