function &getXmlText($indenting = true) { if ($indenting) { return DH::dom_to_xml($this->xmlroot, 0, true); } return DH::dom_to_xml($this->xmlroot, -1, true); }
/** * @param string $newValue * @return bool */ public function API_setValue($newValue) { if (!$this->setValue($newValue)) { return false; } $c = findConnectorOrDie($this); $xpath = $this->getXPath(); $c->sendSetRequest($xpath, DH::dom_to_xml($this->xmlroot, -1, false)); $this->setValue($newValue); return true; }
/** * send current config to the firewall and save under name $config_name * */ public function API_uploadConfig($config_name = 'panconfigurator-default.xml') { print "Uploadig config to device...."; $url = "&type=import&category=configuration&category=configuration"; $answer =& $this->connector->sendRequest($url, false, DH::dom_to_xml($this->xmlroot), $config_name); print "OK!\n"; }
/** * @param DOMNode $node * @param int $indenting * @param bool $lineReturn * @param int $limitSubLevels * @return string */ static function &dom_to_xml(DOMNode $node, $indenting = 0, $lineReturn = true, $limitSubLevels = -1, $indentingIncrement = 1) { $ind = ''; $out = ''; if ($limitSubLevels >= 0 && $limitSubLevels == $indenting) { return $ind; } $ind = str_pad('', $indenting, ' '); $firstTag = $ind . '<' . $node->nodeName; if (get_class($node) != 'DOMDocument') { foreach ($node->attributes as $at) { $firstTag .= ' ' . $at->name . '="' . $at->value . '"'; } } //$firsttag .= '>'; $c = 0; $wroteChildren = false; $tmpout = ''; if (DH::firstChildElement($node) !== FALSE) { foreach ($node->childNodes as $n) { if ($n->nodeType != 1) { continue; } if ($indenting != -1) { $tmpout .= DH::dom_to_xml($n, $indenting + $indentingIncrement, $lineReturn, $limitSubLevels, $indentingIncrement); } else { $tmpout .= DH::dom_to_xml($n, -1, $lineReturn, $limitSubLevels); } $wroteChildren = true; } } if ($wroteChildren == false) { if (DH::firstChildElement($node) !== FALSE || is_null($node->textContent) || strlen($node->textContent) < 1) { if ($lineReturn) { $out .= $firstTag . "/>\n"; } else { $out .= $firstTag . "/>"; } } else { if ($lineReturn) { $out .= $firstTag . '>' . str_replace(self::$charsToConvert, self::$charsToConvertInto, $node->nodeValue) . '</' . $node->nodeName . ">\n"; } else { $out .= $firstTag . '>' . str_replace(self::$charsToConvert, self::$charsToConvertInto, $node->nodeValue) . '</' . $node->nodeName . ">"; } } } else { if ($lineReturn) { $out .= $firstTag . ">\n" . $tmpout . $ind . '</' . $node->nodeName . ">\n"; } else { $out .= $firstTag . ">" . $tmpout . $ind . '</' . $node->nodeName . ">"; } } return $out; }
function mwarning($msg, $object = null) { global $PANC_WARN; if (isset($PANC_WARN) && $PANC_WARN == 0) { return; } if ($object !== null) { $class = get_class($object); if ($class == 'DOMNode' || $class == 'DOMElement' || is_subclass_of($object, 'DOMNode')) { $msg .= "\nXML line #" . $object->getLineNo() . ", XPATH: " . DH::elementToPanXPath($object) . "\nRaw xml:" . DH::dom_to_xml($object, 0, true, 3); } } fwrite(STDERR, "\n*WARNING* " . $msg . "\n"); //debug_print_backtrace(); $d = debug_backtrace(); $skip = 0; print " *** Backtrace ***\n"; foreach ($d as $l) { if ($skip >= 0) { if ($skip == 0 && isset($l['object'])) { fwrite(STDERR, $l['object']->toString() . "\n"); } fwrite(STDERR, $l['function'] . "()\n"); if (isset($l['object'])) { fwrite(STDERR, ' ' . $l['class'] . '::' . $l['file'] . " line " . $l['line'] . "\n"); } else { fwrite(STDERR, ' ::' . $l['file'] . " line " . $l['line'] . "\n"); } } $skip++; } fwrite(STDERR, "\n\n"); }
if ($configOutput['status'] == 'fail') { fwrite(STDERR, "\n\n**ERROR** " . $configOutput['msg'] . "\n\n"); exit(1); } if ($configOutput['type'] == 'file') { if (isset(PH::$args['toxpath'])) { derr("toXpath options was used, it's incompatible with a file output"); } print "{$configOutput['filename']} ... "; $doc->save($configOutput['filename']); } elseif ($configOutput['type'] == 'api') { if ($debugAPI) { $configOutput['connector']->setShowApiCalls(true); } if (isset(PH::$args['toxpath'])) { $configOutput['connector']->sendSetRequest(PH::$args['toxpath'], DH::dom_to_xml(DH::firstChildElement($doc), -1, false)); } else { if (isset(PH::$args['preservemgmtconfig']) || isset(PH::$args['preservemgmtusers'])) { print "Option 'preserveXXXXX was used, we will first download the running config ..."; $runningConfig = $configOutput['connector']->getRunningConfig(); print "OK!\n"; $xpathQrunning = new DOMXPath($runningConfig); $xpathQlocal = new DOMXPath($doc); $xpathQueryList = array(); if (isset(PH::$args['preservemgmtconfig']) || isset(PH::$args['preservemgmtusers'])) { $xpathQueryList[] = '/config/mgt-config/users'; } if (isset(PH::$args['preservemgmtconfig']) || isset(PH::$args['preservemgmtsystem'])) { $xpathQueryList[] = '/config/devices/entry/deviceconfig/system'; } if (isset(PH::$args['preservemgmtconfig'])) {
if (!$vsys->isVirtualSystem()) { derr("this is filter is only supported on firewall/vsys based, Panorama is not allowed." . $object->toString()); } $connector = findConnector($vsys); if ($connector === null) { derr("this filter is available only from API enabled PANConf objects"); } if (!isset($vsys->apiCache)) { $vsys->apiCache = array(); } // caching results for speed improvements if (!isset($vsys->apiCache['unusedSecurity'])) { $vsys->apiCache['unusedSecurity'] = array(); $apiCmd = '<show><running><rule-use><rule-base>security</rule-base><type>unused</type><vsys>' . $vsys->name() . '</vsys></rule-use></running></show>'; $apiResult = $connector->sendCmdRequest($apiCmd); DH::dom_to_xml($apiResult); $rulesXml = DH::findXPath('/result/rules/entry', $apiResult); for ($i = 0; $i < $rulesXml->length; $i++) { $ruleName = $rulesXml->item($i)->textContent; $vsys->apiCache['unusedSecurity'][$ruleName] = $ruleName; } } if (isset($vsys->apiCache['unusedSecurity'][$object->name()])) { return true; } return false; }, 'arg' => false); RQuery::$defaultFilters['rule']['name']['operators']['eq'] = array('eval' => function ($object, &$nestedQueries, $value) { /** @var $object Rule|SecurityRule|NatRule|DecryptionRule */ return $object->name() == $value; }, 'arg' => true);
/** * @param Rule $rule * @param bool $inPost * @return bool */ public function API_addRule($rule, $inPost = false) { if (!$this->addRule($rule, $inPost)) { return false; } $xpath = $this->getXPath($rule); $con = findConnectorOrDie($this); $con->sendSetRequest($xpath, DH::dom_to_xml($rule->xmlroot, -1, false)); return true; }
/** * send a config to the firewall and save under name $config_name * * * @param DOMNode $configDomXml * @param string $configName * @return DOMNode */ public function uploadConfiguration($configDomXml, $configName = 'stage0.xml', $verbose = true) { if ($verbose) { print "Uploadig config to device {$this->apihost}/{$configName}...."; } $url = "&type=import&category=configuration&category=configuration"; $answer = $this->sendRequest($url, false, DH::dom_to_xml($configDomXml), $configName, array('timeout' => 7)); if ($verbose) { print "OK!\n"; } return $answer; }