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';
26 * Name of user with administration privileges
39 protected static $arTranslations = array(
40 'GPRS_MSG.WWBEAR' => 'type',
41 'GPRS_MSG.NNAME' => 'network',
42 'GPRS_MSG.STRENGTH' => 'signal strength',
43 'GPRS_MSG.ACQUIRING' => 'aquiring',
44 'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
45 'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
51 * @return HTTP_Request2_Response
53 * @throws Exception When the router can't be reached, or unauthorized
57 $r = new HTTP_Request2();
58 $r->setMethod(HTTP_Request2::METHOD_POST);
62 . ':' . $this->password
66 $r->addPostParameter('action', 'Reboot');
67 $r->addPostParameter('submit_button', 'Diagnostics');
68 $r->addPostParameter('wait_time', 1);
77 * Retrieves status information about the router
79 * @return array Array with several key-value pairs
80 * connection => connecting, disconnected, connected
82 * @throws Exception When the router can't be reached, or unauthorized
88 $strUrlBase = 'http://'
90 . ':' . $this->password
96 $r = new HTTP_Request2();
97 $r->setMethod(HTTP_Request2::METHOD_GET);
98 $r->setUrl($strUrlBase . '/index_wstatus2.asp');
100 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
101 $body = $resp->getBody();
102 preg_match('/var status2 = "(.+)"/', $body, $arMatches);
104 $strStatus = $arMatches[1];
108 $arRetval['connection'] = strtolower($strStatus);
113 $r->setUrl($strUrlBase . '/index_wstatus1.asp');
115 $body = $resp->getBody();
116 $arRetval = array_merge($arRetval, $this->parseStatus($body));
119 }//function getStatus()
124 * Parses the body and returns extracted values
126 * @param string $body HTML document to parse
128 * @return array Array of key-value pairs
130 function parseStatus($body)
133 $arMatches = array();
134 preg_match_all('#>Capture\(([^)]+)\)</#', $body, $arMatches);
136 reset($arMatches[1]);
137 while (current($arMatches[1])) {
138 $key = current($arMatches[1]);
139 $value = next($arMatches[1]);
140 if (isset(self::$arTranslations[$key])) {
141 $key = self::$arTranslations[$key];
143 if (isset(self::$arTranslations[$value])) {
144 $value = self::$arTranslations[$value];
146 $arRetval[$key] = $value;