migrate more stuff to new Settings class, refs #1325

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-12-15 14:38:53 +01:00
parent bcf187761c
commit 7f565c305c
12 changed files with 146 additions and 160 deletions

View File

@@ -19,31 +19,33 @@
$configcommand = array();
if(isConfigDir($settings['system']['apacheconf_vhost']))
{
$configcommand['vhost'] = 'mkdir -p ' . $settings['system']['apacheconf_vhost'];
$configcommand['include'] = 'echo -e "\\nInclude ' . makeCorrectDir($settings['system']['apacheconf_vhost']) . '*.conf" >> ' . makeCorrectFile(makeCorrectDir('/etc/apache2/httpd.conf'));
$configcommand['v_inclighty'] = 'echo -e \'\\ninclude_shell "cat ' . makeCorrectDir($settings['system']['apacheconf_vhost']) . '*.conf"\' >> /etc/lighttpd/lighttpd.conf';
}
else
{
$configcommand['vhost'] = 'touch ' . $settings['system']['apacheconf_vhost'];
$configcommand['include'] = 'echo -e "\\nInclude ' . $settings['system']['apacheconf_vhost'] . '" >> ' . makeCorrectFile('/etc/apache2/httpd.conf');
$configcommand['v_inclighty'] = 'echo -e \'\\ninclude "' . $settings['system']['apacheconf_vhost'] . '"\' >> /etc/lighttpd/lighttpd.conf';
if (isConfigDir(Settings::Get('system.apacheconf_vhost'))) {
$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';
} else {
$configcommand['vhost'] = 'touch ' . Settings::Get('system.apacheconf_vhost');
$configcommand['include'] = 'echo -e "\\nInclude ' . Settings::Get('system.apacheconf_vhost') . '" >> ' . makeCorrectFile('/etc/apache2/httpd.conf');
$configcommand['v_inclighty'] = 'echo -e \'\\ninclude "' . Settings::Get('system.apacheconf_vhost') . '"\' >> /etc/lighttpd/lighttpd.conf';
}
if(isConfigDir($settings['system']['apacheconf_diroptions']))
{
$configcommand['diroptions'] = 'mkdir -p ' . $settings['system']['apacheconf_diroptions'];
$configcommand['d_inclighty'] = 'echo -e \'\\ninclude_shell "cat ' . makeCorrectDir($settings['system']['apacheconf_diroptions']) . '*.conf"\' >> /etc/lighttpd/lighttpd.conf';
}
else
{
$configcommand['diroptions'] = 'touch ' . $settings['system']['apacheconf_diroptions'];
$configcommand['d_inclighty'] = 'echo -e \'\\ninclude "' . $settings['system']['apacheconf_diroptions'] . '"\' >> /etc/lighttpd/lighttpd.conf';
if (isConfigDir(Settings::Get('system.apacheconf_diroptions'))) {
$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 {
$configcommand['diroptions'] = 'touch ' . Settings::Get('system.apacheconf_diroptions');
$configcommand['d_inclighty'] = 'echo -e \'\\ninclude "' . Settings::Get('system.apacheconf_diroptions') . '"\' >> /etc/lighttpd/lighttpd.conf';
}
$cfgPath = 'lib/configfiles/';
$configfiles = Array();
$configfiles = array_merge(include $cfgPath . 'wheezy.inc.php', include $cfgPath . 'squeeze.inc.php', include $cfgPath . 'precise.inc.php', include $cfgPath . 'lucid.inc.php', include $cfgPath . 'gentoo.inc.php', include $cfgPath . 'suse11.inc.php', include $cfgPath . 'sle10.inc.php', include $cfgPath . 'freebsd.inc.php');
$configfiles = array();
$configfiles = array_merge(
include $cfgPath . 'wheezy.inc.php',
include $cfgPath . 'squeeze.inc.php',
include $cfgPath . 'precise.inc.php',
include $cfgPath . 'lucid.inc.php',
include $cfgPath . 'gentoo.inc.php',
include $cfgPath . 'suse11.inc.php',
include $cfgPath . 'sle10.inc.php',
include $cfgPath . 'freebsd.inc.php'
);

View File

@@ -127,11 +127,12 @@ try {
}
fwrite($debugHandler, 'Database-connection established' . "\n");
// TODO remove when fully migrated to new Settings class
$result_stmt = Database::query("
SELECT `settingid`, `settinggroup`, `varname`, `value`
FROM `" . TABLE_PANEL_SETTINGS . "`
");
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$settings[$row['settinggroup']][$row['varname']] = $row['value'];
}
@@ -140,26 +141,37 @@ unset($row);
fwrite($debugHandler, 'Froxlor settings have been loaded from the database' . "\n");
/**
* if settings['system']['mod_fcgid_ownvhost'] is set, we have to check
* if using fcgid or fpm for froxlor-vhost itself, we have to check
* whether the permission of the files are still correct
*/
if ((int)$settings['system']['mod_fcgid'] == 1
&& (int)$settings['system']['mod_fcgid_ownvhost'] == 1
fwrite($debugHandler, 'Checking froxlor file permissions');
$_mypath = makeCorrectDir(FROXLOR_INSTALL_DIR);
if (((int)Settings::Get('system.mod_fcgid') == 1 && (int)Settings::Get('system.mod_fcgid_ownvhost') == 1)
|| ((int)Settings::Get('phpfpm.enabled') == 1 && (int)Settings::Get('phpfpm.enabled_ownvhost') == 1)
) {
fwrite($debugHandler, 'Checking froxlor file permissions');
$mypath = makeCorrectDir(FROXLOR_INSTALL_DIR);
$user = $settings['system']['mod_fcgid_httpuser'];
$group = $settings['system']['mod_fcgid_httpgroup'];
$user = Settings::Get('system.mod_fcgid_httpuser');
$group = Settings::Get('system.mod_fcgid_httpgroup');
if (Settings::Get('phpfpm.enabled') == 1) {
$user = Settings::Get('phpfpm.vhost_httpuser');
$group = Settings::Get('phpfpm.vhost_httpgroup');
}
// all the files and folders have to belong to the local user
// now because we also use fcgid for our own vhost
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath));
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($_mypath));
} else {
// back to webserver permission
$user = Settings::Get('system.httpuser');
$group = Settings::Get('system.httpgroup');
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($_mypath));
}
// be sure HTMLPurifier's cache folder is writable
safe_exec('chmod -R 0755 '.escapeshellarg(dirname(__FILE__).'/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer'));
if (!isset($settings['panel']['version'])
|| $settings['panel']['version'] != $version
if (Settings::Get('panel.version') == null
|| Settings::Get('panel.version') != $version
) {
/**
* Do not proceed further if the Database version is not the same as the script version
@@ -168,18 +180,18 @@ if (!isset($settings['panel']['version'])
unlink($lockfile);
$errormessage = "Version of file doesnt match version of database. Exiting...\n\n";
$errormessage.= "Possible reason: Froxlor update\n";
$errormessage.= "Information: Current version in database: ".$settings['panel']['version']." - version of Froxlor files: ".$version."\n";
$errormessage.= "Information: Current version in database: ".Settings::Get('panel.version')." - version of Froxlor files: ".$version."\n";
$errormessage.= "Solution: Please visit your Foxlor admin interface for further information.\n";
die($errormessage);
}
fwrite($debugHandler, 'Froxlor version and database version are correct' . "\n");
$cronscriptDebug = ($settings['system']['debug_cron'] == '1') ? true : false;
$cronscriptDebug = (Settings::Get('system.debug_cron') == '1') ? true : false;
// Create a new idna converter
$idna_convert = new idna_convert_wrapper();
// Initialize logging
$cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob'), $settings);
$cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob'));
fwrite($debugHandler, 'Logger has been included' . "\n");

View File

@@ -17,7 +17,7 @@
*
*/
if ($settings['logger']['log_cron'] == '1') {
if (Settings::Get('logger.log_cron') == '1') {
$cronlog->setCronLog(0);
fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n");
}

View File

@@ -26,38 +26,23 @@
*
* @author Florian Lippert <flo@syscp.org>
*/
function isConfigDir($dir, $ifexists = false)
{
if(file_exists($dir))
{
if(is_dir($dir))
{
function isConfigDir($dir, $ifexists = false) {
if (file_exists($dir)) {
if (is_dir($dir)) {
$returnval = true;
}
else
{
} else {
$returnval = false;
}
}
else
{
if(!$ifexists)
{
if(substr($dir, -1) == '/')
{
} else {
if (!$ifexists) {
if (substr($dir, -1) == '/') {
$returnval = true;
}
else
{
} else {
$returnval = false;
}
}
else
{
} else {
$returnval = false;
}
}
return $returnval;
}

View File

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

View File

@@ -145,6 +145,7 @@ if (get_magic_quotes_gpc()) {
/**
* Selects settings from MySQL-Table
* TODO remove when completely migrated to new Settings class
*/
$settings_data = loadConfigArrayDir('actions/admin/settings/');
$settings = loadSettings($settings_data);
@@ -176,7 +177,7 @@ if (isset($_POST['s'])) {
$nosession = 1;
}
$timediff = time() - $settings['session']['sessiontimeout'];
$timediff = time() - Settings::Get('session.sessiontimeout');
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_SESSIONS . "` WHERE `lastactivity` < :timediff
");
@@ -270,7 +271,7 @@ foreach ($langs as $key => $value) {
// set default langauge before anything else to
// ensure that we can display messages
$language = $settings['panel']['standardlanguage'];
$language = Settings::Get('panel.standardlanguage');
if (isset($userinfo['language']) && isset($languages[$userinfo['language']])) {
// default: use language from session, #277
@@ -299,7 +300,7 @@ if (isset($userinfo['language']) && isset($languages[$userinfo['language']])) {
// if HTTP_ACCEPT_LANGUAGES has no valid langs, use default (very unlikely)
if (!strlen($language)>0) {
$language = $settings['panel']['standardlanguage'];
$language = Settings::Get('panel.standardlanguage');
}
}
}
@@ -329,7 +330,7 @@ $linker = new linker('index.php', $s);
/**
* global Theme-variable
*/
$theme = isset($settings['panel']['default_theme']) ? $settings['panel']['default_theme'] : 'Sparkle';
$theme = (Settings::Get('panel.default_theme') !== null) ? Settings::Get('panel.default_theme') : 'Sparkle';
/**
* overwrite with customer/admin theme if defined
@@ -374,7 +375,7 @@ if (isset($userinfo['loginname'])
) {
$lng['menue']['main']['username'].= $userinfo['loginname'];
//Initialize logging
$log = FroxlorLogger::getInstanceOf($userinfo, $settings);
$log = FroxlorLogger::getInstanceOf($userinfo);
}
/**
@@ -428,7 +429,7 @@ if (AREA == 'admin' || AREA == 'customer') {
*/
$awaitingtickets = 0;
$awaitingtickets_text = '';
if ($settings['ticket']['enabled'] == '1') {
if (Settings::Get('ticket.enabled') == '1') {
$opentickets = 0;
@@ -460,7 +461,7 @@ if ($settings['ticket']['enabled'] == '1') {
}
}
$webfont = str_replace('+', ' ', $settings['panel']['webfont']);
$webfont = str_replace('+', ' ', Settings::Get('panel.webfont'));
eval("\$header = \"" . getTemplate('header', '1') . "\";");
$current_year = date('Y', time());
@@ -496,10 +497,10 @@ if ($page == '') {
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
if (PHPMailer::ValidateAddress($settings['panel']['adminmail']) !== false) {
if (PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76
$mail->SetFrom($settings['panel']['adminmail'], $settings['panel']['adminmail_defname']);
if ($settings['panel']['adminmail_return'] != '') {
$mail->AddReplyTo($settings['panel']['adminmail_return'], $settings['panel']['adminmail_defname']);
$mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
if (Settings::Get('panel.adminmail_return') != '') {
$mail->AddReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname'));
}
}