Captcha updates

This commit is contained in:
Sascha Leib
2025-11-02 21:22:38 +01:00
parent ad279a215c
commit fb281ca1a1
8 changed files with 45 additions and 20 deletions

View File

@@ -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 '</script>' . NL;
}
}

View File

@@ -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) {

View File

@@ -53,6 +53,13 @@ class admin_plugin_botmon extends AdminPlugin {
</ul>
</nav>
<article role="tabpanel" id="botmon__latest">
<script>
const BMSettings = {
showday: ' . json_encode($this->getConf('showday')) . ',
combineNets: ' . json_encode($this->getConf('combineNets')) . ',
useCaptcha: ' . json_encode($this->getConf('useCaptcha') !== 'disabled') . '
};
</script>
<h2 class="a11y">Latest data</h2>
<header id="botmon__today__title">Loading&nbsp;&hellip;</header>
<div id="botmon__today__content">
@@ -116,13 +123,6 @@ class admin_plugin_botmon extends AdminPlugin {
}
echo DOKU_TAB . DOKU_TAB . '</ul>' . NL . DOKU_TAB . '</article>' . NL;
echo DOKU_TAB . '<script>
const BMSettings = {
showday: ' . json_encode($this->getConf('showday')) . ',
combineNets: ' . json_encode($this->getConf('combineNets')) . ',
useCaptcha: ' . json_encode($this->getConf('useCaptcha') !== 'disabled') . '
};
</script>' . NL;
echo '</div><!-- End of BotMon Admin Tool -->';
}

View File

@@ -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:

View File

@@ -10,3 +10,4 @@ $conf['combineNets'] = true;
$conf['geoiplib'] = 'disabled';
$conf['useCaptcha'] = 'disabled';
$conf['captchaSeed'] = 'c53bc5f94929451987efa6c768d8856b';
$conf['captchaBypass'] = '';

View File

@@ -5,14 +5,21 @@
* @author Sascha Leib <sascha@leib.be>
*/
// 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');

View File

@@ -21,3 +21,6 @@ $lang['useCaptcha'] = 'Enable Captcha<br><small>(Experimental, read the manual
$lang['useCaptcha_o_dada'] = 'Captcha with Dada placeholder text';
$lang['captchaSeed'] = 'Captcha Seed<br><small>(Enter a random string, e.g. <a href="https://www.browserling.com/tools/random-hex" target="_blank">from here</a>)</small>';
$lang['captchaBypass'] = 'Automatically solve the Captcha, if …<br><small>(Note: this probably does not make much sense for English wikis!)</small>';
$lang['captchaBypass_langmatch'] = 'Client and page languages match ';

View File

@@ -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