Skip to content

Commit

Permalink
Merge pull request #692 from favicode/fix/maintenance-ips-in-rate-lim…
Browse files Browse the repository at this point in the history
…iting

Fix for checking if current IP is in maintenance IP list
  • Loading branch information
vvuksan committed Mar 27, 2024
2 parents a5748c1 + a0622b7 commit 2f4e11b
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 2f4e11b

Please sign in to comment.