Exemple #1
0
        private void btnRunAutomation_Click(object sender, EventArgs e)
        {
            try
            {
                GetAccessLevel current = new GetAccessLevel();
                current.SessionKey = information.Token;
                current.Id         = servers[lstServerList.SelectedIndex].ServerOsId;

                string json = "";
                json = JsonConvert.SerializeObject(current);
                json = "=" + json;

                string path = "";
                path = information.URL + "/api/protectedAccount/get";

                string           response = ApiConnector.SendToApi(path, json);
                ProtectedAccount acc      = JsonConvert.DeserializeObject <ProtectedAccount>(response);

                SshClient currentSession = new SshClient(servers[lstServerList.SelectedIndex].ServerIp, 22, acc.Username, acc.Password);
                currentSession.Connect();

                // get the automation script!
                currentSession.RunCommand(currentAutomation[cmbAutomationList.SelectedIndex].ScriptText);

                // close session
                currentSession.Disconnect();

                // show success message box!
                MessageBox.Show("Successfully Completed Automation!");
            }
            catch (Exception ex)
            {
                MessageBox.Show("An Error Occorred Running this automation for more info: " + ex);
            }
        }
Exemple #2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            //Decide if the server is SSH or VNC
            if (servers[lstServerList.SelectedIndex].ServerOsId == 3 || servers[lstServerList.SelectedIndex].ServerOsId == 4 || servers[lstServerList.SelectedIndex].ServerOsId == 5 || servers[lstServerList.SelectedIndex].ServerOsId == 6)
            {
                try
                {
                    // Start SSH session
                    GetAccessLevel current = new GetAccessLevel();
                    current.SessionKey = information.Token;
                    current.Id         = servers[lstServerList.SelectedIndex].ServerOsId;

                    string json = "";
                    json = JsonConvert.SerializeObject(current);
                    json = "=" + json;

                    string path = "";
                    path = information.URL + "/api/protectedAccount/get";

                    string           response = ApiConnector.SendToApi(path, json);
                    ProtectedAccount acc      = JsonConvert.DeserializeObject <ProtectedAccount>(response);

                    SshSessionDetails details = new SshSessionDetails
                    {
                        ServerIp = servers[lstServerList.SelectedIndex].ServerIp,
                        Port     = 22,
                        Username = acc.Username,
                        Password = acc.Password
                    };

                    SshConnectionForm sshCon = new SshConnectionForm(details, information);
                    sshCon.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error connecting to server. Check the server is on.");
                }
            }
            else
            {
                // Start VNC session
                try
                {
                    GetAccessLevel current = new GetAccessLevel();
                    current.SessionKey = information.Token;
                    current.Id         = servers[lstServerList.SelectedIndex].ServerOsId;

                    string json = "";
                    json = JsonConvert.SerializeObject(current);
                    json = "=" + json;

                    string path = "";
                    path = information.URL + "/api/protectedAccount/get";

                    string           response = ApiConnector.SendToApi(path, json);
                    ProtectedAccount acc      = JsonConvert.DeserializeObject <ProtectedAccount>(response);

                    SshSessionDetails details = new SshSessionDetails
                    {
                        ServerIp = servers[lstServerList.SelectedIndex].ServerIp,
                        Port     = 22,
                        Username = acc.Username,
                        Password = acc.Password
                    };

                    VncWindow rdp = new VncWindow(details, information);
                    rdp.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error connecting to server. Check the server is on.");
                }
            }
        }