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 * Loads "Status_NoAuth.asp" page and parses the body.
158 * @return array Associative array with connection status.
160 * @throws Exception When something goes wrong, i.e. router not
163 protected function loadStatus_NoAuth()
165 $strUrlBase = $this->getAnonBaseUrl();
167 $url = $strUrlBase . '/Status_NoAuth.asp';
168 $this->log('Connecting to ' . $url, 1);
170 $r = new HTTP_Request2();
171 $r->setMethod(HTTP_Request2::METHOD_GET);
174 $this->log($resp->getStatus() . ' ' . $resp->getReasonPhrase(), 1);
175 //FIXME: check status
177 $parser = new Wrt3g_HtmlParser();
179 return $parser->status_noauth(
187 * Retrieves pc card/SIM status information
189 * @return array Array with several key-value pairs
190 * connection => connecting, disconnected, connected
192 * @throws Exception When the router can't be reached
194 public function getCardStatus()
196 $arRetval = $this->loadStatus_NoAuth();
198 return array_intersect_key(
202 'card revision' => 0,
203 'card firmware' => 0,
212 * Retrieves all status information one can get.
214 * @return array Array with several key-value pairs
215 * connection => connecting, disconnected, connected
217 * @throws Exception When the router can't be reached
219 public function getFullStatus()
221 return $this->loadStatus_NoAuth();
227 * Log a message to stdout.
229 * @param string $msg Message to display
230 * @param integer $level Log level, see $verbosity
234 public function log($msg, $level = 1)
236 if ($this->verbosity >= $level) {