3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (!isset($_SESSION)) { session_start(); } function dumpDOMnodeList($xml) { $docTmp = new DOMDocument(); foreach($xml as $n) $docTmp->appendChild($docTmp->importNode($n,true)); //echo '<pre>'; print_r($docTmp->saveHTML()); //echo '</pre>'; } class ipm { //BEGIN VARIABLES public $soapVersion; public $soapLocation; public $soapContext; public $soapParameters; public $soapClient; public $soapCookies; public $soapService; const groupID = '104362395629'; //MAIN GROUP NUMBER WITHIN IPM, NEVER CHANGES //END VARIABLES //BEGIN CONSTRUCTOR function __construct($soapService) { $this->soapService = $soapService; //STATUS OR CONFIG $this->soapVersion = '1.2'; $this->soapLocation = 'https://webservice.domain/soap/'.$this->soapService.'.asmx'; $this->soapContext = stream_context_create(array('ssl' => array('verify_peer' => TRUE))); $this->soapParameters = array ( 'location' => $this->soapLocation, 'login' => 'user', 'password' => 'password', 'stream_context' => $this->soapContext, 'trace' => 1, 'keep_alive' => 1, 'cache_wsdl' => WSDL_CACHE_NONE ); $this->soapClient = new SoapClient('./'.$this->soapService.'.wsdl',$this->soapParameters); } //END CONSTRUCTOR //BEGIN PRIVATE FUNCTIONS private function schemaOpen($fn='',$vars) { $tmp = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'; if(empty($vars)) { return $tmp.'<soap:Body><'.$fn.' xmlns="'.$this->schemaBase().'" />'; } else { return $tmp.'<soap:Body><'.$fn.' xmlns="'.$this->schemaBase().'">'; } } private function schemaClose($fn='',$vars) { if(empty($vars)) { return '</soap:Body></soap:Envelope>'; } else { return '</'.$fn.'></soap:Body></soap:Envelope>'; } } private function schemaBase($fn='') { return 'http://schemas.ipmonitor.com/ipm70/'.$fn; } private function dumpDOMnodeList($xml) { $docTmp = new DOMDocument(); foreach($xml as $n) $docTmp->appendChild($docTmp->importNode($n,true)); echo '<pre>'; print_r(htmlentities($docTmp->saveHTML())); echo '</pre>'; } private function debugSoap() { echo '<pre>'; echo $this->soapClient->__getLastRequestHeaders(); echo $this->soapClient->__getLastRequest(); echo $this->soapClient->__getLastResponseHeaders(); echo '</pre>'; } private function soapRequest($fn='',$vars=array()) { $xml=$this->schemaOpen($fn,$vars); foreach($vars as $key=>$val) { $xml .= '<'.$key.'>'.$val.'</'.$key.'>'; } $xml.=$this->schemaClose($fn,$vars); return $xml; } private function callMethod($fn,$vars=array()) { $soapRequest = $this->soapRequest($fn,$vars); $soapAction = $this->schemaBase($fn); $soapResponse = $this->soapClient->__doRequest($soapRequest, $this->soapLocation, $soapAction, $this->soapVersion,0); $this->logSoap($soapRequest, $this->soapLocation, $soapAction, $this->soapVersion, $soapResponse,$this->debugSoap()); return $soapResponse; } private function logSoap($request, $location, $action, $version, $reponse, $debug) { file_put_contents('soap_log', date('m-d-Y H:i:s')."\r\nRequest: $request\r\n\r\nLocation: $location\r\nAction: $action\r\nVersion: $version\r\nResponse: $response\r\nDebug: $debug\r\n\r\n"); } //END PRIVATE FUNCTIONS //BEGIN METHODS public function GetGroup($rtGroupID) { /* GetGroup returns the status and some minor details about a specific Monitor. */ return $this->callMethod(__FUNCTION__,array('id'=>$rtGroupID)); } public function GetGroups() { /* GetGroups returns the status of members and depends of a specific Group */ return $this->callMethod(__FUNCTION__,array()); } public function GetMonitors($rtGroupID) { /* GetMonitor returns the status of the members and depends of a specific Group. */ return $this->callMethod(__FUNCTION__,array('groupid'=>$rtGroupID,'bTroubleOnly'=>'TRUE')); } public function GetMonitor($rtMonitorID) { /* GetMonitor returns the status and some minor details about a specific Monitor. */ return $this->callMethod(__FUNCTION__,array('id'=>$rtMonitorID)); } public function MonitorView($rtMonitorID) { /* MonitorView retrieves an ipMonitor 7 Monitor objects's settings in xml format. */ return $this->callMethod(__FUNCTION__,array('mon_id'=>$rtMonitorID)); } public function GroupList() { /* GroupList retrieves the ID's of all the existing Group objects. */ return $this->callMethod(__FUNCTION__,array()); } public function GroupView($rtGroupID) { /* GroupView retrieves an ipMonitor 7 Group objects's settings in xml format. */ return $this->callMethod(__FUNCTION__,array('groupid'=>$rtGroupID)); } //END METHODS } /* BEGIN GET ALL DOWN MONITORS */ $ipm = new ipm('status'); $ipmGroups = $ipm->GetGroups(); if(!empty($ipmGroups)) { $doc = new DOMDocument(); $doc->LoadXML($ipmGroups); $xpath = new DOMXpath($doc); $xpath->registerNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); $xpath->registerNamespace('def', 'http://schemas.ipmonitor.com/ipm70/'); $ipmGroupsAlarming = $xpath->query("/soap:Envelope/soap:Body/def:GetGroupsResponse/def:GetGroupsResult/def:rtGroup[(contains(def:status,'lost') or contains(def:status,'warn') or contains(def:status,'down')) and contains(def:isroot,'false')]"); $numGroupsAlarming = $ipmGroupsAlarming->length; if($numGroupsAlarming === 0) { echo '<div class="text-success">No issues</div>'."\r\n"; } else { unset($ipm,$ipmGroups,$doc,$xpath,$numGroupsAlarming); foreach($ipmGroupsAlarming as $ipmGroupAlarming) { $groupName = $ipmGroupAlarming->getElementsByTagName('name')->item(0)->nodeValue; $groupStatus = $ipmGroupAlarming->getElementsByTagName('status')->item(0)->nodeValue; $groupID = $ipmGroupAlarming->getElementsByTagName('id')->item(0)->nodeValue; echo $groupName.'<br/>'."\r\n"; $ipm = new ipm('status'); $ipmMonitors= $ipm->GetMonitors($groupID); $doc = new DOMDocument(); $doc->LoadXML($ipmMonitors); $xpath = new DOMXpath($doc); $xpath->registerNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); $xpath->registerNamespace('def', 'http://schemas.ipmonitor.com/ipm70/'); $ipmMonitorsAlarming = $xpath->query("/soap:Envelope/soap:Body/def:GetMonitorsResponse/def:GetMonitorsResult/def:rtMonitor"); $numMonitorsAlarming = $ipmMonitorsAlarming->length; if($numMonitorsAlarming === 0) { echo 'No Monitors Down Under This Device<br/>'."\r\n"; } else { foreach($ipmMonitorsAlarming as $ipmMonitorAlarming) { $monitorName = $ipmMonitorAlarming->getElementsByTagName('name')->item(0)->nodeValue; $monitorStatus = $ipmMonitorAlarming->getElementsByTagName('status')->item(0)->nodeValue; $monitorID = $ipmMonitorAlarming->getElementsByTagName('id')->item(0)->nodeValue; echo '--&gt; '.$monitorStatus.' - '.$monitorName.'<br/>'."\r\n"; } } unset($ipm,$ipmMonitors,$doc,$xpath,$numMonitorsAlarming,$ipmMonitorsAlarming); echo '<br/>'; } } } elseif($ipmGroups == NULL) {echo 'NULL SOAP RESPONSE';} else { echo 'No issues'."\r\n"; } /* END GET ALL DOWN MONITORS */ ?>
Output for 7.0.0 - 7.1.0
Notice: Use of undefined constant WSDL_CACHE_NONE - assumed 'WSDL_CACHE_NONE' in /in/jeSkS on line 42 Fatal error: Uncaught Error: Class 'SoapClient' not found in /in/jeSkS:44 Stack trace: #0 /in/jeSkS(183): ipm->__construct('status') #1 {main} thrown in /in/jeSkS on line 44
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Notice: Use of undefined constant WSDL_CACHE_NONE - assumed 'WSDL_CACHE_NONE' in /in/jeSkS on line 43 Fatal error: Class 'SoapClient' not found in /in/jeSkS on line 44
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from './status.wsdl' : failed to load external entity "./status.wsdl" in /in/jeSkS:44 Stack trace: #0 /in/jeSkS(44): SoapClient->SoapClient('./status.wsdl', Array) #1 /in/jeSkS(183): ipm->__construct('status') #2 {main} thrown in /in/jeSkS on line 44
Process exited with code 255.