Exemplo n.º 1
0
        //*************************************************************************************************************
        private void OnLoad(object sender, EventArgs e)
        {
            if (server.Port == 0)
            {
                server.Port = 22;
            }

            SuspendLayout();

            PuttyAppPanel.PuttyAppStartedCallback startedCallback = delegate()
            {
                BeginInvoke((MethodInvoker) delegate
                {
                    statusLabel.Visible    = false;
                    loadingCircle1.Visible = false;
                    puttyPanel.Visible     = true;
                });
            };

            PuttyAppPanel.PuttyAppClosedCallback closedCallback = delegate(bool closed)
            {
                BeginInvoke((MethodInvoker) delegate
                {
                    ((KRBTabControl)(Parent.Parent)).TabPages.Remove((TabPageEx)Parent);
                    DeletePuttySession();
                });
            };

            puttyPanel                       = new PuttyAppPanel(Main.config.GetValue("SSH_CORRECT_FOCUS").ToBoolOrDefault(true));
            puttyPanel.Parent                = this;
            puttyPanel.Dock                  = System.Windows.Forms.DockStyle.Fill;
            puttyPanel.ApplicationCommand    = @"putty\putty.exe";
            puttyPanel.ApplicationParameters = string.Empty;
            puttyPanel.Name                  = "puttyPanel";
            puttyPanel.Margin                = new Padding(10);
            puttyPanel.TabIndex              = 0;
            puttyPanel.StartedCallback       = startedCallback;
            puttyPanel.ClosedCallback        = closedCallback;
            puttyPanel.Visible               = false;
            Controls.Add(puttyPanel);

            ResumeLayout();
        }
Exemplo n.º 2
0
        //*************************************************************************************************************
        public void Connect()
        {
            // Auto accept the host key
            // using putty is starting to be complicated
            // but there is no real alternative
            // if we try to avoid some focus problems, we need to auto accept host keys
            if (Main.config.GetValue("SSH_ACCEPT_KEYS").ToBoolOrDefault(true))
            {
                try
                {
                    System.Diagnostics.ProcessStartInfo procStartInfo =
                        new System.Diagnostics.ProcessStartInfo("cmd", $"/c echo y | putty\\plink -ssh {server.Username}@{server.Host} -P {server.Port} \"exit\"");

                    procStartInfo.RedirectStandardOutput = true;
                    procStartInfo.UseShellExecute        = false;
                    procStartInfo.CreateNoWindow         = true;
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();
                    proc.StartInfo = procStartInfo;
                    proc.Start();
                    //string result = proc.StandardOutput.ReadToEnd();
                }
                catch
                {
                    // do nothing, yes do nothing
                    // putty will ask for the key acceptance
                }
            }

            PuttyAppPanel.PuttyAppStartedCallback startedCallback = delegate()
            {
                BeginInvoke((MethodInvoker) delegate
                {
                    loadingCircle1.Visible = false;
                    loadingCircle1.Active  = false;
                    statusLabel.Visible    = false;
                    puttyPanel.Visible     = true;
                });
            };

            PuttyAppPanel.PuttyAppClosedCallback closedCallback = delegate(bool closed)
            {
                try
                {
                    BeginInvoke((MethodInvoker) delegate
                    {
                        ((KRBTabControl)(Parent.Parent)).TabPages.Remove((TabPageEx)Parent);
                        DeletePuttySession();
                    });
                }
                catch
                {
                    // yeah yeah! it will have to do
                }
            };

            puttyPanel.StartedCallback = startedCallback;
            puttyPanel.ClosedCallback  = closedCallback;

            loadingCircle1.Active            = true;
            loadingCircle1.InnerCircleRadius = 15;
            loadingCircle1.OuterCircleRadius = 30;
            loadingCircle1.SpokeThickness    = 5;
            loadingCircle1.Top     = (this.Height / 2) + 10;
            loadingCircle1.Left    = (this.Width / 2) - 40;
            loadingCircle1.Visible = true;
            loadingCircle1.BringToFront();
            SetStatusText("Connecting...");

            if (File.Exists("putty\\putty.exe"))
            {
                CreatePuttySession();
                puttyPanel.ApplicationParameters = string.Format(" -load \"{4}\" {0} -P {5} -l {1} -pw {2} {3}",
                                                                 server.Host,
                                                                 server.Username,
                                                                 server.Password,
                                                                 (server.SSH1) ? "-1" : "-2",
                                                                 string.Format("XwRemote{0}", server.ID),
                                                                 server.Port);

                ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectTrd), this);
            }
            else
            {
                loadingCircle1.Visible = false;
                SetStatusText("Putty not found");
            }
        }