#!/usr/bin/php '; $tmp = DoCurl($data_url,$data_soap,$data_xml); $data_result = Array(); $data_result['NewLayer1UpstreamMaxBitRate'] = FindKey($tmp,"NewLayer1UpstreamMaxBitRate"); $data_result['NewLayer1DownstreamMaxBitRate'] = FindKey($tmp,"NewLayer1DownstreamMaxBitRate"); $data_result['NewWANAccessType'] = FindKey($tmp,"NewWANAccessType"); $data_result['NewPhysicalLinkStatus'] = FindKey($tmp,"NewPhysicalLinkStatus"); return $data_result; } function GetAddonInfos() { $data_url = '/igdupnp/control/WANCommonIFC1'; $data_soap = '"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"'; $data_xml = ''; $tmp = DoCurl($data_url,$data_soap,$data_xml); $data_result = Array(); $data_result['NewTotalBytesSent'] = FindKey($tmp,"NewTotalBytesSent"); $data_result['NewTotalBytesReceived'] = FindKey($tmp,"NewTotalBytesReceived"); return $data_result; } function GetExternalIP() { $data_url = '/igdupnp/control/WANIPConn1'; $data_soap = '"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"'; $data_xml = ''; $tmp = DoCurl($data_url,$data_soap,$data_xml); $data_result = Array(); $data_result['NewExternalIPAddress'] = FindKey($tmp,"NewExternalIPAddress"); return $data_result; } function DoCurl($url,$soap,$xml) { $ch = curl_init("http://" . $GLOBALS["host"] . ":49000" . $url); $headers = array(); //$headers[] = 'POST ' . $url . ' HTTP/1.1'; // Will be automatically set. $headers[] = 'Content-Type: text/xml; charset="utf-8"'; $headers[] = 'HOST: ' . $GLOBALS["host"] . ':49000'; $headers[] = 'Content-Length: ' . strlen($xml); $headers[] = 'SOAPACTION: ' . $soap; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_IPRESOLVE, 1); // Force IPv4 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); // Add XML in POST-Header $tmp = curl_exec($ch); curl_close($ch); return $tmp; } function FindKey($text,$key) { $p1 = strpos($text,$key); if($p1 === false) { $tmp = ""; } else { $p1 = strpos($text,'>',$p1) +1; $p2 = strpos($text,'<',$p1); if($p2 === false) { $tmp = ""; } else { $tmp = substr($text,$p1,$p2-$p1); } } return $tmp; } ?>