Пример #1
0
        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;
        }
Пример #2
0
        private void CheckTasks()
        {
            UltraCalendarInfo ultraCalendarInfo = new UltraCalendarInfo();

            ultraCalendarInfo.AllowRecurringAppointments = true;
            TaskSchedulesDAO lTaskSchedulesDAO = new TaskSchedulesDAO();
            SettingsDAO      lSettingsDAO      = new SettingsDAO();
            Appointment      appointment;
            object           rawAppointmentData;

            try
            {
                foreach (DataRow row in lTaskSchedulesDAO.GetAllAppointments().Rows)
                {
                    rawAppointmentData = row["_APPOINTMENTDATA"];

                    if (rawAppointmentData is byte[] == false)
                    {
                        continue;
                    }

                    appointment         = Appointment.FromBytes(rawAppointmentData as byte[]);
                    appointment.DataKey = row[0];
                    ultraCalendarInfo.Appointments.Add(appointment);
                }

                string strLastReportRunTime = lSettingsDAO.GetSetting("LastTaskReportRun", false);

                DateTime lLastReportRunDateTime = (strLastReportRunTime == "") ? DateTime.MinValue : Convert.ToDateTime(strLastReportRunTime);
                DateTime lReportRunTime         = DateTime.Now;

                AppointmentsSubsetCollection expiredAppointments = ultraCalendarInfo.GetAppointmentsInRange(lLastReportRunDateTime, lReportRunTime);
                lSettingsDAO.SetSetting("LastTaskReportRun", DateTime.Now.ToString(), false);

                foreach (Appointment expiredAppointment in expiredAppointments)
                {
                    // need to re-check that this appointment is between the LastTaskReportRun date and DateTime.Now
                    // there is a hole in the ultraCalendarInfo.GetAppointmentsInRange logic above
                    if ((lLastReportRunDateTime < expiredAppointment.StartDateTime) && (lReportRunTime > expiredAppointment.StartDateTime))
                    {
                        string lSubject = String.Format("The following task is due at {0}." + Environment.NewLine + Environment.NewLine +
                                                        expiredAppointment.Subject, expiredAppointment.StartDateTime.ToString());

                        DesktopAlert.ShowDesktopAlertForTasks(lSubject, (int)expiredAppointment.DataKey);

                        NewsFeed.AddNewsItem(NewsFeed.Priority.Information, "Task due: " + expiredAppointment.Subject);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Initialize this tab
        /// </summary>
        private void InitializeTools()
        {
            SettingsDAO lwDataAccess  = new SettingsDAO();
            string      remoteDesktop = lwDataAccess.GetSetting("RemoteDesktopCommand", false);

            if (remoteDesktop == "")
            {
                remoteDesktop = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.System), "mstsc.exe /v:%A");
            }
            tbRemoteDesktop.Text = remoteDesktop;
        }
Пример #4
0
        /// <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
        }
        /// <summary>
        /// Initialize this tab
        /// </summary>
        private void InitializeTab()
        {
            RefreshAlertMonitors();

            // Set the alert monitor email settings
            SettingsDAO lSettingsDao = new SettingsDAO();

            // Get time first to prevent it from being reset
            string time = lSettingsDao.GetSetting(DatabaseSettings.Setting_AlertMonitorEmailTime, false);

            if (time == "")
            {
                time = "18:00";
            }
            DateTime startTime = DateTime.Parse(time);

            udteEmailAtTime.DateTime = startTime;
            //
            string mailFrequency = lSettingsDao.GetSetting(DatabaseSettings.Setting_AlertMonitorEmailFrequency, false);

            hourlyRadioButton.Checked = ((mailFrequency == "") || (mailFrequency == DatabaseSettings.Setting_AlertMonitorEmailHourly));
            dailyRadioButton.Checked  = !hourlyRadioButton.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();
        }
Пример #7
0
        private void HandleCalendarEvent()
        {
            LogFile ourLog = new LogFile();

            try
            {
                SettingsDAO        lSettingsDAO        = new SettingsDAO();
                ReportSchedulesDAO lReportSchedulesDAO = new ReportSchedulesDAO();
                Appointment        appointment;
                object             rawAppointmentData;
                ultraCalendarInfo.Appointments.Clear();

                foreach (DataRow row in lReportSchedulesDAO.GetAllAppointments().Rows)
                {
                    rawAppointmentData = row["_APPOINTMENTDATA"];

                    if (rawAppointmentData is byte[] == false)
                    {
                        continue;
                    }

                    appointment = Appointment.FromBytes(rawAppointmentData as byte[]);
                    ultraCalendarInfo.Appointments.Add(appointment);
                }

                string strLastReportRunTime = lSettingsDAO.GetSetting("LastReportRun", false);

                DateTime lLastReportRunDateTime = (strLastReportRunTime == "") ? DateTime.MinValue : Convert.ToDateTime(strLastReportRunTime);
                DateTime lReportRunTime         = DateTime.Now;

                AppointmentsSubsetCollection expiredAppointments = ultraCalendarInfo.GetAppointmentsInRange(lLastReportRunDateTime, lReportRunTime);
                lSettingsDAO.SetSetting("LastReportRun", lReportRunTime.ToString(), false);

                foreach (Appointment expiredAppointment in expiredAppointments)
                {
                    // need to re-check that this appointment is between the LastTaskReportRun date and DateTime.Now
                    // there is a hole in the ultraCalendarInfo.GetAppointmentsInRange logic above
                    if ((lLastReportRunDateTime < expiredAppointment.StartDateTime) && (lReportRunTime > expiredAppointment.StartDateTime))
                    {
                        string[] lSubject        = expiredAppointment.Subject.Split('|');
                        string   lReportCategory = "";
                        string   lReportName     = "";

                        if (lSubject.Length == 2)
                        {
                            lReportCategory = lSubject[0];
                            lReportName     = lSubject[1];
                        }
                        else if (lSubject.Length == 3)
                        {
                            lReportCategory = lSubject[0];
                            lReportName     = lSubject[1] + " | " + lSubject[2];
                        }

                        if (lReportCategory.StartsWith("Custom Report"))
                        {
                            int lReportId = Convert.ToInt32(expiredAppointment.Description);
                            emailController.SendCustomReportByEmail(expiredAppointment.Subject, lReportId, expiredAppointment.Location);
                        }
                        else if (lReportCategory.StartsWith("Compliance Report"))
                        {
                            int lReportId = Convert.ToInt32(expiredAppointment.Description);
                            emailController.SendComplianceReportByEmail(expiredAppointment.Subject, lReportId, expiredAppointment.Location);
                        }
                        else if (lReportCategory.StartsWith("User-Defined SQL Report"))
                        {
                            int lReportId = Convert.ToInt32(expiredAppointment.Description);
                            emailController.SendSQLReportByEmail(expiredAppointment.Subject, lReportId, expiredAppointment.Location);
                        }
                        else
                        {
                            emailController.SendReportByEmail(expiredAppointment.Subject, expiredAppointment.Location);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ourLog.Write(ex.Message, true);
            }
        }
Пример #8
0
        /// <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);
            }
        }