diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 37000d486f..cd6c1bf8f3 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -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()) { diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php index 4994bc2f55..fe19adfc2b 100644 --- a/modules/cms/lang/en/lang.php +++ b/modules/cms/lang/en/lang.php @@ -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", diff --git a/modules/cms/models/MaintenanceSetting.php b/modules/cms/models/MaintenanceSetting.php index be806055b1..890ea014d0 100644 --- a/modules/cms/models/MaintenanceSetting.php +++ b/modules/cms/models/MaintenanceSetting.php @@ -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; /** @@ -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')); + } } diff --git a/modules/cms/models/maintenancesetting/fields.yaml b/modules/cms/models/maintenancesetting/fields.yaml index 6c5e3dec4c..765590e2c5 100644 --- a/modules/cms/models/maintenancesetting/fields.yaml +++ b/modules/cms/models/maintenancesetting/fields.yaml @@ -15,4 +15,21 @@ fields: cms_page: type: dropdown - cssClass: checkbox-align \ No newline at end of file + 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