add some simple logging
[linksys-wrt3g-tools.git] / 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