<?php /** * Remote Service Display module for ZPanelX (uses XMWS) * Written by Bobby Allen, 05/04/2012. */ require_once 'lib/xmwsclient.class.php'; $service_status = new xmwsclient(); $service_status->InitRequest($apiurl, 'services', 'GetServiceStatus', $apikey); $response_array = $service_status->XMLDataToArray($service_status->Request($service_status->BuildRequest())); if ($response_array['xmws']['response'] != '1101') { die("API Error: " . $response_array['xmws']['content']); } /** * We have to manually check the DNS port at present as DNS is not currently part of the standard port array in the service webservice class (will add in ZPX 1.0.1) */ $dns_status = new xmwsclient(); $dns_status->InitRequest($apiurl, 'services', 'GetPortStatus', $apikey); $dns_status->SetRequestData("<port>53</port>"); $dnsresponse_array = $dns_status->XMLDataToArray($dns_status->Request($dns_status->BuildRequest())); if ($dnsresponse_array['xmws']['response'] != '1101') { die("API Error: " . $response_array['xmws']['content']); }
// URL to the ZPanel server (with or without the trailing slash) $xmws->wsurl = 'http://localhost/zpanelx/'; // The server won't help you unless you can authenticate with the correct server API key (the key is a Zpanel setting, use ctrl_options::GetOption('apikey') to find out what yours is) $xmws->serverkey = 'ee8795c8c53bfdb3b2cc595186b68912'; // Specify the 'module' where the web service class exists in. $xmws->module = 'test'; // Specify what method you want to run and get the response back from. $xmws->method = 'TestMe'; // If the web service class requires authentication then you need to specify the username and password! - This is a ZPanel user account! $xmws->username = ''; $xmws->password = ''; // Finally we now send over any variables that can be used by the Zpanel module to help with the request (eg. a string, a comma seperated list, binary data etc.) if not required then it can be left blank. $xmws->SetRequestData('Bobby Allen, how come you ask? and what is yours?'); // Alternatively you can set it using the normal class variable set like: $xmws->data = ''; // Now we just prepare the XML, this can be built dynamically (like in this example) or you can specify raw XML if you wish. $auto_prepared_xml = $xmws->BuildRequest(); // So here we are sending the request and converting the response into a PHP array so we can access the data in an easy to handle format. // By just requesting $repsonse = $xmws->Request($auto_prepared_xml); you would recieve the raw request. (XML data) $ws_handle = $xmws->ResponseToArray($xmws->Request($auto_prepared_xml)); if ($ws_handle['response'] == 1101) { echo "<table><tr><th>Server response data</th></tr><tr><td>" . $ws_handle['data'] . "</td></tr></table>"; } else { echo "Something appeared to go wrong! The webservice reported response code: <strong>" . $ws_handle['response'] . "</strong>, The human readable version of this error is: '<strong>" . $ws_handle['data'] . "</strong>'"; } // This can be used to debug, this shows the values of the response. /*$xmws->ShowXMLAsArrayData($xmws->Request($auto_prepared_xml));*/ // Another example of how to quickly grab everything is like so:- /*$another_xmws_instance = new xmwsclient(); $another_xmws_instance->InitRequest('http://localhost/zpanelx/', 'test', 'TestMe', 'ee8795c8c53bfdb3b2cc595186b68912'); $another_xmws_instance->SetRequestData('some_example_variable_data_here'); $response_data = $another_xmws_instance->ResponseToArray($another_xmws_instance->Request($another_xmws_instance->BuildRequest()));