private static bool IsRuleSimilarToRule(CheckPoint_Rule rule1, CheckPoint_Rule rule2)
        {
            if (rule1.Action != rule2.Action)
            {
                return(false);
            }

            if (rule1.Enabled != rule2.Enabled)
            {
                return(false);
            }

            if (rule1.SourceNegated != rule2.SourceNegated || rule1.DestinationNegated != rule2.DestinationNegated)
            {
                return(false);
            }

            if ((rule1.Time.Count != rule2.Time.Count) ||
                (rule1.Time.Count > 0 && rule2.Time.Count > 0 && rule1.Time[0].Name != rule2.Time[0].Name))
            {
                return(false);
            }

            bool sourceMatch  = CompareLists(rule1.Source, rule2.Source);
            bool destMatch    = CompareLists(rule1.Destination, rule2.Destination);
            bool serviceMatch = CompareLists(rule1.Service, rule2.Service);

            return(sourceMatch && destMatch || destMatch && serviceMatch || sourceMatch && serviceMatch);
        }
        private static void AddRule(CheckPoint_Layer layer, CheckPoint_Rule newRule)
        {
            bool match = false;

            int pos = GetFirstRuleWithSameAction(layer, newRule.Action);

            if (pos >= 0)
            {
                for (int i = pos; i < layer.Rules.Count(); i++)
                {
                    if (IsRuleSimilarToRule(layer.Rules[i], newRule))
                    {
                        layer.Rules[i] = MergeRules(layer.Rules[i], newRule);
                        match          = true;
                        break;
                    }
                }
            }

            if (!match)
            {
                CheckPoint_Rule rule = newRule.Clone();
                rule.Layer              = layer.Name;
                rule.Comments           = "";
                rule.ConversionComments = newRule.ConversionComments;
                layer.Rules.Add(rule);
            }
        }
        public CheckPoint_Rule Clone()
        {
            var newRule = new CheckPoint_Rule();

            newRule.Name                   = Name;
            newRule.Comments               = Comments;
            newRule.Enabled                = Enabled;
            newRule.Layer                  = Layer;
            newRule.SubPolicyName          = SubPolicyName;
            newRule.Action                 = Action;
            newRule.Track                  = Track;
            newRule.SourceNegated          = SourceNegated;
            newRule.DestinationNegated     = DestinationNegated;
            newRule.ConvertedCommandId     = ConvertedCommandId;
            newRule.ConversionIncidentType = ConversionIncidentType;

            foreach (CheckPointObject obj in Source)
            {
                newRule.Source.Add(obj);
            }
            foreach (CheckPointObject obj in Destination)
            {
                newRule.Destination.Add(obj);
            }
            foreach (CheckPointObject obj in Service)
            {
                newRule.Service.Add(obj);
            }
            foreach (CheckPointObject obj in Time)
            {
                newRule.Time.Add(obj);
            }

            return(newRule);
        }
Exemple #4
0
        //specific extension for comparing applications
        protected override bool CompareApplications(CheckPoint_Rule other)
        {
            if (other is CheckPoint_RuleWithApplication)
            {
                return(CompareLists(Application, ((CheckPoint_RuleWithApplication)other).Application));
            }

            return(false);
        }
        private static CheckPoint_Rule MergeRules(CheckPoint_Rule rule1, CheckPoint_Rule rule2)
        {
            var mergedRule = new CheckPoint_Rule();

            var sources      = new List <CheckPointObject>();
            var destinations = new List <CheckPointObject>();
            var services     = new List <CheckPointObject>();
            var times        = new List <CheckPointObject>();

            sources.AddRange(rule1.Source);
            sources.AddRange(rule2.Source);
            mergedRule.Source = sources.Distinct().ToList();
            OmitAnyFromList(mergedRule.Source);

            destinations.AddRange(rule1.Destination);
            destinations.AddRange(rule2.Destination);
            mergedRule.Destination = destinations.Distinct().ToList();
            OmitAnyFromList(mergedRule.Destination);

            services.AddRange(rule1.Service);
            services.AddRange(rule2.Service);
            mergedRule.Service = services.Distinct().ToList();
            OmitAnyFromList(mergedRule.Service);

            times.AddRange(rule1.Time);
            times.AddRange(rule2.Time);
            mergedRule.Time = times.Distinct().ToList();
            OmitAnyFromList(mergedRule.Time);

            mergedRule.Enabled                = (rule1.Enabled && rule2.Enabled);
            mergedRule.Layer                  = rule1.Layer;
            mergedRule.Action                 = rule1.Action;
            mergedRule.Track                  = rule1.Track;
            mergedRule.SourceNegated          = rule1.SourceNegated;
            mergedRule.DestinationNegated     = rule1.DestinationNegated;
            mergedRule.Comments               = "";
            mergedRule.ConversionComments     = rule1.ConversionComments + " | " + rule2.ConversionComments;
            mergedRule.ConvertedCommandId     = rule1.ConvertedCommandId;
            mergedRule.ConversionIncidentType = ConversionIncidentType.None;

            if (rule1.ConversionIncidentType != ConversionIncidentType.None || rule2.ConversionIncidentType != ConversionIncidentType.None)
            {
                if (rule1.ConversionIncidentType > rule2.ConversionIncidentType)
                {
                    mergedRule.ConvertedCommandId     = rule1.ConvertedCommandId;
                    mergedRule.ConversionIncidentType = rule1.ConversionIncidentType;
                }
                else
                {
                    mergedRule.ConvertedCommandId     = rule2.ConvertedCommandId;
                    mergedRule.ConversionIncidentType = rule2.ConversionIncidentType;
                }
            }

            return(mergedRule);
        }
Exemple #6
0
 //specific extension for cloning applications
 protected override void CloneApplicationsToRule(CheckPoint_Rule newRule)
 {
     if (newRule is CheckPoint_RuleWithApplication)
     {
         foreach (CheckPointObject obj in Application)
         {
             ((CheckPoint_RuleWithApplication)newRule).Application.Add(obj);
         }
     }
 }
        public bool CompareTo(CheckPoint_Rule other)
        {
            if (Enabled != other.Enabled ||
                Action != other.Action ||
                Track != other.Track ||
                SourceNegated != other.SourceNegated ||
                DestinationNegated != other.DestinationNegated)
            {
                return(false);
            }

            if ((Time.Count != other.Time.Count) ||
                (Time.Count > 0 && other.Time.Count > 0 && Time[0].Name != other.Time[0].Name))
            {
                return(false);
            }

            bool sourceMatch  = CompareLists(Source, other.Source);
            bool destMatch    = CompareLists(Destination, other.Destination);
            bool serviceMatch = CompareLists(Service, other.Service);

            return(sourceMatch && destMatch && serviceMatch);
        }
Exemple #8
0
 //CompareApplications will be overridden in the derived class if the class needs specific compare implementation for applications
 //this function returns true so the CompareTo function won't be affected.
 protected virtual bool CompareApplications(CheckPoint_Rule other)
 {
     return(true);
 }
Exemple #9
0
 //CloneApplicationsToRule will be overridden in the derived class if the class needs specific clone implementation for applications
 //in this class the function empty because it doesn't handle with applications in services.
 protected virtual void CloneApplicationsToRule(CheckPoint_Rule newRule)
 {
     return;
 }