From 52aaedd33a26491282f5b183405092790e7e33d3 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Sun, 15 Dec 2013 13:05:19 +0100 Subject: [PATCH] migrated a few functions to new Settings class and removed unused function createAWStatsVhost(), refs #1325 Signed-off-by: Michael Kaufmann (d00p) --- .../function.makeChownWithNewStats.php | 20 +++----- .../filedir/function.storeDefaultIndex.php | 10 ++-- .../froxlor/function.CorrectErrorDocument.php | 7 ++- .../froxlor/function.createAWStatsConf.php | 10 ++-- .../froxlor/function.createAWStatsVhost.php | 49 ------------------- .../froxlor/function.generatePassword.php | 3 +- .../froxlor/function.getFilesystemQuota.php | 44 ++++++++--------- lib/functions/froxlor/function.inserttask.php | 6 +-- .../system/function.checklastguid.php | 9 ++-- .../system/function.makeCryptPassword.php | 4 +- .../validate/function.checkFcgidPhpFpm.php | 16 ++---- .../validate/function.checkPathConflicts.php | 42 ++++++---------- .../function.checkPhpInterfaceSetting.php | 4 +- .../validate/function.checkUsername.php | 22 ++++----- .../validate/function.validatePassword.php | 16 +++--- 15 files changed, 85 insertions(+), 177 deletions(-) delete mode 100644 lib/functions/froxlor/function.createAWStatsVhost.php diff --git a/lib/functions/filedir/function.makeChownWithNewStats.php b/lib/functions/filedir/function.makeChownWithNewStats.php index b0b1b5dc..6ead2c50 100644 --- a/lib/functions/filedir/function.makeChownWithNewStats.php +++ b/lib/functions/filedir/function.makeChownWithNewStats.php @@ -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))); } diff --git a/lib/functions/filedir/function.storeDefaultIndex.php b/lib/functions/filedir/function.storeDefaultIndex.php index 98c3af5f..93acffb7 100644 --- a/lib/functions/filedir/function.storeDefaultIndex.php +++ b/lib/functions/filedir/function.storeDefaultIndex.php @@ -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 { diff --git a/lib/functions/froxlor/function.CorrectErrorDocument.php b/lib/functions/froxlor/function.CorrectErrorDocument.php index 71835639..bb25bb4d 100644 --- a/lib/functions/froxlor/function.CorrectErrorDocument.php +++ b/lib/functions/froxlor/function.CorrectErrorDocument.php @@ -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'); } } diff --git a/lib/functions/froxlor/function.createAWStatsConf.php b/lib/functions/froxlor/function.createAWStatsConf.php index 2338ebe9..cc848f8b 100644 --- a/lib/functions/froxlor/function.createAWStatsConf.php +++ b/lib/functions/froxlor/function.createAWStatsConf.php @@ -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); diff --git a/lib/functions/froxlor/function.createAWStatsVhost.php b/lib/functions/froxlor/function.createAWStatsVhost.php deleted file mode 100644 index 55713bb9..00000000 --- a/lib/functions/froxlor/function.createAWStatsVhost.php +++ /dev/null @@ -1,49 +0,0 @@ - (2003-2009) - * @author Froxlor team (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 = ' ' . "\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.= ' ' . "\n"; - - } - - return $vhosts_file; -} diff --git a/lib/functions/froxlor/function.generatePassword.php b/lib/functions/froxlor/function.generatePassword.php index 3653cffb..47241993 100644 --- a/lib/functions/froxlor/function.generatePassword.php +++ b/lib/functions/froxlor/function.generatePassword.php @@ -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) ); } diff --git a/lib/functions/froxlor/function.getFilesystemQuota.php b/lib/functions/froxlor/function.getFilesystemQuota.php index d7063172..6738967a 100644 --- a/lib/functions/froxlor/function.getFilesystemQuota.php +++ b/lib/functions/froxlor/function.getFilesystemQuota.php @@ -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; diff --git a/lib/functions/froxlor/function.inserttask.php b/lib/functions/froxlor/function.inserttask.php index f8807d30..a51c76fa 100644 --- a/lib/functions/froxlor/function.inserttask.php +++ b/lib/functions/froxlor/function.inserttask.php @@ -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(" diff --git a/lib/functions/system/function.checklastguid.php b/lib/functions/system/function.checklastguid.php index de15dae2..615fa4bb 100644 --- a/lib/functions/system/function.checklastguid.php +++ b/lib/functions/system/function.checklastguid.php @@ -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'); diff --git a/lib/functions/system/function.makeCryptPassword.php b/lib/functions/system/function.makeCryptPassword.php index 923b6cff..5758a279 100644 --- a/lib/functions/system/function.makeCryptPassword.php +++ b/lib/functions/system/function.makeCryptPassword.php @@ -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: diff --git a/lib/functions/validate/function.checkFcgidPhpFpm.php b/lib/functions/validate/function.checkFcgidPhpFpm.php index 43dbfec1..f8178795 100644 --- a/lib/functions/validate/function.checkFcgidPhpFpm.php +++ b/lib/functions/validate/function.checkFcgidPhpFpm.php @@ -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'); } diff --git a/lib/functions/validate/function.checkPathConflicts.php b/lib/functions/validate/function.checkPathConflicts.php index df87a070..da58eb03 100644 --- a/lib/functions/validate/function.checkPathConflicts.php +++ b/lib/functions/validate/function.checkPathConflicts.php @@ -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); } diff --git a/lib/functions/validate/function.checkPhpInterfaceSetting.php b/lib/functions/validate/function.checkPhpInterfaceSetting.php index be13f268..3f525634 100644 --- a/lib/functions/validate/function.checkPhpInterfaceSetting.php +++ b/lib/functions/validate/function.checkPhpInterfaceSetting.php @@ -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'); diff --git a/lib/functions/validate/function.checkUsername.php b/lib/functions/validate/function.checkUsername.php index ba26c275..f00ea977 100644 --- a/lib/functions/validate/function.checkUsername.php +++ b/lib/functions/validate/function.checkUsername.php @@ -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; diff --git a/lib/functions/validate/function.validatePassword.php b/lib/functions/validate/function.validatePassword.php index 84481fcd..94bb26b8 100644 --- a/lib/functions/validate/function.validatePassword.php +++ b/lib/functions/validate/function.validatePassword.php @@ -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' ); }