示例#1
0
        //Method that handles monitoring Whitelist
        public static void monitorWhitelist(object state)
        {
            //Run a loop to continue running service every 15 seconds
            while (!BW_Service._stopping)
            {
                Thread.Sleep(100);
                List <KeyValuePair <string, Application> > toRemovePrograms = null;
                List <KeyValuePair <string, Website> >     toRemoveWebsites = null;
                //Check Whitelist with current running programs
                foreach (KeyValuePair <string, Application> p in _programs)
                {
                    //Compare the running times to the time limit. If Over the time limit, remove from whitelist and add to blacklist
                    if (p.Value.getLimit() != 0 && p.Value.getRuntime().TotalSeconds > p.Value.getLimit())
                    {
                        FireBaseFunctions.addToList(p.Key.ToLower(), 0, "black", "programs");
                        FireBaseFunctions.removeFromList(p.Key.ToLower(), "white", "programs");
                        if (toRemovePrograms == null)
                        {
                            toRemovePrograms = new List <KeyValuePair <string, Application> >();
                            toRemovePrograms.Add(p);
                        }
                    }
                }
                if (toRemovePrograms != null)
                {
                    foreach (KeyValuePair <string, Application> p in toRemovePrograms)
                    {
                        _programs.Remove(p.Key);
                    }
                }

                //Check Whitelist with current running websites
                foreach (KeyValuePair <string, Website> w in _websites)
                {
                    if (w.Value.getTimeLimit() != -600 && w.Value.getRuntime().TotalSeconds > w.Value.getTimeLimit())
                    {
                        string website = w.Value.getWebURL().ToLower().Replace("www.", "").Replace('.', '*');
                        FireBaseFunctions.addToList(website, 0, "black", "websites");
                        FireBaseFunctions.removeFromList(website, "white", "websites");
                        if (toRemoveWebsites == null)
                        {
                            toRemoveWebsites = new List <KeyValuePair <string, Website> >();
                            toRemoveWebsites.Add(w);
                        }
                    }
                }
                if (toRemoveWebsites != null)
                {
                    foreach (KeyValuePair <string, Website> w in toRemoveWebsites)
                    {
                        _websites.Remove(w.Key);
                    }
                }
            }

            BW_Service._stoppedEvent.Set();

            //END monitorWhitelist method
        }
示例#2
0
        /*////////////////////////////////////////////////
         * /
         * /			Service Command Processing
         * /
         * /////////////////////////////////////////////////*/

        //This Method is responsible for processing the Received messages from the clients
        //CHANGE, change once communications protocol is setup for sure
        private void processCommands(MessageEventArgs e)
        {
            //Split up the command, CHANGE once we decide on what character to split by

            /*
             * commandReceived[0] = Requester
             * commandReceived[1] = Request/Command
             * commandReceived[2] = RequestNumber
             * commandReceived[3] = Parameters
             */

            String[] commandRecieved = e.Data.Split(':');
            string   response;

            //Use a switch statement that will decide what will happen
            switch (commandRecieved[1].ToLower())
            {
            //Query the current security level set
            case "request_securitylevel":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions._securityLevel));
                break;

            //Change the security level
            case "set_securitylevel":
                response = FireBaseFunctions.changeSecurityLevel(commandRecieved[3]);
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            /////////////////////////////////////
            // Requesting lists
            /////////////////////////////////////
            case "request_blacklistprograms":
                response = FireBaseFunctions.requestList("black", "programs");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_blacklistwebsites":
                response = FireBaseFunctions.requestList("black", "websites");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_whitelistprograms":
                response = FireBaseFunctions.requestList("white", "programs");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_whitelistwebsites":
                response = FireBaseFunctions.requestList("white", "websites");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            /////////////////////////////////////
            // Requesting removal from lists
            /////////////////////////////////////
            case "request_removefromblacklistprograms":
                response = FireBaseFunctions.removeFromList(commandRecieved[3].ToLower(), "black", "programs");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_removefromblacklistwebsites":
                response = FireBaseFunctions.removeFromList(commandRecieved[3].ToLower(), "black", "websites");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_removefromwhitelistprograms":
                response = FireBaseFunctions.removeFromList(commandRecieved[3].ToLower(), "white", "programs");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_removefromwhitelistwebsites":
                response = FireBaseFunctions.removeFromList(commandRecieved[3].ToLower(), "white", "websites");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;


            /////////////////////////////////////
            // Requesting add to lists
            /////////////////////////////////////
            case "request_addtoblacklistprograms":
                response = FireBaseFunctions.addToList(commandRecieved[3].ToLower(), 0, "black", "programs");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_addtoblacklistwebsites":
                response = FireBaseFunctions.addToList(commandRecieved[3].ToLower(), 0, "black", "websites");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_addtowhitelistprograms":
                String[] programToAdd = commandRecieved[3].Split(',');
                response = FireBaseFunctions.addToList(programToAdd[0].ToLower(), Int32.Parse(programToAdd[1]), "white", "programs");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_addtowhitelistwebsites":
                String[] websiteToAdd = commandRecieved[3].Split(',');
                response = FireBaseFunctions.addToList(websiteToAdd[0].ToLower(), Int32.Parse(websiteToAdd[1]), "white", "websites");
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            /////////////////////////////////////
            // Monitoring  Commands
            /////////////////////////////////////
            case "request_programisrunning":
                Send(String.Format("{0}:{1}", e.Data, Monitor.isRunning(commandRecieved[3])));
                break;

            case "request_timespentprogram":
                Send(String.Format("{0}:{1}", e.Data, Monitor.programRuntime(commandRecieved[3])));
                break;

            case "request_timeremainingprogram":
                Send(String.Format("{0}:{1}", e.Data, Monitor.programRemainingTime(commandRecieved[3])));
                break;

            case "request_addTime":
                Send(String.Format("{0}:{1}", e.Data, Monitor.programAddTime(commandRecieved[3].Split(',')[0], int.Parse(commandRecieved[3].Split(',')[1]))));
                break;

            case "request_totaltimeallocatedprogram":
                Send(String.Format("{0}:{1}", e.Data, Monitor.allocatedTime("program", commandRecieved[3])));
                break;

            case "request_totaltimeallocatedwebsite":
                Send(String.Format("{0}:{1}", e.Data, Monitor.allocatedTime("website", commandRecieved[3])));
                break;

            case "request_timeremainingwebsite":
                Send(String.Format("{0}:{1}", e.Data, Monitor.websiteRemainingTime(commandRecieved[3])));
                break;

            case "request_timespentwebsite":
                Send(String.Format("{0}:{1}", e.Data, Monitor.websiteRuntime(commandRecieved[3])));
                break;

            /////////////////////////////////////
            // Parent Settings Commands
            /////////////////////////////////////
            case "request_notificationcanemail":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.requestSettings("can_email")));
                break;

            case "request_notificationcansms":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.requestSettings("can_sms")));
                break;

            case "request_notificationemailaddress":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.requestSettings("parent_email")));
                break;

            case "request_notificationsmsnumber":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.requestSettings("parent_sms")));
                break;

            case "set_notificationemailbool":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.updateSettings("can_email", commandRecieved[3])));
                break;

            case "set_notificationsmsbool":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.updateSettings("can_sms", commandRecieved[3])));
                break;

            case "set_notificationsms":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.updateSettings("sms", commandRecieved[3])));
                break;

            case "set_notificationemail":
                Send(String.Format("{0}:{1}", e.Data, FireBaseFunctions.updateSettings("email", commandRecieved[3])));
                break;

            /////////////////////////////////////////////////////////////
            // Extensions Recieving data, update dict in monitoring class
            /////////////////////////////////////////////////////////////
            case "logstarttime":
                Monitor.addToWebsiteList(commandRecieved[4], commandRecieved[3]);
                //Send("ok");		//For Testing
                break;

            case "logendtime":
                Monitor.websiteListEndTime(commandRecieved[4], commandRecieved[3]);
                break;

            case "request_programlist":
                response = String.Join(",", new String[] { "Spotify", "MinecraftLauncher", "Chrome", "Firefox", "Calculator", "Notepad" });
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_programsused":
                response = String.Join(",", Monitor.getProgramsRan());
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_websitesvisited":
                response = String.Join(",", Monitor.getWebsitesVisited());
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            /////////////////////////////////////////////////////////////
            // updated the total computer time
            /////////////////////////////////////////////////////////////

            case "request_totalcomputertime":
                response = FireBaseFunctions.queryComputerTime().ToString();
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "request_remainingcomputertime":
                response = Monitor.getRemainingComputerTime().ToString();
                Send(String.Format("{0}:{1}", e.Data, response));
                break;

            case "set_totalcomputertime":
                response = FireBaseFunctions.changeComputerTime(int.Parse(commandRecieved[3]));
                Send(String.Format("{0}:{1}", e.Data, response));
                break;


            //Command not found, or incorrect format
            default:
                Send(String.Format("{0}:{1}", e.Data, "command not found"));
                break;
            }
        }