root / plugins / router / avm-fritzbox-wan-traffic @ 74c7fc3d
Historique | Voir | Annoter | Télécharger (5,28 ko)
| 1 | 53cf606e | Andreas Kreisl | #!/usr/bin/php |
|---|---|---|---|
| 2 | <?php |
||
| 3 | ############################## |
||
| 4 | # |
||
| 5 | # Plugin: AVM Fritz!Box WAN traffic (over UPNP) |
||
| 6 | # |
||
| 7 | # Author: Andreas Kreisl |
||
| 8 | # |
||
| 9 | 17f78427 | Lars Kruse | # Licence: Creative Commons - Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) |
| 10 | 53cf606e | Andreas Kreisl | # http://creativecommons.org/licenses/by-sa/3.0/ |
| 11 | # |
||
| 12 | ############################## |
||
| 13 | #%# family=auto |
||
| 14 | #%# capabilities=autoconf |
||
| 15 | |||
| 16 | $host = "fritz.box"; |
||
| 17 | |||
| 18 | if(isset($argv[1]) && $argv[1] == "autoconf") {
|
||
| 19 | echo "yes\n"; |
||
| 20 | } else if(isset($argv[1]) && $argv[1] == "config") {
|
||
| 21 | $data_prop = GetCommonLinkProperties(); |
||
| 22 | //$data_ip = GetExternalIP(); // $data_ip['NewExternalIPAddress'] |
||
| 23 | echo "graph_order down up maxdown maxup\n"; |
||
| 24 | echo "graph_title AVM Fritz!Box WAN traffic\n"; |
||
| 25 | echo "graph_args --base 1024\n"; |
||
| 26 | echo "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
|
||
| 27 | echo "graph_category network\n"; |
||
| 28 | echo "graph_info This graph shows the traffic of the AVM Fritz!Box WAN network interface. Please note that the traffic is shown in bits per second, not bytes.\n"; |
||
| 29 | echo "down.label received\n"; |
||
| 30 | f5857c2b | Andreas Kreisl | echo "down.type DERIVE\n"; |
| 31 | 53cf606e | Andreas Kreisl | echo "down.graph no\n"; |
| 32 | echo "down.cdef down,8,*\n"; |
||
| 33 | f5857c2b | Andreas Kreisl | echo "down.min 0\n"; |
| 34 | 53cf606e | Andreas Kreisl | echo "down.max 1000000000\n"; |
| 35 | echo "up.label " . $data_prop['NewWANAccessType'] . " (" . $data_prop['NewPhysicalLinkStatus'] . ")\n";
|
||
| 36 | f5857c2b | Andreas Kreisl | echo "up.type DERIVE\n"; |
| 37 | 53cf606e | Andreas Kreisl | echo "up.negative down\n"; |
| 38 | echo "up.draw AREA\n"; |
||
| 39 | echo "up.cdef up,8,*\n"; |
||
| 40 | f5857c2b | Andreas Kreisl | echo "up.min 0\n"; |
| 41 | 53cf606e | Andreas Kreisl | echo "up.max 1000000000\n"; |
| 42 | echo "up.info Traffic of the WAN interface.\n"; |
||
| 43 | echo "maxdown.label received\n"; |
||
| 44 | echo "maxdown.type GAUGE\n"; |
||
| 45 | echo "maxdown.graph no\n"; |
||
| 46 | echo "maxup.label MAX\n"; |
||
| 47 | echo "maxup.type GAUGE\n"; |
||
| 48 | echo "maxup.negative maxdown\n"; |
||
| 49 | echo "maxup.draw LINE1\n"; |
||
| 50 | echo "maxup.info Maximum speed of the WAN interface.\n"; |
||
| 51 | } else {
|
||
| 52 | $data_prop = GetCommonLinkProperties(); |
||
| 53 | $data_stats = GetAddonInfos(); |
||
| 54 | echo "up.value " . $data_stats['NewTotalBytesSent'] . "\n"; |
||
| 55 | echo "down.value " . $data_stats['NewTotalBytesReceived'] . "\n"; |
||
| 56 | echo "maxup.value " . $data_prop['NewLayer1UpstreamMaxBitRate'] . "\n"; |
||
| 57 | echo "maxdown.value " . $data_prop['NewLayer1DownstreamMaxBitRate'] . "\n"; |
||
| 58 | } |
||
| 59 | |||
| 60 | |||
| 61 | function GetCommonLinkProperties() {
|
||
| 62 | d0b57b8f | Raphael Freudiger | $data_url = '/igdupnp/control/WANCommonIFC1'; |
| 63 | 53cf606e | Andreas Kreisl | $data_soap = '"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetCommonLinkProperties"'; |
| 64 | $data_xml = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetCommonLinkProperties xmlns:u=urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 /></s:Body></s:Envelope>'; |
||
| 65 | $tmp = DoCurl($data_url,$data_soap,$data_xml); |
||
| 66 | $data_result = Array(); |
||
| 67 | $data_result['NewLayer1UpstreamMaxBitRate'] = FindKey($tmp,"NewLayer1UpstreamMaxBitRate"); |
||
| 68 | $data_result['NewLayer1DownstreamMaxBitRate'] = FindKey($tmp,"NewLayer1DownstreamMaxBitRate"); |
||
| 69 | $data_result['NewWANAccessType'] = FindKey($tmp,"NewWANAccessType"); |
||
| 70 | $data_result['NewPhysicalLinkStatus'] = FindKey($tmp,"NewPhysicalLinkStatus"); |
||
| 71 | return $data_result; |
||
| 72 | } |
||
| 73 | |||
| 74 | function GetAddonInfos() {
|
||
| 75 | d0b57b8f | Raphael Freudiger | $data_url = '/igdupnp/control/WANCommonIFC1'; |
| 76 | 53cf606e | Andreas Kreisl | $data_soap = '"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1#GetAddonInfos"'; |
| 77 | $data_xml = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetAddonInfos xmlns:u=urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 /></s:Body></s:Envelope>'; |
||
| 78 | $tmp = DoCurl($data_url,$data_soap,$data_xml); |
||
| 79 | $data_result = Array(); |
||
| 80 | $data_result['NewTotalBytesSent'] = FindKey($tmp,"NewTotalBytesSent"); |
||
| 81 | $data_result['NewTotalBytesReceived'] = FindKey($tmp,"NewTotalBytesReceived"); |
||
| 82 | return $data_result; |
||
| 83 | } |
||
| 84 | |||
| 85 | function GetExternalIP() {
|
||
| 86 | d0b57b8f | Raphael Freudiger | $data_url = '/igdupnp/control/WANIPConn1'; |
| 87 | 53cf606e | Andreas Kreisl | $data_soap = '"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"'; |
| 88 | $data_xml = '<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalIPAddress xmlns:u=urn:schemas-upnp-org:service:WANIPConnection:1 /></s:Body></s:Envelope>'; |
||
| 89 | $tmp = DoCurl($data_url,$data_soap,$data_xml); |
||
| 90 | $data_result = Array(); |
||
| 91 | $data_result['NewExternalIPAddress'] = FindKey($tmp,"NewExternalIPAddress"); |
||
| 92 | return $data_result; |
||
| 93 | } |
||
| 94 | |||
| 95 | function DoCurl($url,$soap,$xml) {
|
||
| 96 | $ch = curl_init("http://" . $GLOBALS["host"] . ":49000" . $url);
|
||
| 97 | |||
| 98 | $headers = array(); |
||
| 99 | fba800ae | Veres Lajos | //$headers[] = 'POST ' . $url . ' HTTP/1.1'; // Will be automatically set. |
| 100 | 53cf606e | Andreas Kreisl | $headers[] = 'Content-Type: text/xml; charset="utf-8"'; |
| 101 | $headers[] = 'HOST: ' . $GLOBALS["host"] . ':49000'; |
||
| 102 | $headers[] = 'Content-Length: ' . strlen($xml); |
||
| 103 | $headers[] = 'SOAPACTION: ' . $soap; |
||
| 104 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
||
| 105 | |||
| 106 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
||
| 107 | curl_setopt($ch, CURLOPT_HEADER, 0); |
||
| 108 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 109 | curl_setopt($ch, CURLOPT_IPRESOLVE, 1); // Force IPv4 |
||
| 110 | |||
| 111 | curl_setopt($ch, CURLOPT_POST, 1); |
||
| 112 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); // Add XML in POST-Header |
||
| 113 | |||
| 114 | $tmp = curl_exec($ch); |
||
| 115 | curl_close($ch); |
||
| 116 | return $tmp; |
||
| 117 | } |
||
| 118 | |||
| 119 | function FindKey($text,$key) {
|
||
| 120 | $p1 = strpos($text,$key); |
||
| 121 | if($p1 === false) {
|
||
| 122 | $tmp = ""; |
||
| 123 | } else {
|
||
| 124 | $p1 = strpos($text,'>',$p1) +1; |
||
| 125 | $p2 = strpos($text,'<',$p1); |
||
| 126 | if($p2 === false) {
|
||
| 127 | $tmp = ""; |
||
| 128 | } else {
|
||
| 129 | $tmp = substr($text,$p1,$p2-$p1); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | return $tmp; |
||
| 133 | } |
||
| 134 | |||
| 135 | ?> |
