add some simple logging
authorChristian Weiske <cweiske@cweiske.de>
Wed, 15 Dec 2010 17:55:44 +0000 (18:55 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 15 Dec 2010 17:55:44 +0000 (18:55 +0100)
Wrt3g.php
scripts/linksys-wrt3g.php

index 131f626951a745ad74c116694bdc7333e808d380..8d12ca611538f9e58195399a3c279e49c84e78de 100644 (file)
--- a/Wrt3g.php
+++ b/Wrt3g.php
@@ -46,6 +46,16 @@ class Wrt3g
      */
     public $password;
 
+    /**
+     * Logging verbosity
+     * 0 - no debug logging
+     * 1 - show important details (connected URLs)
+     * 2 - show internal details
+     *
+     * @var integer
+     */
+    public $verbosity = 0;
+
 
 
     /**
@@ -86,11 +96,12 @@ class Wrt3g
     */
     public function reboot()
     {
+        $url = $this->getAuthBaseUrl() . '/apply.cgi';
+        $this->log('Connecting to ' . $url);
+
         $r = new HTTP_Request2();
         $r->setMethod(HTTP_Request2::METHOD_POST);
-        $r->setUrl(
-            $this->getAuthBaseUrl() . '/apply.cgi'
-        );
+        $r->setUrl($url);
         $r->addPostParameter('action', 'Reboot');
         $r->addPostParameter('submit_button', 'Diagnostics');
         $r->addPostParameter('wait_time', 1);
@@ -122,19 +133,38 @@ class Wrt3g
         $r = new HTTP_Request2();
         $r->setMethod(HTTP_Request2::METHOD_GET);
         $r->setUrl($strUrlBase . '/index_wstatus2.asp');
+        $this->log('Connecting to ' . $strUrlBase . '/index_wstatus2.asp', 1);
         $resp = $r->send();
-        echo $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n";
+        $this->log($resp->getStatus() . ' ' . $resp->getReasonPhrase(), 1);
         $arRetval = $parser->index_wstatus2($resp->getBody());
 
         /**
         * GPRS/UMTS Status
         */
         $r->setUrl($strUrlBase . '/index_wstatus1.asp');
+        $this->log('Connecting to ' . $strUrlBase . '/index_wstatus1.asp', 1);
         $resp = $r->send();
         $body = $resp->getBody();
         $arRetval = array_merge($arRetval, $parser->index_wstatus1($body));
 
         return $arRetval;
     }//public function getStatus()
+
+
+
+    /**
+     * Log a message to stdout.
+     *
+     * @param string  $msg   Message to display
+     * @param integer $level Log level, see $verbosity
+     *
+     * @return void
+     */
+    protected function log($msg, $level = 1)
+    {
+        if ($this->verbosity >= $level) {
+            echo $msg . "\n";
+        }
+    }
 }
 ?>
\ No newline at end of file
index ae7317bd3a00f50e42af14b743f61c440c50ae69..e9279e3d464b0317071c10d77a7a99669acf55e8 100755 (executable)
@@ -62,6 +62,15 @@ $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->addCommand(
     'status',
@@ -87,9 +96,10 @@ 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'];
 
     switch ($result->command_name) {
     case 'reboot':