Esempio n. 1
0
        public static void MessageHandler(CmdOutput co)
        {
            if (co == null)
            {
                return;
            }
            var dm = GlobalSettings.Message.Where(a => a.MessageId == co.MessageId).Select(b => b).FirstOrDefault();

            if (dm == null)
            {
                return;
            }
            if (co.Message != null)
            {
                dm.MessageList.AddRange(co.Message);
                dm.MessageList = (from m in dm.MessageList group m by m.MessageId into gm select gm.OrderByDescending(a => a.TimeStamp).FirstOrDefault()).ToList();
            }
            dm.State = co.State;
            if (dm.State == CmdRunState.EXITWITHERROR || dm.State == CmdRunState.FINISHED || dm.State == CmdRunState.FINISHEDWITHWARNING || dm.State == CmdRunState.INVALID)
            {
                var tmpms = dm.MessageList.Where(a => a.MessageType == (int)MessageType.JOBNAME).FirstOrDefault();
                if (tmpms != null)
                {
                    tmpms.Message = tmpms.Message.Substring("Working on ".Length);
                    tmpms.Message = tmpms.Message.Substring(0, tmpms.Message.Length - 10);
                }
                GlobalSettings.AppState.isProcessingCommand = false;
                dm.End = DateTime.Now;
            }
            GlobalSettings.AppState.NotifyObserver();
        }
Esempio n. 2
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            // write to console
            CmdOutput.Invoke(new Action(() => CmdOutput.AppendText("Launching pipes...\r\n")));

            // save auth mode in application settings
            Properties.Settings.Default.authMode = authTabControl.SelectedTab.Name;

            // start service, authenticating to target machine as specified
            if (Properties.Settings.Default.authMode == "elevated")
            {
                paexecService.StartService(PAExecEXELocation.Text, TestComputer.Text, AdminUsername.Text,
                                           ElevatedAccountEXELocation.Text);
            }
            else
            {
                paexecService.StartService(PAExecEXELocation.Text, TestComputer.Text, AdminUsername.Text,
                                           userAuthTextbox.Text, passAuthTextbox.Text, ElevatedAccountEXELocation.Text);
            }

            // enable/disable buttons on gui
            KillButton.Enabled    = paexecService.IsRunning;
            ConnectButton.Enabled = !paexecService.IsRunning;
            ExecuteButton.Enabled = (CmdQueueListView.Items.Count > 0);
        }
Esempio n. 3
0
        public void Input(string cmd, CmdOutput callback = null, bool fullInfo = true)
        {
            _returnMsgs.Clear();

            _currentCallback = callback;
            _fullInfo        = fullInfo;

            _process.StandardInput.WriteLine(cmd);
            _process.StandardInput.WriteLine(CommandReturnCMD);
        }
Esempio n. 4
0
 private void StringFromClientHandler(object o, string e)
 {
     if (e.StartsWith("echo **HEARTBEAT"))
     {
         // do not print to cmd
     }
     else
     {
         CmdOutput.Invoke(new Action(() => CmdOutput.AppendText(e.ToString())));
     }
 }
Esempio n. 5
0
 private void KillButton_Click(object sender, EventArgs e)
 {
     // sends kill message to paexecService service
     paexecService.KillPipes();
     shouldSendCommands = false;
     CmdOutput.Invoke(new Action(() => CmdOutput.AppendText("\r\nKilling pipes...\r\n")));
     CmdOutput.Invoke(new Action(() => CmdOutput.AppendText("\r\nPipes killed.\r\n")));
     KillButton.Enabled    = false;
     ConnectButton.Enabled = true;
     ExecuteButton.Enabled = false;
 }
Esempio n. 6
0
        /// <summary>
        /// Begins the process of executing the commands that are "checked" in CmdQueueListView. <para/>
        /// Commands are sent to the remote computer via the PAExecService instance, and displayed in real time.
        /// </summary>
        private async void StartCmdQueue()
        {
            // because this is an asynchronous method, all access to the GUI thread (and its controls) must be through invokes.
            int numUnchecked = (int)CmdQueueListView.Invoke(new Func <int>(() => CmdQueueListView.Items.Count - CmdQueueListView.CheckedItems.Count));


            while (shouldSendCommands && CmdQueueListView.Items.Count > numUnchecked)
            {
                // is the item at top (index 0) of the queue checked?
                bool isChecked = (bool)CmdQueueListView.Invoke(new Func <bool>(() => CmdQueueListView.Items[0].Checked));

                if (isChecked)
                {
CheckIfConsoleAllowsInput:
                    string cmdText = (string)CmdOutput.Invoke(new Func <string>(() => CmdOutput.Text));
                    string endOfConsoleText = cmdText.Substring(cmdText.Length - Math.Min(10, cmdText.Length));
                    if (!endOfConsoleText.Contains('>'))
                    {
                        if (!shouldSendCommands)
                        {
                            break;
                        }                                   // stop endless loops if console dies
                        await Task.Delay(1000);

                        goto CheckIfConsoleAllowsInput; // check again after waiting
                    }

                    // send next command to the paexecService, remove from queue, then start over
                    string nextCmd = (string)CmdQueueListView.Invoke(new Func <string>(() => CmdQueueListView.Items[0].SubItems[1].Text.ToString()));
                    paexecService.WriteToClient(nextCmd.TrimEnd());
                    CmdQueueListView.Invoke(new Action(() => CmdQueueListView.Items.RemoveAt(0)));
                    await Task.Delay(500);

                    await Task.Run(() => StartCmdQueue());
                }
                else
                {
                    // if the command isn't checked, then move it to bottom of command queue
                    CmdQueueListView.Invoke(new Action(() => CmdQueueListView.Items.Add((ListViewItem)CmdQueueListView.Items[0].Clone())));
                    CmdQueueListView.Invoke(new Action(() => CmdQueueListView.Items.RemoveAt(0)));
                }
            }
            shouldSendCommands = false;
            StopExecutingButton.Invoke(new Action(() => StopExecutingButton.Enabled = false));
        }
Esempio n. 7
0
 public void RunCmd(string cmd, CmdOutput callback)
 {
     proxy.Input(cmd, callback);
 }