Exemplo n.º 1
0
        private bool ProcessInstructionInteracting(string instruction, string[] parts)
        {
            try
            {
                ClientLock.AcquireReaderLock(15 * 1000);

                try
                {
                    RevShellLock.AcquireReaderLock(15 * 1000);
                    if (IsRevShellActive)
                    {
                        Application.ExecInShell(Client, instruction);
                        return(true);
                    }
                }
                catch (ApplicationException)
                {
                    C.WriteLine("DeadLock ? ProcessInstructionInteracting");
                }
                finally
                {
                    RevShellLock.ReleaseReaderLock();
                }

                if (parts[0] == "ls")
                {
                    if (CurrentView == FileSystemView)
                    {
                        string basePath = FileSystemView.CurrentBasePath;
                        if (basePath == null)
                        {
                            Application.FetchFileSystemDrives(Client);
                        }
                        else
                        {
                            Application.FetchDirEntries(Client, basePath);
                        }
                    }
                    else
                    {
                        if (parts.Length == 1 || (parts.Length > 1 && parts[1].Trim().Equals("/")))
                        {
                            Application.FetchFileSystemDrives(Client);
                        }
                        else
                        {
                            string basePath = Path.GetFullPath(parts[1]);
                            Application.FetchDirEntries(Client, basePath);
                        }
                    }

                    return(true);
                }

                if (parts[0].Equals("sysinfo", StringComparison.OrdinalIgnoreCase))
                {
                    Application.FetchSystemInfo(Client);
                    return(true);
                }

                if (parts[0] == "fs")
                {
                    if (parts.Length == 1 ||
                        (parts.Length > 1 && parts[1].Equals("start", StringComparison.OrdinalIgnoreCase)))
                    {
                        CurrentView = FileSystemView;
                        FileSystemView.SetActiveClient(Application.GetClient(Client.Id));
                    }
                }
                else if (parts[0] == "ps")
                {
                    Application.FetchProcessList(Client);
                    return(true);
                }
                else if (instruction.Equals("desktop start", StringComparison.OrdinalIgnoreCase))
                {
                    bool shouldStart;

                    lock (IsDesktopActiveLock)
                    {
                        shouldStart = !IsDesktopActive;
                    }

                    if (shouldStart)
                    {
                        Application.StartDesktop(Client);
                    }

                    return(true);
                }
                else if (instruction.Equals("desktop stop", StringComparison.OrdinalIgnoreCase))
                {
                    lock (IsDesktopActiveLock)
                    {
                        if (IsDesktopActive)
                        {
                            IsDesktopActive = false;
                            Application.StopDesktop(Client);
                        }
                    }

                    return(true);
                }
                else if (parts[0] == "cd")
                {
                    if (parts.Length > 1)
                    {
                        if (CurrentView != FileSystemView)
                        {
                            CurrentView = FileSystemView;
                            FileSystemView.ChangeDirectory(parts[1]);
                            FileSystemView.Client = Client;
                        }
                    }
                }
                else if (parts[0] == "shell")
                {
                    try
                    {
                        RevShellLock.AcquireWriterLock(15 * 1000);
                        IsRevShellActive = true;
                    }
                    catch (ApplicationException)
                    {
                        C.WriteLine("DeadLock? RevShellLock.AcquireWriterLock");
                    }
                    finally
                    {
                        RevShellLock.ReleaseWriterLock();
                    }

                    Application.StartShell(Client);

                    return(true);
                }
            }
            catch (ApplicationException exception)
            {
                C.WriteLine("============================================================================");
                C.WriteLine("DeadLock? ConsoleUiMediator::ProcessInstructionInteracting AcquireReaderLock");
                C.WriteLine("============================================================================");
                return(false);
            }
            finally
            {
                ClientLock.ReleaseReaderLock();
            }

            return(false);
        }
Exemplo n.º 2
0
        private bool ProcessInstructionInteracting(string instruction, string[] parts)
        {
            try
            {
                ClientLock.AcquireReaderLock(15 * 1000);

                if (CurrentView == ShellView)
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Shell, Action = Action.Push, Data = string.Join(" ", parts)
                    });
                    return(true);
                }
                else if (parts[0] == "ls")
                {
                    if (CurrentView == FileSystemView)
                    {
                        string basePath = FileSystemView.CurrentBasePath;
                        if (basePath == null)
                        {
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start
                            });
                        }
                        else
                        {
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start, Data = basePath
                            });
                        }
                    }
                    else
                    {
                        if (parts.Length == 1 || (parts.Length > 1 && parts[1].Trim().Equals("/")))
                        {
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start
                            });
                        }
                        else
                        {
                            string basePath = Path.GetFullPath(parts[1]);
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.FileSystem, Action = Action.Start, Data = basePath
                            });
                        }
                    }

                    return(true);
                }
                else if (parts[0].Equals("sysinfo", StringComparison.OrdinalIgnoreCase))
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Information, Action = Action.Start
                    });

                    return(true);
                }
                else if (parts[0] == "fs")
                {
                    if (parts.Length == 1 ||
                        (parts.Length > 1 && parts[1].Equals("start", StringComparison.OrdinalIgnoreCase)))
                    {
                        CurrentView = FileSystemView;
                        FileSystemView.SetActiveClient(Client);
                    }
                }
                else if (parts[0] == "ps")
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Process, Action = Action.Start
                    });
                    return(true);
                }
                else if (parts[0] == "exec")
                {
                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Shell, Action = Action.Push
                    });
                    return(true);
                }
                else if (parts[0] == "shell")
                {
                    CurrentView = ShellView;
                    ShellView.SetActiveClient(Client);

                    AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                    {
                        Subject = Subject.Shell, Action = Action.Start
                    });
                    return(true);
                }
                else if (instruction.Equals("desktop start", StringComparison.OrdinalIgnoreCase))
                {
                    bool shouldStart;

                    lock (IsDesktopActiveLock)
                    {
                        shouldStart = !IsDesktopActive;
                    }

                    if (shouldStart)
                    {
                        AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                        {
                            Subject = Subject.Desktop, Action = Action.Start
                        });
                        return(true);
                    }

                    return(true);
                }
                else if (instruction.Equals("desktop stop", StringComparison.OrdinalIgnoreCase))
                {
                    lock (IsDesktopActiveLock)
                    {
                        if (IsDesktopActive)
                        {
                            IsDesktopActive = false;
                            AppUiChannel.SubmitToApp(new ClientAppEvent(Client)
                            {
                                Subject = Subject.Desktop, Action = Action.Stop
                            });
                        }
                    }

                    return(true);
                }
                else if (parts[0] == "cd")
                {
                    if (parts.Length > 1)
                    {
                        if (CurrentView != FileSystemView)
                        {
                            CurrentView = FileSystemView;
                            FileSystemView.ChangeDirectory(parts[1]);
                            FileSystemView.Client = Client;
                        }
                    }
                }
            }
            catch (ApplicationException exception)
            {
                C.WriteLine("============================================================================");
                C.WriteLine("DeadLock? ConsoleUiMediator::ProcessInstructionInteracting AcquireReaderLock");
                C.WriteLine("============================================================================");
                return(false);
            }
            finally
            {
                ClientLock.ReleaseReaderLock();
            }

            return(false);
        }