示例#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);
        }
示例#2
0
        private bool MakeCustom(Program prog, UInt64 expiration, ConEntry entry = null)
        {
            FirewallRuleEx rule = new FirewallRuleEx()
            {
                guid = null, Profile = (int)FirewallRule.Profiles.All, Interface = (int)FirewallRule.Interfaces.All, Enabled = true
            };

            rule.SetProgID(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);

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

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

            return(true);
        }
示例#3
0
        private void consGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ConEntry entry = (ConEntry)consGrid.SelectedItem;

            if (entry == null)
            {
                return;
            }

            ProgramList.ID id         = mEventList.ElementAt(curIndex);
            long           expiration = GetExpiration();

            if (MakeCustom(id, expiration, entry))
            {
                PopEntry();
            }
        }
示例#4
0
        private void consGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ConEntry entry = (ConEntry)consGrid.SelectedItem;

            if (entry == null)
            {
                return;
            }

            ProgramID id = mEventList.ElementAt(curIndex);
            Tuple <Program, List <Engine.FwEventArgs> > list = mEvents[id];

            UInt64 expiration = GetExpiration();

            if (MakeCustom(list.Item1, expiration, entry))
            {
                PopEntry();
            }
        }