protected function _load_description_from_domxml()
 {
     $descroot = DH::findFirstElement('description', $this->xmlroot);
     if ($descroot !== false) {
         $this->_description = $descroot->textContent;
     }
 }
 public function load_from_domxml(DOMElement $xml)
 {
     $this->xmlroot = $xml;
     $this->name = DH::findAttribute('name', $xml);
     if ($this->name === FALSE) {
         derr("loopback name name not found\n");
     }
     $ipNode = DH::findFirstElement('ip', $xml);
     if ($ipNode !== false) {
         foreach ($ipNode->childNodes as $l3ipNode) {
             if ($ipNode->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             $this->_ipv4Addresses[] = $ipNode->getAttribute('name');
         }
     }
 }
Beispiel #3
0
 /**
  * @param string $name
  * @param TagStore|null $owner
  */
 public function Tag($name, $owner, $fromXmlTemplate = false)
 {
     $this->name = $name;
     if ($fromXmlTemplate) {
         $doc = new DOMDocument();
         if ($owner->owner->version < 60) {
             derr('tag stores were introduced in v6.0');
         } else {
             $doc->loadXML(self::$templatexml_v6);
         }
         $node = DH::findFirstElement('entry', $doc);
         $rootDoc = $owner->xmlroot->ownerDocument;
         $this->xmlroot = $rootDoc->importNode($node, true);
         $this->load_from_domxml($this->xmlroot);
         $this->setName($name);
     }
     $this->owner = $owner;
 }
 /**
  * @param $xml DOMElement
  */
 function load_from_xml($xml)
 {
     $this->xmlroot = $xml;
     $this->name = DH::findAttribute('name', $xml);
     if ($this->name === FALSE) {
         derr("static-route name not found\n");
     }
     $dstNode = DH::findFirstElementOrDie('destination', $xml);
     $this->_destination = $dstNode->textContent;
     $ifNode = DH::findFirstElement('interface', $xml);
     if ($ifNode !== false) {
         $this->_interface = $this->owner->owner->owner->network->findInterfaceOrCreateTmp($ifNode->textContent);
     }
     $fhNode = DH::findFirstElement('nexthop', $xml);
     if ($fhNode !== false) {
         $fhTypeNode = DH::findFirstElement('ip-address', $fhNode);
         if ($fhTypeNode !== false) {
             $this->_nexthopType = 'ip-address';
             $this->_nexthopIP = $fhTypeNode->textContent;
         }
     }
 }
 /**
  * Add a member to this group, it must be passed as an object
  * @param Address|AddressGroup $newObject Object to be added
  * @param bool $rewriteXml
  * @return bool
  */
 public function add($newObject, $rewriteXml = true)
 {
     if ($this->isDynamic) {
         derr('cannot be used on Dynamic Address Groups');
     }
     if (!is_object($newObject)) {
         derr("Only objects can be passed to this function");
     }
     if (!in_array($newObject, $this->members, true)) {
         $this->members[] = $newObject;
         $newObject->addReference($this);
         if ($rewriteXml) {
             if ($this->owner->owner->version >= 60) {
                 $membersRoot = DH::findFirstElement('static', $this->xmlroot);
                 if ($membersRoot === false) {
                     derr('<static> not found');
                 }
                 $tmpElement = $membersRoot->appendChild($this->xmlroot->ownerDocument->createElement('member'));
                 $tmpElement->nodeValue = $newObject->name();
             } else {
                 $tmpElement = $this->xmlroot->appendChild($this->xmlroot->ownerDocument->createElement('member'));
                 $tmpElement->nodeValue = $newObject->name();
             }
         }
         return true;
     }
     return false;
 }
 public function load_from_domxml($xml)
 {
     $this->xmlroot = $xml;
     $this->name = DH::findAttribute('name', $xml);
     if ($this->name === FALSE) {
         derr("name not found\n");
     }
     //print "found rule name '".$this->name."'\n";
     $this->extract_disabled_from_domxml();
     $this->extract_description_from_domxml();
     $this->load_tags();
     $this->load_from();
     $this->load_to();
     $this->load_source();
     $this->load_destination();
     //						//
     // Destination NAT properties Extraction	//
     //						//
     $this->dnatroot = DH::findFirstElement('destination-translation', $xml);
     if ($this->dnatroot !== FALSE) {
         //print "rule '".$this->name."' has destination-translation\n";
         if ($this->dnatroot->hasChildNodes()) {
             $this->subdnatTAroot = DH::findFirstElement('translated-address', $this->dnatroot);
             if ($this->subdnatTAroot !== FALSE) {
                 $f = $this->parentAddressStore->findOrCreate($this->subdnatTAroot->textContent, $this);
                 $this->dnathost = $f;
                 $this->subdnatTProot = DH::findFirstElement('translated-port', $this->dnatroot);
                 if ($this->subdnatTProot !== FALSE) {
                     $this->subdnatport = $this->subdnatTProot->textContent;
                 }
             }
         }
     }
     // end of destination translation extraction
     //										//
     // Source NAT properties Extraction		//
     //										//
     $this->snatroot = DH::findFirstElement('source-translation', $xml);
     if ($this->snatroot !== FALSE) {
         //print "we have found a source NAT\n";
         // next <tag> will determine NAT type
         $firstE = DH::firstChildElement($this->snatroot);
         $this->snattype = $firstE->nodeName;
         // Do we support this type of NAT ?
         if ($this->snattype != "static-ip" && $this->snattype != "dynamic-ip-and-port" && $this->snattype != "dynamic-ip") {
             derr("SNAT type '" . $this->snattype . "' for rule '" . $this->name . "' is not supported, EXIT\n");
         }
         //print "Determined NAT type ".$tcur['name']."\n";
         if ($this->snattype == "static-ip") {
             $isbidrx = DH::findFirstElement('bi-directional', $firstE);
             if ($isbidrx !== FALSE) {
                 $this->snatbidir = $isbidrx->textContent;
             }
             $transladx = DH::findFirstElement('translated-address', $firstE);
             $fad = $this->parentAddressStore->findOrCreate($transladx->textContent, $this);
             $this->snathosts->addObject($fad);
             $this->snathosts->xmlroot = $transladx;
         } else {
             if ($this->snattype == "dynamic-ip-and-port") {
                 // Is it <translated-address> type ?
                 $subtype = DH::findFirstElement('translated-address', $firstE);
                 if ($subtype !== FALSE) {
                     if (DH::firstChildElement($subtype) === FALSE) {
                         // this rule has no address specified
                     } else {
                         foreach ($subtype->childNodes as $node) {
                             if ($node->nodeType != 1) {
                                 continue;
                             }
                             $translad = $this->parentAddressStore->findOrCreate($node->textContent, $this);
                             $this->snathosts->addObject($translad);
                         }
                         $this->snathosts->xmlroot = $subtype;
                     }
                 } else {
                     $subtype = DH::findFirstElement('interface-address', $firstE);
                     if ($subtype !== FALSE) {
                         if (DH::firstChildElement($subtype) === FALSE) {
                             derr("Cannot understand dynmaic NAT for rule '" . $this->name . "'\n");
                         }
                         foreach ($subtype->childNodes as $node) {
                             if ($node->nodeType != 1) {
                                 continue;
                             }
                             if ($node->nodeName == 'interface') {
                                 $this->snatinterface = $node->textContent;
                             } else {
                                 if ($node->nodeName == 'ip') {
                                     $translad = $this->parentAddressStore->findOrCreate($node->textContent, $this);
                                     $this->snathosts->addObject($translad);
                                 } else {
                                     derr("Cannot understand dynmaic NAT for rule '" . $this->name . "'\n");
                                 }
                             }
                         }
                     } else {
                         mwarning("Unknown dynamic SNAT type on rule '" . $this->name . " don't mess too much with this rule or face unpredictable results");
                     }
                 }
             }
         }
     }
     //
     // End of Source NAT properties extraction	//
     //  								//
     //	Begin of <service> extraction				//
     //								//
     $this->serviceroot = DH::findFirstElementOrCreate('service', $xml, 'any');
     if ($this->serviceroot !== FALSE) {
         $lname = $this->serviceroot->textContent;
         if (strtolower($lname) != 'any') {
             //print "found service named $lname in  NAT rule '".$this->name."'\n";
             $f = $this->parentServiceStore->findOrCreate($lname, $this, true);
             if (!$f) {
                 derr("Error: service object named '{$lname}' not found in NAT rule '" . $this->name . "'\n");
             }
             $this->service = $f;
         }
     } else {
         derr('unexpected error');
     }
     // End of <service> extraction 	//
 }
 /**
  * @param DOMElement $xml
  */
 public function load_sub_from_domxml($xml)
 {
     $this->xmlroot = $xml;
     $this->name = DH::findAttribute('name', $xml);
     if ($this->name === FALSE) {
         derr("address name not found\n");
     }
     foreach ($xml->childNodes as $node) {
         if ($node->nodeType != 1) {
             continue;
         }
         $nodeName = $node->nodeName;
         if ($nodeName == 'comment') {
             $this->description = $node->textContent;
             //print "Desc found: {$this->description}\n";
         } elseif ($nodeName == 'tag') {
             $this->tag = $node->textContent;
         }
     }
     if ($this->type == 'layer3') {
         if ($this->type == 'layer3') {
             $this->l3ipv4Addresses = array();
             $ipNode = DH::findFirstElement('ip', $xml);
             if ($ipNode !== false) {
                 foreach ($ipNode->childNodes as $l3ipNode) {
                     if ($l3ipNode->nodeType != XML_ELEMENT_NODE) {
                         continue;
                     }
                     $this->l3ipv4Addresses[] = $l3ipNode->getAttribute('name');
                 }
             }
         }
     }
 }
Beispiel #8
0
 /**
  * For developer use only
  */
 protected function load_tags()
 {
     $tmp = DH::findFirstElement('tag', $this->xmlroot);
     if ($tmp !== false) {
         $this->tags->load_from_domxml($tmp);
     }
 }
 public function load_from_domxml($xml)
 {
     $this->xmldoc = $xml;
     $this->configroot = DH::findFirstElementOrDie('config', $this->xmldoc);
     $this->xmlroot = $this->configroot;
     $versionAttr = DH::findAttribute('version', $this->configroot);
     if ($versionAttr !== false) {
         $this->version = PH::versionFromString($versionAttr);
     } else {
         if (isset($this->connector) && $this->connector !== null) {
             $version = $this->connector->getSoftwareVersion();
         } else {
             derr('cannot find PANOS version used for make this config');
         }
         $this->version = $version['version'];
     }
     $tmp = DH::findFirstElementOrCreate('mgt-config', $this->configroot);
     $tmp = DH::findFirstElementOrCreate('devices', $tmp);
     foreach ($tmp->childNodes as $serial) {
         if ($serial->nodeType != 1) {
             continue;
         }
         $s = DH::findAttribute('name', $serial);
         if ($s === FALSE) {
             derr('no serial found');
         }
         $this->managedFirewallsSerials[] = $s;
     }
     $this->sharedroot = DH::findFirstElementOrDie('shared', $this->configroot);
     $this->devicesroot = DH::findFirstElementOrDie('devices', $this->configroot);
     $this->localhostroot = DH::findFirstElementByNameAttrOrDie('entry', 'localhost.localdomain', $this->devicesroot);
     $this->devicegrouproot = DH::findFirstElementOrDie('device-group', $this->localhostroot);
     $this->templateroot = DH::findFirstElementOrDie('template', $this->localhostroot);
     //
     // Extract Tag objects
     //
     if ($this->version >= 60) {
         $tmp = DH::findFirstElementOrCreate('tag', $this->sharedroot);
         $this->tagStore->load_from_domxml($tmp);
     }
     // End of Tag objects extraction
     //
     // Shared address objects extraction
     //
     $tmp = DH::findFirstElementOrCreate('address', $this->sharedroot);
     $this->addressStore->load_addresses_from_domxml($tmp);
     // end of address extraction
     //
     // Extract address groups
     //
     $tmp = DH::findFirstElementOrCreate('address-group', $this->sharedroot);
     $this->addressStore->load_addressgroups_from_domxml($tmp);
     // End of address groups extraction
     //
     // Extract services
     //
     $tmp = DH::findFirstElementOrCreate('service', $this->sharedroot);
     $this->serviceStore->load_services_from_domxml($tmp);
     // End of address groups extraction
     //
     // Extract service groups
     //
     $tmp = DH::findFirstElementOrCreate('service-group', $this->sharedroot);
     $this->serviceStore->load_servicegroups_from_domxml($tmp);
     // End of address groups extraction
     $prerulebase = DH::findFirstElementOrCreate('pre-rulebase', $this->sharedroot);
     $postrulebase = DH::findFirstElementOrCreate('post-rulebase', $this->sharedroot);
     $tmp = DH::findFirstElementOrCreate('security', $prerulebase);
     $tmp = DH::findFirstElementOrCreate('rules', $tmp);
     $tmpPost = DH::findFirstElementOrCreate('security', $postrulebase);
     $tmpPost = DH::findFirstElementOrCreate('rules', $tmpPost);
     $this->securityRules->load_from_domxml($tmp, $tmpPost);
     $tmp = DH::findFirstElementOrCreate('nat', $prerulebase);
     $tmp = DH::findFirstElementOrCreate('rules', $tmp);
     $tmpPost = DH::findFirstElementOrCreate('nat', $postrulebase);
     $tmpPost = DH::findFirstElementOrCreate('rules', $tmpPost);
     $this->natRules->load_from_domxml($tmp, $tmpPost);
     $tmp = DH::findFirstElementOrCreate('decryption', $prerulebase);
     $tmp = DH::findFirstElementOrCreate('rules', $tmp);
     $tmpPost = DH::findFirstElementOrCreate('decryption', $postrulebase);
     $tmpPost = DH::findFirstElementOrCreate('rules', $tmpPost);
     $this->decryptionRules->load_from_domxml($tmp, $tmpPost);
     $tmp = DH::findFirstElementOrCreate('application-override', $prerulebase);
     $tmp = DH::findFirstElementOrCreate('rules', $tmp);
     $tmpPost = DH::findFirstElementOrCreate('application-override', $postrulebase);
     $tmpPost = DH::findFirstElementOrCreate('rules', $tmpPost);
     $this->appOverrideRules->load_from_domxml($tmp, $tmpPost);
     //
     // loading templates
     //
     foreach ($this->templateroot->childNodes as $node) {
         if ($node->nodeType != XML_ELEMENT_NODE) {
             continue;
         }
         $ldv = new Template('*tmp*', $this);
         $ldv->load_from_domxml($node);
         $this->templates[] = $ldv;
         //print "Template '{$ldv->name()}' found\n";
     }
     //
     // end of Templates
     //
     //
     // loading Device Groups now
     //
     if ($this->version < 70) {
         foreach ($this->devicegrouproot->childNodes as $node) {
             if ($node->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             $lvname = $node->nodeName;
             //print "Device Group '$lvname' found\n";
             $ldv = new DeviceGroup($this);
             $ldv->load_from_domxml($node);
             $this->deviceGroups[] = $ldv;
         }
     } else {
         $dgMetaDataNode = DH::findXPathSingleEntryOrDie('/config/readonly/dg-meta-data/dginfo', $this->xmlroot);
         $dgToParent = array();
         $parentToDG = array();
         foreach ($dgMetaDataNode->childNodes as $node) {
             if ($node->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             $dgName = DH::findAttribute('name', $node);
             if ($dgName === false) {
                 derr("DeviceGroup name attribute not found in dg-meta-data", $node);
             }
             $parentDG = DH::findFirstElement('parent-dg', $node);
             if ($parentDG === false) {
                 $dgToParent[$dgName] = 'shared';
                 $parentToDG['shared'][] = $dgName;
             } else {
                 $dgToParent[$dgName] = $parentDG->textContent;
                 $parentToDG[$parentDG->textContent][] = $dgName;
             }
         }
         $dgLoadOrder = array('shared');
         while (count($parentToDG) > 0) {
             $dgLoadOrderCount = count($dgLoadOrder);
             foreach ($dgLoadOrder as &$dgName) {
                 if (isset($parentToDG[$dgName])) {
                     foreach ($parentToDG[$dgName] as &$newDGName) {
                         $dgLoadOrder[] = $newDGName;
                     }
                     unset($parentToDG[$dgName]);
                 }
             }
             if (count($dgLoadOrder) <= $dgLoadOrderCount) {
                 derr('dg-meta-data seems to be corrupted, parent.child template cannot be calculated ', $dgMetaDataNode);
             }
             $dgLoadOrderCount = count($dgLoadOrder);
         }
         /*print "DG loading order:\n";
           foreach( $dgLoadOrder as &$dgName )
               print " - {$dgName}\n";*/
         $deviceGroupNodes = array();
         foreach ($this->devicegrouproot->childNodes as $node) {
             if ($node->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             $nodeNameAttr = DH::findAttribute('name', $node);
             if ($nodeNameAttr === false) {
                 derr("DeviceGroup 'name' attribute was not found", $node);
             }
             if (!is_string($nodeNameAttr) || $nodeNameAttr == '') {
                 derr("DeviceGroup 'name' attribute has invalid value", $node);
             }
             $deviceGroupNodes[$nodeNameAttr] = $node;
         }
         foreach ($dgLoadOrder as $dgIndex => &$dgName) {
             if ($dgName == 'shared') {
                 continue;
             }
             if (!isset($deviceGroupNodes[$dgName])) {
                 mwarning("DeviceGroup '{$dgName}' is listed in dg-meta-data but doesn't exist in XML");
                 //unset($dgLoadOrder[$dgIndex]);
                 continue;
             }
             $ldv = new DeviceGroup($this);
             if (!isset($dgToParent[$dgName])) {
                 mwarning("DeviceGroup '{$dgName}' has not parent associated, assuming SHARED");
             } elseif ($dgToParent[$dgName] == 'shared') {
                 // do nothing
             } else {
                 $parentDG = $this->findDeviceGroup($dgToParent[$dgName]);
                 if ($parentDG === null) {
                     mwarning("DeviceGroup '{$dgName}' has DG '{$dgToParent[$dgName]}' listed as parent but it cannot be found in XML");
                 } else {
                     $parentDG->childDeviceGroups[$dgName] = $ldv;
                     $ldv->parentDeviceGroup = $parentDG;
                 }
             }
             $ldv->load_from_domxml($deviceGroupNodes[$dgName]);
             $this->deviceGroups[] = $ldv;
         }
     }
     //
     // End of DeviceGroup loading
     //
 }
 public function loadcontainers_from_domxml(&$xmlDom)
 {
     foreach ($xmlDom->childNodes as $appx) {
         if ($appx->nodeType != 1) {
             continue;
         }
         $app = new App($appx->tagName, $this);
         $app->type = 'predefined';
         $this->add($app);
         $app->subapps = array();
         //print "found container ".$app->name()."\n";
         $cursor = DH::findFirstElement('functions', $appx);
         if ($cursor === FALSE) {
             continue;
         }
         foreach ($cursor->childNodes as $function) {
             $app->subapps[] = $this->findOrCreate($function->textContent);
             //print "  subapp: ".$subapp->name()." type :".$subapp->type."\n";
         }
     }
 }
 /**
  * @param bool $yes
  * @return bool
  */
 public function setDestinationIsNegated($yes)
 {
     if ($this->negatedDestination != $yes) {
         $tmpRoot = DH::findFirstElement('negate-destination', $this->xmlroot);
         if ($tmpRoot === false) {
             if ($yes) {
                 DH::createElement($this->xmlroot, 'negate-destination', 'yes');
             }
         } else {
             if (!$yes) {
                 $this->xmlroot->removeChild($tmpRoot);
             } else {
                 DH::setDomNodeText($tmpRoot, 'yes');
             }
         }
         $this->negatedDestination = $yes;
         return true;
     }
     return false;
 }
 /**
  * @param $xml DOMElement|DOMDocument
  * @throws Exception
  */
 public function load_from_domxml($xml)
 {
     if ($xml->nodeType == XML_DOCUMENT_NODE) {
         $this->xmldoc = $xml;
         $this->configroot = DH::findFirstElementOrDie('config', $this->xmldoc);
         $this->xmlroot = $this->configroot;
     } else {
         $this->xmlroot = $xml;
         $this->configroot = $xml;
     }
     if ($this->owner !== null) {
         $this->version = $this->owner->owner->version;
     } else {
         $versionAttr = DH::findAttribute('version', $this->configroot);
         if ($versionAttr !== false) {
             $this->version = PH::versionFromString($versionAttr);
         } else {
             if (isset($this->connector) && $this->connector !== null) {
                 $version = $this->connector->getSoftwareVersion();
             } else {
                 derr('cannot find PANOS version used for make this config');
             }
             $this->version = $version['version'];
         }
     }
     $this->devicesroot = DH::findFirstElementOrCreate('devices', $this->configroot);
     $this->localhostroot = DH::findFirstElement('entry', $this->devicesroot);
     if ($this->localhostroot === false) {
         $this->localhostroot = DH::createElement($this->devicesroot, 'entry');
         $this->localhostroot->setAttribute('name', 'localhost.localdomain');
     }
     $this->vsyssroot = DH::findFirstElementOrCreate('vsys', $this->localhostroot);
     if ($this->owner === null) {
         $this->sharedroot = DH::findFirstElementOrDie('shared', $this->configroot);
         //
         // Extract Tag objects
         //
         if ($this->version >= 60) {
             $tmp = DH::findFirstElementOrCreate('tag', $this->sharedroot);
             $this->tagStore->load_from_domxml($tmp);
         }
         // End of Tag objects extraction
         //
         // Shared address objects extraction
         //
         $tmp = DH::findFirstElementOrCreate('address', $this->sharedroot);
         $this->addressStore->load_addresses_from_domxml($tmp);
         // end of address extraction
         //
         // Extract address groups
         //
         $tmp = DH::findFirstElementOrCreate('address-group', $this->sharedroot);
         $this->addressStore->load_addressgroups_from_domxml($tmp);
         // End of address groups extraction
         //
         // Extract services
         //
         $tmp = DH::findFirstElementOrCreate('service', $this->sharedroot);
         $this->serviceStore->load_services_from_domxml($tmp);
         // End of address groups extraction
         //
         // Extract service groups
         //
         $tmp = DH::findFirstElementOrCreate('service-group', $this->sharedroot);
         $this->serviceStore->load_servicegroups_from_domxml($tmp);
         // End of address groups extraction
     }
     //
     // Extract network related configs
     //
     $tmp = DH::findFirstElementOrCreate('network', $this->localhostroot);
     $this->network->load_from_domxml($tmp);
     //
     // Now listing and extracting all VirtualSystem configurations
     foreach ($this->vsyssroot->childNodes as $node) {
         if ($node->nodeType != 1) {
             continue;
         }
         //print "DOM type: ".$node->nodeType."\n";
         $lvsys = new VirtualSystem($this);
         $lvname = DH::findAttribute('name', $node);
         if ($lvname === FALSE) {
             derr('cannot find VirtualSystem name');
         }
         if (isset($this->panorama)) {
             $dg = $this->panorama->findApplicableDGForVsys($this->serial, $lvname);
             if ($dg !== FALSE) {
                 $lvsys->addressStore->panoramaDG = $dg->addressStore;
                 $lvsys->serviceStore->panoramaDG = $dg->serviceStore;
             }
         }
         $lvsys->load_from_domxml($node);
         $this->virtualSystems[] = $lvsys;
         $importedInterfaces = $lvsys->importedInterfaces->interfaces();
         foreach ($importedInterfaces as &$ifName) {
             $resolvedIf = $this->network->findInterface($ifName);
             if ($resolvedIf !== null) {
                 $resolvedIf->importedByVSYS = $lvsys;
             }
         }
     }
 }
Beispiel #13
0
 public function load_from_domxml(DOMElement $xml)
 {
     $this->xmlroot = $xml;
     $this->isTmp = false;
     $this->name = DH::findAttribute('name', $xml);
     if ($this->name === FALSE) {
         derr("zone name not found\n", $xml);
     }
     if (strlen($this->name) < 1) {
         derr("Zone name '" . $this->name . "' is not valid", $xml);
     }
     $networkNode = DH::findFirstElement('network', $xml);
     if ($networkNode === false) {
         return;
     }
     foreach ($networkNode->childNodes as $node) {
         if ($node->nodeType != XML_ELEMENT_NODE) {
             continue;
         }
         if ($node->tagName == 'layer3') {
             $this->_type = 'layer3';
             $this->attachedInterfaces->load_from_domxml($node);
         } else {
             if ($node->tagName == 'external') {
                 $this->_type = 'external';
                 foreach ($node->childNodes as $memberNode) {
                     if ($memberNode->nodeType != XML_ELEMENT_NODE) {
                         continue;
                     }
                     $this->externalVsys[$memberNode->textContent] = $memberNode->textContent;
                 }
                 $this->attachedInterfaces->load_from_domxml($node);
             }
         }
     }
 }
            $saveName = 'stage0.xml';
        }
        print "{$configOutput['connector']->apihost}/{$saveName} ... ";
        $configOutput['connector']->uploadConfiguration(DH::firstChildElement($doc), $saveName, false);
    }
} else {
    derr('not supported yet');
}
print "OK!\n";
if ($loadConfigAfterUpload) {
    print "Loading config in the firewall (will display warnings if any) ...\n";
    /** @var PanAPIConnector $targetConnector */
    $targetConnector = $configOutput['connector'];
    $xmlResponse = $targetConnector->sendCmdRequest('<load><config><from>' . $saveName . '</from></config></load>', true, 600);
    $xmlResponse = DH::firstChildElement($xmlResponse);
    if ($xmlResponse === false) {
        derr('unexpected error !');
    }
    $msgElement = DH::findFirstElement('msg', $xmlResponse);
    if ($msgElement !== false) {
        foreach ($msgElement->childNodes as $msg) {
            if ($msg->nodeType != 1) {
                continue;
            }
            print " - " . $msg->nodeValue . "\n";
        }
    }
}
print "\n************ DONE: UPLOAD CONFIG UTILITY ************\n";
print "*****************************************************";
print "\n\n";
 public function rewriteXML()
 {
     if ($this->owner->owner->version >= 60) {
         $membersRoot = DH::findFirstElement('members', $this->xmlroot);
         if ($membersRoot === false) {
             derr('<members> not found');
         }
         DH::Hosts_to_xmlDom($membersRoot, $this->members, 'member', false);
     } else {
         DH::Hosts_to_xmlDom($this->xmlroot, $this->members, 'member', false);
     }
 }
 /**
  * @ignore
  *
  */
 public function load_from_domxml(DOMElement $xml)
 {
     $this->xmlroot = $xml;
     $this->name = DH::findAttribute('name', $xml);
     if ($this->name === FALSE) {
         derr("address name not found\n");
     }
     $this->_load_description_from_domxml();
     //print "object named '".$this->name."' found\n";
     $typeFound = false;
     foreach ($xml->childNodes as $node) {
         if ($node->nodeType != 1) {
             continue;
         }
         $lsearch = array_search($node->nodeName, self::$AddressTypes);
         if ($lsearch !== FALSE) {
             $typeFound = true;
             $this->type = $lsearch;
             $this->value = $node->textContent;
         }
     }
     if (!$typeFound) {
         derr('object type not found or not supported');
     }
     if ($this->owner->owner->version >= 60) {
         $tagRoot = DH::findFirstElement('tag', $xml);
         if ($tagRoot !== false) {
             $this->tags->load_from_domxml($tagRoot);
         }
     }
 }
 public function setAlternativeName($newName)
 {
     if ($newName == $this->_alternativeName) {
         return false;
     }
     if ($newName === null || strlen($newName) == 0) {
         $node = DH::findFirstElement('display-name', $this->xmlroot);
         if ($node === false) {
             return false;
         }
         $this->xmlroot->removeChild($node);
         return true;
     }
     $node = DH::findFirstElementOrCreate('display-name', $this->xmlroot);
     DH::setDomNodeText($node, $newName);
     return true;
 }
 public function setSourcePort($newPorts)
 {
     if ($newPorts === null || strlen($newPorts) == 0) {
         if (strlen($this->_sport) == 0) {
             return false;
         }
         $this->_sport = $newPorts;
         $sportroot = DH::findFirstElement('source-port', $this->tcpOrUdpRoot);
         if ($sportroot !== false) {
             $this->tcpOrUdpRoot->removeChild($sportroot);
         }
         return true;
     }
     if ($this->_sport == $newPorts) {
         return false;
     }
     if (strlen($this->_sport) == 0) {
         DH::findFirstElementOrCreate('source-port', $this->tcpOrUdpRoot, $newPorts);
         return true;
     }
     $sportroot = DH::findFirstElementOrCreate('source-port', $this->tcpOrUdpRoot);
     DH::setDomNodeText($sportroot, $newPorts);
     return true;
 }
Beispiel #19
0
 /**
  * @param string $tagName
  * @param DOMNode $node
  * @param null|string $withText
  * @return bool|DOMElement|DOMNode
  */
 static function findFirstElementOrCreate($tagName, DOMNode $node, $withText = null)
 {
     $ret = DH::findFirstElement($tagName, $node);
     if ($ret === FALSE) {
         return DH::createElement($node, $tagName, $withText);
     }
     return $ret;
 }
 public function getSavedConfig($configurationName)
 {
     //$url = 'action=get&type=config&xpath=/config';
     $url = "type=op&cmd=<show><config><saved>{$configurationName}</saved></config></show>";
     $r = $this->sendRequest($url, true);
     $configRoot = DH::findFirstElement('result', $r);
     if ($configRoot === false) {
         derr("<result> was not found", $r);
     }
     $configRoot = DH::findFirstElement('config', $configRoot);
     if ($configRoot === false) {
         derr("<config> was not found", $r);
     }
     DH::makeElementAsRoot($configRoot, $r);
     return $r;
 }