From 0fc88f2d3ddd998ff5eac8601653085cf179a4e1 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 14 Mar 2023 16:04:33 +0100 Subject: [PATCH] system: yup yup #6376 Most likely this is backend material which needs to be filtered/ used to render page content and react on via formalized API request in order to avoid leaking data. The nice thing about the filtering is that we only ever have to look up service status for matching services making the lookup faster. --- src/opnsense/service/conf/actions_service.conf | 4 ++-- src/sbin/pluginctl | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/opnsense/service/conf/actions_service.conf b/src/opnsense/service/conf/actions_service.conf index a1fc19b86..ba985cf69 100644 --- a/src/opnsense/service/conf/actions_service.conf +++ b/src/opnsense/service/conf/actions_service.conf @@ -12,6 +12,6 @@ message:Reloading all [list] command:/usr/local/sbin/pluginctl -S -parameters: +parameters:%s %s type:script_output -message:Fetching service list +message:Fetching service list (%s %s) diff --git a/src/sbin/pluginctl b/src/sbin/pluginctl index 7aefcd6d2..16be8f65d 100755 --- a/src/sbin/pluginctl +++ b/src/sbin/pluginctl @@ -101,7 +101,22 @@ if (isset($opts['h'])) { } } } elseif (isset($opts['S'])) { - echo json_encode(plugins_services(), JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT) . PHP_EOL; + $services = []; + foreach (plugins_services() as $service) { + /* fail if name filter does not match */ + if (!empty($args[0]) && $service['name'] != $args[0]) { + continue; + } + /* fail if ID lookup is not possible or does not match */ + if (isset($args[1]) && $args[1] !== '' && (!array_key_exists('id', $service) || $service['id'] != $args[1])) { + continue; + } + /* fetch status so the caller does not have to */ + $service['status'] = service_status($service); + /* collect all matches contrary to what service_by_name() is doing */ + $services[] = $service; + } + echo json_encode($services, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT) . PHP_EOL; } elseif (isset($opts['s'])) { $name = !empty($args[0]) ? $args[0] : ''; $act = !empty($args[1]) ? $args[1] : '';