Exemple #1
0
        private bool MakeCustom(ProgramList.ID id, long expiration, ConEntry entry = null)
        {
            FirewallRule rule = new FirewallRule()
            {
                guid = Guid.Empty, Profile = (int)Firewall.Profiles.All, Interface = (int)Firewall.Interfaces.All, Enabled = true
            };

            rule.mID        = id;
            rule.Name       = Translate.fmt("custom_rule", id.GetDisplayName());
            rule.Grouping   = FirewallRule.RuleGroup;
            rule.Expiration = expiration;

            if (entry != null)
            {
                rule.Direction = entry.Entry.Direction;
                rule.Protocol  = entry.Entry.Protocol;
                switch (entry.Entry.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.RemotePort.ToString();
                    break;
                }
                rule.LocalAddresses  = "*";
                rule.RemoteAddresses = entry.Entry.RemoteAddress.ToString();
            }
            else
            {
                rule.Direction = Firewall.Directions.Bidirectiona;
            }

            RuleWindow ruleWnd = new RuleWindow(new List <ProgramList.ID>()
            {
                id
            }, rule);

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

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

            return(true);
        }
Exemple #2
0
        private bool MakeCustom(Program prog, UInt64 expiration, ConEntry entry = null)
        {
            FirewallRule rule = new FirewallRule()
            {
                guid = null, Profile = (int)FirewallRule.Profiles.All, Interface = (int)FirewallRule.Interfaces.All, Enabled = true
            };

            rule.ProgID   = 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);

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

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

            return(true);
        }