Exemple #1
0
        public bool waitForResult(List <ReportTrace> trace, getScanResults scanResults, List <ReportResultAll> resultNew, Dictionary <long, ReportStaging> start, Dictionary <long, ReportStaging> end, Dictionary <long, List <ReportResultAll> > first, Dictionary <long, List <ReportResultAll> > last)
        {
            ConsoleSpinner spinner      = new ConsoleSpinner();
            bool           waitFlag     = false;
            DateTime       wait_expired = DateTime.UtcNow;

            while (!waitFlag)
            {
                if (wait_expired.AddMinutes(2) < DateTime.UtcNow)
                {
                    Console.Error.WriteLine("waitForResult timeout! {0}", getTimeOutObjects(trace));
                    break;
                }
                spinner.Turn();
                waitFlag = true;
                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 1 second(s)");
                }
                Thread.Sleep(1000);
                foreach (ReportTrace rt in trace)
                {
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (token.debug && token.verbosity > 0)
                        {
                            Console.WriteLine("Testing report.Id {0}", rt.reportId);
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Found report.Id {0}", rt.reportId);
                            }
                            Thread.Sleep(2000);
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getFirstandLastReport(result, start, end, first, last);
                                }
                                else
                                {
                                    rt.isRead = true;
                                    if (token.debug && token.verbosity > 1)
                                    {
                                        Console.Error.WriteLine("Dumping XML:");
                                        Console.Error.Write(result.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemple #2
0
        public bool waitForResult(List <ReportTrace> trace, getScanResults scanResults, List <ReportResultAll> resultNew, Dictionary <long, ReportStaging> end, Dictionary <long, List <ReportResultAll> > last)
        {
            bool waitFlag = false;

            while (!waitFlag)
            {
                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 3 second(s)");
                }
                Thread.Sleep(3000);

                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (rt.TimeStamp.AddMinutes(2) < DateTime.UtcNow)
                        {
                            Console.Error.WriteLine("ReportId/ScanId {0}/{1} timeout!", rt.reportId, rt.scanId);
                            rt.isRead = true;
                            continue;
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Got status for reportId {0}", rt.reportId);
                            }
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (token.debug && token.verbosity > 0)
                                {
                                    Console.WriteLine("Got data for reportId {0}", rt.reportId);
                                }
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                            }
                        }
                        else
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Waiting for reportId {0}", rt.reportId);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemple #3
0
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }

            Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > > fix = new Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > >();
            List <ReportTrace> trace = new List <ReportTrace>();
            Dictionary <string, ReportResultExtended> resultAll = new Dictionary <string, ReportResultExtended>();
            List <ReportResultExtended> report_output           = new List <ReportResultExtended>();
            //            Dictionary<long, ReportStaging> start = new Dictionary<long, ReportStaging>();
            //            Dictionary<long, ReportStaging> end = new Dictionary<long, ReportStaging>();
            Dictionary <long, ScanCount> scanCount = new Dictionary <long, ScanCount>();
            getScanResults scanResults             = new getScanResults();
            getScans       scans    = new getScans();
            getProjects    projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            //List<Teams> teams = scans.getTeams(token);
            token.max_scans = (token.max_scans == 0) ? 1 : token.max_scans;
            List <ScanObject> scan = projects.filter_by_projects(token);

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, please check argumants and retry.");
                return(false);
            }
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            Dictionary <long, ScanSettings>   settings         = projects.CxSettings;
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            Dictionary <long, Presets>        presets          = projects.CxPresets;
            List <ReportLastScan>             lastScan         = reportLastScan(token, scan, teams, resultStatistics, settings, presets);

            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", lastScan.Count);
            }

            if (token.pipe)
            {
                foreach (ReportLastScan csv in lastScan)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}", csv.ProjectId, csv.ProjectName, csv.Comment, csv.TeamName, csv.isIncremental, csv.Owner, csv.Origin, csv.ScanType, csv.ScanStartDate, csv.ScanFinishDate, csv.High, csv.Medium, csv.Low);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(lastScan, token);
            }
            return(true);
        }
        private bool fetchReports(List <ReportTrace> trace, getScanResults scanResults, Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > > fix, Dictionary <string, ReportResultExtended> resultAll, List <ReportResultExtended> report_output)
        {
            bool waitFlag = false;
            //ConsoleSpinner spinner = new ConsoleSpinner();
            DateTime wait_expired = DateTime.UtcNow;


            while (!waitFlag)
            {
                //spinner.Turn();
                if (wait_expired.AddMinutes(2) < DateTime.UtcNow)
                {
                    Console.Error.WriteLine("waitForResult timeout! {0}", getTimeOutObjects(trace));
                    break;
                }
                waitFlag = true;
                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 3 second(s)");
                }
                Thread.Sleep(3000);
                foreach (ReportTrace rt in trace)
                {
                    if (token.debug && token.verbosity > 0)
                    {
                        Console.WriteLine("Looping thru {0}, isRead {1}", rt.reportId, rt.isRead);
                    }
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (rt.TimeStamp.AddMinutes(1) < DateTime.UtcNow)
                        {
                            Console.Error.WriteLine("ReportId/ScanId {0}/{1} timeout!", rt.reportId, rt.scanId);
                            rt.isRead = true;
                            continue;
                        }
                        if (token.debug && token.verbosity > 0)
                        {
                            Console.WriteLine("Checking for report.Id {0}", rt.reportId);
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Found report.Id {0}", rt.reportId);
                            }
                            Thread.Sleep(2000);
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(rt.reportId, result, resultAll, fix, report_output))
                                {
                                    rt.isRead = true;
                                }
                                else
                                {
                                    rt.isRead = true;
                                    if (token.debug && token.verbosity > 1)
                                    {
                                        Console.Error.WriteLine("Dumping XML:");
                                        Console.Error.Write(result.ToString());
                                    }
                                    Console.Error.WriteLine("Failed processing reportId {0}", rt.reportId);
                                }
                            }
                            else
                            {
                                Console.Error.WriteLine("Failed retrieving reportId {0}", rt.reportId);
                                rt.isRead = true;
                            }
                        }
                        else
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Waiting for reportId {0}", rt.reportId);
                            }
                        }
                    }
                }
            }
            return(true);
        }
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }

            Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > > fix = new Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > >();
            List <ReportTrace> trace = new List <ReportTrace>();
            Dictionary <string, ReportResultExtended> resultAll = new Dictionary <string, ReportResultExtended>();
            List <ReportResultExtended> report_output           = new List <ReportResultExtended>();
            //            Dictionary<long, ReportStaging> start = new Dictionary<long, ReportStaging>();
            //            Dictionary<long, ReportStaging> end = new Dictionary<long, ReportStaging>();
            Dictionary <long, ScanCount> scanCount = new Dictionary <long, ScanCount>();
            getScanResults scanResults             = new getScanResults();
            getScans       scans    = new getScans();
            getProjects    projects = new getProjects(token);
            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check argumants and retry.");
                return(false);
            }
            foreach (ScanObject s in scan)
            {
                setCount(s.Project.Id, scanCount);

                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                    if (trace.Count % token.max_threads == 0)
                    {
                        fetchReports(trace, scanResults, fix, resultAll, report_output);
                        trace.Clear();
                    }
                }
            }

            fetchReports(trace, scanResults, fix, resultAll, report_output);
            trace.Clear();

            addFixed(fix, report_output);
            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", report_output.Count);
            }
            if (token.pipe)
            {
                foreach (ReportResultExtended csv in report_output)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", csv.projectName, csv.teamName, csv.presetName, csv.similarityId, csv.resultId, csv.reportId, csv.Severity, csv.status, csv.state, csv.Query, csv.Group, csv.scanDate);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(report_output, token);
            }
            return(true);
        }
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }
            List <ReportTrace> trace = new List <ReportTrace>();
            Dictionary <long, List <ReportResultMaxQueries> > report = new Dictionary <long, List <ReportResultMaxQueries> >();
            Dictionary <long, List <ReportResultAll> >        last   = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, ScanCount> scanCount = new Dictionary <long, ScanCount>();
            getScans    scans    = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token, true);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, please check arguments and retry.");
                return(false);
            }

            foreach (ScanObject s in scan)
            {
                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                if (trace.Count % token.max_threads == 0)
                {
                    waitForResult(trace, scanResults, last);
                    trace.Clear();
                }
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                }
            }
            waitForResult(trace, scanResults, last);
            trace.Clear();

            List <ReportResultMaxQueries> reportOutputs = totalScansandReports(last, scan, resultStatistics);

            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", reportOutputs.Count);
            }
            if (token.pipe)
            {
                foreach (ReportResultMaxQueries csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25}", csv.Project_Name, csv.Team_Name, csv.Preset_Name, csv.Scan_Date, csv.Project_Id, csv.Scan_Id, csv.Languages, csv.Query_1, csv.Group_1, csv.Severity_1, csv.False_Positive_1, csv.Query_2, csv.Group_2, csv.Severity_2, csv.False_Positive_2, csv.Query_3, csv.Group_3, csv.Severity_3, csv.False_Positive_3, csv.Query_4, csv.Group_4, csv.Severity_4, csv.False_Positive_4, csv.Query_5, csv.Group_5, csv.Severity_5, csv.False_Positive_5);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Exemple #7
0
        public bool fetchReportsbyDate()
        {
            if (token.debug && token.verbosity > 1)
            {
                Console.WriteLine("Running: {0}", token.report_name);
            }
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultAll>                     resultNew = new List <ReportResultAll>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultAll> > first     = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, List <ReportResultAll> > last      = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();
            getScans    scans    = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check arguments and retry.");
                return(false);
            }

            foreach (ScanObject s in scan)
            {
                setCount(s.Project.Id, scanCount);
                findFirstandLastScan(s.Project.Id, s, resultStatistics[s.Id], start, end);

                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                //                        ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                //                        if (result != null)
                //                        {
                //                            trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, scans.getFullName(teams, s.OwningTeamId), s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                //                        }
                if (trace.Count % token.max_threads == 0)
                {
                    waitForResult(trace, scanResults, resultNew, start, end, first, last);
                    trace.Clear();
                }
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                }
            }

            waitForResult(trace, scanResults, resultNew, start, end, first, last);
            trace.Clear();

            List <ReportOutputExtended> reportOutputs = totalScansandReports(start, end, resultNew, first, last, scanCount);

            if (token.debug)
            {
                Console.WriteLine("Processing data, number of rows: {0}", reportOutputs.Count);
            }
            if (token.pipe)
            {
                foreach (ReportOutputExtended csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21}", csv.ProjectName, csv.Team, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.StartNotExploitable, csv.StartConfirmed, csv.StartToVerify, csv.LastOthers, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.LastNotExploitable, csv.LastConfirmed, csv.LastToVerify, csv.LastOthers, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Exemple #8
0
        public bool fetchReportsbyDate()
        {
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultNew>                     resultNew = new List <ReportResultNew>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultNew> > last      = new Dictionary <long, List <ReportResultNew> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();
            bool              waitFlag    = false;
            getScanResults    scanResults = new getScanResults();
            getScans          scans       = new getScans();
            List <ScanObject> scan        = scans.getScan(token);

            foreach (ScanObject s in scan)
            {
                if ((s.DateAndTime != null) && (s.Status.Id == 7) && (s.DateAndTime.StartedOn > token.start_time) && (s.DateAndTime.StartedOn < token.end_time))
                {
                    setCount(s.Project.Id, scanCount);
                    findFirstorLastScan(s.Project.Id, s, start, true);
                    findFirstorLastScan(s.Project.Id, s, end, false);

                    ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Id, result.ReportId));
                    }
                }
            }
            while (!waitFlag)
            {
                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                            }
                        }
                    }
                }
            }

            List <ReportOutput> reportOutputs = totalScansandReports(start, end, resultNew, last, scanCount);

            if (token.pipe)
            {
                foreach (ReportOutput csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", csv.ProjectName, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.NotExploitable, csv.Confirmed, csv.ToVerify, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Exemple #9
0
        public bool fetchResultsbyDate()
        {
            List<ReportTrace> trace = new List<ReportTrace>();
            bool waitFlag = false;
          
            getScans scans = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary<string, Teams> teams = projects.CxTeams;
            List<ScanObject> scan = projects.filter_by_projects(token);
            Dictionary<long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check arguments and retry.");
                return false;
            }

            foreach (ScanObject s in scan)
            {

                if (token.save_result.Contains("XML"))
                {
                    ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                    }
                }
                if (token.save_result.Contains("PDF"))
                {
                    ReportResult result = scanResults.SetResultRequest(s.Id, "PDF", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "PDF"));
                    }
                }
            }

            while (!waitFlag)
            {
                if (token.debug && token.verbosity > 0) { Console.WriteLine("Sleeping 1 second(s)"); }
                Thread.Sleep(1000);
                waitFlag = true;
                foreach (ReportTrace rt in trace)
                {
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (token.debug && token.verbosity > 0) { Console.WriteLine("Testing report.Id {0}", rt.reportId); }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0) { Console.WriteLine("Found report.Id {0}", rt.reportId); }
                            var result = scanResults.GetGenaricResult(rt.reportId, token);
                            if (result != null)
                            {
                                rt.isRead = true;
                                writeOutputToFile(rt, token);
                                trace.Remove(rt);
                                break;
                            }
                        }
                    }
                }
            }
            return true;
        }
Exemple #10
0
        public bool fetchReportsbyDate()
        {
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultAll>                     resultNew = new List <ReportResultAll>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultAll> > last      = new Dictionary <long, List <ReportResultAll> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();

            /*            getScanResults scanResults = new getScanResults();
             *          getScans scans = new getScans();
             *          List<Teams> teams = scans.getTeams(token);
             *          List<ScanObject> scan = scans.getScan(token);*/
            getScans    scans    = new getScans();
            getProjects projects = new getProjects(token);

            //List<ScanObject> scan = scans.getScan(token);
            Dictionary <string, Teams>        teams            = projects.CxTeams;
            List <ScanObject>                 scan             = projects.filter_by_projects(token);
            Dictionary <long, ScanStatistics> resultStatistics = projects.CxResultStatistics;
            getScanResults scanResults = new getScanResults();

            if (scan.Count == 0)
            {
                Console.Error.WriteLine("No scans were found, pleas check argumants and retry.");
                return(false);
            }

            foreach (ScanObject s in scan)
            {
                setCount(s.Project.Id, scanCount);
                findFirstorLastScan(s.Project.Id, s, teams, start, true);
                findFirstorLastScan(s.Project.Id, s, teams, end, false);

                ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                if (result != null)
                {
                    trace.Add(new ReportTrace(s.Project.Id, s.Project.Name, teams[s.OwningTeamId].fullName, s.DateAndTime.StartedOn, s.Id, result.ReportId, "XML"));
                }
                if (trace.Count % 5 == 0)
                {
                    waitForResult(trace, scanResults, resultNew, end, last);
                    trace.Clear();
                }
            }
            waitForResult(trace, scanResults, resultNew, end, last);
            trace.Clear();

            List <ReportOutput> reportOutputs = totalScansandReports(start, end, resultNew, last, scanCount);

            if (token.pipe)
            {
                foreach (ReportOutput csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18}", csv.ProjectName, csv.company, csv.team, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.NotExploitable, csv.Confirmed, csv.ToVerify, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Exemple #11
0
        public bool waitForResult(List <ReportTrace> trace, getScanResults scanResults, List <ReportResultAll> resultNew, Dictionary <DateTimeOffset, Dictionary <long, Dictionary <string, ReportResultExtended> > > extendedScan, Dictionary <long, ReportStaging> end, Dictionary <long, List <ReportResultAll> > last)
        {
            bool     waitFlag     = false;
            DateTime wait_expired = DateTime.UtcNow;

            while (!waitFlag)
            {
                if (wait_expired.AddMinutes(2) < DateTime.UtcNow)
                {
                    Console.Error.WriteLine("waitForResult timeout! {0}", getTimeOutObjects(trace));
                    break;
                }

                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 3 second(s)");
                }
                Thread.Sleep(3000);

                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (rt.TimeStamp.AddMinutes(2) < DateTime.UtcNow)
                        {
                            Console.Error.WriteLine("ReportId/ScanId {0}/{1} timeout!", rt.reportId, rt.scanId);
                            rt.isRead = true;
                            continue;
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Got status for reportId {0}", rt.reportId);
                            }
                            Thread.Sleep(2000);
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (token.debug && token.verbosity > 0)
                                {
                                    Console.WriteLine("Got data for reportId {0}", rt.reportId);
                                }
                                if (process_CxResponse(result, rt.reportId, rt.projectId, rt.scanTime, extendedScan))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                                else
                                {
                                    rt.isRead = true;
                                    Console.Error.WriteLine("Failed processing reportId {0}", rt.reportId);
                                    if (token.debug && token.verbosity > 1)
                                    {
                                        Console.Error.WriteLine("Dumping XML:");
                                        Console.Error.Write(result.ToString());
                                    }
                                }
                            }
                            else
                            {
                                Console.Error.WriteLine("Failed retrieving reportId {0}", rt.reportId);
                                rt.isRead = true;
                            }
                        }
                        else
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Waiting for reportId {0}", rt.reportId);
                            }
                        }
                    }
                }
            }
            return(true);
        }