3 * Functions to access the router
8 * @package linksys-wrt3g-tools
9 * @author Christian Weiske <cweiske@cweiske.de>
11 * @link http://cweiske.de/linksys-wrt3g-tools.htm
13 require_once 'HTTP/Request2.php';
18 protected static $arTranslations = array(
19 'GPRS_MSG.WWBEAR' => 'type',
20 'GPRS_MSG.NNAME' => 'network',
21 'GPRS_MSG.STRENGTH' => 'signal strength',
22 'GPRS_MSG.ACQUIRING' => 'aquiring',
23 'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
24 'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
30 * @return HTTP_Request2_Response
32 * @throws Exception When the router can't be reached, or unauthorized
36 $r = new HTTP_Request2();
37 $r->setMethod(HTTP_Request2::METHOD_POST);
40 . $GLOBALS['linksys-wrt3g-tools']['user']
41 . ':' . $GLOBALS['linksys-wrt3g-tools']['password']
42 . '@' . $GLOBALS['linksys-wrt3g-tools']['ip']
45 $r->addPostParameter('action', 'Reboot');
46 $r->addPostParameter('submit_button', 'Diagnostics');
47 $r->addPostParameter('wait_time', 1);
56 * Retrieves status information about the router
58 * @return array Array with several key-value pairs
59 * connection => connecting, disconnected, connected
61 * @throws Exception When the router can't be reached, or unauthorized
67 $strUrlBase = 'http://'
68 . $GLOBALS['linksys-wrt3g-tools']['user']
69 . ':' . $GLOBALS['linksys-wrt3g-tools']['password']
70 . '@' . $GLOBALS['linksys-wrt3g-tools']['ip'];
75 $r = new HTTP_Request2();
76 $r->setMethod(HTTP_Request2::METHOD_GET);
77 $r->setUrl($strUrlBase . '/index_wstatus2.asp');
79 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
80 $body = $resp->getBody();
81 preg_match('/var status2 = "(.+)"/', $body, $arMatches);
83 $strStatus = $arMatches[1];
87 $arRetval['connection'] = strtolower($strStatus);
92 $r->setUrl($strUrlBase . '/index_wstatus1.asp');
94 $body = $resp->getBody();
95 $arRetval = array_merge($arRetval, $this->parseStatus($body));
98 }//function getStatus()
103 * Parses the body and returns extracted values
105 * @param string $body HTML document to parse
107 * @return array Array of key-value pairs
109 function parseStatus($body)
112 $arMatches = array();
113 preg_match_all('#>Capture\(([^)]+)\)</#', $body, $arMatches);
115 reset($arMatches[1]);
116 while (current($arMatches[1])) {
117 $key = current($arMatches[1]);
118 $value = next($arMatches[1]);
119 if (isset(self::$arTranslations[$key])) {
120 $key = self::$arTranslations[$key];
122 if (isset(self::$arTranslations[$value])) {
123 $value = self::$arTranslations[$value];
125 $arRetval[$key] = $value;