1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#!/usr/bin/env php
<?php
/**
* Control script for Linksys WRT3g routers.
*
* PHP version 5
*
* @category Tools
* @package linksys-wrt3g-tools
* @author Christian Weiske <cweiske@cweiske.de>
* @license AGPL v3
* @link http://cweiske.de/linksys-wrt3g-tools.htm
*/
require_once 'Wrt3g.php';
require_once 'Console/CommandLine.php';
//default config options
$GLOBALS['linksys-wrt3g-tools'] = array(
'host' => null,
'user' => 'admin',
'password' => null,
);
$configFile = dirname(__FILE__) . '/../config.php';
if (file_exists($configFile)) {
require_once $configFile;
}
$parser = new Console_CommandLine();
$parser->description = 'Tool to control Linksys WRT3g routers';
$parser->version = '0.0.1';//FIXME: dynamic
$parser->addOption(
'host',
array(
'short_name' => '-h',
'long_name' => '--host',
'description' => 'IP/Hostname to connect to',
'help_name' => 'HOST',
'action' => 'StoreString',
'default' => $GLOBALS['linksys-wrt3g-tools']['host']
)
);
$parser->addOption(
'user',
array(
'short_name' => '-u',
'long_name' => '--user',
'description' => 'Admin user name',
'help_name' => 'USER',
'action' => 'StoreString',
'default' => $GLOBALS['linksys-wrt3g-tools']['user']
)
);
$parser->addOption(
'password',
array(
'short_name' => '-p',
'long_name' => '--password',
'description' => 'Password for admin user',
'help_name' => 'PASS',
'action' => 'StoreString',
'default' => $GLOBALS['linksys-wrt3g-tools']['password']
)
);
$parser->addCommand(
'status',
array(
'description' => 'Show the router status'
)
);
$parser->addCommand(
'reboot',
array(
'description' => 'Reboot the router'
)
);
try {
$result = $parser->parse();
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
exit(1);
}
try {
$router = new Wrt3g();
$router->host = $result->options['host'];
$router->user = $result->options['user'];
$router->password = $result->options['password'];
switch ($result->command_name) {
case 'reboot':
$resp = $router->reboot();
echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
if (intval($resp->getStatus() / 100) != 2) {
exit(3);
}
break;
case 'status':
default:
$arStatus = $router->getStatus();
foreach ($arStatus as $key => $value) {
echo $key . ': ' . $value . "\n";
}
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage() . "\n";
exit(2);
}
?>
|