diff --git a/www/nginx/pkg-descr b/www/nginx/pkg-descr
index daad3ba2b..1ecc41ab8 100644
--- a/www/nginx/pkg-descr
+++ b/www/nginx/pkg-descr
@@ -11,6 +11,7 @@ Plugin Changelog
1.5
* Add proxy options for ignore client abort and disabling buffering
+* Add logviewer support for streams
1.4 (Development only)
diff --git a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php
index 00de73e5f..26d16716a 100644
--- a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php
+++ b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/LogsController.php
@@ -57,6 +57,28 @@ class LogsController extends ApiControllerBase
return $this->call_configd('error', $uuid);
}
}
+ public function stream_accessesAction($uuid = null)
+ {
+ $this->nginx = new Nginx();
+ if (!isset($uuid)) {
+ // emulate REST API -> /stream_accesses delivers a list of servers with access logs
+ return $this->list_streams();
+ } else {
+ // emulate REST call for a specific log /stream_accesses/uuid
+ return $this->call_configd_stream('streamaccess', $uuid);
+ }
+ }
+ public function stream_errorsAction($uuid = null)
+ {
+ $this->nginx = new Nginx();
+ if (!isset($uuid)) {
+ // emulate REST API -> /stream_errors delivers a list of servers with error logs
+ return $this->list_streams();
+ } else {
+ // emulate REST call for a specific log /stream_errors/uuid
+ return $this->call_configd_stream('streamerror', $uuid);
+ }
+ }
private function call_configd($type, $uuid)
{
@@ -68,6 +90,16 @@ class LogsController extends ApiControllerBase
$data = $backend->configdRun('nginx log ' . $type . ' ' . $uuid);
return json_decode($data, true);
}
+ private function call_configd_stream($type, $uuid)
+ {
+ if (!$this->stream_exists($uuid)) {
+ $this->response->setStatusCode(404, "Not Found");
+ }
+
+ $backend = new Backend();
+ $data = $backend->configdRun('nginx log ' . $type . ' ' . $uuid);
+ return json_decode($data, true);
+ }
private function list_vhosts()
{
@@ -77,10 +109,23 @@ class LogsController extends ApiControllerBase
}
return $data;
}
+ private function list_streams()
+ {
+ $data = [];
+ foreach ($this->nginx->stream_server->__items as $item) {
+ $data[] = array('id' => $item->getAttributes()['uuid'], 'port' => (string)$item->listen_port);
+ }
+ return $data;
+ }
private function vhost_exists($uuid)
{
$data = $this->nginx->getNodeByReference('http_server.'. $uuid);
return isset($data);
}
+ private function stream_exists($uuid)
+ {
+ $data = $this->nginx->getNodeByReference('stream_server.'. $uuid);
+ return isset($data);
+ }
}
diff --git a/www/nginx/src/opnsense/mvc/app/library/OPNsense/Nginx/StreamAccessLogLine.php b/www/nginx/src/opnsense/mvc/app/library/OPNsense/Nginx/StreamAccessLogLine.php
new file mode 100644
index 000000000..db58bb5e3
--- /dev/null
+++ b/www/nginx/src/opnsense/mvc/app/library/OPNsense/Nginx/StreamAccessLogLine.php
@@ -0,0 +1,39 @@
+file_name = $file_name;
+ $this->lines = file($this->file_name);
+ $this->result = array_map([$this, 'parse_line'], $this->lines);
+ }
+ private function parse_line($line)
+ {
+ $container = new StreamAccessLogLine();
+ if (preg_match(self::LogLineRegex, $line, $data)) {
+ $container->remote_ip = $data[1];
+ $container->time = $data[2];
+ $container->status = $data[3];
+ $container->bytes_sent = $data[4];
+ $container->bytes_received = $data[5];
+ $container->session_time = $data[6];
+ }
+ return $container;
+ }
+
+ public function get_result()
+ {
+ return $this->result;
+ }
+}
diff --git a/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt b/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt
index 7b41c062f..ac0771e2f 100644
--- a/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt
+++ b/www/nginx/src/opnsense/mvc/app/views/OPNsense/Nginx/index.volt
@@ -58,7 +58,7 @@
-
+