Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/cms/classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function run($url = '/')
if (
MaintenanceSetting::isConfigured() &&
MaintenanceSetting::get('is_enabled', false) &&
!MaintenanceSetting::isAllowedIp(Request::ip()) &&
!BackendAuth::getUser()
) {
if (!Request::ajax()) {
Expand Down
7 changes: 7 additions & 0 deletions modules/cms/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
'is_enabled' => 'Enable maintenance mode',
'is_enabled_comment' => 'Select the page to show when maintenance mode is activated.',
'hint' => 'Maintenance mode will display the maintenance page to visitors who are not signed in to the back-end area.',
'allowed_ips' => [
'name' => 'Allowed IP addresses',
'description' => 'IP addresses that are permitted to view the site while maintenance mode is active',
'prompt' => 'Add an IP Address',
'ip' => 'IP address',
'label' => 'Description'
]
],
'page' => [
'not_found_name' => "The page ':name' is not found",
Expand Down
13 changes: 13 additions & 0 deletions modules/cms/models/MaintenanceSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Model;
use Cms\Classes\Page;
use Cms\Classes\Theme;
use Winter\Storm\Support\Arr;
use Symfony\Component\HttpFoundation\IpUtils;
use ApplicationException;

/**
Expand Down Expand Up @@ -89,4 +91,15 @@ public function afterFetch()
$this->is_enabled = false;
}
}

/**
* Check if the provided IP is in the allowed IP list.
*
* @param string $ip
* @return bool
*/
public static function isAllowedIp(string $ip): bool
{
return IpUtils::checkIp($ip, Arr::pluck(static::get('allowed_ips', []), 'ip'));
}
}
19 changes: 18 additions & 1 deletion modules/cms/models/maintenancesetting/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ fields:

cms_page:
type: dropdown
cssClass: checkbox-align
cssClass: checkbox-align

allowed_ips:
label: cms::lang.maintenance.allowed_ips.name
type: repeater
commentAbove: cms::lang.maintenance.allowed_ips.description
prompt: cms::lang.maintenance.allowed_ips.prompt
cssClass: checkbox-align
form:
fields:
ip:
label: cms::lang.maintenance.allowed_ips.ip
type: text
span: left
label:
label: cms::lang.maintenance.allowed_ips.label
type: text
span: right