Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- $fbroot ='http://fritz.box:49000'; //Adresse + Port (immer 49000)
- $desc = "igddesc.xml"; //Hier sind die Infos über die Dienste enthalten
- $SCPD = "igdicfgSCPD.xml"; // Hier sind die Infos über die Funktionen und Parameter/Variablen enthalten, sowie die Definition der Variablen Typen.
- $action="GetAddonInfos"; //Diese Funktion soll ausgeführt werden
- // FB_getServiceData holt alle benötigten Daten aus der $desc XML
- $service = FB_getServiceData($fbroot,$desc,$SCPD,$action);
- //$service =
- /*array(3) {
- ["uri"]=>
- string(55) "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
- ["location"]=>
- string(52) "http://fritz.box:49000/igdupnp/control/WANCommonIFC1"
- ["SCPDURL"]=>
- string(15) "igdicfgSCPD.xml"
- }
- */
- // FB_getStateVars holt die Definition der Variablen aus der SCPD XML für die gewählte Aktion
- // Wen die die Typen kennt/manuell die IPS-Variablen befüllt, braucht Ihr diese Funktion nicht ausführen.
- $StateVars = FB_getStateVars ($fbroot,$service,$action);
- /*
- $StateVars = (Beispiel)
- array(14) {
- ["NewByteSendRate"]=>
- string(3) "ui4"
- ["NewByteReceiveRate"]=>
- string(3) "ui4"
- ["NewPacketSendRate"]=>
- string(3) "ui4"
- ["NewPacketReceiveRate"]=>
- string(3) "ui4"
- ["NewTotalBytesSent"]=>
- string(3) "ui4"
- ["NewTotalBytesReceived"]=>
- string(3) "ui4"
- ["NewAutoDisconnectTime"]=>
- string(3) "ui4"
- ["NewIdleDisconnectTime"]=>
- string(3) "ui4"
- ["NewDNSServer1"]=>
- string(6) "string"
- ["NewDNSServer2"]=>
- string(6) "string"
- ["NewVoipDNSServer1"]=>
- string(6) "string"
- ["NewVoipDNSServer2"]=>
- string(6) "string"
- ["NewUpnpControlEnabled"]=>
- string(7) "boolean"
- ["NewRoutedBridgedModeBoth"]=>
- string(7) "boolean"
- }
- */
- // FB_SoapAction($service,$action,$user = false,$pass = false) führt den SOAP Request aus. Variablen wie oben beschrieben. $service könnt ihr auch manuell befüllen, dann wird FB_getServiceData auch nicht benötigt.
- $result = FB_SoapAction($service,$action);
- /*
- $result = (Beispiel)
- array(14) {
- ["NewByteSendRate"]=>
- string(5) "14380"
- ["NewByteReceiveRate"]=>
- string(6) "900533"
- ["NewPacketSendRate"]=>
- string(3) "209"
- ["NewPacketReceiveRate"]=>
- string(3) "605"
- ["NewTotalBytesSent"]=>
- string(8) "27991885"
- ["NewTotalBytesReceived"]=>
- string(10) "1116689220"
- ["NewAutoDisconnectTime"]=>
- string(1) "0"
- ["NewIdleDisconnectTime"]=>
- string(1) "0"
- ["NewDNSServer1"]=>
- string(14) "111.111.111"
- ["NewDNSServer2"]=>
- string(14) "111.111.111"
- ["NewVoipDNSServer1"]=>
- string(14) "111.111.111"
- ["NewVoipDNSServer2"]=>
- string(14) "111.111.111"
- ["NewUpnpControlEnabled"]=>
- string(1) "0"
- ["NewRoutedBridgedModeBoth"]=>
- string(1) "0"
- }
- */
- // UpdateIPSvar($parent,$ident,$value,$type) ist eine 'typische' Hilfsfunktion, welche eine Variable erstellt wenn sie nicht vorhanden ist und sie mit den aktuellen Daten (bei Änderung) befüllt.
- // $parent = IPS_ID welche der Parent der Variable ist /wird
- // $ident = IDENT der Variable zum wiederfinden (wird beim anlegen auch als Name genutzt; Name kann jederzeit geändert werden im Objektbaum)
- // $value = Neuer Wert der Variable
- // $type = String welcher den Type der Variable im FritzBox-Format enthält. Oder als int den Typ in IPS-Format (0 = bool, 1 = int, 2 = float, 3 = string)
- UpdateIPSvar(IPS_GetParent($_IPS['SELF']),'KByteSendRate',$result['NewByteSendRate']/1024,2);
- UpdateIPSvar(IPS_GetParent($_IPS['SELF']),'KByteReceiveRate',$result['NewByteReceiveRate']/1024,2);
- function FB_getServiceData($fbroot,$desc,$SCPD,$action)
- {
- $xml = @simplexml_load_file($fbroot.'/'.$desc);
- if ($xml === false)
- {
- echo "Not found:".$descXML.PHP_EOL;
- return false;
- }
- $xml->registerXPathNamespace('fb', $xml->getNameSpaces(false)[""]);
- $xmlservice = $xml->xpath("//fb:service[fb:SCPDURL='/".$SCPD."']");
- $service['uri'] = (string)$xmlservice[0]->serviceType;
- $service['location'] =$fbroot.(string)$xmlservice[0]->controlURL;
- $service['SCPDURL'] =trim((string)$xmlservice[0]->SCPDURL,"/");
- return $service;
- }
- function FB_getStateVars ($fbroot,$service,$action)
- {
- $xmlDesc = @simplexml_load_file($fbroot.'/'.$service['SCPDURL']);
- if ($xmlDesc === false)
- {
- echo "Not found:".$service['SCPDURL'].PHP_EOL;
- return false;
- }
- $xmlDesc->registerXPathNamespace('fritzbox', $xmlDesc->getNameSpaces(false)[""]);
- $xmlArgumentList = $xmlDesc->xpath("//fritzbox:actionList/fritzbox:action[fritzbox:name='".$action."']/fritzbox:argumentList/fritzbox:argument");
- $StateVariables=false;
- foreach ($xmlArgumentList as $xmlArgument)
- {
- $xmlStateVariable = $xmlDesc->xpath("//fritzbox:stateVariable[fritzbox:name='".(string)$xmlArgument->relatedStateVariable."']");
- $StateVariables[(string)$xmlArgument->name] = (string)$xmlStateVariable[0]->dataType;
- }
- return $StateVariables;
- }
- function FB_SoapAction($service,$action,$user = false,$pass = false)
- {
- $service['noroot'] = true;
- $service['trace'] = false;
- $service['exceptions'] = false;
- if (!($user === false))
- {
- $service['login'] = $user;
- $service['password'] = $pass;
- }
- $client = new SoapClient(null,$service);
- $status = $client->{$action}();
- if (is_soap_fault($status))
- {
- return false;
- }
- return $status;
- }
- function UpdateIPSvar($parent,$ident,$value,$type)
- {
- $ident=str_replace(array("_","-"),array("",""),$ident);
- if (is_int($type))
- {
- $ips_type=$type;
- } else {
- switch ($type)
- {
- case "i1":
- case "i2":
- case "i4":
- case "ui1":
- case "ui2":
- case "ui4":
- $ips_type=1;
- break;
- case "boolean":
- $ips_type=0;
- break;
- case "uuid":
- case "dateTime":
- case "string":
- $ips_type=3;
- break;
- default:
- echo "Unbekannter Datentyp:".$type.PHP_EOL;
- return;
- break;
- }
- }
- $var_id = @IPS_GetObjectIDByIdent($ident,$parent);
- if ($var_id === false)
- {
- $var_id = IPS_CreateVariable($ips_type);
- IPS_SetName($var_id,$ident);
- IPS_SetIdent($var_id,$ident);
- IPS_SetParent($var_id,$parent);
- }
- switch ($ips_type)
- {
- case 0:
- if (GetValueBoolean($var_id) <> (bool)$value)
- {
- SetValueBoolean($var_id,(bool)$value);
- }
- break;
- case 1:
- if (GetValueInteger($var_id) <> (int)$value)
- {
- SetValueInteger($var_id,(int)$value);
- }
- break;
- case 2:
- if (GetValueFloat($var_id) <> round((float)$value,2))
- {
- SetValueFloat($var_id,round((float)$value,2));
- }
- break;
- case 3:
- if (GetValueString($var_id) <> $value)
- {
- SetValueString($var_id,$value);
- }
- break;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement