인스톨시 기존 데이터베이스가 존재하는지 체크과정 추가
This commit is contained in:
53
install/ajax.install.check.php
Normal file
53
install/ajax.install.check.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
include_once ('../config.php');
|
||||
include_once('../lib/json.lib.php');
|
||||
include_once('../lib/common.lib.php'); // 공통 라이브러리
|
||||
include_once('./install.function.php'); // 인스톨 과정 함수 모음
|
||||
|
||||
$data_path = '../'.G5_DATA_DIR;
|
||||
|
||||
// 파일이 존재한다면 설치할 수 없다.
|
||||
$dbconfig_file = $data_path.'/'.G5_DBCONFIG_FILE;
|
||||
if (file_exists($dbconfig_file)) {
|
||||
die(install_json_msg('프로그램이 이미 설치되어 있습니다.'));
|
||||
}
|
||||
|
||||
$mysql_host = safe_install_string_check($_POST['mysql_host'], 'json');
|
||||
$mysql_user = safe_install_string_check($_POST['mysql_user'], 'json');
|
||||
$mysql_pass = safe_install_string_check($_POST['mysql_pass'], 'json');
|
||||
$mysql_db = safe_install_string_check($_POST['mysql_db'], 'json');
|
||||
$table_prefix= safe_install_string_check($_POST['table_prefix']);
|
||||
|
||||
$tmp_str = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
|
||||
$ajax_token = md5($tmp_str.$_SERVER['REMOTE_ADDR'].$_SERVER['DOCUMENT_ROOT']);
|
||||
|
||||
$bool_ajax_token = ($ajax_token == $_POST['ajax_token']) ? true : false;
|
||||
|
||||
if( !($mysql_host && $mysql_user && $mysql_pass && $mysql_db && $table_prefix && $bool_ajax_token) ){
|
||||
die(install_json_msg('잘못된 요청입니다.'));
|
||||
}
|
||||
|
||||
try {
|
||||
$dblink = sql_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (!$dblink) {
|
||||
die(install_json_msg('MySQL Host, User, Password 를 확인해 주십시오.'));
|
||||
}
|
||||
|
||||
try {
|
||||
$select_db = sql_select_db($mysql_db, $dblink);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
if (!$select_db) {
|
||||
die(install_json_msg('MySQL DB 를 확인해 주십시오.'));
|
||||
}
|
||||
|
||||
if(sql_query("DESCRIBE `{$table_prefix}config`", G5_DISPLAY_SQL_ERROR, $dblink)) {
|
||||
die(install_json_msg('주의! 이미 테이블이 존재하므로, 기존 DB 자료가 망실됩니다. 계속 진행하겠습니까?', 'exists'));
|
||||
}
|
||||
|
||||
die(install_json_msg('ok', 'success'));
|
||||
?>
|
||||
40
install/install.function.php
Normal file
40
install/install.function.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
||||
|
||||
if( ! function_exists('safe_install_string_check') ){
|
||||
function safe_install_string_check( $str, $is_json=false ) {
|
||||
$is_check = false;
|
||||
|
||||
if(preg_match('#\);(passthru|eval|pcntl_exec|exec|system|popen|fopen|fsockopen|file|file_get_contents|readfile|unlink|include|include_once|require|require_once)\s?#i', $str)) {
|
||||
$is_check = true;
|
||||
}
|
||||
|
||||
if(preg_match('#\$_(get|post|request)\s?\[.*?\]\s?\)#i', $str)){
|
||||
$is_check = true;
|
||||
}
|
||||
|
||||
if($is_check){
|
||||
$msg = "입력한 값에 안전하지 않는 문자가 포함되어 있습니다. 설치를 중단합니다.";
|
||||
|
||||
if($is_json){
|
||||
die(install_json_msg($msg));
|
||||
}
|
||||
|
||||
die($msg);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
if( ! function_exists('install_json_msg') ){
|
||||
function install_json_msg($msg, $type='error'){
|
||||
|
||||
$error_msg = ($type==='error') ? $msg : '';
|
||||
$success_msg = ($type==='success') ? $msg : '';
|
||||
$exists_msg = ($type==='exists') ? $msg : '';
|
||||
|
||||
return json_encode(array('error'=>$error_msg, 'success'=>$success_msg, 'exists'=>$exists_msg));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -17,6 +17,9 @@ if (!isset($_POST['agree']) || $_POST['agree'] != '동의함') {
|
||||
echo "<div class=\"inner_btn\"><a href=\"./\">뒤로가기</a></div></div>".PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$tmp_str = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
|
||||
$ajax_token = md5($tmp_str.$_SERVER['REMOTE_ADDR'].$_SERVER['DOCUMENT_ROOT']);
|
||||
?>
|
||||
|
||||
|
||||
@ -66,6 +69,7 @@ if (!isset($_POST['agree']) || $_POST['agree'] != '동의함') {
|
||||
|
||||
<table class="ins_frm">
|
||||
<caption>최고관리자 정보입력</caption>
|
||||
<input type="hidden" name="ajax_token" value="<?php echo $ajax_token; ?>" >
|
||||
<colgroup>
|
||||
<col style="width:150px">
|
||||
<col>
|
||||
@ -108,6 +112,7 @@ if (!isset($_POST['agree']) || $_POST['agree'] != '동의함') {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/jquery-1.8.3.min.js"></script>
|
||||
<script>
|
||||
function frm_install_submit(f)
|
||||
{
|
||||
@ -168,6 +173,29 @@ function frm_install_submit(f)
|
||||
f.admin_id.focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (window.jQuery) {
|
||||
|
||||
var jqxhr = jQuery.post( "ajax.install.check.php", $(f).serialize(), function(data) {
|
||||
|
||||
if( data.error ){
|
||||
alert(data.error);
|
||||
} else if( data.exists ) {
|
||||
if( confirm(data.exists) ){
|
||||
f.submit();
|
||||
}
|
||||
} else if( data.success ) {
|
||||
f.submit();
|
||||
}
|
||||
|
||||
}, "json");
|
||||
|
||||
jqxhr.fail(function(xhr) {
|
||||
alert( xhr.responseText );
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -11,26 +11,7 @@ header('Pragma: no-cache'); // HTTP/1.0
|
||||
|
||||
include_once ('../config.php');
|
||||
include_once ('../lib/common.lib.php');
|
||||
|
||||
if( ! function_exists('safe_install_string_check') ){
|
||||
function safe_install_string_check( $str ) {
|
||||
$is_check = false;
|
||||
|
||||
if(preg_match('#\);(passthru|eval|pcntl_exec|exec|system|popen|fopen|fsockopen|file|file_get_contents|readfile|unlink|include|include_once|require|require_once)\s?#i', $str)) {
|
||||
$is_check = true;
|
||||
}
|
||||
|
||||
if(preg_match('#\$_(get|post|request)\s?\[.*?\]\s?\)#i', $str)){
|
||||
$is_check = true;
|
||||
}
|
||||
|
||||
if($is_check){
|
||||
die("입력한 값에 안전하지 않는 문자가 포함되어 있습니다. 설치를 중단합니다.");
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
include_once('./install.function.php'); // 인스톨 과정 함수 모음
|
||||
|
||||
$title = G5_VERSION." 설치 완료 3/3";
|
||||
include_once ('./install.inc.php');
|
||||
|
||||
Reference in New Issue
Block a user