Beispiel #1
0
 public c_ScpConnectionManager(c_DBHandler _dbh, c_ConnectionObject _Conn)
 {
     Dbh         = _dbh;
     _connection = _Conn;
     if (_connection != null)
     {
         _protocol    = _connection.protocol();
         _host        = _connection.Host;
         _username    = _connection.Username;
         _password    = _connection.Password;
         _fingerprint = _connection.SshHostKeyFingerprint;
         _keyPath     = _connection.Keyfile_path;
     }
 }
Beispiel #2
0
        public f_EditConnection(bool edit = false, c_ConnectionObject conn = null)
        {
            InitializeComponent();

            Load += F_EditConnection_Load;

            if (edit && conn != null)
            {
                loadConnectionData(conn);
            }
            else
            {
                tb_ConnectionName.Text          = "New Connection";
                cb_Protocol.SelectedIndex       = 0;
                cb_Authentication.SelectedIndex = 0;
            }
        }
        public List <c_ConnectionObject> getConnections()
        {
            if (!checkConnection())
            {
                return(null);
            }
            List <c_ConnectionObject> conns = new List <c_ConnectionObject>();

            _sql.CommandText = "SELECT * FROM connections";

            SQLiteDataReader reader = _sql.ExecuteReader();

            while (reader.Read())
            {
                c_ConnectionObject c = new c_ConnectionObject();

                c.Id                    = coalesce(0, reader.GetValue(reader.GetOrdinal("id")));
                c.Project_id            = coalesce(0, reader.GetValue(reader.GetOrdinal("project_id")));
                c.Log_id                = coalesce(0, reader.GetValue(reader.GetOrdinal("log_id")));
                c.Name                  = coalesce("", reader.GetValue(reader.GetOrdinal("name")));
                c.Host                  = coalesce("", reader.GetValue(reader.GetOrdinal("host_name")));
                c.Port                  = coalesce(0, reader.GetValue(reader.GetOrdinal("port")));
                c.Password              = coalesce("", reader.GetValue(reader.GetOrdinal("password")));
                c.Username              = coalesce("", reader.GetValue(reader.GetOrdinal("username")));
                c.Connection_protocol   = coalesce("", reader.GetValue(reader.GetOrdinal("connection_protocol")));
                c.Authentication_method = coalesce("", reader.GetValue(reader.GetOrdinal("authentication_method")));
                c.Username              = coalesce("", reader.GetValue(reader.GetOrdinal("username")));
                c.Password              = coalesce("", reader.GetValue(reader.GetOrdinal("password")));
                c.Keyfile_path          = coalesce("", reader.GetValue(reader.GetOrdinal("keyfile_path")));
                c.Key_pass_phrase       = coalesce("", reader.GetValue(reader.GetOrdinal("key_pass_phrase")));
                c.Use_stored_keys       = coalesce("", reader.GetValue(reader.GetOrdinal("use_stored_keys")));
                c.SshHostKeyFingerprint = coalesce("", reader.GetValue(reader.GetOrdinal("SshHostKeyFingerprint")));
                c.Home_folder           = coalesce("", reader.GetValue(reader.GetOrdinal("home_folder")));
                c.LastConnected         = coalesce("", reader.GetValue(reader.GetOrdinal("lastConnected")));
                c.Last_error            = coalesce("", reader.GetValue(reader.GetOrdinal("last_error")));
                c.Last_update_finished  = coalesce("", reader.GetValue(reader.GetOrdinal("last_update_finished")));
                c.Ping_interval         = coalesce(0, reader.GetValue(reader.GetOrdinal("ping_interval")));

                conns.Add(c);
            }

            reader.Close();

            return(conns);
        }
        private void cb_Servers_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Text = "Connect to Server - " + cb_Servers.Text;
                tag  = (c_ConnectionObject)cb_Servers.getTag();

                if (tag != null)
                {
                    if (tag.Host != "" && tag.Username != "" &&
                        ((tag.Password != "" && tag.Authentication_method == "pwd") ||
                         (tag.Key_pass_phrase != "" && tag.Keyfile_path != "" && File.Exists(tag.Keyfile_path) && tag.Authentication_method == "key") ||
                         tag.Use_stored_keys == "Y"))
                    {
                        btn_Connect.Enabled = true;
                    }
                    else
                    {
                        btn_Connect.Enabled = false;
                    }

                    lbl_HostName.Text      = tag.Host;
                    lbl_ProjectName.Text   = Dbh.getProjectName(tag.Project_id);
                    lbl_Username.Text      = tag.Username;
                    lbl_Auth.Text          = tag.Authentication_method;
                    lbl_HomeDir.Text       = tag.Home_folder;
                    lbl_Key.Text           = tag.Keyfile_path;
                    lbl_LastConnected.Text = tag.LastConnected;
                    lbl_LastUpdate.Text    = tag.Last_update_finished;
                    lbl_Password.Text      = string.Concat(tag.Password.ToCharArray().Select(x => '•').ToArray());
                    lbl_Port.Text          = tag.Port + "";
                    lbl_Protocol.Text      = tag.Connection_protocol;
                }
                else
                {
                    btn_Connect.Enabled = false;
                }
            }
            catch
            {
            }
        }
Beispiel #5
0
        public void save()
        {
            c_ConnectionObject c = new c_ConnectionObject()
            {
                Name = tb_ConnectionName.Text,
                Connection_protocol = cb_Protocol.Text,
                Host                  = tb_HostName.Text,
                Password              = tb_Password.Text,
                Key_pass_phrase       = tb_Password.Text,
                Keyfile_path          = tb_KeyFile.Text,
                Use_stored_keys       = cb_Authentication.SelectedIndex == 2 ? "T" : "F",
                Authentication_method = cb_Authentication.Text,
                Home_folder           = tb_HomeFolder.Text,
                Ping_interval         = (int)num_PingInterval.Value,
                Username              = tb_Username.Text,
                Port                  = (int)num_Port.Value,
                Proxy_Settings        = _proxy_settings,
                Ssh_Settings          = _ssh_settings,
                Tunnel_Settings       = _tunnel_settings
            };

            Dbh.saveConnection(c);
            close();
        }
        public void saveConnection(c_ConnectionObject c)
        {
            if (!checkConnection())
            {
                return;
            }

            if (c.Id == -1)
            {
                string logid      = "";
                byte[] logidbytes = Encoding.UTF8.GetBytes($"{c.Project_id}{c.Name}{c.Host}{c.Username}{c.Password}");
                System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                byte[] ret = md5.ComputeHash(logidbytes);
                foreach (byte b in ret)
                {
                    logid += b.ToString("X2").ToUpper();
                }

                _sql.CommandText =
                    $@"
INSERT INTO connections
(
	project_id,
	log_id,
	name,
	host_name,
	username,
	password,
	port,
	connection_protocol,
	authentication_method,
	keyfile_path,
	key_pass_phrase,
	use_stored_keys,
	SshHostKeyFingerprint,
	home_folder,
	proxy_settings,
	ssh_settings,
	tunnel_settings,
	ping_interval
)
VALUES
(
	'{c.Project_id}',
	'{logid}',
	'{c.Name}',
	'{c.Host}',
	'{c.Username}',
	'{c.Password}',
	'{c.Port}',
	'{c.Connection_protocol}',
	'{c.Authentication_method}',
	'{c.Keyfile_path}',
	'{c.Key_pass_phrase}',
	'{c.Use_stored_keys}',
	'{c.SshHostKeyFingerprint}',
	'{c.Home_folder}',
	'{c.Proxy_Settings}',
	'{c.Ssh_Settings}',
	'{c.Tunnel_Settings}',
	'{c.Ping_interval}'
);
";
                _sql.ExecuteNonQuery();
            }
        }
Beispiel #7
0
 private void loadConnectionData(c_ConnectionObject conn)
 {
 }