From faada48e388f10a036e19b3e1c2f745fa46ca1ba Mon Sep 17 00:00:00 2001 From: "Sorin Pohontu (frontline)" Date: Wed, 20 Mar 2013 21:37:37 +0200 Subject: [PATCH] Feature #536: Use complete domain name as default path for DocumentRoot --- actions/admin/settings/120.system.php | 8 ++++++ admin_domains.php | 23 +++++++++++++--- customer_domains.php | 26 ++++++++++++++++--- install/froxlor.sql | 1 + .../updates/froxlor/0.9/update_0.9.inc.php | 12 +++++++++ .../preconfig/0.9/preconfig_0.9.inc.php | 13 ++++++++++ lib/tables.inc.php | 2 +- lng/english.lng.php | 6 +++++ 8 files changed, 83 insertions(+), 8 deletions(-) diff --git a/actions/admin/settings/120.system.php b/actions/admin/settings/120.system.php index c9f7c271..f721365c 100644 --- a/actions/admin/settings/120.system.php +++ b/actions/admin/settings/120.system.php @@ -32,6 +32,14 @@ return array( 'save_method' => 'storeSettingField', 'plausibility_check_method' => 'checkPathConflicts' ), + 'system_documentroot_use_default_value' => array( + 'label' => $lng['serversettings']['documentroot_use_default_value'], + 'settinggroup' => 'system', + 'varname' => 'documentroot_use_default_value', + 'type' => 'bool', + 'default' => true, + 'save_method' => 'storeSettingField', + ), 'system_ipaddress' => array( 'label' => $lng['serversettings']['ipaddress'], 'settinggroup' => 'system', diff --git a/admin_domains.php b/admin_domains.php index f515d26d..0a59c701 100644 --- a/admin_domains.php +++ b/admin_domains.php @@ -305,11 +305,13 @@ if($page == 'domains' $specialsettings = validate(str_replace("\r\n", "\n", $_POST['specialsettings']), 'specialsettings', '/^[^\0]*$/'); validate($_POST['documentroot'], 'documentroot'); + // If path is empty and 'Use domain name as default value for DocumentRoot path' is enabled in settings, + // set default path to subdomain or domain name if(isset($_POST['documentroot']) - && $_POST['documentroot'] != '') + && ($_POST['documentroot'] != '')) { if(substr($_POST['documentroot'], 0, 1) != '/' - && !preg_match('/^https?\:\/\//', $_POST['documentroot'])) + && !preg_match('/^https?\:\/\//', $_POST['documentroot'])) { $documentroot.= '/' . $_POST['documentroot']; } @@ -318,6 +320,12 @@ if($page == 'domains' $documentroot = $_POST['documentroot']; } } + elseif (isset($_POST['documentroot']) + && ($_POST['documentroot'] == '') + && ($settings['system']['documentroot_use_default_value'] == 1)) + { + $documentroot = makeCorrectDir($customer['documentroot'] . '/' . $domain); + } } else { @@ -828,7 +836,16 @@ if($page == 'domains' if($documentroot == '') { - $documentroot = $customer['documentroot']; + // If path is empty and 'Use domain name as default value for DocumentRoot path' is enabled in settings, + // set default path to subdomain or domain name + if ($settings['system']['documentroot_use_default_value'] == 1) + { + $documentroot = makeCorrectDir($customer['documentroot'] . '/' . $result['domain']); + } + else + { + $documentroot = $customer['documentroot']; + } } if(!preg_match('/^https?\:\/\//', $documentroot) diff --git a/customer_domains.php b/customer_domains.php index 8c46e0f8..c2f7619d 100644 --- a/customer_domains.php +++ b/customer_domains.php @@ -254,8 +254,17 @@ elseif($page == 'domains') if(!preg_match('/^https?\:\/\//', $path) || !validateUrl($idna_convert->encode($path))) { - $path = $userinfo['documentroot'] . '/' . $path; - $path = makeCorrectDir($path); + // If path is empty or '/' and 'Use domain name as default value for DocumentRoot path' is enabled in settings, + // set default path to subdomain or domain name + if((($path == '') || ($path == '/')) + && $settings['system']['documentroot_use_default_value'] == 1) + { + $path = makeCorrectDir($userinfo['documentroot'] . '/' . $completedomain); + } + else + { + $path = makeCorrectDir($userinfo['documentroot'] . '/' . $path); + } if (strstr($path, ":") !== FALSE) { standard_error('pathmaynotcontaincolon'); @@ -430,8 +439,17 @@ elseif($page == 'domains') if(!preg_match('/^https?\:\/\//', $path) || !validateUrl($idna_convert->encode($path))) { - $path = $userinfo['documentroot'] . '/' . $path; - $path = makeCorrectDir($path); + // If path is empty or '/' and 'Use domain name as default value for DocumentRoot path' is enabled in settings, + // set default path to subdomain or domain name + if((($path == '') || ($path == '/')) + && $settings['system']['documentroot_use_default_value'] == 1) + { + $path = makeCorrectDir($userinfo['documentroot'] . '/' . $result['domain']); + } + else + { + $path = makeCorrectDir($userinfo['documentroot'] . '/' . $path); + } if (strstr($path, ":") !== FALSE) { standard_error('pathmaynotcontaincolon'); diff --git a/install/froxlor.sql b/install/froxlor.sql index 95a42fa8..1ebb189f 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -509,6 +509,7 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'perl_server', 'unix:/var/run/nginx/cgiwrap-dispatch.sock'), ('system', 'phpreload_command', ''), ('system', 'apache24', '0'), + ('system', 'documentroot_use_default_value', '0'), ('panel', 'decimal_places', '4'), ('panel', 'adminmail', 'admin@SERVERNAME'), ('panel', 'phpmyadmin_url', ''), diff --git a/install/updates/froxlor/0.9/update_0.9.inc.php b/install/updates/froxlor/0.9/update_0.9.inc.php index 9db69d1d..0f8ee35a 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -2024,3 +2024,15 @@ if (isFroxlorVersion('0.9.28-svn6')) { lastStepStatus(0); updateToVersion('0.9.28-rc1'); } + +if (isFroxlorVersion('0.9.28-rc1')) { + $update_system_documentroot_use_default_value = isset($_POST['update_system_documentroot_use_default_value']) ? (int)$_POST['update_system_documentroot_use_default_value'] : '0'; + showUpdateStep("Adding new settings for using domain name as default value for DocumentRoot path", true); + $db->query("INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'documentroot_use_default_value', '".$update_system_documentroot_use_default_value."');"); + lastStepStatus(0); + + showUpdateStep("Updating from 0.9.28-rc1 to 0.9.28-rc2", true); + lastStepStatus(0); + + updateToVersion('0.9.28-rc2'); +} \ No newline at end of file diff --git a/install/updates/preconfig/0.9/preconfig_0.9.inc.php b/install/updates/preconfig/0.9/preconfig_0.9.inc.php index b96d5e09..f26bdff8 100644 --- a/install/updates/preconfig/0.9/preconfig_0.9.inc.php +++ b/install/updates/preconfig/0.9/preconfig_0.9.inc.php @@ -471,4 +471,17 @@ LoadModule authz_host_module modules/mod_authz_host.so
'; } } + if(versionInUpdate($current_version, '0.9.28-rc2')) + { + $has_preconfig = true; + + $description = 'This version will add an option to set default path for all domains and subdomains, to be the full subdomain or domain name.
'; + $description .= 'You can enable or disable this feature anytime from Server -> Settings -> System settings.
'; + + $question .= 'Do you want to Use domain name as default value for DocumentRoot path?: '; + $question.= makeyesno('update_system_documentroot_use_default_value', '1', '0', '1'); + + eval("\$return.=\"" . getTemplate("update/preconfigitem") . "\";"); + } + } diff --git a/lib/tables.inc.php b/lib/tables.inc.php index b7aa9e14..28aa2a59 100644 --- a/lib/tables.inc.php +++ b/lib/tables.inc.php @@ -73,6 +73,6 @@ define('PACKAGE_ENABLED', 2); // VERSION INFO -$version = '0.9.28-rc1'; +$version = '0.9.28-rc2'; $dbversion = '2'; $branding = ''; diff --git a/lng/english.lng.php b/lng/english.lng.php index 2544ab38..1e112832 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1933,3 +1933,9 @@ $lng['serversettings']['enablewebfonts']['title'] = 'Enable usage of a google we $lng['serversettings']['enablewebfonts']['description'] = 'If enabled, the defined webfont is being used for the font-display'; $lng['serversettings']['definewebfont']['title'] = 'Define a google-webfont for the panel'; $lng['serversettings']['definewebfont']['description'] = 'If enabled, this wefont will be used for the font-display.
Note: replace spaces with the "+" sign, e.g. "Open+Sans"'; + +/* + * Added in Froxlor 0.9.28-rc2 + */ +$lng['serversettings']['documentroot_use_default_value']['title'] = 'Use domain name as default value for DocumentRoot path'; +$lng['serversettings']['documentroot_use_default_value']['description'] = 'If enabled and DocumentRoot path is empty, default value will be the (sub)domain name.

Examples:
/var/customers/customer_name/example.com/
/var/customers/customer_name/subdomain.example.com/'; \ No newline at end of file