3 * Control script for Linksys WRT3g routers.
8 * @package linksys-wrt3g-tools
9 * @author Christian Weiske <cweiske@cweiske.de>
11 * @link http://cweiske.de/linksys-wrt3g-tools.htm
13 require_once 'Wrt3g.php';
14 require_once 'Console/CommandLine.php';
16 //default config options
17 $GLOBALS['linksys-wrt3g-tools'] = array(
23 $configFile = dirname(__FILE__) . '/../config.php';
24 if (file_exists($configFile)) {
25 require_once $configFile;
28 $parser = new Console_CommandLine();
29 $parser->description = 'Tool to control Linksys WRT3g routers';
30 $parser->version = '0.0.1';//FIXME: dynamic
35 'long_name' => '--host',
36 'description' => 'IP/Hostname to connect to',
37 'help_name' => 'HOST',
38 'action' => 'StoreString',
39 'default' => $GLOBALS['linksys-wrt3g-tools']['host']
46 'long_name' => '--user',
47 'description' => 'Admin user name',
48 'help_name' => 'USER',
49 'action' => 'StoreString',
50 'default' => $GLOBALS['linksys-wrt3g-tools']['user']
57 'long_name' => '--password',
58 'description' => 'Password for admin user',
59 'help_name' => 'PASS',
60 'action' => 'StoreString',
61 'default' => $GLOBALS['linksys-wrt3g-tools']['password']
68 'description' => 'Show the router status'
74 'description' => 'Reboot the router'
79 $result = $parser->parse();
80 } catch (Exception $exc) {
81 $parser->displayError($exc->getMessage());
86 $router = new Wrt3g();
87 $router->host = $result->options['host'];
88 $router->user = $result->options['user'];
89 $router->password = $result->options['password'];
91 switch ($result->command_name) {
93 $resp = $router->reboot();
94 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
99 $arStatus = $router->getStatus();
100 foreach ($arStatus as $key => $value) {
101 echo $key . ': ' . $value . "\n";
104 } catch (Exception $e) {
105 echo 'Error: ' . $e->getMessage() . "\n";