diff --git a/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/Api/ReverseProxyController.php b/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/Api/ReverseProxyController.php index 4dcd01ce6..eb94b82e0 100644 --- a/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/Api/ReverseProxyController.php +++ b/www/caddy/src/opnsense/mvc/app/controllers/OPNsense/Caddy/Api/ReverseProxyController.php @@ -41,9 +41,22 @@ class ReverseProxyController extends ApiMutableModelControllerBase /*ReverseProxy Section*/ - public function searchReverseProxyAction($add_empty = '0') + /*Search Function adjusted for the search filter dropdown*/ + public function searchReverseProxyAction() { - return $this->searchBase("reverseproxy.reverse", null, 'description'); + // Get a comma-separated list of UUIDs from the request + $reverseUuids = $this->request->get('reverseUuids'); + $uuidArray = !empty($reverseUuids) ? explode(',', $reverseUuids) : []; + + // Define the filter function to handle multiple UUIDs + $filterFunction = function ($modelItem) use ($uuidArray) { + $itemUuid = (string)$modelItem->getAttributes()['uuid']; + // Include the item if no UUIDs are provided (empty array) or if it's in the array of UUIDs + return empty($uuidArray) || in_array($itemUuid, $uuidArray, true); + }; + + // Return the search results filtered by the provided UUIDs, if any + return $this->searchBase("reverseproxy.reverse", null, 'description', $filterFunction); } public function setReverseProxyAction($uuid) @@ -70,13 +83,48 @@ class ReverseProxyController extends ApiMutableModelControllerBase { return $this->toggleBase("reverseproxy.reverse", $uuid, $enabled); } + + /*Function for the search filter dropdown in the bootgrid*/ + public function getAllReverseDomainsAction() + { + $this->sessionClose(); // Close session early for performance + $result = array("rows" => array()); + + $mdlCaddy = new \OPNsense\Caddy\Caddy(); + $reverseNodes = $mdlCaddy->reverseproxy->reverse->iterateItems(); + + foreach ($reverseNodes as $item) { + if (!empty($item->FromDomain)) { + // Conditionally concatenate port if it exists + $domain = (string)$item->FromDomain; + $port = (string)$item->FromPort; + $combinedDomainPort = $domain . (!empty($port) ? ':' . $port : ''); + + $result['rows'][] = array( + 'id' => (string)$item->getAttributes()['uuid'], + 'domainPort' => $combinedDomainPort // Combined domain and port, conditionally adding port + ); + } + } + + return $result; + } /*Subdomain Section*/ - public function searchSubdomainAction($add_empty = '0') + /*Search Function adjusted for the search filter dropdown*/ + public function searchSubdomainAction() { - return $this->searchBase("reverseproxy.subdomain", null, 'description'); + $reverseUuids = $this->request->get('reverseUuids'); + $uuidArray = !empty($reverseUuids) ? explode(',', $reverseUuids) : []; + + $filterFunction = function ($modelItem) use ($uuidArray) { + // Filtering on domain UUIDs referenced by subdomains + return empty($uuidArray) || in_array((string)$modelItem->reverse, $uuidArray, true); + }; + + return $this->searchBase("reverseproxy.subdomain", null, 'description', $filterFunction); } public function setSubdomainAction($uuid) @@ -106,10 +154,25 @@ class ReverseProxyController extends ApiMutableModelControllerBase /*Handler Section*/ - - public function searchHandleAction($add_empty = '0') + + /*Search Function adjusted for the search filter dropdown*/ + public function searchHandleAction() { - return $this->searchBase("reverseproxy.handle", null, 'description'); + $reverseUuids = $this->request->get('reverseUuids'); + $uuidArray = explode(',', $reverseUuids); + + if (empty($reverseUuids)) { + // If no UUIDs are provided, do not apply any filter, return all records + return $this->searchBase("reverseproxy.handle", null, 'description'); + } else { + // Apply the filter only if UUIDs are provided + $filterFunction = function ($modelItem) use ($uuidArray) { + $modelUUID = (string)$modelItem->reverse; + return in_array($modelUUID, $uuidArray, true); + }; + + return $this->searchBase("reverseproxy.handle", null, 'description', $filterFunction); + } } public function setHandleAction($uuid) @@ -140,7 +203,7 @@ class ReverseProxyController extends ApiMutableModelControllerBase /* AccessList Section */ - public function searchAccessListAction($add_empty = '0') + public function searchAccessListAction() { return $this->searchBase("reverseproxy.accesslist", null, 'description'); } @@ -168,7 +231,7 @@ class ReverseProxyController extends ApiMutableModelControllerBase /* BasicAuth Section */ - public function searchBasicAuthAction($add_empty = '0') + public function searchBasicAuthAction() { return $this->searchBase("reverseproxy.basicauth", null, 'description'); } @@ -216,7 +279,7 @@ class ReverseProxyController extends ApiMutableModelControllerBase /* Header Section */ - public function searchHeaderAction($add_empty = '0') + public function searchHeaderAction() { return $this->searchBase("reverseproxy.header", null, 'description'); } diff --git a/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt b/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt index 5d9ebc406..ed93146a1 100644 --- a/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt +++ b/www/caddy/src/opnsense/mvc/app/views/OPNsense/Caddy/reverse_proxy.volt @@ -26,6 +26,17 @@ + +