Skip to content

Commit

Permalink
make unconfigured/unknown domain page a file-template
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Nov 26, 2023
1 parent 75cf44a commit 735ef85
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 44 deletions.
10 changes: 0 additions & 10 deletions actions/admin/settings/120.system.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@
'default' => false,
'save_method' => 'storeSettingField'
],
'system_index_file_extension' => [
'label' => lng('serversettings.index_file_extension'),
'settinggroup' => 'system',
'varname' => 'index_file_extension',
'type' => 'text',
'string_regexp' => '/^[a-zA-Z0-9]{1,6}$/',
'default' => 'html',
'save_method' => 'storeSettingField',
'advanced_mode' => true
],
'system_store_index_file_subs' => [
'label' => lng('serversettings.system_store_index_file_subs'),
'settinggroup' => 'system',
Expand Down
3 changes: 2 additions & 1 deletion admin_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
}

$file_templates = [
'index_html'
'index_html',
'unconfigured_html'
];

$languages = Language::getLanguages();
Expand Down
3 changes: 1 addition & 2 deletions install/froxlor.sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@
('system', 'mod_fcgid_wrapper', '1'),
('system', 'mod_fcgid_starter', '0'),
('system', 'mod_fcgid_peardir', '/usr/share/php/:/usr/share/php5/'),
('system', 'index_file_extension', 'html'),
('system', 'mod_fcgid_maxrequests', '250'),
('system', 'ssl_key_file','/etc/ssl/froxlor_selfsigned.key'),
('system', 'ssl_ca_file', ''),
Expand Down Expand Up @@ -728,7 +727,7 @@
('panel', 'settings_mode', '0'),
('panel', 'menu_collapsed', '1'),
('panel', 'version', '2.1.0-rc2'),
('panel', 'db_version', '202305240');
('panel', 'db_version', '202311260');
DROP TABLE IF EXISTS `panel_tasks`;
Expand Down
15 changes: 15 additions & 0 deletions install/updates/froxlor/update_2.1.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@

Froxlor::updateToVersion('2.1.0-rc2');
}

if (Froxlor::isDatabaseVersion('202305240')) {

Update::showUpdateStep("Adjusting file-template file extension setttings");
$current_fileextension = Settings::Get('system.index_file_extension');
Database::query("DELETE FROM `" . TABLE_PANEL_SETTINGS . "` WHERE `settinggroup`= 'system' AND `varname`= 'index_file_extension'");
Database::query("ALTER TABLE `" . TABLE_PANEL_TEMPLATES . "` ADD `file_extension` varchar(50) NOT NULL default 'html';");
if (strtolower(trim($current_fileextension)) != 'html') {
$stmt = Database::prepare("UPDATE TABLE `" . TABLE_PANEL_TEMPLATES . "` SET `file_extension` = :ext WHERE `templategroup` = 'files'");
Database::pexecute($stmt, ['ext' => strtolower(trim($current_fileextension))]);
}
Update::lastStepStatus(0);

Froxlor::updateToDbVersion('202311260');
}
36 changes: 33 additions & 3 deletions lib/Froxlor/FileDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,36 @@ public static function safe_exec(string $exec_string, &$return_value = false, $a
return $return;
}

/**
* Read unconfigured-domain template from database if exists or fallback to default
*
* @param string $servername
*
* @return string
*/
public static function getUnknownDomainTemplate(string $servername = "")
{
$result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_TEMPLATES . "` WHERE `templategroup` = 'files' AND `varname` = 'unconfigured_html'
");
Database::pexecute($result_stmt);
if (Database::num_rows() > 0) {
$template = $result_stmt->fetch(PDO::FETCH_ASSOC);
$replace_arr = [
'SERVERNAME' => $servername,
];
$tpl_content = PhpHelper::replaceVariables($template['value'], $replace_arr);
} else {
$unconfiguredPath = FileDir::makeCorrectFile(Froxlor::getInstallDir() . '/templates/misc/unconfigured/index.html');
if (file_exists($unconfiguredPath)) {
$tpl_content = file_get_contents($unconfiguredPath);
} else {
$tpl_content = lng('admin.templates.unconfigured_content_fallback');
}
}
return $tpl_content;
}

/**
* store the default index-file in a given destination folder
*
Expand All @@ -277,7 +307,7 @@ public static function storeDefaultIndex(
{
if ($force || (int)Settings::Get('system.store_index_file_subs') == 1) {
$result_stmt = Database::prepare("
SELECT `t`.`value`, `c`.`email` AS `customer_email`, `a`.`email` AS `admin_email`, `c`.`loginname` AS `customer_login`, `a`.`loginname` AS `admin_login`
SELECT `t`.`value`, `t`.`file_extension`, `c`.`email` AS `customer_email`, `a`.`email` AS `admin_email`, `c`.`loginname` AS `customer_login`, `a`.`loginname` AS `admin_login`
FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` INNER JOIN `" . TABLE_PANEL_ADMINS . "` AS `a`
ON `c`.`adminid` = `a`.`adminid`
INNER JOIN `" . TABLE_PANEL_TEMPLATES . "` AS `t`
Expand All @@ -300,15 +330,15 @@ public static function storeDefaultIndex(

// replaceVariables
$htmlcontent = PhpHelper::replaceVariables($template['value'], $replace_arr);
$indexhtmlpath = self::makeCorrectFile($destination . '/index.' . Settings::Get('system.index_file_extension'));
$indexhtmlpath = self::makeCorrectFile($destination . '/index.' . $template['file_extension']);
$index_html_handler = fopen($indexhtmlpath, 'w');
fwrite($index_html_handler, $htmlcontent);
fclose($index_html_handler);
if ($logger !== null) {
$logger->logAction(
FroxlorLogger::CRON_ACTION,
LOG_NOTICE,
'Creating \'index.' . Settings::Get('system.index_file_extension') . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)
'Creating \'index.' . $template['file_extension'] . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)
);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Froxlor/Froxlor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class Froxlor
const VERSION = '2.1.0-rc2';

// Database version (YYYYMMDDC where C is a daily counter)
const DBVERSION = '202305240';
const DBVERSION = '202311260';

// Distribution branding-tag (used for Debian etc.)
const BRANDING = '';
Expand Down
11 changes: 10 additions & 1 deletion lib/formfields/admin/templates/formfield.filetemplate_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@
'type' => 'select',
'select_var' => $free_templates
],
'file_extension' => [
'label' => lng('admin.templates.file_extension'),
'type' => 'text',
'string_regexp' => '/^[a-zA-Z0-9]{1,6}$/',
'default' => 'html',
'value' => 'html',
'mandatory' => true
],
'filecontent' => [
'label' => lng('admin.templates.filecontent'),
'type' => 'textarea',
'cols' => 60,
'rows' => 12
'rows' => 12,
'mandatory' => true
],
'filesend' => [
'type' => 'hidden',
Expand Down
11 changes: 10 additions & 1 deletion lib/formfields/admin/templates/formfield.filetemplate_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@
'value' => lng('admin.templates.' . $row['varname']),
'display' => lng('admin.templates.' . $row['varname'])
],
'file_extension' => [
'label' => lng('admin.templates.file_extension'),
'type' => 'text',
'string_regexp' => '/^[a-zA-Z0-9]{1,6}$/',
'value' => $row['file_extension'],
'default' => 'html',
'mandatory' => true
],
'filecontent' => [
'label' => lng('admin.templates.filecontent'),
'type' => 'textarea',
'cols' => 60,
'rows' => 12,
'value' => $row['value']
'value' => $row['value'],
'mandatory' => true
],
'filesend' => [
'type' => 'hidden',
Expand Down
8 changes: 2 additions & 6 deletions lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,8 @@
(!empty(Settings::Get('system.froxloraliases')) && !in_array($_SERVER['SERVER_NAME'], array_map('trim', explode(',', Settings::Get('system.froxloraliases')))))
)) {
// not the froxlor system-hostname, show info page for domains not configured in froxlor
$unconfiguredPath = FileDir::makeCorrectFile(Froxlor::getInstallDir() . '/templates/misc/unconfigured/index.html');
if (file_exists($unconfiguredPath)) {
echo file_get_contents($unconfiguredPath);
} else {
echo "This domain requires configuration via the froxlor server management panel, as it is currently not assigned to any customer.";
}
$output = FileDir::getUnknownDomainTemplate($_SERVER['SERVER_NAME']);
echo $output;
die();
}

Expand Down
21 changes: 11 additions & 10 deletions lng/de.lng.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@
'TRAFFICUSED' => 'Wird mit Traffic, der vom Kunden bereits verbraucht wurde, ersetzt.',
'pop_success_alternative' => 'Willkommensmail für neue E-Mail-Konten für die alternative E-Mail-Adresse',
'EMAIL_PASSWORD' => 'Wird mit dem Passwort des neuen POP3/IMAP Kontos ersetzt.',
'index_html' => 'index.html Datei für neu erzeugte Kundenverzeichnisse',
'index_html' => 'index Datei für neu erzeugte Kundenverzeichnisse',
'unconfigured_html' => 'index Datei für unkonfigurierte/unbekannte Domains',
'unconfigured_content_fallback' => 'Diese Domain muss über das Froxlor-Serververwaltungspanel konfiguriert werden, da sie derzeit keinem Kunden zugewiesen ist.',
'file_extension' => [
'description' => 'Die Dateiendung für die index Datei muss zwischen 1 und 6 Zeichen lang sein und darf nur aus den Zeichen a-z, A-Z und 0-9 bestehen<br><br>Standard: html',
'title' => 'Dateiendung für Datei Vorlage',
],
'SERVERNAME' => 'Wird mit dem Servernamen ersetzt.',
'CUSTOMER' => 'Wird mit dem Loginnamen des Kunden ersetzt.',
'ADMIN' => 'Wird mit dem Loginnamen des Admins ersetzt.',
'CUSTOMER_EMAIL' => 'Wird mit der E-Mail-Adresse des Kunden ersetzt.',
'ADMIN_EMAIL' => 'Wird mit der E-Mail-Adresse des Admin ersetzt.',
'CUSTOMER' => 'Wird mit dem Loginnamen des Kunden ersetzt. Nur für "index Datei für neu erzeugte Kundenverzeichnisse".',
'ADMIN' => 'Wird mit dem Loginnamen des Admins ersetzt. Nur für "index Datei für neu erzeugte Kundenverzeichnisse".',
'CUSTOMER_EMAIL' => 'Wird mit der E-Mail-Adresse des Kunden ersetzt. Nur für "index Datei für neu erzeugte Kundenverzeichnisse".',
'ADMIN_EMAIL' => 'Wird mit der E-Mail-Adresse des Admin ersetzt. Nur für "index Datei für neu erzeugte Kundenverzeichnisse".',
'filetemplates' => 'Dateivorlagen',
'filecontent' => 'Dateiinhalt',
'new_database_by_customer' => 'Kunden-Benachrichtigungs nach Erstellung einer neuen Datenbank',
Expand Down Expand Up @@ -831,7 +837,6 @@
'descriptioninvalid' => 'Der Beschreibungstext ist zu kurz, zu lang oder enthält ungültige Zeichen',
'info' => 'Info',
'filecontentnotset' => 'Diese Datei darf nicht leer sein!',
'index_file_extension' => 'Die Dateiendung für die index Datei muss zwischen 1 und 6 Zeichen lang sein und darf nur aus den Zeichen a-z, A-Z und 0-9 bestehen',
'customerdoesntexist' => 'Der ausgewählte Kunde existiert nicht.',
'admindoesntexist' => 'Der ausgewählte Admin existiert nicht.',
'ipportdoesntexist' => 'Die gewählte IP/Port-Kombination existiert nicht.',
Expand Down Expand Up @@ -1610,10 +1615,6 @@
'removelink' => 'Hier klicken, um alle E-Mail-Kontingente zu entfernen',
'enforcelink' => 'Hier klicken, um allen Benutzern das Standard-Kontingent zu zuweisen.',
],
'index_file_extension' => [
'description' => 'Welche Dateiendung soll die index Datei in neu erstellten Kundenverzeichnissen haben? Diese Dateiendung wird dann verwendet, wenn Sie bzw. einer Ihrer Admins eigene index Dateivorlagen erstellt haben.',
'title' => 'Dateiendung für index Datei in neu erstellen Kundenverzeichnissen',
],
'session_allow_multiple_login' => [
'title' => 'Erlaube gleichzeitigen Login',
'description' => 'Wenn diese Option aktiviert ist, können sich Nutzer mehrmals gleichzeitig anmelden.',
Expand Down
19 changes: 10 additions & 9 deletions lng/en.lng.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,17 @@
'pop_success_alternative' => 'Welcome mail for new email accounts sent to alternative address',
'EMAIL_PASSWORD' => 'Replaced with the POP3/IMAP account password.',
'index_html' => 'index file for newly created customer directories',
'unconfigured_html' => 'index file for unconfigured/unknown domains',
'unconfigured_content_fallback' => 'This domain requires configuration via the froxlor server management panel, as it is currently not assigned to any customer.',
'file_extension' => [
'description' => 'The file extension for the index file must be between 1 and 6 characters long. The extension can only contain characters like a-z, A-Z and 0-9<br><br>Default: html',
'title' => 'File extension for the file template',
],
'SERVERNAME' => 'Replaced with the servername.',
'CUSTOMER' => 'Replaced with the loginname of the customer.',
'ADMIN' => 'Replaced with the loginname of the admin.',
'CUSTOMER_EMAIL' => 'Replaced with the e-mail address of the customer.',
'ADMIN_EMAIL' => 'Replaced with the e-mail address of the admin.',
'CUSTOMER' => 'Replaced with the loginname of the customer. Only for "index file for newly created customer directories"',
'ADMIN' => 'Replaced with the loginname of the admin. Only for "index file for newly created customer directories"',
'CUSTOMER_EMAIL' => 'Replaced with the e-mail address of the customer. Only for "index file for newly created customer directories"',
'ADMIN_EMAIL' => 'Replaced with the e-mail address of the admin. Only for "index file for newly created customer directories"',
'filetemplates' => 'File templates',
'filecontent' => 'File content',
'new_database_by_customer' => 'Customer-notification when a database has been created',
Expand Down Expand Up @@ -903,7 +909,6 @@
'descriptioninvalid' => 'The description is too short, too long or contains illegal characters.',
'info' => 'Info',
'filecontentnotset' => 'The file cannot be empty!',
'index_file_extension' => 'The file extension for the index file must be between 1 and 6 characters long. The extension can only contain characters like a-z, A-Z and 0-9',
'customerdoesntexist' => 'The customer you have chosen doesn\'t exist.',
'admindoesntexist' => 'The admin you have chosen doesn\'t exist.',
'ipportdoesntexist' => 'The ip/port combination you have chosen doesn\'t exist.',
Expand Down Expand Up @@ -1732,10 +1737,6 @@
'removelink' => 'Click here to wipe all quotas for mail accounts.',
'enforcelink' => 'Click here to enforce default quota to all User mail accounts.',
],
'index_file_extension' => [
'description' => 'Which file extension should be used for the index file in newly created customer directories? This file extension will be used, if you or one of your admins has created its own index file template.',
'title' => 'File extension for index file in newly created customer directories',
],
'session_allow_multiple_login' => [
'title' => 'Allow multiple login',
'description' => 'If activated a user could login multiple times.',
Expand Down

0 comments on commit 735ef85

Please sign in to comment.