+
+
+
+ /**
+ * Parses the HTML body of /Status_NoAuth.asp and returns the extracted
+ * values.
+ *
+ * @param string $body HTML document to parse
+ *
+ * @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
+ */
+ public function status_noauth($body)
+ {
+ $body = str_replace(
+ array(' ', '</font>', '<script>', '</script>'),
+ '', $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('connection' => null);
+ $bAquiring = false;
+ 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)];
+ if ($value == 'aquiring') {
+ $bAquiring = true;
+ $value = null;
+ }
+ }
+ }
+ unset($value);
+
+ if ($bAquiring) {
+ $arRaw['connection'] = 'connecting';
+ } else if ($arRaw['type'] != null) {
+ $arRaw['connection'] = 'connected';
+ } else {
+ $arRaw['connection'] = 'disconnected';
+ }
+
+ 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'])
+ );
+ if (count($arS) > 1) {
+ $arRaw['session usage'] = array(
+ 'received' => $arS[0],
+ 'sent' => $arS[1]
+ );
+ }
+ }
+
+ if (preg_match('/Capture\\(share.firmwarever\\):(.+?)</', $body, $arMatches)) {
+ $arRaw['router firmware'] = trim($arMatches[1]);
+ }
+
+ return $arRaw;
+ }