4 * Control script for Linksys WRT3g routers.
9 * @package linksys-wrt3g-tools
10 * @author Christian Weiske <cweiske@cweiske.de>
12 * @link http://cweiske.de/linksys-wrt3g-tools.htm
14 require_once 'Wrt3g.php';
15 require_once 'Console/CommandLine.php';
17 //default config options
18 $GLOBALS['linksys-wrt3g-tools'] = array(
24 $configFile = dirname(__FILE__) . '/../config.php';
25 if (file_exists($configFile)) {
26 require_once $configFile;
29 $parser = new Console_CommandLine();
30 $parser->description = "Tool to control Linksys WRT3g routers";
31 $parser->version = '0.0.1';//FIXME: dynamic
36 'long_name' => '--host',
37 'description' => 'IP/Hostname to connect to',
38 'help_name' => 'HOST',
39 'action' => 'StoreString',
40 'default' => $GLOBALS['linksys-wrt3g-tools']['host']
47 'long_name' => '--user',
48 'description' => 'Admin user name',
49 'help_name' => 'USER',
50 'action' => 'StoreString',
51 'default' => $GLOBALS['linksys-wrt3g-tools']['user']
58 'long_name' => '--password',
59 'description' => 'Password for admin user',
60 'help_name' => 'PASS',
61 'action' => 'StoreString',
62 'default' => $GLOBALS['linksys-wrt3g-tools']['password']
69 'long_name' => '--verbose',
70 'description' => 'Show more details (more to see more details)',
71 'action' => 'Counter',
77 'long_name' => '--dummy',
78 'description' => "Use dummy router data, not real ones.
79 Dummy responses can be controlled with the host parameter; 3-letter numeric hosts are interpreted as HTTP response code",
80 'action' => 'StoreTrue',
84 $stCmd = $parser->addCommand(
87 'aliases' => array('s', 'st'),
88 'description' => 'Show the connection status'
91 $stCmd = $parser->addCommand(
94 'aliases' => array('c'),
95 'description' => 'Show the PC card/SIM status'
98 $stCmd = $parser->addCommand(
101 'aliases' => array('a'),
102 'description' => 'Show all status details'
110 'aliases' => array('r'),
111 'description' => 'Reboot the router'
116 $result = $parser->parse();
117 } catch (Exception $exc) {
118 $parser->displayError($exc->getMessage());
123 $router = new Wrt3g();
124 $router->verbosity = $result->options['verbosity'];
125 $router->host = $result->options['host'];
126 $router->user = $result->options['user'];
127 $router->password = $result->options['password'];
129 if ($result->options['dummy']) {
130 require_once 'Wrt3g/DummyRequest.php';
131 $router->requestClass = 'Wrt3g_DummyRequest';
132 $router->log('Using dummy data', 1);
135 $router->log('Command: ' . $result->command_name, 2);
137 switch ($result->command_name) {
139 $resp = $router->reboot();
140 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
141 if (intval($resp->getStatus() / 100) != 2) {
150 if ($result->command_name == 'all') {
151 $arStatus = $router->getFullStatus();
152 } else if ($result->command_name == 'card') {
153 $arStatus = $router->getCardStatus();
155 $arStatus = $router->getConnectionStatus();
157 foreach ($arStatus as $key => $value) {
159 if (is_array($value)) {
161 echo var_export($value, true) . "\n";
167 } catch (Exception $e) {
168 echo 'Error: ' . $e->getMessage() . "\n";