Beispiel #1
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");
        }