/**
 * 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;
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (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 (saveSetting($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;
    }
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (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("\n\t\t\tSELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'\n\t\t");
        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("\n\t\t\t\t\tDELETE FROM `" . TABLE_DOMAINTOIP . "`\n\t\t\t\t\tWHERE `id_domain` IN (" . implode(', ', $ids) . ")\n\t\t\t\t\tAND `id_ipandports` IN (" . $defaultips_old . ", " . $newfieldvalue . ")\n\t\t\t");
            Database::pexecute($del_stmt);
            // Insert the new mappings
            $ins_stmt = Database::prepare("\n\t\t\t\tINSERT INTO `" . TABLE_DOMAINTOIP . "`\n\t\t\t\tSET `id_domain` = :domainid, `id_ipandports` = :ipandportid\n\t\t\t");
            foreach ($ids as $id) {
                foreach ($defaultips_new as $defaultip_new) {
                    Database::pexecute($ins_stmt, array('domainid' => $id, 'ipandportid' => $defaultip_new));
                }
            }
        }
    }
    return $returnvalue;
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (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;
}
/**
 * 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 <*****@*****.**> (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("\n\t\t\tSELECT `id`, `email`, `email_full`, `iscatchall`  FROM `" . TABLE_MAIL_VIRTUAL . "`\n\t\t\tWHERE `iscatchall` = '1'\n\t\t");
        if (Database::num_rows() > 0) {
            $upd_stmt = Database::prepare("\n\t\t\t\tUPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `email` = :email, `iscatchall` = '0' WHERE `id` = :id\n\t\t\t");
            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;
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function storeSettingApsPhpExtensions($fieldname, $fielddata, $newfieldvalue)
{
    $returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
    if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'aps' && isset($fielddata['varname']) && $fielddata['varname'] == 'php-extension') {
        $newfieldvalue_array = explode(',', $newfieldvalue);
        if (in_array('mcrypt', $newfieldvalue_array)) {
            $functions = 'mcrypt_encrypt,mcrypt_decrypt';
        } else {
            $functions = '';
        }
        if ($functions != getSetting('aps', 'php-function')) {
            saveSetting('aps', 'php-function', $functions);
        }
    }
    return $returnvalue;
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function storeSettingDefaultIp($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'] == 'defaultip') {
        global $db;
        $customerstddomains_result = $db->query('SELECT `standardsubdomain` FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `standardsubdomain` <> \'0\'');
        $ids = array();
        while ($customerstddomains_row = $db->fetch_array($customerstddomains_result)) {
            $ids[] = (int) $customerstddomains_row['standardsubdomain'];
        }
        if (count($ids) > 0) {
            $db->query('UPDATE `' . TABLE_PANEL_DOMAINS . '` SET `ipandport`=\'' . (int) $newfieldvalue . '\' WHERE `id` IN (\'' . implode('\',\'', $ids) . '\') AND `ipandport` = \'' . $db->escape(getSetting('system', 'defaultip')) . '\'');
        }
    }
    return $returnvalue;
}
/**
 * This file is part of the SysCP project.
 * Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**>
 * @license    GPLv2 http://files.syscp.org/misc/COPYING.txt
 *
 * @version    $Id$
 */
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';
        }
        $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;
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function storeSettingDefaultIp($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'] == 'defaultip') {
        $customerstddomains_result_stmt = Database::prepare("\n\t\t\tSELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'\n\t\t");
        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("\n\t\t\t\tUPDATE `" . TABLE_DOMAINTOIP . "` SET\n\t\t\t\t`id_ipandports` = :newval\n\t\t\t\tWHERE `id_domain` IN ('" . implode(', ', $ids) . "')\n\t\t\t\tAND `id_ipandports` = :defaultip\n\t\t\t");
            Database::pexecute($upd_stmt, array('newval' => $newfieldvalue, 'defaultip' => Settings::Get('system.defaultip')));
        }
    }
    return $returnvalue;
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function storeSettingHostname($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'] == 'hostname') {
        global $db, $idna_convert;
        $newfieldvalue = $idna_convert->encode($newfieldvalue);
        $customerstddomains_result = $db->query('SELECT `standardsubdomain` FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `standardsubdomain` <> \'0\'');
        $ids = array();
        while ($customerstddomains_row = $db->fetch_array($customerstddomains_result)) {
            $ids[] = (int) $customerstddomains_row['standardsubdomain'];
        }
        if (count($ids) > 0) {
            $db->query('UPDATE `' . TABLE_PANEL_DOMAINS . '` SET `domain` = REPLACE(`domain`, \'' . $db->escape(getSetting('system', 'hostname')) . '\', \'' . $db->escape($newfieldvalue) . '\') WHERE `id` IN (\'' . implode('\',\'', $ids) . '\')');
        }
    }
    return $returnvalue;
}
/**
 * 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("\n\t\t\t\tUPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `theme` = :theme\n\t\t\t");
            Database::pexecute($upd_stmt, array('theme' => $newfieldvalue));
        }
        if (Settings::Get('panel.allow_theme_change_admin') == '0') {
            $upd_stmt = Database::prepare("\n\t\t\t\tUPDATE `" . TABLE_PANEL_ADMINS . "` SET `theme` = :theme\n\t\t\t");
            Database::pexecute($upd_stmt, array('theme' => $newfieldvalue));
        }
    }
    return $returnvalue;
}
/**
 * This file is part of the SysCP project.
 * Copyright (c) 2003-2009 the SysCP 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.syscp.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**>
 * @license    GPLv2 http://files.syscp.org/misc/COPYING.txt
 *
 * @version    $Id$
 */
function storeSettingApsWebserverModules($fieldname, $fielddata, $newfieldvalue)
{
    if (is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'aps' && isset($fielddata['varname']) && $fielddata['varname'] == 'webserver-module') {
        $newfieldvalue_array = explode(',', $newfieldvalue);
        if (in_array('mod_rewrite', $newfieldvalue_array)) {
            // Don't have to guess if we have to remove the leading comma as mod_rewrite is set anyways when we're here...
            $newfieldvalue .= ',mod_rewrite.c';
        }
        if (in_array('htaccess', $newfieldvalue_array)) {
            $htaccess = 'htaccess';
        } else {
            $htaccess = '';
        }
        if ($htaccess != getSetting('aps', 'webserver-htaccess')) {
            saveSetting('aps', 'webserver-htaccess', $htaccess);
        }
    }
    return storeSettingField($fieldname, $fielddata, $newfieldvalue);
}
/**
 * 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 <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (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("\n\t\t\tSELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'\n\t\t");
        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("\n\t\t\t\tUPDATE `" . TABLE_PANEL_DOMAINS . "` SET\n\t\t\t\t`domain` = REPLACE(`domain`, :host, :newval)\n\t\t\t\tWHERE `id` IN ('" . implode(', ', $ids) . "')\n\t\t\t");
            Database::pexecute($upd_stmt, array('host' => Settings::Get('system.hostname'), 'newval' => $newfieldvalue));
        }
    }
    return $returnvalue;
}