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
+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');
+10
View File
@@ -0,0 +1,10 @@
<IfModule mod_headers.c>
Header set Cache-Control "max-age=60, must-revalidate"
</IfModule>
Deny from all
<?php if(isset($allow_ip) && $allow_ip != ''): ?>
SetEnvIf X-Forwarded-For ^<?=str_replace('.', '\\.', $allow_ip)?> env_allow_1
Allow from env=env_allow_1
Allow from <?=$allow_ip?>
<?php endif; ?>