X-Git-Url: https://git.cweiske.de/linksys-wrt3g-tools.git/blobdiff_plain/0b326c29602851bfc839e395d86cc84a86f67c89..6a5bf4c36f788ac0eb8112ccec0bbd371d5bbd94:/scripts/linksys-wrt3g.php diff --git a/scripts/linksys-wrt3g.php b/scripts/linksys-wrt3g.php old mode 100644 new mode 100755 index 1d1b9d2..219e081 --- a/scripts/linksys-wrt3g.php +++ b/scripts/linksys-wrt3g.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php description = 'Tool to control Linksys WRT3g routers'; +$parser->description = "Tool to control Linksys WRT3g routers"; $parser->version = '0.0.1';//FIXME: dynamic $parser->addOption( 'host', @@ -61,16 +62,52 @@ $parser->addOption( 'default' => $GLOBALS['linksys-wrt3g-tools']['password'] ) ); +$parser->addOption( + 'verbosity', + array( + 'short_name' => '-v', + 'long_name' => '--verbose', + 'description' => 'Show more details (more to see more details)', + 'action' => 'Counter', + ) +); +$parser->addOption( + 'dummy', + array( + 'long_name' => '--dummy', + 'description' => "Use dummy router data, not real ones. +Dummy responses can be controlled with the host parameter; 3-letter numeric hosts are interpreted as HTTP response code", + 'action' => 'StoreTrue', + ) +); -$parser->addCommand( +$stCmd = $parser->addCommand( 'status', array( - 'description' => 'Show the router status' + 'aliases' => array('s', 'st'), + 'description' => 'Show the connection status' + ) +); +$stCmd = $parser->addCommand( + 'card', + array( + 'aliases' => array('c'), + 'description' => 'Show the PC card/SIM status' + ) +); +$stCmd = $parser->addCommand( + 'all', + array( + 'aliases' => array('a'), + 'description' => 'Show all status details' ) ); + + $parser->addCommand( 'reboot', array( + 'aliases' => array('r'), 'description' => 'Reboot the router' ) ); @@ -84,20 +121,47 @@ try { try { $router = new Wrt3g(); - $router->host = $result->options['host']; - $router->user = $result->options['user']; - $router->password = $result->options['password']; + $router->verbosity = $result->options['verbosity']; + $router->host = $result->options['host']; + $router->user = $result->options['user']; + $router->password = $result->options['password']; + + if ($result->options['dummy']) { + require_once 'Wrt3g/DummyRequest.php'; + $router->requestClass = 'Wrt3g_DummyRequest'; + $router->log('Using dummy data', 1); + } + + $router->log('Command: ' . $result->command_name, 2); switch ($result->command_name) { case 'reboot': - $router->reboot(); + $resp = $router->reboot(); + echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n"; + if (intval($resp->getStatus() / 100) != 2) { + exit(3); + } break; + case 'all': + case 'card': case 'status': default: - $arStatus = $router->getStatus(); + if ($result->command_name == 'all') { + $arStatus = $router->getFullStatus(); + } else if ($result->command_name == 'card') { + $arStatus = $router->getCardStatus(); + } else { + $arStatus = $router->getConnectionStatus(); + } foreach ($arStatus as $key => $value) { - echo $key . ': ' . $value . "\n"; + echo $key . ': '; + if (is_array($value)) { + //session usage + echo var_export($value, true) . "\n"; + } else { + echo $value . "\n"; + } } } } catch (Exception $e) {