Пример #1
0
    def save(self):
        # Create the Password Manager
        password_manager = PasswordManager()

        # Create the DBConnection
        database = DBConnection()

        # Create the SQL
        if self.id is None:
            sql = "INSERT INTO connections (name, host, port, user, passwd, use_key, key_path)" \
                  " VALUES ('{}', '{}', {}, '{}', '{}', {}, '{}');"
        else:
            sql = "UPDATE connections SET name = '{}', host = '{}', port = {}, user = '******', passwd = '{}'," \
                  " use_key = {}, key_path = '{}' where id_connection = {}"

        # Bind the values
        sql = sql.format(self.name, self.host, self.port, self.user,
                         password_manager.encrypt_password(self.password),
                         1 if self.use_key else 0, self.key_path, self.id)

        # Execute the SQL
        if database.execute_query(sql) > 0:
            # Get the last row inserted
            if self.id is None:
                self.id = database.cursor.lastrowid

            # Return true telling it's OK
            return True
        else:
            # Return False for fail
            return False
Пример #2
0
    def save(self):
        # Instance the database
        database = DBConnection()

        # Remove the settings from database
        database.execute_query("DELETE FROM settings")

        # Create the list of params
        params = [(Settings.X11_FORWARD, self.x11_forward),
                  (Settings.REQUEST_COMPRESSION, self.request_compression),
                  (Settings.FORCE_IPV4, self.force_ipv4),
                  (Settings.FORCE_IPV6, self.force_ipv6)]

        # Save the settings
        affected_rows = database.execute_query_many(
            "INSERT INTO settings (property, value) VALUES (?, ?)", params)

        if affected_rows == 4:
            # Saved all settings
            return True
        else:
            # Something is wrong, try again
            return False
Пример #3
0
    def save(self):
        # Instance the database
        database = DBConnection()

        # Remove the settings from database
        database.execute_query("DELETE FROM settings")

        # Create the list of params
        params = [(Settings.X11_FORWARD, self.x11_forward),
                  (Settings.REQUEST_COMPRESSION, self.request_compression),
                  (Settings.FORCE_IPV4, self.force_ipv4),
                  (Settings.FORCE_IPV6, self.force_ipv6)]

        # Save the settings
        affected_rows = database.execute_query_many(
            "INSERT INTO settings (property, value) VALUES (?, ?)", params
        )

        if affected_rows == 4:
            # Saved all settings
            return True
        else:
            # Something is wrong, try again
            return False
Пример #4
0
    def delete(self):
        # Check if have the connection ID
        if self.id is not None:
            # Create the DBConnection
            database = DBConnection()

            # Create the SQL
            sql = "DELETE FROM connections WHERE id_connection = {}"

            # Bind the value
            sql = sql.format(self.id)

            # Execute the query
            if database.execute_query(sql) > 0:
                # Return true telling it's OK
                return True
            else:
                # Return False
                return False
Пример #5
0
    def delete(self):
        # Check if have the connection ID
        if self.id is not None:
            # Create the DBConnection
            database = DBConnection()

            # Create the SQL
            sql = "DELETE FROM connections WHERE id_connection = {}"

            # Bind the value
            sql = sql.format(self.id)

            # Execute the query
            if database.execute_query(sql) > 0:
                # Return true telling it's OK
                return True
            else:
                # Return False
                return False
Пример #6
0
    def save(self):
        # Create the Password Manager
        password_manager = PasswordManager()

        # Create the DBConnection
        database = DBConnection()

        # Create the SQL
        if self.id is None:
            sql = "INSERT INTO connections (name, host, port, user, passwd, use_key, key_path)" \
                  " VALUES ('{}', '{}', {}, '{}', '{}', {}, '{}');"
        else:
            sql = "UPDATE connections SET name = '{}', host = '{}', port = {}, user = '******', passwd = '{}'," \
                  " use_key = {}, key_path = '{}' where id_connection = {}"

        # Bind the values
        sql = sql.format(
            self.name,
            self.host,
            self.port,
            self.user,
            password_manager.encrypt_password(self.password),
            1 if self.use_key else 0,
            self.key_path,
            self.id
        )

        # Execute the SQL
        if database.execute_query(sql) > 0:
            # Get the last row inserted
            if self.id is None:
                self.id = database.cursor.lastrowid

            # Return true telling it's OK
            return True
        else:
            # Return False for fail
            return False