Example #1
0
        /*public void Dispose()
         * {
         *
         * }*/

        public void Run()
        {
            Console.WriteLine("Entered Engine::Run");

            mDispatcher = Dispatcher.CurrentDispatcher;

            Console.WriteLine("Initializing program list...");
            programs = new ProgramList();
            if (!UwpFunc.IsWindows7OrLower)
            {
                Console.WriteLine("Initializing app manager...");
                appMgr = new AppManager();
            }
            Console.WriteLine("Initializing firewall...");
            firewall = new Firewall();

            Console.WriteLine("Loading program list...");
            programs.LoadList();

            Console.WriteLine("Loading firewall rules...");
            firewall.LoadRules(true);
            Console.WriteLine("Loading connection log...");
            if (App.GetConfigInt("Startup", "LoadLog", 1) != 0)
            {
                firewall.LoadLogAsync();
            }
            firewall.WatchConnections();

            Console.WriteLine("Setting up IPC host...");
            App.host = new PipeHost();
            App.host.Listen();

            mStarted.Set();

            Console.WriteLine("Starting engine timer...");

            mTimer.Tick    += new EventHandler(OnTimer_Tick);
            mTimer.Interval = new TimeSpan(0, 0, 0, 0, 10 * 1000); // every 10 seconds
            mTimer.Start();

            Dispatcher.Run();

            mTimer.Stop();

            firewall.WatchConnections(false);

            Console.WriteLine("Saving program list...");
            programs.StoreList();


            Console.WriteLine("Shuttin down IPC host...");
            App.host.Close();

            //mFinished.Set();
        }
Example #2
0
        public Firewall.Actions LookupAction(LogEntry logEntry)
        {
            Firewall.MatchAddress(logEntry.RemoteAddress, "");


            int BlockRules = 0;
            int AllowRules = 0;

            foreach (FirewallRule rule in Rules.Values)
            {
                // todo: make a map with rules by ID
                if (rule.mID.CompareTo(logEntry.mID) != 0)
                {
                    continue;
                }

                if (!rule.Enabled)
                {
                    continue;
                }
                if (rule.Direction != logEntry.Direction)
                {
                    continue;
                }

                if (!Firewall.IsEmptyOrStar(rule.LocalPorts) && !Firewall.MatchPort(logEntry.LocalPort, rule.LocalPorts))
                {
                    continue;
                }
                if (!Firewall.IsEmptyOrStar(rule.RemotePorts) && !Firewall.MatchPort(logEntry.RemotePort, rule.RemotePorts))
                {
                    continue;
                }

                //if (!Firewall.IsEmptyOrStar(rule.SrcAddresses) && !Firewall.MatchAddress(logEntry.SrcAddress, rule.SrcAddresses))
                //    continue;
                if (!Firewall.IsEmptyOrStar(rule.RemoteAddresses) && !Firewall.MatchAddress(logEntry.RemoteAddress, rule.RemoteAddresses))
                {
                    continue;
                }

                if (rule.Protocol != (int)NetFunc.KnownProtocols.Any && logEntry.Protocol != rule.Protocol)
                {
                    continue;
                }

                if (!Firewall.MatchProfiles(logEntry.Profile, rule.Profile))
                {
                    continue;
                }

                if (rule.Action == Firewall.Actions.Allow)
                {
                    AllowRules++;
                }
                else if (rule.Action == Firewall.Actions.Block)
                {
                    BlockRules++;
                }
            }

            if (BlockRules > 0)
            {
                return(Firewall.Actions.Block);
            }
            if (AllowRules > 0)
            {
                return(Firewall.Actions.Allow);
            }
            return(Firewall.Actions.Undefined);
        }