Example #1
0
        private void BtnCreate_Click(object sender, RoutedEventArgs e)
        {
            ComboBoxItem           itm      = (ComboBoxItem)CmbType.SelectedItem;
            NET_FW_RULE_DIRECTION_ richting = (NET_FW_RULE_DIRECTION_)itm.Tag;
            string name         = txtFirewallRuleName.Text;
            string description  = txtBeschrijving.Text;
            int    profileValue = 0;

            if ((bool)chkProfielDomein.IsChecked)
            {
                profileValue += 1;
            }
            if ((bool)chkProfielPrive.IsChecked)
            {
                profileValue += 2;
            }
            if ((bool)chkProfielOpenbaar.IsChecked)
            {
                profileValue += 4;
            }
            bool           enabled    = (bool)chkIsActief.IsChecked;
            NET_FW_ACTION_ typeOfRule = NET_FW_ACTION_.NET_FW_ACTION_ALLOW;

            if ((bool)rdbBlock.IsChecked)
            {
                typeOfRule = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
            }
            string application = txtProgramma.Text;

            if (application.ToString() == "")
            {
                application = null;
            }
            string localAdresses = txtAdresLokaal.Text;

            if (localAdresses.Trim() == "")
            {
                localAdresses = "*";
            }
            string remoteAdresses = txtAdresExtern.Text;

            if (remoteAdresses.Trim() == "")
            {
                remoteAdresses = "*";
            }
            string localPorts  = txtPoortLokaal.Text;
            string remotePorts = txtPoortExtern.Text;

            itm = (ComboBoxItem)CmbProtocol.SelectedItem;
            int protocolValue = (int)itm.Tag;

            if (WinFireWall.CreateRule(richting, name, description, profileValue, enabled, typeOfRule, application, localAdresses, remoteAdresses, localPorts, remotePorts, protocolValue))
            {
                this.Close();
            }
        }
        private void VulRules(NET_FW_RULE_DIRECTION_ richting)
        {
            lstRules.Items.Clear();
            ListBoxItem itm;

            foreach (INetFwRule regel in WinFireWall.GetAllRules(richting))
            {
                itm         = new ListBoxItem();
                itm.Content = regel.Name;
                itm.Tag     = regel;
                lstRules.Items.Add(itm);
            }
        }
        private void LstRules_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ClearDetails();
            if (lstRules.SelectedItem == null)
            {
                return;
            }

            ListBoxItem itm   = (ListBoxItem)lstRules.SelectedItem;
            INetFwRule  regel = (INetFwRule)itm.Tag;

            txtFirewallRuleName.Text = regel.Name;
            lblBeschrijving.Content  = regel.Description;

            //int d = (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN;  //1
            //int p = (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE; //2
            //int pu = (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC;  //4
            //int a = (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL; //2147483647
            //int x = (int)regel.Profiles;
            if (regel.Profiles == (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL)
            {
                chkProfielDomein.IsChecked   = true;
                chkProfielOpenbaar.IsChecked = true;
                chkProfielPrive.IsChecked    = true;
            }
            if (regel.Profiles == 4 || regel.Profiles == 6 || regel.Profiles == 7)
            {
                chkProfielOpenbaar.IsChecked = true;
            }
            if (regel.Profiles == 2 || regel.Profiles == 3 || regel.Profiles == 6 || regel.Profiles == 7)
            {
                chkProfielPrive.IsChecked = true;
            }
            if (regel.Profiles == 1 || regel.Profiles == 3 || regel.Profiles == 5 || regel.Profiles == 7)
            {
                chkProfielOpenbaar.IsChecked = true;
            }

            chkIsActief.IsChecked = regel.Enabled;

            if (regel.Action == NET_FW_ACTION_.NET_FW_ACTION_ALLOW)
            {
                chkActionAllow.IsChecked  = true;
                chkActionAllow.Background = Brushes.ForestGreen;
            }
            else if (regel.Action == NET_FW_ACTION_.NET_FW_ACTION_BLOCK)
            {
                chkActionBlock.IsChecked  = true;
                chkActionBlock.Background = Brushes.Tomato;
            }
            //else if (regel.Action == NET_FW_ACTION_.NET_FW_ACTION_MAX)

            if (regel.ApplicationName != null)
            {
                txtProgramma.Text = regel.ApplicationName;
            }
            else
            {
                txtProgramma.Text = "<alle programma's>";
            }
            string x = regel.RemoteAddresses;

            if (regel.LocalAddresses == "*")
            {
                txtLokaalAdres.Text = "<elk willekeurig adres>";
            }
            else
            {
                txtLokaalAdres.Text = regel.LocalAddresses;
            }
            if (regel.RemoteAddresses == "*")
            {
                txtExternAdres.Text = "<elk willekeurig adres>";
            }
            else
            {
                txtExternAdres.Text = regel.RemoteAddresses;
            }

            if (regel.LocalPorts == "*")
            {
                txtLokalePoorten.Text = "<elke willekeurige poort>";
            }
            else
            {
                txtLokalePoorten.Text = regel.LocalPorts;
            }
            if (regel.RemotePorts == "*")
            {
                txtExternePoorten.Text = "<elke willekeurige poort>";
            }
            else
            {
                txtExternePoorten.Text = regel.RemotePorts;
            }

            txtProtocol.Text = WinFireWall.getProtocolAsString(regel.Protocol);
        }