/// <summary> /// This is one of the hearts of gS. /// Like it is named, it checks the results and with them controls /// the outer interface of the ScanMonitor. It's somehow a respectful /// connection between the UI and the parallel scanner in the backend. /// </summary> /// <param name="scanmonitor">Instance of ScanMonitor while scanning.</param> private void CheckAndDisplayResults(ScanMonitor scanmonitor) { if (scanmonitor.HasResults()) { Scanner scanner = scanmonitor.GetFinishedScanner(); DorkDone dorkdone = scanner.ResultDork; if (dorkdone == null) { return; } if (dorkdone.ScanResult == (int)RESULT_STATUS.Cancel) { Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceInfo, "Scan was canceled."); dorkdone.ViewItem.ImageIndex = (int)RESULT_STATUS.Cancel; dorkdone.ViewItem.SubItems[0].Text = rm.GetString("RES_CANCELSCAN"); dorkdone.ViewItem.SubItems[2].Text = ""; return; } if (dorkdone.ScanResult == (int)RESULT_STATUS.Nothing) { Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceInfo, "Scan returned no results."); dorkdone.ViewItem.ImageIndex = (int)RESULT_STATUS.Nothing; dorkdone.ViewItem.SubItems[0].Text = rm.GetString("RES_NORESULT"); dorkdone.ViewItem.SubItems[2].Text = ""; summaryStat.ScansNoResult++; return; } if (dorkdone.ScanResult == (int)RESULT_STATUS.Failure) { dorkdone.ViewItem.ImageIndex = (int)RESULT_STATUS.Failure; dorkdone.ViewItem.SubItems[0].Text = rm.GetString("RES_FAILED"); dorkdone.ViewItem.SubItems[2].Text = ""; summaryStat.ScansFailed++; Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceInfo, "Scan failed."); return; } if (dorkdone.ScanResult == (int)RESULT_STATUS.Blocked) { dorkdone.ViewItem.ImageIndex = (int)RESULT_STATUS.Blocked; dorkdone.ViewItem.SubItems[0].Text = rm.GetString("RES_BLOCKED"); dorkdone.ViewItem.SubItems[2].Text = dorkdone.ResultURL; summaryStat.ScansFailed++; Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceInfo, "Scan was blocked."); if (Properties.Settings.Default.BlockDetectMode == (int)BLOCKING_MODE.SingleAndStop) { int stoppedscans = scanmonitor.StopAllActive(); Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceVerbose, stoppedscans, "Scans canceled in queue"); while (scanmonitor.HasPendingScans()) { Thread.Sleep(200); } } if (Properties.Settings.Default.BlockDetectMode != (int)BLOCKING_MODE.Ignore) { ShowScanningDialog(false); DialogResult dr = MessageBox.Show("Start browser to unlock block? Cancel will stop scanning.", "Block detected!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop); if (dr == DialogResult.Yes) { OSUtils.OpenInBrowser(dorkdone.ResultURL); MessageBox.Show("Ready to resume?", "Resume scanning.", MessageBoxButtons.OK, MessageBoxIcon.Question); } else if (dr == DialogResult.Cancel) { int stoppedscans = scanmonitor.StopAllActive(); Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceVerbose, stoppedscans, "Scans canceled in queue"); while (scanmonitor.HasPendingScans()) { Thread.Sleep(100); } StopScanning(); } ShowScanningDialog(true); } return; } if (dorkdone.ScanResult == (int)RESULT_STATUS.ScanWithResult) { resultListView.Items.Remove(dorkdone.ViewItem); // remove the one that is displayed while scanning if (scanner.Count > 0) { int lastIdx = 0; DorkDone resDork = scanner.ResultDork; DorkDone followDork = null; if (resDork.NextPage != 0) { if ((resDork.NextPage / 10) < Properties.Settings.Default.RequestPages) { followDork = new DorkDone(); followDork = (DorkDone)resDork.Clone(); followDork.ScanResult = (int)RESULT_STATUS.WhileScan; Scanner nextscanner = new Scanner(new ScanGoogleProvider(), followDork); while (!scanmonitor.IsThreadAvail()) { Thread.Sleep(300); } scanmonitor.Add(nextscanner); Thread.Sleep(100); } } do { ListViewItem lv1 = resultListView.Items.Add(rm.GetString("RES_SUCCESS"), (int)RESULT_STATUS.ScanWithResult); lv1.SubItems.Add(resDork.Title); lv1.SubItems.Add(resDork.ResultURL); lastIdx = lv1.Index; lv1.Tag = resDork; summaryStat.ScansSuccess++; resDork = resDork.Next; resultListView.EnsureVisible(lastIdx); } while (resDork != null); } } } }
/// <summary> /// Run a scan with a DorkDone. /// </summary> /// <param name="DorkToScan">DorkDone to scan.</param> /// <returns>True if no errors occured.</returns> public bool DoDork(DorkDone DorkToScan) { _ScanStatus = (int)SCANTHREADSTATE.Working; RequestBuilder req = new RequestBuilder(scanProvider); httpGet = new HttpSimpleGet(Properties.Settings.Default.ScanTimeOut); string currentRequest = req.getRequest(DorkToScan.Query, DorkToScan.Host, DorkToScan.NextPage); Trace.WriteLineIf(Debug.Trace.TraceGoolag.TraceInfo, currentRequest, "ScanURL:"); if (!httpGet.Do(currentRequest)) { DorkToScan.ErrorMessage = httpGet.GetErrorMessage(); DorkToScan.ScanResult = (int)RESULT_STATUS.Failure; _ScanStatus = (int)SCANTHREADSTATE.Finished; firstResultDork = DorkToScan; return(false); } ParseHtmlResults parser = new ParseHtmlResults(scanProvider, DorkToScan.NextPage); parsedResults = parser.Parse(httpGet.GetResults()); if (parsedResults.Count > 0) { DorkToScan.ScanResult = (int)RESULT_STATUS.ScanWithResult; DorkToScan.NextPage = parser.NextPage; DorkDone tmpDork = null; foreach (string parsedUrl in parsedResults) { DorkDone newDork = new DorkDone(); newDork = (DorkDone)DorkToScan.Clone(); newDork.ResultURL = parsedUrl; newDork.Next = tmpDork; tmpDork = newDork; } firstResultDork = tmpDork; } else { DorkToScan.Next = null; firstResultDork = DorkToScan; if (parser.Blocked) { DorkToScan.ScanResult = (int)RESULT_STATUS.Blocked; DorkToScan.ResultURL = httpGet.ResponseUri; } else { DorkToScan.ScanResult = (int)RESULT_STATUS.Nothing; } } _ScanStatus = (int)SCANTHREADSTATE.Finished; return(true); }