X-Git-Url: https://git.cweiske.de/linksys-wrt3g-tools.git/blobdiff_plain/3affd264002c60d087a4f8be3ae82e3e4ba0889f..3ace4fe2fcad71500e49dd5b42222a92617b8f43:/Wrt3g/HtmlParser.php diff --git a/Wrt3g/HtmlParser.php b/Wrt3g/HtmlParser.php index fe81c58..90808c3 100644 --- a/Wrt3g/HtmlParser.php +++ b/Wrt3g/HtmlParser.php @@ -21,6 +21,12 @@ class Wrt3g_HtmlParser 'GPRS_MSG.WWBEAR_UMTS' => 'UMTS', 'GPRS_MSG.GOOD' => 'good', 'GPRS_MSG.EXCELLENT' => 'excellent', + 'GPRS_MSG.CTIME' => 'connection time', + 'GPRS_MSG.CFW' => 'card firmware', + 'GPRS_MSG.CMOD' => 'card model', + 'GPRS_MSG.CREV' => 'card revision', + 'GPRS_MSG.IMSI' => 'IMSI', + 'GPRS_MSG.SESSIONUSAGE' => 'session usage', ); @@ -30,8 +36,10 @@ class Wrt3g_HtmlParser * * @param string $body HTML document to parse * - * @return array Array of key-value pairs, probably with "type", "network" and - * "signal strength" + * @return array Array of key-value pairs, probably with + * - "type" + * - "network" + * - "signal strength" */ public function index_wstatus1($body) { @@ -110,9 +118,75 @@ class Wrt3g_HtmlParser * * @param string $body HTML document to parse * - * @return array FIXME + * @return array Array of key-value pairs with the following keys: + * - type + * - network + * - signal strength + * - connection time + * - session usage (array) + * - card model + * - card revision + * - card firmware + * - IMSI + * + * @todo FIXME implement "connection" value as index_wstatus2() does it */ public function status_noauth($body) { + $body = str_replace( + array(' ', '', ''), + '', $body + ); + + $doc = new DomDocument(); + libxml_use_internal_errors(true);//html is broken + $doc->loadHtml($body); + $xpath = new DOMXPath($doc); + $trs = $xpath->query('//table//table/tbody/tr'); + $arRaw = array(); + foreach ($trs as $tr) { + $titleItems = $xpath->query('td[@width=125]/text()', $tr); + $valueItems = $xpath->query('td[@width=296]/*[1]', $tr); + if ($titleItems->length && $valueItems->length) { + $title = substr($doc->saveXML($titleItems->item(0)), 8, -2); + $value = $doc->saveXML($valueItems->item(0)); + $arRaw[self::$arTranslations[$title]] = $value; + } + } + + foreach ($arRaw as $key => &$value) { + $value = trim(strip_tags($value)); + if (substr($value, 0, 8) == 'Capture(') { + $value = self::$arTranslations[substr($value, 8, -1)]; + } + } + unset($value); + + if (isset($arRaw['connection time'])) { + $arRaw['connection time'] = str_replace( + array( + ' Capture(GPRS_MSG.HOURS)', + ' Capture(GPRS_MSG.MINUTE)', + ' Capture(GPRS_MSG.SECOND)', + ), + array( + 'h', 'm', 's' + ), + $arRaw['connection time'] + ); + } + + if (isset($arRaw['session usage'])) { + $arS = explode( + 'TX = ', + str_replace('RX = ', '', $arRaw['session usage']) + ); + $arRaw['session usage'] = array( + 'received' => $arS[0], + 'sent' => $arS[1] + ); + } + + return $arRaw; } } \ No newline at end of file