서버 열단, 리셋 부분 권한 추가

This commit is contained in:
2018-06-18 03:21:52 +09:00
parent acb09bfe71
commit 746977d5d0
16 changed files with 172 additions and 44 deletions
+1
View File
File diff suppressed because one or more lines are too long
+1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -29,7 +29,7 @@ CREATE TABLE `member` (
`NAME` VARCHAR(64) NOT NULL, `NAME` VARCHAR(64) NOT NULL,
`PICTURE` VARCHAR(64) NULL DEFAULT 'default.jpg', `PICTURE` VARCHAR(64) NULL DEFAULT 'default.jpg',
`IMGSVR` INT(1) NULL DEFAULT '0', `IMGSVR` INT(1) NULL DEFAULT '0',
`acl` TEXT NOT NULL COMMENT 'json', `acl` text NOT NULL DEFAULT '{}' COMMENT 'json',
`GRADE` INT(1) NULL DEFAULT '1', `GRADE` INT(1) NULL DEFAULT '1',
`REG_NUM` INT(3) NULL DEFAULT '0', `REG_NUM` INT(3) NULL DEFAULT '0',
`REG_DATE` DATETIME NOT NULL, `REG_DATE` DATETIME NOT NULL,
+8 -1
View File
@@ -9,7 +9,14 @@ if(!class_exists('\sammo\DB')){
} }
$session = Session::requireLogin(); $session = Session::requireLogin();
if($session->userGrade < 5){
$serverName = DB::prefix();
$serverAcl = $session->acl[$serverName]??[];
$allowReset = in_array('reset', $serverAcl);
$allowFullReset = in_array('fullReset',$serverAcl);
$allowReset |= $allowFullReset;
if($session->userGrade < 5 && !$allowReset){
die('관리자 아님'); die('관리자 아님');
} }
+40 -1
View File
@@ -5,7 +5,21 @@ include "lib.php";
include "func.php"; include "func.php";
$session = Session::requireLogin([])->setReadOnly(); $session = Session::requireLogin([])->setReadOnly();
if($session->userGrade < 5){
if(!class_exists('\\sammo\\DB')){
Json::die([
'result'=>false,
'reason'=>'DB리셋 필요'
]);
}
$serverName = DB::prefix();
$serverAcl = $session->acl[$serverName]??[];
$allowReset = in_array('reset', $serverAcl);
$allowFullReset = in_array('fullReset',$serverAcl);
$allowReset |= $allowFullReset;
if($session->userGrade < 5 && !$allowReset){
Json::die([ Json::die([
'result'=>false, 'result'=>false,
'reason'=>'관리자 아님' 'reason'=>'관리자 아님'
@@ -38,6 +52,30 @@ if(!$v->validate()){
]); ]);
} }
$allowReset = true;
if($session->userGrade < 5 && !$allowFullReset){
//리셋 가능한 조건인지 테스트
$allowReset = false;
if(file_exists(__dir__.'/.htaccess')){
$allowReset = true;
}
else{
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
if($gameStor->isunited){
$allowReset = true;
}
}
}
if(!$allowReset){
Json::die([
'result'=>false,
'reason'=>'부족한 권한: 서버가 닫혀있거나, 천통되어 있을 경우에만 리셋 가능합니다.'
]);
}
$turnterm = (int)$_POST['turnterm']; $turnterm = (int)$_POST['turnterm'];
$sync = (int)$_POST['sync']; $sync = (int)$_POST['sync'];
$scenario = (int)$_POST['scenario']; $scenario = (int)$_POST['scenario'];
@@ -83,6 +121,7 @@ if($reserve_open){
]), ]),
'date'=>$reserve_open->format('Y-m-d H:i:s') 'date'=>$reserve_open->format('Y-m-d H:i:s')
]); ]);
AppConf::getList()[DB::prefix()]->closeServer();
Json::die([ Json::die([
'result'=>true, 'result'=>true,
'reason'=>'예약' 'reason'=>'예약'
+8 -1
View File
@@ -4,7 +4,14 @@ namespace sammo;
require "lib.php"; require "lib.php";
require "func.php"; require "func.php";
$session = Session::requireLogin([])->setReadOnly(); $session = Session::requireLogin([])->setReadOnly();
if($session->userGrade < 5){
$serverName = DB::prefix();
$serverAcl = $session->acl[$serverName]??[];
$allowReset = in_array('reset', $serverAcl);
$allowFullReset = in_array('fullReset',$serverAcl);
$allowReset |= $allowFullReset;
if($session->userGrade < 5 && !$allowReset){
Json::die([ Json::die([
'result'=>false, 'result'=>false,
'reason'=>'관리자가 아닙니다.' 'reason'=>'관리자가 아닙니다.'
+4 -2
View File
@@ -11,6 +11,7 @@ $templates = new \League\Plates\Engine(__dir__.'/templates');
$db = RootDB::db(); $db = RootDB::db();
$notice = $db->queryFirstField('SELECT `NOTICE` FROM `system` WHERE `NO`=1'); $notice = $db->queryFirstField('SELECT `NOTICE` FROM `system` WHERE `NO`=1');
$userGrade = $session->userGrade; $userGrade = $session->userGrade;
$acl = $session->acl;
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -34,7 +35,7 @@ $userGrade = $session->userGrade;
<?=WebUtil::printJS('../d_shared/menu.js')?> <?=WebUtil::printJS('../d_shared/menu.js')?>
<?=WebUtil::printJS('../js/title.js')?> <?=WebUtil::printJS('../js/title.js')?>
<?php if ($userGrade >= 5): ?> <?php if ($userGrade >= 5 || $acl): ?>
<!-- 운영자 --> <!-- 운영자 -->
<?=WebUtil::printCSS('../css/admin_server.css')?> <?=WebUtil::printCSS('../css/admin_server.css')?>
<?=WebUtil::printJS('../js/admin_server.js')?> <?=WebUtil::printJS('../js/admin_server.js')?>
@@ -110,8 +111,9 @@ if ($userGrade >= 5) {
</div> </div>
</div> </div>
<?php <?php
if ($userGrade >= 5) { if ($userGrade >= 5 || $acl) {
echo $templates->render('server_panel', []); echo $templates->render('server_panel', []);
} }
?> ?>
+32 -2
View File
@@ -9,7 +9,7 @@ $userID = Session::getUserID();
// 외부 파라미터 // 외부 파라미터
$db = RootDB::db(); $db = RootDB::db();
$member = $db->queryFirstRow('SELECT `id`, `name`, `grade`, `picture`, reg_date, third_use FROM `member` WHERE `NO` = %i', $userID); $member = $db->queryFirstRow('SELECT `id`, `name`, `grade`, `picture`, reg_date, third_use, acl FROM `member` WHERE `NO` = %i', $userID);
if(!$member['picture']){ if(!$member['picture']){
$picture = ServConfig::getSharedIconPath().'/default.jpg'; $picture = ServConfig::getSharedIconPath().'/default.jpg';
@@ -42,6 +42,35 @@ if($member['grade'] == 6) {
$grade = '블럭회원'; $grade = '블럭회원';
} }
$acl = [];
//TODO: Acl을 관리하기 위한 별도의 객체 필요
foreach(Json::decode($member['acl']??'{}') as $serverName=>$aclList){
$serverKorName = AppConf::getList()[$serverName]->getKorName();
$aclTextList = array_map(function($aclName){
$aclText = "알수없음[{$aclName}]";
switch($aclName){
case 'openClose':$aclText='서버여닫기';break;
case 'reset':$aclText='서버리셋';break;
case 'update':$aclText='업데이트';break;
case 'fullUpdate':$aclText='임의업데이트';break;
case 'vote':$aclText='설문조사';break;
case 'globalNotice':$aclText='전역공지';break;
case 'notice':$aclText='공지';break;
case 'blockGeneral':$aclText='장수징계';break;
}
return $aclText;
}, $aclList);
$acl[] = sprintf("%s(%s)", $serverKorName, join(",", $aclTextList));
}
if($acl){
$acl = join(",<br>", $acl);
}
else{
$acl = "-";
}
Json::die([ Json::die([
'result'=>true, 'result'=>true,
'reason'=>'success', 'reason'=>'success',
@@ -51,5 +80,6 @@ Json::die([
'picture'=>$picture, 'picture'=>$picture,
'global_salt'=>RootDB::getGlobalSalt(), 'global_salt'=>RootDB::getGlobalSalt(),
'join_date'=>$member['reg_date'], 'join_date'=>$member['reg_date'],
'third_use'=>($member['third_use']!=0) 'third_use'=>($member['third_use']!=0),
'acl'=>$acl
]); ]);
+14 -9
View File
@@ -18,50 +18,55 @@ $server = Util::getReq('server', 'string', '');
$db = RootDB::db(); $db = RootDB::db();
$userGrade = $session->userGrade; $userGrade = $session->userGrade;
$acl = $session->acl;
$session->setReadOnly(); $session->setReadOnly();
if($userGrade < 5) { if($userGrade < 5 && !$acl) {
Json::die([ Json::die([
'result'=>'FAIL', 'result'=>'FAIL',
'msg'=>'운영자 권한이 없습니다.' 'msg'=>'운영자 권한이 없습니다.'
]); ]);
} }
function doServerModeSet($server, $action, &$response){ function doServerModeSet($server, $action, &$response, $session){
$serverList = AppConf::getList(); $serverList = AppConf::getList();
$settingObj = $serverList[$server]; $settingObj = $serverList[$server];
$serverAcl = $session->acl[$server]??[];
$userGrade = $session->userGrade;
$serverDir = $settingObj->getShortName(); $serverDir = $settingObj->getShortName();
$serverPath = $settingObj->getBasePath(); $serverPath = $settingObj->getBasePath();
$realServerPath = realpath(dirname(__FILE__)).'/'.$serverPath; $realServerPath = realpath(dirname(__FILE__)).'/'.$serverPath;
if($action == 'close') { //폐쇄 if($action == 'close' && ($userGrade >= 5 || in_array('openClose', $serverAcl))) { //폐쇄
return $settingObj->closeServer(); return $settingObj->closeServer();
} elseif($action == 'reset') {//리셋 } elseif($action == 'reset' && $userGrade >= 6) {//리셋
//FIXME: reset, reset_full 구현 //FIXME: reset, reset_full 구현
if(file_exists($serverPath.'/d_setting/DB.php')){ if(file_exists($serverPath.'/d_setting/DB.php')){
@unlink($serverPath.'/d_setting/DB.php'); @unlink($serverPath.'/d_setting/DB.php');
} }
$response['installURL'] = $serverDir."/install.php"; $response['installURL'] = $serverDir."/install.php";
} elseif($action == 'open') {//오픈 } elseif($action == 'open' && ($userGrade >= 5 || in_array('openClose', $serverAcl))) {//오픈
return $settingObj->openServer(); return $settingObj->openServer();
} else{ } else{
$response['msg'] = '올바르지 않은 요청입니다';
return false; return false;
} }
return true; return true;
} }
function doAdminPost($action, $notice, $server){ function doAdminPost($action, $notice, $server, $session){
$response = ['result' => 'FAIL']; $response = ['result' => 'FAIL'];
if($action == 'notice') { if($action == 'notice' && ($userGrade >= 5 || in_array('notice', $serverAcl))) {
RootDB::db()->update('system', ['NOTICE'=>$notice], true); RootDB::db()->update('system', ['NOTICE'=>$notice], true);
$response['result'] = 'SUCCESS'; $response['result'] = 'SUCCESS';
return $response; return $response;
} }
if(doServerModeSet($server, $action, $response)){ if(doServerModeSet($server, $action, $response, $session)){
$response['result'] = 'SUCCESS'; $response['result'] = 'SUCCESS';
return $response; return $response;
} }
@@ -70,6 +75,6 @@ function doAdminPost($action, $notice, $server){
} }
$response = doAdminPost($action, $notice, $server); $response = doAdminPost($action, $notice, $server, $session);
Json::die($response); Json::die($response);
+2 -2
View File
@@ -4,8 +4,7 @@ namespace sammo;
require(__dir__.'/../vendor/autoload.php'); require(__dir__.'/../vendor/autoload.php');
$session = Session::requireLogin([])->setReadOnly(); $session = Session::requireLogin([])->setReadOnly();
if($session->userGrade < 5 && !$session->acl){
if($session->userGrade < 5){
Json::die([ Json::die([
'result'=>false, 'result'=>false,
'reason'=>'권한이 부족합니다.' 'reason'=>'권한이 부족합니다.'
@@ -83,6 +82,7 @@ foreach (AppConf::getList() as $setting) {
} }
Json::die([ Json::die([
'acl' => $session->acl,
'server' => $server, 'server' => $server,
'grade' => $session->userGrade 'grade' => $session->userGrade
]); ]);
+16 -11
View File
@@ -44,12 +44,12 @@ require(__dir__.'/../vendor/autoload.php');
<a href="entrance.php"><button id="btn_back1" class="with_skin">돌아가기</button></a> <a href="entrance.php"><button id="btn_back1" class="with_skin">돌아가기</button></a>
</caption> </caption>
<colgroup> <colgroup>
<col style="width:80px;" /> <col style="width:80px;min-width:80px;" />
<col style="width:80px;"/> <col style="width:80px;min-width:80px;"/>
<col style="width:80px;"/> <col style="width:80px;min-width:80px;"/>
<col style="width:80px;"/> <col style="width:80px;min-width:80px;"/>
<col style="width:80px;"/> <col style="width:80px;min-width:80px;"/>
<col/> <col style="min-width:80px;"/>
</colgroup> </colgroup>
<thead> <thead>
<tr> <tr>
@@ -59,19 +59,24 @@ require(__dir__.'/../vendor/autoload.php');
<tbody> <tbody>
<tr> <tr>
<th class="bg1">ID</th> <th class="bg1">ID</th>
<td> <td colspan="5">
<span id="slot_id"></span> <span id="slot_id"></span>
</td> </td>
</tr>
<tr>
<th class="bg1">닉네임</th> <th class="bg1">닉네임</th>
<td style="height:36px;"> <td colspan="5" style="height:36px;">
<span id="slot_nickname"></span> <span id="slot_nickname"></span>
</td> </td>
</tr>
<tr>
<th class="bg1">등급</th> <th class="bg1">등급</th>
<td> <td colspan="2">
<span id="slot_grade"></span> <span id="slot_grade"></span>
</td> </td>
<td colspan="3">
<span id="slot_acl"></span>
</td>
</tr> </tr>
<tr> <tr>
<th class="bg1">가입일시</th> <th class="bg1">가입일시</th>
+2 -2
View File
@@ -21,7 +21,7 @@ if(!$username || !$password){
} }
$userInfo = $RootDB->queryFirstRow( $userInfo = $RootDB->queryFirstRow(
'SELECT `no`, `id`, `name`, `grade`, `delete_after` '. 'SELECT `no`, `id`, `name`, `grade`, `delete_after`, `acl` '.
'from member where id=%s_username AND '. 'from member where id=%s_username AND '.
'pw=sha2(concat(salt, %s_password, salt), 512)',[ 'pw=sha2(concat(salt, %s_password, salt), 512)',[
'username'=>$username, 'username'=>$username,
@@ -72,7 +72,7 @@ $RootDB->insert('member_log',[
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade']); $session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], Json::decode($userInfo['acl']??'{}'));
Json::die([ Json::die([
'result'=>true, 'result'=>true,
'reason'=>'로그인 되었습니다.' 'reason'=>'로그인 되었습니다.'
+34 -8
View File
@@ -1,16 +1,16 @@
var serverAdminTemplate = '\ var serverAdminTemplate = '\
<tr class="bg0" data-server_name="<%name%>" data-is_root="<%isRoot%>" data-git-path="<%lastGitPath%>">\ <tr class="bg0 server_admin_<%name%>" data-server_name="<%name%>" data-is_root="<%isRoot%>" data-git-path="<%lastGitPath%>">\
<th style="color:<%color%>;"><%korName%>(<%name%>)</th>\ <th style="color:<%color%>;"><%korName%>(<%name%>)</th>\
<td><%status%></td>\ <td><%status%></td>\
<td><%version%></td>\ <td><%version%></td>\
<td><button class="with_skin valid_if_set with_border obj_fill" onclick="modifyServerStatus(this, \'close\');">폐쇄</button></td>\ <td><button class="serv_act_close with_skin valid_if_set with_border obj_fill" onclick="modifyServerStatus(this, \'close\');">폐쇄</button></td>\
<td><button class="with_skin valid_if_set with_border obj_fill" onclick="modifyServerStatus(this, \'open\');">오픈</button></td>\ <td><button class="serv_act_open with_skin valid_if_set with_border obj_fill" onclick="modifyServerStatus(this, \'open\');">오픈</button></td>\
<td><a class="just_link" href="../<%name%>/install.php"><button class="with_skin valid_if_set with_border obj_fill">리셋</button></a></td>\ <td><a class="just_link" href="../<%name%>/install.php"><button class="serv_act_reset with_skin valid_if_set with_border obj_fill">리셋</button></a></td>\
<td><a class="just_link" href="../<%name%>/install_db.php"><button class="with_skin valid_if_installed only_admin with_border obj_fill">하드리셋</button></a></td>\ <td><a class="just_link" href="../<%name%>/install_db.php"><button class="serv_act_hard_reset with_skin valid_if_installed only_admin with_border obj_fill">하드리셋</button></a></td>\
<td><button class="with_skin valid_if_set with_border obj_fill" onclick="Entrance_AdminClosedLogin(this);">폐쇄중 로그인</button></td>\ <td><button class="serv_act_login_close with_skin valid_if_set with_border obj_fill" onclick="Entrance_AdminClosedLogin(this);">폐쇄중 로그인</button></td>\
<td><button class="with_skin valid_if_set with_border obj_fill" onclick="Entrance_AdminOpen119(this);">서버119</button></td>\ <td><button class="serv_act_119 with_skin valid_if_set with_border obj_fill" onclick="Entrance_AdminOpen119(this);">서버119</button></td>\
<td><button class="with_skin with_border obj_fill" onclick="serverUpdate(this);">업데이트</button></td>\ <td><button class="serv_act_update with_skin with_border obj_fill" onclick="serverUpdate(this);">업데이트</button></td>\
</tr>\ </tr>\
'; ';
@@ -81,12 +81,38 @@ function drawServerAdminList(serverList){
var $tr = $(TemplateEngine(serverAdminTemplate, server)); var $tr = $(TemplateEngine(serverAdminTemplate, server));
$table.append($tr); $table.append($tr);
if(serverList.grade < 4){
$tr.find('button').prop('disabled', true);
}
if(!server.valid){ if(!server.valid){
$tr.find('.valid_if_set').prop('disabled', true); $tr.find('.valid_if_set').prop('disabled', true);
} }
if(!server.installed){ if(!server.installed){
$tr.find('.valid_if_installed').prop('disabled', true); $tr.find('.valid_if_installed').prop('disabled', true);
} }
var aclByServer = serverList.acl[server.name];
$.each(aclByServer, function(idx, action){
console.log(action);
if(action == 'update'){
if(!server.installed){
return true;
}
$tr.find('.serv_act_update').prop('disabled', false);
}
else if(action == 'openClose'){
if(!server.valid){
return true;
}
$tr.find('.serv_act_open, .serv_act_close').prop('disabled', false);
}
else if(action == 'reset'){
if(!server.installed){
return true;
}
$tr.find('.serv_act_reset').prop('disabled', false);
}
});
}); });
window.adminGrade = serverList.grade; window.adminGrade = serverList.grade;
if(serverList.grade == 5){ if(serverList.grade == 5){
+1
View File
@@ -12,6 +12,7 @@ function fillUserInfo(result){
$('#slot_id').html(result.id); $('#slot_id').html(result.id);
$('#slot_nickname').html(result.name); $('#slot_nickname').html(result.name);
$('#slot_grade').html(result.grade); $('#slot_grade').html(result.grade);
$('#slot_acl').html(result.acl);
$('#slot_icon').attr('src', result.picture); $('#slot_icon').attr('src', result.picture);
$('#global_salt').val(result.global_salt); $('#global_salt').val(result.global_salt);
$('#slot_join_date').html(result.join_date); $('#slot_join_date').html(result.join_date);
+2 -2
View File
@@ -91,7 +91,7 @@ if(!$email){
$userInfo = $RootDB->queryFirstRow( $userInfo = $RootDB->queryFirstRow(
'SELECT `no`, `id`, `name`, `grade`, `delete_after` from member where email=%s',$email); 'SELECT `no`, `id`, `name`, `grade`, `delete_after`, `acl` from member where email=%s',$email);
if(!$userInfo){ if(!$userInfo){
$restAPI->unlink(); $restAPI->unlink();
@@ -132,7 +132,7 @@ $RootDB->insert('member_log',[
]) ])
]); ]);
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade']); $session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], Json::decode($userInfo['acl']??'{}'));
Json::die([ Json::die([
'result'=>true, 'result'=>true,
'reason'=>'로그인 되었습니다.' 'reason'=>'로그인 되었습니다.'
+6 -2
View File
@@ -8,6 +8,7 @@ namespace sammo;
* @property string $userName 유저명 * @property string $userName 유저명
* @property int $userGrade 유저등급 * @property int $userGrade 유저등급
* @property string $ip IP * @property string $ip IP
* @property array $acl 권한
*/ */
class Session class Session
{ {
@@ -19,7 +20,8 @@ class Session
'userGrade'=>true, 'userGrade'=>true,
'writeClosed'=>true, 'writeClosed'=>true,
'generalID'=>true, 'generalID'=>true,
'generalName'=>true 'generalName'=>true,
'acl'=>true
]; ];
const GAME_KEY_DATE = '_g_loginDate'; const GAME_KEY_DATE = '_g_loginDate';
@@ -161,13 +163,14 @@ class Session
return Util::array_get($_SESSION[$name]); return Util::array_get($_SESSION[$name]);
} }
public function login(int $userID, string $userName, int $grade): Session public function login(int $userID, string $userName, int $grade, array $acl): Session
{ {
$this->set('userID', $userID); $this->set('userID', $userID);
$this->set('userName', $userName); $this->set('userName', $userName);
$this->set('ip', Util::get_client_ip(true)); $this->set('ip', Util::get_client_ip(true));
$this->set('time', time()); $this->set('time', time());
$this->set('userGrade', $grade); $this->set('userGrade', $grade);
$this->set('acl', $acl);
$this->set('access_token', null); $this->set('access_token', null);
return $this; return $this;
} }
@@ -185,6 +188,7 @@ class Session
$this->set('userID', null); $this->set('userID', null);
$this->set('userName', null); $this->set('userName', null);
$this->set('userGrade', null); $this->set('userGrade', null);
$this->set('acl', null);
$this->set('time', time()); $this->set('time', time());
return $this; return $this;
} }