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

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,
`PICTURE` VARCHAR(64) NULL DEFAULT 'default.jpg',
`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',
`REG_NUM` INT(3) NULL DEFAULT '0',
`REG_DATE` DATETIME NOT NULL,
+8 -1
View File
@@ -9,7 +9,14 @@ if(!class_exists('\sammo\DB')){
}
$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('관리자 아님');
}
+40 -1
View File
@@ -5,7 +5,21 @@ include "lib.php";
include "func.php";
$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([
'result'=>false,
'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'];
$sync = (int)$_POST['sync'];
$scenario = (int)$_POST['scenario'];
@@ -83,6 +121,7 @@ if($reserve_open){
]),
'date'=>$reserve_open->format('Y-m-d H:i:s')
]);
AppConf::getList()[DB::prefix()]->closeServer();
Json::die([
'result'=>true,
'reason'=>'예약'
+8 -1
View File
@@ -4,7 +4,14 @@ namespace sammo;
require "lib.php";
require "func.php";
$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([
'result'=>false,
'reason'=>'관리자가 아닙니다.'
+4 -2
View File
@@ -11,6 +11,7 @@ $templates = new \League\Plates\Engine(__dir__.'/templates');
$db = RootDB::db();
$notice = $db->queryFirstField('SELECT `NOTICE` FROM `system` WHERE `NO`=1');
$userGrade = $session->userGrade;
$acl = $session->acl;
?>
<!DOCTYPE html>
<html>
@@ -34,7 +35,7 @@ $userGrade = $session->userGrade;
<?=WebUtil::printJS('../d_shared/menu.js')?>
<?=WebUtil::printJS('../js/title.js')?>
<?php if ($userGrade >= 5): ?>
<?php if ($userGrade >= 5 || $acl): ?>
<!-- 운영자 -->
<?=WebUtil::printCSS('../css/admin_server.css')?>
<?=WebUtil::printJS('../js/admin_server.js')?>
@@ -110,8 +111,9 @@ if ($userGrade >= 5) {
</div>
</div>
<?php
if ($userGrade >= 5) {
if ($userGrade >= 5 || $acl) {
echo $templates->render('server_panel', []);
}
?>
+32 -2
View File
@@ -9,7 +9,7 @@ $userID = Session::getUserID();
// 외부 파라미터
$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']){
$picture = ServConfig::getSharedIconPath().'/default.jpg';
@@ -42,6 +42,35 @@ if($member['grade'] == 6) {
$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([
'result'=>true,
'reason'=>'success',
@@ -51,5 +80,6 @@ Json::die([
'picture'=>$picture,
'global_salt'=>RootDB::getGlobalSalt(),
'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();
$userGrade = $session->userGrade;
$acl = $session->acl;
$session->setReadOnly();
if($userGrade < 5) {
if($userGrade < 5 && !$acl) {
Json::die([
'result'=>'FAIL',
'msg'=>'운영자 권한이 없습니다.'
]);
}
function doServerModeSet($server, $action, &$response){
function doServerModeSet($server, $action, &$response, $session){
$serverList = AppConf::getList();
$settingObj = $serverList[$server];
$serverAcl = $session->acl[$server]??[];
$userGrade = $session->userGrade;
$serverDir = $settingObj->getShortName();
$serverPath = $settingObj->getBasePath();
$realServerPath = realpath(dirname(__FILE__)).'/'.$serverPath;
if($action == 'close') { //폐쇄
if($action == 'close' && ($userGrade >= 5 || in_array('openClose', $serverAcl))) { //폐쇄
return $settingObj->closeServer();
} elseif($action == 'reset') {//리셋
} elseif($action == 'reset' && $userGrade >= 6) {//리셋
//FIXME: reset, reset_full 구현
if(file_exists($serverPath.'/d_setting/DB.php')){
@unlink($serverPath.'/d_setting/DB.php');
}
$response['installURL'] = $serverDir."/install.php";
} elseif($action == 'open') {//오픈
} elseif($action == 'open' && ($userGrade >= 5 || in_array('openClose', $serverAcl))) {//오픈
return $settingObj->openServer();
} else{
$response['msg'] = '올바르지 않은 요청입니다';
return false;
}
return true;
}
function doAdminPost($action, $notice, $server){
function doAdminPost($action, $notice, $server, $session){
$response = ['result' => 'FAIL'];
if($action == 'notice') {
if($action == 'notice' && ($userGrade >= 5 || in_array('notice', $serverAcl))) {
RootDB::db()->update('system', ['NOTICE'=>$notice], true);
$response['result'] = 'SUCCESS';
return $response;
}
if(doServerModeSet($server, $action, $response)){
if(doServerModeSet($server, $action, $response, $session)){
$response['result'] = 'SUCCESS';
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);
+2 -2
View File
@@ -4,8 +4,7 @@ namespace sammo;
require(__dir__.'/../vendor/autoload.php');
$session = Session::requireLogin([])->setReadOnly();
if($session->userGrade < 5){
if($session->userGrade < 5 && !$session->acl){
Json::die([
'result'=>false,
'reason'=>'권한이 부족합니다.'
@@ -83,6 +82,7 @@ foreach (AppConf::getList() as $setting) {
}
Json::die([
'acl' => $session->acl,
'server' => $server,
'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>
</caption>
<colgroup>
<col style="width:80px;" />
<col style="width:80px;"/>
<col style="width:80px;"/>
<col style="width:80px;"/>
<col style="width:80px;"/>
<col/>
<col style="width:80px;min-width:80px;" />
<col style="width:80px;min-width:80px;"/>
<col style="width:80px;min-width:80px;"/>
<col style="width:80px;min-width:80px;"/>
<col style="width:80px;min-width:80px;"/>
<col style="min-width:80px;"/>
</colgroup>
<thead>
<tr>
@@ -59,19 +59,24 @@ require(__dir__.'/../vendor/autoload.php');
<tbody>
<tr>
<th class="bg1">ID</th>
<td>
<td colspan="5">
<span id="slot_id"></span>
</td>
</tr>
<tr>
<th class="bg1">닉네임</th>
<td style="height:36px;">
<td colspan="5" style="height:36px;">
<span id="slot_nickname"></span>
</td>
</tr>
<tr>
<th class="bg1">등급</th>
<td>
<td colspan="2">
<span id="slot_grade"></span>
</td>
<td colspan="3">
<span id="slot_acl"></span>
</td>
</tr>
<tr>
<th class="bg1">가입일시</th>
+2 -2
View File
@@ -21,7 +21,7 @@ if(!$username || !$password){
}
$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 '.
'pw=sha2(concat(salt, %s_password, salt), 512)',[
'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([
'result'=>true,
'reason'=>'로그인 되었습니다.'
+34 -8
View File
@@ -1,16 +1,16 @@
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>\
<td><%status%></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="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_db.php"><button class="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="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_close with_skin valid_if_set with_border obj_fill" onclick="modifyServerStatus(this, \'close\');">폐쇄</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="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="serv_act_hard_reset with_skin valid_if_installed only_admin with_border obj_fill">하드리셋</button></a></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="serv_act_119 with_skin valid_if_set with_border obj_fill" onclick="Entrance_AdminOpen119(this);">서버119</button></td>\
<td><button class="serv_act_update with_skin with_border obj_fill" onclick="serverUpdate(this);">업데이트</button></td>\
</tr>\
';
@@ -81,12 +81,38 @@ function drawServerAdminList(serverList){
var $tr = $(TemplateEngine(serverAdminTemplate, server));
$table.append($tr);
if(serverList.grade < 4){
$tr.find('button').prop('disabled', true);
}
if(!server.valid){
$tr.find('.valid_if_set').prop('disabled', true);
}
if(!server.installed){
$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;
if(serverList.grade == 5){
+1
View File
@@ -12,6 +12,7 @@ function fillUserInfo(result){
$('#slot_id').html(result.id);
$('#slot_nickname').html(result.name);
$('#slot_grade').html(result.grade);
$('#slot_acl').html(result.acl);
$('#slot_icon').attr('src', result.picture);
$('#global_salt').val(result.global_salt);
$('#slot_join_date').html(result.join_date);
+2 -2
View File
@@ -91,7 +91,7 @@ if(!$email){
$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){
$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([
'result'=>true,
'reason'=>'로그인 되었습니다.'
+6 -2
View File
@@ -8,6 +8,7 @@ namespace sammo;
* @property string $userName 유저명
* @property int $userGrade 유저등급
* @property string $ip IP
* @property array $acl 권한
*/
class Session
{
@@ -19,7 +20,8 @@ class Session
'userGrade'=>true,
'writeClosed'=>true,
'generalID'=>true,
'generalName'=>true
'generalName'=>true,
'acl'=>true
];
const GAME_KEY_DATE = '_g_loginDate';
@@ -161,13 +163,14 @@ class Session
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('userName', $userName);
$this->set('ip', Util::get_client_ip(true));
$this->set('time', time());
$this->set('userGrade', $grade);
$this->set('acl', $acl);
$this->set('access_token', null);
return $this;
}
@@ -185,6 +188,7 @@ class Session
$this->set('userID', null);
$this->set('userName', null);
$this->set('userGrade', null);
$this->set('acl', null);
$this->set('time', time());
return $this;
}