diff --git a/action.php b/action.php index 4a9bc68..d526b92 100644 --- a/action.php +++ b/action.php @@ -208,14 +208,16 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { private function checkCaptchaCookie() { - $cookieVal = isset($_COOKIE['captcha']) ? $_COOKIE['captcha'] : null; + $cookieVal = isset($_COOKIE['DWConfirm']) ? $_COOKIE['DWConfirm'] : null; - $today = new DateTime(); - $isodate = substr((new DateTime())->format('c'), 0, 10); + $today = substr((new DateTime())->format('c'), 0, 10); - $raw = $this->getConf('captchaSeed') . '|' . $_SERVER['SERVER_NAME'] . '|' . $_SERVER['REMOTE_ADDR'] . '|' . $isodate; + $raw = $this->getConf('captchaSeed') . '|' . $_SERVER['SERVER_NAME'] . '|' . $_SERVER['REMOTE_ADDR'] . '|' . $today; + $expected = hash('sha256', $raw); - return $cookieVal !== hash('sha256', $raw); + //echo '
Checking if you are a human …
'; + dlg.innerHTML = 'Making sure you are a human:
'; // Checkbox: const lbl = document.createElement('label'); + lbl.innerHTML = 'Click to confirm.Checking …Loading …'; const cb = document.createElement('input'); cb.setAttribute('type', 'checkbox'); + cb.setAttribute('disabled', 'disabled'); cb.addEventListener('click', $BMCaptcha._cbCallback); - lbl.appendChild(cb); - lbl.appendChild(document.createTextNode('I am a human.')); + lbl.prepend(cb); dlg.appendChild(lbl); bm_parent.appendChild(dlg); + + // call the delayed callback in a couple of seconds: + setTimeout($BMCaptcha._delayedCallback, 1500); }, /* creates a digest hash for the cookie function */ @@ -147,19 +152,42 @@ const $BMCaptcha = { if (e.target.checked) { //document.getElementById('botmon_captcha_box').close(); - // make a hash for the cookie: - const seed = document._botmon.seed || ''; - const extIp = document._botmon.ip || '0.0.0.0'; - const d = new Date(document._botmon.t0); - const raw = seed + '|' + location.hostname + '|' + extIp + '|' + d.toISOString().substring(0, 10); + const dat = [ // the data to encode + document._botmon.seed || '', + location.hostname, + document._botmon.ip || '0.0.0.0', + (document._botmon.t0 ? new Date(document._botmon.t0) : new Date()).toISOString().substring(0, 10) + ]; + const hash = $BMCaptcha.digest.hash(dat.join('|')); - const hash = $BMCaptcha.digest.hash(raw); - console.log('Setting cookie to:', raw, ' --> ', hash); - document.cookie = "captcha=" + hash + ';'; + // set the cookie: + document.cookie = "DWConfirm=" + hash + ';path=/;'; + // change the interface: + const dlg = document.getElementById('botmon_captcha_box'); + if (dlg) { + dlg.classList.remove('ready'); + dlg.classList.add('loading'); + } + + // reload the page: window.location.reload(true); } - } + }, + + _delayedCallback: function() { + const dlg = document.getElementById('botmon_captcha_box'); + if (dlg) { + dlg.classList.remove('checking'); + dlg.classList.add('ready'); + + const input = dlg.getElementsByTagName('input')[0]; + if (input) { + input.removeAttribute('disabled'); + input.focus(); + } + } + }, } // initialise the captcha module: diff --git a/img/busy-light.svg b/img/busy-light.svg new file mode 100644 index 0000000..ce57394 --- /dev/null +++ b/img/busy-light.svg @@ -0,0 +1,139 @@ + \ No newline at end of file diff --git a/lang/en/wordlist.txt b/lang/en/wordlist.txt index 527810d..dfc4bfc 100644 --- a/lang/en/wordlist.txt +++ b/lang/en/wordlist.txt @@ -520,7 +520,6 @@ road 8 late 8 stand 8 suppose 8 -la 8 daughter 8 real 8 nearly 8 @@ -1955,7 +1954,6 @@ ends 2 shop 2 stairs 2 pardon 2 -gay 2 beg 2 seldom 2 kinds 2 diff --git a/style.less b/style.less index 7211d4c..0f6cb90 100644 --- a/style.less +++ b/style.less @@ -11,15 +11,95 @@ body.botmon_captcha { } } #botmon_captcha_box { - border: red dotted 2pt; + & { position: fixed; width: 400px; - height: 400px; - top: ~"calc(50vh - 200px)"; + height: 220px; + top: ~"calc(50vh - 110px)"; left: ~"calc(50vw - 200px)"; - border-radius: .5rem; - margin: 0; padding: .5rem; + background: #1C1B22 none; + border: #7C7B82 solid 1pt; + border-radius: 12px; + margin: 0; padding: 18px; + font-family: system-ui, sans-serif; + box-shadow: .25rem .25rem .5rem rgba(0,0,0,.5); + box-sizing: border-box; } + & * { + color: #EDEDF5; + margin: 0; + } + h2 { + font-size: 24px; + line-height: 32px; + padding: 0 0 12px 0; + } + p { + font-size: 16px; + line-height: 20px; + padding: 6px 0; + } + label { + & { + display: grid; + grid-template-columns: 32px auto; + column-gap: 8px; + align-items: center; + padding: 24px; + margin: 16px 0 0 0; + background-color: #32313A; + border: #7C7B82 solid 1px; + border-radius: 3px; + font-size: 16px; + } + span.busy { + display: inline-block; + width: 24px; height: 24px; + background: transparent url('img/busy-light.svg') center no-repeat; + background-size: 24px; + } + } + input[type="checkbox"] { + width: 24px; height: 24px; + border: 2px solid #00CADB; + border-radius: 4px; + appearance: none; + } + input[type="checkbox"]:focus { + outline: none; + box-shadow: 0 0 6px rgba(0, 202, 219, .8); + } + + input[type="checkbox"]:disabled { + display: none; + } + &.checking { + input[type="checkbox"], span.confirm, span.loading { display: none;} + span.busy, span.checking { display: initial; } + label, input[type="checkbox"] { cursor: none; } + } + &.ready { + input[type="checkbox"], span.confirm { display: initial;} + span.busy, span.checking, span.loading { display: none; } + label, input[type="checkbox"] { cursor: pointer; } + } + &.loading { + span.busy, span.loading { display: initial; } + input[type="checkbox"], span.confirm, span.checking { display: none;} + label { cursor: busy; } + } + } +} + +// smaller screens: +@media (max-width: 480px) { + body.botmon_captcha #botmon_captcha_box { + width: 100vw; + height: auto; + left: 0; top: 80px; + border-radius: 2px; + z-index: 10001; + } } /* dark mode overrides */ @@ -33,5 +113,19 @@ body.botmon_captcha { text-shadow: 0 0 .35em rgba(170,170,170,.75); } } + #botmon_captcha_box { + & { + background-color: #FFF; + border-color: #9F9EA1; + box-shadow: .25rem .25rem .5rem rgba(0,0,0,.25); + } + & * { + color: #15141A; + } + label { + background-color: #EEE; + border-color: #9F9EA1; + } + } } } \ No newline at end of file