Skip to content

Commit

Permalink
NOISSUE db.config.php 파일 생성 시 var_export()를 사용하도록 변경
Browse files Browse the repository at this point in the history
- 코드 단순화 및 기타 설정 추가 시 처리 문제 단순화
  • Loading branch information
bnu committed Jan 24, 2014
1 parent 1c1f117 commit 7659e25
Showing 1 changed file with 9 additions and 56 deletions.
65 changes: 9 additions & 56 deletions modules/install/install.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,71 +523,24 @@ function installModule($module, $module_path)
return new Object();
}

function _getDbConnText($key, $val, $with_array = false)
function _getDBConfigFileContents($db_info)
{
$buff = array("\$db_info->$key = ");
if($with_array) $buff[] = "array(";
else $val = array($val);
if(substr($db_info->master_db['db_table_prefix'], -1) != '_')
{
$db_info->master_db['db_table_prefix'] .= '_';
}

foreach($val as $con_string)
foreach($db_info->slave_db as &$slave)
{
$buff[] = 'array(';
foreach($con_string as $k => $v)
if(substr($slave['db_table_prefix'], -1) != '_')
{
if($k == 'resource' || $k == 'is_connected') continue;
if($k == 'db_table_prefix' && !empty($v) && substr($v,-1)!='_') $v .= '_';
$buff[] = "'$k' => '$v',";
$slave['db_table_prefix'] .= '_';
}
$buff[] = ($with_array) ? '),' : ')';
}

if($with_array) $buff[] = ')';

return join(PHP_EOL, $buff) . ';' . PHP_EOL;
}

function _getDBConfigFileContents($db_info)
{
$buff = array();
$buff[] = '<?php if(!defined("__XE__")) exit();';
$buff[] = '$db_info = new stdClass;';

$db_info = get_object_vars($db_info);
foreach($db_info as $key => $val)
{
if($key == 'master_db')
{
$tmpValue = $this->_getDbConnText($key, $val);
}
else if($key == 'slave_db')
{
$tmpValue = $this->_getDbConnText($key, $val, true);
}
else if($key == 'sitelock_whitelist' || $key == 'admin_ip_list')
{
if(!is_array($val))
continue;
$tmpValue = sprintf('$db_info->%s = array(\'%s\');' . PHP_EOL, $key, implode('\', \'', $val));
}
else
{
if($key == 'default_url')
{
$tmpValue = sprintf("\$db_info->%s = '%s';" . PHP_EOL, $key, addslashes($val));
}
else
{
$tmpValue = sprintf("\$db_info->%s = '%s';" . PHP_EOL, $key, str_replace("'","\\'",$val));
}
}

if(preg_match('/(<\?|<\?php|\?>|fputs|fopen|fwrite|fgets|fread|\/\*|\*\/|chr\()/xsm', preg_replace('/\s/', '', $tmpValue)))
{
throw new Exception('msg_invalid_request');
}

$buff[] = $tmpValue;
}
$buff[] = '$db_info = (object)' . var_export(get_object_vars($db_info), TRUE) . ';';

return implode(PHP_EOL, $buff);
}
Expand Down

0 comments on commit 7659e25

Please sign in to comment.