Merge branch '0.11-dev' of github.com:Froxlor/Froxlor into 0.11-dev

This commit is contained in:
envoyr
2022-02-23 18:28:13 +01:00
4 changed files with 104 additions and 38 deletions

View File

@@ -37,39 +37,23 @@ if ($page == 'ipsandports' || $page == 'overview') {
if ($action == '') { if ($action == '') {
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_ipsandports"); $log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_NOTICE, "viewed admin_ipsandports");
$fields = array( $ipsandports_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/admin/tablelisting.ipsandports.php';
'ip' => $lng['admin']['ipsandports']['ip'],
'port' => $lng['admin']['ipsandports']['port']
);
try { try {
// get total count // get collection
$json_result = IpsAndPorts::getLocal($userinfo)->listingCount(); $collection = new \Froxlor\UI\Collection(\Froxlor\Api\Commands\IpsAndPorts::class, $userinfo);
$result = json_decode($json_result, true)['data'];
// initialize pagination and filtering // initialize pagination and filtering
$paging = new \Froxlor\UI\Pagination($userinfo, $fields, $result); $paging = new \Froxlor\UI\Pagination($userinfo, $ipsandports_list_data['ipsandports_list']['columns'], $collection->count());
// get list // get filtered collection
$json_result = IpsAndPorts::getLocal($userinfo, $paging->getApiCommandParams())->listing(); $collection = new \Froxlor\UI\Collection(\Froxlor\Api\Commands\IpsAndPorts::class, $userinfo, $paging->getApiCommandParams());
} catch (Exception $e) { } catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage()); \Froxlor\UI\Response::dynamic_error($e->getMessage());
} }
$result = json_decode($json_result, true)['data'];
$ipsandports = ''; UI::twigBuffer('user/table.html.twig', [
$sortcode = $paging->getHtmlSortCode($lng); 'listing' => \Froxlor\UI\Listing::format($collection, $ipsandports_list_data['ipsandports_list']),
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); ]);
$searchcode = $paging->getHtmlSearchCode($lng); UI::twigOutputBuffer();
$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") . "\";");
} elseif ($action == 'delete' && $id != 0) { } elseif ($action == 'delete' && $id != 0) {
try { try {
$json_result = IpsAndPorts::getLocal($userinfo, array( $json_result = IpsAndPorts::getLocal($userinfo, array(

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Froxlor\UI; namespace Froxlor\UI;
/** /**
@@ -23,7 +24,7 @@ class Collection
private array $params; private array $params;
private string $class; private string $class;
public function __construct($class, $userInfo, $params = []) public function __construct(string $class, array $userInfo, array $params = [])
{ {
$this->class = $class; $this->class = $class;
$this->params = $params; $this->params = $params;
@@ -57,16 +58,20 @@ class Collection
return json_encode($this->get()); 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 ($this->items['data']['list'] as $key => $item) {
foreach ($attributes['data']['list'] as $list) { foreach ($attributes['data']['list'] as $list) {
if ($item[$parentKey] == $list[$childKey]) { if ($item[$parentKey] == $list[$childKey]) {
$this->items['data']['list'][$key][$column] = $list; $this->items['data']['list'][$key][$column] = $list;
}
} }
} }
} }
return $this;
} }
} }

View File

@@ -0,0 +1,77 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @author Maurice Preuß <hello@envoyr.com>
* @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'
]),
]
];

View File

@@ -12,9 +12,9 @@
{% macro boolean(data) %} {% macro boolean(data) %}
{% if (data) %} {% if (data) %}
<i class="fa fa-check-circle"></i> <i class="fa fa-check-circle text-success"></i>
{% else %} {% else %}
<i class="fa fa-times-circle"></i> <i class="fa fa-times-circle text-danger"></i>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
@@ -33,4 +33,4 @@
{% endapply %} {% endapply %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}