コード例 #1
0
        private void ShowScanData(ref CxWSQueryVulnerabilityData[] scanData, ref long scanId, CxWebServiceClient client)
        {
            // Get url to scanned project result
            string savedFileName = string.Format("report{0}", Guid.NewGuid());
            long   id            = 0;
            CxWSResponseScanStatus scanStatus = client.ServiceClient.GetStatusOfSingleScan(_scan.LoginResult.SessionId, _scan.RunScanResult.ScanId);
            string ScanTaskId = scanStatus.ScanId.ToString();//after scan is finished the server replaces the scan id with task scan id

            scanData = PerspectiveHelper.GetScanResultsPaths(ScanTaskId, ref scanId);
            id       = scanId;
            LoginData.BindProject bindProject = _scan.LoginResult.AuthenticationData.BindedProjects.Find(project => project.BindedProjectId == CommonData.ProjectId &&
                                                                                                         project.ProjectName == CommonData.ProjectName &&
                                                                                                         project.RootPath == CommonData.ProjectRootPath);

            if (bindProject == null) // scaned for the first time
            {
                bindProject             = new LoginData.BindProject();
                bindProject.ProjectName = CommonData.ProjectName;
                bindProject.RootPath    = CommonData.ProjectRootPath;
                bindProject.IsBound     = true;
                _scan.LoginResult.AuthenticationData.BindedProjects.Add(bindProject);
            }
            if (!CommonData.IsProjectBound) // its new project
            {
                bindProject.BindedProjectId = scanStatus.ProjectId;
                CommonData.ProjectId        = scanStatus.ProjectId;
                CommonData.IsProjectPublic  = scanStatus.IsPublic;
                bindProject.IsPublic        = scanStatus.IsPublic;
                bindProject.IsBound         = true;
            }
            bindProject.SelectedScanId = id;
            bindProject.ScanReports    = new List <ScanReportInfo>();
            LoginHelper.Save(_scan.LoginResult.AuthenticationData);


            BackgroundWorkerHelper bgWork = new BackgroundWorkerHelper(delegate
            {
                CommonData.SelectedScanId = id;
                String path = PerspectiveHelper.GetScanXML(id);
                ScanReportInfo scanReportInfo         = new ScanReportInfo();
                scanReportInfo.Path                   = path;
                scanReportInfo.Id                     = id;
                LoginData.BindProject projectToUpdate = _scan.LoginResult.AuthenticationData.BindedProjects.Find(delegate(LoginData.BindProject bp)
                {
                    return(bp.BindedProjectId == CommonData.ProjectId);
                }
                                                                                                                 );

                projectToUpdate.ScanReports = new List <ScanReportInfo>();
                projectToUpdate.ScanReports.Add(scanReportInfo);

                LoginHelper.Save(_scan.LoginResult.AuthenticationData);
            });

            bgWork.DoWork();
        }
コード例 #2
0
        private void RetrieveResultsFromServer(LoginData.BindProject bindPro, LoginData login)
        {
            CxWSResponseScansDisplayData cxWSResponseScansDisplayData = PerspectiveHelper.GetScansDisplayData(CommonData.ProjectId);

            if (cxWSResponseScansDisplayData == null)
            { //error occured
                return;
            }
            if (cxWSResponseScansDisplayData.ScanList.Length == 0)
            {
                // show error about 0 scan list
                System.Windows.Forms.MessageBox.Show("The chosen project doesn't contain scans", "Error", System.Windows.Forms.MessageBoxButtons.OK);
                return;
            }
            bindPro.ScanReports.Clear();
            foreach (ScanDisplayData item in cxWSResponseScansDisplayData.ScanList)
            {
                // Add relation to scanned project and scan report
                ScanReportInfo scanReportInfo = new ScanReportInfo {
                    Id = item.ScanID
                };
                string minutes = item.QueuedDateTime.Minute.ToString().Length > 1 ? item.QueuedDateTime.Minute.ToString() : "0" + item.QueuedDateTime.Minute;

                scanReportInfo.Name = string.Format("{0}/{1}/{2} {3}:{4}", item.QueuedDateTime.Month,
                                                    item.QueuedDateTime.Day,
                                                    item.QueuedDateTime.Year,
                                                    item.QueuedDateTime.Hour,
                                                    minutes);

                bindPro.AddScanReport(scanReportInfo);
            }
            LoginHelper.Save(login);


            ShowResultLogic showResultLogic = new ShowResultLogic();

            showResultLogic.Act();


            return;
        }
コード例 #3
0
        static void BindSelectedProject(LoginResult loginResult, Entities.Project project)
        {
            CxWSResponseProjectsDisplayData cxWSResponseProjectsDisplayData = null;
            // show bind project form
            CxWebServiceClient client = null;
            bool isThrewError         = false;
            BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate
            {
                try
                {
                    client = new CxWebServiceClient(loginResult.AuthenticationData);
                }
                catch (Exception e)
                {
                    Logger.Create().Error(e.ToString());
                    System.Windows.Forms.MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK);
                    isThrewError = true;
                    return;
                }

                if (client == null)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot connect to server", "Error", System.Windows.Forms.MessageBoxButtons.OK);
                    isThrewError = true;
                    return;
                }
                cxWSResponseProjectsDisplayData = client.ServiceClient.GetProjectsDisplayData(loginResult.SessionId);
            }, loginResult.AuthenticationData.ReconnectInterval * 1000, loginResult.AuthenticationData.ReconnectCount);

            //Show wait dialog and perform server request in different thread to safe UI responsibility
            if (!bg.DoWork(RETRIEVE_RESULTS_LOADING_TEXT))
            {
                return;
            }

            if (cxWSResponseProjectsDisplayData == null || !cxWSResponseProjectsDisplayData.IsSuccesfull || isThrewError)
            {
                return;
            }

            var bindProjectEntity = new BindProjectEntity {
                CxProjectsDisplayData = cxWSResponseProjectsDisplayData
            };

            #region show Select Project window

            //            if (projectID < 0)
            //            {
            if (_dispatcher == null)
            {
                _dispatcher = ServiceLocators.ServiceLocator.GetDispatcher();
            }

            if (_dispatcher != null)
            {
                _dispatcher.Dispatch(bindProjectEntity);
            }


            if (bindProjectEntity.CommandResult == System.Windows.Forms.DialogResult.Cancel)
            {
                _canceled = true;
                return;
            }
            //            }

            #endregion

            long selectedProjectId = 0;
            if (client != null && ((bindProjectEntity.SelectedProject != null && bindProjectEntity.CommandResult == System.Windows.Forms.DialogResult.OK)))
            {
                Logger.Create().Info("Loading project id: " + bindProjectEntity.SelectedProject.projectID);
                bg.DoWorkFunc = delegate(object obj)
                {
                    selectedProjectId = bindProjectEntity.SelectedProject.projectID;
                    if (loginResult.AuthenticationData.BindedProjects == null)
                    {
                        loginResult.AuthenticationData.BindedProjects = new List <LoginData.BindProject>();
                    }

                    LoginData.BindProject bindProject = loginResult.AuthenticationData.BindedProjects.Find(delegate(LoginData.BindProject bp)
                    {
                        return(bp.ProjectName == project.ProjectName && bp.RootPath == project.RootPath);
                    }
                                                                                                           );
                    bool isNewProject = true;
                    if (bindProject != null)
                    {
                        bindProject.BindedProjectId = selectedProjectId;
                        bindProject.ScanReports     = new List <ScanReportInfo>();
                        bindProject.IsBound         = true;
                        bindProject.SelectedScanId  = 0;
                        bindProject.IsPublic        = bindProjectEntity.isPublic;
                        isNewProject = false;
                    }
                    else
                    {
                        bindProject = new LoginData.BindProject()
                        {
                            BindedProjectId = selectedProjectId,
                            RootPath        = project.RootPath,
                            ProjectName     = project.ProjectName,
                            ScanReports     = new List <ScanReportInfo>(),
                            IsPublic        = bindProjectEntity.isPublic,
                            IsBound         = true,
                        };
                        isNewProject = true;
                    }


                    CxWSResponseScansDisplayData cxWSResponseScansDisplayData = PerspectiveHelper.GetScansDisplayData(selectedProjectId);
                    if (cxWSResponseScansDisplayData.ScanList.Length == 0)
                    {
                        // show error about 0 scan list
                        System.Windows.Forms.MessageBox.Show("The chosen project doesn't contain scans", "Error", System.Windows.Forms.MessageBoxButtons.OK);
                        isThrewError = true;
                        return;
                    }

                    foreach (ScanDisplayData item in cxWSResponseScansDisplayData.ScanList)
                    {
                        // Add relation to scanned project and scan report
                        ScanReportInfo scanReportInfo = new ScanReportInfo {
                            Id = item.ScanID
                        };
                        string minutes = item.QueuedDateTime.Minute.ToString().Length > 1 ? item.QueuedDateTime.Minute.ToString() : "0" + item.QueuedDateTime.Minute;

                        scanReportInfo.Name = string.Format("{0}/{1}/{2} {3}:{4}", item.QueuedDateTime.Month,
                                                            item.QueuedDateTime.Day,
                                                            item.QueuedDateTime.Year,
                                                            item.QueuedDateTime.Hour,
                                                            minutes);

                        bindProject.AddScanReport(scanReportInfo);
                    }

                    if (bindProject.ScanReports.Count > 0)
                    {
                        CommonData.SelectedScanId  = bindProject.ScanReports[0].Id;
                        bindProject.SelectedScanId = CommonData.SelectedScanId;
                    }

                    if (isNewProject)
                    {
                        loginResult.AuthenticationData.BindedProjects.Add(bindProject);
                    }
                };
                bool bCancel = !bg.DoWork("Downloading project data...");

                if (!bCancel && !isThrewError)
                {
                    CommonData.ProjectId = selectedProjectId;
                    LoginHelper.Save(loginResult.AuthenticationData);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Execute 'Previous Result' command
        /// </summary>
        public static void DoPrevResult()
        {
            Logger.Create().Debug("DoPrevResult in");
            // Get logged user credentials and project relation data
            LoginData login = Helpers.LoginHelper.Load(0);

            CxWSQueryVulnerabilityData[] perspective = null;
            login.IsOpenPerspective = Entities.Enum.SimpleDecision.Yes;

            LoginData.BindProject bindProject = login.BindedProjects.Find(delegate(LoginData.BindProject bp)
            {
                return(bp.BindedProjectId == CommonData.ProjectId &&
                       bp.ProjectName == CommonData.ProjectName &&
                       bp.RootPath == CommonData.ProjectRootPath);
            }
                                                                          );

            if (bindProject != null && bindProject.ScanReports != null && bindProject.ScanReports.Count > 0)
            {
                ScanReportInfo tmp = bindProject.ScanReports.Find(delegate(ScanReportInfo sri)
                {
                    return(sri.Id == CommonData.SelectedScanId);
                }
                                                                  );
                if (tmp == null || tmp.Id == 0)
                {
                    tmp = bindProject.ScanReports[0];
                    CommonData.SelectedScanId = tmp.Id;
                }

                perspective = GetScanResultsPath(tmp.Id);
                bindProject.SelectedScanId = tmp.Id;
                if (!string.IsNullOrEmpty(tmp.Path))
                {
                    StorageHelper.Delete(tmp.Path);
                }

                BackgroundWorkerHelper bgWork = new BackgroundWorkerHelper(delegate
                {
                    tmp.Path = PerspectiveHelper.GetScanXML(CommonData.SelectedScanId);

                    LoginHelper.Save(login);
                });

                bgWork.DoWork();



                Dictionary <string, long> list = new Dictionary <string, long>();
                foreach (ScanReportInfo item in bindProject.ScanReports)
                {
                    if (!list.ContainsKey(item.Name))
                    {
                        list.Add(item.Name, item.Id);
                    }
                }
                CommonActionsInstance.getInstance().ReportPersepectiveView.SetScanList(list, tmp.Id);

                if (perspective != null)
                {
                    ShowStored(perspective, login, tmp.Id);
                }
            }
        }