Esempio n. 1
0
        public static resultClass mono_command_args(string[] args)
        {
            resultClass   token = new resultClass();
            List <string> extra;

            var p = new OptionSet()
            {
                { "a|appsettings=", "Optional, point to alternate appsettings directory",
                  v => token.appsettings = v },
                { "t|get_token", "Fetch the bearer token from the CxSAST service",
                  v => token.api_action = api_action.getToken },
                { "c|store_credentials", "Store username and credential in an encrypted file",
                  v => token.api_action = api_action.storeCredentials },
                { "s|scan_results", "Get scan results, filtered by time and project",
                  v => token.api_action = api_action.scanResults },
                { "rn|report_name=", "Select desired report",
                  v => token.report_name = v },
                { "pn|project_name=", "Filter with project name, Will return project if any portion of the project name is a match",
                  v => token.project_name = v },
                { "tn|team_name=", "Filter with team name, Will return a team if any portion of the team name is a match",
                  v => token.team_name = v },
                { "ps|preset_name=", "Filter with preset name, Will return a preset if any portion of the team name is a match",
                  v => token.preset = v },
                { "pi|pipe", "Do not write to file but pipe output to stdout. Useful when using other API's",
                  v => token.pipe = true },
                { "path|file_path=", "Override file path in configuration",
                  v => token.file_path = v },
                { "file|file_name=", "Override file name in configuration",
                  v => token.file_name = v },
                { "sf|severity_filter=", "Filter results by Severity",
                  v => token.severity_filter = v },
                { "sr|save_result=", "Enable saving of results as XML",
                  v => token.save_result = v },
                { "srp|save_result_path=", "Override save result path in configuration",
                  v => token.save_result_path = v },
                { "u|user_name=", "The username to use to retreive the token (REST) or session (SOAP)",
                  v => token.user_name = v },
                { "p|password="******"The password needed to retreive the token (REST) or session (SOAP)",
                  v => token.credential = v },
                { "st|start_time=", "Last scan start time",
                  v => token.start_time = DateTime.Parse(v) },
                { "et|end_time=", "Last scan end time",
                  v => token.end_time = DateTime.Parse(v) },
                //add proxy stuff
                { "up|use_proxy", "Use web proxy",
                  v => token.use_proxy = true },
                { "ud|proxy_use_default", "Use default credentials",
                  v => token.proxy_use_default = true },
                { "pu|proxy_user_name=", "Proxy User Name",
                  v => token.proxy_username = v },
                { "pp|proxy_password="******"Proxy Password",
                  v => token.proxy_password = v },
                { "pd|proxy_domain=", "Proxy Domain",
                  v => token.proxy_domain = v },
                //proxy
                { "v|verbose=", "Change degrees of debugging info",
                  v => token.verbosity = Convert.ToInt32(v) },
                { "mt|max_threads=", "Change the max number of report requests to CxManager",
                  v => token.max_threads = Convert.ToInt32(v) },
                { "ms|max_scans=", "Change the max number of report requests to CxManager",
                  v => token.max_scans = Convert.ToInt32(v) },
                { "ff|filename_filter=", "Firter results so only filename matches are reported",
                  v => token.filename_filter = v },
                { "d|debug", "Output debugging info ",
                  v => token.debug = true },
                { "T|test", "Wait at end of program ",
                  v => token.test = true },
                { "?|h|help", "show your options",
                  v => token.api_action = api_action.help },
            };

            try
            {
                extra = p.Parse(args);
                Configuration.configuration(args, token.appsettings);
                token._setresultClass();
                settingClass _settings = get_settings();
                if (_settings.use_proxy || token.use_proxy)
                {
                    token.use_proxy         = true;
                    token.proxy_use_default = token.proxy_use_default ? true : _settings.proxy_use_default;
                    token.proxy_url         = String.IsNullOrEmpty(token.proxy_url) ? _settings.proxy_url : token.proxy_url;
                    Console.WriteLine("Using proxy {0}", token.proxy_url);
                }

                token.save_result_filename = String.IsNullOrEmpty(token.save_result_filename) ? _settings.CxResultFileName : token.save_result_filename;
                token.save_result_path     = String.IsNullOrEmpty(token.save_result_path) ? _settings.CxResultFilePath : token.save_result_path;
                _settings.CxFilePath       = string.IsNullOrEmpty(_settings.CxDefaultFilePath) ? _settings.CxFilePath : _settings.CxDefaultFilePath;
                token.file_name            = String.IsNullOrEmpty(token.file_name) ? _settings.CxDefaultFileName : token.file_name;
                token.file_path            = String.IsNullOrEmpty(token.file_path) ? _settings.CxFilePath : token.file_path;
                token.end_time             = (token.end_time == null) ? DateTime.Today : token.end_time;
                token.start_time           = (token.start_time == null) ? DateTime.Today.AddMonths(-1) : token.start_time;

                if (token.debug && token.verbosity > 0)
                {
                    debug_configuration(_settings, token);
                }
            }

            // if (String.IsNullOrEmpty(token.file_name) ? _configuration
            catch (OptionException e)
            {
                Console.Write("CxApi_Core: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try CxApi --help' for more information.");
                token.status = -1;
            }

            if (token.api_action == api_action.help)
            {
                ShowHelp(p);
            }
            return(token);
        }