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 $parser = new Console_CommandLine();
18 $parser->description = "Tool to control Linksys WRT3g routers";
19 $parser->version = '0.0.1';//FIXME: dynamic
24 'long_name' => '--host',
25 'description' => 'IP/Hostname to connect to',
26 'help_name' => 'HOST',
27 'action' => 'StoreString',
35 'long_name' => '--user',
36 'description' => 'Admin user name',
37 'help_name' => 'USER',
38 'action' => 'StoreString',
46 'long_name' => '--password',
47 'description' => 'Password for admin user',
48 'help_name' => 'PASS',
49 'action' => 'StoreString',
57 'long_name' => '--verbose',
58 'description' => 'Show more details (more to see more details)',
59 'action' => 'Counter',
65 'long_name' => '--dummy',
66 'description' => "Use dummy router data, not real ones.
67 Dummy responses can be controlled with the host parameter; 3-letter numeric hosts are interpreted as HTTP response code",
68 'action' => 'StoreTrue',
72 $stCmd = $parser->addCommand(
75 'aliases' => array('s', 'st'),
76 'description' => 'Show the connection status'
79 $stCmd = $parser->addCommand(
82 'aliases' => array('c'),
83 'description' => 'Show the PC card/SIM status'
86 $stCmd = $parser->addCommand(
89 'aliases' => array('a'),
90 'description' => 'Show all status details'
93 $stCmd = $parser->addCommand(
96 'description' => 'Show the connection status the old way (authenticated)'
104 'aliases' => array('r'),
105 'description' => 'Reboot the router'
108 $stCmd = $parser->addCommand(
111 'description' => 'Saves the router configuration into the config file'
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->loadConfig($result->options);
127 if ($result->options['dummy']) {
128 require_once 'Wrt3g/DummyRequest.php';
129 $router->requestClass = 'Wrt3g_DummyRequest';
130 $router->log('Using dummy data', 1);
133 $router->log('Command: ' . $result->command_name, 2);
135 switch ($result->command_name) {
137 $resp = $router->reboot();
138 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
139 if (intval($resp->getStatus() / 100) != 2) {
145 $router->config->save($router->config->getConfigFilePath());
152 if ($result->command_name == 'all') {
153 $arStatus = $router->getFullStatus();
154 } else if ($result->command_name == 'card') {
155 $arStatus = $router->getCardStatus();
156 } else if ($result->command_name == 'authstatus') {
157 $arStatus = $router->getConnectionStatusAuth();
159 $arStatus = $router->getConnectionStatus();
162 foreach ($arStatus as $key => $value) {
164 if (is_array($value)) {
166 echo var_export($value, true) . "\n";
172 } catch (Exception $e) {
173 echo 'Error: ' . $e->getMessage() . "\n";