예제 #1
0
        private void InitAdvancedTab()
        {
            IocProperties p = m_ioc.Properties;
            Dictionary <string, List <IocPropertyInfo> > dProps = GetPropertyInfos();

            const int d         = 7;
            int       hLabel    = m_lblUrl.Height;
            int       hTextBox  = m_tbUrl.Height;
            int       hComboBox = m_cmbCredSaveMode.Height;
            Font      f         = m_lblUrl.Font;

            Debug.Assert(m_pnlAdv.AutoScroll);
            m_pnlAdv.AutoScrollMargin = new Size(1, d);

            int wPanel = m_pnlAdv.ClientSize.Width - UIUtil.GetVScrollBarWidth() - 1;
            int wGroup = wPanel - (2 * d);
            int wCell  = (wPanel - (3 * d)) / 2;
            int xText  = d - 1;
            int xInput = d + wCell + d - 1;
            int xGroup = xText;

            if (this.RightToLeft == RightToLeft.Yes)
            {
                int iTemp = xText;
                xText  = xInput;
                xInput = iTemp;
            }

            int y   = 1;
            int iID = 0;

            m_pnlAdv.SuspendLayout();

            foreach (KeyValuePair <string, List <IocPropertyInfo> > kvp in dProps)
            {
                string strGroup = kvp.Key;
                y += d;

                Label lblGroup = new Label();
                lblGroup.Name = "cGroup" + iID.ToString(NumberFormatInfo.InvariantInfo);
                ++iID;
                lblGroup.AutoEllipsis = true;
                lblGroup.AutoSize     = false;
                lblGroup.Dock         = DockStyle.None;
                lblGroup.Location     = new Point(xGroup, y);
                lblGroup.Size         = new Size(wGroup, hLabel);
                lblGroup.Text         = strGroup;
                lblGroup.TextAlign    = ContentAlignment.MiddleLeft;
                // lblGroup.BackColor = Color.Red;
                FontUtil.AssignDefaultBold(lblGroup);

                m_pnlAdv.Controls.Add(lblGroup);
                y += hLabel;

                foreach (IocPropertyInfo pi in kvp.Value)
                {
                    string strName = pi.Name;
                    string strText = pi.DisplayName + ":";
                    Type   t       = pi.Type;
                    y += d;

                    int hText = hLabel;
                    int wRem  = TextRenderer.MeasureText(strText, f).Width;
                    while (wRem >= wCell)
                    {
                        hText += (hLabel + 1);
                        wRem  -= wCell;
                    }

                    Label lblText = new Label();
                    lblText.Name = "cText" + iID.ToString(NumberFormatInfo.InvariantInfo);
                    ++iID;
                    lblText.AutoEllipsis = true;
                    lblText.AutoSize     = false;
                    lblText.Dock         = DockStyle.None;
                    lblText.Size         = new Size(wCell, hText);
                    lblText.Text         = strText;
                    lblText.TextAlign    = ContentAlignment.MiddleLeft;
                    // lblText.BackColor = Color.Green;

                    Control cInput = null;
                    if ((t == typeof(string)) || (t == typeof(long)))
                    {
                        TextBox tb = new TextBox();
                        tb.Size = new Size(wCell, hTextBox);

                        tb.Text = (p.Get(strName) ?? string.Empty);

                        cInput = tb;
                    }
                    else if (t == typeof(bool))
                    {
                        ComboBox cmb = new ComboBox();
                        cmb.DropDownStyle = ComboBoxStyle.DropDownList;
                        cmb.Size          = new Size(wCell, hComboBox);

                        cmb.Items.Add(KPRes.Auto);
                        cmb.Items.Add(KPRes.Yes);
                        cmb.Items.Add(KPRes.No);

                        bool?ob = p.GetBool(strName);
                        if (ob.HasValue)
                        {
                            cmb.SelectedIndex = (ob.Value ? 1 : 2);
                        }
                        else
                        {
                            cmb.SelectedIndex = 0;
                        }

                        cInput = cmb;
                    }
                    else
                    {
                        Debug.Assert(false); continue;
                    }

                    cInput.Dock = DockStyle.None;
                    cInput.Name = "cInput" + iID.ToString(NumberFormatInfo.InvariantInfo);
                    ++iID;

                    int hDiff = lblText.Height - cInput.Height;
                    if (hDiff >= 0)
                    {
                        lblText.Location = new Point(xText, y);
                        cInput.Location  = new Point(xInput, y + (hDiff / 2));

                        y += lblText.Height;
                    }
                    else
                    {
                        lblText.Location = new Point(xText, y - (hDiff / 2));
                        cInput.Location  = new Point(xInput, y);

                        y += cInput.Height;
                    }

                    m_pnlAdv.Controls.Add(lblText);
                    m_pnlAdv.Controls.Add(cInput);

                    m_lProps.Add(new KeyValuePair <IocPropertyInfo, Control>(
                                     pi, cInput));
                }
            }

            m_pnlAdv.ResumeLayout(true);
        }
예제 #2
0
        public override WebResponse GetResponse()
        {
            NetworkCredential cred        = (m_cred as NetworkCredential);
            string            strUser     = ((cred != null) ? cred.UserName : null);
            string            strPassword = ((cred != null) ? cred.Password : null);

            BaseClient m_Client = null;

            int l_port = m_uri.Port == -1 ? 22 : m_uri.Port;

            Uri uriTo = null;

            if (m_strMethod == IOConnection.WrmMoveFile)
            {
                uriTo = new Uri(m_whcHeaders.Get(IOConnection.WrhMoveFileTo));
            }

            MemoryStream reqStream = null;

            if (m_reqBody.Count > 0)
            {
                reqStream = new MemoryStream(m_reqBody.ToArray());
            }



            KeyboardInteractiveAuthenticationMethod v_kauth = new KeyboardInteractiveAuthenticationMethod(strUser);

            v_kauth.AuthenticationPrompt += SftpWebRequest_AuthenticationPrompt;
            PasswordAuthenticationMethod v_pauth = new PasswordAuthenticationMethod(strUser, strPassword);

            ConnectionInfo n_con_info = new ConnectionInfo(m_uri.Host, l_port, strUser, v_pauth, v_kauth);

            m_Client = new SftpClient(n_con_info);

            if (m_props.Get("HostKey") != null)
            {
                string[] v_ssh_dss_parts = m_props.Get("HostKey").Split(':');
                if (v_ssh_dss_parts.Length != 16)
                {
                    throw new Exception("Input incorrect host fingerprint. Check it. Must bu like: 12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef");
                }
                List <byte> v_ssh_dss_parts_b = new List <byte>();
                foreach (string str in v_ssh_dss_parts)
                {
                    try
                    {
                        v_ssh_dss_parts_b.Add(byte.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier));
                    }
                    catch (Exception)
                    {
                        throw new Exception("Input incorrect host fingerprint. Check it. Must bu like: 12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef");
                    }
                }
                m_fingerprint             = v_ssh_dss_parts_b.ToArray();
                m_Client.HostKeyReceived += M_Client_HostKeyReceived;
            }

            Console.WriteLine("Request: " + m_strMethod + ", " + m_uri.AbsoluteUri);
            return(new SftpWebResponse(m_Client, m_strMethod, m_uri, uriTo, reqStream));
        }
예제 #3
0
        public override WebResponse GetResponse()
        {
            NetworkCredential cred        = (m_cred as NetworkCredential);
            string            strUser     = ((cred != null) ? cred.UserName : null);
            string            strPassword = ((cred != null) ? cred.Password : null);

            BaseClient m_Client = null;

            int l_port = m_uri.Port == -1 ? 22 : m_uri.Port;

            Uri uriTo = null;

            if (m_strMethod == KeePassLib.Serialization.IOConnection.WrmMoveFile)
            {
                uriTo = new Uri(m_whcHeaders.Get(
                                    IOConnection.WrhMoveFileTo));
            }

            MemoryStream reqStream = null;

            if (m_reqBody.Count > 0)
            {
                reqStream = new MemoryStream(m_reqBody.ToArray());
            }

            ConnectionInfo n_con_info;

            if (File.Exists(m_props.Get("SSHKey")))
            {
                using (FileStream keyStream = new FileStream(m_props.Get("SSHKey"), FileMode.Open))
                {
                    PrivateKeyFile v_keyauth;

                    if (strPassword == null)
                    {
                        v_keyauth = new PrivateKeyFile(keyStream);
                    }
                    else
                    {
                        v_keyauth = new PrivateKeyFile(keyStream, strPassword);
                    }

                    n_con_info = new PrivateKeyConnectionInfo(m_uri.Host, l_port, strUser, v_keyauth);
                }
            }
            else if (!String.IsNullOrWhiteSpace(m_props.Get("SSHKey")))
            {
                string keyString = m_props.Get("SSHKey").Replace("\\n", "\n");
                using (MemoryStream keyStream = new MemoryStream(Encoding.ASCII.GetBytes(keyString)))
                {
                    PrivateKeyFile v_keyauth;

                    if (strPassword == null)
                    {
                        v_keyauth = new PrivateKeyFile(keyStream);
                    }
                    else
                    {
                        v_keyauth = new PrivateKeyFile(keyStream, strPassword);
                    }

                    n_con_info = new PrivateKeyConnectionInfo(m_uri.Host, l_port, strUser, v_keyauth);
                }
            }
            else if (String.IsNullOrWhiteSpace(m_props.Get("SSHKey")) &&
                     String.IsNullOrWhiteSpace(strPassword))
            {
                // No password, no keyfile, try pageant
                PageantProtocol agent = new PageantProtocol();
                n_con_info = new AgentConnectionInfo(m_uri.Host, l_port, strUser, agent);
            }
            else
            {
                KeyboardInteractiveAuthenticationMethod v_kauth = new KeyboardInteractiveAuthenticationMethod(strUser);
                v_kauth.AuthenticationPrompt += SftpWebRequest_AuthenticationPrompt;

                PasswordAuthenticationMethod v_pauth = new PasswordAuthenticationMethod(strUser, strPassword);
                n_con_info = new ConnectionInfo(m_uri.Host, l_port, strUser, v_pauth, v_kauth);
            }

            m_Client = new SftpClient(n_con_info);

            //Set timeout to reasonable setting of 30 seconds for default.
            int connectionTimeout = 30000;

            if (m_props.Get("SSHTimeout") != null)
            {
                int.TryParse(m_props.Get("SSHTimeout"), out connectionTimeout);
            }

            m_Client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 0, 0, connectionTimeout);

            if (m_props.Get("HostKey") != null)
            {
                string[] v_ssh_dss_parts = m_props.Get("HostKey").Split(':');
                if (v_ssh_dss_parts.Length != 16)
                {
                    throw new Exception("Input incorrect host fingerprint. Check it. Must look like: 12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef");
                }
                List <byte> v_ssh_dss_parts_b = new List <byte>();
                foreach (string str in v_ssh_dss_parts)
                {
                    try
                    {
                        v_ssh_dss_parts_b.Add(byte.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier));
                    }
                    catch (Exception)
                    {
                        throw new Exception("Input incorrect host fingerprint. Check it. Must look like: 12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef");
                    }
                }
                m_fingerprint             = v_ssh_dss_parts_b.ToArray();
                m_Client.HostKeyReceived += M_Client_HostKeyReceived;
            }

            return(new SftpWebResponse(m_Client, m_strMethod, m_uri, uriTo, reqStream));
        }