예제 #1
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);
     }
 }
예제 #2
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);
        }