global.php
222 lines
| 1 | <?php |
| 2 | |
| 3 | namespace { |
| 4 | use Matomo\Cache\Eager; |
| 5 | use Piwik\SettingsServer; |
| 6 | return [ |
| 7 | 'path.root' => \PIWIK_DOCUMENT_ROOT, |
| 8 | 'path.misc.user' => 'misc/user/', |
| 9 | 'path.tmp' => function (\Piwik\Container\Container $c) { |
| 10 | $root = \PIWIK_USER_PATH; |
| 11 | // TODO remove that special case and instead have plugins override 'path.tmp' to add the instance id |
| 12 | if ($c->has('ini.General.instance_id')) { |
| 13 | $instanceId = $c->get('ini.General.instance_id'); |
| 14 | $instanceId = $instanceId ? '/' . $instanceId : ''; |
| 15 | } else { |
| 16 | $instanceId = ''; |
| 17 | } |
| 18 | /** @var Piwik\Config\ $config */ |
| 19 | $config = $c->get('Piwik\\Config'); |
| 20 | $general = $config->General; |
| 21 | $tmp = empty($general['tmp_path']) ? '/tmp' : $general['tmp_path']; |
| 22 | return $root . $tmp . $instanceId; |
| 23 | }, |
| 24 | 'path.tmp.templates' => \Piwik\DI::string('{path.tmp}/templates_c'), |
| 25 | 'path.cache' => \Piwik\DI::string('{path.tmp}/cache/tracker/'), |
| 26 | 'view.clearcompiledtemplates.enable' => \true, |
| 27 | 'twig.cache' => \Piwik\DI::string('{path.tmp.templates}'), |
| 28 | 'Matomo\\Cache\\Eager' => function (\Piwik\Container\Container $c) { |
| 29 | $backend = $c->get('Matomo\\Cache\\Backend'); |
| 30 | $cacheId = $c->get('cache.eager.cache_id'); |
| 31 | if (SettingsServer::isTrackerApiRequest()) { |
| 32 | $eventToPersist = 'Tracker.end'; |
| 33 | $cacheId .= 'tracker'; |
| 34 | } else { |
| 35 | $eventToPersist = 'Request.dispatch.end'; |
| 36 | $cacheId .= 'ui'; |
| 37 | } |
| 38 | $cache = new Eager($backend, $cacheId); |
| 39 | \Piwik\Piwik::addAction($eventToPersist, function () use($cache) { |
| 40 | $cache->persistCacheIfNeeded(43200); |
| 41 | }); |
| 42 | return $cache; |
| 43 | }, |
| 44 | 'Matomo\\Cache\\Backend' => function (\Piwik\Container\Container $c) { |
| 45 | // If Piwik is not installed yet, it's possible the tmp/ folder is not writable |
| 46 | // we prevent failing with an unclear message eg. coming from doctrine-cache |
| 47 | // by forcing to use a cache backend which always works ie. array |
| 48 | if (!\Piwik\SettingsPiwik::isMatomoInstalled()) { |
| 49 | $backend = 'array'; |
| 50 | } else { |
| 51 | try { |
| 52 | $backend = $c->get('ini.Cache.backend'); |
| 53 | } catch (\Piwik\Exception\DI\NotFoundException $ex) { |
| 54 | $backend = 'chained'; |
| 55 | // happens if global.ini.php is not available |
| 56 | } |
| 57 | } |
| 58 | return \Piwik\Cache::buildBackend($backend); |
| 59 | }, |
| 60 | 'cache.eager.cache_id' => function () { |
| 61 | return 'eagercache-' . \str_replace(['.', '-'], '', \Piwik\Version::VERSION) . '-'; |
| 62 | }, |
| 63 | /** |
| 64 | * A list of API query parameters that map to entity IDs, for example, `idGoal` for goals. |
| 65 | * |
| 66 | * If your plugin introduces new entities that can be fetched or manipulated by ID through |
| 67 | * API requests, you should add the query parameters that represent the new entity's IDs |
| 68 | * to this array. |
| 69 | */ |
| 70 | 'entities.idNames' => \Piwik\DI::add(['idGoal', 'idDimension']), |
| 71 | /** |
| 72 | * If your plugin uses custom query parameters in API requests (that is, query parameters not used |
| 73 | * by a core plugin), and you want to be able to use those query parameters in system tests, you |
| 74 | * will need to add them, via DI, to this array. Otherwise, in system tests, they will be |
| 75 | * silently ignored. |
| 76 | * |
| 77 | * Note: if the query parameter has been added to `'entities.idNames'`, it does not need to be added |
| 78 | * here as well. |
| 79 | */ |
| 80 | 'DocumentationGenerator.customParameters' => [], |
| 81 | /** |
| 82 | * A list of exact (case-sensitive) `Module.Action` pairs where token_auths with write/admin |
| 83 | * access are allowed for non-API requests. |
| 84 | * |
| 85 | * Plugins can register actions in their `config/config.php`: |
| 86 | * |
| 87 | * return [ |
| 88 | * 'token_auth.write_admin_allowed_module_actions' => \Piwik\DI::add(['MyPlugin.myAction']), |
| 89 | * ]; |
| 90 | * |
| 91 | * @internal |
| 92 | */ |
| 93 | 'token_auth.write_admin_allowed_module_actions' => [], |
| 94 | \Piwik\Log\Logger::class => \Piwik\DI::create(\Piwik\Log\NullLogger::class), |
| 95 | \Piwik\Log\LoggerInterface::class => \Piwik\DI::create(\Piwik\Log\NullLogger::class), |
| 96 | 'Piwik\\Translation\\Loader\\LoaderInterface' => \Piwik\DI::autowire('Piwik\\Translation\\Loader\\LoaderCache')->constructorParameter('loader', \Piwik\DI::get('Piwik\\Translation\\Loader\\JsonFileLoader')), |
| 97 | 'DeviceDetector\\Cache\\Cache' => \Piwik\DI::autowire('Piwik\\DeviceDetector\\DeviceDetectorCache')->constructor(86400), |
| 98 | // specify plugins to load on demand via DI config. mostly for tests. |
| 99 | 'plugins.shouldLoadOnDemand' => [], |
| 100 | // allow users to override plugin hardcoded value and avoid loading on demand |
| 101 | 'plugins.shouldNotLoadOnDemand' => [], |
| 102 | 'observers.global' => [], |
| 103 | 'dev.forced_plugin_update_result' => null, |
| 104 | /** |
| 105 | * By setting this option to false, the check that the DB schema version matches the version of the source code will |
| 106 | * be no longer performed. Thus it allows you to execute for example a newer version of Matomo with an older Matomo |
| 107 | * database version. Please note disabling this setting is not recommended because often an older DB version is not |
| 108 | * compatible with newer source code. |
| 109 | * If you disable this setting, make sure to execute the updates after updating the source code. The setting can be |
| 110 | * useful if you want to update Matomo without any outage when you know the current source code update will still |
| 111 | * run fine for a short time while in the background the database updates are running. |
| 112 | */ |
| 113 | 'EnableDbVersionCheck' => \true, |
| 114 | 'fileintegrity.ignore' => \Piwik\DI::add([ |
| 115 | '*.htaccess', |
| 116 | '*web.config', |
| 117 | 'bootstrap.php', |
| 118 | 'favicon.ico', |
| 119 | 'robots.txt', |
| 120 | '.bowerrc', |
| 121 | '.lfsconfig', |
| 122 | '.phpstorm.meta.php', |
| 123 | 'config/config.ini.php', |
| 124 | 'config/config.php', |
| 125 | 'config/common.ini.php', |
| 126 | 'config/*.config.ini.php', |
| 127 | 'config/manifest.inc.php', |
| 128 | 'misc/*.dat', |
| 129 | 'misc/*.dat.gz', |
| 130 | 'misc/*.mmdb', |
| 131 | 'misc/*.mmdb.gz', |
| 132 | 'misc/*.bin', |
| 133 | 'misc/user/*png', |
| 134 | 'misc/user/*svg', |
| 135 | 'misc/user/*js', |
| 136 | 'misc/user/*/config.ini.php', |
| 137 | 'misc/package', |
| 138 | 'misc/package/WebAppGallery/*.xml', |
| 139 | 'misc/package/WebAppGallery/install.sql', |
| 140 | 'plugins/ImageGraph/fonts/unifont.ttf', |
| 141 | 'plugins/*/config/tracker.php', |
| 142 | 'plugins/*/config/config.php', |
| 143 | 'vendor/autoload.php', |
| 144 | 'vendor/composer/autoload_real.php', |
| 145 | 'vendor/szymach/c-pchart/app/*', |
| 146 | 'tmp/*', |
| 147 | // Search engine sites verification |
| 148 | 'google*.html', |
| 149 | 'BingSiteAuth.xml', |
| 150 | 'yandex*.html', |
| 151 | // common files on shared hosters |
| 152 | 'php.ini', |
| 153 | '.user.ini', |
| 154 | 'error_log', |
| 155 | // Files below are not expected but they used to be present in older Piwik versions and may be still here |
| 156 | // As they are not going to cause any trouble we won't report them as 'File to delete' |
| 157 | '*.coveralls.yml', |
| 158 | '*.scrutinizer.yml', |
| 159 | '*.gitignore', |
| 160 | '*.gitkeep', |
| 161 | '*.gitmodules', |
| 162 | '*.gitattributes', |
| 163 | '*.git-blame-ignore-revs', |
| 164 | '*.bower.json', |
| 165 | '*.travis.yml', |
| 166 | ]), |
| 167 | 'Piwik\\EventDispatcher' => \Piwik\DI::autowire()->constructorParameter('observers', \Piwik\DI::get('observers.global')), |
| 168 | 'login.allowlist.ips' => function (\Piwik\Container\Container $c) { |
| 169 | /** @var Piwik\Config\ $config */ |
| 170 | $config = $c->get('Piwik\\Config'); |
| 171 | $general = $config->General; |
| 172 | $ips = []; |
| 173 | if (!empty($general['login_allowlist_ip']) && \is_array($general['login_allowlist_ip'])) { |
| 174 | $ips = $general['login_allowlist_ip']; |
| 175 | } elseif (!empty($general['login_whitelist_ip']) && \is_array($general['login_whitelist_ip'])) { |
| 176 | // for BC |
| 177 | $ips = $general['login_whitelist_ip']; |
| 178 | } |
| 179 | $ipsResolved = []; |
| 180 | foreach ($ips as $ip) { |
| 181 | $ip = \trim($ip); |
| 182 | if (\filter_var($ip, \FILTER_VALIDATE_IP) || \Matomo\Network\IPUtils::getIPRangeBounds($ip) !== null) { |
| 183 | $ipsResolved[] = $ip; |
| 184 | } else { |
| 185 | $lazyCache = \Piwik\Cache::getLazyCache(); |
| 186 | $cacheKey = 'DNS.' . \md5($ip); |
| 187 | $resolvedIps = $lazyCache->fetch($cacheKey); |
| 188 | if (!\is_array($resolvedIps)) { |
| 189 | $resolvedIps = []; |
| 190 | $ipFromHost = @\gethostbyname($ip); |
| 191 | if (!empty($ipFromHost) && $ipFromHost !== $ip) { |
| 192 | $resolvedIps[] = $ipFromHost; |
| 193 | } |
| 194 | if (\function_exists('dns_get_record')) { |
| 195 | $entry = @\dns_get_record($ip, \DNS_AAAA); |
| 196 | if (!empty($entry['0']['ipv6']) && \filter_var($entry['0']['ipv6'], \FILTER_VALIDATE_IP)) { |
| 197 | $resolvedIps[] = $entry['0']['ipv6']; |
| 198 | } |
| 199 | } |
| 200 | $lazyCache->save($cacheKey, $resolvedIps, 30); |
| 201 | } |
| 202 | $ipsResolved = \array_merge($ipsResolved, $resolvedIps); |
| 203 | } |
| 204 | } |
| 205 | return $ipsResolved; |
| 206 | }, |
| 207 | /** |
| 208 | * This defines a list of hostnames Matomo's Http class will deny requests to. Wildcards (*) can be used in the |
| 209 | * beginning to match any subdomain level or in the end to match any tlds |
| 210 | */ |
| 211 | 'http.blocklist.hosts' => ['*.amazonaws.com'], |
| 212 | 'Piwik\\Tracker\\VisitorRecognizer' => \Piwik\DI::autowire()->constructorParameter('trustCookiesOnly', \Piwik\DI::get('ini.Tracker.trust_visitors_cookies'))->constructorParameter('visitStandardLength', \Piwik\DI::get('ini.Tracker.visit_standard_length'))->constructorParameter('lookbackNSecondsCustom', \Piwik\DI::get('ini.Tracker.window_look_back_for_visitor')), |
| 213 | 'Piwik\\Tracker\\Settings' => \Piwik\DI::autowire()->constructorParameter('isSameFingerprintsAcrossWebsites', \Piwik\DI::get('ini.Tracker.enable_fingerprinting_across_websites')), |
| 214 | 'archiving.performance.logger' => null, |
| 215 | \Piwik\CronArchive\Performance\Logger::class => \Piwik\DI::autowire()->constructorParameter('logger', \Piwik\DI::get('archiving.performance.logger')), |
| 216 | \Piwik\Concurrency\LockBackend::class => \Piwik\DI::get(\Piwik\Concurrency\LockBackend\MySqlLockBackend::class), |
| 217 | \Piwik\Segment\SegmentsList::class => function () { |
| 218 | return \Piwik\Segment\SegmentsList::get(); |
| 219 | }, |
| 220 | ]; |
| 221 | } |
| 222 |