make the request observer work correctly, remove response logging in main class
[linksys-wrt3g-tools.git] / scripts / linksys-wrt3g.php
index f47502523af8deb09809ed58a9f456892be33802..219e081c1c87be924830d8e756b32e1c4a622dac 100755 (executable)
@@ -27,7 +27,7 @@ if (file_exists($configFile)) {
 }
 
 $parser = new Console_CommandLine();
-$parser->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',
@@ -71,19 +71,35 @@ $parser->addOption(
         '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',
+    )
+);
 
 $stCmd = $parser->addCommand(
     'status',
     array(
         'aliases'     => array('s', 'st'),
-        'description' => 'Show the router status'
+        'description' => 'Show the connection status'
+    )
+);
+$stCmd = $parser->addCommand(
+    'card',
+    array(
+        'aliases'     => array('c'),
+        'description' => 'Show the PC card/SIM status'
     )
 );
 $stCmd = $parser->addCommand(
-    'cardstatus',
+    'all',
     array(
-        'aliases'     => array('c', 'cs'),
-        'description' => 'Show the card/SIM status'
+        'aliases'     => array('a'),
+        'description' => 'Show all status details'
     )
 );
 
@@ -110,6 +126,12 @@ try {
     $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) {
@@ -121,16 +143,25 @@ try {
         }
         break;
 
-    case 'cardstatus':
+    case 'all':
+    case 'card':
     case 'status':
     default:
-        if ($result->command_name == 'cardstatus') {
+        if ($result->command_name == 'all') {
+            $arStatus = $router->getFullStatus();
+        } else if ($result->command_name == 'card') {
             $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) {