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 'action' => 'StoreTrue',
83 $stCmd = $parser->addCommand(
86 'aliases' => array('s', 'st'),
87 'description' => 'Show the connection status'
90 $stCmd = $parser->addCommand(
93 'aliases' => array('c', 'cs'),
94 'description' => 'Show the card/SIM status'
97 $stCmd = $parser->addCommand(
100 'aliases' => array('a', 'as'),
101 'description' => 'Show all status details'
109 'aliases' => array('r'),
110 'description' => 'Reboot the router'
115 $result = $parser->parse();
116 } catch (Exception $exc) {
117 $parser->displayError($exc->getMessage());
122 $router = new Wrt3g();
123 if ($result->options['dummy']) {
124 require_once 'Wrt3g/DummyRequest.php';
125 $router->requestClass = 'Wrt3g_DummyRequest';
126 $router->log('Using dummy data', 1);
129 $router->verbosity = $result->options['verbosity'];
130 $router->host = $result->options['host'];
131 $router->user = $result->options['user'];
132 $router->password = $result->options['password'];
134 $router->log('Command: ' . $result->command_name, 2);
136 switch ($result->command_name) {
138 $resp = $router->reboot();
139 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
140 if (intval($resp->getStatus() / 100) != 2) {
149 if ($result->command_name == 'allstatus') {
150 $arStatus = $router->getFullStatus();
151 } else if ($result->command_name == 'cardstatus') {
152 $arStatus = $router->getCardStatus();
154 $arStatus = $router->getConnectionStatus();
156 foreach ($arStatus as $key => $value) {
158 if (is_array($value)) {
160 echo var_export($value, true) . "\n";
166 } catch (Exception $e) {
167 echo 'Error: ' . $e->getMessage() . "\n";