Beispiel #1
0
    def load(self):
        # Create the Password Manager
        password_manager = PasswordManager()

        # Create the DBConnection
        database = DBConnection()

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

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

        # Execute the query
        rows = database.select_query(sql)

        # Set the attrs
        for row in rows:
            self.name = row['name']
            self.host = row['host']
            self.port = row['port']
            self.user = row['user']
            self.password = password_manager.decrypt_password(row['passwd'])
            self.use_key = True if int(row['use_key']) == 1 else False
            self.key_path = row['key_path']
Beispiel #2
0
    def load_tunnels(self):
        # Clear the tunnels list form the collection
        self.tunnels.clear_tunnels()

        # Create the DBConnection
        database = DBConnection()

        # Create the SQL
        sql = "SELECT * FROM tunnels WHERE id_connection = {}"

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

        # Execute the query
        rows = database.select_query(sql)

        # Set the attrs
        for row in rows:
            tunnel = Tunnel()
            tunnel.id = row['id_tunnel']
            tunnel.id_connection = self.id
            tunnel.local_port = row['local_port']
            tunnel.address = row['address']
            tunnel.remote_port = row['remote_port']

            # Add on Tunnels
            self.tunnels.add_tunnel(tunnel)
Beispiel #3
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
Beispiel #4
0
    def load_tunnels(self):
        # Clear the tunnels list form the collection
        self.tunnels.clear_tunnels()

        # Create the DBConnection
        database = DBConnection()

        # Create the SQL
        sql = "SELECT * FROM tunnels WHERE id_connection = {}"

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

        # Execute the query
        rows = database.select_query(sql)

        # Set the attrs
        for row in rows:
            tunnel = Tunnel()
            tunnel.id = row['id_tunnel']
            tunnel.id_connection = self.id
            tunnel.local_port = row['local_port']
            tunnel.address = row['address']
            tunnel.remote_port = row['remote_port']

            # Add on Tunnels
            self.tunnels.add_tunnel(tunnel)
Beispiel #5
0
    def load(self):
        # Create the Password Manager
        password_manager = PasswordManager()

        # Create the DBConnection
        database = DBConnection()

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

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

        # Execute the query
        rows = database.select_query(sql)

        # Set the attrs
        for row in rows:
            self.name = row['name']
            self.host = row['host']
            self.port = row['port']
            self.user = row['user']
            self.password = password_manager.decrypt_password(row['passwd'])
            self.use_key = True if int(row['use_key']) == 1 else False
            self.key_path = row['key_path']
Beispiel #6
0
    def load(self):
        # Create the databse
        database = DBConnection()

        # Make the select
        rows = database.select_query("SELECT * FROM settings")
        for row in rows:
            # Check the name of the property and set the value correctly
            if row['property'] == Settings.X11_FORWARD:
                self.x11_forward = int(row['value'])
            elif row['property'] == Settings.REQUEST_COMPRESSION:
                self.request_compression = int(row['value'])
            elif row['property'] == Settings.FORCE_IPV4:
                self.force_ipv4 = int(row['value'])
            elif row['property'] == Settings.FORCE_IPV6:
                self.force_ipv6 = int(row['value'])
Beispiel #7
0
    def load(self):
        # Create the databse
        database = DBConnection()

        # Make the select
        rows = database.select_query("SELECT * FROM settings")
        for row in rows:
            # Check the name of the property and set the value correctly
            if row['property'] == Settings.X11_FORWARD:
                self.x11_forward = int(row['value'])
            elif row['property'] == Settings.REQUEST_COMPRESSION:
                self.request_compression = int(row['value'])
            elif row['property'] == Settings.FORCE_IPV4:
                self.force_ipv4 = int(row['value'])
            elif row['property'] == Settings.FORCE_IPV6:
                self.force_ipv6 = int(row['value'])
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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
Beispiel #11
0
class Connections:

    dbconnection = None
    connections = []
    model = None

    def __init__(self):
        # Create the DB connection
        self.dbconnection = DBConnection()

    def load_connections(self):
        # Reset the List
        self.connections = []

        # Create the SQL
        sql = "select * from connections order by name"

        # Execute the sql
        results = self.dbconnection.select_query(sql)

        # Create a model for every connection
        for row in results:
            # Create new Connection
            connection = Connection()
            connection.id = row['id_connection']
            connection.name = row['name']
            connection.host = row['host']
            connection.user = row['user']
            connection.port = row['port']
            connection.use_key = True if row['use_key'] == 1 else False
            connection.key_path = row['key_path']

            # Add to the list
            self.connections.append(connection)

    # Method to get ListStore of names
    def get_connection_names_model(self):
        # Create the ListStore
        self.model = Gtk.ListStore(str, int)

        # Looping passing by every connection
        for connection in self.connections:
            self.model.append([connection.name, connection.id])

        # return the model
        return self.model

    # Return all Connection
    def get_connections(self):
        return self.connections
Beispiel #12
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
Beispiel #13
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
Beispiel #14
0
 def __init__(self):
     # Create the DB connection
     self.dbconnection = DBConnection()
Beispiel #15
0
class Tunnels:

    dbconnection = None
    tunnels = []
    model = None

    def __init__(self):
        # Create the DB connection
        self.dbconnection = DBConnection()

    def add_tunnel(self, tunnel):
        # Add to the list
        self.tunnels.append(tunnel)

    def remove_tunnel_at(self, index):
        # Remove the tunnel
        if len(self.tunnels) > 0:
            self.tunnels.pop(index)

    def load_tunnels(self, id_connection):
        # Reset the List
        self.tunnels = []

        # Create the SQL
        sql = "select * from tunnels where id_connection = {}"
        sql = sql.format(id_connection)

        # Execute the sql
        results = self.dbconnection.select_query(sql)

        # Create a model for every tunnel
        for row in results:
            # Create new Connection
            tunnel = Tunnel()
            tunnel.id = 0 if row['id_tunnel'] is None else row['id_tunnel']
            tunnel.id_connection = 0 if row['id_connection'] is None else row['id_connection']
            tunnel.local_port = row['local_port']
            tunnel.address = row['address']
            tunnel.remote_port = row['remote_port']

            # Add to the list
            self.tunnels.append(tunnel)

    def clear_tunnels(self):
        # Clear list of tunnels
        self.tunnels = []

    # Method to get ListStore of names
    def get_tunnels_model(self):
        # Create the ListStore
        self.model = Gtk.ListStore(int, str, int, int)

        # Looping passing by every tunnel
        index = 0
        for tunnel in self.tunnels:
            # Add the model
            self.model.append([int(tunnel.local_port), tunnel.address, int(tunnel.remote_port), index])

            # Increment the counter
            index += 1

        # return the model
        return self.model

    # Return all Connection
    def get_tunnels(self):
        return self.tunnels
Beispiel #16
0
 def __init__(self):
     # Create the DB connection
     self.dbconnection = DBConnection()