diff --git a/common/defaults/config.php b/common/defaults/config.php index 20c3d7894..7550f7af4 100644 --- a/common/defaults/config.php +++ b/common/defaults/config.php @@ -5,3 +5,103 @@ * * Copyright (c) Rhymix Developers and Contributors */ +return array( + 'config_version' => '2.0', + 'db' => array( + 'master' => array( + 'type' => 'mysql', + 'host' => 'localhost', + 'port' => 3306, + 'user' => null, + 'pass' => null, + 'database' => null, + 'prefix' => null, + 'charset' => null, + 'engine' => null, + ), + ), + 'cache' => array(), + 'ftp' => array( + 'host' => 'localhost', + 'port' => 21, + 'path' => null, + 'user' => null, + 'pass' => null, + 'pasv' => true, + 'sftp' => false, + ), + 'crypto' => array( + 'encryption_key' => null, + 'authentication_key' => null, + 'session_key' => null, + ), + 'locale' => array( + 'default_lang' => 'ko', + 'enabled_lang' => array('ko'), + 'default_timezone' => 'Asia/Seoul', + 'internal_timezone' => 32400, + ), + 'url' => array( + 'default' => null, + 'http_port' => null, + 'https_port' => null, + 'ssl' => 'none', + ), + 'session' => array( + 'delay' => false, + 'use_db' => false, + 'domain' => null, + 'path' => null, + 'lifetime' => 0, + 'refresh' => 300, + ), + 'file' => array( + 'umask' => '022', + ), + 'mail' => array( + 'transport' => 'mail', + 'smtp_host' => null, + 'smtp_port' => null, + 'smtp_security' => 'none', + 'smtp_user' => null, + 'smtp_pass' => null, + 'api_domain' => null, + 'api_token' => null, + 'api_user' => null, + 'api_pass' => null, + ), + 'view' => array( + 'minify_scripts' => 'common', + 'concat_scripts' => 'none', + 'use_gzip' => false, + ), + 'admin' => array( + 'allow' => array(), + 'deny' => array(), + ), + 'lock' => array( + 'locked' => false, + 'title' => 'Maintenance', + 'message' => '', + 'allow' => array(), + ), + 'debug' => array( + 'enabled' => true, + 'log_errors' => true, + 'log_queries' => false, + 'log_slow_queries' => 1, + 'log_slow_triggers' => 1, + 'log_slow_widgets' => 1, + 'display_type' => 'comment', + 'display_to' => 'admin', + 'allow' => array(), + ), + 'embedfilter' => array( + 'iframe' => array(), + 'object' => array(), + ), + 'use_mobile_view' => true, + 'use_prepared_statements' => true, + 'use_rewrite' => true, + 'use_sso' => false, +); diff --git a/common/framework/config.php b/common/framework/config.php new file mode 100644 index 000000000..aad54dc90 --- /dev/null +++ b/common/framework/config.php @@ -0,0 +1,358 @@ +master_db)) + { + $db_info->master_db = array(); + $db_info->master_db['db_type'] = $db_info->db_type; + $db_info->master_db['db_hostname'] = $db_info->db_hostname; + $db_info->master_db['db_port'] = $db_info->db_port; + $db_info->master_db['db_userid'] = $db_info->db_userid; + $db_info->master_db['db_password'] = $db_info->db_password; + $db_info->master_db['db_database'] = $db_info->db_database; + $db_info->master_db['db_table_prefix'] = $db_info->db_table_prefix; + } + + $config['db']['master']['type'] = strtolower($db_info->master_db['db_type']); + $config['db']['master']['host'] = $db_info->master_db['db_hostname']; + $config['db']['master']['port'] = $db_info->master_db['db_port']; + $config['db']['master']['user'] = $db_info->master_db['db_userid']; + $config['db']['master']['pass'] = $db_info->master_db['db_password']; + $config['db']['master']['database'] = $db_info->master_db['db_database']; + $config['db']['master']['prefix'] = $db_info->master_db['db_table_prefix']; + + if (substr($config['db']['master']['prefix'], -1) !== '_') + { + $config['db']['master']['prefix'] .= '_'; + } + + $config['db']['master']['charset'] = $db_info->master_db['db_charset'] ?: 'utf8'; + + if (strpos($config['db']['master']['type'], 'innodb') !== false) + { + $config['db']['master']['type'] = str_replace('_innodb', '', $config['db']['master']['type']); + $config['db']['master']['engine'] = 'innodb'; + } + elseif (strpos($config['db']['master']['type'], 'mysql') !== false) + { + $config['db']['master']['engine'] = 'myisam'; + } + + if (isset($db_info->slave_db) && count($db_info->slave_db)) + { + foreach ($db_info->slave_db as $slave_id => $slave_db) + { + if ($slave_db !== $db_info->master_db) + { + $slave_id = 'slave' . $slave_id; + $config['db'][$slave_id]['type'] = strtolower($slave_db['db_type']); + $config['db'][$slave_id]['host'] = $slave_db['db_hostname']; + $config['db'][$slave_id]['port'] = $slave_db['db_type']; + $config['db'][$slave_id]['user'] = $slave_db['db_userid']; + $config['db'][$slave_id]['pass'] = $slave_db['db_password']; + $config['db'][$slave_id]['database'] = $slave_db['db_database']; + $config['db'][$slave_id]['prefix'] = $slave_db['db_table_prefix']; + + if (substr($config['db'][$slave_id]['prefix'], -1) !== '_') + { + $config['db'][$slave_id]['prefix'] .= '_'; + } + + $config['db'][$slave_id]['charset'] = $slave_db['db_charset'] ?: 'utf8'; + + if (strpos($config['db'][$slave_id]['type'], 'innodb') !== false) + { + $config['db'][$slave_id]['type'] = str_replace('_innodb', '', $config['db'][$slave_id]['type']); + $config['db'][$slave_id]['engine'] = 'innodb'; + } + elseif (strpos($config['db'][$slave_id]['type'], 'mysql') !== false) + { + $config['db'][$slave_id]['engine'] = 'myisam'; + } + } + } + } + + // Convert cache configuration. + if (isset($db_info->use_object_cache)) + { + $config['cache'][] = $db_info->use_object_cache; + } + + // Convert FTP configuration. + if (isset($ftp_info)) + { + $config['ftp']['host'] = $ftp_info->ftp_host; + $config['ftp']['port'] = $ftp_info->ftp_port; + $config['ftp']['path'] = $ftp_info->ftp_root_path; + $config['ftp']['user'] = $ftp_info->ftp_user; + $config['ftp']['pasv'] = $ftp_info->ftp_pasv; + $config['ftp']['sftp'] = $ftp_info->sftp === 'Y' ? true : false; + } + + // Create new crypto keys. + $config['crypto']['encryption_key'] = \Password::createSecureSalt(64, 'alnum'); + $config['crypto']['authentication_key'] = \Password::createSecureSalt(64, 'alnum'); + $config['crypto']['session_key'] = \Password::createSecureSalt(64, 'alnum'); + + // Convert language configuration. + if (isset($db_info->lang_type)) + { + $config['locale']['default_lang'] = str_replace('jp', 'ja', strtolower($db_info->lang_type)); + } + elseif (count($lang_selected)) + { + $config['locale']['default_lang'] = array_first($lang_selected); + } + $config['locale']['enabled_lang'] = array_values($lang_selected); + + // Convert timezone configuration. + $old_timezone = intval(get_time_zone_offset($db_info->time_zone ?: '+0900') / 3600); + switch ($old_timezone) + { + case 9: + $config['locale']['default_timezone'] = 'Asia/Seoul'; break; + case 0: + $config['locale']['default_timezone'] = 'Etc/UTC'; break; + default: + $config['locale']['default_timezone'] = 'Etc/GMT' . ($old_timezone > 0 ? '-' : '+') . abs($old_timezone); + } + $config['locale']['internal_timezone'] = intval(date('Z')); + + // Convert URL configuration. + $config['url']['default'] = $db_info->default_url ?: \RX_BASEURL; + $config['url']['http_port'] = $db_info->http_port ?: null; + $config['url']['https_port'] = $db_info->https_port ?: null; + $config['url']['ssl'] = $db_info->use_ssl ?: 'none'; + + // Convert session configuration. + $config['session']['delay'] = $db_info->delay_session === 'Y' ? true : false; + $config['session']['use_db'] = $db_info->use_db_session === 'Y' ? true : false; + + // Convert view configuration. + $config['view']['minify_scripts'] = $db_info->minify_scripts ?: 'common'; + $config['view']['use_gzip'] = (defined('__OB_GZHANDLER_ENABLE__') && constant('__OB_GZHANDLER_ENABLE__')); + + // Convert admin IP whitelist. + if (isset($db_info->admin_ip_list) && is_array($db_info->admin_ip_list) && count($db_info->admin_ip_list)) + { + $config['admin']['allow'] = array_values($db_info->admin_ip_list); + } + + // Convert sitelock configuration. + $config['lock']['locked'] = $db_info->use_sitelock === 'Y' ? true : false; + $config['lock']['title'] = strval($db_info->sitelock_title); + $config['lock']['message'] = strval($db_info->sitelock_message); + $config['lock']['allow'] = is_array($db_info->sitelock_whitelist) ? array_values($db_info->sitelock_whitelist) : array(); + + // Convert debug configuration. + $config['debug']['enabled'] = true; + $config['debug']['log_errors'] = true; + $config['debug']['log_queries'] = (\__DEBUG__ & 4) ? true : false; + $config['debug']['log_slow_queries'] = floatval(\__LOG_SLOW_QUERY__); + $config['debug']['log_slow_triggers'] = floatval(\__LOG_SLOW_TRIGGER__ * 1000); + $config['debug']['log_slow_widgets'] = floatval(\__LOG_SLOW_WIDGET__ * 1000); + + // Convert embed filter configuration. + if (is_array($db_info->embed_white_iframe)) + { + $whitelist = array_unique(array_map(function($item) { + return preg_match('@^https?://(.*)$@i', $item, $matches) ? $matches[1] : $item; + }, $db_info->embed_white_iframe)); + natcasesort($whitelist); + $config['embedfilter']['iframe'] = $whitelist; + } + if (is_array($db_info->embed_white_object)) + { + $whitelist = array_unique(array_map(function($item) { + return preg_match('@^https?://(.*)$@i', $item, $matches) ? $matches[1] : $item; + }, $db_info->embed_white_object)); + natcasesort($whitelist); + $config['embedfilter']['object'] = $whitelist; + } + + // Convert miscellaneous configuration. + $config['use_mobile_view'] = $db_info->use_mobile_view === 'Y' ? true : false; + $config['use_prepared_statements'] = $db_info->use_prepared_statements === 'Y' ? true : false; + $config['use_rewrite'] = $db_info->use_rewrite === 'Y' ? true : false; + $config['use_sso'] = $db_info->use_sso === 'Y' ? true : false; + + // Return the new configuration. + return $config; + } + + /** + * Save the current system configuration. + * + * @return bool + */ + public static function save() + { + if (!count(self::$_config)) + { + self::init(); + } + $buff = '\s+array\(\n/', "=> array(\n", $value); + $value = preg_replace('/array\(\s*\n\s*\)/', 'array()', $value); + $value = preg_replace_callback('/\n(\x20+)/', function($m) { + return "\n" . str_repeat("\t", intval(strlen($m[1]) / 2)); + }, $value); + $value = preg_replace('/\n(\t+)[0-9]+ => /', "\n\$1", $value); + return $value; + } + else + { + return var_export($value, true); + } + } +}