Merge branch 'master' of github.com:Froxlor/Froxlor
This commit is contained in:
109
lib/classes/io/class.frxDirectory.php
Normal file
109
lib/classes/io/class.frxDirectory.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @author Froxlor team <team@froxlor.org> (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) <d00p@froxlor.org>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2003-2009 the SysCP Team (see authors).
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (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 <flo@syscp.org>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@@ -26,52 +26,43 @@
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
*/
|
||||
|
||||
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[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', $templatefile))
|
||||
{
|
||||
$templatefile = preg_replace('/<if[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile);
|
||||
}
|
||||
}
|
||||
elseif(file_exists('./templates/' . $template . '.tpl') && is_readable('./templates/' . $template . '.tpl'))
|
||||
{
|
||||
$filename = './templates/' . $template . '.tpl';
|
||||
$templatefile = addcslashes(file_get_contents($filename), '"\\');
|
||||
if ($templatefile == false) {
|
||||
// check for old layout
|
||||
$_filename = './templates/' . $template . '.tpl';
|
||||
$templatefile = _checkAndParseTpl($_filename);
|
||||
|
||||
// loop through template more than once in case we have an "if"-statement in another one
|
||||
|
||||
while(preg_match('/<if[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', $templatefile))
|
||||
{
|
||||
$templatefile = preg_replace('/<if[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($templatefile == false) {
|
||||
// not found
|
||||
$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[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', $templatefile)) {
|
||||
$templatefile = preg_replace('/<if[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile);
|
||||
}
|
||||
|
||||
return $templatefile;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -230,7 +230,12 @@ class apache {
|
||||
$this->virtualhosts_data[$vhosts_filename].= ' </FilesMatch>' . "\n";
|
||||
// >=apache-2.4 enabled?
|
||||
if (Settings::Get('system.apache24') == '1') {
|
||||
$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].= ' </FilesMatch>' . "\n";
|
||||
// >=apache-2.4 enabled?
|
||||
if (Settings::Get('system.apache24') == '1') {
|
||||
$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') {
|
||||
$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 = '';
|
||||
|
||||
|
||||
@@ -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')));
|
||||
|
||||
@@ -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 = '';
|
||||
|
||||
|
||||
@@ -46,11 +46,11 @@ $header
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>{SALUTATION}</em></td>
|
||||
<td><em>{SALUTATION}</em></td>
|
||||
<td>{$lng['admin']['templates']['SALUTATION']}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>{FIRSTNAME}</em></td>
|
||||
<td><em>{FIRSTNAME}</em></td>
|
||||
<td>{$lng['admin']['templates']['FIRSTNAME']}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -48,11 +48,11 @@ $header
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>{SALUTATION}</em></td>
|
||||
<td><em>{SALUTATION}</em></td>
|
||||
<td>{$lng['admin']['templates']['SALUTATION']}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>{FIRSTNAME}</em></td>
|
||||
<td><em>{FIRSTNAME}</em></td>
|
||||
<td>{$lng['admin']['templates']['FIRSTNAME']}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
Reference in New Issue
Block a user