private void FormConfigureNewsFeed_Load(object sender, EventArgs e) { SettingsDAO lSettingsDAO = new SettingsDAO(); cbAssetUpdated.Checked = lSettingsDAO.GetSettingAsBoolean("NewsFeedUpdateAsset", false); tbDiskSpace.Value = lSettingsDAO.GetSettingAsString("NewsFeedDiskSpace", "25") == String.Empty ? 25 : Convert.ToInt32(lSettingsDAO.GetSettingAsString("NewsFeedDiskSpace", "25")); lbDiskSpace.Text = String.Format("Less Than {0}% Disk Space Remaining", tbDiskSpace.Value); tbLicenses.Value = lSettingsDAO.GetSettingAsString("NewsFeedLicenses", "100") == String.Empty ? 100 : Convert.ToInt32(lSettingsDAO.GetSettingAsString("NewsFeedLicenses", "100")); lbLicenses.Text = String.Format("Greater Than {0}% Software Licenses Used", tbLicenses.Value); tbPrinterSupplies.Value = lSettingsDAO.GetSettingAsString("NewsFeedPrinters", "25") == String.Empty ? 25 : Convert.ToInt32(lSettingsDAO.GetSettingAsString("NewsFeedPrinters", "25")); lbPrinterSupplies.Text = String.Format("Less Than {0}% Printer Supplies Remaining", tbPrinterSupplies.Value); }
private void Form_Load(object sender, EventArgs e) { SettingsDAO lSettingsDAO = new SettingsDAO(); string adLocationStrings = lSettingsDAO.GetSettingAsString("ADCustomString", String.Empty); foreach (string adLocationString in adLocationStrings.Split('|')) { if (adLocationString != String.Empty) { lbReadStrings.Items.Add(adLocationString); } } rbCustomLocation.Checked = lSettingsDAO.GetSettingAsBoolean("UseADCustomString", false); rbRootLocation.Checked = !rbCustomLocation.Checked; ugbCustomLocations.Enabled = rbCustomLocation.Checked; }
public override void Start() { try { isStarted = true; List <string> returnValues = new List <string>(); SettingsDAO lSettingsDAO = new SettingsDAO(); // are we using a custom string or presenting the AD dialog? if (lSettingsDAO.GetSettingAsBoolean("UseADCustomString", false)) { string lCustomStrings = lSettingsDAO.GetSettingAsString("ADCustomString", String.Empty); if (lCustomStrings != String.Empty) { foreach (string lCustomString in lCustomStrings.Split('|')) { if (lCustomString != String.Empty) { DirectoryEntry ent = new DirectoryEntry(lCustomString); DirectorySearcher searcher = new DirectorySearcher(ent); searcher.Filter = "(objectClass=Computer)"; foreach (SearchResult result in searcher.FindAll()) { if (!returnValues.Contains(result.Path)) { returnValues.Add(result.Path); } } } } } } else { // displays the "Select Computers" dialog to the user try { computerPicker.ShowDialog(); foreach (string ldapString in computerPicker.ReturnValues) { returnValues.Add(ldapString); } } catch { // the dialog throws an exception if no directories are found...just ignore it } } //if (computerPicker.ReturnValues != null) if (returnValues.Count > 0) { string computerName = ""; string domainName = ""; bool domainFound = false; foreach (string ldapString in returnValues) { // remove the LDAP address from the returning string string ldapFilters = ldapString.Substring(ldapString.IndexOf("CN=")); // now split the string into the sub-strings string[] filterStrings = ldapFilters.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string filter in filterStrings) { if (filter.StartsWith("CN=", StringComparison.OrdinalIgnoreCase)) { string pcName = filter.Remove(0, 3); if (pcName.Length > 0 && !pcName.Equals("Computers", StringComparison.OrdinalIgnoreCase)) { computerName = pcName; } } else if (filter.StartsWith("DC=", StringComparison.OrdinalIgnoreCase)) { string domain = filter.Remove(0, 3); if (domain.Length > 0 && !domain.Equals("local", StringComparison.OrdinalIgnoreCase) && !domainFound) { domainName = domain.ToUpper(); domainFound = true; } } } // first check if this is a new domain if (domainName != "" && !domains.Contains(domainName)) { domains.Add(domainName); } // add the computer to the list along with its domain name if (computerName != "") { computers.Add(new string[] { computerName, domainName }); } domainFound = false; } } isComplete = true; FireNetworkDiscoveryUpdate(new DiscoveryUpdateEventArgs(computers.Count.ToString(), "Computer", computers.Count, 0)); } catch (Exception ex) { logger.Error(ex.Message); Utility.DisplayApplicationErrorMessage(String.Format( "AuditWizard encountered an error during Network Discovery. The error message is:{0}{1}{2}", Environment.NewLine, Environment.NewLine, ex.Message)); isComplete = true; } }
/// <summary> /// Called as the alert timer expires to check for any alerts having been generated and reporting them /// optionally sending emails if these have been configured /// /// Alert checking is done daily and will result in a number of entries being added to the ALERT table /// These entries are in turn /// </summary> public void CheckForAlerts() { LogFile ourLog = LogFile.Instance; ourLog.Write("CheckForAlerts", true); // try { SettingsDAO lSettingsDao = new SettingsDAO(); string fileName = String.Empty; string selectedFileName = String.Empty; System.Xml.Serialization.XmlSerializer serializer; AlertDefinition definition; // We need to be sure that we do not email the same alerts multiple times so we recover the date at // which we last send an email alert and only add alerts which occurred after that date to our email DateTime dateLastAlertEmail; string lastAlertDate = lSettingsDao.GetSettingAsString(DatabaseSettings.Setting_LastAlertEmailDate, ""); // If we have not previously checked alerts then look for alerts in the last day if (lastAlertDate == "") { dateLastAlertEmail = DateTime.Now.AddDays(-1); } else { dateLastAlertEmail = Convert.ToDateTime(lastAlertDate); } // Log the last alert date (if any) ourLog.Write("Checking For Alerts generated since " + dateLastAlertEmail.ToString(), true); // Allocate a list to hold the alerts so that they can be emailed in one go AlertList listAlerts = new AlertList(); // +8.3.3 // Now check the email frequency as if this is set to daily and we have already emailed today then we do not email again string mailFrequency = lSettingsDao.GetSetting(DatabaseSettings.Setting_AlertMonitorEmailFrequency, false); if (mailFrequency == DatabaseSettings.Setting_AlertMonitorEmailDaily) { string mailtime = lSettingsDao.GetSetting(DatabaseSettings.Setting_AlertMonitorEmailTime, false); if (mailtime == "") { mailtime = "18:00"; } DateTime emailTime = DateTime.Parse(mailtime); ourLog.Write("Daily checking set for " + emailTime.ToString("HH:mm") + " - Current time is " + DateTime.Now.ToString("HH:mm") + " Last Check Date was " + dateLastAlertEmail.Date.ToShortDateString(), true); // Are we still prior to the checking time? if (DateTime.Now.TimeOfDay < emailTime.TimeOfDay) { ourLog.Write("Check time not reached so exiting", true); return; } // We are past the check date - we check if we have not previously checked today else if (dateLastAlertEmail.Date == DateTime.Now.Date) { ourLog.Write("Check yime reached but already checked today so exiting", true); return; } } // Populate the Alert date so that we do not re-do this process lSettingsDao.SetSetting(DatabaseSettings.Setting_LastAlertEmailDate, DateTime.Now.ToString(), false); // Now we read all alerts created since the specified date listAlerts.Populate(dateLastAlertEmail); if (listAlerts.Count != 0) { // read the alert definitions as we need to know which if any of these alerts should be emailed // first get the AuditScanner object // Loop through the alerts and weed out any AM alerts which do not require email for (int index = 0; index < listAlerts.Count;) { Alert alert = listAlerts[index]; if (alert.Type == Alert.AlertType.alertmonitor) { fileName = alert.AlertName; selectedFileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "scanners\\alertmonitors\\") + fileName + ".xml"; serializer = new System.Xml.Serialization.XmlSerializer(typeof(AlertDefinition)); definition = (AlertDefinition)serializer.Deserialize(new StreamReader(selectedFileName)); //if ((definition.Name != alert.AlertName) || (!definition.EmailAlert)) if (!definition.EmailAlert) { listAlerts.Remove(alert); continue; } } index++; } // If we still have some alerts left then email them if (listAlerts.Count != 0) { // get the Email Controller Task EmailController emailController = _service.GetEmailController(); // and request it to send an Alerts email on our behalf ourLog.Write("....an alerts email is required", true); emailController.SendStatusEmail(true, false, listAlerts); } } } catch (Exception ex) { ourLog.Write("Exception occurred in [CheckForAlerts], Exception Text is " + ex.Message, true); } }