/// <summary> /// Primary constructor loads the Email configuration from the database /// </summary> public EmailConfiguration() { // Get the database object SettingsDAO lwDataAccess = new SettingsDAO(); // List of email recipients string recipientList = lwDataAccess.GetSetting(MailSettingsKeys.MailAddress, false); if (recipientList != null) { string[] recipients = recipientList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string recipient in recipients) { this.ListRecipients.Add(recipient); } } // Get the email configuration from the database Sender = lwDataAccess.GetSetting(MailSettingsKeys.MailSender, false); // It's possible that the Port hasn't been set so this conversion could fail try { Port = Convert.ToInt32(lwDataAccess.GetSetting(MailSettingsKeys.MailPort, false)); } catch (Exception) { Port = 23; } Server = lwDataAccess.GetSetting(MailSettingsKeys.MailServer, false); RequiresAuthentication = lwDataAccess.GetSettingAsBoolean(MailSettingsKeys.MailRequiresAuthentication, false); UserName = lwDataAccess.GetSetting(MailSettingsKeys.MailUserName, false); Password = lwDataAccess.GetSetting(MailSettingsKeys.MailPassword, true); SSLEnabled = lwDataAccess.GetSettingAsBoolean(MailSettingsKeys.MailSSLEnabled, false); //Added for ID 66125/66652 }
private void Form_Load(object sender, EventArgs e) { SettingsDAO settingDAO = new SettingsDAO(); cbEnableScan.Checked = settingDAO.GetSettingAsBoolean("AutoScanNetwork", false); cbDeployAgent.Checked = settingDAO.GetSettingAsBoolean("AutoScanDeployAgent", false); string intervalUnits = settingDAO.GetSetting("AutoScanIntervalValue", false); tbScanInterval.Text = (intervalUnits == String.Empty) ? "1" : intervalUnits; string intervalPeriod = settingDAO.GetSetting("AutoScanIntervalUnits", false); cbScanInterval.SelectedItem = (intervalPeriod == String.Empty) ? "days" : intervalPeriod; bnApply.Enabled = false; }
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); }
public FormAlertLog(DateTime startDate) { Application.UseWaitCursor = false; InitializeComponent(); SettingsDAO lwDataAccess = new SettingsDAO(); cbShowNewAtStartup.Checked = lwDataAccess.GetSettingAsBoolean(DatabaseSettingsKeys.Setting_ShowNewAlertsAtStartup, false); // Populate the alerts dtpStartDateTime.Value = startDate; // ...and populate the control Populate(); }
/// <summary> /// This function is called once and once only during a run of the program. We call this /// from the main 'ActivateWorkItem' function which may be called multiple times. As such /// we guard against performing these actions either too early or multiple times /// </summary> protected void PerformInitializationActions() { // Show that we have performed the initialization actions now _initializationDone = true; // First of all we need to allow the user to login to the system if security has been enabled UsersDAO awDataAccess = new UsersDAO(); bool securityEnabled = awDataAccess.SecurityStatus(); if (securityEnabled) { FormLogin loginform = new FormLogin(); if (loginform.ShowDialog() != DialogResult.OK) { Application.Exit(); return; } // If we are logged in as a USER then we need to disable the Administration Tab User loggedInUser = loginform.LoggedInUser; if (loggedInUser.AccessLevel != 0) { List <WorkItem> workItemList = (List <WorkItem>)workItem.RootWorkItem.WorkItems.FindByType(typeof(AdministrationWorkItem)); AdministrationWorkItem administrationWorkItem = workItemList[0] as AdministrationWorkItem; administrationWorkItem.Terminate(); AdministrationWorkItemController controller = administrationWorkItem.Controller as AdministrationWorkItemController; controller.HideWorkspace(); } } // Display the startup wizard now if required if (!Properties.Settings.Default.DoNotShowWizard) { RunStartupWizard(); } // Ok Logged in - do we need to display any (New) Alerts? SettingsDAO lwDataAccess = new SettingsDAO(); if (lwDataAccess.GetSettingAsBoolean(DatabaseSettingsKeys.Setting_ShowNewAlertsAtStartup, false)) { ShowNewAlerts(); } }
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; }
/// <summary> /// Perform initialization of fields on the Email tab /// </summary> public void InitializeEmailSettings() { SettingsDAO lSettingsDao = new SettingsDAO(); tbSendingEmailAddress.Text = lSettingsDao.GetSetting(MailSettingsKeys.MailSender, false); tbRecipientEmailAddress.Text = lSettingsDao.GetSetting(MailSettingsKeys.MailAddress, false); smtpTextBox.Text = lSettingsDao.GetSetting(MailSettingsKeys.MailServer, false); string strPort = lSettingsDao.GetSetting(MailSettingsKeys.MailPort, false); int port = 0; if (strPort != String.Empty) { port = Convert.ToInt32(strPort); } if (port != 0) { emailForm.Port = port; } emailForm.UseAuthentication = lSettingsDao.GetSettingAsBoolean(MailSettingsKeys.MailRequiresAuthentication, false); if (emailForm.UseAuthentication) { emailForm.Username = lSettingsDao.GetSetting(MailSettingsKeys.MailUserName, false); emailForm.Password = lSettingsDao.GetSetting(MailSettingsKeys.MailPassword, true); } emailForm.EnabledSSL = lSettingsDao.GetSettingAsBoolean(MailSettingsKeys.MailSSLEnabled, false);// Added for ID 66125/66652 // Set the mail frequency string mailFrequency = lSettingsDao.GetSetting(MailSettingsKeys.MailFrequency, false); switch (mailFrequency) { case MailFrequencyValues.Daily: dailyRadioButton.Checked = true; break; case MailFrequencyValues.Weekly: weeklyRadioButton.Checked = true; break; case MailFrequencyValues.Monthly: monthlyRadioButton.Checked = true; break; default: neverRadioButton.Checked = true; break; } // email type if (lSettingsDao.GetSettingAsBoolean("EmailAsHtml", true)) { rbHtml.Checked = true; } else { rbText.Checked = true; } // Check if the settings are valid CheckEmailConfiguration(); }
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; } }
public void InsertComputer(string assetName, string groupName, string ipAddress, string macAddress) { LocationsDAO lwDataAccess = new LocationsDAO(); SettingsDAO lSettingsDao = new SettingsDAO(); // We need to get the root item as all of the domains need to be parented to this System.Data.DataTable table = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.domain)); AssetGroup rootGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.domain); // Get the child domains - as domains are single level we do not need to recurse rootGroup.Populate(false, false, true); // We'll loop through the domains first and add then to the database recovering their ids so that // we only have to do this once. // Does this domain already exist? AssetGroup childGroup; lock (this) { childGroup = rootGroup.IsChildGroup(groupName); // No - add it as a new group both to the database and to the parent if (childGroup == null) { childGroup = new AssetGroup(AssetGroup.GROUPTYPE.domain); childGroup.Name = groupName; childGroup.ParentID = rootGroup.GroupID; childGroup.GroupID = lwDataAccess.GroupAdd(childGroup); rootGroup.Groups.Add(childGroup); } } string vendor = String.Empty; try { if (macAddress != String.Empty) { // // CMD IMPORTANT UNCOMMENT THESE LINES // using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.Combine(Application.StartupPath, "oui.txt"))) // { // string line; // while ((line = sr.ReadLine()) != null) // { // if (line.StartsWith(macAddress.Substring(0, 8))) // { // if (line.Substring(18).ToUpper().StartsWith("APPLE")) // { // vendor = line.Substring(18); // break; // } // } // } // } } } catch (FormatException) { } // Now that we have the ID of the group (even if we just added the group) we can now // add the asset to the database also. Asset newAsset = new Asset(); newAsset.Name = assetName; newAsset.MACAddress = macAddress.Replace('-', ':'); newAsset.Make = vendor; if (vendor.ToUpper().StartsWith("APPLE")) { // add as an Apple Device assetTypes.Populate(); AssetType parentAssetType = assetTypes.FindByName("Apple Devices"); if (parentAssetType == null) { // Now create a child of this asset type parentAssetType = new AssetType(); parentAssetType.Name = "Apple Devices"; parentAssetType.Auditable = false; parentAssetType.Icon = "apple.png"; parentAssetType.ParentID = 0; parentAssetType.Add(); // Update the internal list assetTypes.Add(parentAssetType); } assetTypes.Populate(); parentAssetType = assetTypes.FindByName("Apple Devices"); AssetType childAssetType = assetTypes.FindByName("Apple Device"); if (childAssetType == null) { // Now create a child of this asset type childAssetType = new AssetType(); childAssetType.Name = "Apple Device"; childAssetType.Auditable = false; childAssetType.Icon = parentAssetType.Icon; childAssetType.ParentID = parentAssetType.AssetTypeID; childAssetType.Add(); // Update the internal list assetTypes.Add(childAssetType); } assetTypes.Populate(); childAssetType = assetTypes.FindByName("Apple Device"); newAsset.AssetTypeID = childAssetType.AssetTypeID; } AssetList assetList = new AssetList(new AssetDAO().GetAssets(0, AssetGroup.GROUPTYPE.userlocation, false), true); bool bUpdateAsset = true; bool bSNMPAsset = false; bool bExistingAuditedAsset = false; foreach (Asset existingAsset in assetList) { if ((existingAsset.AgentVersion == "SNMP") && (existingAsset.IPAddress == ipAddress)) { bSNMPAsset = true; break; } if ((assetName == existingAsset.Name) && (groupName == existingAsset.Domain)) { // this asset already exists - only need to check if domain or IP have changed // if they have, send it away to be updated if (existingAsset.IPAddress != ipAddress || existingAsset.DomainID != childGroup.GroupID) { newAsset = existingAsset; newAsset.IPAddress = newAsset.IPAddress != ipAddress ? ipAddress : newAsset.IPAddress; newAsset.DomainID = newAsset.DomainID != childGroup.GroupID ? childGroup.GroupID : newAsset.DomainID; } else { // asset exists, nothing has changed so don't process bUpdateAsset = false; } break; } if (!bSNMPAsset && existingAsset.IPAddress == ipAddress && existingAsset.Domain != newAsset.Domain) { bExistingAuditedAsset = true; //check for any asset name change if so update asset with audittrail entry if (existingAsset.Name != assetName) { string strOldValue = existingAsset.Name; newAsset = existingAsset; newAsset.Name = assetName; newAsset.Update(); AuditTrailDAO objAuditTrailDAO = new AuditTrailDAO(); // Build a blank AuditTrailEntry AuditTrailEntry ate = CreateAteForAssetNameChange(newAsset); ate.Key = ate.Key + "|" + "Computer Name"; ate.OldValue = strOldValue; ate.NewValue = assetName; objAuditTrailDAO.AuditTrailAdd(ate); } } } if (bUpdateAsset && !bSNMPAsset && !bExistingAuditedAsset) { newAsset.Domain = childGroup.Name; newAsset.DomainID = childGroup.GroupID; newAsset.IPAddress = ipAddress; // Add the asset newAsset.Add(); if (lSettingsDao.GetSettingAsBoolean("AutoScanNetwork", false) && lSettingsDao.GetSettingAsBoolean("AutoScanDeployAgent", false)) { string scannerPath = System.IO.Path.Combine(Application.StartupPath, "scanners") + "\\auditagent\\default.xml"; System.IO.File.Copy(scannerPath, "AuditAgent\\AuditAgent.xml", true); Operation newOperation = new Operation(newAsset.AssetID, Operation.OPERATION.deployagent); newOperation.Add(); } } if (!bSNMPAsset) { Interlocked.Increment(ref _foundCounter); FireNetworkDiscoveryUpdate(new DiscoveryUpdateEventArgs(_foundCounter.ToString(), "Computer", _maximumCount, 0)); } }