diff --git a/actions/admin/settings/120.system.php b/actions/admin/settings/120.system.php index e676f5c0..346b2424 100644 --- a/actions/admin/settings/120.system.php +++ b/actions/admin/settings/120.system.php @@ -85,6 +85,14 @@ return array( 'default' => 'html', 'save_method' => 'storeSettingField', ), + 'system_store_index_file_subs' => array( + 'label' => $lng['serversettings']['system_store_index_file_subs'], + 'settinggroup' => 'system', + 'varname' => 'store_index_file_subs', + 'type' => 'bool', + 'default' => true, + 'save_method' => 'storeSettingField', + ), 'system_httpuser' => array( 'settinggroup' => 'system', 'varname' => 'httpuser', diff --git a/install/froxlor.sql b/install/froxlor.sql index f5c5dbc9..71a48f56 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -551,6 +551,7 @@ INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) V INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (120, 'spf', 'spf_entry', '@ IN TXT "v=spf1 a mx -all"'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (121, 'system', 'debug_cron', '0'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (122, 'panel', 'password_min_length', '0'); +INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (123, 'system', 'store_index_file_subs', '1'); # -------------------------------------------------------- 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 a40b0912..0bc3f984 100644 --- a/install/updates/froxlor/0.9/update_0.9.inc.php +++ b/install/updates/froxlor/0.9/update_0.9.inc.php @@ -320,6 +320,7 @@ if(isFroxlorVersion('0.9.3')) showUpdateStep("Updating tables"); $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('panel', 'password_min_length', '0');"); + $db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'store_index_file_subs', '1');"); lastStepStatus(0); updateToVersion('0.9.3-svn1'); diff --git a/lib/functions/filedir/function.mkDirWithCorrectOwnership.php b/lib/functions/filedir/function.mkDirWithCorrectOwnership.php index 2d80a714..ee8299d4 100644 --- a/lib/functions/filedir/function.mkDirWithCorrectOwnership.php +++ b/lib/functions/filedir/function.mkDirWithCorrectOwnership.php @@ -26,13 +26,15 @@ * @param string The dir which should be created * @param int The uid of the user * @param int The gid of the user + * @param bool Place standard-index.html into the new folder + * * @return bool true if everything went okay, false if something went wrong * * @author Florian Lippert * @author Martin Burchert */ -function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid) +function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid, $placeindex = false) { $returncode = true; @@ -73,6 +75,17 @@ function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid) { $sdir = makeCorrectDir($sdir); safe_exec('mkdir -p ' . escapeshellarg($sdir)); + + /** + * #68 + */ + if ($placeindex) { + $loginname = getLoginNameByUid($uid); + if ($loginname !== false) { + storeDefaultIndex($loginname, $sdir, null); + } + } + safe_exec('chown -R ' . (int)$uid . ':' . (int)$gid . ' ' . escapeshellarg($sdir)); } } diff --git a/lib/functions/filedir/function.storeDefaultIndex.php b/lib/functions/filedir/function.storeDefaultIndex.php new file mode 100644 index 00000000..0626640f --- /dev/null +++ b/lib/functions/filedir/function.storeDefaultIndex.php @@ -0,0 +1,50 @@ +query("SELECT `t`.`value`, `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` ON `a`.`adminid` = `t`.`adminid` WHERE `varname` = 'index_html' AND `c`.`loginname` = '" . $db->escape($loginname) . "'"); + + if($db->num_rows($result) > 0) + { + $template = $db->fetch_array($result); + $replace_arr = array( + 'SERVERNAME' => $settings['system']['hostname'], + 'CUSTOMER' => $template['customer_login'], + 'ADMIN' => $template['admin_login'], + 'CUSTOMER_EMAIL' => $template['customer_email'], + 'ADMIN_EMAIL' => $template['admin_email'] + ); + $htmlcontent = replace_variables($template['value'], $replace_arr); + $indexhtmlpath = makeCorrectFile($destination . '/index.' . $settings['system']['index_file_extension']); + $index_html_handler = fopen($indexhtmlpath, 'w'); + fwrite($index_html_handler, $htmlcontent); + fclose($index_html_handler); + if ($logger !== null) { + $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Creating \'index.' . $settings['system']['index_file_extension'] . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)); + } + } + else + { + if ($logger !== null) { + $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); + } + safe_exec('cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); + } + } + return; +} diff --git a/lib/functions/froxlor/function.getLoginNameByUid.php b/lib/functions/froxlor/function.getLoginNameByUid.php new file mode 100644 index 00000000..8d4e5cfa --- /dev/null +++ b/lib/functions/froxlor/function.getLoginNameByUid.php @@ -0,0 +1,20 @@ +query_first("SELECT `loginname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `guid` = '".(int)$uid."'"); + if($db->num_rows($result) > 0) + { + return $result['loginname']; + } + return false; +} diff --git a/lng/english.lng.php b/lng/english.lng.php index 895d0ef0..aa78a11f 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1310,5 +1310,7 @@ $lng['error']['hiddenfieldvaluechanged'] = 'The value for the hidden field " $lng['serversettings']['panel_password_min_length']['title'] = 'Minimum password length'; $lng['serversettings']['panel_password_min_length']['description'] = 'Here you can set a minimum length for passwords. \'0\' means: no minimum length required.'; $lng['error']['notrequiredpasswordlength'] = 'The given password is too short. Please enter at least %s characters.'; +$lng['serversettings']['system_store_index_file_subs']['title'] = 'Store default index file also to new subfolders'; +$lng['serversettings']['system_store_index_file_subs']['description'] = 'If enabled, the default index-file is being stored to every subdomain-path newly created (not if the folder already exists!)'; ?> diff --git a/lng/german.lng.php b/lng/german.lng.php index c47eaab6..a7e40ed9 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1290,5 +1290,7 @@ $lng['error']['hiddenfieldvaluechanged'] = 'Der Wert des verborgenen Feldes &quo $lng['serversettings']['panel_password_min_length']['title'] = 'Mindestlänge von Passwörtern'; $lng['serversettings']['panel_password_min_length']['description'] = 'Hier können Sie die Mindestlänge für Passwörter festlegen. \'0\' bedeutet: Keine Mindestlänge'; $lng['error']['notrequiredpasswordlength'] = 'Das Passwort ist zu kurz. Bitte geben Sie mindestens %s Zeichen an.'; +$lng['serversettings']['system_store_index_file_subs']['title'] = 'Erstelle Index-Datei auch in neuen Unterordnern'; +$lng['serversettings']['system_store_index_file_subs']['description'] = 'Wenn aktiviert, wird für jede Subdomain mit neuem Unterordner die Standard-Index Datei angelegt.'; ?> diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index 30f9cc93..b8a11444 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -563,7 +563,7 @@ class apache } } - mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid']); + mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid'], true); $vhost_content.= $this->getWebroot($domain); $vhost_content.= $this->composePhpOptions($domain); $vhost_content.= $this->getStats($domain); diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index d4b8bd0a..a93d3ef7 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -253,7 +253,7 @@ class lighttpd $ipport = $domain['ip'] . ':' . $domain['port']; } - mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid']); + mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid'], true); $vhost_content.= $this->getServerNames($domain) . " {\n"; $vhost_content.= $this->getWebroot($domain, $ssl_vhost); diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index fab32ff2..6c73f698 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -144,31 +144,8 @@ while($row = $db->fetch_array($result_tasks)) safe_exec('mkdir -p ' . escapeshellarg($settings['system']['vmail_homedir'] . $row['data']['loginname'])); //check if admin of customer has added template for new customer directories - - $result = $db->query("SELECT `t`.`value`, `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` ON `a`.`adminid` = `t`.`adminid` WHERE `varname` = 'index_html' AND `c`.`loginname` = '" . $db->escape($row['data']['loginname']) . "'"); - - if($db->num_rows($result) > 0) - { - $template = $db->fetch_array($result); - $replace_arr = array( - 'SERVERNAME' => $settings['system']['hostname'], - 'CUSTOMER' => $template['customer_login'], - 'ADMIN' => $template['admin_login'], - 'CUSTOMER_EMAIL' => $template['customer_email'], - 'ADMIN_EMAIL' => $template['admin_email'] - ); - $htmlcontent = replace_variables($template['value'], $replace_arr); - $indexhtmlpath = $settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/index.' . $settings['system']['index_file_extension']; - $index_html_handler = fopen($indexhtmlpath, 'w'); - fwrite($index_html_handler, $htmlcontent); - fclose($index_html_handler); - $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Creating \'index.' . $settings['system']['index_file_extension'] . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)); - } - else - { - $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/')); - safe_exec('cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'] . '/')); - } + $destdir = makeCorrectDir($settings['system']['documentroot_prefix'] . $loginname); + storeDefaultIndex($row['data']['loginname'], $destdir, $cronlog, true); $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: chown -R ' . (int)$row['data']['uid'] . ':' . (int)$row['data']['gid'] . ' ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname'])); safe_exec('chown -R ' . (int)$row['data']['uid'] . ':' . (int)$row['data']['gid'] . ' ' . escapeshellarg($settings['system']['documentroot_prefix'] . $row['data']['loginname']));