Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
class-IkeCryptoProfileStore - bring in new methods for IKE import
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Waschkut committed Jun 12, 2018
1 parent 9c83691 commit 39e2a0d
Showing 1 changed file with 63 additions and 18 deletions.
81 changes: 63 additions & 18 deletions lib/network-classes/class-IkeCryptoProfileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +38,7 @@ public function __construct($name, $owner)
/**
* @return IkeCryptoProfil[]
*/
public function ikeCryptProfil()
public function ikeCryptoProfil()
{
return $this->o;
}
Expand All @@ -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);
}
}

}
}

0 comments on commit 39e2a0d

Please sign in to comment.