예제 #1
0
 /**
  * @param $rules
  * @return wfWAFRuleComparisonGroup
  * @throws wfWAFBuildRulesException
  */
 protected function _buildRuleSet($rules)
 {
     $ruleGroup = new wfWAFRuleComparisonGroup();
     foreach ($rules as $rule) {
         if (!array_key_exists('type', $rule)) {
             throw new wfWAFBuildRulesException('Invalid rule: type not set.');
         }
         switch ($rule['type']) {
             case 'comparison_group':
                 if (!array_key_exists('comparisons', $rule) || !is_array($rule['comparisons'])) {
                     throw new wfWAFBuildRulesException('Invalid rule format passed to _buildRuleSet.');
                 }
                 $ruleGroup->add($this->_buildRuleSet($rule['comparisons']));
                 break;
             case 'comparison':
                 if (array_key_exists('parameter', $rule)) {
                     $rule['parameters'] = array($rule['parameter']);
                 }
                 foreach (array('action', 'expected', 'parameters') as $ruleRequirement) {
                     if (!array_key_exists($ruleRequirement, $rule)) {
                         throw new wfWAFBuildRulesException("Invalid rule: {$ruleRequirement} not set.");
                     }
                 }
                 $ruleGroup->add(new wfWAFRuleComparison($this, $rule['action'], $rule['expected'], $rule['parameters']));
                 break;
             case 'operator':
                 if (!array_key_exists('operator', $rule)) {
                     throw new wfWAFBuildRulesException('Invalid rule format passed to _buildRuleSet. operator not passed.');
                 }
                 $ruleGroup->add(new wfWAFRuleLogicalOperator($rule['operator']));
                 break;
             default:
                 throw new wfWAFBuildRulesException("Invalid rule type [{$rule['type']}] passed to _buildRuleSet.");
         }
     }
     return $ruleGroup;
 }
예제 #2
0
파일: parser.php 프로젝트: ashenkar/sanga
 /**
  * @return wfWAFRuleComparisonGroup
  */
 private function parseConditional()
 {
     $comparisonGroup = new wfWAFRuleComparisonGroup();
     while ($token = $this->nextToken()) {
         switch ($token->getType()) {
             case wfWAFRuleLexer::T_IDENTIFIER:
                 $comparisonGroup->add($this->parseComparison());
                 break;
             case wfWAFRuleLexer::T_COMPARISON_OPERATOR:
                 $comparisonGroup->add(new wfWAFRuleLogicalOperator($token->getValue()));
                 break;
             case wfWAFRuleLexer::T_OPEN_PARENTHESIS:
                 $this->parenCount++;
                 $comparisonGroup->add($this->parseConditional());
                 break;
             case wfWAFRuleLexer::T_CLOSE_PARENTHESIS:
                 if ($this->parenCount === 0) {
                     $this->index--;
                     return $comparisonGroup;
                 }
                 $this->parenCount--;
                 return $comparisonGroup;
         }
     }
     return $comparisonGroup;
 }