This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathext_localconf.php
101 lines (89 loc) · 4.32 KB
/
ext_localconf.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
<?php
defined('TYPO3_MODE') || die();
$boot = function ($_EXTKEY) {
$config = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY]);
if (!is_array($config)) {
$config = [];
}
// Register additional clear_cache method
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] = \Causal\Cloudflare\Hooks\TCEmain::class . '->clear_cacheCmd';
$remoteIp = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR');
// @see https://www.cloudflare.com/ips
$whiteListIPv4s = [
'103.21.244.0/22',
'103.22.200.0/22',
'103.31.4.0/22',
'104.16.0.0/12',
'108.162.192.0/18',
'131.0.72.0/22',
'141.101.64.0/18',
'162.158.0.0/15',
'172.64.0.0/13',
'173.245.48.0/20',
'188.114.96.0/20',
'190.93.240.0/20',
'197.234.240.0/22',
'198.41.128.0/17',
'199.27.128.0/21',
];
$whiteListIPv6s = [
'2400:cb00::/32',
'2405:8100::/32',
'2405:b500::/32',
'2606:4700::/32',
'2803:f800::/32',
'2c0f:f248::/32',
'2a06:98c0::/29',
];
$isProxied = false;
if (isset($config['enableOriginatingIPs']) && (bool)$config['enableOriginatingIPs']) {
if (\TYPO3\CMS\Core\Utility\GeneralUtility::validIPv6($remoteIp)) {
$isProxied |= \TYPO3\CMS\Core\Utility\GeneralUtility::cmpIPv6($remoteIp, implode(',', $whiteListIPv6s));
} else {
$isProxied |= \TYPO3\CMS\Core\Utility\GeneralUtility::cmpIPv4($remoteIp, implode(',', $whiteListIPv4s));
}
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// We take for granted that reverse-proxy is properly configured
$isProxied = true;
}
if ($isProxied) {
// Flexible-SSL support
if (isset($_SERVER['HTTP_CF_VISITOR'])) {
$cloudflareVisitor = json_decode($_SERVER['HTTP_CF_VISITOR'], true);
if ($cloudflareVisitor['scheme'] === 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
$_SERVER['SERVER_PORT'] = '443';
}
}
// Cache SSL content
if (isset($config['cacheSslContent']) && (bool)$config['cacheSslContent']) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['nc_staticfilecache/class.tx_ncstaticfilecache.php']['createFile_initializeVariables'][] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/tx_ncstaticfilecache.php:Tx_Cloudflare_Hooks_NcStaticfilecache->createFile_initializeVariables';
}
if (isset($config['enableOriginatingIPs']) && (bool)$config['enableOriginatingIPs']) {
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
}
}
if (isset($config['enablePurgeByTags']) && (bool)$config['enablePurgeByTags']) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['insertPageIncache'][$_EXTKEY] =
\Causal\Cloudflare\Hooks\ContentProcessor::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-output'][$_EXTKEY] =
\Causal\Cloudflare\Hooks\ContentProcessor::class . '->sendPageCacheTag';
}
if (TYPO3_MODE === 'BE' && !empty($config['apiKey'])) {
if (version_compare(TYPO3_version, '6.99.99', '<=')) {
$cloudflareToolbarItemClassPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY, 'Classes/Hooks/TYPO3backend_Cloudflare.php');
$GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'][] = $cloudflareToolbarItemClassPath;
} else {
$GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'][] = 'Causal\\Cloudflare\\Backend\\ToolbarItems\\CloudflareToolbarItem';
}
if ($config['domains'] !== '') {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions']['clearCloudflareCache'] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/TYPO3backend.php:Causal\\Cloudflare\\Hooks\\TYPO3backend';
$GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['cloudflare::clearCache'] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/TCEmain.php:Causal\\Cloudflare\\Hooks\\TCEmain->clearCache';
}
}
};
$boot($_EXTKEY);
unset($boot);