diff --git a/common/framework/ipfilter.php b/common/framework/ipfilter.php
index 2c8e19c54..21a087256 100644
--- a/common/framework/ipfilter.php
+++ b/common/framework/ipfilter.php
@@ -174,7 +174,6 @@ class IpFilter
$range .= str_repeat('.*', 4 - $count);
}
$range = str_replace(array('.', '*'), array('\\.', '\\d+'), trim($range));
- var_dump($ip, $range);
return preg_match("/^$range$/", $ip) ? true : false;
}
diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php
index a05426d88..a3c47f6da 100644
--- a/modules/admin/admin.admin.view.php
+++ b/modules/admin/admin.admin.view.php
@@ -471,9 +471,28 @@ class adminAdminView extends admin
Context::set('sitelock_title', escape(Rhymix\Framework\Config::get('lock.title')));
Context::set('sitelock_message', escape(Rhymix\Framework\Config::get('lock.message')));
- $allowed_ip = Rhymix\Framework\Config::get('lock.allow');
- if (!in_array('127.0.0.1', $allowed_ip)) $allowed_ip[] = '127.0.0.1';
- if (!in_array(RX_CLIENT_IP, $allowed_ip)) $allowed_ip[] = RX_CLIENT_IP;
+ $allowed_ip = Rhymix\Framework\Config::get('lock.allow') ?: array();
+ $allowed_localhost = false;
+ $allowed_current = false;
+ foreach ($allowed_ip as $range)
+ {
+ if (Rhymix\Framework\IpFilter::inRange('127.0.0.1', $range))
+ {
+ $allowed_localhost = true;
+ }
+ if (Rhymix\Framework\IpFilter::inRange(RX_CLIENT_IP, $range))
+ {
+ $allowed_current = true;
+ }
+ }
+ if (!$allowed_localhost)
+ {
+ array_unshift($allowed_ip, '127.0.0.1');
+ }
+ if (!$allowed_current)
+ {
+ array_unshift($allowed_ip, RX_CLIENT_IP);
+ }
Context::set('sitelock_allowed_ip', implode(PHP_EOL, $allowed_ip));
Context::set('remote_addr', RX_CLIENT_IP);
diff --git a/modules/admin/tpl/config_sitelock.html b/modules/admin/tpl/config_sitelock.html
index 560272236..67f61f190 100644
--- a/modules/admin/tpl/config_sitelock.html
+++ b/modules/admin/tpl/config_sitelock.html
@@ -12,7 +12,7 @@
-
+
diff --git a/modules/install/install.controller.php b/modules/install/install.controller.php
index 7c50eef10..90d608952 100644
--- a/modules/install/install.controller.php
+++ b/modules/install/install.controller.php
@@ -234,6 +234,16 @@ class installController extends install
}
}
+ // Apply site lock.
+
+ if (Context::get('use_sitelock') === 'Y')
+ {
+ $user_ip_range = getView('install')->detectUserIPRange();
+ Rhymix\Framework\Config::set('lock.locked', true);
+ Rhymix\Framework\Config::set('lock.message', 'This site is locked.');
+ Rhymix\Framework\Config::set('lock.allow', array('127.0.0.1', $user_ip_range));
+ }
+
// Save the new configuration.
Rhymix\Framework\Config::save();
diff --git a/modules/install/install.view.php b/modules/install/install.view.php
index b45dae69c..752208b80 100644
--- a/modules/install/install.view.php
+++ b/modules/install/install.view.php
@@ -153,9 +153,31 @@ class installView extends install
// Always use SSL if installing via SSL.
Context::set('use_ssl', RX_SSL ? 'always' : 'none');
+ Context::set('sitelock_ip_range', $this->detectUserIPRange());
$this->setTemplateFile('other_config');
}
+ /**
+ * Detect the IP range of the user.
+ */
+ function detectUserIPRange()
+ {
+ if (RX_CLIENT_IP_VERSION === 4)
+ {
+ return preg_replace('/\.\d+$/', '.*', RX_CLIENT_IP);
+ }
+ elseif (function_exists('inet_pton'))
+ {
+ $binary = inet_pton(RX_CLIENT_IP);
+ $binary = substr($binary, 0, 8) . str_repeat(chr(0), 8);
+ return inet_ntop($binary) . '/64';
+ }
+ else
+ {
+ return RX_CLIENT_IP;
+ }
+ }
+
/**
* Detect best time zone for the user.
*/
diff --git a/modules/install/lang/en.php b/modules/install/lang/en.php
index e14213872..332ec919c 100644
--- a/modules/install/lang/en.php
+++ b/modules/install/lang/en.php
@@ -77,9 +77,13 @@ $lang->about_nginx_rewrite = 'To use this feature at nginx, you need to configur
$lang->time_zone = 'Time Zone';
$lang->about_time_zone = 'If the server time is different from your time zone, you can use this option to display times in your time zone.';
$lang->use_ssl = 'SSL';
-$lang->ssl_options['none'] = 'Never';
+$lang->ssl_options['none'] = 'None';
$lang->ssl_options['optional'] = 'Optional';
$lang->ssl_options['always'] = 'Always';
+$lang->use_sitelock = 'Site Lock';
+$lang->sitelock_options['none'] = 'None';
+$lang->sitelock_options['lock'] = 'Lock after Install';
+$lang->about_sitelock_after_install = 'If you lock your site, only your current IP range (%s) will be able to access your site.';
$lang->about_database_file = 'Sqlite saves data in a file. Location of the database file should be unreachable by web
Data file should be inside the permission of 777.';
$lang->success_installed = 'Installation has been completed.';
$lang->msg_installing = 'Installing...';
diff --git a/modules/install/lang/ja.php b/modules/install/lang/ja.php
index dc6bbf56f..857aff19f 100644
--- a/modules/install/lang/ja.php
+++ b/modules/install/lang/ja.php
@@ -78,6 +78,10 @@ $lang->use_ssl = 'SSLを使用';
$lang->ssl_options['none'] = '使わない';
$lang->ssl_options['optional'] = '部分的に使う';
$lang->ssl_options['always'] = '常に使う';
+$lang->use_sitelock = 'サイトロック';
+$lang->sitelock_options['none'] = '使わない';
+$lang->sitelock_options['lock'] = 'ロック';
+$lang->about_sitelock_after_install = 'サイトをロックすると、インストールに使用したIP帯域(%s)以外接続できなくなるので注意してください。';
$lang->about_database_file = 'Sqliteはファイルにデータを保存します。そのため、データベースファイルにはウェブからアクセスできない場所にしなければなりません。
データファイルのパーミッションは「777」に設定してください。';
$lang->success_installed = '正常にインストールされました。';
$lang->msg_cannot_proc = 'インストールできる環境が整っていないため、リクエストを実行できませんでした。';
diff --git a/modules/install/lang/ko.php b/modules/install/lang/ko.php
index b403afeda..2b2875b2d 100644
--- a/modules/install/lang/ko.php
+++ b/modules/install/lang/ko.php
@@ -80,6 +80,10 @@ $lang->use_ssl = 'SSL 사용';
$lang->ssl_options['none'] = '사용 안함';
$lang->ssl_options['optional'] = '선택적으로';
$lang->ssl_options['always'] = '항상 사용';
+$lang->use_sitelock = '사이트 잠금';
+$lang->sitelock_options['none'] = '사용 안함';
+$lang->sitelock_options['lock'] = '잠금 상태로 설치';
+$lang->about_sitelock_after_install = '사이트를 잠그면 설치에 사용하신 IP 대역 (%s) 외에는 접속할 수 없게 되니 주의하십시오.';
$lang->about_database_file = 'Sqlite는 파일에 데이터를 저장합니다. 데이터베이스 파일의 위치를 웹에서 접근할 수 없는 곳으로 해야 합니다.
데이터 파일은 777퍼미션 설정된 곳으로 지정해주세요.';
$lang->success_installed = '설치가 되었습니다.';
$lang->msg_cannot_proc = '설치 환경이 갖춰지지 않아 요청을 실행할 수가 없습니다.';
diff --git a/modules/install/tpl/css/install.css b/modules/install/tpl/css/install.css
index 79499ff2a..8739cc3f0 100644
--- a/modules/install/tpl/css/install.css
+++ b/modules/install/tpl/css/install.css
@@ -176,7 +176,10 @@ button.grey:hover, a.button.grey:hover {
.x #content ul li {
line-height: 160%;
}
-.x #content label input[type=checkbox] {
+.x #content label.x_inline {
+ display: inline-block; margin-right: 12px;
+}
+.x #content label input[type=checkbox], .x #content label input[type=radio] {
position: relative;
top: 2px;
}
@@ -207,6 +210,9 @@ button.grey:hover, a.button.grey:hover {
line-height: 17px; padding: 3px 5px;
width: 260px; box-sizing: border-box;
}
+.x .x_control-group .x_controls input[type=checkbox], .x .x_control-group .x_controls input[type=radio] {
+ padding: 0; width: auto;
+}
.x .x_control-group .x_controls select {
line-height: 17px; padding: 3px 7px 3px 3px;
width: 260px; box-sizing: border-box;
diff --git a/modules/install/tpl/other_config.html b/modules/install/tpl/other_config.html
index 1c8b48964..493c76cb8 100644
--- a/modules/install/tpl/other_config.html
+++ b/modules/install/tpl/other_config.html
@@ -50,13 +50,19 @@
+
+ {$lang->about_sitelock_after_install($sitelock_ip_range)}