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 'description' => 'Show the router status'
75 'description' => 'Reboot the router'
80 $result = $parser->parse();
81 } catch (Exception $exc) {
82 $parser->displayError($exc->getMessage());
87 $router = new Wrt3g();
88 $router->host = $result->options['host'];
89 $router->user = $result->options['user'];
90 $router->password = $result->options['password'];
92 switch ($result->command_name) {
94 $resp = $router->reboot();
95 echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
96 if (intval($resp->getStatus() / 100) != 2) {
103 $arStatus = $router->getStatus();
104 foreach ($arStatus as $key => $value) {
105 echo $key . ': ' . $value . "\n";
108 } catch (Exception $e) {
109 echo 'Error: ' . $e->getMessage() . "\n";