more language cleanup and adding mysql-servers to customer add/delete in UI

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-29 09:36:46 +02:00
parent fe747b321c
commit 0dc77997fe
16 changed files with 84 additions and 131 deletions

View File

@@ -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

View File

@@ -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
*/

View File

@@ -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;
}

View File

@@ -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 .= ' <a href="http://' . $attributes['data'] . '/' . $statsapp . '" rel="external" title="' . UI::getLng('domains.statstics') . '"><i class="fa-solid fa-chart-line text-secondary"></i></a>';
$result .= ' <a href="http://' . $attributes['data'] . '/' . $statsapp . '" rel="external" title="' . lng('domains.statstics') . '"><i class="fa-solid fa-chart-line text-secondary"></i></a>';
}
if ($attributes['fields']['registration_date'] != '') {
$result .= '<br><small>' . UI::getLng('domains.registration_date') . ': ' . $attributes['fields']['registration_date'] . '</small>';
$result .= '<br><small>' . lng('domains.registration_date') . ': ' . $attributes['fields']['registration_date'] . '</small>';
}
if ($attributes['fields']['termination_date'] != '') {
$result .= '<br><small>' . UI::getLng('domains.termination_date_overview') . ': ' . $attributes['fields']['termination_date'] . '</small>';
$result .= '<br><small>' . lng('domains.termination_date_overview') . ': ' . $attributes['fields']['termination_date'] . '</small>';
}
return $result;
}

View File

@@ -39,9 +39,9 @@ class PHPConf
$domains .= $idna->decode($configdomain) . "<br>";
}
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'],
]),
]
];

View File

@@ -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';

View File

@@ -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

View File

@@ -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',
];
}

View File

@@ -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)

View File

@@ -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
*

View File

@@ -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',

View File

@@ -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',

View File

@@ -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' => [

View File

@@ -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' => [

View File

@@ -1751,10 +1751,10 @@ Nota: Perfavore <b>sii sicuro</b> 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.',

View File

@@ -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' => [