3 * Part of Linksys WRT3G tools
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';
14 require_once 'Wrt3g/HtmlParser.php';
18 * Main class to interact with the router.
21 * @package linksys-wrt3g-tools
22 * @author Christian Weiske <cweiske@cweiske.de>
24 * @link http://cweiske.de/linksys-wrt3g-tools.htm
36 * Name of user with administration privileges
51 * 0 - no debug logging
52 * 1 - show important details (connected URLs)
53 * 2 - show internal details
57 public $verbosity = 0;
62 * Returns the base URL to use for requests that require authentification.
63 * Includes username, password and host.
65 * @return string URL without trailing slash after the host
67 protected function getAuthBaseUrl()
71 . ':' . $this->password
78 * Returns the base URL to use for requests that do
79 * not require authentification.
81 * @return string URL without trailing slash after the host
83 protected function getAnonBaseUrl()
85 return 'http://' . $this->host;
93 * @return HTTP_Request2_Response
95 * @throws Exception When the router can't be reached, or unauthorized
97 public function reboot()
99 $url = $this->getAuthBaseUrl() . '/apply.cgi';
100 $this->log('Connecting to ' . $url);
102 $r = new HTTP_Request2();
103 $r->setMethod(HTTP_Request2::METHOD_POST);
105 $r->addPostParameter('action', 'Reboot');
106 $r->addPostParameter('submit_button', 'Diagnostics');
107 $r->addPostParameter('wait_time', 1);
111 }//public function reboot()
116 * Retrieves status information about the router
118 * @return array Array with several key-value pairs
119 * connection => connecting, disconnected, connected
121 * @throws Exception When the router can't be reached, or unauthorized
123 public function getConnectionStatus()
127 $strUrlBase = $this->getAuthBaseUrl();
128 $parser = new Wrt3g_HtmlParser();
133 $r = new HTTP_Request2();
134 $r->setMethod(HTTP_Request2::METHOD_GET);
135 $r->setUrl($strUrlBase . '/index_wstatus2.asp');
136 $this->log('Connecting to ' . $strUrlBase . '/index_wstatus2.asp', 1);
138 $this->log($resp->getStatus() . ' ' . $resp->getReasonPhrase(), 1);
139 $arRetval = $parser->index_wstatus2($resp->getBody());
144 $r->setUrl($strUrlBase . '/index_wstatus1.asp');
145 $this->log('Connecting to ' . $strUrlBase . '/index_wstatus1.asp', 1);
147 $body = $resp->getBody();
148 $arRetval = array_merge($arRetval, $parser->index_wstatus1($body));
151 }//public function getConnectionStatus()
156 * Retrieves pc card/SIM status information
158 * @return array Array with several key-value pairs
159 * connection => connecting, disconnected, connected
161 * @throws Exception When the router can't be reached
163 public function getCardStatus()
167 $strUrlBase = $this->getAnonBaseUrl();
169 $url = $strUrlBase . '/Status_NoAuth.asp';
170 $this->log('Connecting to ' . $url, 1);
172 $r = new HTTP_Request2();
173 $r->setMethod(HTTP_Request2::METHOD_GET);
176 $this->log($resp->getStatus() . ' ' . $resp->getReasonPhrase(), 1);
177 //FIXME: check status
179 $parser = new Wrt3g_HtmlParser();
180 $arRetval = $parser->status_noauth($resp->getBody());
182 return array_intersect_key(
186 'card revision' => 0,
187 'card firmware' => 0,
196 * Retrieves all status information one can get.
198 * @return array Array with several key-value pairs
199 * connection => connecting, disconnected, connected
201 * @throws Exception When the router can't be reached
203 public function getFullStatus()
207 $strUrlBase = $this->getAnonBaseUrl();
209 $url = $strUrlBase . '/Status_NoAuth.asp';
210 $this->log('Connecting to ' . $url, 1);
212 $r = new HTTP_Request2();
213 $r->setMethod(HTTP_Request2::METHOD_GET);
216 $this->log($resp->getStatus() . ' ' . $resp->getReasonPhrase(), 1);
217 //FIXME: check status
219 $parser = new Wrt3g_HtmlParser();
220 return $parser->status_noauth($resp->getBody());
226 * Log a message to stdout.
228 * @param string $msg Message to display
229 * @param integer $level Log level, see $verbosity
233 public function log($msg, $level = 1)
235 if ($this->verbosity >= $level) {