Setting에 closerServer, openServer를 통합. 서버 업데이트시 자동 폐쇄 상태로

This commit is contained in:
2018-04-01 20:31:20 +09:00
parent 4f113f210e
commit 97c6904918
5 changed files with 43 additions and 23 deletions
+2 -23
View File
@@ -12,10 +12,6 @@ $session = Session::requireLogin(null);
// $_POST['notice'] : 공지
// $_POST['server'] : 서버 인덱스
function escapeIPv4($ip){
return str_replace('.', '\\.', $ip);
}
$action = Util::array_get($_POST['action'], '');
$notice = Util::array_get($_POST['notice'], '');
$server = Util::array_get($_POST['server'], '');
@@ -40,22 +36,7 @@ function doServerModeSet($server, $action, &$response){
$realServerPath = realpath(dirname(__FILE__)).'/'.$serverPath;
if($action == 'close') { //폐쇄
$templates = new \League\Plates\Engine('templates');
//TODO: .htaccess가 서버 오픈에도 사용될 수 있으니 별도의 방법이 필요함
$allow_ip = Util::get_client_ip(false);
if(Util::starts_with($allow_ip, '192.168.') ||
Util::starts_with($allow_ip, '10.'))
{
//172.16~172.31은 코딩하기 귀찮으니까 안할거다
$allow_ip = Util::get_client_ip(true);
}
$xforward_allow_ip = escapeIPv4($allow_ip);
$htaccess = $templates->render('block_htaccess',
['allow_ip' => $allow_ip, 'xforward_allow_ip' => $xforward_allow_ip]);
file_put_contents($serverPath.'/.htaccess', $htaccess);
return $settingObj->closeServer();
} elseif($action == 'reset') {//리셋
//FIXME: reset, reset_full 구현
if(file_exists($serverPath.'/d_setting/DB.php')){
@@ -64,9 +45,7 @@ function doServerModeSet($server, $action, &$response){
$response['installURL'] = $serverDir."/install.php";
} elseif($action == 'open') {//오픈
if(file_exists($serverPath.'/.htaccess')){
@unlink($serverPath.'/.htaccess');
}
return $settingObj->openServer();
} else{
return false;
}
+5
View File
@@ -98,6 +98,8 @@ if($server == $baseServerName){
], true
);
AppConf::getList()[$server]->closeServer();
Json::die([
'server'=>$server,
'result'=>true,
@@ -148,6 +150,9 @@ $result = Util::generateFileUsingSimpleTemplate(
], true
);
AppConf::getList()[$server]->closeServer();
Json::die([
'server'=>$server,
'result'=>true,
+32
View File
@@ -89,6 +89,38 @@ class Setting {
return $version;
}
public function closeServer(){
if(!file_exists($this->basepath) || !is_dir($this->basepath)){
return false;
}
$templates = new \League\Plates\Engine(__dir__.'/templates');
//TODO: .htaccess가 서버 오픈에도 사용될 수 있으니 별도의 방법이 필요함
$allow_ip = Util::get_client_ip(false);
if(Util::starts_with($allow_ip, '192.168.') ||
Util::starts_with($allow_ip, '10.'))
{
//172.16~172.31은 코딩하기 귀찮으니까 안할거다
$allow_ip = Util::get_client_ip(true);
}
$xforward_allow_ip = WebUtil::escapeIPv4($allow_ip);
$htaccess = $templates->render('block_htaccess',
['allow_ip' => $allow_ip, 'xforward_allow_ip' => $xforward_allow_ip]);
file_put_contents($this->basepath.'/.htaccess', $htaccess);
return true;
}
public function openServer(){
if(!file_exists($this->basepath) || !is_dir($this->basepath)){
return false;
}
if(file_exists($this->basepath.'/.htaccess')){
@unlink($this->basepath.'/.htaccess');
}
return true;
}
}
+4
View File
@@ -2,6 +2,10 @@
namespace sammo;
class WebUtil{
public static function escapeIPv4($ip){
return str_replace('.', '\\.', $ip);
}
public static function setHeaderNoCache(){
if(!headers_sent()) {
header('Expires: Wed, 01 Jan 2014 00:00:00 GMT');