From 0dc77997feee46e25da8287e7f374a3d36554dac Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Fri, 29 Apr 2022 09:36:46 +0200 Subject: [PATCH] more language cleanup and adding mysql-servers to customer add/delete in UI Signed-off-by: Michael Kaufmann --- admin_customers.php | 31 ++++++++++- lib/Froxlor/Ajax/Ajax.php | 52 ------------------- lib/Froxlor/System/Cronjob.php | 22 +++----- lib/Froxlor/UI/Callbacks/Domain.php | 8 +-- lib/Froxlor/UI/Callbacks/PHPConf.php | 8 +-- lib/Froxlor/UI/Callbacks/ProgressBar.php | 5 +- lib/Froxlor/UI/Callbacks/Text.php | 6 +-- lib/Froxlor/UI/Listing.php | 2 +- lib/Froxlor/UI/Panel/FroxlorTwig.php | 4 +- lib/Froxlor/UI/Panel/UI.php | 35 ------------- .../admin/customer/formfield.customer_add.php | 8 +++ .../customer/formfield.customer_edit.php | 8 +++ lng/de.lng.php | 9 ++-- lng/en.lng.php | 9 ++-- lng/it.lng.php | 4 +- lng/nl.lng.php | 4 +- 16 files changed, 84 insertions(+), 131 deletions(-) diff --git a/admin_customers.php b/admin_customers.php index 3a52c451..b3de82b5 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -27,7 +27,8 @@ const AREA = 'admin'; require __DIR__ . '/lib/init.php'; use Froxlor\Api\Commands\Admins; -use Froxlor\Api\Commands\Customers as Customers; +use Froxlor\Api\Commands\Customers; +use Froxlor\Api\Commands\MysqlServer; use Froxlor\CurrentUser; use Froxlor\Database\Database; use Froxlor\Froxlor; @@ -175,6 +176,20 @@ if ($page == 'customers' && $userinfo['customers'] != '0') { 'page' => $page ]); } else { + $mysql_servers = []; + try { + $result_json = MysqlServer::getLocal($userinfo)->listing(); + $result_decoded = json_decode($result_json, true)['data']['list']; + foreach ($result_decoded as $dbserver => $dbdata) { + $mysql_servers[] = [ + 'label' => $dbdata['caption'], + 'value' => $dbserver + ]; + } + } catch (Exception $e) { + /* just none */ + } + $phpconfigs = []; $configs = Database::query(" SELECT c.*, fc.description as interpreter @@ -244,6 +259,20 @@ if ($page == 'customers' && $userinfo['customers'] != '0') { $result = PhpHelper::htmlentitiesArray($result); + $mysql_servers = []; + try { + $result_json = MysqlServer::getLocal($userinfo)->listing(); + $result_decoded = json_decode($result_json, true)['data']['list']; + foreach ($result_decoded as $dbserver => $dbdata) { + $mysql_servers[] = [ + 'label' => $dbdata['caption'], + 'value' => $dbserver + ]; + } + } catch (Exception $e) { + /* just none */ + } + $phpconfigs = []; $configs = Database::query(" SELECT c.*, fc.description as interpreter diff --git a/lib/Froxlor/Ajax/Ajax.php b/lib/Froxlor/Ajax/Ajax.php index 677ece83..10fdc171 100644 --- a/lib/Froxlor/Ajax/Ajax.php +++ b/lib/Froxlor/Ajax/Ajax.php @@ -46,7 +46,6 @@ class Ajax protected string $action; protected string $theme; protected array $userinfo; - protected array $lng; /** * @throws Exception @@ -67,8 +66,6 @@ class Ajax { $this->userinfo = $this->getValidatedSession(); - $this->initLang(); - switch ($this->action) { case 'newsfeed': return $this->getNewsfeed(); @@ -100,55 +97,6 @@ class Ajax return CurrentUser::getData(); } - /** - * initialize global $lng variable to have - * localized strings available for the ApiCommands - */ - private function initLang() - { - global $lng; - - // query the whole table - $result_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_LANGUAGE . "`"); - - $langs = []; - // presort languages - while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { - $langs[$row['language']][] = $row; - } - - // set default language before anything else to - // ensure that we can display messages - $language = Settings::Get('panel.standardlanguage'); - - if (isset($this->userinfo['language']) && isset($langs[$this->userinfo['language']])) { - // default: use language from session, #277 - $language = $this->userinfo['language']; - } elseif (isset($this->userinfo['def_language'])) { - $language = $this->userinfo['def_language']; - } - - // include every english language file we can get - foreach ($langs['English'] as $value) { - include_once FileDir::makeSecurePath(Froxlor::getInstallDir() . '/' . $value['file']); - } - - // now include the selected language if its not english - if ($language != 'English') { - if (isset($langs[$language])) { - foreach ($langs[$language] as $value) { - include_once FileDir::makeSecurePath(Froxlor::getInstallDir() . '/' . $value['file']); - } - } - } - - // last but not least include language references file - include_once FileDir::makeSecurePath(Froxlor::getInstallDir() . '/lng/lng_references.php'); - - // set array - $this->lng = $lng; - } - /** * @throws Exception */ diff --git a/lib/Froxlor/System/Cronjob.php b/lib/Froxlor/System/Cronjob.php index 0f1dae13..43642442 100644 --- a/lib/Froxlor/System/Cronjob.php +++ b/lib/Froxlor/System/Cronjob.php @@ -225,15 +225,13 @@ class Cronjob */ public static function getCronjobsLastRun() { - global $lng; - $query = "SELECT `lastrun`, `desc_lng_key` FROM `" . TABLE_PANEL_CRONRUNS . "` WHERE `isactive` = '1' ORDER BY `cronfile` ASC"; $result = Database::query($query); $cronjobs_last_run = []; while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $cronjobs_last_run[] = [ - 'title' => $lng['crondesc'][$row['desc_lng_key']], + 'title' => lng('crondesc.' . $row['desc_lng_key']), 'lastrun' => $row['lastrun'] ]; } @@ -261,8 +259,6 @@ class Cronjob */ public static function getOutstandingTasks() { - global $lng; - $query = "SELECT * FROM `" . TABLE_PANEL_TASKS . "` ORDER BY `type` ASC"; $result = Database::query($query); @@ -275,21 +271,20 @@ class Cronjob $task_id = $row['type']; if (TaskId::isValid($task_id)) { $task_constname = TaskId::convertToConstant($task_id); - $task = [ - 'desc' => isset($lng['tasks'][$task_constname]) ? $lng['tasks'][$task_constname] : $task_constname - ]; + $lngParams = []; if (is_array($row['data'])) { // task includes loginname if (isset($row['data']['loginname'])) { - $loginname = $row['data']['loginname']; - $task['desc'] = str_replace('%loginname%', $loginname, $task['desc']); + $lngParams = [$row['data']['loginname']]; } // task includes domain data if (isset($row['data']['domain'])) { - $domain = $row['data']['domain']; - $task['desc'] = str_replace('%domain%', $domain, $task['desc']); + $lngParams = [$row['data']['domain']]; } } + $task = [ + 'desc' => lng('tasks.' . $task_constname, $lngParams) + ]; } else { // unknown $task = ['desc' => "ERROR: Unknown task type '" . $row['type'] . "'"]; @@ -299,10 +294,9 @@ class Cronjob } if (empty($tasks)) { - $tasks = [['desc' => $lng['tasks']['noneoutstanding']]]; + $tasks = [['desc' => lng('tasks.noneoutstanding')]]; } - $text = $lng['tasks']['outstanding_tasks']; return $tasks; } diff --git a/lib/Froxlor/UI/Callbacks/Domain.php b/lib/Froxlor/UI/Callbacks/Domain.php index ad72856f..b49a1446 100644 --- a/lib/Froxlor/UI/Callbacks/Domain.php +++ b/lib/Froxlor/UI/Callbacks/Domain.php @@ -67,7 +67,7 @@ class Domain return $attributes['fields']['documentroot']; } } - return UI::getLng('domains.aliasdomain') . ' ' . $attributes['fields']['aliasdomain']; + return lng('domains.aliasdomain') . ' ' . $attributes['fields']['aliasdomain']; } public static function domainExternalLinkInfo(array $attributes) @@ -79,13 +79,13 @@ class Domain if (Settings::Get('system.awstats_enabled') == '1') { $statsapp = 'awstats'; } - $result .= ' '; + $result .= ' '; } if ($attributes['fields']['registration_date'] != '') { - $result .= '
' . UI::getLng('domains.registration_date') . ': ' . $attributes['fields']['registration_date'] . ''; + $result .= '
' . lng('domains.registration_date') . ': ' . $attributes['fields']['registration_date'] . ''; } if ($attributes['fields']['termination_date'] != '') { - $result .= '
' . UI::getLng('domains.termination_date_overview') . ': ' . $attributes['fields']['termination_date'] . ''; + $result .= '
' . lng('domains.termination_date_overview') . ': ' . $attributes['fields']['termination_date'] . ''; } return $result; } diff --git a/lib/Froxlor/UI/Callbacks/PHPConf.php b/lib/Froxlor/UI/Callbacks/PHPConf.php index 28ac3d94..211fe6dc 100644 --- a/lib/Froxlor/UI/Callbacks/PHPConf.php +++ b/lib/Froxlor/UI/Callbacks/PHPConf.php @@ -39,9 +39,9 @@ class PHPConf $domains .= $idna->decode($configdomain) . "
"; } if ($subdomains_count == 0 && empty($domains)) { - $domains = UI::getLng('admin.phpsettings.notused'); + $domains = lng('admin.phpsettings.notused'); } else { - $domains .= !empty($subdomains_count) ? ((!empty($domains) ? '+ ' : '') . $subdomains_count . ' ' . UI::getLng('customer.subdomains')) : ''; + $domains .= !empty($subdomains_count) ? ((!empty($domains) ? '+ ' : '') . $subdomains_count . ' ' . lng('customer.subdomains')) : ''; } return $domains; @@ -75,8 +75,8 @@ class PHPConf 'href' => $linker->getLink([ 'section' => 'phpsettings', 'page' => 'fpmdaemons', - 'action' => 'edit', - 'id' => $attributes['fields']['fpmsettingid'], + 'searchfield' => 'id', + 'searchtext' => $attributes['fields']['fpmsettingid'], ]), ] ]; diff --git a/lib/Froxlor/UI/Callbacks/ProgressBar.php b/lib/Froxlor/UI/Callbacks/ProgressBar.php index 64b24fcb..f1c216c3 100644 --- a/lib/Froxlor/UI/Callbacks/ProgressBar.php +++ b/lib/Froxlor/UI/Callbacks/ProgressBar.php @@ -27,7 +27,6 @@ namespace Froxlor\UI\Callbacks; use Froxlor\PhpHelper; use Froxlor\Settings; -use Froxlor\UI\Panel\UI; class ProgressBar { @@ -41,7 +40,7 @@ class ProgressBar { $infotext = null; if (isset($attributes['fields']['webspace_used']) && isset($attributes['fields']['mailspace_used']) && isset($attributes['fields']['dbspace_used'])) { - $infotext = UI::getLng('panel.used') . ':' . PHP_EOL; + $infotext = lng('panel.used') . ':' . PHP_EOL; $infotext .= 'web: ' . PhpHelper::sizeReadable($attributes['fields']['webspace_used'] * 1024, null, 'bi') . PHP_EOL; $infotext .= 'mail: ' . PhpHelper::sizeReadable($attributes['fields']['mailspace_used'] * 1024, null, 'bi') . PHP_EOL; $infotext .= 'mysql: ' . PhpHelper::sizeReadable($attributes['fields']['dbspace_used'] * 1024, null, 'bi'); @@ -57,7 +56,7 @@ class ProgressBar { $percent = 0; $style = 'bg-primary'; - $text = PhpHelper::sizeReadable($attributes[$field . '_used'] * $size_factor, null, 'bi') . ' / ' . UI::getLng('panel.unlimited'); + $text = PhpHelper::sizeReadable($attributes[$field . '_used'] * $size_factor, null, 'bi') . ' / ' . lng('panel.unlimited'); if ((int)$attributes[$field] >= 0) { if (($attributes[$field] / 100) * $report_max < $attributes[$field . '_used']) { $style = 'bg-danger'; diff --git a/lib/Froxlor/UI/Callbacks/Text.php b/lib/Froxlor/UI/Callbacks/Text.php index ab2762b9..d1a30030 100644 --- a/lib/Froxlor/UI/Callbacks/Text.php +++ b/lib/Froxlor/UI/Callbacks/Text.php @@ -52,17 +52,17 @@ class Text public static function timestamp(array $attributes): string { - return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : UI::getLng('panel.never'); + return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : lng('panel.never'); } public static function timestampUntil(array $attributes): string { - return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : UI::getLng('panel.unlimited'); + return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : lng('panel.unlimited'); } public static function crondesc(array $attributes): string { - return UI::getLng('crondesc.' . $attributes['data']); + return lng('crondesc.' . $attributes['data']); } public static function shorten(array $attributes): string diff --git a/lib/Froxlor/UI/Listing.php b/lib/Froxlor/UI/Listing.php index bc97f769..ad330029 100644 --- a/lib/Froxlor/UI/Listing.php +++ b/lib/Froxlor/UI/Listing.php @@ -74,7 +74,7 @@ class Listing // Table headings for actions if (isset($tabellisting['actions'])) { $heading['actions'] = [ - 'text' => UI::getLng('panel.options'), + 'text' => lng('panel.options'), 'class' => 'text-end', ]; } diff --git a/lib/Froxlor/UI/Panel/FroxlorTwig.php b/lib/Froxlor/UI/Panel/FroxlorTwig.php index 6c243a6d..e98e4568 100644 --- a/lib/Froxlor/UI/Panel/FroxlorTwig.php +++ b/lib/Froxlor/UI/Panel/FroxlorTwig.php @@ -125,9 +125,9 @@ class FroxlorTwig extends AbstractExtension return Settings::Get($setting); } - public function getLang($identifier = null) + public function getLang($identifier = null, array $arguments = []) { - return UI::getLng($identifier); + return lng($identifier, $arguments); } public function getLink($linkopts) diff --git a/lib/Froxlor/UI/Panel/UI.php b/lib/Froxlor/UI/Panel/UI.php index d3a4f14c..92f45f64 100644 --- a/lib/Froxlor/UI/Panel/UI.php +++ b/lib/Froxlor/UI/Panel/UI.php @@ -56,13 +56,6 @@ class UI */ private static $twigbuf = []; - /** - * language strigs array - * - * @var array - */ - private static $lng = []; - /** * linker class object */ @@ -212,34 +205,6 @@ class UI return self::$userinfo; } - public static function getLng($identifier, $context = null) - { - $id = explode(".", $identifier); - if (is_null($context)) { - $id_first = array_shift($id); - if (!isset(self::$lng[$id_first])) { - return null; - } - if (empty($id)) { - return self::$lng[$id_first]; - } else { - return self::getLng(implode(".", $id), self::$lng[$id_first]); - } - } else { - $id_first = array_shift($id); - if (empty($id)) { - return isset($context[$id_first]) ? $context[$id_first] : null; - } else { - return self::getLng(implode(".", $id), $context[$id_first]); - } - } - } - - public static function setLng($lng = []) - { - self::$lng = $lng; - } - /** * returns an array of available themes * diff --git a/lib/formfields/admin/customer/formfield.customer_add.php b/lib/formfields/admin/customer/formfield.customer_add.php index 8934fc94..5fc508e7 100644 --- a/lib/formfields/admin/customer/formfield.customer_add.php +++ b/lib/formfields/admin/customer/formfield.customer_add.php @@ -256,6 +256,14 @@ return [ 'maxlength' => 9, 'mandatory' => true ], + 'allowed_mysqlserver' => [ + 'visible' => count($mysql_servers) > 1, + 'label' => lng('customer.mysqlserver'), + 'type' => 'checkbox', + 'values' => $mysql_servers, + 'value' => [0], + 'is_array' => 1 + ], 'phpenabled' => [ 'label' => lng('admin.phpenabled') . '?', 'type' => 'checkbox', diff --git a/lib/formfields/admin/customer/formfield.customer_edit.php b/lib/formfields/admin/customer/formfield.customer_edit.php index 435bc026..9a662ac0 100644 --- a/lib/formfields/admin/customer/formfield.customer_edit.php +++ b/lib/formfields/admin/customer/formfield.customer_edit.php @@ -268,6 +268,14 @@ return [ 'maxlength' => 9, 'mandatory' => true ], + 'allowed_mysqlserver' => [ + 'visible' => count($mysql_servers) > 1, + 'label' => lng('customer.mysqlserver'), + 'type' => 'checkbox', + 'values' => $mysql_servers, + 'value' => isset($result['allowed_mysqlserver']) && !empty($result['allowed_mysqlserver']) ? json_decode($result['allowed_phpconfigs'], JSON_OBJECT_AS_ARRAY) : [], + 'is_array' => 1 + ], 'phpenabled' => [ 'label' => lng('admin.phpenabled') . '?', 'type' => 'checkbox', diff --git a/lng/de.lng.php b/lng/de.lng.php index 05543c07..9642e7b7 100644 --- a/lng/de.lng.php +++ b/lng/de.lng.php @@ -545,6 +545,7 @@ return [ ], 'selectserveralias_addinfo' => 'Diese Option steht beim Bearbeiten der Domain zur Verfügung. Als Initial-Wert wird die Einstellung der Hauptdomain vererbt.', 'total_diskspace' => 'Gesamtspeicherplatz', + 'mysqlserver' => 'Erlaubte MySQL-Server', ], 'diskquota' => 'Quota', 'dkim' => [ @@ -2013,18 +2014,18 @@ Vielen Dank, Ihr Administrator', 'tasks' => [ 'outstanding_tasks' => 'Ausstehende Cron-Aufgaben', 'REBUILD_VHOST' => 'Neuerstellung der Webserver-Konfiguration', - 'CREATE_HOME' => 'Erstelle neuen Kunden %loginname%', + 'CREATE_HOME' => 'Erstelle neuen Kunden %s', 'REBUILD_DNS' => 'Neuerstellung der Bind-Konfiguration', 'CREATE_FTP' => 'Erstelle Verzeichnis für neuen FTP-Benutzer', - 'DELETE_CUSTOMER_FILES' => 'Löschen von Kunden-Dateien %loginname%', + 'DELETE_CUSTOMER_FILES' => 'Löschen von Kunden-Dateien %s', 'noneoutstanding' => 'Zur Zeit gibt es keine ausstehenden Aufgaben für Froxlor', 'CREATE_QUOTA' => 'Quota auf dem Dateisystem setzen', 'DELETE_EMAIL_DATA' => 'E-Mail-Dateien des Kunden löschen', 'DELETE_FTP_DATA' => 'Kunden FTP-Konto Dateien löschen', 'REBUILD_CRON' => 'Neuerstellung der cron.d-Datei', - 'CREATE_CUSTOMER_BACKUP' => 'Datensicherung für Kunde %loginname%', + 'CREATE_CUSTOMER_BACKUP' => 'Datensicherung für Kunde %s', 'DELETE_DOMAIN_PDNS' => 'Lösche Domain %domain% von PowerDNS Datenbank', - 'DELETE_DOMAIN_SSL' => 'Lösche SSL Dateien von Domain %domain%', + 'DELETE_DOMAIN_SSL' => 'Lösche SSL Dateien von Domain %s', ], 'terms' => 'AGB', 'traffic' => [ diff --git a/lng/en.lng.php b/lng/en.lng.php index dc95643f..c61cef6b 100644 --- a/lng/en.lng.php +++ b/lng/en.lng.php @@ -838,6 +838,7 @@ return [ ], 'selectserveralias_addinfo' => 'This option can be set when editing the domain. Its initial value is inherited from the parent-domain.', 'total_diskspace' => 'Total diskspace', + 'mysqlserver' => 'Usable mysql-server', ], 'diskquota' => 'Quota', 'dkim' => [ @@ -2367,18 +2368,18 @@ Yours sincerely, your administrator', 'tasks' => [ 'outstanding_tasks' => 'Outstanding cron-tasks', 'REBUILD_VHOST' => 'Rebuilding webserver-configuration', - 'CREATE_HOME' => 'Adding new customer %loginname%', + 'CREATE_HOME' => 'Adding new customer %s', 'REBUILD_DNS' => 'Rebuilding bind-configuration', 'CREATE_FTP' => 'Creating directory for new ftp-user', - 'DELETE_CUSTOMER_FILES' => 'Deleting customer-files %loginname%', + 'DELETE_CUSTOMER_FILES' => 'Deleting customer-files %s', 'noneoutstanding' => 'There are currently no outstanding tasks for Froxlor', 'CREATE_QUOTA' => 'Set quota on filesystem', 'DELETE_EMAIL_DATA' => 'Delete customer e-mail data.', 'DELETE_FTP_DATA' => 'Delete customer ftp-account data.', 'REBUILD_CRON' => 'Rebuilding the cron.d-file', - 'CREATE_CUSTOMER_BACKUP' => 'Backup job for customer %loginname%', + 'CREATE_CUSTOMER_BACKUP' => 'Backup job for customer %s', 'DELETE_DOMAIN_PDNS' => 'Delete domain %domain% from PowerDNS database', - 'DELETE_DOMAIN_SSL' => 'Delete ssl files of domain %domain%', + 'DELETE_DOMAIN_SSL' => 'Delete ssl files of domain %s', ], 'terms' => 'Terms of use', 'traffic' => [ diff --git a/lng/it.lng.php b/lng/it.lng.php index 350c284a..be4b1d24 100644 --- a/lng/it.lng.php +++ b/lng/it.lng.php @@ -1751,10 +1751,10 @@ Nota: Perfavore sii sicuro di usare lo stesso nome di file come per il cr 'tasks' => [ 'outstanding_tasks' => 'Processi Cron in sospeso', 'REBUILD_VHOST' => 'Ricostruzione della configurazione del webserver', - 'CREATE_HOME' => 'Aggiunto il nuovo cliente %loginname%', + 'CREATE_HOME' => 'Aggiunto il nuovo cliente %s', 'REBUILD_DNS' => 'Ricostruzione della configurazione di bind', 'CREATE_FTP' => 'Creazione delle cartelle per i nuovi utenti ftp', - 'DELETE_CUSTOMER_FILES' => 'Eliminazione dei file del cliente %loginname%', + 'DELETE_CUSTOMER_FILES' => 'Eliminazione dei file del cliente %s', 'noneoutstanding' => 'Attualmente non ci sono processi in sospeso per Froxlor', 'CREATE_QUOTA' => 'Setta quota al filesystem', 'DELETE_EMAIL_DATA' => 'Elimina i dati di posta elettronica del cliente.', diff --git a/lng/nl.lng.php b/lng/nl.lng.php index aabc7288..426b3d25 100644 --- a/lng/nl.lng.php +++ b/lng/nl.lng.php @@ -1115,10 +1115,10 @@ Met vriendelijke groet, uw beheerder', 'tasks' => [ 'outstanding_tasks' => 'Uitstaande cron-taken', 'REBUILD_VHOST' => 'Bezig met opnieuw opbouwen van de configuratie van de webserver', - 'CREATE_HOME' => 'Klant met naam %loginname% wordt toegevoegd', + 'CREATE_HOME' => 'Klant met naam %s wordt toegevoegd', 'REBUILD_DNS' => 'Opnieuw opbouwen bind-configuratie', 'CREATE_FTP' => 'Map aanmaken voor nieuwe FTP-gebruiker', - 'DELETE_CUSTOMER_FILES' => 'Verwijderen klantbestanden van %loginname%', + 'DELETE_CUSTOMER_FILES' => 'Verwijderen klantbestanden van %s', 'noneoutstanding' => 'Er zijn op dit moment geen uitstaande taken voor Froxlor', ], 'traffic' => [