/// <summary> /// Load a new scanner configuration /// </summary> public void LoadScannerConfiguration() { ILaytonView tabView = (ILaytonView)WorkItem.RootWorkItem.Workspaces[WorkspaceNames.TabWorkspace].ActiveSmartPart; // Display the load configuration screen and if we click OK load the new configuration FormLoadScannerConfiguration form = new FormLoadScannerConfiguration(tabView is AuditAgentTabView); if (form.ShowDialog() == DialogResult.OK) { try { // Use the Deserialize method to restore the object's state. _auditScannerDefinition = AuditWizardSerialization.DeserializeObject(form.FileName); } catch (Exception ex) { logger.Error("Error in LoadScannerConfiguration using " + form.FileName, ex); MessageBox.Show("Unable to load scanner configuration file", "AuditWizard", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // If the active tab is either the scanner configuration or alert monitor tab then calls // its refresh function to pick up the new scanner configuration if ((tabView is ScannerConfigurationTabView) || (tabView is AlertMonitorSettingsTabView) || tabView is AuditAgentTabView) { tabView.RefreshView(); } } }
private void ProcessScannerFiles(List <String> listScannerFileNames) { // For each of these scanners we need to validate them and read the audit data path foreach (string scannerFileName in listScannerFileNames) { // get the scanner object first AuditScannerDefinition currentScannerConfiguration = AuditWizardSerialization.DeserializeObject(scannerFileName); if (currentScannerConfiguration != null) { // Do we already have this scanner in our list? AutoLoaderFolder thisFolder = _listUploadFolders.ContainsScanner(currentScannerConfiguration); // If it doesn't already exist, add it if (thisFolder == null) { AddUploadFolder(currentScannerConfiguration); } else { CheckUploadFolder(thisFolder); } } } }
/// <summary> /// Called as the form loads - initialize the default path from the current scanner configuration /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormUploadAudits_Load(object sender, EventArgs e) { string lLastFolder = new SettingsDAO().GetSetting("LastUploadFolder", false); try { if (lLastFolder != "") { tbAuditFolder.Text = lLastFolder; } else { AuditScannerDefinition auditScannerDefinition = AuditWizardSerialization.DeserializeDefaultScannerObject(); tbAuditFolder.Text = auditScannerDefinition.DeployPathData; } if (tbAuditFolder.Text != String.Empty) { watcher.Path = tbAuditFolder.Text; watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.Filter = "*.adf"; watcher.Changed += new FileSystemEventHandler(watcher_Changed); watcher.Deleted += new FileSystemEventHandler(watcher_Changed); watcher.EnableRaisingEvents = true; RefreshList(); } } catch (ArgumentException ex) { Logger.Error(ex.Message); } }
private void PopulateMenuItemWithAgents(ToolStripMenuItem menuItem) { menuItem.DropDownItems.Clear(); // Get the path to the scanner configurations string scannerPath = Path.Combine(Application.StartupPath, @"scanners\\auditagent"); DirectoryInfo di = new DirectoryInfo(scannerPath); FileInfo[] rgFiles = di.GetFiles("*.xml"); foreach (FileInfo fi in rgFiles) { try { string scannerName = fi.Name.Replace(".xml", ""); string fileName = Path.Combine(Application.StartupPath, @"scanners\auditagent\" + scannerName + ".xml"); AuditScannerDefinition configuration = AuditWizardSerialization.DeserializeObject(fileName); ToolStripMenuItem item = new ToolStripMenuItem(); item.Tag = fileName; item.Text = scannerName; item.ToolTipText = configuration.Description; menuItem.DropDownItems.Add(item); } catch (Exception ex) { logger.Debug(ex.Message); } } }
/// <summary> /// save function for the IAdministrationView Interface /// </summary> public void Save() { if (!ValidateRequiredValues()) { return; } auditAgentScannerDefinition.ScannerName = tbName.Text; auditAgentScannerDefinition.Filename = Path.Combine(Application.StartupPath, @"scanners\auditagent\" + auditAgentScannerDefinition.ScannerName + ".xml"); if (File.Exists(auditAgentScannerDefinition.Filename)) { if (MessageBox.Show("The config file '" + auditAgentScannerDefinition.ScannerName + "' already exists." + Environment.NewLine + Environment.NewLine + "Do you wish to overwrite the file?", "AuditWizard", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } UpdateChanges(); if (AuditWizardSerialization.SerializeObjectToFile(auditAgentScannerDefinition)) { DesktopAlert.ShowDesktopAlert("The scanner configuration file '" + auditAgentScannerDefinition.ScannerName + "' has been saved."); } }
/// <summary> /// Called as this tab is activated to ensure that we display the latest possible data /// This function comes from the IAdministrationView Interface /// </summary> public void Activate() { // if we don't have a scanner, load default if (tbName.Text == String.Empty) { try { string scannerPath = Path.Combine(Application.StartupPath, "scanners") + "\\default.xml"; auditScannerDefinition = AuditWizardSerialization.DeserializeObject(scannerPath); } catch (Exception) { // if there was an error here simply log it and load blank config file // JML TODO log this error } } else { string scannerPath = Path.Combine(Application.StartupPath, "scanners") + "\\" + tbName.Text + ".xml"; auditScannerDefinition = AuditWizardSerialization.DeserializeObject(scannerPath); } // ...and then refresh the view RefreshDefaultView(); }
/// <summary> /// This function is called to check the supplied scanner to determine if it has been updated /// and if so to check and if necessary update the data folder being watched /// </summary> /// <param name="theFolder"></param> protected void CheckUploadFolder(AutoLoaderFolder aFolder) { LogFile ourLog = LogFile.Instance; try { // Get the timestamp for the file and if matches that stored exit DateTime lastWriteTime = File.GetLastWriteTime(aFolder.FileName); if (lastWriteTime == aFolder.LastTimeStamp) { return; } ourLog.Write("File timestamp indicates changes made - validating", true); // the timestamp differs meaning that the file has been updated - this means that we // will have to re-read the file and check it's data folder aFolder.LastTimeStamp = lastWriteTime; // Update the timestamp anyway AuditScannerDefinition scannerConfiguration = AuditWizardSerialization.DeserializeObject(aFolder.FileName); if (Convert.ToBoolean(config.AppSettings.Settings["disable_all_uploads"].Value)) { ourLog.Write("disable_all_uploads is turned on - removing from list of watched folders.", true); _listUploadFolders.Remove(aFolder); return; } if (!scannerConfiguration.AutoUpload) { // if the auto-upload has been changed to false then remove from the list ourLog.Write("Auto-upload is set to false - removing from list of watched folders.", true); _listUploadFolders.Remove(aFolder); return; } // Check to see if the file is in fact a valid file and if not we ignore this file but update our timestamp if (!scannerConfiguration.IsValidFile) { ourLog.Write("Scanner configuration File does not appear to be valid and will be ignored.", true); return; } // Get the data Path - has it changed? If not then return if (scannerConfiguration.DeployPathData == aFolder.DataFolder) { ourLog.Write("Scanner data path does not appear to have changed - ignoring file update.", true); return; } // Ok the path has changed so we need to change the path looked at by the watcher. aFolder.DataFolder = scannerConfiguration.DeployPathData; } catch (Exception ex) { ourLog.Write("Exception occurred in [CheckUploadFolder], Exception Text is is " + ex.Message, true); } }
private void lbScanners_SelectedIndexChanged(object sender, EventArgs e) { int selectedIndex = lbScanners.SelectedIndex; if (selectedIndex != -1) { AuditScannerDefinition configuration = AuditWizardSerialization.DeserializeObject(((AuditScannerDefinition)(lbScanners.SelectedItem)).Filename); tbDescription.Text = configuration.Description; bnOK.Enabled = true; bnDelete.Enabled = (lbScanners.Items.Count > 1); } else { tbDescription.Text = ""; bnOK.Enabled = false; } }
private void ReauditAssets() { System.Collections.Specialized.NameValueCollection ipRanges = new System.Collections.Specialized.NameValueCollection(); foreach (Asset asset in GetSelectedAssets()) { if (asset.IPAddress != String.Empty) { ipRanges.Add(asset.IPAddress, asset.IPAddress); } } SNMPDiscovery discoverer = new SNMPDiscovery(ipRanges); discoverer.Start(); // Yes - we need to check whether or not the current scanner is configured to upload audits to an FTP // site as in this case we need to create audit files for any assets discovered AuditScannerDefinition auditScannerDefinition = null; try { string scannerPath = Path.Combine(Application.StartupPath, "scanners") + "\\default.xml"; auditScannerDefinition = AuditWizardSerialization.DeserializeObject(scannerPath); } catch (Exception) { } // 8.3.4 - CMD // // If we found a scanner and it defines an FTP upload of audit files then process this // Note that we support either Upload to FTP Location or Audit to FTP which are flagged differently in the scanner if ((auditScannerDefinition != null) && (auditScannerDefinition.FTPCopyToNetwork || auditScannerDefinition.UploadSetting == AuditScannerDefinition.eUploadSetting.ftp)) { discoverer.UploadDiscoveredAssets(auditScannerDefinition); } }
private void RunThreadedNetworkDiscovery() { if (discoverer.CanRunInOwnThread) { // start the discovery NetworkDiscoveryTabView tabView = workItem.Items[Properties.Settings.Default.NetworkDiscoveryTabView] as NetworkDiscoveryTabView; if (tabView != null) { tabView.ShowStart(); } discoverer.Start(); if (runBothDiscovery) { SNMPDiscovery snmpDiscovery = new SNMPDiscovery(Utility.GetSNMPIpRanges()); discoverer = snmpDiscovery; //tabView.ShowStart(); discoverer.Start(); } // discover has completed...update subscribers and TabView if (tabView != null) { tabView.ShowComplete(); } // +8.3.3 // Did we complete an SNMP Discovery? if (discoverer is SNMPDiscovery) { // Yes - we need to check whether or not the current scanner is configured to upload audits to an FTP // site as in this case we need to create audit files for any assets discovered AuditScannerDefinition auditScannerDefinition = null; try { string scannerPath = Path.Combine(Application.StartupPath, "scanners") + "\\default.xml"; auditScannerDefinition = AuditWizardSerialization.DeserializeObject(scannerPath); } catch (Exception) { } // 8.3.4 - CMD // // If we found a scanner and it defines an FTP upload of audit files then process this // Note that we support either Upload to FTP Location or Audit to FTP which are flagged differently in the scanner if ((auditScannerDefinition != null) && (auditScannerDefinition.FTPCopyToNetwork || auditScannerDefinition.UploadSetting == AuditScannerDefinition.eUploadSetting.ftp)) { ((SNMPDiscovery)discoverer).UploadDiscoveredAssets(auditScannerDefinition); } } // -8.3.3 FireNetworkDiscoveryComplete(discoverer.ComputerList); discoveryThread = new Thread(new ThreadStart(RunThreadedNetworkDiscovery)); discoverer.NetworkDiscoveryUpdate -= discoverer_NetworkDiscoveryUpdate; discoverer = null; } }