示例#1
0
 public override void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         string[] commands = UserInput.Split(" ");
         if (commands.Length != 2 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
         {
             menuItem.PrintInvalidOptionError(UserInput);
             EliteConsole.PrintFormattedErrorLine("Usage: Delete <username>");
             return;
         }
         List <CovenantUser> Users = ((UsersMenuItem)menuItem).Users;
         CovenantUser        user  = Users.FirstOrDefault(U => U.UserName == commands[1]);
         if (user != null)
         {
             EliteConsole.PrintFormattedWarning("Delete user: \"" + commands[1] + "\"? [y/N] ");
             string input = EliteConsole.Read();
             if (input.StartsWith("y", StringComparison.OrdinalIgnoreCase))
             {
                 this.CovenantClient.ApiUsersByIdDelete(user.Id);
             }
         }
         else
         {
             EliteConsole.PrintFormattedErrorLine("User: \"" + commands[1] + "\" does not exist.");
         }
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
示例#2
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenuItem = (GruntsMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "hide")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (commands[1].ToLower() == "all")
            {
                gruntsMenuItem.HiddenGruntNames.AddRange(gruntsMenuItem.Grunts.Select(G => G.Name));
            }
            Grunt grunt = gruntsMenuItem.Grunts.FirstOrDefault(G => G.Name == commands[1]);

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Invalid GruntName: \"" + commands[1] + "\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            EliteConsole.PrintFormattedWarning("Hide Grunt: " + commands[1] + "? [y/N] ");
            string input = EliteConsole.Read();

            if (!input.ToLower().StartsWith("y"))
            {
                return;
            }
            gruntsMenuItem.HiddenGruntNames.Add(grunt.Name);
        }
示例#3
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            UsersMenuItem usersMenuItem = (UsersMenuItem)menuItem;

            usersMenuItem.Refresh();
            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "delete")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                EliteConsole.PrintFormattedErrorLine("Usage: Delete <username>");
                return;
            }

            CovenantUser user = usersMenuItem.Users.FirstOrDefault(U => U.UserName == commands[1]);

            if (user != null)
            {
                EliteConsole.PrintFormattedWarning("Delete user: \"" + commands[1] + "\"? [y/N] ");
                string input = EliteConsole.Read();
                if (input.ToLower().StartsWith("y"))
                {
                    this.CovenantClient.ApiUsersByUidDelete(user.Id);
                }
            }
            else
            {
                EliteConsole.PrintFormattedErrorLine("User: \"" + commands[1] + "\" does not exist.");
            }
        }
示例#4
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenuItem = (GruntsMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "kill")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (commands[1].ToLower() == "all")
            {
                EliteConsole.PrintFormattedWarning("Kill all Grunts? [y/N] ");
                string input1 = EliteConsole.Read();
                if (!input1.ToLower().StartsWith("y"))
                {
                    return;
                }
                gruntsMenuItem.HiddenGruntNames.AddRange(gruntsMenuItem.Grunts.Select(G => G.Name));
                foreach (Grunt g in gruntsMenuItem.Grunts)
                {
                    GruntTasking gt = new GruntTasking {
                        Type = GruntTaskingType.Kill, GruntId = g.Id
                    };
                    this.CovenantClient.ApiGruntsByIdTaskingsPost(g.Id ?? default, gt);
                }
            }
            Grunt grunt = gruntsMenuItem.Grunts.FirstOrDefault(G => G.Name == commands[1]);

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Invalid GruntName: \"" + commands[1] + "\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            EliteConsole.PrintFormattedWarning("Kill Grunt: " + commands[1] + "? [y/N] ");
            string input2 = EliteConsole.Read();

            if (!input2.ToLower().StartsWith("y"))
            {
                return;
            }
            GruntTasking gruntTasking = new GruntTasking {
                Type = GruntTaskingType.Kill, GruntId = grunt.Id
            };

            this.CovenantClient.ApiGruntsByIdTaskingsPost(grunt.Id ?? default, gruntTasking);
        }
示例#5
0
        public override async void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                string[] commands = UserInput.Split(" ");
                if (commands.Length != 1 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
                {
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }
                HttpListener HttpListener = ((HTTPListenerMenuItem)menuItem).HttpListener;
                if ((HttpListener.UseSSL ?? default) && (string.IsNullOrEmpty(HttpListener.SslCertHash) || string.IsNullOrEmpty(HttpListener.SslCertificate)))
                {
                    EliteConsole.PrintWarning("No SSLCertificate specified. Would you like to generate and use a self-signed certificate? [y/N] ");
                    string input = EliteConsole.Read();
                    if (input.StartsWith("y", StringComparison.OrdinalIgnoreCase))
                    {
                        X509Certificate2 certificate = Utilities.CreateSelfSignedCertificate(HttpListener.BindAddress);

                        string autopath = "httplistener-" + HttpListener.Id + "-certificate.pfx";
                        File.WriteAllBytes(
                            Path.Combine(Common.EliteDataFolder, autopath),
                            certificate.Export(X509ContentType.Pfx, HttpListener.SslCertificatePassword)
                            );
                        EliteConsole.PrintFormattedHighlightLine("Certificate written to: " + autopath);
                        EliteConsole.PrintFormattedWarningLine("(Be sure to disable certificate validation on Launchers/Grunts using this self-signed certificate)");
                        menuItem.AdditionalOptions.FirstOrDefault(O => O.Name == "Set").Command(menuItem, "Set SSLCertPath " + autopath);
                        menuItem.Refresh();
                        HttpListener = ((HTTPListenerMenuItem)menuItem).HttpListener;
                    }
                    else
                    {
                        EliteConsole.PrintFormattedErrorLine("Must specify an SSLCertfiicate to Start an HTTP Listener with SSL.");
                        return;
                    }
                }
                HttpListener.Status = ListenerStatus.Active;
                await this.CovenantClient.ApiListenersHttpPutAsync(HttpListener);

                ((HTTPListenerMenuItem)menuItem).RefreshHTTPTemplate();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
示例#6
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            HTTPListenerMenuItem httpListenerMenuItem = (HTTPListenerMenuItem)menuItem;

            // TODO: error if http lsitener already on this port
            if ((httpListenerMenuItem.httpListener.UseSSL ?? default) && (httpListenerMenuItem.httpListener.SslCertHash == "" || httpListenerMenuItem.httpListener.SslCertificate == ""))
            {
                EliteConsole.PrintWarning("No SSLCertificate specified. Would you like to generate and use a self-signed certificate? [y/N] ");
                string input = EliteConsole.Read();
                if (input.ToLower().StartsWith("y"))
                {
                    X509Certificate2 certificate = Utilities.CreateSelfSignedCertificate(httpListenerMenuItem.httpListener.BindAddress);

                    string autopath = "httplistener-" + httpListenerMenuItem.httpListener.Id + "-certificate.pfx";
                    File.WriteAllBytes(Path.Combine(Common.EliteDataFolder, autopath),
                                       certificate.Export(X509ContentType.Pfx, httpListenerMenuItem.httpListener.SslCertificatePassword));
                    EliteConsole.PrintFormattedInfoLine("Certificate written to: " + autopath);
                    httpListenerMenuItem.AdditionalOptions.FirstOrDefault(O => O.Name == "Set").Command(httpListenerMenuItem, "Set SSLCertPath " + autopath);
                }
                else
                {
                    EliteConsole.PrintFormattedErrorLine("Must specify an SSLCertfiicate to Start an HTTP Listener with SSL.");
                    return;
                }
            }
            httpListenerMenuItem.Refresh();
            httpListenerMenuItem.httpListener.Status = ListenerStatus.Active;
            httpListenerMenuItem.httpListener        = this.CovenantClient.ApiListenersHttpPut(httpListenerMenuItem.httpListener);

            EventModel eventModel = new EventModel {
                Message = "Started HTTP Listener: " + httpListenerMenuItem.httpListener.Name + " at: " + httpListenerMenuItem.httpListener.Url,
                Level   = EventLevel.Highlight,
                Context = "*"
            };

            eventModel = this.CovenantClient.ApiEventsPost(eventModel);
            this.EventPrinter.PrintEvent(eventModel);
            httpListenerMenuItem.RefreshHTTPTemplate();
            httpListenerMenuItem.Refresh();
        }
示例#7
0
        public bool PrintMenu(string UserInput = "")
        {
            try
            {
                if (UserInput != "")
                {
                    MenuItem currentMenuItem = this.GetCurrentMenuItem();
                    if (UserInput.ToLower() == "back")
                    {
                        if (this.MenuStack.Count > 1)
                        {
                            currentMenuItem.LeavingMenuItem();
                            this.MenuStack.RemoveAt(this.MenuStack.Count - 1);
                            currentMenuItem = this.GetCurrentMenuItem();
                            currentMenuItem.ValidateMenuParameters(new string[] {}, false);
                        }
                        else
                        {
                            currentMenuItem.PrintInvalidOptionError(UserInput);
                        }
                    }
                    else if (UserInput.ToLower() == "exit")
                    {
                        EliteConsole.PrintFormattedWarning("Exit Elite console? [y/N] ");
                        string input = EliteConsole.Read();
                        if (input.ToLower().StartsWith("y"))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        MenuItem newMenuLevelItem = currentMenuItem.GetMenuOption(UserInput);
                        if (newMenuLevelItem != null)
                        {
                            this.MenuStack.Add(newMenuLevelItem);
                            newMenuLevelItem.PrintMenu();
                        }
                        else
                        {
                            MenuCommand menuCommandOption = currentMenuItem.GetMenuCommandOption(UserInput);
                            if (menuCommandOption != null)
                            {
                                menuCommandOption.Command(currentMenuItem, UserInput);
                            }
                            else
                            {
                                currentMenuItem.PrintInvalidOptionError(UserInput);
                            }
                        }
                    }
                    currentMenuItem = this.GetCurrentMenuItem();
                    ReadLine.AutoCompletionHandler = currentMenuItem.TabCompletionHandler;
                }
                this.PrintMenuLevel();

                return(true);
            }
            catch (HttpRequestException)
            {
                EliteConsole.PrintFormattedWarning("Covenant has disconnected. Quit? [y/N] ");
                string input = EliteConsole.Read();
                if (input.ToLower().StartsWith('y'))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                EliteConsole.PrintFormattedErrorLine("EliteMenu Exception: " + e.Message);
                EliteConsole.PrintErrorLine(e.StackTrace);
                this.PrintMenuLevel();
                return(true);
            }
            this.PrintMenuLevel();
            return(true);
        }
示例#8
0
        public override async void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenuItem = (GruntsMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || !commands[0].Equals("kill", StringComparison.OrdinalIgnoreCase))
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (commands[1].Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                EliteConsole.PrintFormattedWarning("Kill all Grunts? [y/N] ");
                string input1 = EliteConsole.Read();
                if (!input1.StartsWith("y", StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                foreach (Grunt g in gruntsMenuItem.Grunts)
                {
                    GruntTasking gt = new GruntTasking
                    {
                        Id             = 0,
                        GruntId        = g.Id,
                        TaskId         = 1,
                        Name           = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10),
                        Status         = GruntTaskingStatus.Uninitialized,
                        Type           = GruntTaskingType.Kill,
                        TaskingCommand = UserInput,
                        TokenTask      = false
                    };
                    try
                    {
                        await this.CovenantClient.ApiGruntsByIdTaskingsPostAsync(g.Id ?? default, gt);
                    }
                    catch (HttpOperationException e)
                    {
                        EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
                    }
                }
                return;
            }
            Grunt grunt = gruntsMenuItem.Grunts.FirstOrDefault(G => G.Name == commands[1]);

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Invalid GruntName: \"" + commands[1] + "\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            EliteConsole.PrintFormattedWarning("Kill Grunt: " + commands[1] + "? [y/N] ");
            string input2 = EliteConsole.Read();

            if (!input2.StartsWith("y", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            GruntTasking gruntTasking = new GruntTasking
            {
                Id             = 0,
                GruntId        = grunt.Id,
                TaskId         = 1,
                Name           = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10),
                Status         = GruntTaskingStatus.Uninitialized,
                Type           = GruntTaskingType.Kill,
                TaskingCommand = UserInput,
                TokenTask      = false
            };

            try
            {
                await this.CovenantClient.ApiGruntsByIdTaskingsPostAsync(grunt.Id ?? default, gruntTasking);
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }