From 8c6452bb05a8fd0e5bab0e88785bcd1893054079 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Fri, 25 Feb 2022 17:17:29 +0100 Subject: [PATCH] customer-extras overviews Signed-off-by: Michael Kaufmann --- customer_extras.php | 104 +++++------------- .../customer/extras/formfield.backup.php | 7 +- .../extras/formfield.htaccess_add.php | 2 +- .../extras/formfield.htaccess_edit.php | 2 +- .../extras/formfield.htpasswd_add.php | 2 +- .../extras/formfield.htpasswd_edit.php | 2 +- .../customer/tablelisting.htaccess.php | 87 +++++++++++++++ .../customer/tablelisting.htpasswd.php | 63 +++++++++++ lng/english.lng.php | 4 +- lng/german.lng.php | 4 +- templates/Froxlor/form/formfields.html.twig | 22 +++- 11 files changed, 211 insertions(+), 88 deletions(-) create mode 100644 lib/tablelisting/customer/tablelisting.htaccess.php create mode 100644 lib/tablelisting/customer/tablelisting.htpasswd.php diff --git a/customer_extras.php b/customer_extras.php index 59427300..2fed7fd6 100644 --- a/customer_extras.php +++ b/customer_extras.php @@ -50,36 +50,18 @@ if ($page == 'overview') { 'path' => $lng['panel']['path'] ); try { - // get total count - $json_result = DirProtections::getLocal($userinfo)->listingCount(); - $result = json_decode($json_result, true)['data']; - // initialize pagination and filtering - $paging = new \Froxlor\UI\Pagination($userinfo, $fields, $result); - // get list - $json_result = DirProtections::getLocal($userinfo, $paging->getApiCommandParams())->listing(); + $htpasswd_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/customer/tablelisting.htpasswd.php'; + $list = (new \Froxlor\UI\Collection(\Froxlor\Api\Commands\DirProtections::class, $userinfo)) + ->withPagination($htpasswd_list_data['htpasswd_list']['columns']) + ->getList(); } catch (Exception $e) { \Froxlor\UI\Response::dynamic_error($e->getMessage()); } - $result = json_decode($json_result, true)['data']; - $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; - $htpasswds = ''; - - foreach ($result['list'] as $row) { - if (strpos($row['path'], $userinfo['documentroot']) === 0) { - $row['path'] = str_replace($userinfo['documentroot'], "/", $row['path']); - } - $row['path'] = \Froxlor\FileDir::makeCorrectDir($row['path']); - $row = \Froxlor\PhpHelper::htmlentitiesArray($row); - eval("\$htpasswds.=\"" . \Froxlor\UI\Template::getTemplate("extras/htpasswds_htpasswd") . "\";"); - $count ++; - } - - eval("echo \"" . \Froxlor\UI\Template::getTemplate("extras/htpasswds") . "\";"); + UI::twigBuffer('user/table.html.twig', [ + 'listing' => \Froxlor\UI\Listing::format($list, $htpasswd_list_data['htpasswd_list']), + ]); + UI::twigOutputBuffer(); } elseif ($action == 'delete' && $id != 0) { try { $json_result = DirProtections::getLocal($userinfo, array( @@ -181,51 +163,22 @@ if ($page == 'overview') { if ($action == '') { $log->logAction(\Froxlor\FroxlorLogger::USR_ACTION, LOG_NOTICE, "viewed customer_extras::htaccess"); - $fields = array( - 'path' => $lng['panel']['path'], - 'options_indexes' => $lng['extras']['view_directory'], - 'error404path' => $lng['extras']['error404path'], - 'error403path' => $lng['extras']['error403path'], - 'error500path' => $lng['extras']['error500path'], - 'options_cgi' => $lng['extras']['execute_perl'] - ); - try { - // get total count - $json_result = DirOptions::getLocal($userinfo)->listingCount(); - $result = json_decode($json_result, true)['data']; - // initialize pagination and filtering - $paging = new \Froxlor\UI\Pagination($userinfo, $fields, $result); - // get list - $json_result = DirOptions::getLocal($userinfo, $paging->getApiCommandParams())->listing(); - } catch (Exception $e) { - \Froxlor\UI\Response::dynamic_error($e->getMessage()); - } - $result = json_decode($json_result, true)['data']; - - $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; - $htaccess = ''; $cperlenabled = \Froxlor\Customer\Customer::customerHasPerlEnabled($userinfo['customerid']); - foreach ($result['list'] as $row) { - if (strpos($row['path'], $userinfo['documentroot']) === 0) { - $row['path'] = str_replace($userinfo['documentroot'], "/", $row['path']); - } - $row['path'] = \Froxlor\FileDir::makeCorrectDir($row['path']); - $row['options_indexes'] = str_replace('1', $lng['panel']['yes'], $row['options_indexes']); - $row['options_indexes'] = str_replace('0', $lng['panel']['no'], $row['options_indexes']); - $row['options_cgi'] = str_replace('1', $lng['panel']['yes'], $row['options_cgi']); - $row['options_cgi'] = str_replace('0', $lng['panel']['no'], $row['options_cgi']); - $row = \Froxlor\PhpHelper::htmlentitiesArray($row); - eval("\$htaccess.=\"" . \Froxlor\UI\Template::getTemplate("extras/htaccess_htaccess") . "\";"); - $count ++; + try { + $htaccess_list_data = include_once dirname(__FILE__) . '/lib/tablelisting/customer/tablelisting.htaccess.php'; + $list = (new \Froxlor\UI\Collection(\Froxlor\Api\Commands\DirOptions::class, $userinfo)) + ->withPagination($htaccess_list_data['htaccess_list']['columns']) + ->getList(); + } catch (Exception $e) { + \Froxlor\UI\Response::dynamic_error($e->getMessage()); } - eval("echo \"" . \Froxlor\UI\Template::getTemplate("extras/htaccess") . "\";"); + UI::twigBuffer('user/table.html.twig', [ + 'listing' => \Froxlor\UI\Listing::format($list, $htaccess_list_data['htaccess_list']), + ]); + UI::twigOutputBuffer(); } elseif ($action == 'delete' && $id != 0) { try { $json_result = DirOptions::getLocal($userinfo, array( @@ -363,7 +316,7 @@ if ($page == 'overview') { \Froxlor\UI\Response::standard_success('backupscheduled'); } else { - if (! empty($existing_backupJob)) { + if (!empty($existing_backupJob)) { $action = "abort"; $row = $existing_backupJob['data']; @@ -371,18 +324,19 @@ if ($page == 'overview') { $row['backup_web'] = ($row['backup_web'] == '1') ? $lng['panel']['yes'] : $lng['panel']['no']; $row['backup_mail'] = ($row['backup_mail'] == '1') ? $lng['panel']['yes'] : $lng['panel']['no']; $row['backup_dbs'] = ($row['backup_dbs'] == '1') ? $lng['panel']['yes'] : $lng['panel']['no']; - } - $pathSelect = \Froxlor\FileDir::makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid']); - $backup_data = include_once dirname(__FILE__) . '/lib/formfields/customer/extras/formfield.backup.php'; - $backup_form = \Froxlor\UI\HtmlForm::genHTMLForm($backup_data); - $title = $backup_data['backup']['title']; - $image = $backup_data['backup']['image']; - if (! empty($existing_backupJob)) { // overwrite backup_form after we took everything from it we needed eval("\$backup_form = \"" . \Froxlor\UI\Template::getTemplate("extras/backup_listexisting") . "\";"); } - eval("echo \"" . \Froxlor\UI\Template::getTemplate("extras/backup") . "\";"); + + $pathSelect = \Froxlor\FileDir::makePathfield($userinfo['documentroot'], $userinfo['guid'], $userinfo['guid']); + $backup_data = include_once dirname(__FILE__) . '/lib/formfields/customer/extras/formfield.backup.php'; + + UI::twigBuffer('user/form.html.twig', [ + 'formaction' => $linker->getLink(array('section' => 'extras')), + 'formdata' => $backup_data['backup'] + ]); + UI::twigOutputBuffer(); } } } else { diff --git a/lib/formfields/customer/extras/formfield.backup.php b/lib/formfields/customer/extras/formfield.backup.php index 13de0341..354202ae 100644 --- a/lib/formfields/customer/extras/formfield.backup.php +++ b/lib/formfields/customer/extras/formfield.backup.php @@ -17,7 +17,7 @@ return array( 'backup' => array( 'title' => $lng['extras']['backup'], - 'image' => 'icons/backup_big.png', + 'image' => 'fa-solid fa-server', 'sections' => array( 'section_a' => array( 'title' => $lng['extras']['backup'], @@ -33,8 +33,9 @@ return array( ), 'path_protection_info' => array( 'label' => $lng['extras']['path_protection_label'], - 'type' => 'label', - 'value' => $lng['extras']['path_protection_info'] + 'type' => 'infotext', + 'value' => $lng['extras']['path_protection_info'], + 'classes' => 'fw-bold text-danger' ), 'backup_web' => array( 'label' => $lng['extras']['backup_web'], diff --git a/lib/formfields/customer/extras/formfield.htaccess_add.php b/lib/formfields/customer/extras/formfield.htaccess_add.php index 7d44f488..0c17f77d 100644 --- a/lib/formfields/customer/extras/formfield.htaccess_add.php +++ b/lib/formfields/customer/extras/formfield.htaccess_add.php @@ -17,7 +17,7 @@ return array( 'htaccess_add' => array( 'title' => $lng['extras']['pathoptions_add'], - 'image' => 'icons/htpasswd_add.png', + 'image' => 'fa-solid fa-folder', 'sections' => array( 'section_a' => array( 'title' => $lng['extras']['pathoptions_add'], diff --git a/lib/formfields/customer/extras/formfield.htaccess_edit.php b/lib/formfields/customer/extras/formfield.htaccess_edit.php index bcf0879e..3f6788cc 100644 --- a/lib/formfields/customer/extras/formfield.htaccess_edit.php +++ b/lib/formfields/customer/extras/formfield.htaccess_edit.php @@ -17,7 +17,7 @@ return array( 'htaccess_edit' => array( 'title' => $lng['extras']['pathoptions_edit'], - 'image' => 'icons/htpasswd_edit.png', + 'image' => 'fa-solid fa-folder', 'sections' => array( 'section_a' => array( 'title' => $lng['extras']['pathoptions_edit'], diff --git a/lib/formfields/customer/extras/formfield.htpasswd_add.php b/lib/formfields/customer/extras/formfield.htpasswd_add.php index 6b4bce20..ab2d674c 100644 --- a/lib/formfields/customer/extras/formfield.htpasswd_add.php +++ b/lib/formfields/customer/extras/formfield.htpasswd_add.php @@ -17,7 +17,7 @@ return array( 'htpasswd_add' => array( 'title' => $lng['extras']['directoryprotection_add'], - 'image' => 'icons/htpasswd_add.png', + 'image' => 'fa-solid fa-lock', 'sections' => array( 'section_a' => array( 'title' => $lng['extras']['directoryprotection_add'], diff --git a/lib/formfields/customer/extras/formfield.htpasswd_edit.php b/lib/formfields/customer/extras/formfield.htpasswd_edit.php index 607ef682..2fe44227 100644 --- a/lib/formfields/customer/extras/formfield.htpasswd_edit.php +++ b/lib/formfields/customer/extras/formfield.htpasswd_edit.php @@ -17,7 +17,7 @@ return array( 'htpasswd_edit' => array( 'title' => $lng['extras']['directoryprotection_edit'], - 'image' => 'icons/htpasswd_edit.png', + 'image' => 'fa-solid fa-lock', 'sections' => array( 'section_a' => array( 'title' => $lng['extras']['directoryprotection_edit'], diff --git a/lib/tablelisting/customer/tablelisting.htaccess.php b/lib/tablelisting/customer/tablelisting.htaccess.php new file mode 100644 index 00000000..eab4b7ab --- /dev/null +++ b/lib/tablelisting/customer/tablelisting.htaccess.php @@ -0,0 +1,87 @@ + (2010-) + * @author Maurice Preuß + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Tabellisting + * + */ + +use Froxlor\UI\Callbacks\Ftp; +use Froxlor\UI\Callbacks\Text; +use Froxlor\UI\Listing; + +return [ + 'htaccess_list' => [ + 'title' => $lng['menue']['extras']['pathoptions'], + 'icon' => 'fa-solid fa-folder', + 'columns' => [ + 'path' => [ + 'label' => $lng['panel']['path'], + 'column' => 'path', + 'format_callback' => [Ftp::class, 'pathRelative'] + ], + 'option_indexes' => [ + 'label' => $lng['extras']['view_directory'], + 'column' => 'option_indexes', + 'format_callback' => [Text::class, 'boolean'] + ], + 'error404path' => [ + 'label' => $lng['extras']['error404path'], + 'column' => 'error404path' + ], + 'error403path' => [ + 'label' => $lng['extras']['error403path'], + 'column' => 'error403path' + ], + 'error500path' => [ + 'label' => $lng['extras']['error500path'], + 'column' => 'error500path' + ], + 'options_cgi' => [ + 'label' => $lng['extras']['execute_perl'], + 'column' => 'options_cgi', + 'format_callback' => [Text::class, 'boolean'], + 'visible' => $cperlenabled + ] + ], + 'visible_columns' => Listing::getVisibleColumnsForListing('htaccess_list', [ + 'path', + 'option_indexes', + 'error404path', + 'error403path', + 'error500path', + 'options_cgi' + ]), + 'actions' => [ + 'edit' => [ + 'icon' => 'fa fa-edit', + 'href' => [ + 'section' => 'extras', + 'page' => 'htaccess', + 'action' => 'edit', + 'id' => ':id' + ], + ], + 'delete' => [ + 'icon' => 'fa fa-trash', + 'class' => 'text-danger', + 'href' => [ + 'section' => 'extras', + 'page' => 'htaccess', + 'action' => 'delete', + 'id' => ':id' + ], + ] + ] + ] +]; diff --git a/lib/tablelisting/customer/tablelisting.htpasswd.php b/lib/tablelisting/customer/tablelisting.htpasswd.php new file mode 100644 index 00000000..7d2f1c66 --- /dev/null +++ b/lib/tablelisting/customer/tablelisting.htpasswd.php @@ -0,0 +1,63 @@ + (2010-) + * @author Maurice Preuß + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Tabellisting + * + */ + +use Froxlor\UI\Callbacks\Ftp; +use Froxlor\UI\Listing; + +return [ + 'htpasswd_list' => [ + 'title' => $lng['menue']['extras']['directoryprotection'], + 'icon' => 'fa-solid fa-lock', + 'columns' => [ + 'username' => [ + 'label' => $lng['login']['username'], + 'column' => 'username' + ], + 'path' => [ + 'label' => $lng['panel']['path'], + 'column' => 'path', + 'format_callback' => [Ftp::class, 'pathRelative'] + ] + ], + 'visible_columns' => Listing::getVisibleColumnsForListing('htpasswd_list', [ + 'username', + 'path' + ]), + 'actions' => [ + 'edit' => [ + 'icon' => 'fa fa-edit', + 'href' => [ + 'section' => 'extras', + 'page' => 'htpasswds', + 'action' => 'edit', + 'id' => ':id' + ], + ], + 'delete' => [ + 'icon' => 'fa fa-trash', + 'class' => 'text-danger', + 'href' => [ + 'section' => 'extras', + 'page' => 'htpasswds', + 'action' => 'delete', + 'id' => ':id' + ], + ] + ] + ] +]; diff --git a/lng/english.lng.php b/lng/english.lng.php index 71eed37c..ecec69dc 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1893,8 +1893,8 @@ $lng['crondesc']['cron_backup'] = 'Process backup jobs'; $lng['error']['backupfunctionnotenabled'] = 'The backup function is not enabled'; $lng['serversettings']['backupenabled']['title'] = "Enable backup for customers"; $lng['serversettings']['backupenabled']['description'] = "If activated, the customer will be able to schedule backup jobs (cron-backup) which generates an archive within his docroot (subdirectory chosable by customer)"; -$lng['extras']['path_protection_label'] = 'Important'; -$lng['extras']['path_protection_info'] = 'We strongly recommend protecting the given path, see "Extras" -> "Directory protection"'; +$lng['extras']['path_protection_label'] = 'Important'; +$lng['extras']['path_protection_info'] = 'We strongly recommend protecting the given path, see "Extras" -> "Directory protection"'; $lng['tasks']['CREATE_CUSTOMER_BACKUP'] = 'Backup job for customer %loginname%'; $lng['error']['dns_domain_nodns'] = 'DNS is not enabled for this domain'; diff --git a/lng/german.lng.php b/lng/german.lng.php index badb40e6..286585d0 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1543,8 +1543,8 @@ $lng['crondesc']['cron_backup'] = 'Ausstehende Sicherungen erstellen'; $lng['error']['backupfunctionnotenabled'] = 'Die Sicherungs-Funktion is nicht aktiviert'; $lng['serversettings']['backupenabled']['title'] = "Backup für Kunden aktivieren"; $lng['serversettings']['backupenabled']['description'] = "Wenn dies aktiviert ist, kann der Kunde Sicherungen planen (cron-backup) welche ein Archiv in sein Heimatverzeichnis ablegt (Unterordner vom Kunden wählbar)"; -$lng['extras']['path_protection_label'] = 'Wichtig'; -$lng['extras']['path_protection_info'] = 'Wir raten dringend dazu den angegebenen Pfad zu schützen, siehe "Extras" -> "Verzeichnisschutz"'; +$lng['extras']['path_protection_label'] = 'Wichtig'; +$lng['extras']['path_protection_info'] = 'Wir raten dringend dazu den angegebenen Pfad zu schützen, siehe "Extras" -> "Verzeichnisschutz"'; $lng['tasks']['CREATE_CUSTOMER_BACKUP'] = 'Datensicherung für Kunde %loginname%'; $lng['error']['dns_domain_nodns'] = 'DNS ist für diese Domain nicht aktiviert'; diff --git a/templates/Froxlor/form/formfields.html.twig b/templates/Froxlor/form/formfields.html.twig index 08920022..2d6d341e 100644 --- a/templates/Froxlor/form/formfields.html.twig +++ b/templates/Froxlor/form/formfields.html.twig @@ -6,7 +6,7 @@ {% if field.desc is defined and field.desc is not empty %}
{{ field.desc|raw }} {% endif %} -
+
{% endif %} {% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' or field.type == 'email' or field.type == 'hidden' %} {{ _self.input(id, field) }} @@ -24,6 +24,8 @@ {{ _self.link(id, field) }} {% elseif field.type == 'itemlist' %} {{ _self.itemlist(id, field) }} + {% elseif field.type == 'infotext' %} + {{ _self.infotext(id, field) }} {% endif %} {% if norow == false and field.type != 'hidden' %}
@@ -49,6 +51,22 @@ {% endif %} {% endmacro %} +{% macro infotext(id, field) %} + {% if field.next_to is defined %} +
+ {% endif %} + {{ field.value }} + {% if field.next_to is defined %} + {% for nid, nfield in field.next_to %} + {% if nfield.next_to_prefix is defined %} + {{ nfield.next_to_prefix }} + {% endif %} + {{ _self.fieldrow(nid, nfield, true) }} + {% endfor %} +
+ {% endif %} +{% endmacro %} + {% macro plain(id, field) %} {% if field.next_to is defined %}
@@ -74,7 +92,7 @@ {% endif %} {% if field.note is defined and field.note is not empty %} -
{{ field.note|raw }}
+
{{ field.note|raw }}
{% endif %} {% if field.next_to is defined %} {% for nid, nfield in field.next_to %}