phpuri 추가. root, shredIcon, gameIage 경로 계산 코드를 추가

This commit is contained in:
2018-04-08 18:38:01 +09:00
parent 9108ce3f19
commit f060716a3c
17 changed files with 438 additions and 42 deletions
+88 -36
View File
@@ -12,28 +12,28 @@ $servHost = Util::getReq('serv_host');
$sharedIconPath = Util::getReq('shared_icon_path');
$gameImagePath = Util::getReq('game_image_path');
if(!$host || !$port || !$username || !$password || !$dbName || !$servHost || !$sharedIconPath || !$gameImagePath){
if (!$host || !$port || !$username || !$password || !$dbName || !$servHost || !$sharedIconPath || !$gameImagePath) {
Json::die([
'result'=>false,
'reason'=>'입력 값이 올바르지 않습니다'
]);
}
if(!filter_var($servHost, FILTER_VALIDATE_URL)){
Json::die([
if (!filter_var($servHost, FILTER_VALIDATE_URL)) {
Json::die([
'result'=>false,
'reason'=>'접속 경로가 올바르지 않습니다.'
]);
}
if(file_exists(ROOT.'/d_setting/RootDB.php') && is_dir(ROOT.'/d_setting/RootDB.php')){
if (file_exists(ROOT.'/d_setting/RootDB.php') && is_dir(ROOT.'/d_setting/RootDB.php')) {
Json::die([
'result'=>false,
'reason'=>'d_setting/RootDB.php 가 디렉토리입니다'
]);
}
if(class_exists('\\sammo\\RootDB')){
if (class_exists('\\sammo\\RootDB')) {
Json::die([
'result'=>false,
'reason'=>'이미 RootDB.php 파일이 있습니다'
@@ -41,35 +41,39 @@ if(class_exists('\\sammo\\RootDB')){
}
//파일 권한 검사
if(file_exists(AppConf::getUserIconPathFS()) && !is_dir(AppConf::getUserIconPathFS())){
if (file_exists(AppConf::getUserIconPathFS()) && !is_dir(AppConf::getUserIconPathFS())) {
Json::die([
'result'=>false,
'reason'=>AppConf::$userIconPath.' 이 디렉토리가 아닙니다'
]);
}
if(file_exists(ROOT.'/d_log') && !is_dir(ROOT.'/d_log')){
if (file_exists(ROOT.'/d_log') && !is_dir(ROOT.'/d_log')) {
Json::die([
'result'=>false,
'reason'=>'d_log 가 디렉토리가 아닙니다'
]);
}
if(file_exists(ROOT.'/d_shared') && !is_dir(ROOT.'/d_shared')){
if (file_exists(ROOT.'/d_shared') && !is_dir(ROOT.'/d_shared')) {
Json::die([
'result'=>false,
'reason'=>'d_shared 가 디렉토리가 아닙니다'
]);
}
if(!file_exists(ROOT.'/d_setting')){
if (file_exists(ROOT.'/d_setting') && !is_dir(ROOT.'/d_setting')) {
Json::die([
'result'=>false,
'reason'=>'d_setting 이 존재하지 않습니다'
'reason'=>'d_shared 가 디렉토리가 아닙니다'
]);
}
if (!file_exists(ROOT.'/d_log') || !file_exists(ROOT.'/d_shared') || !file_exists(AppConf::getUserIconPathFS())) {
if (!file_exists(ROOT.'/d_log')
|| !file_exists(ROOT.'/d_shared')
|| !file_exists(ROOT.'/d_setting')
|| !file_exists(AppConf::getUserIconPathFS())
) {
if (!is_writable(ROOT)) {
Json::die([
'result'=>false,
@@ -78,42 +82,46 @@ if (!file_exists(ROOT.'/d_log') || !file_exists(ROOT.'/d_shared') || !file_exist
}
//기본 파일 생성
if(!file_exists(AppConf::getUserIconPathFS())){
if (!file_exists(AppConf::getUserIconPathFS())) {
mkdir(AppConf::getUserIconPathFS());
}
if(!file_exists(ROOT.'/d_log')){
if (!file_exists(ROOT.'/d_log')) {
mkdir(ROOT.'/d_log');
}
if(!file_exists(ROOT.'/d_shared')){
if (!file_exists(ROOT.'/d_setting')) {
mkdir(ROOT.'/d_setting');
}
if (!file_exists(ROOT.'/d_shared')) {
mkdir(ROOT.'/d_shared');
}
}
if(!is_writable(AppConf::getUserIconPathFS())){
if (!is_writable(AppConf::getUserIconPathFS())) {
Json::die([
'result'=>false,
'reason'=>AppConf::$userIconPath.' 디렉토리의 쓰기 권한이 없습니다'
]);
}
if(!is_writable(ROOT.'/d_log')){
if (!is_writable(ROOT.'/d_log')) {
Json::die([
'result'=>false,
'reason'=>'d_log 디렉토리의 쓰기 권한이 없습니다'
]);
}
if(!is_writable(ROOT.'/d_shared')){
if (!is_writable(ROOT.'/d_shared')) {
Json::die([
'result'=>false,
'reason'=>'d_shared 디렉토리의 쓰기 권한이 없습니다'
]);
}
if(!is_writable(ROOT.'/d_setting')){
if (!is_writable(ROOT.'/d_setting')) {
Json::die([
'result'=>false,
'reason'=>'d_setting 디렉토리의 쓰기 권한이 없습니다.'
@@ -122,28 +130,28 @@ if(!is_writable(ROOT.'/d_setting')){
if(!file_exists(ROOT.'/d_log/.htaccess')){
if (!file_exists(ROOT.'/d_log/.htaccess')) {
@file_put_contents(ROOT.'/d_log/.htaccess', 'Deny from all');
}
if(!file_exists(ROOT.'/d_setting/.htaccess')){
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,'utf8mb4');
$rootDB = new \MeekroDB($host, $username, $password, $dbName, $port, 'utf8mb4');
$rootDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
$rootDB->throw_exception_on_nonsql_error = false;
$rootDB->nonsql_error_handler = function($params){
$rootDB->nonsql_error_handler = function ($params) {
Json::die([
'result'=>false,
'reason'=>'DB 접속에 실패했습니다.'
]);
};
$rootDB->error_handler = function($params){
$rootDB->error_handler = function ($params) {
Json::die([
'result'=>false,
'reason'=>'SQL을 제대로 실행하지 못했습니다. DB상태를 확인해 주세요.'
@@ -152,12 +160,12 @@ $rootDB->error_handler = function($params){
$mysqli_obj = $rootDB->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
if($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/common_schema.sql'))){
while(true){
if ($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/common_schema.sql'))) {
while (true) {
if (!$mysqli_obj->more_results()) {
break;
}
if(!$mysqli_obj->next_result()){
if (!$mysqli_obj->next_result()) {
break;
}
}
@@ -172,16 +180,21 @@ $rootDB->insert('system', array(
$globalSalt = bin2hex(random_bytes(16));
$sharedIconPath = WebUtil::resolveRelativePath($sharedIconPath, $servHost);
$gameImagePath = WebUtil::resolveRelativePath($gameImagePath, $servHost);
$result = Util::generateFileUsingSimpleTemplate(
ROOT.'/d_setting/ServConfig.orig.php',
ROOT.'/d_setting/ServConfig.php',[
__dir__.'/templates/ServConfig.orig.php',
ROOT.'/d_setting/ServConfig.php',
[
'serverBasePath'=>$servHost,
'sharedIconPath'=>$sharedIconPath,
'gameImagePath'=>$gameImagePath
]
, true);
],
true
);
if($result !== true){
if ($result !== true) {
Json::die([
'result'=>false,
'reason'=>$result
@@ -189,8 +202,47 @@ if($result !== true){
}
$result = Util::generateFileUsingSimpleTemplate(
ROOT.'/d_setting/RootDB.orig.php',
ROOT.'/d_setting/RootDB.php',[
__dir__.'/templates/common_path.orig.js',
ROOT.'/d_shared/common_path.js',
[
'serverBasePath'=>$servHost,
'sharedIconPath'=>$sharedIconPath,
'gameImagePath'=>$gameImagePath
],
true
);
if ($result !== true) {
Json::die([
'result'=>false,
'reason'=>$result
]);
}
$result = Util::generateFileUsingSimpleTemplate(
__dir__.'/templates/common.orig.css',
ROOT.'/d_shared/common.css',
[
'serverBasePath'=>$servHost,
'sharedIconPath'=>$sharedIconPath,
'gameImagePath'=>$gameImagePath
],
true
);
if ($result !== true) {
Json::die([
'result'=>false,
'reason'=>$result
]);
}
$result = Util::generateFileUsingSimpleTemplate(
__dir__.'/templates/RootDB.orig.php',
ROOT.'/d_setting/RootDB.php',
[
'host'=>$host,
'user'=>$username,
'password'=>$password,
@@ -198,9 +250,9 @@ $result = Util::generateFileUsingSimpleTemplate(
'port'=>$port,
'globalSalt'=>$globalSalt,
]
);
);
if($result !== true){
if ($result !== true) {
Json::die([
'result'=>false,
'reason'=>$result
@@ -210,4 +262,4 @@ if($result !== true){
Json::die([
'result'=>true,
'reason'=>'success'
]);
]);