get rid of storeSetting*-functions

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-19 19:58:14 +01:00
parent 26510f0745
commit d654b18517
15 changed files with 481 additions and 685 deletions

View File

@@ -1,86 +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
*
*/
function correctMysqlUsers($mysql_access_host_array) {
global $log;
// get sql-root access data
Database::needRoot(true);
Database::needSqlData();
$sql_root = Database::getSqlData();
Database::needRoot(false);
$dbservers_stmt = Database::query("SELECT DISTINCT `dbserver` FROM `".TABLE_PANEL_DATABASES."`");
$mysql_servers = '';
while ($dbserver = $dbservers_stmt->fetch(PDO::FETCH_ASSOC)) {
Database::needRoot(true, $dbserver['dbserver']);
Database::needSqlData();
$sql_root = Database::getSqlData();
$dbm = new DbManager($log);
$users = $dbm->getManager()->getAllSqlUsers(false);
$databases = array(
$sql_root['db']
);
$databases_result_stmt = Database::prepare("
SELECT * FROM `" . TABLE_PANEL_DATABASES . "`
WHERE `dbserver` = :mysqlserver
");
Database::pexecute($databases_result_stmt, array('mysqlserver' => $dbserver['dbserver']));
while ($databases_row = $databases_result_stmt->fetch(PDO::FETCH_ASSOC)) {
$databases[] = $databases_row['databasename'];
}
foreach ($databases as $username) {
if (isset($users[$username])
&& is_array($users[$username])
&& isset($users[$username]['hosts'])
&& is_array($users[$username]['hosts'])
) {
$password = $users[$username]['password'];
foreach ($mysql_access_host_array as $mysql_access_host) {
$mysql_access_host = trim($mysql_access_host);
if (!in_array($mysql_access_host, $users[$username]['hosts'])) {
$dbm->getManager()->grantPrivilegesTo($username, $password, $mysql_access_host, true);
}
}
foreach ($users[$username]['hosts'] as $mysql_access_host) {
if (!in_array($mysql_access_host, $mysql_access_host_array)) {
$dbm->getManager()->deleteUser($username, $mysql_access_host);
}
}
}
}
$dbm->getManager()->flushPrivileges();
Database::needRoot(false);
}
}

View File

@@ -20,9 +20,9 @@
function saveForm($fielddata, $newfieldvalue)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['save_method']) && $fielddata['save_method'] != '' && function_exists($fielddata['save_method']))
if(is_array($fielddata) && isset($fielddata['save_method']) && $fielddata['save_method'] != '')
{
$returnvalue = call_user_func($fielddata['save_method'], $fielddata, $newfieldvalue);
$returnvalue = call_user_func(array('\\Froxlor\\Settings\\Store', $fielddata['save_method']), $fielddata, $newfieldvalue);
}
elseif(is_array($fielddata) && !isset($fielddata['save_method']))
{

View File

@@ -16,20 +16,17 @@
* @package Functions
*
*/
function saveFormField($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['save_method']) && $fielddata['save_method'] != '' && function_exists($fielddata['save_method']))
{
$returnvalue = call_user_func($fielddata['save_method'], $fieldname, $fielddata, $newfieldvalue);
}
elseif(is_array($fielddata) && !isset($fielddata['save_method']))
{
if (is_array($fielddata) && isset($fielddata['save_method']) && $fielddata['save_method'] != '') {
$returnvalue = call_user_func(array(
'\\Froxlor\\Settings\\Store',
$fielddata['save_method']
), $fieldname, $fielddata, $newfieldvalue);
} elseif (is_array($fielddata) && ! isset($fielddata['save_method'])) {
$returnvalue = array();
}
else
{
} else {
$returnvalue = false;
}
return $returnvalue;

View File

@@ -16,15 +16,13 @@
* @package Functions
*
*/
function validateFieldDefinition($field)
{
$returnvalue = false;
if(is_array($field) && !empty($field) && isset($field['fields']) && is_array($field['fields']) && !empty($field['fields']))
{
if (is_array($field) && ! empty($field) && isset($field['fields']) && is_array($field['fields']) && ! empty($field['fields'])) {
$returnvalue = true;
}
return $returnvalue;
}

View File

@@ -1,37 +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 Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function storeSettingClearCertificates($fieldname, $fielddata, $newfieldvalue) {
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'system'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'le_froxlor_enabled'
&& $newfieldvalue == '0'
) {
Database::query("
DELETE FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = '0'
");
}
return $returnvalue;
}

View File

@@ -1,133 +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
*
*/
function storeSettingDefaultIp($fieldname, $fielddata, $newfieldvalue) {
$defaultips_old = Settings::Get('system.defaultip');
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'system'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'defaultip'
) {
$customerstddomains_result_stmt = Database::prepare("
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
");
Database::pexecute($customerstddomains_result_stmt);
$ids = array();
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(PDO::FETCH_ASSOC)) {
$ids[] = (int)$customerstddomains_row['standardsubdomain'];
}
if (count($ids) > 0) {
$defaultips_new = explode(',', $newfieldvalue);
// Delete the existing mappings linking to default IPs
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_DOMAINTOIP . "`
WHERE `id_domain` IN (" . implode(', ', $ids) . ")
AND `id_ipandports` IN (" . $defaultips_old . ", " . $newfieldvalue . ")
");
Database::pexecute($del_stmt);
// Insert the new mappings
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_DOMAINTOIP . "`
SET `id_domain` = :domainid, `id_ipandports` = :ipandportid
");
foreach ($ids as $id) {
foreach ($defaultips_new as $defaultip_new) {
Database::pexecute($ins_stmt, array('domainid' => $id, 'ipandportid' => $defaultip_new));
}
}
}
}
return $returnvalue;
}
function storeSettingDefaultSslIp($fieldname, $fielddata, $newfieldvalue) {
$defaultips_old = Settings::Get('system.defaultsslip');
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'system'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'defaultsslip'
) {
$customerstddomains_result_stmt = Database::prepare("
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
");
Database::pexecute($customerstddomains_result_stmt);
$ids = array();
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(PDO::FETCH_ASSOC)) {
$ids[] = (int)$customerstddomains_row['standardsubdomain'];
}
if (count($ids) > 0) {
$defaultips_new = explode(',', $newfieldvalue);
if (!empty($defaultips_old) && !empty($newfieldvalue))
{
$in_value = $defaultips_old . ", " . $newfieldvalue;
} elseif (!empty($defaultips_old) && empty($newfieldvalue))
{
$in_value = $defaultips_old;
} else {
$in_value = $newfieldvalue;
}
// Delete the existing mappings linking to default IPs
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_DOMAINTOIP . "`
WHERE `id_domain` IN (" . implode(', ', $ids) . ")
AND `id_ipandports` IN (" . $in_value . ")
");
Database::pexecute($del_stmt);
if (count($defaultips_new) > 0) {
// Insert the new mappings
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_DOMAINTOIP . "`
SET `id_domain` = :domainid, `id_ipandports` = :ipandportid
");
foreach ($ids as $id) {
foreach ($defaultips_new as $defaultip_new) {
Database::pexecute($ins_stmt, array('domainid' => $id, 'ipandportid' => $defaultip_new));
}
}
}
}
}
return $returnvalue;
}

View File

@@ -1,61 +0,0 @@
<?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 Functions
*
* @since 0.9.29.1
*
*/
/**
* updates the setting for the default panel-theme
* and also the user themes (customers and admins) if
* the changing of themes is disallowed for them
*
* @param string $fieldname
* @param array $fielddata
* @param mixed $newfieldvalue
*
* @return boolean|array
*/
function storeSettingDefaultTheme($fieldname, $fielddata, $newfieldvalue) {
// first save the setting itself
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'panel'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'default_theme'
) {
// now, if changing themes is disabled we recursivly set
// the new theme (customers and admin, depending on settings)
if (Settings::Get('panel.allow_theme_change_customer') == '0') {
$upd_stmt = Database::prepare("
UPDATE `".TABLE_PANEL_CUSTOMERS."` SET `theme` = :theme
");
Database::pexecute($upd_stmt, array('theme' => $newfieldvalue));
}
if (Settings::Get('panel.allow_theme_change_admin') == '0') {
$upd_stmt = Database::prepare("
UPDATE `".TABLE_PANEL_ADMINS."` SET `theme` = :theme
");
Database::pexecute($upd_stmt, array('theme' => $newfieldvalue));
}
}
return $returnvalue;
}

View File

@@ -1,74 +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
*
*/
function storeSettingField($fieldname, $fielddata, $newfieldvalue) {
if (is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] != ''
&& isset($fielddata['varname'])
&& $fielddata['varname'] != ''
) {
if (Settings::Set($fielddata['settinggroup'].'.'.$fielddata['varname'], $newfieldvalue) !== false) {
/*
* when fielddata[cronmodule] is set, this means enable/disable a cronjob
*/
if (isset($fielddata['cronmodule'])
&& $fielddata['cronmodule'] != ''
) {
toggleCronStatus($fielddata['cronmodule'], $newfieldvalue);
}
/*
* satisfy dependencies
*/
if (isset($fielddata['dependency'])
&& is_array($fielddata['dependency'])
) {
if ((int)$fielddata['dependency']['onlyif'] == (int)$newfieldvalue) {
storeSettingField($fielddata['dependency']['fieldname'], $fielddata['dependency']['fielddata'], $newfieldvalue);
}
}
return array($fielddata['settinggroup'] . '.' . $fielddata['varname'] => $newfieldvalue);
} else {
return false;
}
} else {
return false;
}
}
function storeSettingFieldInsertBindTask($fieldname, $fielddata, $newfieldvalue) {
if (is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] != ''
&& isset($fielddata['varname'])
&& $fielddata['varname'] != ''
) {
if (Settings::Set($fielddata['settinggroup'].'.'.$fielddata['varname'], $newfieldvalue) !== false) {
return array($fielddata['settinggroup'] . '.' . $fielddata['varname'] => $newfieldvalue);
} else {
return false;
}
} else {
return false;
}
}

View File

@@ -1,57 +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
*
*/
function storeSettingHostname($fieldname, $fielddata, $newfieldvalue) {
global $idna_convert;
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'system'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'hostname'
) {
$newfieldvalue = $idna_convert->encode($newfieldvalue);
$customerstddomains_result_stmt = Database::prepare("
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
");
Database::pexecute($customerstddomains_result_stmt);
$ids = array();
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(PDO::FETCH_ASSOC)) {
$ids[] = (int)$customerstddomains_row['standardsubdomain'];
}
if (count($ids) > 0) {
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_DOMAINS . "` SET
`domain` = REPLACE(`domain`, :host, :newval)
WHERE `id` IN ('" . implode(', ', $ids) . "')
");
Database::pexecute($upd_stmt, array('host' => Settings::Get('system.hostname'), 'newval' => $newfieldvalue));
}
}
return $returnvalue;
}

View File

@@ -1,40 +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
*
*/
function storeSettingIpAddress($fieldname, $fielddata, $newfieldvalue) {
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'system'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'ipaddress'
) {
$mysql_access_host_array = array_map('trim', explode(',', Settings::Get('system.mysql_access_host')));
$mysql_access_host_array[] = $newfieldvalue;
$mysql_access_host_array = array_unique(array_trim($mysql_access_host_array));
$mysql_access_host = implode(',', $mysql_access_host_array);
correctMysqlUsers($mysql_access_host_array);
Settings::Set('system.mysql_access_host', $mysql_access_host);
}
return $returnvalue;
}

View File

@@ -1,51 +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
*
*/
function storeSettingMysqlAccessHost($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'mysql_access_host') {
$mysql_access_host_array = array_map('trim', explode(',', $newfieldvalue));
if (in_array('127.0.0.1', $mysql_access_host_array) && ! in_array('localhost', $mysql_access_host_array)) {
$mysql_access_host_array[] = 'localhost';
}
if (! in_array('127.0.0.1', $mysql_access_host_array) && in_array('localhost', $mysql_access_host_array)) {
$mysql_access_host_array[] = '127.0.0.1';
}
// be aware that ipv6 addresses are enclosed in [ ] when passed here
$mysql_access_host_array = array_map('cleanMySQLAccessHost', $mysql_access_host_array);
$mysql_access_host_array = array_unique(array_trim($mysql_access_host_array));
$newfieldvalue = implode(',', $mysql_access_host_array);
correctMysqlUsers($mysql_access_host_array);
}
return $returnvalue;
}
function cleanMySQLAccessHost($value)
{
if (substr($value, 0, 1) == '[' && substr($value, - 1) == ']') {
return substr($value, 1, - 1);
}
return $value;
}

View File

@@ -1,50 +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 Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
function storeSettingResetCatchall($fieldname, $fielddata, $newfieldvalue) {
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false
&& is_array($fielddata)
&& isset($fielddata['settinggroup'])
&& $fielddata['settinggroup'] == 'catchall'
&& isset($fielddata['varname'])
&& $fielddata['varname'] == 'catchall_enabled'
&& $newfieldvalue == '0'
) {
$result_stmt = Database::query("
SELECT `id`, `email`, `email_full`, `iscatchall` FROM `" . TABLE_MAIL_VIRTUAL . "`
WHERE `iscatchall` = '1'
");
if (Database::num_rows() > 0) {
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = :email, `iscatchall` = '0' WHERE `id` = :id
");
while ($result_row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
Database::pexecute($upd_stmt, array('email' => $result_row['email_full'], 'id' => $result_row['id']));
}
}
}
return $returnvalue;
}

View File

@@ -1,58 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2015 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 Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
* @since 0.9.34
*/
/**
* Whenever the webserver- / FCGID- or FPM-user gets updated
* we need to update ftp_groups accordingly
*/
function storeSettingWebserverFcgidFpmUser($fieldname, $fielddata, $newfieldvalue)
{
if (is_array($fielddata) && isset($fielddata['settinggroup']) && isset($fielddata['varname'])) {
$update_user = null;
// webserver
if ($fielddata['settinggroup'] == 'system' && $fielddata['varname'] == 'httpuser') {
$update_user = Settings::Get('system.httpuser');
}
// fcgid
if ($fielddata['settinggroup'] == 'system' && $fielddata['varname'] == 'mod_fcgid_httpuser') {
$update_user = Settings::Get('system.mod_fcgid_httpuser');
}
// webserver
if ($fielddata['settinggroup'] == 'phpfpm' && $fielddata['varname'] == 'vhost_httpuser') {
$update_user = Settings::Get('phpfpm.vhost_httpuser');
}
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if ($returnvalue !== false) {
/**
* only update if anything changed
*/
if ($update_user != null && $newfieldvalue != $update_user) {
$upd_stmt = Database::prepare("UPDATE `" . TABLE_FTP_GROUPS . "` SET `members` = REPLACE(`members`, :olduser, :newuser)");
Database::pexecute($upd_stmt, array('olduser' => $update_user, 'newuser' => $newfieldvalue));
}
}
}
return $returnvalue;
}