private function _call($request) { $response = pm_ApiRpc::getService('1.6.5.0')->call($request); // TODO error handling // $response->dns->add_to_acl->result->status // $response->dns->remove_from_acl->result->status }
private function _isClientExist($login) { $apiRequest = <<<APICALL <customer> <get> <filter> <login>{$login}</login> </filter> <dataset> <gen_info/> </dataset> </get> </customer> APICALL; $apiResponse = pm_ApiRpc::getService()->call($apiRequest); $result = $apiResponse->customer->get->result; return $result->status && 'ok' == $result->status; }
public function getServerIP() { if (self::$_serverIp) { return self::$_serverIp; } $request = "<ip><get/></ip>"; $response = pm_ApiRpc::getService('1.6.5.0')->call($request); if ('ok' != $response->ip->get->result->status) { throw new pm_Exception("Unable to get server IP. Error: {$response->ip->get->result->errtext}"); } // Get default IP foreach ($response->ip->get->result->addresses->ip_info as $address) { if (!isset($address->default)) { continue; } return self::$_serverIp = (string) $address->public_ip_address ?: (string) $address->ip_address; } // Get first IP foreach ($response->ip->get->result->addresses->ip_info as $address) { return self::$_serverIp = (string) $address->public_ip_address ?: (string) $address->ip_address; } throw new pm_Exception("Unable to get server IP: empty result."); }
/** * Perform API request * * @param string|array|SimpleXMLElement $request * @param int $mode * @return XmlResponse */ public function request($request, $mode = self::RESPONSE_SHORT) { if ($request instanceof SimpleXMLElement) { $request = $request->asXml(); } else { $xml = $this->getPacket(); if (is_array($request)) { $request = $this->_arrayToXml($request, $xml)->asXML(); } else { if (preg_match('/^[a-z]/', $request)) { $request = $this->_expandRequestShortSyntax($request, $xml); } } } if ('sdk' == $this->_protocol) { $requestXml = new SimpleXMLElement((string) $request); $xml = \pm_ApiRpc::getService()->call($requestXml->children()[0]->asXml()); } else { $xml = $this->_performHttpRequest($request); } $this->_verifyResponse($xml); return self::RESPONSE_FULL == $mode ? $xml : $xml->xpath('//result')[0]; }
<?php pm_Context::init('example'); $id = pm_Settings::get('customButtonId'); $request = <<<APICALL <ui> <delete-custombutton> <filter> <custombutton-id>{$id}</custombutton-id> </filter> </delete-custombutton> </ui> APICALL; try { $response = pm_ApiRpc::getService()->call($request); $result = $response->ui->{"delete-custombutton"}->result; if (true || 'ok' == $result->status) { echo "done\n"; exit(0); } else { echo "error {$result->errcode}: {$result->errtext}\n"; exit(1); } } catch (PleskAPIParseException $e) { echo $e->getMessage() . "\n"; exit(1); }
public function __construct() { $request = '<server><get><stat/></get></server>'; $this->_stats = pm_ApiRpc::getService()->call($request)->server->get->result->stat->objects; }