From 39e2a0dd6ec59b729b71f0b674c93290cba1ac0f Mon Sep 17 00:00:00 2001 From: Sven Waschkut Date: Tue, 12 Jun 2018 16:22:34 +0200 Subject: [PATCH] class-IkeCryptoProfileStore - bring in new methods for IKE import --- .../class-IkeCryptoProfileStore.php | 81 ++++++++++++++----- 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/lib/network-classes/class-IkeCryptoProfileStore.php b/lib/network-classes/class-IkeCryptoProfileStore.php index 838f1805..44ed6c0b 100644 --- a/lib/network-classes/class-IkeCryptoProfileStore.php +++ b/lib/network-classes/class-IkeCryptoProfileStore.php @@ -25,6 +25,9 @@ class IkeCryptoProfileStore extends ObjStore { public static $childn = 'IkeCryptoProfil'; + protected $fastMemToIndex=null; + protected $fastNameToIndex=null; + public function __construct($name, $owner) { $this->name = $name; @@ -35,7 +38,7 @@ public function __construct($name, $owner) /** * @return IkeCryptoProfil[] */ - public function ikeCryptProfil() + public function ikeCryptoProfil() { return $this->o; } @@ -62,27 +65,69 @@ public function find($name, $ref=null, $nested = true) /** - * @param $name string - * @param $type string - * @param $value string - * @param string $description - * @return Address - * @throws Exception + * Creates a new IkeCryptoProfil in this store. It will be placed at the end of the list. + * @param string $name name of the new IkeCryptoProfil + * @return IkeCryptoProfil + */ + public function newIkeCryptoProfil( $name ) + { + $CryptoProfile = new IkeCryptoProfil( $name, $this); + $xmlElement = DH::importXmlStringOrDie($this->owner->xmlroot->ownerDocument, IkeCryptoProfil::$templatexml); + + $CryptoProfile->load_from_domxml($xmlElement); + + $CryptoProfile->owner = null; + $CryptoProfile->setName($name); + + $this->addProfil( $CryptoProfile ); + + return $CryptoProfile; + } + + /** + * @param IkeCryptoProfil $CryptoProfile + * @return bool */ - public function newIkeCryptoProfil($name , $type, $value, $description = '') + public function addProfil( $CryptoProfile ) { - $found = $this->find($name,null, true); - if( $found !== null ) - derr("cannot create Address named '".$name."' as this name is already in use"); + if( !is_object($CryptoProfile) ) + derr('this function only accepts IKEGateway class objects'); + + if( $CryptoProfile->owner !== null ) + derr('Trying to add a gateway that has a owner already !'); + + + $ser = spl_object_hash($CryptoProfile); + + if (!isset($this->fastMemToIndex[$ser])) + { + $CryptoProfile->owner = $this; - $newObject = new Address($name,$this, true); - $newObject->setType($type); - $newObject->setValue($value); - $newObject->setDescription($description); + if( $this->xmlroot === null ) + $this->createXmlRoot(); - $this->add($newObject); + $this->xmlroot->appendChild($CryptoProfile->xmlroot); - return $newObject; + return true; + } else + derr('You cannot add a Gateway that is already here :)'); + + return false; + } + + public function createXmlRoot() + { + if( $this->xmlroot === null ) + { + //TODO: 20180331 why I need to create full path? why it is not set before??? + $xml = DH::findFirstElementOrCreate('devices', $this->owner->xmlroot); + $xml = DH::findFirstElementOrCreate('entry', $xml); + $xml = DH::findFirstElementOrCreate('network', $xml); + $xml = DH::findFirstElementOrCreate('ike', $xml); + $xml = DH::findFirstElementOrCreate('crypto-profiles', $xml); + + $this->xmlroot = DH::findFirstElementOrCreate('ike-crypto-profiles', $xml); + } } -} \ No newline at end of file +}