public function prepareArgumentsForAction($arguments) { $this->arguments = array(); if (strlen($arguments) != 0 && !isset($this->actionRef['args'])) { display_error_usage_exit("error while processing argument '{$this->actionRef['name']}' : arguments were provided while they are not supported by this action"); } if (!isset($this->actionRef['args']) || $this->actionRef['args'] === false) { return; } $ex = explode(',', $arguments); if (count($ex) > count($this->actionRef['args'])) { display_error_usage_exit("error while processing argument '{$this->actionRef['name']}' : too many arguments provided"); } $count = -1; foreach ($this->actionRef['args'] as $argName => &$properties) { $count++; $argValue = null; if (isset($ex[$count])) { $argValue = $ex[$count]; } if ((!isset($properties['default']) || $properties['default'] == '*nodefault*') && ($argValue === null || strlen($argValue)) == 0) { derr("action '{$this->actionRef['name']}' argument#{$count} '{$argName}' requires a value, it has no default one"); } if ($argValue !== null && strlen($argValue) > 0) { $argValue = trim($argValue); } else { $argValue = $properties['default']; } if ($properties['type'] == 'string') { if (isset($properties['choices'])) { foreach ($properties['choices'] as $choice) { $tmpChoice[strtolower($choice)] = true; } $argValue = strtolower($argValue); if (!isset($tmpChoice[$argValue])) { derr("unsupported value '{$argValue}' for action '{$this->actionRef['name']}' arg#{$count} '{$argName}'"); } } } elseif ($properties['type'] == 'boolean') { if ($argValue == '1' || strtolower($argValue) == 'true' || strtolower($argValue) == 'yes') { $argValue = true; } elseif ($argValue == '0' || strtolower($argValue) == 'false' || strtolower($argValue) == 'no') { $argValue = false; } else { derr("unsupported argument value '{$argValue}' which should of type '{$properties['type']}' for action '{$this->actionRef['name']}' arg#{$count} helper#'{$argName}'"); } } elseif ($properties['type'] == 'integer') { if (!is_integer($argValue)) { derr("unsupported argument value '{$argValue}' which should of type '{$properties['type']}' for action '{$this->actionRef['name']}' arg#{$count} helper#'{$argName}'"); } } else { derr("unsupported argument type '{$properties['type']}' for action '{$this->actionRef['name']}' arg#{$count} helper#'{$argName}'"); } $this->arguments[$argName] = $argValue; } }
} if (isset(PH::$args['groupfile'])) { $groupFile = PH::$args['groupfile']; if (!is_string($groupFile) || strlen($groupFile) < 1) { display_error_usage_exit('"groupfile" argument is not a valid string'); } } if (isset(PH::$args['group'])) { $groupName = PH::$args['group']; if (!is_string($groupName) || strlen($groupName) < 1) { display_error_usage_exit('"group" argument is not a valid string'); } if (isset(PH::$args['location'])) { $groupLocation = PH::$args['location']; if (!is_string($groupLocation) || strlen($groupLocation) < 1) { display_error_usage_exit('"group" argument is not a valid string'); } } else { print " notice : missing argument 'location', assuming 'shared'\n"; $groupLocation = 'shared'; } } // // // Script really starts here // $configType = strtolower(PH::$args['type']); if ($configType != 'panos' && $configType != 'panorama') { derr("\n**ERROR** Unsupported config type '{$configType}'. Check your CLI arguments\n\n"); } print "Config type is '{$configType}', intput filename is '{$inputFile}'\n";
$ruleTypes = array_unique($ruleTypes); } // // Extracting actions // $explodedActions = explode('/', $doActions); /** @var CallContext[] $doActions */ $doActions = array(); foreach ($explodedActions as &$exAction) { $explodedAction = explode(':', $exAction); if (count($explodedAction) > 2) { display_error_usage_exit('"actions" argument has illegal syntax: ' . PH::$args['actions']); } $actionName = strtolower($explodedAction[0]); if (!isset($supportedActions[$actionName])) { display_error_usage_exit('unsupported Action: "' . $actionName . '"'); } if (count($explodedAction) == 1) { $explodedAction[1] = ''; } $context = new CallContext($supportedActions[$actionName], $explodedAction[1], $nestedQueries); if ($configInput['type'] == 'api') { $context->isAPI = true; } $doActions[] = $context; } // // --------- // // create a RQuery if a filter was provided //
} else { display_error_usage_exit("'stopMergingIfDenySeen' argument was given unsupported value '" . PH::$args['stopmergingifdenyseen'] . "'"); } } if (!isset(PH::$args['mergeadjacentonly'])) { print " - No 'mergeAdjacentOnly' argument provided, using default 'no'\n"; $mergeAdjacentOnly = false; } else { if (PH::$args['mergeadjacentonly'] === null || strlen(PH::$args['mergeadjacentonly']) == 0) { $mergeAdjacentOnly = true; } elseif (strtolower(PH::$args['mergeadjacentonly']) == 'yes' || strtolower(PH::$args['mergeadjacentonly']) == 'true' || strtolower(PH::$args['mergeadjacentonly']) == 1) { $mergeAdjacentOnly = true; } elseif (strtolower(PH::$args['mergeadjacentonly']) == 'no' || strtolower(PH::$args['mergeadjacentonly']) == 'false' || strtolower(PH::$args['mergeadjacentonly']) == 0) { $mergeAdjacentOnly = false; } else { display_error_usage_exit("(mergeAdjacentOnly' argument was given unsupported value '" . PH::$args['mergeadjacentonly'] . "'"); } print " - mergeAdjacentOnly = " . boolYesNo($mergeAdjacentOnly) . "\n"; } $hashTable = array(); /** * @param $rule SecurityRule * @param $method * @throws Exception */ function updateRuleHash($rule, $method) { global $hashTable; if (isset($rule->mergeHash)) { if (isset($hashTable[$rule->mergeHash])) { if (isset($hashTable[$rule->mergeHash][$rule->serial])) {