Captcha improvements

Auto-check if languages match;
Collect METHOD data in Server-log
This commit is contained in:
Sascha Leib
2025-11-02 11:19:58 +01:00
parent 780ef5db68
commit ad279a215c
4 changed files with 24 additions and 8 deletions

View File

@@ -16,7 +16,7 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin {
public function __construct() {
// determine if a captcha should be loaded:
$this->showCaptcha = 'Z';
$this->showCaptcha = 'Z'; // Captcha unknown
$useCaptcha = $this->getConf('useCaptcha'); // should we show a captcha?
@@ -153,7 +153,8 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin {
substr($conf['lang'],0,2), /* page language */
implode(',', array_unique(array_map( function($it) { return substr(trim($it),0,2); }, explode(',',trim($_SERVER['HTTP_ACCEPT_LANGUAGE'], " \t;,*"))))), /* accepted client languages */
$this->getCountryCode(), /* GeoIP country code */
$this->showCaptcha /* show captcha? */
$this->showCaptcha, /* show captcha? */
$_SERVER['REQUEST_METHOD'] ?? '' /* request method */
);
//* create the log line */

View File

@@ -476,8 +476,6 @@
max-width: 100%;
overflow: hidden;
}
dd {
}
dd a {
white-space: nowrap;
overflow: hidden;

View File

@@ -1845,7 +1845,7 @@ BotMon.live = {
switch (type) {
case "srv":
typeName = "Server";
columns = ['ts','ip','pg','id','typ','usr','agent','ref','lang','accept','geo','captcha'];
columns = ['ts','ip','pg','id','typ','usr','agent','ref','lang','accept','geo','captcha','method'];
break;
case "log":
typeName = "Page load";

View File

@@ -6,9 +6,8 @@
const $BMCaptcha = {
init: function() {
/* mark the page to contain the captcha styles */
document.getElementsByTagName('body')[0].classList.add('botmon_captcha');
$BMCaptcha._cbDly = 1.5;
$BMCaptcha.install()
},
@@ -51,7 +50,8 @@ const $BMCaptcha = {
bm_parent.appendChild(dlg);
// call the delayed callback in a couple of seconds:
setTimeout($BMCaptcha._delayedCallback, 1500);
$BMCaptcha._st = performance.now();
setTimeout($BMCaptcha._delayedCallback, $BMCaptcha._cbDly * 1000);
},
/* creates a digest hash for the cookie function */
@@ -175,6 +175,7 @@ const $BMCaptcha = {
document._botmon.ip || '0.0.0.0',
(new Date()).toISOString().substring(0, 10)
];
if ($BMCaptcha._st - performance.now() >= 0) dat.push($BMCaptcha._st - performance.now());
const hash = $BMCaptcha.digest.hash(dat.join('|'));
// set the cookie:
@@ -208,10 +209,26 @@ const $BMCaptcha = {
if (input) {
input.removeAttribute('disabled');
input.focus();
setTimeout($BMCaptcha._autoCheck, 200, input);
}
}
},
_cbDly: null,
_st: null,
_autoCheck: function(e) {
let bPass = 0;
const threshold = 1;
const pLang = document.documentElement.lang || 'en';
if (pLang !== 'en') {
const cntLangs = navigator.languages.map(lang => lang.split('-')[0]);
if (cntLangs.indexOf(pLang) >= 0) bPass += 1;
}
if (bPass >= threshold) e.click();
}
}
// initialise the captcha module:
$BMCaptcha.init();