Esempio n. 1
0
        public void RemoveDuplicatesFromDatabase()
        {
            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    var hostDuplicates = from h in db.Hosts
                                         group h by new { h.HostIP, h.NetBiosName, h.FQDN, h.OperatingSystem }
                    into g
                    where g.Count() > 1
                    select g;

                    foreach (var g in hostDuplicates)
                    {
                        List <Host> duplicates = g.Skip(1).ToList();

                        foreach (Host record in duplicates)
                        {
                            db.Configuration.AutoDetectChangesEnabled = false;
                            db.Hosts.Remove(record);
                        }
                    }
                    db.SaveChanges();
                }
                catch (Exception) {
                    Debug.WriteLine("Error: 965777");
                }
                finally {
                    db.Dispose();
                }
            }
        }
Esempio n. 2
0
        public void MergeSelectedVulnerabilities(List <int> pluginIDList, string newIssueTitle, string pluginNames, string severityRating, string riskFactor)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    List <Vulnerability> vulnsToMerge = new List <Vulnerability>();
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled    = false;

                    int newPluginID = GetFreePluginID();

                    foreach (int pluginID in pluginIDList)
                    {
                        db.Vulnerabilities.Where(v => v.PluginID == pluginID).Update(x => new Vulnerability()
                        {
                            PluginID    = newPluginID,
                            PluginName  = newIssueTitle,
                            Description = pluginNames,
                            Solution    = "",
                            Severity    = severityRating,
                            RiskFactor  = riskFactor
                        });
                    }

                    db.SaveChanges();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 923843" + ": " + e);
                }
                finally {
                    db.Dispose();
                }
            }
        }
Esempio n. 3
0
        public void SetAppendixPluginID(int pluginID)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                AppendixData appData = new AppendixData();

                try {
                    if (db.Appendix.Any())
                    {
                        AppendixData recordDelete = db.Appendix.FirstOrDefault();
                        db.Appendix.Remove(recordDelete);
                        db.SaveChanges();
                    }

                    appData.pluginID = pluginID;
                    db.Appendix.Add(appData);
                    db.SaveChanges();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 921234" + e);
                }
            }
        }
Esempio n. 4
0
        public void RemoveSelectedVulnerability(List <int> pluginIDList)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled    = false;

                    foreach (int pluginID in pluginIDList)
                    {
                        db.Vulnerabilities.Where(v => v.PluginID == pluginID).Delete();
                    }

                    db.SaveChanges();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 923657" + ": " + e);
                }
                finally {
                    db.Dispose();
                }
            }
        }