Example #1
0
/**
 * Prepare content for writing to the config.php file
 *
 * @param array $params
 *
 * @return void
 */
function change_config(&$params)
{
    global $installation_auth_code;
    static $pairs = array('hostspec' => 'mysqlhost', 'database' => 'mysqlbase', 'username' => 'mysqluser', 'password' => 'mysqlpass', 'table_prefix' => 'mysqlprefix', 'port' => 'mysqlport', 'socket' => 'mysqlsock', 'http_host' => 'xlite_http_host', 'https_host' => 'xlite_https_host', 'web_dir' => 'xlite_web_dir');
    // check whether config file is writable
    clearstatcache();
    if (!@is_readable(LC_DIR_CONFIG . constant('LC_CONFIG_FILE')) || !@is_writable(LC_DIR_CONFIG . constant('LC_CONFIG_FILE'))) {
        return false;
    }
    // read file content
    if (!($config = file(LC_DIR_CONFIG . constant('LC_CONFIG_FILE')))) {
        return false;
    }
    $params['xlite_http_host'] = x_install_get_host($params['xlite_http_host']);
    // fixing the empty xlite_https_host value
    if (!isset($params['xlite_https_host']) || $params['xlite_https_host'] == '') {
        $params['xlite_https_host'] = $params['xlite_http_host'];
    }
    $_params = $params;
    // check whether the authcode is set in params.
    $new_config = '';
    // change config file ..
    foreach ($config as $num => $line) {
        $patterns = array();
        $replacements = array();
        foreach ($pairs as $pk => $pv) {
            $patterns[] = '/^' . $pk . '\\s*=.*/';
            $replacements[] = $pk . ' = "' . (empty($_params[$pv]) ? '' : $_params[$pv]) . '"';
        }
        $patterns[] = '/^shared_secret_key.*=.*/';
        $replacements[] = 'shared_secret_key = "' . uniqid('', true) . '"';
        // check whether skin param is specified: not used at present
        if (isset($_params['skin'])) {
            $patterns[] = '/^skin.*=.*/';
            $replacements[] = 'skin = "' . $params['skin'] . '"';
        }
        $patterns[] = '/^installation_lng.*=.*/';
        $replacements[] = 'installation_lng = ' . XLITE_EDITION_LNG;
        $patterns[] = '/^default = [a-z]{2}/';
        $replacements[] = 'default = ' . XLITE_EDITION_LNG;
        // escape every backslash and dollar sign with a backslash
        // to avoid using them as backreferences
        $replacements = array_map(function ($replacement) {
            return strtr($replacement, array('\\\\' => '\\\\\\\\', '$' => '\\$'));
        }, $replacements);
        $new_config .= preg_replace($patterns, $replacements, $line);
    }
    return save_config($new_config);
}
Example #2
0
/**
 * Prepare content for writing to the config.php file
 *
 * @param array $params
 *
 * @return void
 */
function change_config(&$params)
{
    global $installation_auth_code;
    // check whether config file is writable
    clearstatcache();
    if (!@is_readable(LC_DIR_CONFIG . constant('LC_CONFIG_FILE')) || !@is_writable(LC_DIR_CONFIG . constant('LC_CONFIG_FILE'))) {
        return false;
    }
    // read file content
    if (!($config = file(LC_DIR_CONFIG . constant('LC_CONFIG_FILE')))) {
        return false;
    }
    $params['xlite_http_host'] = x_install_get_host($params['xlite_http_host']);
    // fixing the empty xlite_https_host value
    if (!isset($params['xlite_https_host']) || $params['xlite_https_host'] == '') {
        $params['xlite_https_host'] = $params['xlite_http_host'];
    }
    $_params = $params;
    if (!isset($_params['mysqlpass'])) {
        $_params['mysqlpass'] = '';
    }
    if (!isset($_params['mysqlport'])) {
        $_params['mysqlport'] = '';
    }
    if (!isset($_params['mysqlsock'])) {
        $_params['mysqlsock'] = '';
    }
    // check whether the authcode is set in params.
    $new_config = '';
    // change config file ..
    foreach ($config as $num => $line) {
        $patterns = array('/^hostspec.*=.*/', '/^database.*=.*/', '/^username.*=.*/', '/^password.*=.*/', '/^port.*=.*/', '/^socket.*=.*/', '/^http_host.*=.*/', '/^https_host.*=.*/', '/^web_dir.*=.*/', '/^shared_secret_key.*=.*/');
        $replacements = array('hostspec = "' . $_params['mysqlhost'] . '"', 'database = "' . $_params['mysqlbase'] . '"', 'username = "******"', 'password = "******"', 'port     = "' . $_params['mysqlport'] . '"', 'socket   = "' . $_params['mysqlsock'] . '"', 'http_host = "' . $_params['xlite_http_host'] . '"', 'https_host = "' . $_params['xlite_https_host'] . '"', 'web_dir = "' . $_params['xlite_web_dir'] . '"', 'shared_secret_key = "' . uniqid('', true) . '"');
        // check whether skin param is specified: not used at present
        if (isset($_params['skin'])) {
            $patterns[] = '/^skin.*=.*/';
            $replacements[] = 'skin = "' . $params['skin'] . '"';
        }
        $new_config .= preg_replace($patterns, $replacements, $line);
    }
    return save_config($new_config);
}