예제 #1
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (Ssh.isOpen())
     {
         Ssh.Close();
     }
     if (!Ssh.Open(
             textBoxSshIp.Text,
             textBoxSshLogin.Text,
             textBoxSshPassword.Text,
             textBoxSshBoundHost.Text,
             (uint)numericUpDownSshBoundPort.Value,
             textBoxSshHost.Text,
             (uint)numericUpDownSshPort.Value))
     {
         if (MessageBox.Show(
                 "Ошибка подключения по SSH:\n'" + Ssh.lastErrorMeassage + "'\nВсё равно сохранить?",
                 "Тестовое подключение по SSH",
                 MessageBoxButtons.YesNo,
                 MessageBoxIcon.Error) != DialogResult.Yes)
         {
             return;
         }
     }
     Properties.Settings.Default.SshIp        = Encryption.EncryptString(textBoxSshIp.Text);
     Properties.Settings.Default.SshLogin     = Encryption.EncryptString(textBoxSshLogin.Text);
     Properties.Settings.Default.SshPassword  = Encryption.EncryptString(textBoxSshPassword.Text);
     Properties.Settings.Default.SshBoundHost = textBoxSshBoundHost.Text;
     Properties.Settings.Default.SshBoundPort = (uint)numericUpDownSshBoundPort.Value;
     Properties.Settings.Default.SshHost      = textBoxSshHost.Text;
     Properties.Settings.Default.SshPort      = (uint)numericUpDownSshPort.Value;
     Properties.Settings.Default.Save();
     this.Close();
 }
예제 #2
0
        private void toolStripMenuItemSshChange_Click(object sender, EventArgs e)
        {
            Ssh.Close();
            FormSsh formSsh = new FormSsh();

            formSsh.ShowDialog();
        }
예제 #3
0
 private void toolStripMenuItemSshClose_Click(object sender, EventArgs e)
 {
     Ssh.Close();
 }
        /// <summary>
        /// Parse and execute command line
        /// </summary>
        /// <param name="commandLine">Falcon command line string</param>
        private void ExecuteCli(string commandLine)
        {
            // ignore empty command line
            if (commandLine == "")
            {
                PrintLinePrefix();
                return;
            }

            historyBuff.ResetNavigation();
            historyBuff.AddItem(commandLine);

            if (displayMode == DisplayMode.SSH)
            {
                ssh_.RunCommand(commandLine);
                if (commandLine == "exit")
                {
                    ssh_.Close();
                    PrintToScreen("ssh session terminated.", Color.White, true);
                    ssh_        = null;
                    displayMode = DisplayMode.NORMAL;
                }
                return;
            }

            Argument argumentObj  = null;
            string   reply        = "";
            string   parserAnswer = "";

            Command.Type cmdType = Command.Type.INVALID;
            bool         validCmd;

            validCmd = CommandParser.Parse(commandLine, ref parserAnswer, ref cmdType, ref argumentObj);

            if (validCmd)
            {
                switch (cmdType)
                {
                case Command.Type.PING:
                    string targetIp = ((PingArgument)argumentObj).GetIp();
                    int    timeout  = ((PingArgument)argumentObj).GetTimeout();

                    if (timeout != -1)     // use timeout
                    {
                        Pinger.Ping(targetIp, timeout, ref reply);
                    }
                    else     // disable timeout
                    {
                        Pinger.Ping(targetIp, 0, ref reply);
                    }

                    break;

                case Command.Type.SSH:
                    bool success = ConnectSsh(((SshArgument)argumentObj).GetHostAddress(),
                                              ((SshArgument)argumentObj).GetUserName(),
                                              ((SshArgument)argumentObj).GetPassword(),
                                              ref reply,
                                              ref ssh_);
                    if (success)
                    {
                        displayMode = DisplayMode.SSH;
                    }
                    break;

                case Command.Type.CLEAR:
                    cliDisplayTxtBx.Text = "";
                    break;

                case Command.Type.INVALID:
                    break;
                }
            }

            if (parserAnswer != "")
            {
                PrintToScreen(parserAnswer + "\n", Color.White, true);
            }
            if (reply != "")
            {
                PrintToScreen(reply + "\n", Color.White, true);
            }

            PrintLinePrefix();
        }