예제 #1
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (!checkAll())
            {
                return;
            }

            Rule.Name        = txtName.Text;
            Rule.Grouping    = cmbGroup.Text;
            Rule.Description = txtInfo.Text;

            Rule.ProgID = ((cmbProgram.SelectedItem as ContentControl).Tag as ProgramID);

            Rule.Action = (FirewallRule.Actions)(cmbAction.SelectedItem as ContentControl).Tag;

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

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

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

            Rule.Direction = (FirewallRule.Directions)(cmbDirection.SelectedItem as ContentControl).Tag;

            Rule.Protocol = curProtocol.Value;
            if (Rule.Protocol == (int)FirewallRule.KnownProtocols.TCP || Rule.Protocol == (int)FirewallRule.KnownProtocols.UDP)
            {
                if (cmbRemotePorts.SelectedItem != null)
                {
                    Rule.RemotePorts = (string)((cmbRemotePorts.SelectedItem as ContentControl).Tag);
                }
                else
                {
                    Rule.RemotePorts = cmbRemotePorts.Text.Replace(" ", ""); // white spaces are not valid
                }
                if (cmbLocalPorts.SelectedItem != null)
                {
                    Rule.LocalPorts = (string)((cmbLocalPorts.SelectedItem as ContentControl).Tag);
                }
                else
                {
                    Rule.LocalPorts = cmbLocalPorts.Text.Replace(" ", ""); // white spaces are not valid
                }
            }
            else if (Rule.Protocol == (int)FirewallRule.KnownProtocols.ICMP || Rule.Protocol == (int)FirewallRule.KnownProtocols.ICMPv6)
            {
                if (cmbICMP.SelectedItem != null)
                {
                    Rule.SetIcmpTypesAndCodes((cmbICMP.SelectedItem as ContentControl).Tag as string);
                }
                else
                {
                    Rule.SetIcmpTypesAndCodes(cmbICMP.Text);
                }
            }

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

            this.DialogResult = true;
        }