From ca9dfd03c419bb55cc479fb46862f6187c08091f Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 14 Apr 2016 19:09:59 +0200 Subject: [PATCH] (network insight) add protocols and services to api --- .../Api/NetworkinsightController.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php index 8e0646f25..dfae16b98 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/NetworkinsightController.php @@ -168,4 +168,41 @@ class NetworkinsightController extends ApiControllerBase } return $allInterfaces; } + + /** + * return known protocols + */ + public function getProtocolsAction() + { + $result = array(); + foreach (explode ("\n", file_get_contents('/etc/protocols')) as $line) { + if (strlen($line) > 1 && $line[0] != '#') { + $parts = preg_split('/\s+/', $line); + if (count($parts) >= 4) { + $result[$parts[1]] = $parts[0]; + } + } + } + return $result; + } + + /** + * return known services + */ + public function getServicesAction() + { + $result = array(); + foreach (explode ("\n", file_get_contents('/etc/services')) as $line) { + if (strlen($line) > 1 && $line[0] != '#') { + // there a few ports which have different names for different protocols, but to not overcomplicate + // things here, we ignore those exceptions. + $parts = preg_split('/\s+/', $line); + if (count($parts) >= 2) { + $portnum = explode('/', trim($parts[1]))[0]; + $result[$portnum] = $parts[0]; + } + } + } + return $result; + } }