Example #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);
        }
Example #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);
        }
Example #3
0
 public string this[string propName]
 {
     get
     {
         if (propName == "RuleName")
         {
             if (this.RuleName == null || this.RuleName.Length == 0)
             {
                 return("Rule Name must be set");
             }
         }
         else if (propName == "RuleAction")
         {
             if (curAction == null)
             {
                 return("Rule Action must be set");
             }
         }
         else if (propName == "ProtocolTxt")
         {
             if (curProtocol == null)
             {
                 int prot;
                 if (!int.TryParse(ProtocolTxt, out prot) || prot < 0 || prot > 255)
                 {
                     return("Invalid protocol value");
                 }
             }
         }
         else if (propName == "LocalPortTxt")
         {
             string reason = "";
             if (curLocalPort == null && !RuleWindow.ValidatePorts(curLocalPortTxt, ref reason)) // we can only select valid items
             {
                 return(reason);
             }
         }
         else if (propName == "RemotePortTxt")
         {
             string reason = "";
             if (curRemotePort == null && !RuleWindow.ValidatePorts(curRemotePortTxt, ref reason)) // we can only select valid items
             {
                 return(reason);
             }
         }
         return(null);
     }
 }
Example #4
0
        private bool checkAll()
        {
            if (txtName.Text.Length == 0)
            {
                return(false);
            }

            if (cmbProgram.SelectedItem == null)
            {
                return(false);
            }

            if (cmbAction.SelectedItem == null)
            {
                return(false);
            }

            if (cmbDirection.SelectedItem == null)
            {
                return(false);
            }

            if (curProtocol == null)
            {
                return(false);
            }

            if (curProtocol == (int)FirewallRule.KnownProtocols.TCP || curProtocol == (int)FirewallRule.KnownProtocols.UDP)
            {
                string reason = "";
                if (cmbRemotePorts.SelectedItem == null && !RuleWindow.ValidatePorts(cmbRemotePorts.Text, ref reason))
                {
                    return(false);
                }
                if (cmbLocalPorts.SelectedItem == null && !RuleWindow.ValidatePorts(cmbLocalPorts.Text, ref reason))
                {
                    return(false);
                }
            }
            else if (Rule.Protocol == (int)FirewallRule.KnownProtocols.ICMP || Rule.Protocol == (int)FirewallRule.KnownProtocols.ICMPv6)
            {
                // ToDo: Validate ICMP values
            }

            return(true);
        }