add dummy responses
[linksys-wrt3g-tools.git] / scripts / linksys-wrt3g.php
index f47502523af8deb09809ed58a9f456892be33802..824c287ae8861718b8f2945de4fa10068aef9893 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',
@@ -71,12 +74,20 @@ $parser->addOption(
         'action'      => 'Counter',
     )
 );
+$parser->addOption(
+    'dummy',
+    array(
+        'long_name'   => '--dummy',
+        'description' => 'Use dummy router data, not real ones',
+        'action'      => 'StoreTrue',
+    )
+);
 
 $stCmd = $parser->addCommand(
     'status',
     array(
         'aliases'     => array('s', 'st'),
-        'description' => 'Show the router status'
+        'description' => 'Show the connection status'
     )
 );
 $stCmd = $parser->addCommand(
@@ -86,6 +97,13 @@ $stCmd = $parser->addCommand(
         'description' => 'Show the card/SIM status'
     )
 );
+$stCmd = $parser->addCommand(
+    'allstatus',
+    array(
+        'aliases'     => array('a', 'as'),
+        'description' => 'Show all status details'
+    )
+);
 
 
 $parser->addCommand(
@@ -105,6 +123,12 @@ try {
 
 try {
     $router = new Wrt3g();
+    if ($result->options['dummy']) {
+        require_once 'Wrt3g/DummyRequest.php';
+        $router->requestClass = 'Wrt3g_DummyRequest';
+        $router->log('Using dummy data', 1);
+    } else {
+    }
     $router->verbosity = $result->options['verbosity'];
     $router->host      = $result->options['host'];
     $router->user      = $result->options['user'];
@@ -121,16 +145,25 @@ try {
         }
         break;
 
+    case 'allstatus':
     case 'cardstatus':
     case 'status':
     default:
-        if ($result->command_name == 'cardstatus') {
+        if ($result->command_name == 'allstatus') {
+            $arStatus = $router->getFullStatus();
+        } else if ($result->command_name == 'cardstatus') {
             $arStatus = $router->getCardStatus();
         } else {
-            $arStatus = $router->getStatus();
+            $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) {