diff --git a/lib/classes/io/class.frxDirectory.php b/lib/classes/io/class.frxDirectory.php new file mode 100644 index 00000000..0a89bd68 --- /dev/null +++ b/lib/classes/io/class.frxDirectory.php @@ -0,0 +1,109 @@ + + * @author Froxlor team (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Cron + * + * @since 0.9.33 + * + */ + +/** + * Class frxDirectory handles directory actions and gives information + * about a given directory in connections with its usage in froxlor + * + * @author Michael Kaufmann (d00p) + * + */ +class frxDirectory { + + /** + * directory string + * + * @var string + */ + private $_dir = null; + + /** + * class constructor, optionally set directory + * + * @param string $dir + */ + public function __construct($dir = null) { + $this->_dir = makeCorrectDir($dir); + } + + /** + * check whether the directory has options set in panel_htaccess + */ + public function hasUserOptions() { + $uo_stmt = Database::prepare(" + SELECT COUNT(`id`) as `usropts` FROM `".TABLE_PANEL_HTACCESS."` WHERE `path` = :dir + "); + $uo_res = Database::pexecute_first($uo_stmt, array('dir' => $this->_dir)); + if ($uo_res != false && isset($uo_res['usropts'])) { + return ($uo_res['usropts'] > 0 ? true : false); + } + return false; + } + + /** + * check whether the directory is protected using panel_htpasswd + */ + public function isUserProtected() { + $up_stmt = Database::prepare(" + SELECT COUNT(`id`) as `usrprot` FROM `".TABLE_PANEL_HTPASSWDS."` WHERE `path` = :dir + "); + $up_res = Database::pexecute_first($up_stmt, array('dir' => $this->_dir)); + if ($up_res != false && isset($up_res['usrprot'])) { + return ($up_res['usrprot'] > 0 ? true : false); + } + return false; + } + + /** + * Checks if a given directory is valid for multiple configurations + * or should rather be used as a single file + * + * @param bool $ifexists also check whether file/dir exists + * + * @return bool true if usable as dir, false otherwise + */ + public function isConfigDir($ifexists = false) { + + if (is_null($this->_dir)) { + trigger_error(__CLASS__.'::'.__FUNCTION__.' has been called with a null value', E_USER_WARNING); + return false; + } + + if (file_exists($this->_dir)) { + if (is_dir($this->_dir)) { + $returnval = true; + } else { + $returnval = false; + } + } else { + if (!$ifexists) { + if (substr($this->_dir, -1) == '/') { + $returnval = true; + } else { + $returnval = false; + } + } else { + $returnval = false; + } + } + return $returnval; + } + +} \ No newline at end of file diff --git a/lib/configfiles_index.inc.php b/lib/configfiles_index.inc.php index d64a46bf..9a1adb8a 100644 --- a/lib/configfiles_index.inc.php +++ b/lib/configfiles_index.inc.php @@ -19,7 +19,10 @@ $configcommand = array(); -if (isConfigDir(Settings::Get('system.apacheconf_vhost'))) { +$vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); +$optsDir = new frxDirectory(Settings::Get('system.apacheconf_diroptions')); + +if ($vhostDir->isConfigDir()) { $configcommand['vhost'] = 'mkdir -p ' . Settings::Get('system.apacheconf_vhost'); $configcommand['include'] = 'echo -e "\\nInclude ' . makeCorrectDir(Settings::Get('system.apacheconf_vhost')) . '*.conf" >> ' . makeCorrectFile(makeCorrectDir('/etc/apache2/httpd.conf')); $configcommand['v_inclighty'] = 'echo -e \'\\ninclude_shell "cat ' . makeCorrectDir(Settings::Get('system.apacheconf_vhost')) . '*.conf"\' >> /etc/lighttpd/lighttpd.conf'; @@ -29,7 +32,7 @@ if (isConfigDir(Settings::Get('system.apacheconf_vhost'))) { $configcommand['v_inclighty'] = 'echo -e \'\\ninclude "' . Settings::Get('system.apacheconf_vhost') . '"\' >> /etc/lighttpd/lighttpd.conf'; } -if (isConfigDir(Settings::Get('system.apacheconf_diroptions'))) { +if ($optsDir->isConfigDir()) { $configcommand['diroptions'] = 'mkdir -p ' . Settings::Get('system.apacheconf_diroptions'); $configcommand['d_inclighty'] = 'echo -e \'\\ninclude_shell "cat ' . makeCorrectDir(Settings::Get('system.apacheconf_diroptions')) . '*.conf"\' >> /etc/lighttpd/lighttpd.conf'; } else { diff --git a/lib/functions/filedir/function.isConfigDir.php b/lib/functions/filedir/function.isConfigDir.php deleted file mode 100644 index 574308ad..00000000 --- a/lib/functions/filedir/function.isConfigDir.php +++ /dev/null @@ -1,48 +0,0 @@ - (2003-2009) - * @author Froxlor team (2010-) - * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt - * @package Functions - * - */ - -/** - * Checks if a given directory is valid for multiple configurations - * or should rather be used as a single file - * - * @param string The dir - * @return bool true if usable as dir, false otherwise - * - * @author Florian Lippert - */ -function isConfigDir($dir, $ifexists = false) { - if (file_exists($dir)) { - if (is_dir($dir)) { - $returnval = true; - } else { - $returnval = false; - } - } else { - if (!$ifexists) { - if (substr($dir, -1) == '/') { - $returnval = true; - } else { - $returnval = false; - } - } else { - $returnval = false; - } - } - return $returnval; -} diff --git a/lib/functions/output/function.getTemplate.php b/lib/functions/output/function.getTemplate.php index ae36c28c..0cae450a 100644 --- a/lib/functions/output/function.getTemplate.php +++ b/lib/functions/output/function.getTemplate.php @@ -26,52 +26,43 @@ * @author Florian Lippert */ -function getTemplate($template, $noarea = 0) -{ +function getTemplate($template, $noarea = 0) { + global $templatecache, $theme; - if(!isset($theme) || $theme == '') - { - $theme = 'Froxlor'; + $fallback_theme = 'Sparkle'; + + if (!isset($theme) || $theme == '') { + $theme = $fallback_theme; } - if($noarea != 1) - { + if ($noarea != 1) { $template = AREA . '/' . $template; } - if(!isset($templatecache[$theme][$template])) - { + if (!isset($templatecache[$theme][$template])) { + $filename = './templates/' . $theme . '/' . $template . '.tpl'; - if(file_exists($filename) - && is_readable($filename)) - { - $templatefile = addcslashes(file_get_contents($filename), '"\\'); + // check the current selected theme for the template + $templatefile = _checkAndParseTpl($filename); - // loop through template more than once in case we have an "if"-statement in another one + if ($templatefile == false && $theme != $fallback_theme) { + // check fallback + $_filename = './templates/' . $fallback_theme . '/' . $template . '.tpl'; + $templatefile = _checkAndParseTpl($_filename); - while(preg_match('/(.*)(<\/if>|(.*)<\/if>)/Uis', $templatefile)) - { - $templatefile = preg_replace('/(.*)(<\/if>|(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile); + if ($templatefile == false) { + // check for old layout + $_filename = './templates/' . $template . '.tpl'; + $templatefile = _checkAndParseTpl($_filename); + + if ($templatefile == false) { + // not found + $templatefile = 'TEMPLATE NOT FOUND: ' . $filename; + } } } - elseif(file_exists('./templates/' . $template . '.tpl') && is_readable('./templates/' . $template . '.tpl')) - { - $filename = './templates/' . $template . '.tpl'; - $templatefile = addcslashes(file_get_contents($filename), '"\\'); - - // loop through template more than once in case we have an "if"-statement in another one - - while(preg_match('/(.*)(<\/if>|(.*)<\/if>)/Uis', $templatefile)) - { - $templatefile = preg_replace('/(.*)(<\/if>|(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile); - } - } - else - { - $templatefile = 'TEMPLATE NOT FOUND: ' . $filename; - } $output = $templatefile; // Minify_HTML::minify($templatefile, array('cssMinifier', 'jsMinifier')); $templatecache[$theme][$template] = $output; @@ -79,3 +70,30 @@ function getTemplate($template, $noarea = 0) return $templatecache[$theme][$template]; } + +/** + * check whether a tpl file exists and if so, return it's content or else return false + * + * @param string $filename + * + * @return string|bool content on success, else false + */ +function _checkAndParseTpl($filename) { + + $templatefile = ""; + + if (file_exists($filename) + && is_readable($filename) + ) { + + $templatefile = addcslashes(file_get_contents($filename), '"\\'); + + // loop through template more than once in case we have an "if"-statement in another one + while (preg_match('/(.*)(<\/if>|(.*)<\/if>)/Uis', $templatefile)) { + $templatefile = preg_replace('/(.*)(<\/if>|(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile); + } + + return $templatefile; + } + return false; +} diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index 9bf7bb8d..6223741d 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -230,7 +230,12 @@ class apache { $this->virtualhosts_data[$vhosts_filename].= ' ' . "\n"; // >=apache-2.4 enabled? if (Settings::Get('system.apache24') == '1') { - $this->virtualhosts_data[$vhosts_filename].= ' Require all granted' . "\n"; + $mypath_dir = new frxDirectory($mypath); + // only create the require all granted if there is not active directory-protection + // for this path, as this would be the first require and therefore grant all access + if ($mypath_dir->isUserProtected() == false) { + $this->virtualhosts_data[$vhosts_filename].= ' Require all granted' . "\n"; + } } else { $this->virtualhosts_data[$vhosts_filename].= ' Order allow,deny' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' allow from all' . "\n"; @@ -279,7 +284,12 @@ class apache { $this->virtualhosts_data[$vhosts_filename].= ' ' . "\n"; // >=apache-2.4 enabled? if (Settings::Get('system.apache24') == '1') { - $this->virtualhosts_data[$vhosts_filename] .= ' Require all granted' . "\n"; + $mypath_dir = new frxDirectory($mypath); + // only create the require all granted if there is not active directory-protection + // for this path, as this would be the first require and therefore grant all access + if ($mypath_dir->isUserProtected() == false) { + $this->virtualhosts_data[$vhosts_filename] .= ' Require all granted' . "\n"; + } } else { $this->virtualhosts_data[$vhosts_filename] .= ' Order allow,deny' . "\n"; $this->virtualhosts_data[$vhosts_filename] .= ' allow from all' . "\n"; @@ -941,7 +951,12 @@ class apache { $this->diroptions_data[$diroptions_filename] .= ' AddHandler cgi-script .cgi .pl' . "\n"; // >=apache-2.4 enabled? if (Settings::Get('system.apache24') == '1') { - $this->diroptions_data[$diroptions_filename] .= ' Require all granted' . "\n"; + $mypath_dir = new frxDirectory($row_diroptions['path']); + // only create the require all granted if there is not active directory-protection + // for this path, as this would be the first require and therefore grant all access + if ($mypath_dir->isUserProtected() == false) { + $this->diroptions_data[$diroptions_filename] .= ' Require all granted' . "\n"; + } } else { $this->diroptions_data[$diroptions_filename] .= ' Order allow,deny' . "\n"; $this->diroptions_data[$diroptions_filename] .= ' Allow from all' . "\n"; @@ -1018,7 +1033,8 @@ class apache { $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_diroptions')); if (count($this->diroptions_data) > 0) { - if (!isConfigDir(Settings::Get('system.apacheconf_diroptions'))) { + $optsDir = new frxDirectory(Settings::Get('system.apacheconf_diroptions')); + if (!$optsDir->isConfigDir()) { // Save one big file $diroptions_file = ''; @@ -1065,7 +1081,8 @@ class apache { umask($umask); } - if (isConfigDir(Settings::Get('system.apacheconf_htpasswddir'), true)) { + $htpasswdDir = new frxDirectory(Settings::Get('system.apacheconf_htpasswddir')); + if ($htpasswdDir->isConfigDir(true)) { foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) { $this->known_htpasswdsfilenames[] = basename($htpasswd_filename); $htpasswd_file_handler = fopen($htpasswd_filename, 'w'); @@ -1084,7 +1101,8 @@ class apache { $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost')); if (count($this->virtualhosts_data) > 0) { - if (!isConfigDir(Settings::Get('system.apacheconf_vhost'))) { + $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); + if (!$vhostDir->isConfigDir()) { // Save one big file $vhosts_file = ''; diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index 212d3251..f1cf1038 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -826,7 +826,8 @@ class lighttpd { fwrite($this->debugHandler, ' lighttpd::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost')); - if (!isConfigDir(Settings::Get('system.apacheconf_vhost'))) { + $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); + if (!$vhostDir->isConfigDir()) { // Save one big file $vhosts_file = ''; @@ -871,7 +872,8 @@ class lighttpd { } // Write the diroptions - if (isConfigDir(Settings::Get('system.apacheconf_htpasswddir'))) { + $htpasswdDir = new frxDirectory(Settings::Get('system.apacheconf_htpasswddir')); + if ($htpasswdDir->isConfigDir()) { foreach ($this->needed_htpasswds as $key => $data) { if (!is_dir(Settings::Get('system.apacheconf_htpasswddir'))) { mkdir(makeCorrectDir(Settings::Get('system.apacheconf_htpasswddir'))); diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index dd360de8..0c06ab1f 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -419,7 +419,7 @@ class nginx { ) { $vhost_content.= $this->composeSslSettings($domain); } - $vhost_content = $this->mergeVhostCustom($vhost_content, $this->create_pathOptions($domain)); + $vhost_content = $this->mergeVhostCustom($vhost_content, $this->create_pathOptions($domain)) . "\n"; $vhost_content.= $this->composePhpOptions($domain, $ssl_vhost); $vhost_content.= isset($this->needed_htpasswds[$domain['id']]) ? $this->needed_htpasswds[$domain['id']] . "\n" : ''; @@ -619,7 +619,7 @@ class nginx { break; default: if ($single['path'] == '/') { - $path_options .= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $path_options .= "\t\t" . 'auth_basic "' . $single['authname'] . '";' . "\n"; $path_options .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n"; // remove already used entries so we do not have doubles unset($htpasswds[$idx]); @@ -679,7 +679,7 @@ class nginx { break; default: $path_options .= "\t" . 'location ' . makeCorrectDir($single['path']) . ' {' . "\n"; - $path_options .= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $path_options .= "\t\t" . 'auth_basic "' . $single['authname'] . '";' . "\n"; $path_options .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n"; $path_options .= "\t".'}' . "\n"; } @@ -728,6 +728,7 @@ class nginx { $returnval[$x]['path'] = $path; $returnval[$x]['root'] = makeCorrectDir($domain['documentroot']); + $returnval[$x]['authname'] = $row_htpasswds['authname']; $returnval[$x]['usrf'] = $htpasswd_filename; $x++; } @@ -819,7 +820,7 @@ class nginx { } $stats_text .= "\t\t" . 'alias ' . $alias_dir . ';' . "\n"; - $stats_text .= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text .= "\t\t" . 'auth_basic "' . $single['authname'] . '";' . "\n"; $stats_text .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n"; $stats_text .= "\t" . '}' . "\n\n"; @@ -950,7 +951,8 @@ class nginx { fwrite($this->debugHandler, ' nginx::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost')); - if (!isConfigDir(Settings::Get('system.apacheconf_vhost'))) { + $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); + if (!$vhostDir->isConfigDir()) { // Save one big file $vhosts_file = ''; diff --git a/templates/Sparkle/admin/templates/templates_add_2.tpl b/templates/Sparkle/admin/templates/templates_add_2.tpl index 8ab6aebb..a6df4668 100644 --- a/templates/Sparkle/admin/templates/templates_add_2.tpl +++ b/templates/Sparkle/admin/templates/templates_add_2.tpl @@ -46,11 +46,11 @@ $header - {SALUTATION} + {SALUTATION} {$lng['admin']['templates']['SALUTATION']} - {FIRSTNAME} + {FIRSTNAME} {$lng['admin']['templates']['FIRSTNAME']} diff --git a/templates/Sparkle/admin/templates/templates_edit.tpl b/templates/Sparkle/admin/templates/templates_edit.tpl index 782ac719..7a85e069 100644 --- a/templates/Sparkle/admin/templates/templates_edit.tpl +++ b/templates/Sparkle/admin/templates/templates_edit.tpl @@ -48,11 +48,11 @@ $header - {SALUTATION} + {SALUTATION} {$lng['admin']['templates']['SALUTATION']} - {FIRSTNAME} + {FIRSTNAME} {$lng['admin']['templates']['FIRSTNAME']}