public RuleWindow(List <Program> progs, FirewallRule 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; 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; } } 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.Outboun }); 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; WpfFunc.LoadWnd(this, "Rule"); }
private void UpdatePorts() { cmbRemotePorts.Items.Clear(); cmbLocalPorts.Items.Clear(); if (curProtocol == (int)FirewallRule.KnownProtocols.TCP || curProtocol == (int)FirewallRule.KnownProtocols.UDP) { cmbRemotePorts.Items.Add(new ContentControl() { Content = Translate.fmt("port_any"), Tag = "*" }); cmbLocalPorts.Items.Add(new ContentControl() { Content = Translate.fmt("port_any"), Tag = "*" }); if (Rule.Direction == FirewallRule.Directions.Outboun) { if (curProtocol == (int)FirewallRule.KnownProtocols.TCP) { cmbRemotePorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordIpTlsOut, Tag = FirewallRule.PortKeywordIpTlsOut }); } } else if (Rule.Direction == FirewallRule.Directions.Inbound) { if (curProtocol == (int)FirewallRule.KnownProtocols.TCP) { cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordIpTlsIn, Tag = FirewallRule.PortKeywordIpTlsIn }); cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordRpcEp, Tag = FirewallRule.PortKeywordRpcEp }); cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordRpc, Tag = FirewallRule.PortKeywordRpc }); } else if (curProtocol == (int)FirewallRule.KnownProtocols.UDP) { cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordTeredo, Tag = FirewallRule.PortKeywordTeredo }); cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordPly2Disc, Tag = FirewallRule.PortKeywordPly2Disc }); cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordMDns, Tag = FirewallRule.PortKeywordMDns }); cmbLocalPorts.Items.Add(new ContentControl() { Content = FirewallRule.PortKeywordDhcp, Tag = FirewallRule.PortKeywordDhcp }); } } //if (!WpfFunc.CmbSelect(cmbRemotePorts, Rule.RemotePorts) && Rule.RemotePorts != null) // cmbRemotePorts.Text = Rule.RemotePorts; viewModel.RemotePort = WpfFunc.CmbPick(cmbRemotePorts, FirewallRule.IsEmptyOrStar(Rule.RemotePorts) ? "*" : Rule.RemotePorts); if (viewModel.RemotePort == null) { viewModel.RemotePortTxt = Rule.RemotePorts; } //if (!WpfFunc.CmbSelect(cmbLocalPorts, Rule.LocalPorts) && Rule.LocalPorts != null) // cmbLocalPorts.Text = Rule.LocalPorts; viewModel.LocalPort = WpfFunc.CmbPick(cmbLocalPorts, FirewallRule.IsEmptyOrStar(Rule.LocalPorts) ? "*" : Rule.LocalPorts); if (viewModel.LocalPort == null) { viewModel.LocalPortTxt = Rule.LocalPorts; } } }
private void UpdatePorts() { cmbRemotePorts.Items.Clear(); cmbLocalPorts.Items.Clear(); if (curProtocol == (int)FirewallRule.KnownProtocols.TCP || curProtocol == (int)FirewallRule.KnownProtocols.UDP) { cmbRemotePorts.Items.Add(new ContentControl() { Content = Translate.fmt("port_any"), Tag = "*" }); cmbLocalPorts.Items.Add(new ContentControl() { Content = Translate.fmt("port_any"), Tag = "*" }); if (Rule.Direction == Firewall.Directions.Outboun) { if (curProtocol == (int)FirewallRule.KnownProtocols.TCP) { cmbRemotePorts.Items.Add(new ContentControl() { Content = "IPHTTPS", Tag = "IPHTTPS" }); } } else if (Rule.Direction == Firewall.Directions.Inbound) { if (curProtocol == (int)FirewallRule.KnownProtocols.TCP) { cmbLocalPorts.Items.Add(new ContentControl() { Content = "IPHTTPS", Tag = "IPHTTPS" }); cmbLocalPorts.Items.Add(new ContentControl() { Content = "RPC-EPMap", Tag = "RPC-EPMap" }); cmbLocalPorts.Items.Add(new ContentControl() { Content = "RPC", Tag = "RPC" }); } else if (curProtocol == (int)FirewallRule.KnownProtocols.UDP) { cmbLocalPorts.Items.Add(new ContentControl() { Content = "Teredo", Tag = "Teredo" }); cmbLocalPorts.Items.Add(new ContentControl() { Content = "Ply2Disc", Tag = "Ply2Disc" }); cmbLocalPorts.Items.Add(new ContentControl() { Content = "mDNS", Tag = "mDNS" }); } } //if (!WpfFunc.CmbSelect(cmbRemotePorts, Rule.RemotePorts) && Rule.RemotePorts != null) // cmbRemotePorts.Text = Rule.RemotePorts; viewModel.RemotePort = WpfFunc.CmbPick(cmbRemotePorts, Rule.RemotePorts == null ? "*" : Rule.RemotePorts); if (viewModel.RemotePort == null) { viewModel.RemotePortTxt = Rule.RemotePorts; } //if (!WpfFunc.CmbSelect(cmbLocalPorts, Rule.LocalPorts) && Rule.LocalPorts != null) // cmbLocalPorts.Text = Rule.LocalPorts; viewModel.LocalPort = WpfFunc.CmbPick(cmbLocalPorts, Rule.LocalPorts == null ? "*" : Rule.LocalPorts); if (viewModel.LocalPort == null) { viewModel.LocalPortTxt = Rule.LocalPorts; } } }