| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
- /**
- * Zm_Server
- *
- * @author Yannick Lorenz <ylorenz@1g6.biz>
- * @author Fabrizio La Rosa <fabrizio.larosa@unime.it>
- * @version 2.2
- * @copyright Copyright (c) 2009, Yannick Lorenz
- * @copyright Copyright (c) 2012, Fabrizio La Rosa
- * @example ../test.php
- */
- /**
- * Zm_Server class documentation
- */
- // utils.php contains a small collection of useful functions
- require_once ("utils.php");
- /**
- * Zm_Server is a class which allows to manage Kerio servers via SOAP
- *
- * You may create, modify, rename, delete and get the attributes of a Kerio server using this class
- *
- * For the usage examples of all class methods check the source code of test.php
- */
- class Zm_Server
- {
- /**
- * $auth
- * @var Zm_Auth $auth soap authentication
- */
- private $auth;
- /**
- * Constructor
- * @param Zm_Auth $auth soap authentication
- */
- function __construct($auth)
- {
- $this->auth = $auth;
- }
- /**
- * getAllServers
- * @return array informations
- */
- function getAllServers()
- {
- $result = null;
- try
- {
- $result = $this->auth->execSoapCall(
- "GetAllServersRequest"
- );
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return $result;
- }
- /**
- * getServerId
- * @param string $name a server name
- * @return string a server id
- */
- function getServerId($name)
- {
- $result = null;
- $params = array(
- new SoapVar('<ns1:server by="name">' . $name . '</ns1:server>', XSD_ANYXML),
- );
- try
- {
- $result = $this->auth->execSoapCall(
- "GetServerRequest",
- $params
- );
- $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETSERVERRESPONSE']['SERVER']['ID'];
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return $result;
- }
- /**
- * serverExists
- * @param string $idOrNameServer server id or server name
- * @param string $type value of the server (auto, name, id)
- * @return bool exists
- */
- function serverExists($idOrNameServer, $type="auto")
- {
- if($type == "auto")
- $realType = getServerType($idOrNameServer);
- else
- $realType = $type;
- $result = null;
- $params = array(
- new SoapVar('<ns1:server by="' . $realType . '">' . $idOrNameServer . '</ns1:server>', XSD_ANYXML),
- );
- try
- {
- $result = $this->auth->execSoapCall(
- "GetServerRequest",
- $params
- );
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return (!is_a($result, "Exception"));
- }
- /**
- * getServerOptions
- * @param string $idOrNameServer server id or server name
- * @param string $type value of the server (auto, name, id)
- * @return array
- */
- function getServerOptions($idOrNameServer, $type="auto")
- {
- if($type == "auto")
- $realType = getServerType($idOrNameServer);
- else
- $realType = $type;
- $result = null;
- $params = array(
- new SoapVar('<ns1:server by="' . $realType . '">' . $idOrNameServer . '</ns1:server>', XSD_ANYXML),
- );
- try
- {
- $result = $this->auth->execSoapCall(
- "GetServerRequest",
- $params
- );
- $attrs = array();
- foreach ($result['SOAP:ENVELOPE']['SOAP:BODY']['GETSERVERRESPONSE']['SERVER']['A'] as $a) {
- $attrs[$a['N']] = $a['DATA'];
- }
- $result = $attrs;
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return $result;
- }
- /**
- * createServer
- * @param string $name a server name
- * @param array $attrs an optional array containing the server attributes to be set
- * @return array an array with the new server's info
- */
- function createServer($name, $attrs = array ())
- {
- $result = null;
- $params = array(
- new SoapParam($name, "name"),
- );
- foreach ($attrs as $key=>$value)
- $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
- try
- {
- $result = $this->auth->execSoapCall(
- "CreateServerRequest",
- $params
- );
- $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATESERVERRESPONSE']['SERVER'];
- usleep(250000); // introduce a small delay, otherwise some troubles may arise if we modify the new server right after its creation
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return $result;
- }
- /**
- * modifyServer
- * @param string $idOrNameServer server id or server name
- * @param array $attrs an array containing the server attributes to be set
- * @param string $type value of the server (auto, name, id)
- * @return array informations
- */
- function modifyServer($idOrNameServer, $attrs = array(), $type="auto")
- {
- if($type == "auto")
- $realType = getServerType($idOrNameServer);
- else
- $realType = $type;
- if($realType == "name")
- $serverId = $this->getServerId($idOrNameServer);
- else
- $serverId = $idOrNameServer;
- $result = null;
- $params = array(
- new SoapParam($serverId, "id"),
- );
- foreach ($attrs as $key=>$value)
- $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
- try
- {
- $result = $this->auth->execSoapCall(
- "ModifyServerRequest",
- $params
- );
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return $result;
- }
- /**
- * deleteServer
- * @param string $idOrNameServer server id or server name
- * @param string $type value of the server (auto, name, id)
- * @return array informations
- */
- function deleteServer($idOrNameServer, $type="auto")
- {
- if($type == "auto")
- $realType = getServerType($idOrNameServer);
- else
- $realType = $type;
- if($realType == "name")
- $serverId = $this->getServerId($idOrNameServer);
- else
- $serverId = $idOrNameServer;
- $result = null;
- $params = array(
- new SoapParam($serverId, "id"),
- );
- try
- {
- $result = $this->auth->execSoapCall(
- "DeleteServerRequest",
- $params
- );
- }
- catch (SoapFault $exception)
- {
- $result = $exception;
- }
- return $result;
- }
- }
- ?>
|