diff --git a/i_entrance/j_server_change_status.php b/i_entrance/j_server_change_status.php index ac0a3e17..5416121d 100644 --- a/i_entrance/j_server_change_status.php +++ b/i_entrance/j_server_change_status.php @@ -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; } diff --git a/j_updateServer.php b/j_updateServer.php index ff91ae08..85b87974 100644 --- a/j_updateServer.php +++ b/j_updateServer.php @@ -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, diff --git a/src/sammo/Setting.php b/src/sammo/Setting.php index db7d0b99..ec59ff7a 100644 --- a/src/sammo/Setting.php +++ b/src/sammo/Setting.php @@ -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; + } } diff --git a/src/sammo/WebUtil.php b/src/sammo/WebUtil.php index 7f18c7d3..bb5f2556 100644 --- a/src/sammo/WebUtil.php +++ b/src/sammo/WebUtil.php @@ -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'); diff --git a/i_entrance/templates/block_htaccess.php b/src/sammo/templates/block_htaccess.php similarity index 100% rename from i_entrance/templates/block_htaccess.php rename to src/sammo/templates/block_htaccess.php