Skip to content

Commit

Permalink
Merge branch 'master' into chore/PE2-1049/additional-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdebski-netacea authored May 6, 2024
2 parents d985098 + fdd616c commit a7dd24b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
20 changes: 11 additions & 9 deletions Block/GeoIp/GetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
* @license BSD, see LICENSE_FASTLY_CDN.txt
*/

namespace Fastly\Cdn\Block\GeoIp;

use Fastly\Cdn\Model\Config;
Expand Down Expand Up @@ -60,13 +61,14 @@ class GetAction extends AbstractBlock
* @param EncoderInterface $urlEncoder
*/
public function __construct(
Config $config,
Context $context,
Response $response,
Url $url,
Config $config,
Context $context,
Response $response,
Url $url,
EncoderInterface $urlEncoder,
array $data = []
) {
array $data = []
)
{
$this->config = $config;
$this->response = $response;
$this->url = $url;
Expand All @@ -92,8 +94,8 @@ protected function _toHtml() // @codingStandardsIgnoreLine - required by parent
$currentUrl = $this->url->getCurrentUrl();
$baseUrl = $this->url->getBaseUrl();
$webTypeUrl = $this->url->getBaseUrl(['_type' => Url::URL_TYPE_WEB]);
if (strpos($currentUrl, $baseUrl) !== false) {

if (strpos($currentUrl, rtrim($baseUrl, "/")) !== false) {
$targetUrl = $currentUrl;
} else {
$targetUrl = str_replace($webTypeUrl, $baseUrl, $currentUrl);
Expand All @@ -109,7 +111,7 @@ protected function _toHtml() // @codingStandardsIgnoreLine - required by parent
$this->response->setHeader("x-esi", "1");
}
// Due to Varnish parser limitations HTTPS ESIs are not supported so we need to turn them into HTTP URLs
// This does not mean that request will go over HTTP. ESI subrequest will go out to the backend that is
// This does not mean that request will go over HTTP. ESI subrequest will go out to the backend that is
// currently specified so if it's HTTPS it will go over HTTPS
return sprintf(
'<esi:include src=\'%s\' />',
Expand Down
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
2 changes: 1 addition & 1 deletion Model/Layout/LayoutPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function afterGenerateElements(\Magento\Framework\View\Layout $subject):
public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result) // @codingStandardsIgnoreLine - unused parameter
{
if ($this->config->getType() === Config::FASTLY) {
$this->response->setHeader("Fastly-Module-Enabled", "1.2.214", true);
$this->response->setHeader("Fastly-Module-Enabled", "1.2.216", true);
}

return $result;
Expand Down
8 changes: 8 additions & 0 deletions Release-Notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Fastly_Cdn Release Notes

## 1.2.216

- Fix for GEOIP redirection causes 404 in specific cases https://github.com/fastly/fastly-magento2/pull/694

## 1.2.215

- Fix for checking if current IP is in maintenance IP list https://github.com/fastly/fastly-magento2/pull/692

## 1.2.214

- Rate limiting doesn't work correctly when store codes are involved https://github.com/fastly/fastly-magento2/pull/689
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.214
1.2.216
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"zordius/lightncandy": "^1.2"
},
"type": "magento2-module",
"version": "1.2.214",
"version": "1.2.216",
"license": "BSD-3-Clause",
"autoload": {
"files": [ "registration.php" ],
Expand Down
2 changes: 1 addition & 1 deletion etc/vcl_snippets/deliver.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# Add an easy way to see whether custom Fastly VCL has been uploaded
if ( req.http.Fastly-Debug ) {
set resp.http.Fastly-Magento-VCL-Uploaded = "1.2.214";
set resp.http.Fastly-Magento-VCL-Uploaded = "1.2.216";
if (table.lookup(magentomodule_config, "allow_super_users_during_maint", "0") == "1") {
set resp.http.Fastly-Magento-Maintenance-Mode = "on";
}
Expand Down
2 changes: 1 addition & 1 deletion etc/vcl_snippets/miss.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
unset bereq.http.Accept-Encoding;

# Send VCL version uploaded to the backend
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.214";
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.216";
2 changes: 1 addition & 1 deletion etc/vcl_snippets/pass.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
}

# Send VCL version uploaded to the backend
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.214";
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.216";

0 comments on commit a7dd24b

Please sign in to comment.