public function load_from_domxml(DOMElement $xml)
 {
     $this->xmlroot = $xml;
     foreach ($xml->childNodes as $node) {
         if ($node->nodeType != XML_ELEMENT_NODE) {
             continue;
         }
         $interfaceString = $node->textContent;
         $interface = $this->parentCentralStore->findInterfaceOrCreateTmp($interfaceString);
         $this->add($interface);
     }
 }
Exemplo n.º 2
0
 /**
  * @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;
             }
         }
     }
 }