Ejemplo n.º 1
0
        public string GetRuleDescription(FirewallRuleEx rule, bool AlwaysMake = false)
        {
            if (rule.Description != null && rule.Description.Length > 0 && !AlwaysMake)
            {
                return(rule.Description);
            }

            string DescrStr = "";

            switch (rule.Action)
            {
            case FirewallRule.Actions.Allow: DescrStr += Translate.fmt("str_allow") + " "; break;

            case FirewallRule.Actions.Block: DescrStr += Translate.fmt("str_block") + " "; break;
            }

            switch (rule.Direction)
            {
            case FirewallRule.Directions.Inbound: DescrStr += Translate.fmt("str_inbound") + " "; break;

            case FirewallRule.Directions.Outbound: DescrStr += Translate.fmt("str_outbound") + " "; break;
            }

            DescrStr += ProgramControl.FormatProgID(rule.ProgID);

            // todo: add more info

            return(DescrStr);
        }
Ejemplo n.º 2
0
        public RuleItemControl(FirewallPreset.SingleRule rule, FirewallRuleEx fwRule, FirewallPreset firewallPreset)
        {
            InitializeComponent();

            int CustomMode = 0;

            if (firewallPreset.OnState == ProgramConfig.AccessLevels.CustomConfig)
            {
                CustomMode |= 1;
            }
            if (firewallPreset.OffState == ProgramConfig.AccessLevels.CustomConfig)
            {
                CustomMode |= 2;
            }

            PrepPresetCmb(cmbPreset, this, CustomMode);

            FwRule = fwRule;
            DoUpdate(rule);

            rect.MouseDown        += new MouseButtonEventHandler(rect_Click);
            label.MouseDown       += new MouseButtonEventHandler(rect_Click);
            info.PreviewMouseDown += new MouseButtonEventHandler(rect_Click);

            //toggle.Click += new RoutedEventHandler(toggle_Click);
        }
Ejemplo n.º 3
0
        private bool MakeCustom(Program prog, UInt64 expiration, ConEntry entry = null)
        {
            FirewallRuleEx rule = new FirewallRuleEx()
            {
                guid = null, Profile = (int)FirewallRule.Profiles.All, Interface = (int)FirewallRule.Interfaces.All, Enabled = true
            };

            rule.SetProgID(prog.ID);
            rule.Name     = FirewallManager.MakeRuleName(FirewallManager.CustomName, expiration != 0, prog.Description);
            rule.Grouping = FirewallManager.RuleGroup;

            if (entry != null)
            {
                rule.Direction = entry.Entry.FwEvent.Direction;
                rule.Protocol  = (int)entry.Entry.FwEvent.Protocol;
                switch (entry.Entry.FwEvent.Protocol)
                {
                /*case (int)FirewallRule.KnownProtocols.ICMP:
                 * case (int)FirewallRule.KnownProtocols.ICMPv6:
                 *
                 *  break;*/
                case (int)FirewallRule.KnownProtocols.TCP:
                case (int)FirewallRule.KnownProtocols.UDP:
                    rule.LocalPorts  = "*";
                    rule.RemotePorts = entry.Entry.FwEvent.RemotePort.ToString();
                    break;
                }
                rule.LocalAddresses  = "*";
                rule.RemoteAddresses = entry.Entry.FwEvent.RemoteAddress.ToString();
            }
            else
            {
                rule.Direction = FirewallRule.Directions.Bidirectiona;
            }

            RuleWindow ruleWnd = new RuleWindow(new List <Program>()
            {
                prog
            }, rule);

            ruleWnd.Topmost = true;
            if (ruleWnd.ShowDialog() != true)
            {
                return(false);
            }

            if (!App.client.UpdateRule(rule, expiration))
            {
                MessageBox.Show(Translate.fmt("msg_rule_failed"), App.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public PresetFirewall()
        {
            InitializeComponent();

            ProgramControl.PrepAccessCmb(cmbOnAccess);
            ProgramControl.PrepAccessCmb(cmbOffAccess);

            RuleList = new ControlList <RuleItemControl, FirewallPreset.SingleRule>(this.ruleScroll, (rule) =>
            {
                FirewallRuleEx FwRule = Rules.Find(x => x.guid.Equals(rule.RuleId));
                var ctrl          = new RuleItemControl(rule, FwRule, FirewallPreset);
                ctrl.RuleChanged += Ctrl_RuleChanged;
                return(ctrl);
            }, (rule) => rule.RuleId);
        }
Ejemplo n.º 5
0
            public void Update(FirewallRuleEx rule)
            {
                Rule = rule;

                NotifyPropertyChanged(null); // update all
            }
Ejemplo n.º 6
0
 public RuleItem(FirewallRuleEx rule)
 {
     Rule = rule;
 }
Ejemplo n.º 7
0
 public RuleItem(FirewallRuleEx rule, Program prog = null)
 {
     Rule = rule;
     Prog = prog;
 }
Ejemplo n.º 8
0
        public RuleWindow(List <Program> progs, FirewallRuleEx rule)
        {
            InitializeComponent();

            this.Title = Translate.fmt("wnd_rule");

            this.grpRule.Header = Translate.fmt("lbl_rule");
            this.lblName.Text   = Translate.fmt("lbl_name");
            this.lblGroup.Text  = Translate.fmt("lbl_group");

            this.grpProgram.Header  = Translate.fmt("lbl_program");
            this.lblProgram.Text    = Translate.fmt("lbl_program");
            this.lblExecutable.Text = Translate.fmt("lbl_exe");
            this.lblService.Text    = Translate.fmt("lbl_svc");
            this.lblApp.Text        = Translate.fmt("lbl_app");

            this.grpAction.Header = Translate.fmt("grp_action");
            this.lblAction.Text   = Translate.fmt("lbl_action");

            this.radProfileAll.Content    = Translate.fmt("lbl_prof_all");
            this.radProfileCustom.Content = Translate.fmt("lbl_prof_sel");
            this.chkPublic.Content        = Translate.fmt("lbl_prof_pub");
            this.chkDomain.Content        = Translate.fmt("lbl_prof_dmn");
            this.chkPrivate.Content       = Translate.fmt("lbl_prof_priv");

            this.radNicAll.Content    = Translate.fmt("lbl_itf_all");
            this.radNicCustom.Content = Translate.fmt("lbl_itf_select");
            this.chkLAN.Content       = Translate.fmt("lbl_itf_lan");
            this.chkVPN.Content       = Translate.fmt("lbl_itf_vpn");
            this.chkWiFi.Content      = Translate.fmt("lbl_itf_wifi");

            this.grpNetwork.Header = Translate.fmt("grp_network");
            this.lblDirection.Text = Translate.fmt("lbl_direction");
            this.lblProtocol.Text  = Translate.fmt("lbl_protocol");

            this.lblLocalPorts.Text  = Translate.fmt("lbl_local_port");
            this.lblRemotePorts.Text = Translate.fmt("lbl_remote_port");

            this.lblICMP.Text = Translate.fmt("lbl_icmp");

            this.lblLocalIP.Text  = Translate.fmt("lbl_local_ip");
            this.lblRemoteIP.Text = Translate.fmt("lbl_remote_ip");

            this.btnOK.Content     = Translate.fmt("lbl_ok");
            this.btnCancel.Content = Translate.fmt("lbl_cancel");

            Rule = rule;
            bool bNew = Rule.guid == null;

            viewModel   = new RuleWindowViewModel();
            DataContext = viewModel;

            //txtName.Text = Rule.Name;
            viewModel.RuleName   = Rule.Name;
            cmbGroup.ItemsSource = GroupModel.GetInstance().GetGroups();
            if (!WpfFunc.CmbSelect(cmbGroup, Rule.Grouping))
            {
                cmbGroup.Text = Rule.Grouping;
            }
            txtInfo.Text = Rule.Description;

            if (progs != null)
            {
                foreach (Program prog in progs)
                {
                    ContentControl program = new ContentControl()
                    {
                        Content = prog.Description, Tag = prog.ID
                    };
                    cmbProgram.Items.Add(program);
                    if (Rule.ProgID != null && prog.ID.CompareTo(Rule.ProgID) == 0)
                    {
                        cmbProgram.SelectedItem = program;
                    }
                }
            }
            else
            {
                ContentControl program = new ContentControl()
                {
                    Content = ProgramControl.FormatProgID(Rule.ProgID), Tag = Rule.ProgID
                };
                cmbProgram.Items.Add(program);
                cmbProgram.SelectedItem = program;
            }

            txtPath.Text    = rule.BinaryPath ?? "";
            txtService.Text = rule.ServiceTag ?? "";
            txtApp.Text     = rule.AppSID != null?AppModel.GetInstance().GetAppPkgBySid(rule.AppSID)?.ID ?? rule.AppSID : "";

            cmbAction.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_allow"), Tag = FirewallRule.Actions.Allow
            });
            cmbAction.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_block"), Tag = FirewallRule.Actions.Block
            });
            //WpfFunc.CmbSelect(cmbAction, Rule.Action.ToString());
            viewModel.RuleAction = WpfFunc.CmbPick(cmbAction, Rule.Action.ToString());

            if (Rule.Profile == (int)FirewallRule.Profiles.All)
            {
                radProfileAll.IsChecked = true;
                chkPrivate.IsChecked    = true;
                chkDomain.IsChecked     = true;
                chkPublic.IsChecked     = true;
            }
            else
            {
                radProfileCustom.IsChecked = true;
                chkPrivate.IsChecked       = ((Rule.Profile & (int)FirewallRule.Profiles.Private) != 0);
                chkDomain.IsChecked        = ((Rule.Profile & (int)FirewallRule.Profiles.Domain) != 0);
                chkPublic.IsChecked        = ((Rule.Profile & (int)FirewallRule.Profiles.Public) != 0);
            }

            if (Rule.Interface == (int)FirewallRule.Interfaces.All)
            {
                radNicAll.IsChecked = true;
                chkLAN.IsChecked    = true;
                chkVPN.IsChecked    = true;
                chkWiFi.IsChecked   = true;
            }
            else
            {
                radNicCustom.IsChecked = true;
                chkLAN.IsChecked       = ((Rule.Interface & (int)FirewallRule.Interfaces.Lan) != 0);
                chkVPN.IsChecked       = ((Rule.Interface & (int)FirewallRule.Interfaces.RemoteAccess) != 0);
                chkWiFi.IsChecked      = ((Rule.Interface & (int)FirewallRule.Interfaces.Wireless) != 0);
            }

            if (bNew)
            {
                cmbDirection.Items.Add(new ContentControl()
                {
                    Content = Translate.fmt("str_inandout"), Tag = FirewallRule.Directions.Bidirectiona
                });
            }
            cmbDirection.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_outbound"), Tag = FirewallRule.Directions.Outbound
            });
            cmbDirection.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("str_inbound"), Tag = FirewallRule.Directions.Inbound
            });
            WpfFunc.CmbSelect(cmbDirection, Rule.Direction.ToString());

            cmbProtocol.Items.Add(new ContentControl()
            {
                Content = Translate.fmt("pro_any"), Tag = (int)NetFunc.KnownProtocols.Any
            });
            for (int i = (int)NetFunc.KnownProtocols.Min; i <= (int)NetFunc.KnownProtocols.Max; i++)
            {
                string name = NetFunc.Protocol2Str((UInt32)i);
                if (name != null)
                {
                    cmbProtocol.Items.Add(new ContentControl()
                    {
                        Content = i.ToString() + " - " + name, Tag = i
                    });
                }
            }
            //if (!WpfFunc.CmbSelect(cmbProtocol, Rule.Protocol.ToString()))
            //    cmbProtocol.Text = Rule.Protocol.ToString();
            viewModel.Protocol = WpfFunc.CmbPick(cmbProtocol, Rule.Protocol.ToString());
            if (viewModel.Protocol == null)
            {
                viewModel.ProtocolTxt = Rule.Protocol.ToString();
            }

            UpdatePorts();

            addrDest.Address = Rule.RemoteAddresses;
            addrSrc.Address  = Rule.LocalAddresses;

            App.LoadWnd(this, "Rule");
        }