예제 #1
0
        private static void GetBrowserWindows()
        {
            var getSniffer = sniffer.PrintBrowserTabName();

            foreach (var browser in getSniffer)
            {
                logger.WriteTransactionToEventViewer(string.Format("Detected Browser Window(s): {0} at {1} for user {2}", browser, DateTime.Now.Date, Environment.UserName));
            }
        }
        /// <summary>
        /// Sends an email notification as needed
        /// </summary>
        /// <param name="notifyType">Dictates the subject and email that is sent via notification</param>
        /// <returns></returns>
        public bool SendEmailNotification(int notifyType)
        {
            try
            {
                var credKeys = credentialKeys.RetrieveCredentials();
                foreach (var cKeys in credKeys)
                {
                    if (cKeys.Key == "User")
                    {
                        FromEmail = cKeys.Value;
                    }

                    if (cKeys.Key == "Password")
                    {
                        EmailPassword = cKeys.Value;
                    }
                }


                switch (notifyType)
                {
                case 1:     //login
                    Subject = string.Format(@"User logged in at {0:HH:mm:ss on MMddyyyy}", DateTime.Now);
                    break;

                case 2:     //restricted
                    Subject = string.Format(@"Restricted usage at {0:HH:mm:ss on MMddyyyy}", DateTime.Now);
                    break;

                case 3:     //non-restricted
                    Subject = string.Format(@"Internet usage at {0:HH:mm:ss on MMddyyyy}", DateTime.Now);
                    break;
                }

                using (SmtpClient client = new SmtpClient())
                    using (MailMessage msg = new MailMessage())
                    {
#if DEBUG
                        //Set port, host, and to emails here;
                        ToEmail    = new MailAddress("*****@*****.**");
                        SMTPPort   = 587;
                        SMTPServer = "smtp.live.com";
#else
                        //Set port, host, and to emails here;
                        FromEmail  = "*****";
                        ToEmail    = new MailAddress("*****");
                        SMTPPort   = 587;
                        SMTPServer = "smtp.live.com";
#endif
                        msg.To.Add(ToEmail);
                        msg.From    = new MailAddress(FromEmail);
                        msg.Subject = Subject;

                        //if restricted activity, send a high priority message.
                        if (notifyType == 2)
                        {
                            msg.Priority = MailPriority.High;
                        }

                        client.Port      = SMTPPort;
                        client.Host      = SMTPServer;
                        client.EnableSsl = true;


                        //put the outlook.com email and password here (masked, of course)
                        client.Credentials = new System.Net.NetworkCredential(FromEmail, EmailPassword);

                        try
                        {
                            client.Send(msg);
                            //TODO - put a logger.write event here
                            logger.WriteTransactionToEventViewer("Login Email Successfully Sent!");
                        }
                        catch (SmtpException smtpEx)
                        {
                            //if email isn't sent, write an exception to the event log
                            logger.WriteExceptionToEventViewer(smtpEx.Message);
                        }
                    }
                return(true);
            }
            catch (Exception ex)
            {
                logger.WriteExceptionToEventViewer(ex.Message);
                return(false);
            }
        }