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',
75 $stCmd = $parser->addCommand(
78 'aliases' => array('s', 'st'),
79 'description' => 'Show the connection status'
82 $stCmd = $parser->addCommand(
85 'aliases' => array('c', 'cs'),
86 'description' => 'Show the card/SIM status'
89 $stCmd = $parser->addCommand(
92 'aliases' => array('a', 'as'),
93 'description' => 'Show all status details'
101 'aliases' => array('r'),
102 'description' => 'Reboot the router'
107 $result = $parser->parse();
108 } catch (Exception $exc) {
109 $parser->displayError($exc->getMessage());
114 $router = new Wrt3g();
115 $router->verbosity = $result->options['verbosity'];
116 $router->host = $result->options['host'];
117 $router->user = $result->options['user'];
118 $router->password = $result->options['password'];
120 $router->log('Command: ' . $result->command_name, 2);
122 switch ($result->command_name) {
124 $resp = $router->reboot();
125 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
126 if (intval($resp->getStatus() / 100) != 2) {
135 if ($result->command_name == 'allstatus') {
136 $arStatus = $router->getFullStatus();
137 } else if ($result->command_name == 'cardstatus') {
138 $arStatus = $router->getCardStatus();
140 $arStatus = $router->getConnectionStatus();
142 foreach ($arStatus as $key => $value) {
143 echo $key . ': ' . $value . "\n";
146 } catch (Exception $e) {
147 echo 'Error: ' . $e->getMessage() . "\n";