From a440fc6931f0336596262603729ed539c66b9038 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Thu, 6 Mar 2025 20:53:22 -0700 Subject: [PATCH 1/4] chore: correct var names for Forms in PrivilegesCache --- .../usr/local/pkg/RESTAPI/Caches/PrivilegesCache.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Caches/PrivilegesCache.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Caches/PrivilegesCache.inc index fa196bf26..095278d6b 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Caches/PrivilegesCache.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Caches/PrivilegesCache.inc @@ -25,10 +25,10 @@ class PrivilegesCache extends Cache { $privs += $endpoint_object->generate_pfsense_privs(); } - # Obtain privileges for each Endpoint class - foreach (get_classes_from_namespace('\\RESTAPI\\Forms\\') as $endpoint_class) { - $endpoint_object = new $endpoint_class(); - $privs += $endpoint_object->generate_pfsense_privs(); + # Obtain privileges for each Form class + foreach (get_classes_from_namespace('\\RESTAPI\\Forms\\') as $form_class) { + $form_object = new $form_class(); + $privs += $form_object->generate_pfsense_privs(); } return $privs; From 5f8547a092954298119c9ac263f22472c2dc88ed Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Thu, 6 Mar 2025 21:08:35 -0700 Subject: [PATCH 2/4] fix: tighten priv matches for Form classes #658 --- pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc index d90e39454..6684a6af8 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc @@ -513,6 +513,7 @@ class Form { $this->get_priv_name() => [ 'name' => 'WebCfg - ' . $this->verbose_name, 'descr' => "Allow access to the $this->url page.", + 'match' => [substr($this->url, 1)] ], ]; } From e829caf433b0f31079920c737b91f8b0cbe2ee5b Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Thu, 6 Mar 2025 21:19:13 -0700 Subject: [PATCH 3/4] fix: adjust Form priv verbose names --- .../files/usr/local/pkg/RESTAPI/Core/Form.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc index 6684a6af8..962a20bdd 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc @@ -165,7 +165,17 @@ class Form { private function generate_verbose_name(): string { # Separate the class name's words with spaces, allow consecutive capital characters like 'DNS' $form_name = $this->get_class_shortname(); - return preg_replace('/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/', ': ', $form_name); + $verbose_name = preg_replace('/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/', ' ', $form_name); + + # Add a colon after the first word if the class name is more than one word + if (str_contains($verbose_name, ' ')) { + $verbose_name = explode(' ', $verbose_name); + $verbose_name[0] .= ': '; + $verbose_name = implode(' ', $verbose_name); + } + + # Return the verbose name with the 'Form' suffix removed + return str_replace(' Form', '', $verbose_name); } /** From 88bb8bd758154b25f303a6afdcd879bd19a50d68 Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Thu, 6 Mar 2025 21:19:44 -0700 Subject: [PATCH 4/4] style: run prettier on changed files --- pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc index 962a20bdd..769d1d195 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Form.inc @@ -523,7 +523,7 @@ class Form { $this->get_priv_name() => [ 'name' => 'WebCfg - ' . $this->verbose_name, 'descr' => "Allow access to the $this->url page.", - 'match' => [substr($this->url, 1)] + 'match' => [substr($this->url, 1)], ], ]; }