*/
public $verbosity = 0;
+ /**
+ * Class to send HTTP Requests with.
+ * Needs to be compatible with HTTP_Request2
+ *
+ * @var string
+ */
+ public $requestClass = 'HTTP_Request2';
+
/**
$url = $this->getAuthBaseUrl() . '/apply.cgi';
$this->log('Connecting to ' . $url);
- $r = new HTTP_Request2();
+ $r = new $this->requestClass();
$r->setMethod(HTTP_Request2::METHOD_POST);
$r->setUrl($url);
$r->addPostParameter('action', 'Reboot');
/**
* Connection status
*/
- $r = new HTTP_Request2();
+ $r = new $this->requestClass();
$r->setMethod(HTTP_Request2::METHOD_GET);
$r->setUrl($strUrlBase . '/index_wstatus2.asp');
$this->log('Connecting to ' . $strUrlBase . '/index_wstatus2.asp', 1);
$url = $strUrlBase . '/Status_NoAuth.asp';
$this->log('Connecting to ' . $url, 1);
- $r = new HTTP_Request2();
+ $r = new $this->requestClass();
$r->setMethod(HTTP_Request2::METHOD_GET);
$r->setUrl($url);
$resp = $r->send();
--- /dev/null
+<?php
+require_once 'HTTP/Request2.php';
+require_once 'HTTP/Request2/Adapter/Mock.php';
+
+class Wrt3g_DummyRequest extends HTTP_Request2
+{
+ /**
+ * Maps request paths (i.e. "/index.php") to files containing the HTML body
+ *
+ * @var array
+ */
+ public static $mapping = array(
+ '/Status_NoAuth.asp' => 'tests/status_noauth-connected.htm'
+ );
+
+
+
+ /**
+ * Sets the mock connection adapter
+ *
+ * @param string|Net_Url2 Request URL
+ * @param string Request method
+ * @param array Configuration for this Request instance
+ */
+ public function __construct(
+ $url = null, $method = self::METHOD_GET, array $config = array()
+ ) {
+ parent::__construct($url, $method, $config);
+ $this->setAdapter(new HTTP_Request2_Adapter_Mock());
+ }
+
+
+
+ /**
+ * Sends the request and returns the response
+ *
+ * @return HTTP_Request2_Response
+ *
+ * @throws HTTP_Request2_Exception When the path is not mapped, or
+ * the mapped file does not exist
+ */
+ public function send()
+ {
+ $path = $this->url->getPath();
+ if (!isset(self::$mapping[$path])) {
+ throw new HTTP_Request2_Exception(
+ 'No predefined response for path: ' . $path
+ );
+ }
+
+ $file = dirname(__FILE__) . '/../' . self::$mapping[$path];
+ if (!file_exists($file)) {
+ throw new HTTP_Request2_Exception(
+ 'Response file does not exist: ' . $file
+ );
+ }
+
+ $this->adapter->addResponse(
+ "HTTP/1.0 200 OK\n"
+ . "\n"
+ . file_get_contents($file)
+ );
+
+ return parent::send();
+ }
+}
+
+?>
\ No newline at end of file
'action' => 'Counter',
)
);
+$parser->addOption(
+ 'dummy',
+ array(
+ 'long_name' => '--dummy',
+ 'description' => 'Use dummy router data, not real ones',
+ 'action' => 'StoreTrue',
+ )
+);
$stCmd = $parser->addCommand(
'status',
try {
$router = new Wrt3g();
+ if ($result->options['dummy']) {
+ require_once 'Wrt3g/DummyRequest.php';
+ $router->requestClass = 'Wrt3g_DummyRequest';
+ $router->log('Using dummy data', 1);
+ } else {
+ }
$router->verbosity = $result->options['verbosity'];
$router->host = $result->options['host'];
$router->user = $result->options['user'];
$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) {