public static void playSendMissingReportsThread(object parameterObj)
        {
            string missingAlerts = (string)parameterObj;

            using (MailMessage mail = new MailMessage())
                using (SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"))
                {
                    mail.From = new MailAddress("*****@*****.**", "Bsafe ", Encoding.UTF8);
                    Setting settingInstance = Setting.Instance;
                    mail.To.Add(settingInstance.email);
                    mail.Subject = "Alerts collected from offline mode ";
                    mail.Body    = missingAlerts;

                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "rcza voco ctyq ptal");
                    SmtpServer.EnableSsl   = true;
                    try
                    {
                        SmtpServer.Send(mail);
                        DBclient dbInstance = DBclient.Instance;
                        dbInstance.RemoveReportImmediateTable();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("fail send missing alerts\n" + ex);
                    }

                    // ShowErrorDialog("send missingAlerts\n"+ missingAlerts);
                }
        }
Esempio n. 2
0
        public string readSettingFromDB()
        {
            //string userName = Environment.UserName;

            //String projectDirectory = Environment.CurrentDirectory;
            //string filepath = Directory.GetParent(projectDirectory).Parent.FullName;
            //String[] paths = new string[] { @filepath, "files" };
            //filepath = Path.Combine(paths);
            //string setting = "";
            //DirectoryInfo d = new DirectoryInfo(filepath);//Assuming Test is your Folder
            ////ShowErrorDialog("filepath is: \n" + filepath);
            //if (!Directory.Exists(filepath))
            //{
            //    return "";
            //}

            //using (StreamReader sr = System.IO.File.OpenText(Path.Combine(filepath, "setting_" + userName + ".txt")))
            //{
            //    sr.ReadLine();
            //    sr.ReadLine();

            //    //ShowErrorDialog("id\n" + id);
            //    string line = "";
            //    while ((line = sr.ReadLine()) != null)
            //    {
            //        //ShowErrorDialog("line\n" + line);
            //        setting += line + "\r\n";
            //    }
            //}

            DBclient DBInstance = DBclient.Instance;
            string   setting    = DBInstance.getGeneralDetailsTable("setting");

            return(setting);
        }
        public static string getReportString()
        {
            DBclient DBInstance    = DBclient.Instance;
            string   settingString = DBInstance.getGeneralDetailsTable("lastReport");



            return(settingString);
        }
Esempio n. 4
0
        // send immediate alert to server
        public static void sendAlertToMail(string picName, string TriggerDescription, string triggerDetails, string triggerName)
        {
            DBclient DBInstance = DBclient.Instance;

            string[] args       = { picName, TriggerDescription, triggerDetails, triggerName };
            Thread   alertTread = new Thread(playSendAlertThread);

            alertTread.Start(args);
        }
Esempio n. 5
0
        private bool connectToExistClient()
        {
            DBclient DBInstance = DBclient.Instance;

            ip = DBInstance.getGeneralDetailsTable("ip");
            string setting = DBInstance.getGeneralDetailsTable("setting");

            Console.WriteLine("setting: " + setting + "\nip: " + ip);
            if (setting.Length > 0)
            {
                id = DBInstance.getGeneralDetailsTable("id");
                Console.WriteLine("connectToExistClient - RECONNECT");
                reConnect();
                playAllTrigers();

                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        public void setAllSetting()
        {
            triggersForAlert   = new List <string>();
            triggersForReport  = new List <string>();
            anotherSitesReport = new List <string>();
            anotherSitesIgnore = new List <string>();
            settingString      = readSettingFromDB();
            createOffensiveWordsList();
            installationSetting();
            reportFrequencyInSecond = buildReportFrequency();
            anotherSitesReport      = buildAnotherSitesReportList();
            anotherSitesIgnore      = buildAnotherSitesIgnoreList();
            buildCategoryList();// build triggersForAlert list and triggersForRepor list
            getEmail(settingString);

            // connect to DB
            DBclient DBInstance = DBclient.Instance;

            DBInstance.removeIgnoredSites(anotherSitesIgnore.ToArray());
            DBInstance.funAddCategorySiteTable(anotherSitesReport.ToArray(), "anotherSitesReport");
        }
Esempio n. 7
0
        // sara
        private void removeClient()
        {
            // ShowErrorDialog("removeeeeeeeeeeee");

            // turn off all theards
            manageMonitor.stopAllTriggers();

            // stop timer
            PeriodicReporting.stopTimer();

            // db
            DBclient DBInstance = DBclient.Instance;

            DBInstance.deleteDB();

            // restart - delete key
            RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            rkApp.DeleteValue("ClientSide.exe", false);

            System.Environment.Exit(0);
        }
Esempio n. 8
0
        //public void sendDataByParts(Socket clientSocket, string data)
        //{
        //    string subject = data.Split(new[] { '\r'}, 2)[0];
        //    string testData = data.Split(new[] { '\r' }, 2).Last();
        //    var sendData = Encoding.UTF8.GetBytes("start send data by parts\r" + subject + "\r");
        //    clientSocket.BeginSend(sendData, 0, sendData.Length, SocketFlags.None, SendCallback, clientSocket);


        //    string subData = "";
        //    string subEncrypt = "";
        //    int index = 0;
        //    int length = 20;

        //    bool lastPart = false;
        //    while (!lastPart)
        //    {

        //        if ((index + length) > testData.Length)
        //        {
        //            length = testData.Length;
        //            subData += testData.Substring(index, length);
        //            lastPart = true;
        //        }
        //        else
        //        {
        //            subData += testData.Substring(index, index + length);
        //        }


        //        Byte[] subStringByte = Encoding.UTF8.GetBytes(testData);

        //        subEncrypt = Crypto.Encryption(subData);
        //        if (subEncrypt != string.Empty)
        //        {
        //            DBclient DBInstance = DBclient.Instance;
        //            string id = DBInstance.getGeneralDetailsTable("id");

        //            sendData = Encoding.UTF8.GetBytes("sub encrypt data\r" + id + "\r" + subEncrypt);
        //            clientSocket.BeginSend(sendData, 0, sendData.Length, SocketFlags.None, SendCallback, clientSocket);
        //            index += length;
        //            length += 20;
        //        }



        //    }


        //    sendData = Encoding.UTF8.GetBytes("stop send data by parts\r" + id + "\r");
        //    clientSocket.BeginSend(sendData, 0, sendData.Length, SocketFlags.None, SendCallback, clientSocket);


        //}



        public void reConnect()
        {
            try
            {
                if (checkSocketConnections())
                {
                    return;
                }
                // Create new socket
                clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                buffer       = new byte[clientSocket.ReceiveBufferSize];

                //ShowErrorDialog("reConnect in socket: " + clientSocket.RemoteEndPoint);
                // Connect To Server
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ip), 3333);
                // The function ConnectCallback set callback to receive and send
                clientSocket.BeginConnect(endPoint, ConnectCallback, clientSocket);

                // send to server alert who missing
                DBclient DBInstance      = DBclient.Instance;
                string   immadiateAlerts = DBInstance.getReportImmediateTable();
                if (immadiateAlerts.Length > 0)
                {
                    PeriodicReporting.sendMissingReportsToMail(immadiateAlerts);
                }
            }
            catch (SocketException ex)
            {
                ShowErrorDialog("reConnect send SocketException\r\n" + ex.Message + " \n\n" + ex);
            }
            catch (ObjectDisposedException ex)
            {
                ShowErrorDialog("reConnect send ObjectDisposedException \r\n" + ex.Message + " \n\n" + ex);
            }
            catch (InvalidOperationException ex) {
                ShowErrorDialog("reConnect send InvalidOperationException \r\n" + ex.Message + " \n\n" + ex);
            }
        }
Esempio n. 9
0
        // The function is activated as soon as data is received in the socket
        private void ReceiveCallback(IAsyncResult AR)
        {
            try
            {
                clientSocket = AR.AsyncState as Socket;
                int received = clientSocket.EndReceive(AR);
                if (received == 0)
                {
                    return;
                }

                string data = Encoding.ASCII.GetString(buffer);

                var dataFromServer = data.Split(new[] { '\r', '\n', '\0' }, 2);

                DBclient DBInstance = DBclient.Instance;

                switch (dataFromServer[0])// dddd
                {
                // Get uniqe id
                case ID:
                    id = dataFromServer[1].Split('\r', '\n', '\0')[0];
                    DBInstance.fillGeneralDetailsTable("id", id);
                    //ShowErrorDialog("get id");
                    break;

                // Get Setting to implement monitoring gg
                case SETTING:
                    string setting = dataFromServer[1].Split('\0')[0];
                    setting = setting.Substring(setting.IndexOf("\n") + 1);

                    // save setting

                    DBInstance.fillGeneralDetailsTable("name", name);
                    DBInstance.fillGeneralDetailsTable("ip", ip);
                    DBInstance.fillGeneralDetailsTable("setting", setting);
                    playAllTrigers();     //This method obtains the settings string from the server

                    // Set Periodic Report
                    // PeriodicReporting.setReportPeriodic();

                    break;

                // Launch the software in live reporting mode
                case LIVE:
                    liveMode(clientSocket);
                    break;

                // Stop live reporting mode
                case STOP_LIVE:
                    // ShowErrorDialog("server send: |" + dataFromServer[0].Split('\0')[0] + "|");
                    stopLiveMode(clientSocket);
                    break;

                // Stop live reporting mode
                case LAST_REPORT:    // abo
                    Console.WriteLine("accept request to last report");
                    sendLastReport(clientSocket);
                    break;

                // Remove computer from monitoring
                case REMOVE_CLIENT:
                    removeClient();
                    break;

                default:
                    // ShowErrorDialog("server send: |" + dataFromServer[0].Split('\0')[0] + "|");
                    break;
                }

                buffer = new byte[clientSocket.ReceiveBufferSize];
                clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, clientSocket);
            }

            catch (SocketException ex)
            {
                //ShowErrorDialog("ReceiveCallback\n" + ex );
                Console.WriteLine("ReceiveCallback SocketException - RECONNECT");
                reConnect();
            }
            catch (ObjectDisposedException ex)
            {
                ShowErrorDialog("ReceiveCallback ObjectDisposedException\n " + ex.Message + " \n\n" + ex);
                Console.WriteLine("ReceiveCallback ObjectDisposedException");
            }
        }
Esempio n. 10
0
        private static void createDailyReportFile()
        {
            DateTime yesterdayDate = DateTime.Today;//.AddDays(-1)
            DBclient DBInstance    = DBclient.Instance;

            try
            {
                string   projectDirectory = Environment.CurrentDirectory;
                string   path             = Directory.GetParent(projectDirectory).Parent.FullName;
                Document Report           = new Document();
                string   date             = DateTime.UtcNow.ToString("MM-dd-yyyy");
                date = date.Replace('-', '_');

                string reportName = Environment.UserName + "_" + date + "_DailyReport.pdf";

                if (!File.Exists(Path.Combine(path, reportName)))
                {
                    PdfWriter.GetInstance(Report, new FileStream(path + "/" + reportName, FileMode.Create));
                    Report.Open();
                    Image jpg = Image.GetInstance(path + "/logo.JPG");
                    jpg.ScalePercent(12f);
                    jpg.SetAbsolutePosition(Report.PageSize.Width - 410f,
                                            Report.PageSize.Height - 130f);

                    Report.Add(jpg);
                    Report.Add(new Paragraph("\n\n\n\n\n"));
                    Report.Add(new Paragraph("DAILY REPORT FOR USER:"******"\n" + "DATE: " + yesterdayDate.ToString()));

                    // GET BROWSE HISTORY
                    string urls = DBInstance.getDailyUrlTable(yesterdayDate.ToString());
                    if (urls.Length > 0)
                    {
                        Report.Add(new Paragraph("\rWeb sites visited by the user yesterday:\r" + urls));
                    }
                    else
                    {
                        Report.Add(new Paragraph("NO SITETS TOREPORT"));
                    }

                    // GET ALL PROCCESS
                    string proccess = DBInstance.getDailyProcessTable(yesterdayDate.ToString());
                    if (proccess.Length > 0)
                    {
                        Report.Add(new Paragraph("\rProccess visited by the user yesterday:\r" + proccess));
                    }
                    else
                    {
                        Report.Add(new Paragraph("NO PROCCESS TOREPORT"));
                    }

                    Report.Close();
                    sendReportFileToMail("Daily Report " + DateTime.UtcNow.ToString("MM-dd-yyyy") + ", USER: "******"" + ex);
            }



            DBInstance.RemoveDailyUrlTable(yesterdayDate.ToString());
        }
Esempio n. 11
0
        private static void createReportFile()
        {
            stringReport = "";
            //ShowErrorDialog(getReportString());
            var      Report           = new Document();
            DBclient DBInstance       = DBclient.Instance;
            string   projectDirectory = Environment.CurrentDirectory;
            string   path             = Directory.GetParent(projectDirectory).Parent.FullName;
            string   userName         = Environment.UserName;

            PdfWriter.GetInstance(Report, new FileStream(path + "/Report.pdf", FileMode.Create));
            //PdfWriter.GetInstance(Report, new FileStream(path + "/logo.JPG", FileMode.Create));

            Report.Open();
            Image jpg = Image.GetInstance(path + "/logo.JPG");

            jpg.ScalePercent(12f);
            jpg.SetAbsolutePosition(Report.PageSize.Width - 410f,
                                    Report.PageSize.Height - 130f);

            Report.Add(jpg);

            Report.Add(new Paragraph(DateTime.Now.ToString()));
            stringReport += DateTime.Now.ToString() + "\n";

            Report.Add(new Paragraph("\n\n\n\n\n" + frequencyWord + " report for user: "******" report for user: "******"\n";

            // add bad word trigger
            string wordsTrigger = DBInstance.getTriggerById(1);

            if (wordsTrigger.Length > 0)
            {
                Report.Add(new Paragraph("\nOn the dates listed, the following words were typed:"));
                Report.Add(new Paragraph(wordsTrigger));
                stringReport += "On the dates listed, the following words were typed:\n" + wordsTrigger + "\n";
            }
            else
            {
                Report.Add(new Paragraph("\nNO TRIGGER KIND BAD WORDS TO REPORT!"));
                stringReport += "NO TRIGGER KIND BAD WORDS TO REPORT!\n";
            }

            // add site trigger
            string siteTrigger = DBInstance.getTriggerById(2);

            if (siteTrigger.Length > 0)
            {
                Report.Add(new Paragraph("\nOn the dates listed the user browsed the following sites:"));
                Report.Add(new Paragraph(siteTrigger));
                stringReport += "On the dates listed the user browsed the following sites:\n" + siteTrigger + "\n";
            }
            else
            {
                Report.Add(new Paragraph("\nNO TRIGGER KIND SITES TO REPORT!"));
                stringReport += "NO TRIGGER KIND SITES TO REPORT!\n";
            }

            // installations trigger
            string installationsTrigger = DBInstance.getTriggerById(3);

            if (installationsTrigger.Length > 0)
            {
                Report.Add(new Paragraph("\nOn the dates listed The user has downloaded the following software:"));
                Report.Add(new Paragraph(installationsTrigger));
                stringReport += "On the dates listed The user has downloaded the following software:" + installationsTrigger + "\n";
            }
            else
            {
                Report.Add(new Paragraph("\nNO TRIGGER KIND INSTALLATIONS TO REPORT!"));
                stringReport += "NO TRIGGER KIND INSTALLATIONS TO REPORT!\n";
            }

            Report.Close();

            ShowErrorDialog("report created, send mail");
            sendReportFileToMail("Report File", "Report.pdf");

            //db.printClientData();
            string pathLastReport = Path.Combine(path, "lastReport.txt");

            DBInstance.fillGeneralDetailsTable("lastReport", stringReport);
        }
Esempio n. 12
0
        private static void removeTriggers()
        {
            DBclient DBInstance = DBclient.Instance;

            DBInstance.RemoveTriggersTable();
        }
Esempio n. 13
0
        private static void playSendAlertThread(object parameterObj)
        {
            string[] args               = (string[])parameterObj;
            string   picName            = args[0];
            string   TriggerDescription = args[1];
            string   triggerDetails     = args[2];
            string   triggerName        = args[3];

            // get directory to pictures
            string projectDirectory = Environment.CurrentDirectory;
            string filepath         = Directory.GetParent(projectDirectory).Parent.FullName;


            // get Camera picture
            string[] paths = new string[] { @filepath, "files", picName };
            cameraPic = Path.Combine(paths);


            // get screenshot picture
            paths     = new string[] { @filepath, "files", "snapshot_" + picName };
            screenPic = Path.Combine(paths);

            Thread.Sleep(60000);

            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("*****@*****.**", "Bsafe ", Encoding.UTF8);
                Setting settingInstance = Setting.Instance;
                mail.To.Add(settingInstance.email);
                mail.Subject = "Alert " + TriggerDescription;

                switch (triggerName)
                {
                case ("typing"):
                    mail.Body = "The user typing word: " + triggerDetails;
                    break;

                case ("Site"):
                    mail.Body = "The user browse in site: " + triggerDetails;
                    break;

                case ("Insta"):
                    mail.Body = "The user try install app " + triggerDetails;
                    break;
                }

                Attachment attachment;
                attachment = new Attachment(cameraPic);
                mail.Attachments.Add(attachment);

                Debug.WriteLine("add camera pic");

                Attachment attachment2;
                attachment2 = new Attachment(screenPic);//sara
                mail.Attachments.Add(attachment2);

                Debug.WriteLine("add screen pic");

                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "rcza voco ctyq ptal");
                SmtpServer.EnableSsl   = true;

                SmtpServer.Send(mail);

                mail.Attachments.Dispose();
                Thread.Sleep(120000);
                if (File.Exists(cameraPic))
                {
                    File.Delete(cameraPic);
                }
                if (File.Exists(screenPic))
                {
                    File.Delete(screenPic);
                }
                Debug.WriteLine("send email seccess");
            }

            catch (SmtpException ex)
            {
                Console.WriteLine("fail send mailllll: \n" + ex);

                // if no internet - save imadiate alert in DB
                string date = DateTime.Now.ToString();

                DBclient DBInstance = DBclient.Instance;
                DBInstance.fillReportImmediateTable(triggerName, TriggerDescription, triggerDetails, date);
            }
            catch (Exception ex)
            {
                Console.WriteLine("fail send mail: \n" + ex);
            }
        }