Exemplo n.º 1
0
 public frmStartup(string Element)
 {
     if (Element == null)
     {
         this.Element = null;
     }
     else
     {
         this.Element = JsonConvert.DeserializeObject <ReportingPolicyElementStartup>(Element);
     }
     InitializeComponent();
 }
Exemplo n.º 2
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            Element       = new ReportingPolicyElementStartup();
            Element.Names = new List <string>();
            foreach (string s in txtPrograms.Text.Split('\n', '\r'))
            {
                if (s.Trim() == "")
                {
                    continue;
                }
                Element.Names.Add(s.Trim());
            }

            Element.SearchLocations = "";
            foreach (string s in txtLocations.Text.Split('\n', '\r'))
            {
                if (s.Trim() == "")
                {
                    continue;
                }
                Element.SearchLocations += s.Trim() + ";";
            }
            if (Element.SearchLocations.EndsWith(";") == true)
            {
                Element.SearchLocations = Element.SearchLocations.Substring(0, Element.SearchLocations.Length - 1);
            }

            Element.SearchNameIn   = lstCheck.SelectedIndex;
            Element.NotifyOnAdd    = chkNotifyOnAdd.Checked;
            Element.NotifyOnRemove = chkNotifyOnRemove.Checked;
            Element.NotifyOnUpdate = chkNotifyOnUpdate.Checked;
            if (Element.NotifyOnAdd == false && Element.NotifyOnRemove == false && Element.NotifyOnUpdate == false)
            {
                MessageBox.Show(this, "Please check at least one notification.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 3
0
        string Explain(string e)
        {
            string res = "Missing description: " + e;

            switch (lstType.SelectedIndex)
            {
            case 1:
            {
                ReportingPolicyElementDisk d = JsonConvert.DeserializeObject <ReportingPolicyElementDisk>(e);
                res = (d.DriveLetter == "$" ? "(SYSTEM DRIVE)" : d.DriveLetter + ":\\") + " - Size < " + d.MinimumSize.ToString() + " " + (d.Method == 1 ? "%" : "bytes");
                break;
            }

            case 2:
            {
                ReportingPolicyElementEventLog d = JsonConvert.DeserializeObject <ReportingPolicyElementEventLog>(e);
                res = "";
                if (d.Book == null)
                {
                    d.Book = new List <string>();
                }
                if (d.Sources == null)
                {
                    d.Sources = new List <string>();
                }
                if (d.CategoryNumbers == null)
                {
                    d.CategoryNumbers = new List <int>();
                }
                if (d.EventLogTypes == null)
                {
                    d.EventLogTypes = new List <int>();
                }

                if (d.Book.Count == 0)
                {
                    res += "Book: (all)";
                }
                else
                {
                    res += "Book: ";
                    foreach (string s in d.Book)
                    {
                        res += s + ", ";
                    }
                    if (res.EndsWith(", ") == true)
                    {
                        res = res.Substring(0, res.Length - 2);
                    }
                }

                if (d.Sources.Count == 0)
                {
                    res += " Sources: (any)";
                }
                else
                {
                    res += " Sources: ";
                    foreach (string s in d.Sources)
                    {
                        res += s + ", ";
                    }
                    if (res.EndsWith(", ") == true)
                    {
                        res = res.Substring(0, res.Length - 2);
                    }
                }

                if (d.EventLogTypes.Count == 0)
                {
                    res += " Types: (any)";
                }
                else
                {
                    bool GotInfo = false;
                    res += " Types: ";
                    foreach (int s in d.EventLogTypes)
                    {
                        switch (s)
                        {
                        case 0:
                        case 4:
                            res += GotInfo == false ? " Information, " : ""; GotInfo = true; break;

                        case 1:
                            res += " Error, "; break;

                        case 2:
                            res += " Warning, "; break;

                        case 8:
                            res += " Success Audit, "; break;

                        case 16:
                            res += " Failure Audit, "; break;

                        default:
                            res += " ??? " + d.ToString() + ", "; break;
                        }
                    }
                    if (res.EndsWith(", ") == true)
                    {
                        res = res.Substring(0, res.Length - 2);
                    }
                }

                if (d.CategoryNumbers.Count == 0)
                {
                    res += " Event IDs: (any)";
                }
                else
                {
                    res += " Event IDs: ";
                    foreach (int s in d.CategoryNumbers)
                    {
                        res += s.ToString() + ", ";
                    }
                    if (res.EndsWith(", ") == true)
                    {
                        res = res.Substring(0, res.Length - 2);
                    }
                }
                break;
            }

            case 3:
            {
                ReportingPolicyElementAddRemovePrograms d = JsonConvert.DeserializeObject <ReportingPolicyElementAddRemovePrograms>(e);
                if (d.Names == null)
                {
                    d.Names = new List <string>();
                }
                res = "";
                switch (d.SearchNameIn)
                {
                case 0: res += "Programs with their exact IDs: "; break;

                case 1: res += "Programs containing: "; break;

                case 2: res += "Programs starting with: "; break;

                default: res += "????? " + d.SearchNameIn.ToString() + ": "; break;
                }
                if (d.Names.Count == 0)
                {
                    res += "(any)";
                }
                else
                {
                    foreach (string s in d.Names)
                    {
                        res += "\"" + s + "\", ";
                    }
                    if (res.EndsWith(", ") == true)
                    {
                        res = res.Substring(0, res.Length - 2);
                    }
                }
                res += " ";
                switch (d.SearchBits)
                {
                case 0: break;

                case 1: res += "(32 bit only)"; break;

                case 2: res += "(64 bit only)"; break;
                }

                res += " Notify on: ";
                if (d.NotifyOnAdd == true)
                {
                    res += "Add, ";
                }
                if (d.NotifyOnRemove == true)
                {
                    res += "Removal, ";
                }
                if (d.NotifyOnUpdate == true)
                {
                    res += "Update, ";
                }
                if (res.EndsWith(", ") == true)
                {
                    res = res.Substring(0, res.Length - 2);
                }
                break;
            }

            case 4:
            {
                ReportingPolicyElementStartup d = JsonConvert.DeserializeObject <ReportingPolicyElementStartup>(e);
                if (d.Names == null)
                {
                    d.Names = new List <string>();
                }
                res = "";
                switch (d.SearchNameIn)
                {
                case 0: res += "Startup Item with their exact text: "; break;

                case 1: res += "Startup Item containing: "; break;

                case 2: res += "Startup Item starting with: "; break;

                default: res += "????? " + d.SearchNameIn.ToString() + ": "; break;
                }
                if (d.Names.Count == 0)
                {
                    res += "(any)";
                }
                else
                {
                    foreach (string s in d.Names)
                    {
                        res += "\"" + s + "\", ";
                    }
                    if (res.EndsWith(", ") == true)
                    {
                        res = res.Substring(0, res.Length - 2);
                    }
                }
                res += " ";

                if (string.IsNullOrWhiteSpace(d.SearchLocations) == false)
                {
                    res += " Locations: " + d.SearchLocations;
                }

                res += " Notify on: ";
                if (d.NotifyOnAdd == true)
                {
                    res += "Add, ";
                }
                if (d.NotifyOnRemove == true)
                {
                    res += "Removal, ";
                }
                if (d.NotifyOnUpdate == true)
                {
                    res += "Update, ";
                }
                if (res.EndsWith(", ") == true)
                {
                    res = res.Substring(0, res.Length - 2);
                }
                break;
            }

            case 5:
            {
                ReportingPolicyElementSMART d = JsonConvert.DeserializeObject <ReportingPolicyElementSMART>(e);
                res = "";

                res += " Notify on: ";
                if (d.NotifyOnAdd == true)
                {
                    res += "Add, ";
                }
                if (d.NotifyOnRemove == true)
                {
                    res += "Removal, ";
                }
                if (d.NotifyOnUpdate == true)
                {
                    res += "Update";
                    if (d.SkipAttribUpdateReport != null)
                    {
                        if (d.SkipAttribUpdateReport.Count > 0)
                        {
                            res += " (Skip Attributes: ";
                            foreach (int s in d.SkipAttribUpdateReport)
                            {
                                res += "0x" + s.ToString("X") + ", ";
                            }
                            if (res.EndsWith(", ") == true)
                            {
                                res = res.Substring(0, res.Length - 2);
                            }
                            res += "), ";
                        }
                        else
                        {
                            res += ", ";
                        }
                    }
                    else
                    {
                        res += ", ";
                    }
                }
                if (d.NotifyOnError == true)
                {
                    res += "Error, ";
                }
                if (res.EndsWith(", ") == true)
                {
                    res = res.Substring(0, res.Length - 2);
                }
                break;
            }

            case 6:
            {
                res = "Simple Task is completed";
                break;
            }
            }
            return(res);
        }
Exemplo n.º 4
0
        void ReportingThread(object StartupListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for Startup Data"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for Startup Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    StartupLst   StartupList  = (StartupLst)StartupListO;
                    ComputerData computerdata = Computers.GetComputerDetail(sql, StartupList.MachineID);
                    if (computerdata == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot get any computer data for Startup Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }

                    List <PolicyObject>        Pol             = Policies.GetPolicyForComputerInternal(sql, StartupList.MachineID);
                    Dictionary <string, Int64> AlreadyReported = new Dictionary <string, long>();
                    foreach (PolicyObject PolO in Pol)
                    {
                        if (PolO.Type != PolicyIDs.ReportingPolicy)
                        {
                            continue;
                        }
                        ReportingPolicyElement RepElementRoot = JsonConvert.DeserializeObject <ReportingPolicyElement>(Policies.GetPolicy(sql, PolO.ID).Data);
                        if (RepElementRoot.Type != ReportingPolicyType.Startup)
                        {
                            continue;
                        }
                        if (RepElementRoot.ReportToAdmin == null)
                        {
                            RepElementRoot.ReportToAdmin = false;
                        }
                        if (RepElementRoot.ReportToClient == null)
                        {
                            RepElementRoot.ReportToClient = false;
                        }
                        if (RepElementRoot.UrgentForAdmin == null)
                        {
                            RepElementRoot.UrgentForAdmin = false;
                        }
                        if (RepElementRoot.UrgentForClient == null)
                        {
                            RepElementRoot.UrgentForClient = false;
                        }
                        if (RepElementRoot.ReportToAdmin == false && RepElementRoot.ReportToClient == false && RepElementRoot.UrgentForAdmin == false && RepElementRoot.UrgentForClient == false)
                        {
                            continue;
                        }

                        foreach (string Element in RepElementRoot.ReportingElements)
                        {
                            ReportingPolicyElementStartup arprep = JsonConvert.DeserializeObject <ReportingPolicyElementStartup>(Element);
                            if (arprep.NotifyOnAdd == false && arprep.NotifyOnRemove == false && arprep.NotifyOnUpdate == false)
                            {
                                continue;
                            }

                            if (arprep.NotifyOnAdd == true)
                            {
                                foreach (StartupItem ar in GetFilteredData(StartupList.Added, computerdata, arprep))
                                {
                                    ReportThings(sql, StartupList.MachineID, "Add", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnUpdate == true)
                            {
                                foreach (StartupItem ar in GetFilteredData(StartupList.Updated, computerdata, arprep))
                                {
                                    ReportThings(sql, StartupList.MachineID, "Update", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnRemove == true)
                            {
                                foreach (StartupItem ar in GetFilteredData(StartupList.Removed, computerdata, arprep))
                                {
                                    ReportThings(sql, StartupList.MachineID, "Remove", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in Startup Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }
Exemplo n.º 5
0
        List <StartupItem> GetFilteredData(List <StartupItem> FullList, ComputerData computerdata, ReportingPolicyElementStartup arprep)
        {
            List <StartupItem> Lst = new List <StartupItem>();

            if (arprep.Names == null)
            {
                arprep.Names = new List <string>();
            }
            foreach (StartupItem ar in FullList)
            {
                if (arprep.Names.Count != 0)
                {
                    bool Found = false;
                    foreach (string n in arprep.Names)
                    {
                        switch (arprep.SearchNameIn)
                        {
                        case 0:
                            if (n.ToLower() == ar.Key.ToLower() ||
                                n.ToLower() == ar.Item.ToLower())
                            {
                                Found = true;
                            }
                            break;

                        case 1:
                            if (ar.Key.ToLower().Contains(n.ToLower()) == true ||
                                ar.Item.ToLower().Contains(n.ToLower()) == true)
                            {
                                Found = true;
                            }
                            break;

                        case 2:
                            if (ar.Key.ToLower().StartsWith(n.ToLower()) == true ||
                                ar.Item.ToLower().StartsWith(n.ToLower()) == true)
                            {
                                Found = true;
                            }
                            break;
                        }
                        if (Found == true)
                        {
                            break;
                        }
                    }
                    if (Found == false)
                    {
                        continue;
                    }
                }
                if (string.IsNullOrWhiteSpace(arprep.SearchLocations) == false)
                {
                    bool Found = false;
                    foreach (string loc in arprep.SearchLocations.Split(';'))
                    {
                        if (loc.ToLower().Trim() == ar.Location.ToLower())
                        {
                            Found = true;
                            break;
                        }
                    }
                    if (Found == false)
                    {
                        continue;
                    }
                }
                Lst.Add(ar);
            }
            return(Lst);
        }