From 8735a31fb391e9ef228f23873addb015385c77b4 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 15 Dec 2010 18:55:44 +0100 Subject: [PATCH] add some simple logging --- Wrt3g.php | 38 ++++++++++++++++++++++++++++++++++---- scripts/linksys-wrt3g.php | 16 +++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/Wrt3g.php b/Wrt3g.php index 131f626..8d12ca6 100644 --- 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 diff --git a/scripts/linksys-wrt3g.php b/scripts/linksys-wrt3g.php index ae7317b..e9279e3 100755 --- a/scripts/linksys-wrt3g.php +++ b/scripts/linksys-wrt3g.php @@ -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': -- 2.30.2