コード例 #1
0
        public SSHProxy(string server, int port, string sshServer, int sshPort, SshProxyCredentials sshCredentials)
        {
            this.Server         = server;
            this.Port           = port;
            this.SshServer      = sshServer;
            this.SshPort        = sshPort;
            this.SshCredentials = sshCredentials;

            _lastUsed = DateTime.Now;
        }
コード例 #2
0
ファイル: DbManager.cs プロジェクト: Dakicksoft/QueryTree
        public bool TryUseDbConnection(DatabaseConnection connection, Action <DbConnection> action, out string error)
        {
            string password = _passwordManager.GetSecret(SecretType.DatabasePassword.ToString() + "_" + connection.DatabaseConnectionID);
            SshProxyCredentials credentials = null;

            if (connection.UseSsh)
            {
                credentials = new SshProxyCredentials(_passwordManager, connection);
            }
            return(TryUseDbConnection(connection.Type, connection.Server, connection.Port, connection.UseSsh, connection.SshServer, connection.SshPort, credentials, connection.Username, password, connection.DatabaseName, action, out error));
        }
コード例 #3
0
ファイル: DbManager.cs プロジェクト: Dakicksoft/QueryTree
 public bool TryUseDbConnection(DatabaseType type, string server, int port, bool useSsh, string sshServer, int?sshPort, SshProxyCredentials credentials, string username, string password, string databaseName, out string error)
 {
     return(TryUseDbConnection(type, server, port, useSsh, sshServer, sshPort, credentials, username, password, databaseName, conn => { return; }, out error));
 }
コード例 #4
0
ファイル: DbManager.cs プロジェクト: Dakicksoft/QueryTree
        public bool TryUseDbConnection(DatabaseType type, string server, int port, bool useSsh, string sshServer, int?sshPort, SshProxyCredentials credentials, string username, string password, string databaseName, Action <DbConnection> action, out string error)
        {
            error = null;
            bool databaseAccessDenied = false;

            try
            {
                if (useSsh)
                {
                    return(SSHProxyManager.TryUseProxy(server, port, sshServer, sshPort.GetValueOrDefault(22), credentials,
                                                       proxy =>
                    {
                        using (var conn = GetDbConnection(type, proxy.ProxyServer, proxy.ProxyPort, username, password, databaseName))
                        {
                            action(conn);
                        }
                    }, out error));
                }
                else
                {
                    using (var conn = GetDbConnection(type, server, port, username, password, databaseName))
                    {
                        action(conn);
                        return(true);
                    }
                }
            }
            catch (MySqlException e)
            {
                if (e.InnerException != null && e.InnerException.Message != null && e.InnerException.Message.StartsWith("Access denied"))
                {
                    databaseAccessDenied = true;
                }
                else
                {
                    throw;
                }
            }
            catch (SqlException e)
            {
                error = e.Message;
            }
            catch (Exception e)
            {
                error = e.Message;
            }

            if (databaseAccessDenied)
            {
                error = string.Format("Access denied for user='******'. Please check username and password are correct.", username);
            }
            return(error == null);
        }
コード例 #5
0
        public static bool TryUseProxy(string server, int port, string sshServer, int sshPort, SshProxyCredentials credentials, Action <SSHProxy> action, out string error)
        {
            error = null;

            Initialize();

            SSHProxy proxy = null;

            if (TryAcquireExistingProxy(server, port, out proxy))
            {
                UseProxy(proxy, action);
                return(true);
            }
            else
            {
                proxy = new SSHProxy(server, port, sshServer, sshPort, credentials);

                lock (_lock)
                {
                    _proxies.Add(proxy);
                }

                Task.Run(() => proxy.Run());
                proxy.WaitUntilStarted();

                if (proxy.RequestUse())
                {
                    UseProxy(proxy, action);
                    return(true);
                }
                else
                {
                    error = proxy.Error;
                    return(false);
                }
            }
        }
コード例 #6
0
        public static bool TryUseProxy(IPasswordManager passwordManager, DatabaseConnection connection, Action <SSHProxy> action, out string error)
        {
            SshProxyCredentials credentials = new SshProxyCredentials(passwordManager, connection);

            return(TryUseProxy(connection.Server, connection.Port, connection.SshServer, connection.SshPort.GetValueOrDefault(22), credentials, action, out error));
        }
コード例 #7
0
 public static bool TryUseProxy(string server, int port, string sshServer, int sshPort, SshProxyCredentials credentials, DatabaseConnection connection, Action <SSHProxy> action, out string error)
 {
     return(TryUseProxy(server, port, sshServer, sshPort, credentials, action, out error));
 }