File: global.php

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (280 lines) | stat: -rw-r--r-- 10,669 bytes parent folder | download
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
<?php

use Matomo\Cache\Eager;
use Piwik\SettingsServer;

return [

    'path.root' => PIWIK_DOCUMENT_ROOT,

    'path.misc.user' => 'misc/user/',

    'path.tmp' => function (\Piwik\Container\Container $c) {
        $root = PIWIK_USER_PATH;

        // TODO remove that special case and instead have plugins override 'path.tmp' to add the instance id
        if ($c->has('ini.General.instance_id')) {
            $instanceId = $c->get('ini.General.instance_id');
            $instanceId = $instanceId ? '/' . $instanceId : '';
        } else {
            $instanceId = '';
        }

        /** @var Piwik\Config\ $config */
        $config = $c->get('Piwik\Config');
        $general = $config->General;
        $tmp = empty($general['tmp_path']) ? '/tmp' : $general['tmp_path'];

        return MATOMO_TMP_PATH . '/' . $instanceId;
    },

    'path.tmp.templates' => Piwik\DI::string('{path.tmp}/templates_c'),

    'path.cache' => Piwik\DI::string('{path.tmp}/cache/tracker/'),

    'view.clearcompiledtemplates.enable' => true,

    'twig.cache' => Piwik\DI::string('{path.tmp.templates}'),

    'Matomo\Cache\Eager' => function (\Piwik\Container\Container $c) {
        $backend = $c->get('Matomo\Cache\Backend');
        $cacheId = $c->get('cache.eager.cache_id');

        if (SettingsServer::isTrackerApiRequest()) {
            $eventToPersist = 'Tracker.end';
            $cacheId .= 'tracker';
        } else {
            $eventToPersist = 'Request.dispatch.end';
            $cacheId .= 'ui';
        }

        $cache = new Eager($backend, $cacheId);
        \Piwik\Piwik::addAction($eventToPersist, function () use ($cache) {
            $cache->persistCacheIfNeeded(43200);
        });

        return $cache;
    },
    'Matomo\Cache\Backend' => function (\Piwik\Container\Container $c) {
        // If Piwik is not installed yet, it's possible the tmp/ folder is not writable
        // we prevent failing with an unclear message eg. coming from doctrine-cache
        // by forcing to use a cache backend which always works ie. array
        if (!\Piwik\SettingsPiwik::isMatomoInstalled()) {
            $backend = 'array';
        } else {
            try {
                $backend = $c->get('ini.Cache.backend');
            } catch (\Piwik\Exception\DI\NotFoundException $ex) {
                $backend = 'chained'; // happens if global.ini.php is not available
            }
        }

        return \Piwik\Cache::buildBackend($backend);
    },
    'cache.eager.cache_id' => function () {
        return 'eagercache-' . str_replace(['.', '-'], '', \Piwik\Version::VERSION) . '-';
    },

    /**
     * A list of API query parameters that map to entity IDs, for example, `idGoal` for goals.
     *
     * If your plugin introduces new entities that can be fetched or manipulated by ID through
     * API requests, you should add the query parameters that represent the new entity's IDs
     * to this array.
     */
    'entities.idNames' => Piwik\DI::add(['idGoal', 'idDimension']),

    /**
     * If your plugin uses custom query parameters in API requests (that is, query parameters not used
     * by a core plugin), and you want to be able to use those query parameters in system tests, you
     * will need to add them, via DI, to this array. Otherwise, in system tests, they will be
     * silently ignored.
     *
     * Note: if the query parameter has been added to `'entities.idNames'`, it does not need to be added
     * here as well.
     */
    'DocumentationGenerator.customParameters' => [],

    /**
     * A list of exact (case-sensitive) `Module.Action` pairs where token_auths with write/admin
     * access are allowed for non-API requests.
     *
     * Plugins can register actions in their `config/config.php`:
     *
     * return [
     *     'token_auth.write_admin_allowed_module_actions' => \Piwik\DI::add(['MyPlugin.myAction']),
     * ];
     *
     * @internal
     */
    'token_auth.write_admin_allowed_module_actions' => [],

    \Piwik\Log\Logger::class => Piwik\DI::create(\Piwik\Log\NullLogger::class),
    \Piwik\Log\LoggerInterface::class => Piwik\DI::create(\Piwik\Log\NullLogger::class),

    'Piwik\Translation\Loader\LoaderInterface' => Piwik\DI::autowire('Piwik\Translation\Loader\LoaderCache')
        ->constructorParameter('loader', Piwik\DI::get('Piwik\Translation\Loader\JsonFileLoader')),

    'DeviceDetector\Cache\Cache' => Piwik\DI::autowire('Piwik\DeviceDetector\DeviceDetectorCache')->constructor(86400),

    // specify plugins to load on demand via DI config. mostly for tests.
    'plugins.shouldLoadOnDemand' => [],

    // allow users to override plugin hardcoded value and avoid loading on demand
    'plugins.shouldNotLoadOnDemand' => [],

    'observers.global' => [],

    'dev.forced_plugin_update_result' => null,

    /**
     * By setting this option to false, the check that the DB schema version matches the version of the source code will
     * be no longer performed. Thus it allows you to execute for example a newer version of Matomo with an older Matomo
     * database version. Please note disabling this setting is not recommended because often an older DB version is not
     * compatible with newer source code.
     * If you disable this setting, make sure to execute the updates after updating the source code. The setting can be
     * useful if you want to update Matomo without any outage when you know the current source code update will still
     * run fine for a short time while in the background the database updates are running.
     */
    'EnableDbVersionCheck' => true,

    'fileintegrity.ignore' => Piwik\DI::add([
        '*.htaccess',
        '*web.config',
        'bootstrap.php',
        'favicon.ico',
        'robots.txt',
        '.bowerrc',
        '.lfsconfig',
        '.phpstorm.meta.php',
        'config/config.ini.php',
        'config/config.php',
        'config/common.ini.php',
        'config/*.config.ini.php',
        'config/manifest.inc.php',
        'misc/*.dat',
        'misc/*.dat.gz',
        'misc/*.mmdb',
        'misc/*.mmdb.gz',
        'misc/*.bin',
        'misc/user/*png',
        'misc/user/*svg',
        'misc/user/*js',
        'misc/user/*/config.ini.php',
        'misc/package',
        'misc/package/WebAppGallery/*.xml',
        'misc/package/WebAppGallery/install.sql',
        'plugins/ImageGraph/fonts/unifont.ttf',
        'plugins/*/config/tracker.php',
        'plugins/*/config/config.php',
        'vendor/autoload.php',
        'vendor/composer/autoload_real.php',
        'vendor/szymach/c-pchart/app/*',
        'tmp/*',
        // Search engine sites verification
        'google*.html',
        'BingSiteAuth.xml',
        'yandex*.html',
        // common files on shared hosters
        'php.ini',
        '.user.ini',
        'error_log',
        // Files below are not expected but they used to be present in older Piwik versions and may be still here
        // As they are not going to cause any trouble we won't report them as 'File to delete'
        '*.coveralls.yml',
        '*.scrutinizer.yml',
        '*.gitignore',
        '*.gitkeep',
        '*.gitmodules',
        '*.gitattributes',
        '*.git-blame-ignore-revs',
        '*.bower.json',
        '*.travis.yml',
    ]),

    'Piwik\EventDispatcher' => Piwik\DI::autowire()->constructorParameter('observers', Piwik\DI::get('observers.global')),

    'login.allowlist.ips' => function (\Piwik\Container\Container $c) {
        /** @var Piwik\Config\ $config */
        $config = $c->get('Piwik\Config');
        $general = $config->General;

        $ips = [];
        if (!empty($general['login_allowlist_ip']) && is_array($general['login_allowlist_ip'])) {
            $ips = $general['login_allowlist_ip'];
        } elseif (!empty($general['login_whitelist_ip']) && is_array($general['login_whitelist_ip'])) {
            // for BC
            $ips = $general['login_whitelist_ip'];
        }

        $ipsResolved = [];

        foreach ($ips as $ip) {
            $ip = trim($ip);
            if (filter_var($ip, FILTER_VALIDATE_IP) || \Matomo\Network\IPUtils::getIPRangeBounds($ip) !== null) {
                $ipsResolved[] = $ip;
            } else {
                $lazyCache = \Piwik\Cache::getLazyCache();
                $cacheKey = 'DNS.' . md5($ip);

                $resolvedIps = $lazyCache->fetch($cacheKey);

                if (!is_array($resolvedIps)) {
                    $resolvedIps = [];

                    $ipFromHost = @gethostbyname($ip);
                    if (!empty($ipFromHost) && $ipFromHost !== $ip) {
                        $resolvedIps[] = $ipFromHost;
                    }

                    if (function_exists('dns_get_record')) {
                        $entry = @dns_get_record($ip, DNS_AAAA);

                        if (
                            !empty($entry['0']['ipv6'])
                            && filter_var($entry['0']['ipv6'], FILTER_VALIDATE_IP)
                        ) {
                            $resolvedIps[] = $entry['0']['ipv6'];
                        }
                    }

                    $lazyCache->save($cacheKey, $resolvedIps, 30);
                }

                $ipsResolved = array_merge($ipsResolved, $resolvedIps);
            }
        }

        return $ipsResolved;
    },

    /**
     * This defines a list of hostnames Matomo's Http class will deny requests to. Wildcards (*) can be used in the
     * beginning to match any subdomain level or in the end to match any tlds
     */
    'http.blocklist.hosts' => [
        '*.amazonaws.com',
    ],

    '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')),

    'Piwik\Tracker\Settings' => Piwik\DI::autowire()
        ->constructorParameter(
            'isSameFingerprintsAcrossWebsites',
            Piwik\DI::get('ini.Tracker.enable_fingerprinting_across_websites')
        ),

    'archiving.performance.logger' => null,

    \Piwik\CronArchive\Performance\Logger::class => Piwik\DI::autowire()
        ->constructorParameter('logger', Piwik\DI::get('archiving.performance.logger')),

    \Piwik\Concurrency\LockBackend::class => \Piwik\DI::get(\Piwik\Concurrency\LockBackend\MySqlLockBackend::class),

    \Piwik\Segment\SegmentsList::class => function () {
        return \Piwik\Segment\SegmentsList::get();
    }
];