Esempio n. 1
0
        public bool PrintEvent(EventModel theEvent, string Context = "*")
        {
            lock (_EventLock)
            {
                if (ContextMatches(theEvent, Context))
                {
                    EliteConsole.PrintInfoLine();
                    switch (theEvent.Level)
                    {
                    case EventLevel.Highlight:
                        EliteConsole.PrintFormattedHighlightLine(theEvent.MessageHeader);
                        break;

                    case EventLevel.Info:
                        EliteConsole.PrintFormattedInfoLine(theEvent.MessageHeader);
                        break;

                    case EventLevel.Warning:
                        EliteConsole.PrintFormattedWarningLine(theEvent.MessageHeader);
                        break;

                    case EventLevel.Error:
                        EliteConsole.PrintFormattedErrorLine(theEvent.MessageHeader);
                        break;

                    default:
                        EliteConsole.PrintFormattedInfoLine(theEvent.MessageHeader);
                        break;
                    }
                    if (!string.IsNullOrWhiteSpace(theEvent.MessageBody))
                    {
                        EliteConsole.PrintInfoLine(theEvent.MessageBody);
                    }
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            CommandLineApplication app = new CommandLineApplication();

            app.HelpOption("-? | -h | --help");
            var UserNameOption = app.Option(
                "-u | --username <USERNAME>",
                "The UserName to login to the Covenant API.",
                CommandOptionType.SingleValue
                );
            var PasswordOption = app.Option(
                "-p | --password <PASSWORD>",
                "The Password to login to the Covenant API.",
                CommandOptionType.SingleValue
                );
            var HashOption = app.Option(
                "-h | --hash <HASH>",
                "The Covenant API certificate hash to trust.",
                CommandOptionType.SingleValue
                );
            var ComputerNameOption = app.Option(
                "-c | --computername <COMPUTERNAME>",
                "The ComputerName (IPAddress or Hostname) to bind the Covenant API to.",
                CommandOptionType.SingleValue
                );

            app.OnExecute(() =>
            {
                string username     = UserNameOption.Value();
                string password     = PasswordOption.Value();
                string computername = ComputerNameOption.Value();
                string hash         = HashOption.Value();
                try
                {
                    if (!ComputerNameOption.HasValue())
                    {
                        EliteConsole.PrintHighlight("Covenant ComputerName: ");
                        computername = EliteConsole.Read();
                    }

                    EliteConsole.PrintFormattedHighlightLine("Connecting to Covenant...");
                    Elite elite    = new Elite(new Uri("https://" + computername + ":7443"));
                    bool connected = elite.Connect();
                    if (!connected)
                    {
                        EliteConsole.PrintFormattedErrorLine("Could not connect to Covenant at: " + computername);
                        if (computername.ToLower() == "localhost" || computername == "127.0.0.1")
                        {
                            EliteConsole.PrintFormattedErrorLine("Are you using Docker? Elite cannot connect over the loopback address while using Docker, because Covenant is not running within the Elite docker container.");
                        }
                        return(-1);
                    }
                    if (!UserNameOption.HasValue())
                    {
                        EliteConsole.PrintHighlight("Username: "******"Password: "******"Covenant CertHash (Empty to trust all): ");
                        hash = EliteConsole.Read();
                    }
                    EliteConsole.PrintFormattedHighlightLine("Logging in to Covenant...");
                    bool login = elite.Login(username, password, hash);
                    if (login)
                    {
                        elite.Launch();
                        elite.CancelEventPoller.Cancel();
                    }
                    else
                    {
                        EliteConsole.PrintFormattedErrorLine("Covenant login failed. Check your username and password again.");
                        EliteConsole.PrintFormattedErrorLine("Incorrect password for user: "******"SocketException")
                {
                    EliteConsole.PrintFormattedErrorLine("Could not connect to Covenant at: " + computername);
                    if (computername.ToLower() == "localhost" || computername == "127.0.0.1")
                    {
                        EliteConsole.PrintFormattedErrorLine("Are you using Docker? Elite cannot connect over the loopback address while using Docker, because Covenant is not running within the Elite docker container.");
                    }
                    return(-1);
                }
                catch (HttpRequestException e) when(e.InnerException.GetType().Name == "AuthenticationException")
                {
                    EliteConsole.PrintFormattedErrorLine("Covenant certificate does not match: " + hash);
                    return(-2);
                }
                catch (HttpRequestException)
                {
                    EliteConsole.PrintFormattedErrorLine("Covenant login failed. Check your username and password again.");
                    EliteConsole.PrintFormattedErrorLine("Incorrect password for user: "******"Unknown Exception Occured: " + e.Message + Environment.NewLine + e.StackTrace);
                    return(-4);
                }
                return(0);
            });
            app.Execute(args);
        }