Repository navigation
Expand file tree
/
Copy pathe404logger.plugin_code.php
More file actions
57 lines (51 loc) · 1.82 KB
/
Copy pathe404logger.plugin_code.php
File metadata and controls
57 lines (51 loc) · 1.82 KB
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
<?php
/**
* Error 404 Logger
*
* Plugin logs requests that trigger an Page not found error.
*
* @category plugin
* @version 0.2
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL)
* @author Andraz Kozelj (andraz dot kozelj at amis dot net) date created: 14.03.2007
* @author yama (https://kyms.jp)
* @internal @events OnPageNotFound, OnWebPageInit
* @internal @modx_category Manager and Admin
* @internal @properties &found_ref_only=Found ref only;list;yes,no;yes &count_robots=Robots count;list;yes,no;no; &robots=Robots list;text;googlebot,baidu,bing,crawl;&limit=Number of limit logs;1000 &trim=Number deleted at a time;100 &remoteIPIndexName=RemoteIP Index Name;text;REMOTE_ADDR
* @global $modx
* @global $remoteIPIndexName
*/
$e404logger_dir = 'assets/modules/error404logger/';
include_once(MODX_BASE_PATH . $e404logger_dir . 'helpers.php');
if (isset($_SESSION['mgrValidated'])) {
if (event()->name !== 'OnWebPageInit' || !getv('e404_redirect')) {
return;
}
header('Refresh: 0.5; URL=' . getv('e404_redirect'));
exit;
}
if (event()->name !== 'OnPageNotFound') {
return;
}
if (event()->param('found_ref_only') === 'yes' && !serverv('HTTP_REFERER')) {
return;
}
if (event()->param('count_robots') === 'no') {
$robots = explode(
',',
event()->param('robots', 'googlebot,baidu,msnbot')
);
$host_name = gethostbyaddr(serverv('REMOTE_ADDR'));
foreach ($robots as $robot) {
if (strpos($host_name, $robot) !== false) {
return;
}
}
}
include_once(MODX_BASE_PATH . $e404logger_dir . 'e404logger.class.inc.php');
$e404 = new Error404Logger();
$e404->insert(event()->param('remoteIPIndexName', 'REMOTE_ADDR'));
$e404->purge_log(
event()->param('limit', 1000),
event()->param('trim', 100)
);