From fb281ca1a13fb0419ac09220cd216d20c52045d5 Mon Sep 17 00:00:00 2001 From: Sascha Leib Date: Sun, 2 Nov 2025 21:22:38 +0100 Subject: [PATCH] Captcha updates --- action.php | 7 ++++++- admin.js | 20 +++++++++++++++----- admin.php | 14 +++++++------- captcha.js | 11 +++++------ conf/default.php | 1 + conf/metadata.php | 7 +++++++ lang/en/settings.php | 3 +++ plugin.info.txt | 2 +- 8 files changed, 45 insertions(+), 20 deletions(-) diff --git a/action.php b/action.php index 62a3c3d..0d9bfdb 100644 --- a/action.php +++ b/action.php @@ -263,7 +263,12 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { echo DOKU_TAB . DOKU_TAB . '"dlgLoading": ' . json_encode($this->getLang('bm_dlgLoading')) . ',' . NL; echo DOKU_TAB . DOKU_TAB . '"dlgError": ' . json_encode($this->getLang('bm_dlgError')) . ',' . NL; echo DOKU_TAB . '};' . NL; - + + // captcha configuration options + echo DOKU_TAB . '$BMConfig = {' . NL; + echo DOKU_TAB . DOKU_TAB . '"captchaBypass": ' . json_encode($this->getConf('captchaBypass')) . NL; + echo DOKU_TAB . '};' . NL; + echo '' . NL; } } diff --git a/admin.js b/admin.js index a2a4d9a..0a7234f 100644 --- a/admin.js +++ b/admin.js @@ -1712,6 +1712,16 @@ BotMon.live = { return visitor.hasOwnProperty('_ipRange'); }, + // is the IP address from a specifin known ISP network + fromISPRange: function(visitor, ...isps) { + if (visitor.hasOwnProperty('_ipRange')) { + if (isps.indexOf(visitor._ipRange.g) > -1) { + return true; + } + } + return false; + }, + // 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) { @@ -2026,7 +2036,7 @@ BotMon.live = { if (botsVsHumans) { botsVsHumans.appendChild(makeElement('dt', {}, "Bot statistics")); - for (let i = 0; i <= 6; i++) { + for (let i = 0; i <= 5; i++) { const dd = makeElement('dd'); let title = ''; let value = ''; @@ -2043,15 +2053,15 @@ BotMon.live = { title = "Bots-humans ratio visits:"; value = BotMon.t._getRatio(data.visits.suspected + data.visits.bots, data.visits.users + data.visits.humans, 100); break; - case 4: + case 3: title = "Known bots views:"; value = data.views.bots || kNoData; break; - case 5: + case 4: title = "Suspected bots views:"; value = data.views.suspected || kNoData; break; - case 6: + case 5: title = "Bots-humans ratio views:"; value = BotMon.t._getRatio(data.views.suspected + data.views.bots, data.views.users + data.views.humans, 100); break; @@ -2771,7 +2781,7 @@ BotMon.live = { /* bot evaluation rating */ if (data._type !== BM_USERTYPE.KNOWN_BOT && data._type !== BM_USERTYPE.KNOWN_USER) { dl.appendChild(make('dt', undefined, "Bot rating:")); - dl.appendChild(make('dd', {'class': 'bot-rating'}, ( data._botVal ? data._botVal : '–' ) + ' (of ' + BotMon.live.data.rules._threshold + ')')); + dl.appendChild(make('dd', {'class': 'bot-rating'}, ( data._botVal ? data._botVal : '0' ) + ' (of ' + BotMon.live.data.rules._threshold + ')')); /* add bot evaluation details: */ if (data._eval) { diff --git a/admin.php b/admin.php index 0821f49..8fa5893 100644 --- a/admin.php +++ b/admin.php @@ -53,6 +53,13 @@ class admin_plugin_botmon extends AdminPlugin {
+

Latest data

Loading …
@@ -116,13 +123,6 @@ class admin_plugin_botmon extends AdminPlugin { } echo DOKU_TAB . DOKU_TAB . '' . NL . DOKU_TAB . '
' . NL; - echo DOKU_TAB . '' . NL; echo ''; } diff --git a/captcha.js b/captcha.js index 61958d7..778cef6 100644 --- a/captcha.js +++ b/captcha.js @@ -218,16 +218,15 @@ const $BMCaptcha = { _autoCheck: function(e) { - let bPass = 0; - const threshold = 1; + const bypass = ($BMConfig['captchaBypass'] || '').split(','); + var action = false; - const pLang = document.documentElement.lang || 'en'; - if (pLang !== 'en') { + if (bypass.indexOf('langmatch') >= 0) { // Languages matching const cntLangs = navigator.languages.map(lang => lang.split('-')[0]); - if (cntLangs.indexOf(pLang) >= 0) bPass += 1; + if (cntLangs.indexOf(document.documentElement.lang || 'en') >= 0) action = true; } - if (bPass >= threshold) e.click(); + if (action) e.click(); // action! } } // initialise the captcha module: diff --git a/conf/default.php b/conf/default.php index 4ae29b2..9c196dd 100644 --- a/conf/default.php +++ b/conf/default.php @@ -10,3 +10,4 @@ $conf['combineNets'] = true; $conf['geoiplib'] = 'disabled'; $conf['useCaptcha'] = 'disabled'; $conf['captchaSeed'] = 'c53bc5f94929451987efa6c768d8856b'; +$conf['captchaBypass'] = ''; diff --git a/conf/metadata.php b/conf/metadata.php index de95acc..8ae3c4c 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -5,14 +5,21 @@ * @author Sascha Leib */ +// How to show data in the admin interface: $meta['showday'] = array('multichoice', '_choices' => array ('yesterday', 'today')); $meta['combineNets'] = array('onoff'); +// Geolocation settings: $meta['geoiplib'] = array('multichoice', '_choices' => array ('disabled', 'phpgeoip')); +// Captcha settings: $meta['useCaptcha'] = array('multichoice', '_choices' => array ('disabled', 'loremipsum', 'dada')); + $meta['captchaSeed'] = array('string'); + +$meta['captchaBypass'] = array('multicheckbox', + '_choices' => array ('langmatch'), '_other' => 'exists'); diff --git a/lang/en/settings.php b/lang/en/settings.php index 42a2d20..67a8835 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -21,3 +21,6 @@ $lang['useCaptcha'] = 'Enable Captcha
(Experimental, read the manual $lang['useCaptcha_o_dada'] = 'Captcha with Dada placeholder text'; $lang['captchaSeed'] = 'Captcha Seed
(Enter a random string, e.g. from here)'; + +$lang['captchaBypass'] = 'Automatically solve the Captcha, if …
(Note: this probably does not make much sense for English wikis!)'; + $lang['captchaBypass_langmatch'] = 'Client and page languages match '; diff --git a/plugin.info.txt b/plugin.info.txt index 9a3a2b1..c960c44 100644 --- a/plugin.info.txt +++ b/plugin.info.txt @@ -1,7 +1,7 @@ base botmon author Sascha Leib email ad@hominem.com -date 2025-10-31 +date 2025-11-02 name Bot Monitoring desc A tool for monitoring and analysing bot traffic to your wiki (under development) url https://www.dokuwiki.org/plugin:botmon