-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathConfig.php
1268 lines (1109 loc) · 35.4 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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;
use Magento\Framework\Filesystem;
use Magento\Framework\Module\Dir;
/**
* Model is responsible for replacing default vcl template
* file configuration with user-defined from configuration
*
* @author Magento Core Team <[email protected]>
*/
/**
* Class Config
*
* @package Fastly\Cdn\Model
*/
class Config extends \Magento\PageCache\Model\Config
{
/**
* Cache types
*/
const FASTLY = 'fastly';
/**
* Magento module prefix used for naming vcl snippets, condition and request
*/
const FASTLY_MAGENTO_MODULE = 'magentomodule';
/**
* Edge module prefix used for naming edge module snippets
*/
const FASTLY_MODLY_MODULE = 'edgemodule';
/**
* Magento Error Page Response Object Name
*/
const ERROR_PAGE_RESPONSE_OBJECT = self::FASTLY_MAGENTO_MODULE.'_error_page_response_object';
/**
* WAF Page Response Object Name
*/
const WAF_PAGE_RESPONSE_OBJECT = 'WAF_Response';
/**
* GeoIP action "dialog"
*/
const GEOIP_ACTION_DIALOG = 'dialog';
/**
* GeoIP action "redirect"
*/
const GEOIP_ACTION_REDIRECT = 'redirect';
/**
* Blocking snippets directory path
*/
const VCL_BLOCKING_PATH = '/vcl_snippets_blocking';
/**
* VCL blocking snippet
*/
const VCL_BLOCKING_SNIPPET = 'recv.vcl';
/**
* Blocking setting name
*/
const BLOCKING_SETTING_NAME = self::FASTLY_MAGENTO_MODULE.'_blocking_recv';
/**
* Rate Limiting snippets directory path
*/
const VCL_RATE_LIMITING_PATH = '/vcl_snippets_rate_limiting';
/**
* Rate limiting snippet
*/
const VCL_RATE_LIMITING_SNIPPET = 'recv.vcl';
/**
* Rate Limiting setting name
*/
const RATE_LIMITING_SETTING_NAME = self::FASTLY_MAGENTO_MODULE.'_rate_limiting';
/**
* WAF snippets directory path
*/
const VCL_WAF_PATH = '/vcl_snippets_waf';
/**
* VCL WAF snippet
*/
const VCL_WAF_ALLOWLIST_SNIPPET = 'recv.vcl';
/**
* WAF setting name
*/
const WAF_SETTING_NAME = self::FASTLY_MAGENTO_MODULE.'_waf_recv';
/**
* Authentication snippets directory path
*/
const VCL_AUTH_SNIPPET_PATH = '/vcl_snippets_basic_auth';
/**
* Maintenance snippets directory path
*/
const VCL_MAINT_SNIPPET_PATH = '/vcl_snippets_maintenance';
/**
* Authentication dictionary name
*/
const AUTH_DICTIONARY_NAME = self::FASTLY_MAGENTO_MODULE.'_basic_auth';
/**
* Image optimization setting name
*/
const IMAGE_SETTING_NAME = self::FASTLY_MAGENTO_MODULE.'_image_optimization_recv';
/**
* Force TLS snippet path
*/
const FORCE_TLS_PATH = '/vcl_snippets_force_tls';
/**
* Force TLS setting name
*/
const FORCE_TLS_SETTING_NAME = self::FASTLY_MAGENTO_MODULE.'_force_tls_recv';
/**
* Configure Dictionary name
*/
const CONFIG_DICTIONARY_NAME = self::FASTLY_MAGENTO_MODULE.'_config';
/**
* Maintenance Allowlist name
*/
const MAINT_ACL_NAME = 'maint_allowlist';
/**
* Config Dictionary key
*/
const CONFIG_DICTIONARY_KEY = 'allow_super_users_during_maint';
/**
* Custom snippet path
*/
const CUSTOM_SNIPPET_PATH = 'vcl_snippets_custom/';
/**
* Image optimization condition name
*/
const IO_CONDITION_NAME = 'fastly-image-optimizer-condition';
/**
* Image optimization header name
*/
const IO_HEADER_NAME = 'fastly-image-optimizer-header';
/**
* Image optimization snippet path
*/
const IO_VCL_SNIPPET_PATH = '/vcl_snippets_image_optimizations';
/**
* Error page snippet path
*/
const VCL_ERROR_SNIPPET_PATH = '/vcl_snippets_error_page';
/**
* Error page snippet
*/
const VCL_ERROR_SNIPPET = 'deliver.vcl';
/**
* XML path to Fastly config template path
*/
const FASTLY_CONFIGURATION_PATH = 'system/full_page_cache/fastly/path';
/**
* Path to Fastly service ID
*/
const FASTLY_API_ENDPOINT = 'https://api.fastly.com/';
/**
* XML path to Fastly service ID
*/
const XML_FASTLY_SERVICE_ID = 'system/full_page_cache/fastly/fastly_service_id';
/**
* XML path to Fastly API token
*/
const XML_FASTLY_API_KEY = 'system/full_page_cache/fastly/fastly_api_key';
/**
* XML path to stale ttl path
*/
const XML_FASTLY_STALE_TTL = 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_ttl';
/**
* config path to basic auth status
*/
const FASTLY_BASIC_AUTH_ENABLE = 'system/full_page_cache/fastly/fastly_basic_auth/enable_basic_auth';
/**
* XML path to stale error ttl path
*/
const XML_FASTLY_STALE_ERROR_TTL = 'system/full_page_cache/fastly/fastly_advanced_configuration/stale_error_ttl';
/**
* XML path to Fastly admin path timeout
*/
const XML_FASTLY_ADMIN_PATH_TIMEOUT
= 'system/full_page_cache/fastly/fastly_advanced_configuration/admin_path_timeout';
/**
* Max first byte timeout value
*/
const XML_FASTLY_MAX_FIRST_BYTE_TIMEOUT = 600;
/**
* XML path to Fastly ignored url parameters
*/
const XML_FASTLY_IGNORED_URL_PARAMETERS
= 'system/full_page_cache/fastly/fastly_advanced_configuration/ignored_url_parameters';
/**
* XML path to X-Magento-Tags size value
*/
const XML_FASTLY_X_MAGENTO_TAGS_SIZE
= 'system/full_page_cache/fastly/fastly_advanced_configuration/x_magento_tags_size';
/**
* XML path to purge catalog category
*/
const XML_FASTLY_PURGE_CATALOG_CATEGORY
= 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_category';
/**
* XML path to purge catalog product
*/
const XML_FASTLY_PURGE_CATALOG_PRODUCT
= 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_catalog_product';
/**
* XML path to purge CMS page
*/
const XML_FASTLY_PURGE_CMS_PAGE = 'system/full_page_cache/fastly/fastly_advanced_configuration/purge_cms_page';
/**
* XML path to config preserve_static
*/
const XML_FASTLY_PRESERVE_STATIC = 'system/full_page_cache/fastly/fastly_advanced_configuration/preserve_static';
/**
* XML path to soft purge
*/
const XML_FASTLY_SOFT_PURGE = 'system/full_page_cache/fastly/fastly_advanced_configuration/soft_purge';
/**
* XML path to enable GeoIP
*/
const XML_FASTLY_GEOIP_ENABLED = 'system/full_page_cache/fastly/fastly_advanced_configuration/enable_geoip';
/**
* XML path to GeoIP action
*/
const XML_FASTLY_GEOIP_ACTION = 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_action';
/**
* XML path to GeoIP redirect mapping
*/
const XML_FASTLY_GEOIP_COUNTRY_MAPPING
= 'system/full_page_cache/fastly/fastly_advanced_configuration/geoip_country_mapping';
/**
* XML path to Rate Limiting paths
*/
const XML_FASTLY_RATE_LIMITING_PATHS
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/fastly_path_protection/rate_limiting_paths';
/**
* XML path to Rate Limiting limit
*/
const XML_FASTLY_RATE_LIMITING_LIMIT
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/fastly_path_protection/rate_limiting_limit';
/**
* XML path to Rate Limiting TTL
*/
const XML_FASTLY_RATE_LIMITING_TTL
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/fastly_path_protection/rate_limiting_ttl';
/**
* XML path to image optimizations flag
*/
const XML_FASTLY_IMAGE_OPTIMIZATIONS
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations';
/**
* XML path to image optimization force lossy flag
*/
const XML_FASTLY_FORCE_LOSSY
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimization_force_lossy';
/**
* XML path to image optimization bg color flag
*/
const XML_FASTLY_IMAGE_OPTIMIZATION_BG_COLOR
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimization_bg_color';
/**
* XML path to image optimization image quality value
*/
const XML_FASTLY_IMAGE_OPTIMIZATION_IMAGE_QUALITY
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimization_image_quality';
/**
* XML path to image optimization canvas flag
*/
const XML_FASTLY_IMAGE_OPTIMIZATION_CANVAS
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimization_canvas';
/**
* XML path to image optimizations pixel ratio flag
*/
const XML_FASTLY_IMAGE_OPTIMIZATIONS_PIXEL_RATIO
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations_pixel_ratio';
/**
* XML path to image optimizations pixel ratios
*/
const XML_FASTLY_IMAGE_OPTIMIZATIONS_RATIOS
= 'system/full_page_cache/fastly/fastly_image_optimization_configuration/image_optimizations_ratios';
/**
* XML path to Google analytics CID
*/
const XML_FASTLY_GA_CID = 'system/full_page_cache/fastly/fastly_ga_cid';
/**
* XML path to Last checked issued Fastly M2 version
*/
const XML_FASTLY_LAST_CHECKED_ISSUED_VERSION = 'system/full_page_cache/fastly/last_checked_issues_version';
/**
* XML path to Fastly module version
*/
const XML_FASTLY_MODULE_VERSION = 'system/full_page_cache/fastly/current_version';
/**
* XML path to Fastly list of blocked countries
*/
const XML_FASTLY_BLOCK_BY_COUNTRY = 'system/full_page_cache/fastly/fastly_blocking/block_by_country';
/**
* XML path to Fastly list of blocked Acls
*/
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 Fastly list of WAF allowed Acls
*/
const XML_FASTLY_WAF_ALLOW_BY_ACL =
'system/full_page_cache/fastly/fastly_web_application_firewall/waf_allow_by_acl';
/**
* XML path to enable Webhooks
*/
const XML_FASTLY_WEBHOOKS_ENABLED = 'system/full_page_cache/fastly/fastly_web_hooks/enable_webhooks';
/**
* XML path to Webhook Username
*/
const XML_FASTLY_WEBHOOKS_USERNAME = 'system/full_page_cache/fastly/fastly_web_hooks/webhooks_username';
/**
* XML path to Incoming webhook URL
*/
const XML_FASTLY_INCOMING_WEBHOOK_URL = 'system/full_page_cache/fastly/fastly_web_hooks/incoming_webhook_url';
/**
* XML path to enable Publish Key and URL Purge Events
*/
const XML_FASTLY_PUBLISH_KEY_URL_PURGE_EVENTS
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_key_url_purge_events';
/**
* XML path to enable Publish Purge All/Clean All Items Events
*/
const XML_FASTLY_PUBLISH_PURGE_ALL_EVENTS
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_purge_all_items_events';
/**
* XML path to enable Publish Purge Events
*/
const XML_FASTLY_PUBLISH_PURGE_EVENTS
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_purge_events';
/**
* XML path to enable Publish Purge All/Clean backtrace
*/
const XML_FASTLY_PUBLISH_PURGE_ALL_TRACE
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_purge_all_trace';
/**
* XML path to enable Publish Purge By Key backtrace
*/
const XML_FASTLY_PUBLISH_PURGE_BY_KEY_TRACE
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_purge_by_key_trace';
/**
* XML path to enable Publish Generic Purge
*/
const XML_FASTLY_PUBLISH_PURGE_TRACE
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_purge_trace';
/**
* XML path to enable Publish Config change events
*/
const XML_FASTLY_PUBLISH_CONFIG_CHANGE_EVENTS
= 'system/full_page_cache/fastly/fastly_web_hooks/publish_config_change_events';
/**
* XML path to enable Publish Config change events
*/
const XML_FASTLY_WEBHOOK_MESSAGE_PREFIX
= 'system/full_page_cache/fastly/fastly_web_hooks/webhook_message_prefix';
/**
* XML path to enable Rate Limiting
*/
const XML_FASTLY_RATE_LIMITING_ENABLE
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/fastly_path_protection/enable_rate_limiting';
/**
* XML path to enable Crawler Protection
*/
const XML_FASTLY_CRAWLER_PROTECTION_ENABLE
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/enable_crawler_protection';
/**
* XML path to Crawler Protection Rate Limiting limit
*/
const XML_FASTLY_CRAWLER_RATE_LIMITING_LIMIT
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/crawler_rate_limiting_limit';
/**
* XML path to Crawler Protection Rate Limiting TTL
*/
const XML_FASTLY_CRAWLER_RATE_LIMITING_TTL
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/crawler_rate_limiting_ttl';
/**
* XML path to Exempt Good Bots flag
*/
const XML_FASTLY_EXEMPT_GOOD_BOTS
= 'system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/exempt_good_bots';
/**
* Check if Fastly is selected for Caching Application
*
* @return bool
*/
public function isFastlyEnabled()
{
if ($this->getType() == Config::FASTLY) {
return true;
}
return false;
}
/**
* Return Fastly module version from core resource
*
* @return string
*/
public function getFastlyVersion()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_MODULE_VERSION);
}
/**
* Return Google Analytics CID
*
* @return string
*/
public function getCID()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_GA_CID);
}
/**
* Return Fastly API endpoint
*
* @return string
*/
public function getApiEndpoint()
{
return self::FASTLY_API_ENDPOINT;
}
/**
* Return Fastly service IP
*
* @return int
*/
public function getServiceId()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_SERVICE_ID);
}
/**
* Return Fastly API token
*
* @return int
*/
public function getApiKey()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_API_KEY);
}
/**
* Return page lifetime
*
* @return int
*/
public function getTtl()
{
return (int)$this->_scopeConfig->getValue(self::XML_PAGECACHE_TTL);
}
/**
* Return page lifetime
*
* @return int
*/
public function getStaleTtl()
{
return (int)$this->_scopeConfig->getValue(self::XML_FASTLY_STALE_TTL);
}
/**
* Return page lifetime
*
* @return int
*/
public function getStaleErrorTtl()
{
return (int)$this->_scopeConfig->getValue(self::XML_FASTLY_STALE_ERROR_TTL);
}
/**
* Return admin path timeout
*
* @return int
*/
public function getAdminPathTimeout()
{
return (int)$this->_scopeConfig->getValue(self::XML_FASTLY_ADMIN_PATH_TIMEOUT);
}
public function getXMagentoTagsSize()
{
return (int)$this->_scopeConfig->getValue(self::XML_FASTLY_X_MAGENTO_TAGS_SIZE);
}
/**
* Return Fastly ignored url parameters
*
* @return int
*/
public function getIgnoredUrlParameters()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_IGNORED_URL_PARAMETERS);
}
/**
* Return basic auth status
*
* @return int
*/
public function getBasicAuthenticationStatus()
{
return (int)$this->_scopeConfig->getValue(self::FASTLY_BASIC_AUTH_ENABLE);
}
/**
* Returns can purge catalog category.
*
* @return bool
*/
public function canPurgeCatalogCategory()
{
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PURGE_CATALOG_CATEGORY);
}
/**
* Returns can purge catalog product.
*
* @return bool
*/
public function canPurgeCatalogProduct()
{
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PURGE_CATALOG_PRODUCT);
}
/**
* Returns can purge CMS page.
*
* @return bool
*/
public function canPurgeCmsPage()
{
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PURGE_CMS_PAGE);
}
/**
* Should we flush all or preserve static?
*
* @return bool
*/
public function canPreserveStatic()
{
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PRESERVE_STATIC);
}
/**
* Returns can use soft purge
*
* @return bool
*/
public function canUseSoftPurge()
{
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_SOFT_PURGE);
}
/**
* Return is GeoIP enabled
*
* @return bool
*/
public function isGeoIpEnabled()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_GEOIP_ENABLED));
}
/**
* Return GeoIP action
*
* @return string
*/
public function getGeoIpAction()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_GEOIP_ACTION);
}
/**
* Return GeoIP redirect mapping
*
* @return array
*/
public function getGeoIpRedirectMapping()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_GEOIP_COUNTRY_MAPPING);
}
/**
* Determines should Image optimization be used
*
* @return bool
*/
public function isImageOptimizationEnabled()
{
if ($this->isFastlyEnabled() !== true) {
return false;
}
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_IMAGE_OPTIMIZATIONS);
}
/**
* Determines should Image optimization pixel ratios be used
*
* @return bool
*/
public function isImageOptimizationPixelRatioEnabled()
{
if ($this->isImageOptimizationEnabled() !== true) {
return false;
}
return $this->_scopeConfig->isSetFlag(self::XML_FASTLY_IMAGE_OPTIMIZATIONS_PIXEL_RATIO);
}
/**
* Checks if the image optimization force lossy option is enabled
*
* @return mixed
*/
public function isForceLossyEnabled()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_FORCE_LOSSY);
}
/**
* Checks if the image optimization bg color option is enabled
*
* @return mixed
*/
public function isImageOptimizationBgColorEnabled()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_IMAGE_OPTIMIZATION_BG_COLOR);
}
/**
* Return image optimization pixel ratios
*
* @return mixed
*/
public function getImageOptimizationRatios()
{
return $this->_scopeConfig->getvalue(self::XML_FASTLY_IMAGE_OPTIMIZATIONS_RATIOS);
}
/**
* Return blocked countries
*
* @return mixed
*/
public function getBlockByCountry()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_BLOCK_BY_COUNTRY);
}
/**
* Return blocked Acls
*
* @return mixed
*/
public function getBlockByAcl()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_BLOCK_BY_ACL);
}
public function getWafAllowByAcl()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_WAF_ALLOW_BY_ACL);
}
/**
* Return are Webhooks enabled
*
* @return bool
*/
public function areWebHooksEnabled()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_WEBHOOKS_ENABLED));
}
/**
* Get Webhooks Endpoint URL
* @return mixed
*/
public function getIncomingWebhookURL()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_INCOMING_WEBHOOK_URL);
}
/**
* Get Webhooks Username
*
* @return mixed
*/
public function getWebhookUsername()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_WEBHOOKS_USERNAME);
}
/**
* Return is Publish Key and URL Purge Events enabled
*
* @return bool
*/
public function canPublishKeyUrlChanges()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_KEY_URL_PURGE_EVENTS));
}
/**
* return is Publish Purge All/Clean All Items Events enabled
*
* @return bool
*/
public function canPublishPurgeAllChanges()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_PURGE_ALL_EVENTS));
}
/**
* Is publishing purge changes allowed
*
* @return bool
*/
public function canPublishPurgeChanges()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_PURGE_EVENTS));
}
/**
* Is publishing backtrace on purge all allowed
*
* @return bool
*/
public function canPublishPurgeAllDebugBacktrace()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_PURGE_ALL_TRACE));
}
/**
* Is publishing backtrace on purge by key allowed
*
* @return bool
*/
public function canPublishPurgeByKeyDebugBacktrace()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_PURGE_BY_KEY_TRACE));
}
/**
* Is publishing backtrace on generic purge allowed
*
* @return bool
*/
public function canPublishPurgeDebugBacktrace()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_PURGE_TRACE));
}
/**
* return is Publish Config change events enabled
*
* @return bool
*/
public function canPublishConfigChanges()
{
return ($this->isEnabled() && $this->_scopeConfig->isSetFlag(self::XML_FASTLY_PUBLISH_CONFIG_CHANGE_EVENTS));
}
/**
* return Webhook message format
*
* @return mixed
*/
public function getWebhookMessagePrefix()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_WEBHOOK_MESSAGE_PREFIX);
}
/**
* return Webhook message format
*
* @return mixed
*/
public function getLastCheckedIssuedVersion()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_LAST_CHECKED_ISSUED_VERSION);
}
/**
* return Rate Limiting status
*
* @return mixed
*/
public function isRateLimitingEnabled()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_RATE_LIMITING_ENABLE);
}
/**
* return Rate Limiting limit
*
* @return mixed
*/
public function getRateLimitingLimit()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_RATE_LIMITING_LIMIT);
}
/**
* return Rate Limiting TTL
*
* @return mixed
*/
public function getRateLimitingTtl()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_RATE_LIMITING_TTL);
}
/**
* return Crawler Protection status
*
* @return mixed
*/
public function isCrawlerProtectionEnabled()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_CRAWLER_PROTECTION_ENABLE);
}
/**
* return Crawler Rate Limiting limit
*
* @return mixed
*/
public function getCrawlerRateLimitingLimit()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_CRAWLER_RATE_LIMITING_LIMIT);
}
/**
* return Crawler Rate Limiting TTL
*
* @return mixed
*/
public function getCrawlerRateLimitingTtl()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_CRAWLER_RATE_LIMITING_TTL);
}
/**
* Check if exempt good bots is enabled
*
* @return mixed
*/
public function isExemptGoodBotsEnabled()
{
return $this->_scopeConfig->getValue(self::XML_FASTLY_EXEMPT_GOOD_BOTS);
}
/**
* Get store ID for country.
*
* @param $countryCode 2-digit country code
* @return int|null
*/
public function getGeoIpMappingForCountry($countryCode)
{
if ($mapping = $this->_scopeConfig->getValue(self::XML_FASTLY_GEOIP_COUNTRY_MAPPING)) {
return $this->extractMapping($mapping, $countryCode);
}
return null;
}
/**
* Filter country code mapping by priority
*
* @param $mapping
* @param $countryCode
* @return int|null
*/
private function extractMapping($mapping, $countryCode)
{
$final = null;
$extractMapping = json_decode($mapping, true);
if (!$extractMapping) {
try {
$extractMapping = unserialize($mapping); // @codingStandardsIgnoreLine
} catch (\Exception $e) {
$extractMapping = [];
}
}
if (is_array($extractMapping)) {