add card status command
authorChristian Weiske <cweiske@cweiske.de>
Wed, 15 Dec 2010 18:09:42 +0000 (19:09 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 15 Dec 2010 18:09:42 +0000 (19:09 +0100)
Wrt3g.php
scripts/linksys-wrt3g.php

index 82c728f04750f4f7179363334bec4423435a5841..a14adf5e5619adea5a995d70ba9af3c405fcdd34 100644 (file)
--- a/Wrt3g.php
+++ b/Wrt3g.php
@@ -152,6 +152,46 @@ class Wrt3g
 
 
 
+    /**
+     * Retrieves pc card/SIM status information
+     *
+     * @return array Array with several key-value pairs
+     *               connection => connecting, disconnected, connected
+     *
+     * @throws Exception When the router can't be reached
+     */
+    public function getCardStatus()
+    {
+        $arRetval = array();
+
+        $strUrlBase = $this->getAuthBaseUrl();
+
+        $url = $strUrlBase . '/Status_NoAuth.asp';
+        $this->log('Connecting to ' . $url, 1);
+
+        $r = new HTTP_Request2();
+        $r->setMethod(HTTP_Request2::METHOD_GET);
+        $r->setUrl($url);
+        $resp = $r->send();
+        $this->log($resp->getStatus() . ' ' . $resp->getReasonPhrase(), 1);
+        //FIXME: check status
+
+        $parser = new Wrt3g_HtmlParser();
+        $arRetval = $parser->status_noauth($resp->getBody());
+
+        return array_intersect_key(
+            $arRetval,
+            array(
+                'card model'    => 0,
+                'card revision' => 0,
+                'card firmware' => 0,
+                'IMSI'          => 0
+            )
+        );
+    }
+
+
+
     /**
      * Log a message to stdout.
      *
@@ -160,7 +200,7 @@ class Wrt3g
      *
      * @return void
      */
-    protected function log($msg, $level = 1)
+    public function log($msg, $level = 1)
     {
         if ($this->verbosity >= $level) {
             echo $msg . "\n";
index e9279e3d464b0317071c10d77a7a99669acf55e8..f47502523af8deb09809ed58a9f456892be33802 100755 (executable)
@@ -72,13 +72,22 @@ $parser->addOption(
     )
 );
 
-$parser->addCommand(
+$stCmd = $parser->addCommand(
     'status',
     array(
         'aliases'     => array('s', 'st'),
         'description' => 'Show the router status'
     )
 );
+$stCmd = $parser->addCommand(
+    'cardstatus',
+    array(
+        'aliases'     => array('c', 'cs'),
+        'description' => 'Show the card/SIM status'
+    )
+);
+
+
 $parser->addCommand(
     'reboot',
     array(
@@ -101,6 +110,8 @@ try {
     $router->user      = $result->options['user'];
     $router->password  = $result->options['password'];
 
+    $router->log('Command: ' . $result->command_name, 2);
+
     switch ($result->command_name) {
     case 'reboot':
         $resp = $router->reboot();
@@ -110,9 +121,14 @@ try {
         }
         break;
 
+    case 'cardstatus':
     case 'status':
     default:
-        $arStatus = $router->getStatus();
+        if ($result->command_name == 'cardstatus') {
+            $arStatus = $router->getCardStatus();
+        } else {
+            $arStatus = $router->getStatus();
+        }
         foreach ($arStatus as $key => $value) {
             echo $key . ': ' . $value . "\n";
         }