git.cweiske.de
/
linksys-wrt3g-tools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make the request observer work correctly, remove response logging in main class
[linksys-wrt3g-tools.git]
/
Wrt3g
/
HtmlParser.php
diff --git
a/Wrt3g/HtmlParser.php
b/Wrt3g/HtmlParser.php
index c40f117a9d77eedd3a94677100d54d2b0cccae9f..bd613acbcc7f6b467631a8647a9e479f1924f425 100644
(file)
--- a/
Wrt3g/HtmlParser.php
+++ b/
Wrt3g/HtmlParser.php
@@
-19,8
+19,11
@@
class Wrt3g_HtmlParser
'GPRS_MSG.ACQUIRING' => 'aquiring',
'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
'GPRS_MSG.ACQUIRING' => 'aquiring',
'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
+ 'GPRS_MSG.None' => null,
+ 'GPRS_MSG.FAIR' => 'fair',
'GPRS_MSG.GOOD' => 'good',
'GPRS_MSG.EXCELLENT' => 'excellent',
'GPRS_MSG.GOOD' => 'good',
'GPRS_MSG.EXCELLENT' => 'excellent',
+ 'GPRS_MSG.NOSIGNAL' => 'no signal',
'GPRS_MSG.CTIME' => 'connection time',
'GPRS_MSG.CFW' => 'card firmware',
'GPRS_MSG.CMOD' => 'card model',
'GPRS_MSG.CTIME' => 'connection time',
'GPRS_MSG.CFW' => 'card firmware',
'GPRS_MSG.CMOD' => 'card model',
@@
-33,11
+36,14
@@
class Wrt3g_HtmlParser
/**
* Parses the body of /index_wstatus1.asp and returns extracted values.
/**
* Parses the body of /index_wstatus1.asp and returns extracted values.
+ * If no connection is established, the values are NULL.
*
* @param string $body HTML document to parse
*
*
* @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" - i.e. "GPRS"
+ * - "network" - Carrier network name, i.e. "BASE DE"
+ * - "signal strength" - good, excellent, poor
*/
public function index_wstatus1($body)
{
*/
public function index_wstatus1($body)
{
@@
-80,6
+86,9
@@
class Wrt3g_HtmlParser
if (isset(self::$arTranslations[$value])) {
$value = self::$arTranslations[$value];
}
if (isset(self::$arTranslations[$value])) {
$value = self::$arTranslations[$value];
}
+ if ($value == 'aquiring') {
+ $value = null;
+ }
$arRetval[$key] = $value;
next($arMatches);
}
$arRetval[$key] = $value;
next($arMatches);
}
@@
-100,6
+109,9
@@
class Wrt3g_HtmlParser
public function index_wstatus2($body)
{
preg_match('/var status2 = "(.+)"/', $body, $arMatches);
public function index_wstatus2($body)
{
preg_match('/var status2 = "(.+)"/', $body, $arMatches);
+ if (!isset($arMatches[1])) {
+ return array();
+ }
$strStatus = $arMatches[1];
//Connecting
$strStatus = $arMatches[1];
//Connecting
@@
-116,7
+128,16
@@
class Wrt3g_HtmlParser
*
* @param string $body HTML document to parse
*
*
* @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
*/
public function status_noauth($body)
{
*/
public function status_noauth($body)
{
@@
-130,7
+151,8
@@
class Wrt3g_HtmlParser
$doc->loadHtml($body);
$xpath = new DOMXPath($doc);
$trs = $xpath->query('//table//table/tbody/tr');
$doc->loadHtml($body);
$xpath = new DOMXPath($doc);
$trs = $xpath->query('//table//table/tbody/tr');
- $arRaw = array();
+ $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);
foreach ($trs as $tr) {
$titleItems = $xpath->query('td[@width=125]/text()', $tr);
$valueItems = $xpath->query('td[@width=296]/*[1]', $tr);
@@
-145,10
+167,22
@@
class Wrt3g_HtmlParser
$value = trim(strip_tags($value));
if (substr($value, 0, 8) == 'Capture(') {
$value = self::$arTranslations[substr($value, 8, -1)];
$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);
}
}
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(
if (isset($arRaw['connection time'])) {
$arRaw['connection time'] = str_replace(
array(
@@
-168,10
+202,16
@@
class Wrt3g_HtmlParser
'TX = ',
str_replace('RX = ', '', $arRaw['session usage'])
);
'TX = ',
str_replace('RX = ', '', $arRaw['session usage'])
);
- $arRaw['session usage'] = array(
- 'received' => $arS[0],
- 'sent' => $arS[1]
- );
+ 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;
}
return $arRaw;