Ejemplo n.º 1
0
 public static Renci.SshNet.SshClient GetSSHConnection(SSHConnectionDetails sshConnection)
 {
     if (sshConnection.UseConnectionString)
     {
         SSHConnectionDetails.FromConnectionString(sshConnection);
     }
     return(GetSSHConnection(sshConnection.SSHSecurityOption, sshConnection.ComputerName, sshConnection.SSHPort, sshConnection.UserName, sshConnection.Password, sshConnection.PrivateKeyFile, sshConnection.PassPhrase));
 }
Ejemplo n.º 2
0
        public static SSHConnectionDetails FromConnectionString(string connectionString)
        {
            SSHConnectionDetails conn = new SSHConnectionDetails();

            conn.ConnectionString = connectionString;
            FromConnectionString(conn);
            return(conn);
        }
Ejemplo n.º 3
0
        public static void FromConnectionString(SSHConnectionDetails conn)
        {
            string sshConnectionString = conn.ConnectionString;

            if (sshConnectionString.Length > 0)
            {
                if (System.IO.File.Exists(sshConnectionString))
                {
                    sshConnectionString = System.IO.File.ReadAllText(sshConnectionString);
                }

                string[] pa = sshConnectionString.Split(';');
                foreach (string s in pa)
                {
                    if (s.ToLower().StartsWith("name="))
                    {
                        conn.ConnectionName = s.Substring("name=".Length);
                    }
                    if (s.ToLower().StartsWith("computer="))
                    {
                        string computerName = s.Substring("computer=".Length);
                        int    port         = 22;
                        if (computerName.Contains(':') && computerName.Split(':')[1].IsInteger())
                        {
                            port         = int.Parse(computerName.Split(':')[1]);
                            computerName = computerName.Split(':')[0];
                        }
                        conn.ComputerName = computerName;
                        conn.SSHPort      = port;
                    }
                    if (s.ToLower().StartsWith("secopt="))
                    {
                        conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(s.Substring("secopt=".Length));
                    }
                    if (s.ToLower().StartsWith("user="******"user="******"pass="******"pass="******"privatekeyfile="))
                    {
                        conn.PrivateKeyFile = s.Substring("privatekeyfile=".Length);
                    }
                    if (s.ToLower().StartsWith("passphrase="))
                    {
                        conn.PassPhrase = s.Substring("passphrase=".Length);
                    }
                    if (s.ToLower().StartsWith("persistent="))
                    {
                        conn.Persistent = FormatUtils.NBool(s.Substring("persistent=".Length));
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public SSHConnectionDetails Clone()
        {
            SSHConnectionDetails clone = new SSHConnectionDetails();

            clone.SSHSecurityOption   = SSHSecurityOption;
            clone.ComputerName        = ComputerName;
            clone.SSHPort             = SSHPort;
            clone.UserName            = UserName;
            clone.Password            = Password;
            clone.PrivateKeyFile      = PrivateKeyFile;
            clone.PassPhrase          = PassPhrase;
            clone.Persistent          = Persistent;
            clone.ConnectionName      = ConnectionName;
            clone.UseConnectionString = UseConnectionString;
            clone.ConnectionString    = ConnectionString;
            return(clone);
        }
Ejemplo n.º 5
0
        public static string FormatSSHConnection(SSHConnectionDetails connection)
        {
            string output = "";

            if (connection.ConnectionString != null && connection.ConnectionString.Length > 0 && !connection.ConnectionString.Contains(';'))
            {
                output = connection.ConnectionString;
            }
            else
            {
                output = string.Format("Name={0};Computer={1}:{2};SecOpt={3};User={4};Pass={5};PrivateKeyFile={6};PassPhrase={7};Persistent={8}",
                                       connection.ConnectionName,
                                       connection.ComputerName,
                                       connection.SSHPort,
                                       connection.SSHSecurityOption.ToString(),
                                       connection.UserName,
                                       connection.Password,
                                       connection.PrivateKeyFile,
                                       connection.PassPhrase,
                                       connection.Persistent ? "True" : "False");
            }

            //if (forDisplayOnly)
            //{
            //    if (connection.UseConnectionString && !connection.ConnectionString.Contains(';'))
            //    {
            //        output = connection.ConnectionString;
            //    }
            //    else
            //    {
            //        output = string.Format("Name={0};Computer={1}:{2};SecOpt={3};User={4};PrivateKeyFile={5};Persistent={6}",
            //            connection.ConnectionName,
            //            connection.ComputerName,
            //            connection.SSHPort,
            //            connection.SSHSecurityOption.ToString(),
            //            connection.UserName,
            //            connection.PrivateKeyFile,
            //            connection.Persistent ? "True" : "False");
            //    }
            //}
            //else
            //{
            //    if (connection.UseConnectionString)
            //    {
            //        output = connection.ConnectionString;
            //    }
            //    else
            //    {
            //        output = string.Format("Name={0};Computer={1}:{2};SecOpt={3};User={4};Pass={5};PrivateKeyFile={6};PassPhrase={7};Persistent={8}",
            //            connection.ConnectionName,
            //            connection.ComputerName,
            //            connection.SSHPort,
            //            connection.SSHSecurityOption.ToString(),
            //            connection.UserName,
            //            connection.Password,
            //            connection.PrivateKeyFile,
            //            connection.PassPhrase,
            //            connection.Persistent ? "True" : "False");
            //    }
            //}
            return(output);
        }
Ejemplo n.º 6
0
        public static SSHConnectionDetails FromXmlElement(System.Xml.XmlElement node)
        {
            SSHConnectionDetails conn = new SSHConnectionDetails();

            conn.UseConnectionString = node.ReadXmlElementAttr("useConnStr", false);
            conn.ConnectionString    = node.ReadXmlElementAttr("connStr", "");

            if (conn.ConnectionString.Length > 0) // conn.UseConnectionString)
            {
                //Parse ConnectionString
                FromConnectionString(conn);

                //string sshConnectionString = conn.ConnectionString;
                //if (sshConnectionString.Length > 0)
                //{
                //    if (System.IO.File.Exists(sshConnectionString))
                //    {
                //        sshConnectionString = System.IO.File.ReadAllText(sshConnectionString);
                //    }

                //    string[] pa = sshConnectionString.Split(';');
                //    foreach (string s in pa)
                //    {
                //        if (s.ToLower().StartsWith("name="))
                //        {
                //            conn.ConnectionName = s.Substring("name=".Length);
                //        }
                //        if (s.ToLower().StartsWith("computer="))
                //        {
                //            string computerName = s.Substring("computer=".Length);
                //            int port = 22;
                //            if (computerName.Contains(':') && computerName.Split(':')[1].IsInteger())
                //            {
                //                port = int.Parse(computerName.Split(':')[1]);
                //                computerName = computerName.Split(':')[0];
                //            }
                //            conn.ComputerName = computerName;
                //            conn.SSHPort = port;
                //        }
                //        if (s.ToLower().StartsWith("secopt="))
                //        {
                //            conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(s.Substring("secopt=".Length));
                //        }
                //        if (s.ToLower().StartsWith("user="******"user="******"pass="******"pass="******"privatekeyfile="))
                //        {
                //            conn.PrivateKeyFile = s.Substring("privatekeyfile=".Length);
                //        }
                //        if (s.ToLower().StartsWith("passphrase="))
                //        {
                //            conn.PassPhrase = s.Substring("passphrase=".Length);
                //        }
                //        if (s.ToLower().StartsWith("persistent="))
                //        {
                //            conn.Persistent = FormatUtils.NBool(s.Substring("persistent=".Length));
                //        }
                //    }
                //}
            }
            else
            {
                conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(node.ReadXmlElementAttr("sshSecOpt", "password"));
                conn.ComputerName      = node.ReadXmlElementAttr("machine", ".");
                conn.SSHPort           = node.ReadXmlElementAttr("sshPort", 22);
                conn.UserName          = node.ReadXmlElementAttr("userName", "");
                conn.Password          = node.ReadXmlElementAttr("password", "");
                conn.PrivateKeyFile    = node.ReadXmlElementAttr("privateKeyFile", "");
                conn.PassPhrase        = node.ReadXmlElementAttr("passPhrase", "");
                conn.Persistent        = node.ReadXmlElementAttr("persistent", false);
                conn.ConnectionName    = node.ReadXmlElementAttr("name", "");
                conn.ConnectionString  = FormatSSHConnection(conn);
            }
            //if (!conn.UseConnectionString || conn.ConnectionString.Length == 0)
            //{
            //    conn.SSHSecurityOption = SSHSecurityOptionTypeConverter.FromString(node.ReadXmlElementAttr("sshSecOpt", "password"));
            //    conn.ComputerName = node.ReadXmlElementAttr("machine", ".");
            //    conn.SSHPort = node.ReadXmlElementAttr("sshPort", 22);
            //    conn.UserName = node.ReadXmlElementAttr("userName", "");
            //    conn.Password = node.ReadXmlElementAttr("password", "");
            //    conn.PrivateKeyFile = node.ReadXmlElementAttr("privateKeyFile", "");
            //    conn.PassPhrase = node.ReadXmlElementAttr("passPhrase", "");
            //    conn.Persistent = node.ReadXmlElementAttr("persistent", false);
            //    conn.ConnectionName = node.ReadXmlElementAttr("name", "");
            //}

            return(conn);
        }