From 8c2a4aeec41ab7c8e19ffd3d0f8b6655d1a64f22 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 23 Feb 2022 17:40:36 +0100 Subject: [PATCH 1/3] add tablisting.ipsandports Signed-off-by: Michael Kaufmann --- admin_ipsandports.php | 37 +++------ .../admin/tablelisting.ipsandports.php | 77 +++++++++++++++++++ templates/Froxlor/table/callbacks.html.twig | 6 +- 3 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 lib/tablelisting/admin/tablelisting.ipsandports.php diff --git a/admin_ipsandports.php b/admin_ipsandports.php index 0eb6ac90..dbe549d9 100644 --- a/admin_ipsandports.php +++ b/admin_ipsandports.php @@ -37,39 +37,24 @@ if ($page == 'ipsandports' || $page == 'overview') { if ($action == '') { $log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_ipsandports"); - $fields = array( - 'ip' => $lng['admin']['ipsandports']['ip'], - 'port' => $lng['admin']['ipsandports']['port'] - ); + $ipsandports_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.ipsandports.php'; + try { - // get total count - $json_result = IpsAndPorts::getLocal($userinfo)->listingCount(); - $result = json_decode($json_result, true)['data']; + // get collection + $collection = new \Froxlor\UI\Collection(\Froxlor\Api\Commands\IpsAndPorts::class, $userinfo); // initialize pagination and filtering - $paging = new \Froxlor\UI\Pagination($userinfo, $fields, $result); - // get list - $json_result = IpsAndPorts::getLocal($userinfo, $paging->getApiCommandParams())->listing(); + $paging = new \Froxlor\UI\Pagination($userinfo, $ipsandports_list_data['ipsandports_list']['columns'], $collection->count()); + // get filtered collection + $collection = new \Froxlor\UI\Collection(\Froxlor\Api\Commands\IpsAndPorts::class, $userinfo, $paging->getApiCommandParams()); } catch (Exception $e) { \Froxlor\UI\Response::dynamic_error($e->getMessage()); } $result = json_decode($json_result, true)['data']; - $ipsandports = ''; - $sortcode = $paging->getHtmlSortCode($lng); - $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); - $searchcode = $paging->getHtmlSearchCode($lng); - $pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s); - $count = 0; - - foreach ($result['list'] as $row) { - $row = \Froxlor\PhpHelper::htmlentitiesArray($row); - if (filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - $row['ip'] = '[' . $row['ip'] . ']'; - } - eval("\$ipsandports.=\"" . \Froxlor\UI\Template::getTemplate("ipsandports/ipsandports_ipandport") . "\";"); - $count++; - } - eval("echo \"" . \Froxlor\UI\Template::getTemplate("ipsandports/ipsandports") . "\";"); + UI::twigBuffer('user/table.html.twig', [ + 'listing' => \Froxlor\UI\Listing::format($collection, $ipsandports_list_data['ipsandports_list']), + ]); + UI::twigOutputBuffer(); } elseif ($action == 'delete' && $id != 0) { try { $json_result = IpsAndPorts::getLocal($userinfo, array( diff --git a/lib/tablelisting/admin/tablelisting.ipsandports.php b/lib/tablelisting/admin/tablelisting.ipsandports.php new file mode 100644 index 00000000..8ebf4abd --- /dev/null +++ b/lib/tablelisting/admin/tablelisting.ipsandports.php @@ -0,0 +1,77 @@ + (2010-) + * @author Maurice Preuß + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Tabellisting + * + */ + +return [ + 'ipsandports_list' => [ + 'title' => $lng['admin']['ipsandports']['ipsandports'], + 'icon' => 'fa-solid fa-user', + 'columns' => [ + 'ip' => [ + 'label' => $lng['admin']['ipsandports']['ip'], + 'column' => 'ip', + ], + 'port' => [ + 'label' => $lng['admin']['ipsandports']['port'], + 'column' => 'port', + ], + 'listen' => [ + 'label' => 'Listen', + 'column' => 'listen_statement', + 'format_callback' => [\Froxlor\UI\Callbacks\Text::class, 'boolean'], + 'visible' => \Froxlor\Settings::Get('system.webserver') != 'nginx' + ], + 'namevirtualhost' => [ + 'label' => 'NameVirtualHost', + 'column' => 'namevirtualhost_statement', + 'format_callback' => [\Froxlor\UI\Callbacks\Text::class, 'boolean'], + 'visible' => \Froxlor\Settings::Get('system.webserver') == 'apache2' && (int) \Froxlor\Settings::Get('system.apache24') == 0 + ], + 'vhostcontainer' => [ + 'label' => 'vHost-Container', + 'column' => 'vhostcontainer', + 'format_callback' => [\Froxlor\UI\Callbacks\Text::class, 'boolean'] + ], + 'specialsettings' => [ + 'label' => 'Specialsettings', + 'column' => 'specialsettings', + 'format_callback' => [\Froxlor\UI\Callbacks\Text::class, 'boolean'] + ], + 'servername' => [ + 'label' => 'ServerName', + 'column' => 'vhostcontainer_servername_statement', + 'format_callback' => [\Froxlor\UI\Callbacks\Text::class, 'boolean'], + 'visible' => \Froxlor\Settings::Get('system.webserver') == 'apache2' + ], + 'ssl' => [ + 'label' => 'SSL', + 'column' => 'ssl', + 'format_callback' => [\Froxlor\UI\Callbacks\Text::class, 'boolean'] + ], + ], + 'visible_columns' => \Froxlor\UI\Listing::getVisibleColumnsForListing('ipsandports_list', [ + 'ip', + 'port', + 'listen', + 'namevirtualhost', + 'vhostcontainer', + 'specialsettings', + 'servername', + 'ssl' + ]), + ] +]; diff --git a/templates/Froxlor/table/callbacks.html.twig b/templates/Froxlor/table/callbacks.html.twig index 1ffbe3c8..8daee937 100644 --- a/templates/Froxlor/table/callbacks.html.twig +++ b/templates/Froxlor/table/callbacks.html.twig @@ -12,8 +12,8 @@ {% macro boolean(data) %} {% if (data) %} - + {% else %} - + {% endif %} -{% endmacro %} \ No newline at end of file +{% endmacro %} From 511c219d19270f4d82539008f64aa31a016c9db8 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 23 Feb 2022 17:41:31 +0100 Subject: [PATCH 2/3] forgot a line of old code Signed-off-by: Michael Kaufmann --- admin_ipsandports.php | 1 - 1 file changed, 1 deletion(-) diff --git a/admin_ipsandports.php b/admin_ipsandports.php index dbe549d9..0c928f71 100644 --- a/admin_ipsandports.php +++ b/admin_ipsandports.php @@ -49,7 +49,6 @@ if ($page == 'ipsandports' || $page == 'overview') { } catch (Exception $e) { \Froxlor\UI\Response::dynamic_error($e->getMessage()); } - $result = json_decode($json_result, true)['data']; UI::twigBuffer('user/table.html.twig', [ 'listing' => \Froxlor\UI\Listing::format($collection, $ipsandports_list_data['ipsandports_list']), From af50eb54628ae111604d1b491c41df3ec156fcdd Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 23 Feb 2022 17:57:10 +0100 Subject: [PATCH 3/3] small enhancements to Collection Signed-off-by: Michael Kaufmann --- lib/Froxlor/UI/Collection.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Froxlor/UI/Collection.php b/lib/Froxlor/UI/Collection.php index 4a20eda2..cf9417ad 100644 --- a/lib/Froxlor/UI/Collection.php +++ b/lib/Froxlor/UI/Collection.php @@ -1,4 +1,5 @@ class = $class; $this->params = $params; @@ -57,16 +58,20 @@ class Collection return json_encode($this->get()); } - public function has($column, $class, $parentKey = 'id', $childKey = 'id', $params = []) + public function has($column, $class, $parentKey = 'id', $childKey = 'id', $params = []): Collection { - $attributes = $this->getListing($class, $params); + // check if the api result contains any items (not the overall listingCount as we might be in a search-resultset) + if (count($this->items) > 0) { + $attributes = $this->getListing($class, $params); - foreach ($this->items['data']['list'] as $key => $item) { - foreach ($attributes['data']['list'] as $list) { - if ($item[$parentKey] == $list[$childKey]) { - $this->items['data']['list'][$key][$column] = $list; + foreach ($this->items['data']['list'] as $key => $item) { + foreach ($attributes['data']['list'] as $list) { + if ($item[$parentKey] == $list[$childKey]) { + $this->items['data']['list'][$key][$column] = $list; + } } } } + return $this; } -} \ No newline at end of file +}