More bot detection rules
This commit is contained in:
18
action.php
18
action.php
@@ -54,6 +54,18 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin {
|
||||
];
|
||||
|
||||
/* Write out server-side info to a server log: */
|
||||
$this->writeServerLog($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the server log.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function writeServerLog($username) {
|
||||
|
||||
global $conf;
|
||||
global $INFO;
|
||||
|
||||
// what is the session identifier?
|
||||
$sessionId = $_COOKIE['DokuWiki'] ?? '';
|
||||
@@ -69,6 +81,7 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin {
|
||||
// clean the page ID
|
||||
$pageId = preg_replace('/[\x00-\x1F]/', "\u{FFFD}", $INFO['id'] ?? '');
|
||||
|
||||
// create the log array:
|
||||
$logArr = Array(
|
||||
$_SERVER['REMOTE_ADDR'] ?? '', /* remote IP */
|
||||
$pageId, /* page ID */
|
||||
@@ -76,7 +89,9 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin {
|
||||
$sessionType, /* session ID type */
|
||||
$username,
|
||||
$_SERVER['HTTP_USER_AGENT'] ?? '', /* User agent */
|
||||
$_SERVER['HTTP_REFERER'] ?? '' /* HTTP Referrer */
|
||||
$_SERVER['HTTP_REFERER'] ?? '', /* HTTP Referrer */
|
||||
substr($conf['lang'],0,2), /* page language */
|
||||
implode(',', array_unique(array_map( function($it) { return substr($it,0,2); }, explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'])))) /* accepted client languages */
|
||||
);
|
||||
|
||||
//* create the log line */
|
||||
@@ -96,6 +111,5 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin {
|
||||
|
||||
/* Done */
|
||||
fclose($logfile);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,10 @@
|
||||
"id": "noRefs", "desc": "No referer field",
|
||||
"bot": 30
|
||||
},
|
||||
{"func": "matchLang", "params": ["en"],
|
||||
"id": "langMatch", "desc": "Client’s ‘Accept-Language’ header does not match the page language (except English pages)",
|
||||
"bot": 20
|
||||
},
|
||||
{"func": "clientTest", "params": ["brave"],
|
||||
"id": "susClient", "desc": "Client identifier that is popular with bot networks",
|
||||
"bot": 10
|
||||
@@ -62,6 +66,7 @@
|
||||
{"from": "124.243.128.0", "to": "124.243.191.255", "isp": "huawei", "loc":"sg"},
|
||||
{"from": "150.40.128.0", "to": "150.40.255.255", "isp": "huawei", "loc":"hk"},
|
||||
{"from": "159.138.0.0", "to": "159.138.225.255", "isp": "huawei", "loc":"th"},
|
||||
{"from": "162.128.0.2505", "to": "162.128.127.255", "isp": "zenlayer", "loc":"sg"},
|
||||
{"from": "166.108.192.0", "to": "166.108.255.255", "isp": "huawei", "loc":"sg"},
|
||||
{"from": "177.0.0.0", "to": "177.223.255.255", "isp": "ths", "loc":"br"},
|
||||
{"from": "183.87.32.0", "to": "183.87.159.255", "isp": "huawei", "loc":"hk"},
|
||||
|
||||
@@ -1 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><path d="M6.791,23.743l10.432,-0c3.601,-0 6.52,-2.921 6.52,-6.524l-0,-10.438c-0,-3.603 -2.919,-6.524 -6.52,-6.524l-10.432,0c-3.601,0 -6.52,2.921 -6.52,6.524l0,10.438c0,3.603 2.919,6.524 6.52,6.524Z" style="fill:#eceff1;fill-rule:nonzero;stroke:#515151;stroke-width:0.5px;"/><path d="M4.522,7.983c-0.279,-0 -0.508,0.229 -0.508,0.508c-0,0.278 0.229,0.508 0.508,0.508c0.279,-0 0.508,-0.23 0.508,-0.508c0,-0.279 -0.229,-0.508 -0.508,-0.508Z" style="fill:#ffc107;fill-rule:nonzero;"/><path d="M6.655,10.54l0.962,-0.407c0.454,-0.813 1.224,-1.284 2.222,-1.284c0.226,-0 0.439,0.028 0.641,0.075l0.915,-0.386c-0.451,-0.222 -0.968,-0.351 -1.556,-0.351c-1.594,0 -2.73,0.876 -3.184,2.353Zm-1.79,0.756l-0,-1.046l-0.683,0l0,1.335l0.683,-0.289Z" style="fill:#ff5722;fill-rule:nonzero;"/><path d="M4.865,13.155l-0,-1.859l-0.683,0.289l-0,1.858l0.683,-0.288Zm2.296,-1.056c0,-0.78 0.164,-1.442 0.456,-1.966l-0.962,0.407c-0.143,0.464 -0.222,0.984 -0.222,1.559c-0,0.134 0.018,0.254 0.026,0.382l0.708,-0.299c-0,-0.029 -0.006,-0.054 -0.006,-0.083Zm9.12,-3.766c-0.186,0.058 -0.358,0.13 -0.516,0.218l0.516,-0.218Zm-4.886,0.205l-0.915,0.386c0.685,0.158 1.219,0.575 1.567,1.197l0.681,-0.288c-0.312,-0.581 -0.767,-1.016 -1.333,-1.295Z" style="fill:#f44336;fill-rule:nonzero;"/><path d="M4.865,15.014l-0,-1.859l-0.683,0.288l-0,1.859l0.683,-0.288Zm11.416,-6.681l-0.516,0.218c-0.656,0.365 -1.052,0.976 -1.052,1.72c0,0.202 0.031,0.381 0.078,0.55l0.688,-0.29c-0.022,-0.088 -0.037,-0.18 -0.037,-0.28c0,-0.818 0.745,-1.412 1.823,-1.412c0.53,0 0.978,0.142 1.305,0.386l0.699,-0.295c-0.463,-0.456 -1.157,-0.742 -1.983,-0.742c-0.365,-0.001 -0.702,0.052 -1.005,0.145Zm-9.114,3.85l-0.708,0.299c0.039,0.639 0.173,1.207 0.398,1.691l0.669,-0.283c-0.223,-0.476 -0.349,-1.05 -0.359,-1.707Zm5.561,-2.349l-0.681,0.288c0.254,0.455 0.402,1.021 0.438,1.673l0.708,-0.298c-0.063,-0.632 -0.215,-1.196 -0.465,-1.663Z" style="fill:#e91e63;fill-rule:nonzero;"/><path d="M13.073,13.405c0.097,-0.401 0.161,-0.831 0.161,-1.306c0,-0.211 -0.022,-0.406 -0.042,-0.603l-0.707,0.299c0.006,0.102 0.02,0.197 0.02,0.304c-0,0.645 -0.118,1.206 -0.321,1.682l0.889,-0.376Zm-5.546,0.484l-0.67,0.283c0.272,0.586 0.672,1.045 1.185,1.359l0.839,-0.354c-0.601,-0.226 -1.063,-0.668 -1.354,-1.288Zm-2.662,1.125l-0.683,0.288l0,0.557l0.683,0l-0,-0.845Zm10.615,-4.484l-0.688,0.291c0.163,0.577 0.61,0.98 1.419,1.259l1.067,-0.451l-0.225,-0.056c-0.972,-0.243 -1.449,-0.555 -1.573,-1.043Zm3.666,-0.348l0.719,0c-0.034,-0.487 -0.253,-0.915 -0.596,-1.253l-0.698,0.296c0.314,0.234 0.519,0.564 0.575,0.957Z" style="fill:#9c27b0;fill-rule:nonzero;"/><path d="M13.073,13.405l-0.889,0.376c-0.419,0.984 -1.233,1.573 -2.346,1.573c-0.352,0 -0.667,-0.069 -0.958,-0.178l-0.839,0.354c0.502,0.306 1.099,0.485 1.797,0.485c1.695,0 2.841,-0.988 3.235,-2.61Zm2.146,0.501l-0.719,0c0.017,0.245 0.085,0.47 0.176,0.681l0.659,-0.279c-0.056,-0.126 -0.1,-0.259 -0.116,-0.402Zm2.578,-2.145l-0.52,-0.131l-1.066,0.451c0.156,0.054 0.324,0.104 0.508,0.149l0.859,0.219c0.476,0.117 0.838,0.266 1.106,0.446l0.803,-0.34c-0.352,-0.343 -0.902,-0.599 -1.69,-0.794Z" style="fill:#3f51b5;fill-rule:nonzero;"/><path d="M15.335,14.309l-0.659,0.278c0.251,0.58 0.759,1.021 1.444,1.249l1.128,-0.476c-0.919,-0.022 -1.638,-0.429 -1.913,-1.051Zm4.608,-0.087c0.023,-0.129 0.042,-0.26 0.042,-0.399c-0,-0.522 -0.156,-0.936 -0.497,-1.268l-0.803,0.34c0.386,0.26 0.57,0.588 0.57,1.006c0,0.262 -0.087,0.5 -0.232,0.709l0.92,-0.388Z" style="fill:#03a9f4;fill-rule:nonzero;"/><path d="M19.943,14.222l-0.92,0.389c-0.314,0.454 -0.929,0.754 -1.7,0.754c-0.026,0 -0.049,-0.004 -0.074,-0.004l-1.128,0.476c0.342,0.114 0.724,0.179 1.14,0.179c1.471,-0.001 2.482,-0.707 2.682,-1.794Z" style="fill:#009688;fill-rule:nonzero;"/></svg>
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><path d="M0.758,5.964c-0.416,0 -0.758,0.342 -0.758,0.758c0,0.414 0.342,0.757 0.758,0.757c0.416,0 0.757,-0.343 0.757,-0.757c0,-0.416 -0.341,-0.758 -0.757,-0.758Z" style="fill:#ffc107;fill-rule:nonzero;"/><path d="M3.938,9.777l1.435,-0.607c0.677,-1.212 1.825,-1.914 3.314,-1.914c0.337,-0 0.654,0.041 0.956,0.111l1.364,-0.575c-0.672,-0.331 -1.443,-0.524 -2.32,-0.524c-2.377,0 -4.071,1.307 -4.749,3.509Zm-2.669,1.128l0,-1.56l-1.018,-0l-0,1.991l1.018,-0.431Z" style="fill:#ff5722;fill-rule:nonzero;"/><path d="M1.269,13.677l0,-2.772l-1.018,0.431l-0,2.77l1.018,-0.429Zm3.424,-1.575c0,-1.163 0.245,-2.15 0.68,-2.932l-1.435,0.607c-0.213,0.692 -0.331,1.468 -0.331,2.325c0,0.2 0.027,0.379 0.039,0.57l1.056,-0.446c0,-0.043 -0.009,-0.081 -0.009,-0.124Zm13.601,-5.616c-0.278,0.087 -0.534,0.194 -0.77,0.325l0.77,-0.325Zm-7.287,0.306l-1.364,0.575c1.021,0.236 1.817,0.858 2.336,1.785l1.016,-0.429c-0.465,-0.867 -1.144,-1.515 -1.988,-1.931Z" style="fill:#f44336;fill-rule:nonzero;"/><path d="M1.269,16.449l0,-2.772l-1.018,0.429l-0,2.773l1.018,-0.43Zm17.025,-9.963l-0.77,0.325c-0.978,0.544 -1.569,1.456 -1.569,2.565c0,0.301 0.046,0.568 0.117,0.82l1.026,-0.432c-0.033,-0.131 -0.056,-0.269 -0.056,-0.418c0,-1.22 1.111,-2.105 2.719,-2.105c0.79,-0 1.458,0.211 1.946,0.575l1.042,-0.44c-0.69,-0.68 -1.725,-1.106 -2.957,-1.106c-0.544,-0.002 -1.047,0.077 -1.498,0.216Zm-13.592,5.741l-1.056,0.446c0.058,0.953 0.258,1.8 0.594,2.522l0.997,-0.422c-0.332,-0.71 -0.52,-1.566 -0.535,-2.546Zm8.293,-3.503l-1.016,0.43c0.379,0.678 0.6,1.523 0.654,2.495l1.055,-0.445c-0.093,-0.942 -0.32,-1.783 -0.693,-2.48Z" style="fill:#e91e63;fill-rule:nonzero;"/><path d="M13.51,14.05c0.144,-0.598 0.24,-1.239 0.24,-1.948c-0,-0.314 -0.033,-0.605 -0.063,-0.899l-1.054,0.446c0.009,0.152 0.029,0.294 0.029,0.453c0,0.962 -0.176,1.799 -0.478,2.509l1.326,-0.561Zm-8.271,0.722l-0.999,0.422c0.405,0.873 1.002,1.558 1.767,2.026l1.251,-0.528c-0.896,-0.337 -1.585,-0.996 -2.019,-1.92Zm-3.97,1.677l-1.018,0.43l-0,0.83l1.018,0l0,-1.26Zm15.83,-6.687l-1.026,0.434c0.243,0.861 0.91,1.462 2.116,1.878l1.591,-0.673l-0.335,-0.083c-1.45,-0.363 -2.161,-0.828 -2.346,-1.556Zm5.467,-0.519l1.072,0c-0.05,-0.726 -0.377,-1.364 -0.889,-1.868l-1.04,0.441c0.468,0.349 0.774,0.841 0.857,1.427Z" style="fill:#9c27b0;fill-rule:nonzero;"/><path d="M13.51,14.05l-1.326,0.561c-0.625,1.467 -1.839,2.345 -3.499,2.345c-0.525,0 -0.994,-0.103 -1.428,-0.265l-1.252,0.528c0.749,0.456 1.639,0.723 2.68,0.723c2.528,0 4.237,-1.473 4.825,-3.892Zm3.2,0.747l-1.072,-0c0.025,0.365 0.126,0.701 0.262,1.015l0.983,-0.416c-0.084,-0.187 -0.149,-0.386 -0.173,-0.599Zm3.844,-3.199l-0.775,-0.195l-1.59,0.672c0.233,0.081 0.483,0.155 0.758,0.223l1.281,0.326c0.71,0.175 1.249,0.397 1.649,0.665l1.198,-0.507c-0.525,-0.511 -1.346,-0.893 -2.521,-1.184Z" style="fill:#3f51b5;fill-rule:nonzero;"/><path d="M16.883,15.398l-0.983,0.414c0.374,0.865 1.132,1.523 2.153,1.863l1.683,-0.71c-1.371,-0.033 -2.443,-0.64 -2.853,-1.567Zm6.872,-0.13c0.034,-0.192 0.062,-0.388 0.062,-0.595c0,-0.778 -0.232,-1.396 -0.741,-1.891l-1.197,0.507c0.575,0.388 0.85,0.877 0.85,1.5c-0,0.391 -0.13,0.746 -0.346,1.058l1.372,-0.579Z" style="fill:#03a9f4;fill-rule:nonzero;"/><path d="M23.755,15.268l-1.372,0.58c-0.469,0.677 -1.386,1.125 -2.536,1.125c-0.038,-0 -0.073,-0.006 -0.11,-0.006l-1.682,0.71c0.51,0.17 1.08,0.267 1.7,0.267c2.194,-0.002 3.701,-1.055 4,-2.676Z" style="fill:#009688;fill-rule:nonzero;"/></svg>
|
||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -67,7 +67,7 @@ foreach ($logArr as $val) {
|
||||
/* write the log line to the file */
|
||||
$logfile = fopen($filename, 'a');
|
||||
if (!$logfile) {
|
||||
http_response_code(500);
|
||||
http_response_code(507);
|
||||
die("Error: Unable to open log file. Please check file permissions.");
|
||||
}
|
||||
|
||||
|
||||
32
script.js
32
script.js
@@ -234,7 +234,9 @@ BotMon.live = {
|
||||
if ( v.id == visitor.id) { /* match the pre-defined IDs */
|
||||
return v;
|
||||
} else if (v.ip == visitor.ip && v.agent == visitor.agent) {
|
||||
console.warn(`Visitor ID “${v.id}” not found, using matchin IP + User-Agent instead.`);
|
||||
if (v.typ !== 'ip') {
|
||||
console.warn(`Visitor ID “${v.id}” not found, using matchin IP + User-Agent instead.`);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -285,6 +287,10 @@ BotMon.live = {
|
||||
visitor._client = BotMon.live.data.clients.match(nv.agent) ?? null; // client info
|
||||
visitor._platform = BotMon.live.data.platforms.match(nv.agent); // platform info
|
||||
model._visitors.push(visitor);
|
||||
} else { // update existing
|
||||
if (visitor._firstSeen < nv.ts) {
|
||||
visitor._firstSeen = nv.ts;
|
||||
}
|
||||
}
|
||||
|
||||
// find browser
|
||||
@@ -307,7 +313,9 @@ BotMon.live = {
|
||||
(prereg.ref !== undefined && prereg.ref !== '');
|
||||
|
||||
// update time stamp for last-seen:
|
||||
visitor._lastSeen = nv.ts;
|
||||
if (visitor._lastSeen < nv.ts) {
|
||||
visitor._lastSeen = nv.ts;
|
||||
}
|
||||
|
||||
// if needed:
|
||||
return visitor;
|
||||
@@ -444,6 +452,8 @@ BotMon.live = {
|
||||
// shortcut to make code more readable:
|
||||
const model = BotMon.live.data.model;
|
||||
|
||||
BotMon.live.gui.status.showBusy("Analysing data …");
|
||||
|
||||
// loop over all visitors:
|
||||
model._visitors.forEach( (v) => {
|
||||
|
||||
@@ -485,8 +495,8 @@ BotMon.live = {
|
||||
}
|
||||
});
|
||||
|
||||
//console.log(this.data);
|
||||
//console.log(this.groups);
|
||||
BotMon.live.gui.status.hideBusy('Done.');
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
@@ -848,7 +858,7 @@ BotMon.live = {
|
||||
return false;
|
||||
},
|
||||
|
||||
// unusual combinations of PLatform and Client:
|
||||
// unusual combinations of Platform and Client:
|
||||
combTest: function(visitor, ...combinations) {
|
||||
|
||||
for (let i=0; i<combinations.length; i++) {
|
||||
@@ -868,6 +878,16 @@ BotMon.live = {
|
||||
const ipInfo = BotMon.live.data.rules.getBotIPInfo(visitor.ip);
|
||||
|
||||
return (ipInfo !== null);
|
||||
},
|
||||
|
||||
// is the page language mentioned in the client's accepted languages?
|
||||
// the parameter holds an array of exceptions, i.e. page languages that should be ignored.
|
||||
matchLang: function(visitor, ...exceptions) {
|
||||
|
||||
if (visitor.lang && visitor.accept && exceptions.indexOf(visitor.lang) < 0) {
|
||||
return visitor.accept.split(',').indexOf(visitor.lang) < 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -906,7 +926,7 @@ BotMon.live = {
|
||||
switch (type) {
|
||||
case "srv":
|
||||
typeName = "Server";
|
||||
columns = ['ts','ip','pg','id','typ','usr','agent','ref'];
|
||||
columns = ['ts','ip','pg','id','typ','usr','agent','ref','lang','accept'];
|
||||
break;
|
||||
case "log":
|
||||
typeName = "Page load";
|
||||
|
||||
Reference in New Issue
Block a user