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
32 Dummy responses can be controlled with the host parameter:
33 A 3-letter numeric host is interpreted as HTTP response code";
34 $parser->version = '0.0.1';//FIXME: dynamic
39 'long_name' => '--host',
40 'description' => 'IP/Hostname to connect to',
41 'help_name' => 'HOST',
42 'action' => 'StoreString',
43 'default' => $GLOBALS['linksys-wrt3g-tools']['host']
50 'long_name' => '--user',
51 'description' => 'Admin user name',
52 'help_name' => 'USER',
53 'action' => 'StoreString',
54 'default' => $GLOBALS['linksys-wrt3g-tools']['user']
61 'long_name' => '--password',
62 'description' => 'Password for admin user',
63 'help_name' => 'PASS',
64 'action' => 'StoreString',
65 'default' => $GLOBALS['linksys-wrt3g-tools']['password']
72 'long_name' => '--verbose',
73 'description' => 'Show more details (more to see more details)',
74 'action' => 'Counter',
80 'long_name' => '--dummy',
81 'description' => 'Use dummy router data, not real ones',
82 'action' => 'StoreTrue',
86 $stCmd = $parser->addCommand(
89 'aliases' => array('s', 'st'),
90 'description' => 'Show the connection status'
93 $stCmd = $parser->addCommand(
96 'aliases' => array('c', 'cs'),
97 'description' => 'Show the card/SIM status'
100 $stCmd = $parser->addCommand(
103 'aliases' => array('a', 'as'),
104 'description' => 'Show all status details'
112 'aliases' => array('r'),
113 'description' => 'Reboot the router'
118 $result = $parser->parse();
119 } catch (Exception $exc) {
120 $parser->displayError($exc->getMessage());
125 $router = new Wrt3g();
126 $router->verbosity = $result->options['verbosity'];
127 $router->host = $result->options['host'];
128 $router->user = $result->options['user'];
129 $router->password = $result->options['password'];
131 if ($result->options['dummy']) {
132 require_once 'Wrt3g/DummyRequest.php';
133 $router->requestClass = 'Wrt3g_DummyRequest';
134 $router->log('Using dummy data', 1);
137 $router->log('Command: ' . $result->command_name, 2);
139 switch ($result->command_name) {
141 $resp = $router->reboot();
142 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
143 if (intval($resp->getStatus() / 100) != 2) {
152 if ($result->command_name == 'allstatus') {
153 $arStatus = $router->getFullStatus();
154 } else if ($result->command_name == 'cardstatus') {
155 $arStatus = $router->getCardStatus();
157 $arStatus = $router->getConnectionStatus();
159 foreach ($arStatus as $key => $value) {
161 if (is_array($value)) {
163 echo var_export($value, true) . "\n";
169 } catch (Exception $e) {
170 echo 'Error: ' . $e->getMessage() . "\n";