migrated a few functions to new Settings class and removed unused function createAWStatsVhost(), refs #1325

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-12-15 13:05:19 +01:00
parent 558108008a
commit 52aaedd33a
15 changed files with 85 additions and 177 deletions

View File

@@ -24,34 +24,30 @@
*
* @return void
*/
function makeChownWithNewStats($row)
{
global $settings;
function makeChownWithNewStats($row) {
// get correct user
if($settings['system']['mod_fcgid'] == '1' && isset($row['deactivated']) && $row['deactivated'] == '0')
{
if ((Settings::Get('system.mod_fcgid') == '1' || Settings::Get('phpfpm.enabled') == '1')
&& isset($row['deactivated'])
&& $row['deactivated'] == '0'
) {
$user = $row['loginname'];
$group = $row['loginname'];
}
else
{
} else {
$user = $row['guid'];
$group = $row['guid'];
}
// get correct directory
$dir = $row['documentroot'];
if($settings['system']['awstats_enabled'] == '1')
{
if (Settings::Get('system.awstats_enabled') == '1') {
$dir .= '/awstats/';
} else {
$dir .= '/webalizer/';
}
// only run chown if directory exists
if (file_exists($dir))
{
if (file_exists($dir)) {
// run chown
safe_exec('chown -R '.escapeshellarg($user).':'.escapeshellarg($group).' '.escapeshellarg(makeCorrectDir($dir)));
}

View File

@@ -27,10 +27,8 @@
*/
function storeDefaultIndex($loginname = null, $destination = null, $logger = null, $force = false) {
global $settings;
if ($force
|| (int)$settings['system']['store_index_file_subs'] == 1
|| (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`
@@ -46,7 +44,7 @@ function storeDefaultIndex($loginname = null, $destination = null, $logger = nul
$template = $result_stmt->fetch(PDO::FETCH_ASSOC);
$replace_arr = array(
'SERVERNAME' => $settings['system']['hostname'],
'SERVERNAME' => Settings::Get('system.hostname'),
'CUSTOMER' => $template['customer_login'],
'ADMIN' => $template['admin_login'],
'CUSTOMER_EMAIL' => $template['customer_email'],
@@ -54,12 +52,12 @@ function storeDefaultIndex($loginname = null, $destination = null, $logger = nul
);
$htmlcontent = replace_variables($template['value'], $replace_arr);
$indexhtmlpath = makeCorrectFile($destination . '/index.' . $settings['system']['index_file_extension']);
$indexhtmlpath = makeCorrectFile($destination . '/index.' . Settings::Get('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));
$logger->logAction(CRON_ACTION, LOG_NOTICE, 'Creating \'index.' . Settings::Get('system.index_file_extension') . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath));
}
} else {

View File

@@ -26,7 +26,7 @@
*/
function correctErrorDocument($errdoc = null) {
global $settings, $idna_convert;
global $idna_convert;
if ($errdoc !== null && $errdoc != '') {
// not a URL
@@ -45,15 +45,14 @@ function correctErrorDocument($errdoc = null) {
// a string (check for ending ")
else {
// string won't work for lighty
if ($settings['system']['webserver'] == 'lighttpd') {
if (Settings::Get('system.webserver') == 'lighttpd') {
standard_error('stringerrordocumentnotvalidforlighty');
} elseif(substr($errdoc, -1) != '"') {
$errdoc .= '"';
}
}
} else {
if ($settings['system']['webserver'] == 'lighttpd') {
if (Settings::Get('system.webserver') == 'lighttpd') {
standard_error('urlerrordocumentnotvalidforlighty');
}
}

View File

@@ -28,8 +28,6 @@
*/
function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot, $awstats_params = array()) {
global $settings;
// Generation header
$header = "## GENERATED BY FROXLOR\n";
$header2 = "## Do not remove the line above! This tells Froxlor to update this configuration\n## If you wish to manually change this configuration file, remove the first line to make sure Froxlor won't rebuild this file\n## Generated for domain {SITE_DOMAIN} on " . date('l dS \of F Y h:i:s A') . "\n";
@@ -42,8 +40,8 @@ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot
makeChownWithNewStats($awstats_params);
// weird but could happen...
if (!is_dir($settings['system']['awstats_conf'])) {
safe_exec('mkdir -p '.escapeshellarg($settings['system']['awstats_conf']));
if (!is_dir(Settings::Get('system.awstats_conf'))) {
safe_exec('mkdir -p '.escapeshellarg(Settings::Get('system.awstats_conf')));
}
// These are the variables we will replace
@@ -59,11 +57,11 @@ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot
$siteDomain,
$hostAliases,
$awstats_dir,
makeCorrectDir($settings['system']['awstats_conf'])
makeCorrectDir(Settings::Get('system.awstats_conf'))
);
// File names
$domain_file = makeCorrectFile($settings['system']['awstats_conf'].'/awstats.' . $siteDomain . '.conf');
$domain_file = makeCorrectFile(Settings::Get('system.awstats_conf').'/awstats.' . $siteDomain . '.conf');
$model_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstatsmodel/awstats.froxlor.model.conf';
$model_file = makeCorrectFile($model_file);

View File

@@ -1,49 +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
*
*/
/**
* This function generates the VHost configuration for AWStats
* This will enable the /awstats url and enable security on these folders
* @author Berend Dekens
*
* @param siteDomain Name of the domain we want stats for
*
* @return String with configuration for use in vhost file
*/
function createAWStatsVhost($siteDomain, $settings = null) {
if ($settings['system']['mod_fcgid'] != '1') {
$vhosts_file = ' # AWStats statistics' . "\n";
$vhosts_file.= ' RewriteEngine On' . "\n";
$vhosts_file.= ' RewriteRule ^/awstats(/.*)?$ /awstats/awstats.pl?config=' . $siteDomain . ' [L,PT]' . "\n";
$vhosts_file.= ' RewriteRule ^/awstats.pl(.*)$ /awstats/awstats.pl$1 [QSA,L,PT]' . "\n";
} else {
$vhosts_file = ' <IfModule mod_proxy.c>' . "\n";
$vhosts_file.= ' RewriteEngine On' . "\n";
$vhosts_file.= ' RewriteRule awstats.pl(.*)$ http://' . $settings['system']['hostname'] . '/cgi-bin/awstats.pl$1 [R,P]' . "\n";
$vhosts_file.= ' RewriteRule awstats$ http://' . $settings['system']['hostname'] . '/cgi-bin/awstats.pl?config=' . $siteDomain . ' [R,P]' . "\n";
$vhosts_file.= ' </IfModule>' . "\n";
}
return $vhosts_file;
}

View File

@@ -19,9 +19,8 @@
* Generates a random password
*/
function generatePassword() {
global $settings;
return substr(
base64_encode(sha1(md5(uniqid(microtime(), 1))).md5(uniqid(microtime(), 1)).sha1(md5(uniqid(microtime(), 1)))),
rand(5, 50), ($settings['panel']['password_min_length'] > 0 ? $settings['panel']['password_min_length'] : 10)
rand(5, 50), (Settings::Get('panel.password_min_length') > 0 ? Settings::Get('panel.password_min_length') : 10)
);
}

View File

@@ -15,38 +15,34 @@
*
*/
function getFilesystemQuota()
{
global $settings, $theme;
if ($settings['system']['diskquota_enabled'])
{
# Fetch all quota in the desired partition
exec($settings['system']['diskquota_repquota_path'] . " -np " . escapeshellarg($settings['system']['diskquota_customer_partition']), $repquota);
function getFilesystemQuota() {
if (Settings::Get('system.diskquota_enabled')) {
// Fetch all quota in the desired partition
exec(Settings::Get('system.diskquota_repquota_path') . " -np " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')), $repquota);
$usedquota = array();
foreach ($repquota as $tmpquota)
{
# Let's see if the line matches a quota - line
if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches))
{
# It matches - put it into an array with userid as key (for easy lookup later)
foreach ($repquota as $tmpquota) {
// Let's see if the line matches a quota - line
if (preg_match('/^#([0-9]+)\s*[+-]{2}\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)/i', $tmpquota, $matches)) {
// It matches - put it into an array with userid as key (for easy lookup later)
$usedquota[$matches[1]] = array(
'block' => array(
'used' => $matches[2],
'soft' => $matches[3],
'hard' => $matches[4],
'grace' => $matches[5]
),
'used' => $matches[2],
'soft' => $matches[3],
'hard' => $matches[4],
'grace' => $matches[5]
),
'file' => array(
'used' => $matches[6],
'soft' => $matches[7],
'hard' => $matches[8],
'grace' => $matches[9]
),
'used' => $matches[6],
'soft' => $matches[7],
'hard' => $matches[8],
'grace' => $matches[9]
),
);
}
}
return $usedquota;
}
return false;

View File

@@ -29,8 +29,6 @@
function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '') {
global $settings;
if ($type == '1'
|| $type == '3'
|| $type == '4'
@@ -38,11 +36,11 @@ function inserttask($type, $param1 = '', $param2 = '', $param3 = '', $param4 = '
|| $type == '10'
) {
// 4 = bind -> if bind disabled -> no task
if ($type == '4' && $settings['system']['bind_enable'] == '0') {
if ($type == '4' && Settings::Get('system.bind_enable') == '0') {
return;
}
// 10 = quota -> if quota disabled -> no task
if ($type == '10' && $settings['system']['diskquota_enabled'] == '0') {
if ($type == '10' && Settings::Get('system.diskquota_enabled') == '0') {
return;
}
$del_stmt = Database::prepare("

View File

@@ -28,8 +28,8 @@
*/
function checkLastGuid() {
global $log, $cronlog, $settings;
global $log, $cronlog;
$mylog = null;
if (isset($cronlog) && $cronlog instanceof FroxlorLogger) {
$mylog = $cronlog;
@@ -86,10 +86,9 @@ function checkLastGuid() {
}
// now check if it differs from our settings
if ($update_to_guid != $settings['system']['lastguid']) {
if ($update_to_guid != Settings::Get('system.lastguid')) {
$mylog->logAction(CRON_ACTION, LOG_NOTICE, 'Updating froxlor last guid to '.$update_to_guid);
saveSetting('system', 'lastguid', $update_to_guid);
$settings['system']['lastguid'] = $update_to_guid;
Settings::Set('system.lastguid', $update_to_guid);
}
} else {
$mylog->logAction(CRON_ACTION, LOG_NOTICE, 'File /etc/group not readable; cannot check for latest guid');

View File

@@ -34,9 +34,7 @@
*/
function makeCryptPassword ($password) {
global $settings;
$type = isset($settings['system']['passwordcryptfunc']) ? (int)$settings['system']['passwordcryptfunc'] : 1;
$type = isset(Settings::Get('system.passwordcryptfunc')) ? (int)Settings::Get('system.passwordcryptfunc') : 1;
switch ($type) {
case 0:

View File

@@ -15,27 +15,21 @@
*
*/
function checkFcgidPhpFpm($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues)
{
global $settings, $theme;
function checkFcgidPhpFpm($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues) {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_OK);
/*
* check whether fcgid should be enabled but php-fpm is
*/
// check whether fcgid should be enabled but php-fpm is
if($fieldname == 'system_mod_fcgid_enabled'
&& (int)$newfieldvalue == 1
&& (int)$settings['phpfpm']['enabled'] == 1
&& (int)Settings::Get('phpfpm.enabled') == 1
) {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_ERROR, 'phpfpmstillenabled');
}
/*
* check whether php-fpm should be enabled but fcgid is
*/
// check whether php-fpm should be enabled but fcgid is
elseif($fieldname == 'system_phpfpm_enabled'
&& (int)$newfieldvalue == 1
&& (int)$settings['system']['mod_fcgid'] == 1
&& (int)Settings::Get('system.mod_fcgid') == 1
) {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_ERROR, 'fcgidstillenabled');
}

View File

@@ -15,44 +15,30 @@
*
*/
function checkPathConflicts($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues)
{
global $settings, $theme;
if((int)$settings['system']['mod_fcgid'] == 1)
{
/**
* fcgid-configdir has changed ->
* check against customer-doc-prefix
*/
if($fieldname == "system_mod_fcgid_configdir")
{
function checkPathConflicts($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues) {
if((int)Settings::Get('system.mod_fcgid') == 1) {
// fcgid-configdir has changed -> check against customer-doc-prefix
if ($fieldname == "system_mod_fcgid_configdir") {
$newdir = makeCorrectDir($newfieldvalue);
$cdir = makeCorrectDir($settings['system']['documentroot_prefix']);
$cdir = makeCorrectDir(Settings::Get('system.documentroot_prefix'));
}
/**
* customer-doc-prefix has changed ->
* check against fcgid-configdir
*/
elseif($fieldname == "system_documentroot_prefix")
{
// customer-doc-prefix has changed -> check against fcgid-configdir
elseif ($fieldname == "system_documentroot_prefix") {
$newdir = makeCorrectDir($newfieldvalue);
$cdir = makeCorrectDir($settings['system']['mod_fcgid_configdir']);
$cdir = makeCorrectDir(Settings::Get('system.mod_fcgid_configdir'));
}
// neither dir can be within the other nor can they be equal
if(substr($newdir, 0, strlen($cdir)) == $cdir
|| substr($cdir, 0, strlen($newdir)) == $newdir
|| $newdir == $cdir
if (substr($newdir, 0, strlen($cdir)) == $cdir
|| substr($cdir, 0, strlen($newdir)) == $newdir
|| $newdir == $cdir
) {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_ERROR, 'fcgidpathcannotbeincustomerdoc');
}
else
{
} else {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_OK);
}
}
else
{
} else {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_OK);
}

View File

@@ -18,11 +18,9 @@
function checkPhpInterfaceSetting($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues) {
global $settings;
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_OK);
if ((int)$settings['system']['mod_fcgid'] == 1) {
if ((int)Settings::Get('system.mod_fcgid') == 1) {
// now check if we enable a webserver != apache
if (strtolower($newfieldvalue) != 'apache2') {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_ERROR, 'fcgidstillenableddeadlock');

View File

@@ -17,20 +17,20 @@
*
*/
function checkUsername($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues)
{
global $settings, $theme;
if(!isset($allnewfieldvalues['customer_mysqlprefix']))
{
$allnewfieldvalues['customer_mysqlprefix'] = $settings['customer']['mysqlprefix'];
function checkUsername($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues) {
if (!isset($allnewfieldvalues['customer_mysqlprefix'])) {
$allnewfieldvalues['customer_mysqlprefix'] = Settings::Get('customer.mysqlprefix');
}
$returnvalue = array();
if(validateUsername($newfieldvalue, $settings['panel']['unix_names'], 14 - strlen($allnewfieldvalues['customer_mysqlprefix'])) === true)
{
if (validateUsername(
$newfieldvalue,
Settings::Get('panel.unix_names'),
14 - strlen($allnewfieldvalues['customer_mysqlprefix'])) === true
) {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_OK);
}
else
{
} else {
$returnvalue = array(FORMFIELDS_PLAUSIBILITY_CHECK_ERROR, 'accountprefixiswrong');
}
return $returnvalue;

View File

@@ -26,24 +26,22 @@
*
* @return string either the password or an errormessage+exit
*/
function validatePassword($password = null)
{
global $settings, $theme;
function validatePassword($password = null) {
if ($settings['panel']['password_min_length'] > 0) {
if (Settings::Get('panel.password_min_length') > 0) {
$password = validate(
$password,
$settings['panel']['password_min_length'], /* replacer needs to be password length, not the fieldname */
'/^.{'.(int)$settings['panel']['password_min_length'].',}$/D',
Settings::Get('panel.password_min_length'),
'/^.{'.(int)Settings::Get('panel.password_min_length').',}$/D',
'notrequiredpasswordlength'
);
}
if ($settings['panel']['password_regex'] != '') {
if (Settings::Get('panel.password_regex') != '') {
$password = validate(
$password,
$settings['panel']['password_regex'],
$settings['panel']['password_regex'],
Settings::Get('panel.password_regex'),
Settings::Get('panel.password_regex'),
'notrequiredpasswordcomplexity'
);
}