Skip to content

Commit

Permalink
Merge pull request #211 from Inchoo/feature/#192-blocking-functionali…
Browse files Browse the repository at this point in the history
…ty-refinement

Feature/#192 blocking functionality refinement
  • Loading branch information
vvuksan authored Oct 2, 2018
2 parents 3971be6 + 04bcc86 commit 90e5a6e
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 7 deletions.
1 change: 1 addition & 0 deletions Controller/Adminhtml/FastlyCdn/Vcl/Blocking.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function execute()
if ($strippedBlockedItems === '') {
$value = '';
} else {
$strippedBlockedItems = $this->config->processBlockedItems($strippedBlockedItems);
$value = str_replace('####BLOCKED_ITEMS####', $strippedBlockedItems, $value);
}

Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/FastlyCdn/Vcl/UpdateBlocking.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function execute()
if ($strippedBlockedItems === '') {
$value = '';
} else {
$strippedBlockedItems = $this->config->processBlockedItems($strippedBlockedItems);
$value = str_replace('####BLOCKED_ITEMS####', $strippedBlockedItems, $value);
}

Expand Down
19 changes: 19 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ class Config extends \Magento\PageCache\Model\Config
*/
const XML_FASTLY_BLOCK_BY_ACL = 'system/full_page_cache/fastly/fastly_blocking/block_by_acl';

/**
* XML path to the Fastly Blocking Type flag
*/
const XML_FASTLY_BLOCKING_TYPE = 'system/full_page_cache/fastly/fastly_blocking/blocking_type';

/**
* XML path to enable Webhooks
*/
Expand Down Expand Up @@ -1012,4 +1017,18 @@ public function validateCustomSnippet($name, $type, $priority)
'error' => $error
];
}

/**
* Process blocked items depending on blocking type
*
* @param $strippedBlockedItems
* @return string
*/
public function processBlockedItems($strippedBlockedItems)
{
if ($this->_scopeConfig->getValue(self::XML_FASTLY_BLOCKING_TYPE) == '1') {
$strippedBlockedItems = '!(' . $strippedBlockedItems . ')';
}
return $strippedBlockedItems;
}
}
48 changes: 48 additions & 0 deletions Model/Config/Backend/BlocklistAllowlist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Fastly CDN for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Fastly CDN for Magento End User License Agreement
* that is bundled with this package in the file LICENSE_FASTLY_CDN.txt.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Fastly CDN to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to http://www.magento.com for more information.
*
* @category Fastly
* @package Fastly_Cdn
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
* @license BSD, see LICENSE_FASTLY_CDN.txt
*/
namespace Fastly\Cdn\Model\Config\Backend;

/**
* @api
* @since 100.0.2
*/
class BlocklistAllowlist implements \Magento\Framework\Option\ArrayInterface
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [['value' => 0, 'label' => __('Blocklist')], ['value' => 1, 'label' => __('Allowlist')]];
}

/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [0 => __('Blocklist'), 1 => __('Allowlist')];
}
}
11 changes: 11 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@
<source_model>Fastly\Cdn\Model\Config\Backend\ListAcl</source_model>
<can_be_empty>1</can_be_empty>
</field>
<!-- ===========================
Block Type select field
============================ -->
<field id="blocking_type" translate="label comment" type="select" sortOrder="21" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Blocking Type</label>
<comment>
<![CDATA[<b>Blocklist:</b> block ALL access for users from designated countries/ACLs <br />
<b>Allowlist:</b> block ALL access except for users from designated countries/ACLs]]>
</comment>
<source_model>Fastly\Cdn\Model\Config\Backend\BlocklistAllowlist</source_model>
</field>
</group>
<!-- ================================
Custom Synthetic Pages group
Expand Down
3 changes: 3 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<purge_cms_page>0</purge_cms_page>
<enable_geoip>0</enable_geoip>
</fastly_advanced_configuration>
<fastly_blocking>
<blocking_type>0</blocking_type>
</fastly_blocking>
<fastly_image_optimization_configuration>
<image_optimizations>0</image_optimizations>
<image_optimization_force_lossy>0</image_optimization_force_lossy>
Expand Down
24 changes: 18 additions & 6 deletions view/adminhtml/templates/system/config/dialogs.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,33 @@
<option value="brisbane-au">AU, Brisbane</option>
<option value="melbourne-au">AU, Melbourne</option>
<option value="perth-au">AU, Perth</option>
<option value="sydney-au">AU, Sydney - Recommended for AWS ap-southeast-2, GCP australia-southeast1 origins</option>
<option value="gru-br-sa">BR, Sao Paulo - Recommended for AWS sa-east-1, GCP southamerica-east1</option>
<option value="sydney-au">
AU, Sydney - Recommended for AWS ap-southeast-2, GCP australia-southeast1 origins
</option>
<option value="gru-br-sa">
BR, Sao Paulo - Recommended for AWS sa-east-1, GCP southamerica-east1
</option>
<option value="yyz-on-ca">CA, Toronto</option>
<option value="yul-montreal-ca">CA, Montreal - Recommended for AWS ca-central-1, GCP northamerica-northeast1 origins</option>
<option value="yul-montreal-ca">
CA, Montreal - Recommended for AWS ca-central-1, GCP northamerica-northeast1 origins
</option>
<option value="mad-madrid-es">ES, Madrid</option>
<option value="hel-helsinki-fi">FI, Helsinki - Recommended for GCP europe-north1</option>
<option value="cdg-par-fr">FR, Paris- Recommended for AWS eu-west3 and GCP e </option>
<option value="hongkong-hk">HK, Hong Kong</option>
<option value="hhn-frankfurt-de">DE, Frankfurt - Interxion - Recommended for GCP europe-west3 origins</option>
<option value="hhn-frankfurt-de">
DE, Frankfurt - Interxion - Recommended for GCP europe-west3 origins
</option>
<option value="frankfurt-de">DE, Frankfurt - Recommended for AWS eu-central1 origins</option>
<option value="tokyo-jp2">JP, Tokyo - Recommended for AWS ap-northeast-1 origins</option>
<option value="osaka-jp">JP, Osaka - Recommened for AWS ap-northeast-3 origins</option>
<option value="amsterdam-nl">NL, Amsterdam - Recommended for GCP eu-west1/4 origins</option>
<option value="auckland-akl">NZ, Auckland</option>
<option value="wellington-wlg">NZ, Wellington</option>
<option value="stockholm-bma">SE, Stockholm</option>
<option value="singapore-sg">SG, Singapore - Recommended for AWS ap-southeast-1, GCP asia-southeast1 origins</option>
<option value="singapore-sg">
SG, Singapore - Recommended for AWS ap-southeast-1, GCP asia-southeast1 origins
</option>
<option value="london_city-uk">
UK, London - LCY - Recommended for AWS eu-west1/2 origins
</option>
Expand All @@ -260,7 +270,9 @@
<option value="miami-fl-us">US, Miami, FL</option>
<option value="jfk-ny-us">US, New York City, NY</option>
<option value="sjc-ca-us">US, San Jose, CA</option>
<option value="sea-wa-us">US, Seattle, WA - Recommended for AWS us-west2, GCP us-west1 origins</option>
<option value="sea-wa-us">
US, Seattle, WA - Recommended for AWS us-west2, GCP us-west1 origins
</option>
<option value="cpt-capetown-za">ZA, Capetown</option>
<option value="jnb-johannesburg-za">ZA, Johannesburg</option>
</select>
Expand Down
29 changes: 28 additions & 1 deletion view/adminhtml/web/js/blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ define([
"popup",
"resetAllMessages",
"showErrorMessage",
"Magento_Ui/js/modal/prompt",
'mage/translate'
], function ($, setServiceLabel, popup, resetAllMessages, showErrorMessage) {
], function ($, setServiceLabel, popup, resetAllMessages, showErrorMessage, prompt) {
return function (config, serviceStatus, isAlreadyConfigured) {

/* Blocking state elements*/
Expand Down Expand Up @@ -153,6 +154,32 @@ define([
});
});

/**
* Blocking Type on change event
*/
$('#system_full_page_cache_fastly_fastly_blocking_blocking_type').on('change', function () {
if (this.value === '1') {
prompt({
title: 'Blocking Type: Allowlist',
content: 'Turning on this feature will block ALL access except for users from designated countries/ACLs. ' +
'Please make sure you as the admin user are in one of the lists since you WILL lose access to the admin pages. ' +
'Only way to fix it is via Fastly management UI. Please type I ACKNOWLEDGE' +
' in the box below if you are sure you want to do this.',
actions: {
confirm: function (input) {
if (input !== 'I ACKNOWLEDGE') {
$('#system_full_page_cache_fastly_fastly_blocking_blocking_type').val('0');
}
},
cancel: function () {
$('#system_full_page_cache_fastly_fastly_blocking_blocking_type').val('0');
},
always: function () {}
}
});
}
});

/**
* Toggle Blocking VCL snippet
*
Expand Down

0 comments on commit 90e5a6e

Please sign in to comment.