Skip to content

Commit

Permalink
Fix for checking if current IP is in maintenance IP list
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanviduka committed Mar 14, 2024
1 parent a5748c1 commit a0622b7
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Model/FrontControllerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,26 +334,24 @@ private function verifyBots($ip)
return false;
}

private function readMaintenanceIp($ip)
private function readMaintenanceIp($clientIps)
{
$tag = self::FASTLY_CACHE_MAINTENANCE_IP_FILE_TAG;
$data = json_decode($this->cache->load($tag));
if (empty($data)) {
$data = [];
$allowedIps = json_decode($this->cache->load($tag));
if (empty($allowedIps)) {
$allowedIps = [];
$flagDir = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
if ($flagDir->isExist('.maintenance.ip')) {
$temp = $flagDir->readFile('.maintenance.ip');
$data = explode(',', trim($temp));
$this->cache->save(json_encode($data), $tag, []);
$allowedIps = explode(',', trim($temp));
$this->cache->save(json_encode($allowedIps), $tag, []);
}
}

foreach ($data as $key => $value) {
if (!empty($value) && trim($value) == $ip) {
return true;
}
}
return false;
$ips = array_map("trim", explode(",", $clientIps));
$isAllowed = array_intersect($allowedIps, $ips);

return !empty($isAllowed);
}

private function log($message)
Expand Down

0 comments on commit a0622b7

Please sign in to comment.