/
global.inc
1274 lines (1192 loc) · 46.8 KB
/
global.inc
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 # global settings.php
/**
* Vars init
*/
$backdropcms = FALSE;
$custom_cache = FALSE;
$custom_da = FALSE;
$custom_fb = FALSE;
$da_inc = FALSE;
$deny_anon = FALSE;
$drupal_eight = FALSE;
$drupal_five = FALSE;
$drupal_seven = FALSE;
$drupal_six = FALSE;
$high_traffic = FALSE;
$ini_loc_src = FALSE;
$ini_plr_src = FALSE;
$is_backend = FALSE;
$is_bot = FALSE;
$is_dev = FALSE;
$is_install = FALSE;
$is_tmp = FALSE;
$raw_host = FALSE;
$redis_lock = FALSE;
$redis_path = FALSE;
$redis_up = FALSE;
$site_subdir = FALSE;
$use_redis = FALSE;
$usr_loc_ini = FALSE;
$usr_plr_ini = FALSE;
/**
* Detecting subdirectory mode
*/
if (isset($_SERVER['SITE_SUBDIR'])) {
$site_subdir = $_SERVER['SITE_SUBDIR'];
}
if (isset($_SERVER['RAW_HOST'])) {
$raw_host = $_SERVER['RAW_HOST'];
}
/**
* Backend and task detection
*/
if (function_exists('drush_get_command')) {
$command = drush_get_command();
$command = explode(" ", $command['command']);
if ($command && !preg_match("/^help/", $command[0])) {
$is_backend = TRUE;
}
if (preg_match("/^(provision-install|provision-save|provision-backup|php-eval)/", $command[0])) {
$is_install = TRUE;
}
}
/**
* Force backward compatible SERVER_SOFTWARE
*/
if (!$is_backend) {
if (isset($_SERVER['SERVER_SOFTWARE']) &&
!preg_match("/ApacheSolarisNginx/i", $_SERVER['SERVER_SOFTWARE'])) {
$_SERVER['SERVER_SOFTWARE'] = 'ApacheSolarisNginx/1.13.4';
}
}
/**
* Bots detection
*/
if (isset($_SERVER['HTTP_USER_AGENT']) &&
preg_match("/(?:crawl|bot|spider|tracker|click|parser|google|yahoo|yandex|baidu|bing)/i", $_SERVER['HTTP_USER_AGENT'])) {
$is_bot = TRUE;
}
/**
* Use Aegir/BOA specific MAIN_SITE_NAME instead of possibly fake SERVER_NAME
*/
if (isset($_SERVER['MAIN_SITE_NAME'])) {
$_SERVER['SERVER_NAME'] = $_SERVER['MAIN_SITE_NAME'];
}
/**
* Set MAIN_SITE_NAME to match SERVER_NAME, if MAIN_SITE_NAME is not set
*/
if (!isset($_SERVER['MAIN_SITE_NAME']) && isset($_SERVER['SERVER_NAME'])) {
$_SERVER['MAIN_SITE_NAME'] = $_SERVER['SERVER_NAME'];
}
/**
* Site mode detection - works also for aliases
*/
if (isset($_SERVER['HTTP_HOST']) &&
(preg_match("/(?:^dev\.|\.dev\.)/i", $_SERVER['HTTP_HOST']) ||
preg_match("/(?:^devel\.|\.devel\.)/i", $_SERVER['HTTP_HOST']) ||
preg_match("/(?:^tmp\.|\.tmp\.)/i", $_SERVER['HTTP_HOST']) ||
preg_match("/(?:^temp\.|\.temp\.)/i", $_SERVER['HTTP_HOST']) ||
preg_match("/(?:^temporary\.|\.temporary\.)/i", $_SERVER['HTTP_HOST']) ||
preg_match("/(?:^test\.|\.test\.)/i", $_SERVER['HTTP_HOST']) ||
preg_match("/(?:^testing\.|\.testing\.)/i", $_SERVER['HTTP_HOST']))) {
$is_tmp = TRUE;
}
/**
* Dev mode detection - works only for aliases
*/
if (isset($_SERVER['HTTP_HOST']) &&
isset($_SERVER['MAIN_SITE_NAME']) &&
preg_match("/(?:^dev\.|^devel\.|\.dev\.|\.devel\.)/i", $_SERVER['HTTP_HOST']) &&
$_SERVER['HTTP_HOST'] != $_SERVER['MAIN_SITE_NAME'] &&
$_SERVER['HTTP_HOST'] != $_SERVER['SERVER_NAME'] &&
!$is_backend) {
$is_dev = TRUE;
}
/**
* Bots protection for all tmp/dev sites - works also for aliases
*/
if ($is_bot) {
if ($is_tmp) {
// Ignore known bots
header('X-Accel-Expires: 300');
header('HTTP/1.0 404 Not Found');
header("Connection: close");
exit;
}
}
/**
* Site cron protection - cron works only for live sites
*/
if (preg_match("/^\/cron\.php/", $_SERVER['REQUEST_URI']) ||
preg_match("/^\/cron\//", $_SERVER['REQUEST_URI'])) {
if ($is_tmp) {
// Ignore cron requests
header('X-Accel-Expires: 300');
header('HTTP/1.0 404 Not Found');
header("Connection: close");
exit;
}
}
/**
* Required for proper Redis support on command line / via Drush
*/
if (isset($_SERVER['HTTP_HOST']) && !isset($_SERVER['SERVER_NAME'])) {
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
}
/**
* Core version detection
*/
if (file_exists('web.config')) {
if (file_exists('core')) {
if (file_exists('vendor/symfony') || file_exists('core/vendor/symfony')) {
$drupal_eight = TRUE;
$use_redis = TRUE;
if ($is_dev && !$is_backend) {
header('X-Backend: A');
}
}
else {
$backdropcms = TRUE;
if ($is_dev && !$is_backend) {
header('X-Backend: B');
}
}
}
else {
$drupal_seven = TRUE;
$use_redis = TRUE;
if ($is_dev && !$is_backend) {
header('X-Backend: C');
}
}
}
elseif (file_exists('modules/path_alias_cache')) {
$drupal_six = TRUE;
$use_redis = TRUE;
if ($is_dev && !$is_backend) {
header('X-Backend: D');
}
}
elseif (file_exists('modules/watchdog')) {
$drupal_five = TRUE;
if ($is_dev && !$is_backend) {
header('X-Backend: E');
}
}
else {
$drupal_unknown = TRUE;
if ($is_dev && !$is_backend) {
header('X-Backend: U');
}
}
/**
* Fix for Mollom, CloudFlare and others running via Proxy
*/
if (isset($_SERVER['REMOTE_ADDR'])) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
$_SERVER['HTTP_X_FORWARDED_FOR'] != "127.0.0.1") {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (isset($_SERVER['HTTP_X_REAL_IP']) &&
$_SERVER['HTTP_X_REAL_IP'] != "127.0.0.1") {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
}
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) &&
$_SERVER['HTTP_CF_CONNECTING_IP'] != "127.0.0.1") {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
}
/**
* Disable reporting errors by default - enable later only for foo.dev.domain
*/
error_reporting(0);
/**
* Forced default settings
*/
if ($drupal_eight) {
//
// Drupal 8 behaviour is confusing, because while it is possible
// to force settings listed below, they will not be shown in the
// site admin area. For example, CSS/JS aggregation checkboxes
// will accept on/off changes on form submit, while being silently
// overriden here.
//
$config['image.settings']['allow_insecure_derivatives'] = TRUE; // Not sure if it's a good idea in D8
$config['image.settings']['suppress_itok_output'] = TRUE; // Not sure if it's a good idea in D8
$config['system.cron']['threshold.autorun'] = FALSE; // Disable poormanscron
$config['system.logging']['error_level'] = 'hide'; // Disable errors on screen
$config['system.performance']['css']['preprocess'] = TRUE; // Enable hardcoded CSS aggregation
$config['system.performance']['js']['preprocess'] = TRUE; // Enable hardcoded JS aggregation
$config['system.performance']['response.gzip'] = FALSE; // Nginx already compresses everything
$config['composer_manager.settings']['vendor_dir'] = 'sites/' . $_SERVER['SERVER_NAME'] . '/vendor'; // Support for composer_manager
}
else {
if ($backdropcms) {
$conf['css_gzip_compression'] = FALSE; // Nginx already compresses everything
$conf['js_gzip_compression'] = FALSE; // Nginx already compresses everything
$settings['backdrop_drupal_compatibility'] = TRUE; // Enable Drupal backwards compatibility
}
$conf['page_compression'] = 0; // Nginx already compresses everything
$conf['boost_crawl_on_cron'] = 0; // Deny Boost crawler
$conf['cron_safe_threshold'] = 0; // Disable poormanscron
$conf['preprocess_css'] = 1; // Enable hardcoded CSS aggregation
$conf['preprocess_js'] = 1; // Enable hardcoded JS aggregation
$conf['file_downloads'] = 1; // Force public downloads by default
$conf['error_level'] = 0; // Disable errors on screen
$conf['statistics_enable_access_log'] = 0; // Disable access log stats
$conf['allow_authorize_operations'] = FALSE; // Disable insecure plugin manager
$conf['admin_menu_cache_client'] = FALSE; // Disable caching in admin_menu #442560
$conf['boost_ignore_htaccess_warning'] = 1; // Silence false alarm in boost
$conf['expire_flush_front'] = 1; // Default settings for expire module
$conf['expire_flush_node_terms'] = 1; // Default settings for expire module
$conf['expire_flush_menu_items'] = 0; // Default settings for expire module
$conf['expire_flush_cck_references'] = 0; // Default settings for expire module
$conf['expire_include_base_url'] = 1; // Default settings for expire module
$conf['js_server_software'] = "other"; // Set JS Callback handler server software
$conf['video_ffmpeg_instances'] = 1; // Force safe default for ffmpeg
$conf['securepages_enable'] = 1; // Force to avoid issues with ssl proxy
$conf['less_devel'] = FALSE; // Prevent CSS regeneration on every page load
$conf['drupal_http_request_fails'] = FALSE; // Avoid false alarm
$conf['image_allow_insecure_derivatives'] = TRUE; // Enable to avoid known issues: https://drupal.org/drupal-7.20-release-notes
$conf['theme_cloudy_settings']['omega_rebuild_aggregates'] = FALSE; // Do not allow to turn it on by default
$conf['theme_cloudy_settings']['omega_rebuild_theme_registry'] = FALSE; // Do not allow to turn it on by default
$conf['composer_manager_vendor_dir'] = 'sites/' . $_SERVER['SERVER_NAME'] . '/vendor'; // Support for composer_manager
$update_free_access = FALSE;
$conf['webform_table'] = TRUE; // Workaround for SA-CONTRIB-2015-063 https://www.drupal.org/node/2445935
$conf['features_rebuild_on_flush'] = FALSE; // https://michaelshadle.com/2015/04/21/speeding-up-drupal-cache-flushing
$conf['entity_rebuild_on_flush'] = FALSE; // http://a-fro.com/speed-up-cache-clearing-on-drupal7
// $conf['redis_eval_enabled'] = TRUE;
// Use EVAL commands to greatly speed up cache clearing
// Enable when https://www.drupal.org/node/2487333 is fixed
}
/**
* Logic for the front-end only
*/
if (!$is_backend) {
if (isset($_SERVER['HTTP_HOST']) && $is_bot) {
if (preg_match("/(?:^tmp\.|\.test\.|\.tmp\.)/i", $_SERVER['HTTP_HOST'])) {
// Deny known search bots on ^(tmp|foo.(tmp|test)).domain subdomains
header('X-Accel-Expires: 60');
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.aegirproject.org/");
header("Connection: close");
exit;
}
elseif (preg_match("/\.(?:host8|boa)\.(?:biz|io)$/i", $_SERVER['HTTP_HOST'])) {
// Deny known search bots on some protected CI subdomains
header('X-Accel-Expires: 60');
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://omega8.cc/");
header("Connection: close");
exit;
}
}
if ($is_dev) {
// Dev mode switch
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('opcache.revalidate_freq', '1');
if ($drupal_eight) {
unset($config['system.logging']['error_level']); // Stop hardcoding no errors on screen
unset($config['system.performance']['cache.page.max_age']); // Stop hardcoding internal page cache
unset($config['system.performance']['css']['preprocess']); // Stop hardcoding CSS aggregation
unset($config['system.performance']['js']['preprocess']); // Stop hardcoding JS aggregation
if (is_readable('sites/' . $_SERVER['SERVER_NAME'] . '/files/development.services.yml')) {
//
// This file, if exists, disables Redis on the fly!
//
$settings['container_yamls'][] = 'sites/' . $_SERVER['SERVER_NAME'] . '/files/development.services.yml';
//
// The two settings below make sense only if the development.services.yml file
// located in the sites/domain/files/ dir contains at least these three lines:
//
// services:
// cache.backend.null:
// class: Drupal\Core\Cache\NullBackendFactory
//
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
//
// Warning: you must clear caches via Aegir interface or with Drush
// before these lines will start working on .dev. alias without error 500
// saying: You have requested a non-existent service "cache.backend.null"
//
// To enable Twig debugging add in the development.services.yml file also lines:
//
// parameters:
// twig.config:
// debug: true
// auto_reload: true
// cache: true
//
// Note that normally you should not disable Twig cache, since auto_reload
// is enough for development and debugging, withot slowing down everything;
// see also: https://www.drupal.org/node/1903374
//
}
}
else {
$conf['xmlsitemap_submit'] = 0; // Disable XML Sitemap for foo.dev.domain
$conf['xmlsitemap_update'] = 0; // Disable XML Sitemap for foo.dev.domain
unset($conf['cache']); // Stop hardcoding internal page cache
unset($conf['error_level']); // Stop hardcoding no errors on screen
unset($conf['less_devel']); // Stop hardcoding CSS regeneration on every page load
unset($conf['preprocess_css']); // Stop hardcoding CSS aggregation
unset($conf['preprocess_js']); // Stop hardcoding JS aggregation
unset($conf['theme_cloudy_settings']['omega_rebuild_aggregates']); // Do not force on dev URLs
unset($conf['theme_cloudy_settings']['omega_rebuild_theme_registry']); // Do not force on dev URLs
}
}
else {
if (preg_match("/^\/cron\.php/", $_SERVER['REQUEST_URI'])) {
// Set longer opcache TTL for web based cron
ini_set('opcache.revalidate_freq', '300');
}
else {
// Set sane default opcache TTL on non-dev sites
ini_set('opcache.revalidate_freq', '60');
}
}
}
/**
* BOA INI defaults
*/
$boa_ini = array(
'session_cookie_ttl' => '86400',
'session_gc_eol' => '86400',
'redis_use_modern' => TRUE,
'redis_flush_forced_mode' => TRUE,
'redis_lock_enable' => TRUE,
'redis_path_enable' => TRUE,
'redis_scan_enable' => FALSE,
'redis_cache_disable' => FALSE,
'redis_exclude_bins' => FALSE,
'speed_booster_anon_cache_ttl' => FALSE,
'allow_anon_node_add' => FALSE,
'disable_admin_dos_protection' => FALSE,
'allow_private_file_downloads' => FALSE,
'server_name_cookie_domain' => FALSE,
'auto_detect_facebook_integration' => TRUE, // For backward compatibility until next release, then FALSE
'auto_detect_domain_access_integration' => TRUE, // For backward compatibility until next release, then FALSE
'advagg_auto_configuration' => FALSE, // Will be set to TRUE in boa_site_control.ini if the module is enabled
'purge_expire_auto_configuration' => FALSE, // Will be set to TRUE in boa_site_control.ini if the module is enabled
'disable_drupal_page_cache' => FALSE, // It is set to FALSE for backward compatibility and max performance
);
/**
* Optional system level early overrides
*/
if (is_readable('/data/conf/settings.global.inc')) {
require_once "/data/conf/settings.global.inc";
}
/**
* Optional site and platform level settings defined in the ini files
* Note: the site-level ini file takes precedence over platform level ini
*/
$all_ini = $boa_ini;
if (is_readable('sites/all/modules/boa_platform_control.ini')) {
$ini_plr_src = 'sites/all/modules/boa_platform_control.ini';
}
if ($ini_plr_src) {
$usr_plr_ini = array();
$usr_plr_ini = parse_ini_file($ini_plr_src);
}
if (is_readable('sites/' . $_SERVER['SERVER_NAME'] . '/modules/boa_site_control.ini')) {
$ini_loc_src = 'sites/' . $_SERVER['SERVER_NAME'] . '/modules/boa_site_control.ini';
}
if ($ini_loc_src) {
$usr_loc_ini = array();
$usr_loc_ini = parse_ini_file($ini_loc_src);
}
if (is_array($usr_plr_ini) && $usr_plr_ini) {
$all_ini = array_merge($all_ini, $usr_plr_ini);
}
if (is_array($usr_loc_ini) && $usr_loc_ini) {
$all_ini = array_merge($all_ini, $usr_loc_ini);
}
if (is_array($all_ini) && $is_dev && !$is_backend) {
if ($ini_plr_src) {
header("X-Ini-Plr-Src: " . $ini_plr_src);
}
if ($ini_loc_src) {
header("X-Ini-Loc-Src: " . $ini_loc_src);
}
if (!$ini_plr_src && !$ini_loc_src) {
header("X-Ini-Src: BOA-Default");
}
header("X-Ini-Redis-Use-Modern: " . $all_ini['redis_use_modern']);
header("X-Ini-Redis-Flush-Forced-Mode: " . $all_ini['redis_flush_forced_mode']);
header("X-Ini-Redis-Lock-Enable: " . $all_ini['redis_lock_enable']);
header("X-Ini-Redis-Path-Enable: " . $all_ini['redis_path_enable']);
header("X-Ini-Redis-Scan-Enable: " . $all_ini['redis_scan_enable']);
header("X-Ini-Redis-Cache-Disable: " . $all_ini['redis_cache_disable']);
header("X-Ini-Redis-Exclude-Bins: " . $all_ini['redis_exclude_bins']);
header("X-Ini-Speed-Booster-Anon-Cache-Ttl: " . $all_ini['speed_booster_anon_cache_ttl']);
header("X-Ini-Allow-Anon-Node-Add: " . $all_ini['allow_anon_node_add']);
header("X-Ini-Disable-Admin-Dos-Protection: " . $all_ini['disable_admin_dos_protection']);
header("X-Ini-Allow-Private-File-Downloads: " . $all_ini['allow_private_file_downloads']);
header("X-Ini-Server-Name-Cookie-Domain: " . $all_ini['server_name_cookie_domain']);
header("X-Ini-Auto-Detect-Facebook-Integration: " . $all_ini['auto_detect_facebook_integration']);
header("X-Ini-Auto-Detect-Domain-Access-Integration: " . $all_ini['auto_detect_domain_access_integration']);
header("X-Ini-Advagg-Auto-Configuration: " . $all_ini['advagg_auto_configuration']);
header("X-Ini-Purge-Expire-Auto-Configuration: " . $all_ini['purge_expire_auto_configuration']);
header("X-Ini-Sql-Conversion-Mode: " . $all_ini['sql_conversion_mode']);
header("X-Ini-Enable-User-Register-Protection: " . $all_ini['enable_user_register_protection']);
header("X-Ini-Entitycache-Dont-Enable: " . $all_ini['entitycache_dont_enable']);
header("X-Ini-Views-Cache-Bully-Dont-Enable: " . $all_ini['views_cache_bully_dont_enable']);
header("X-Ini-Views-Content-Cache-Dont-Enable: " . $all_ini['views_content_cache_dont_enable']);
header("X-Ini-Disable-User-Register-Protection: " . $all_ini['disable_user_register_protection']);
header("X-Ini-Session-Cookie-Ttl: " . $all_ini['session_cookie_ttl']);
header("X-Ini-Session-Gc-Eol: " . $all_ini['session_gc_eol']);
header("X-Ini-Disable-Drupal-Page-Cache: " . $all_ini['disable_drupal_page_cache']);
}
/**
* Enable page caching if disable_drupal_page_cache is not set to TRUE,
* but only on non-dev URLs and only for the front-end.
*/
if (!$is_backend && !$is_dev) {
if (!$is_bot && $all_ini['disable_drupal_page_cache']) {
if ($drupal_eight) {
$config['system.performance']['cache.page.max_age'] = 0;
}
else {
$conf['cache'] = 0;
}
}
else {
if ($drupal_eight) {
$config['system.performance']['cache.page.max_age'] = 60;
}
else {
$conf['cache'] = 1;
}
}
}
/**
* Disable page caching when Speed Booster is disabled on the fly
*/
if (!$is_bot && isset($_SERVER['REQUEST_URI']) &&
preg_match("/nocache=1/", $_SERVER['REQUEST_URI'])) {
if ($drupal_eight) {
$config['system.performance']['cache.page.max_age'] = 0;
}
else {
$conf['cache'] = 0;
}
}
/**
* Session Cookie TTL settings
*
* Set session cookie lifetime (in seconds), i.e. the time from the session is
* created to the cookie expires, i.e. when the browser is expected to discard
* the cookie. The value 0 means "until the browser is closed".
*/
ini_set('session.cookie_lifetime', $all_ini['session_cookie_ttl']);
/**
* Session Garbage Collector EOL settings
*
* Set session lifetime (in seconds), i.e. the time from the user's last visit
* to the active session may be deleted by the session garbage collector. When
* a session is deleted, authenticated users are logged out, and the contents
* of the user's $_SESSION variable is discarded.
*/
ini_set('session.gc_maxlifetime', $all_ini['session_gc_eol']);
/**
* Hostmaster specific settings
*/
if ($conf['install_profile'] == 'hostmaster') {
$conf['hosting_require_disable_before_delete'] = 0;
$conf['theme_link'] = FALSE;
$conf['cache'] = 0;
if (!$is_backend && isset($_SERVER['HTTP_USER_AGENT'])) {
ini_set('session.cookie_lifetime', 0); // Force log-out on browser quit
header('X-Accel-Expires: 1');
if (!file_exists('/data/conf/no-https-aegir.inc')) {
$request_type = ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ||
$_SERVER['HTTPS'] == 'on') ? 'SSL' : 'NONSSL';
if ($request_type != "SSL" &&
!preg_match("/^\/cron\.php/", $_SERVER['REQUEST_URI'])) { // we force secure connection here
header('X-Accel-Expires: 5');
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
header("Connection: close");
exit;
}
}
if (isset($_SERVER['HTTP_HOST']) &&
preg_match("/\.(?:host8|boa)\.(?:biz|io)$/i", $_SERVER['HTTP_HOST'])) {
if (preg_match("/^\/admin\/user\/user\/create/", $_SERVER['REQUEST_URI']) ||
preg_match("/^\/node\/add\/server/", $_SERVER['REQUEST_URI']) ||
preg_match("/^\/node\/(?:1|2|4|5|7|8|10)\/(?:edit|delete)/", $_SERVER['REQUEST_URI'])) {
header('X-Accel-Expires: 5');
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER['HTTP_HOST'] . "/hosting/sites");
header("Connection: close");
exit;
}
}
}
else {
$use_redis = TRUE;
}
}
/**
* Main section starts here
*/
if (isset($_SERVER['SERVER_NAME']) &&
$all_ini['allow_private_file_downloads']) {
unset($conf['file_downloads']); // Disable hardcoded public downloads
if ($is_dev && !$is_backend) {
header('X-Is-Cart: YES');
}
}
if (isset($_SERVER['SERVER_NAME']) && $all_ini['redis_cache_disable']) {
$use_redis = FALSE;
}
if (!$is_bot && isset($_SERVER['REQUEST_URI']) &&
preg_match("/noredis=1/", $_SERVER['REQUEST_URI'])) {
$use_redis = FALSE;
}
if ($use_redis && !$is_install && !$custom_cache) {
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
if ($redis->IsConnected()) {
$redis->auth('isfoobared');
$response = $redis->ping();
if (strpos($response, 'PONG')) {
$redis_up = TRUE;
}
$redis->close();
}
}
if ($redis_up && $use_redis) {
if ($is_dev && !$is_backend) {
header('X-Allow-Redis: YES');
}
}
else {
if ($is_dev && !$is_backend) {
header('X-Allow-Redis: NO');
}
}
if ($all_ini['auto_detect_domain_access_integration']) {
if (is_readable('sites/all/modules/domain/settings.inc')) {
$da_inc = 'sites/all/modules/domain/settings.inc';
}
elseif (is_readable('sites/all/modules/contrib/domain/settings.inc')) {
$da_inc = 'sites/all/modules/contrib/domain/settings.inc';
}
elseif (is_readable('profiles/' . $conf['install_profile'] . '/modules/domain/settings.inc')) {
$da_inc = 'profiles/' . $conf['install_profile'] . '/modules/domain/settings.inc';
}
elseif (is_readable('profiles/' . $conf['install_profile'] . '/modules/contrib/domain/settings.inc')) {
$da_inc = 'profiles/' . $conf['install_profile'] . '/modules/contrib/domain/settings.inc';
}
}
if ($is_install) {
$use_redis = FALSE;
$da_inc = FALSE;
}
if (isset($_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['USER_DEVICE'])) {
$this_device = $_SERVER['USER_DEVICE'];
}
else {
$this_device = 'normal';
}
/**
* Logic for non-dev URLs only
*/
if (!$is_dev) {
if ($all_ini['advagg_auto_configuration']) {
if ($drupal_six) {
if (is_readable('modules/o_contrib/advagg/advagg_bundler/advagg_bundler.module') ||
is_readable('sites/all/modules/advagg/advagg_bundler/advagg_bundler.module')) {
$conf['preprocess_css'] = 0; // CSS aggregation disabled
$conf['preprocess_js'] = 0; // JS aggregation disabled
$conf['advagg_aggregate_mode'] = 1;
$conf['advagg_async_generation'] = 1;
$conf['advagg_checksum_mode'] = "md5";
$conf['advagg_closure'] = 1;
$conf['advagg_css_compress_agg_files'] = 1;
$conf['advagg_css_compress_compressor_level'] = "sane";
$conf['advagg_css_compress_inline'] = 1;
$conf['advagg_css_compressor'] = 2;
$conf['advagg_debug'] = 0;
$conf['advagg_dir_htaccess'] = 0;
$conf['advagg_enabled'] = 1;
$conf['advagg_gzip_compression'] = 1;
$conf['advagg_js_compress_agg_files'] = 1;
$conf['advagg_js_compress_callback'] = 1;
$conf['advagg_js_compress_inline'] = 1;
$conf['advagg_js_compress_packer_enable'] = 0;
$conf['advagg_js_compressor'] = 1;
$conf['advagg_page_cache_mode'] = 0;
$conf['advagg_rebuild_on_flush'] = 0;
$conf['advagg_server_addr'] = "-1";
}
}
elseif ($drupal_seven) {
if (is_readable('modules/o_contrib_seven/advagg/advagg_bundler/advagg_bundler.module') ||
is_readable('sites/all/modules/advagg/advagg_bundler/advagg_bundler.module')) {
$conf['advagg_bundler_active'] = 1;
$conf['advagg_cache_level'] = 3;
$conf['advagg_combine_css_media'] = 0;
$conf['advagg_core_groups'] = 0;
$conf['advagg_css_compressor'] = 2;
$conf['advagg_css_compress_inline'] = 2;
$conf['advagg_css_compress_inline_if_not_cacheable'] = 1;
$conf['advagg_enabled'] = 1;
$conf['advagg_gzip'] = 1;
$conf['advagg_ie_css_selector_limiter'] = 1;
$conf['advagg_js_compressor'] = 3;
$conf['advagg_js_compress_packer'] = 0;
$conf['advagg_js_compress_inline'] = 3;
$conf['advagg_js_compress_inline_if_not_cacheable'] = 1;
$conf['preprocess_css'] = 1;
$conf['preprocess_js'] = 1;
}
}
elseif ($drupal_eight) {
if (is_readable('modules/o_contrib_eight/advagg/advagg_bundler/advagg_bundler.module') ||
is_readable('modules/advagg/advagg_bundler/advagg_bundler.module') ||
is_readable('sites/all/modules/advagg/advagg_bundler/advagg_bundler.module')) {
$config['advagg.settings']['css']['combine_media'] = false;
$config['advagg.settings']['css']['ie']['limit_selectors'] = true;
$config['advagg.settings']['cache_level'] = 3;
$config['advagg.settings']['core_groups'] = false;
$config['advagg.settings']['enabled'] = true;
$config['advagg_bundler.settings']['active'] = true;
$config['advagg_css_minify.settings']['minifier'] = 2;
$config['advagg_js_minify.settings']['minifier'] = 3;
$config['system.performance']['css']['preprocess'] = true;
$config['system.performance']['js']['preprocess'] = true;
}
}
if ($drupal_six || $drupal_seven) {
if (is_readable('modules/o_contrib/httprl/httprl.module') ||
is_readable('modules/o_contrib_seven/httprl/httprl.module')) {
$conf['advagg_use_httprl'] = 1;
$conf['httprl_background_callback'] = 1;
$conf['httprl_connect_timeout'] = 3;
$conf['httprl_dns_timeout'] = 3;
$conf['httprl_global_timeout'] = "60";
$conf['httprl_server_addr'] = "-1";
$conf['httprl_timeout'] = "10";
$conf['httprl_ttfb_timeout'] = "5";
### $conf['drupal_http_request_function'] = "httprl_override_core";
}
}
}
}
if ($drupal_six || $drupal_seven) {
if ($all_ini['purge_expire_auto_configuration']) {
if ($drupal_six) {
if (is_readable('modules/o_contrib/purge/purge.inc')) {
$conf['purge_proxy_urls'] = "http://127.0.0.1:8888/purge-normal?purge_method=get http://127.0.0.1:8888/purge-mobile-tablet?purge_method=get http://127.0.0.1:8888/purge-mobile-smart?purge_method=get http://127.0.0.1:8888/purge-mobile-other?purge_method=get";
if ($is_dev && !$is_backend) {
header('X-Purge-Level: 6');
}
}
else {
if ($is_dev && !$is_backend) {
header('X-Purge-Level: none');
}
}
}
if ($drupal_seven) {
if (is_readable('modules/o_contrib_seven/purge/purge.inc')) {
$conf['expire_flush_node_terms'] = 0; // Disable this to avoid WSOD - see https://drupal.org/node/1151686#comment-5556544
$conf['purge_proxy_urls'] = "http://127.0.0.1:8888/purge-normal?purge_method=get http://127.0.0.1:8888/purge-mobile-tablet?purge_method=get http://127.0.0.1:8888/purge-mobile-smart?purge_method=get http://127.0.0.1:8888/purge-mobile-other?purge_method=get";
if ($is_dev && !$is_backend) {
header('X-Purge-Level: 7');
}
}
else {
if ($is_dev && !$is_backend) {
header('X-Purge-Level: none');
}
}
}
}
else {
if ($is_dev && !$is_backend) {
header('X-Purge-Level: none');
}
}
}
/**
* More logic for the front-end only
*/
if (!$is_backend && isset($_SERVER['HTTP_HOST']) &&
isset($_SERVER['SERVER_NAME'])) {
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) || isset($_SERVER['HTTPS'])) {
$conf['https'] = TRUE;
$request_type = ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || $_SERVER['HTTPS'] == 'on') ? 'SSL' : 'NONSSL';
if ($request_type == "SSL") { // we check for secure connection to set correct base_url
$base_url = 'https://' . $_SERVER['HTTP_HOST'];
if ($conf['install_profile'] != 'hostmaster') {
$_SERVER['HTTPS'] = 'on';
if ($drupal_seven || $drupal_eight) {
ini_set('session.cookie_secure', TRUE);
if ($is_dev) {
header('X-Cookie-Sec: YES');
}
}
}
if ($is_dev) {
header('X-Local-Proto: https');
}
}
else {
if ($site_subdir && $raw_host) {
$base_url = 'http://' . $raw_host . '/' . $site_subdir;
}
else {
$base_url = 'http://' . $_SERVER['HTTP_HOST'];
}
}
}
else {
if ($site_subdir && $raw_host) {
$base_url = 'http://' . $raw_host . '/' . $site_subdir;
}
else {
$base_url = 'http://' . $_SERVER['HTTP_HOST'];
}
}
if ($base_url && $is_dev) {
header("X-Base-Url: " . $base_url);
}
if ($site_subdir && $is_dev) {
header("X-Site-Subdir: " . $site_subdir);
}
if ($all_ini['server_name_cookie_domain']) {
$domain = '.' . preg_replace('`^www\.`', '', $_SERVER['SERVER_NAME']);
}
elseif ($site_subdir && isset($_SERVER['RAW_HOST'])) {
$domain = '.' . preg_replace('`^www\.`', '', $_SERVER['RAW_HOST']);
}
else {
$domain = '.' . preg_replace('`^www\.`', '', $_SERVER['HTTP_HOST']);
}
$domain = str_replace('..', '.', $domain);
if (count(explode('.', $domain)) > 2 &&
!is_numeric(str_replace('.', '', $domain))) {
ini_set('session.cookie_domain', $domain);
$cookie_domain = $domain;
header("X-Cookie-Domain: " . $cookie_domain);
}
$this_prefix = preg_replace('`^www\.`', '', $_SERVER['SERVER_NAME']) . '_y_';
if ($is_dev) {
header("X-Redis-Prefix: " . $this_prefix);
}
if (isset($_SERVER['REQUEST_TIME']) &&
isset($_SERVER['REMOTE_ADDR']) &&
isset($_SERVER['HTTP_USER_AGENT']) &&
!preg_match("/^\/esi\//", $_SERVER['REQUEST_URI'])) {
$identity = $_SERVER['REQUEST_TIME'] . $_SERVER['REMOTE_ADDR'] . $_SERVER['SERVER_NAME'] . $_SERVER['HTTP_USER_AGENT'];
$identity = 'BD' . md5("$identity");
if ($drupal_seven || $drupal_eight) {
$conf['https'] = TRUE;
$sess_prefix = ini_get('session.cookie_secure') ? 'SSESS' : 'SESS';
$test_sess_name = $sess_prefix . substr(hash('sha256', $cookie_domain), 0, 32);
}
else {
$test_sess_name = 'SESS' . md5($cookie_domain);
}
if (!isset($_COOKIE[$test_sess_name]) && !$drupal_eight) {
if ($all_ini['speed_booster_anon_cache_ttl'] && preg_match("/^[0-9]{2,}$/", $all_ini['speed_booster_anon_cache_ttl'])) {
if ($all_ini['speed_booster_anon_cache_ttl'] > 10) {
$expire_in_seconds = $all_ini['speed_booster_anon_cache_ttl'];
header('X-Limit-Booster:' . $all_ini['speed_booster_anon_cache_ttl']);
}
}
}
if (!isset($_COOKIE[$test_sess_name]) && !$drupal_eight) {
if (preg_match("/\/(?:node\/[0-9]+\/edit|node\/add)/", $_SERVER['REQUEST_URI'])) {
if (!$all_ini['allow_anon_node_add']) {
$deny_anon = TRUE;
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $base_url . "/");
header("Connection: close");
exit;
}
}
if (preg_match("/^\/(?:[a-z]{2}\/)?(?:admin|logout|privatemsg|approve)/", $_SERVER['REQUEST_URI'])) {
if (!$all_ini['disable_admin_dos_protection']) {
$deny_anon = TRUE;
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $base_url . "/");
header("Connection: close");
exit;
}
}
}
// Prevent turning the feature server site into a spam machine
// Disable self-registration also on hostmaster
if ($conf['install_profile'] == 'feature_server' ||
$conf['install_profile'] == 'hostmaster') {
$conf['user_register'] = 0; // Force "Only site administrators can create new user accounts"
}
if (!$is_bot && !$high_traffic && !$deny_anon) {
if (preg_match("/^\/(?:[a-z]{2}\/)?(?:admin|cart|checkout|logout|privatemsg)/", $_SERVER['REQUEST_URI']) ||
preg_match("/\/(?:node\/[0-9]+\/edit|node\/add|comment\/reply|approve|ajax_comments|commerce_currency_select)/", $_SERVER['REQUEST_URI']) ||
preg_match("/(?:^dev\.|\.dev\.|\.devel\.)/", $_SERVER['HTTP_HOST'])) {
$expire_in_seconds = '1';
header('X-Limit-Booster: 1');
}
if (isset($_SERVER['REQUEST_URI']) &&
preg_match("/(?:x-progress-id|ahah|progress\/|autocomplete|ajax|batch|js\/.*)/i", $_SERVER['REQUEST_URI'])) {
$expire_in_seconds = '0';
if ($is_dev) {
header('X-Skip-Booster: AjaxRU');
}
}
if (isset($_SERVER['QUERY_STRING']) &&
preg_match("/(?:x-progress-id|ahah|progress\/|autocomplete|ajax|batch|js\/.*)/i", $_SERVER['QUERY_STRING'])) {
$expire_in_seconds = '0';
if ($is_dev) {
header('X-Skip-Booster: AjaxQS');
}
}
if (isset($_SERVER['REQUEST_METHOD']) &&
$_SERVER['REQUEST_METHOD'] == 'POST') {
if (!isset($_COOKIE['NoCacheID'])) {
$lifetime = '15';
setcookie('NoCacheID', 'POST' . $identity, $_SERVER['REQUEST_TIME'] + $lifetime, '/', $cookie_domain);
}
$expire_in_seconds = '0';
if ($is_dev) {
header('X-Skip-Booster: PostRM');
}
}
}
if ($is_bot) {
if (!preg_match("/Pingdom/i", $_SERVER['HTTP_USER_AGENT']) &&
!preg_match("/(?:rss|feed)/i", $_SERVER['REQUEST_URI'])) {
$expire_in_seconds = '3600';
if ($is_dev) {
header('X-Bot-Booster: 3600');
}
}
}
if ($conf['install_profile'] != 'hostmaster' && ($expire_in_seconds > -1)) {
header("X-Accel-Expires: " . $expire_in_seconds);
if ($expire_in_seconds > -1 && $expire_in_seconds < 2) {
$conf['cache'] = 0; // Disable page caching on the fly
}
}
}
}
/**
* Optional system level overrides
*/
if (is_readable('/data/conf/override.global.inc')) {
require_once "/data/conf/override.global.inc";
}
/**
* Use Redis caching and lock support only for d6 and d7 profiles
*/
if ($redis_up && $use_redis && !$custom_cache) {
$cache_backport = FALSE;
$cache_redis = FALSE;
if ($all_ini['redis_use_modern']) {
if ($drupal_eight) {
$redis_dirname = 'redis_eight';
}
else {
$redis_dirname = 'redis_edge';
}
if ($is_dev && !$is_backend) {
header("X-Redis-Version-Is: Modern");
}
if ($all_ini['redis_flush_forced_mode']) {
if ($drupal_eight) {
$settings['redis_perm_ttl'] = 21600; // 6 hours max
$settings['redis_flush_mode'] = 1; // Redis default is 0
$settings['redis_flush_mode_cache_page'] = 2; // Redis default is 1
$settings['redis_flush_mode_cache_block'] = 2; // Redis default is 1
$settings['redis_flush_mode_cache_menu'] = 2; // Redis default is 0
$settings['redis_flush_mode_cache_metatag'] = 2; // Redis default is 0
}
else {
$conf['redis_perm_ttl'] = 21600; // 6 hours max
$conf['redis_flush_mode'] = 1; // Redis default is 0
$conf['redis_flush_mode_cache_page'] = 2; // Redis default is 1
$conf['redis_flush_mode_cache_block'] = 2; // Redis default is 1
$conf['redis_flush_mode_cache_menu'] = 2; // Redis default is 0
$conf['redis_flush_mode_cache_metatag'] = 2; // Redis default is 0
}
// See http://bit.ly/1drmi35 for more information
if ($is_dev && !$is_backend) {
header("X-Redis-Flush-Forced-Mode: Forced");
}
}
}
else {