common install에서 conf.php 생성까지 완료
This commit is contained in:
+33
-3
@@ -162,15 +162,45 @@ function generateFileUsingSimpleTemplate(string $srcFilePath, string $destFilePa
|
||||
if(file_exists($destFilePath) && !$canOverwrite){
|
||||
return 'destFilePath is already exists';
|
||||
}
|
||||
if(!is_writable($destFilePath)){
|
||||
return 'destFilePath is not writabble';
|
||||
if(!is_writable(dirname($destFilePath))){
|
||||
return 'destFilePath is not writable';
|
||||
}
|
||||
|
||||
$text = file_get_contents($srcFilePath);
|
||||
foreach($params as $key => $value){
|
||||
$text = str_replace("_tK_{$key}_", $value);
|
||||
$text = str_replace("_tK_{$key}_", $value, $text);
|
||||
}
|
||||
file_put_contents($destFilePath, $text);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* '비교적' 안전한 int 변환
|
||||
* null -> null
|
||||
* int -> int
|
||||
* float -> int
|
||||
* numeric(int, float) 포함 -> int
|
||||
* 기타 -> 예외처리
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
function toInt($val, $force=false){
|
||||
if($val === null){
|
||||
return null;
|
||||
}
|
||||
if(is_int($val)){
|
||||
return $val;
|
||||
}
|
||||
if(is_numeric($val)){
|
||||
return intval($val);//
|
||||
}
|
||||
if($val === 'NULL' || $val === 'null'){
|
||||
return null;
|
||||
}
|
||||
|
||||
if($force){
|
||||
return intval($val);
|
||||
}
|
||||
throw new InvalidArgumentException('올바르지 않은 타입형 :'.$val);
|
||||
}
|
||||
@@ -36,11 +36,16 @@ session_start();
|
||||
<div class="form-group row">
|
||||
<label for="db_host" class="col-sm-3 col-form-label">DB호스트</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" name="db_host" id="db_host" placeholder="호스트:포트" value="localhost" />
|
||||
<input type="text" class="form-control" name="db_host" id="db_host" placeholder="호스트" value="localhost" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="db_port" class="col-sm-3 col-form-label">DB포트</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" name="db_port" id="db_port" placeholder="접속 포트" value="3306" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="db_id" class="col-sm-3 col-form-label">DB계정명</label>
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
require('_common.php');
|
||||
require(__DIR__.'/../f_config/SETTING.php');
|
||||
use utilphp\util as util;
|
||||
|
||||
session_start();
|
||||
|
||||
function dbConnFail($params){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'DB 접속에 실패했습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
function dbSQLFail($params){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'SQL을 제대로 실행하지 못했습니다. DB상태를 확인해 주세요.'
|
||||
]);
|
||||
}
|
||||
|
||||
$host = util::array_get($_POST['db_host']);
|
||||
$port = util::array_get($_POST['db_port']);
|
||||
$username = util::array_get($_POST['db_id']);
|
||||
$password = util::array_get($_POST['db_pw']);
|
||||
$dbName = util::array_get($_POST['db_name']);
|
||||
|
||||
if(!$host || !$port || !$username || !$password || !$dbName){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'입력 값이 올바르지 않습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(file_exists(ROOT.'/d_setting/conf.php') && is_dir(ROOT.'/d_setting/conf.php')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting/conf.php 가 디렉토리입니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if($SETTING->isExist()){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'이미 conf.php 파일이 있습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
//파일 권한 검사
|
||||
if(file_exists(ROOT.'/d_pic') && !is_dir(ROOT.'/d_pic')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_pic 이 디렉토리가 아닙니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(file_exists(ROOT.'/d_log') && !is_dir(ROOT.'/d_log')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_log 가 디렉토리가 아닙니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_setting')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting 이 존재하지 않습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!is_writable(ROOT.'/d_pic')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_pic 디렉토리의 쓰기 권한이 없습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!is_writable(ROOT.'/d_log')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_log 디렉토리의 쓰기 권한이 없습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!is_writable(ROOT.'/d_setting')){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting 디렉토리의 쓰기 권한이 없습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
//기본 파일 생성
|
||||
if(!file_exists(ROOT.'/d_pic')){
|
||||
mkdir(ROOT.'/d_pic');
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_log')){
|
||||
mkdir(ROOT.'/d_log');
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_log/.htaccess')){
|
||||
@file_put_contents(ROOT.'/d_log/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_setting/.htaccess')){
|
||||
@file_put_contents(ROOT.'/d_setting/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
//DB 접근 권한 검사
|
||||
|
||||
$rootDB = new MeekroDB($host,$username,$password,$dbName,$port,'utf8');
|
||||
$rootDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||
|
||||
$rootDB->throw_exception_on_nonsql_error = false;
|
||||
$rootDB->nonsql_error_handler = 'dbConnFail';
|
||||
$rootDB->error_handler = 'dbSQLFail';
|
||||
|
||||
$mysqli_obj = $rootDB->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
||||
|
||||
$mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/common_schema.sql'));
|
||||
$globalSalt = bin2hex(random_bytes(16));
|
||||
|
||||
$result = generateFileUsingSimpleTemplate(
|
||||
ROOT.'/d_setting/conf.orig.php',
|
||||
ROOT.'/d_setting/conf.php',[
|
||||
'host'=>$host,
|
||||
'user'=>$username,
|
||||
'password'=>$password,
|
||||
'dbName'=>$dbName,
|
||||
'port'=>$port,
|
||||
'globalSalt'=>$globalSalt
|
||||
]
|
||||
);
|
||||
|
||||
if($result !== true){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
]);
|
||||
}
|
||||
|
||||
returnJson([
|
||||
'result'=>true,
|
||||
'reason'=>'NYI'
|
||||
]);
|
||||
@@ -40,4 +40,66 @@ function changeInstallMode(){
|
||||
|
||||
$(document).ready( function () {
|
||||
changeInstallMode();
|
||||
|
||||
$('#db_form').validate({
|
||||
rules:{
|
||||
db_host:"required",
|
||||
db_port:"required",
|
||||
db_id:"required",
|
||||
db_pw:"required",
|
||||
db_name:"required"
|
||||
},
|
||||
errorElement: "div",
|
||||
errorPlacement: function ( error, element ) {
|
||||
// Add the `help-block` class to the error element
|
||||
error.addClass( "invalid-feedback" );
|
||||
|
||||
if ( element.prop( "type" ) === "checkbox" ) {
|
||||
error.insertAfter( element.parent( "label" ) );
|
||||
} else {
|
||||
error.insertAfter( element );
|
||||
}
|
||||
},
|
||||
highlight: function ( element, errorClass, validClass ) {
|
||||
$( element ).addClass( "is-invalid" ).removeClass( "is-valid" );
|
||||
},
|
||||
unhighlight: function (element, errorClass, validClass) {
|
||||
$( element ).addClass( "is-valid" ).removeClass( "is-invalid" );
|
||||
}
|
||||
})
|
||||
$('#db_form').submit(function(e){
|
||||
e.preventDefault();
|
||||
if(!$("#db_form").valid()){
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
cache:false,
|
||||
type:'post',
|
||||
url:'j_setup_db.php',
|
||||
dataType:'json',
|
||||
data:{
|
||||
db_host:$('#db_host').val(),
|
||||
db_port:$('#db_port').val(),
|
||||
db_id:$('#db_id').val(),
|
||||
db_pw:$('#db_pw').val(),
|
||||
db_name:$('#db_name').val()
|
||||
}
|
||||
}).then(function(result){
|
||||
var deferred = $.Deferred();
|
||||
|
||||
if(!result.result){
|
||||
alert(result.reason);
|
||||
deferred.reject('fail');
|
||||
}
|
||||
else{
|
||||
alert('conf.php가 생성되었습니다. 관리자 계정 생성을 진행합니다.');
|
||||
deferred.resolve();
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
}).then(function(){
|
||||
changeInstallMode();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user