fix dummy setup
[linksys-wrt3g-tools.git] / scripts / linksys-wrt3g.php
index ae7317bd3a00f50e42af14b743f61c440c50ae69..628dfe97f68e30bb1b7e1ba3b723766b17c30570 100755 (executable)
@@ -27,7 +27,10 @@ if (file_exists($configFile)) {
 }
 
 $parser = new Console_CommandLine();
-$parser->description = 'Tool to control Linksys WRT3g routers';
+$parser->description = "Tool to control Linksys WRT3g routers
+
+Dummy responses can be controlled with the host parameter:
+ A 3-letter numeric host is interpreted as HTTP response code";
 $parser->version = '0.0.1';//FIXME: dynamic
 $parser->addOption(
     'host',
@@ -62,14 +65,47 @@ $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',
+        'action'      => 'StoreTrue',
+    )
+);
 
-$parser->addCommand(
+$stCmd = $parser->addCommand(
     'status',
     array(
         'aliases'     => array('s', 'st'),
-        'description' => 'Show the router status'
+        'description' => 'Show the connection status'
+    )
+);
+$stCmd = $parser->addCommand(
+    'cardstatus',
+    array(
+        'aliases'     => array('c', 'cs'),
+        'description' => 'Show the card/SIM status'
+    )
+);
+$stCmd = $parser->addCommand(
+    'allstatus',
+    array(
+        'aliases'     => array('a', 'as'),
+        'description' => 'Show all status details'
     )
 );
+
+
 $parser->addCommand(
     'reboot',
     array(
@@ -87,9 +123,18 @@ 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':
@@ -100,11 +145,25 @@ try {
         }
         break;
 
+    case 'allstatus':
+    case 'cardstatus':
     case 'status':
     default:
-        $arStatus = $router->getStatus();
+        if ($result->command_name == 'allstatus') {
+            $arStatus = $router->getFullStatus();
+        } else if ($result->command_name == 'cardstatus') {
+            $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) {