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
52 * Returns the base URL to use for requests that require authentification.
53 * Includes username, password and host.
55 * @return string URL without trailing slash after the host
57 protected function getAuthBaseUrl()
61 . ':' . $this->password
68 * Returns the base URL to use for requests that do
69 * not require authentification.
71 * @return string URL without trailing slash after the host
73 protected function getAnonBaseUrl()
75 return 'http://' . $this->host;
83 * @return HTTP_Request2_Response
85 * @throws Exception When the router can't be reached, or unauthorized
87 public function reboot()
89 $r = new HTTP_Request2();
90 $r->setMethod(HTTP_Request2::METHOD_POST);
92 $this->getAuthBaseUrl() . '/apply.cgi'
94 $r->addPostParameter('action', 'Reboot');
95 $r->addPostParameter('submit_button', 'Diagnostics');
96 $r->addPostParameter('wait_time', 1);
100 }//public function reboot()
105 * Retrieves status information about the router
107 * @return array Array with several key-value pairs
108 * connection => connecting, disconnected, connected
110 * @throws Exception When the router can't be reached, or unauthorized
112 public function getStatus()
116 $strUrlBase = $this->getAuthBaseUrl();
117 $parser = new Wrt3g_HtmlParser();
122 $r = new HTTP_Request2();
123 $r->setMethod(HTTP_Request2::METHOD_GET);
124 $r->setUrl($strUrlBase . '/index_wstatus2.asp');
126 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
127 $arRetval = $parser->index_wstatus2($resp->getBody());
132 $r->setUrl($strUrlBase . '/index_wstatus1.asp');
134 $body = $resp->getBody();
135 $arRetval = array_merge($arRetval, $parser->index_wstatus1($body));
138 }//public function getStatus()