From 6728cfa61cd62383ade8f0066241c9b61cdbe241 Mon Sep 17 00:00:00 2001 From: Sascha Leib Date: Mon, 3 Nov 2025 22:21:41 +0100 Subject: [PATCH] Debugging Help Log captcha data --- action.php | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/action.php b/action.php index c33a63e..cb3830d 100644 --- a/action.php +++ b/action.php @@ -301,6 +301,13 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { $this->showCaptcha = $cCode; // store the captcha code for the logfile } + /** + * Checks if the user has a valid captcha cookie. + * + * @return boolean + * @access private + * + **/ private function hasCaptchaCookie() { $cookieVal = isset($_COOKIE['DWConfirm']) ? $_COOKIE['DWConfirm'] : null; @@ -310,11 +317,48 @@ class action_plugin_botmon extends DokuWiki_Action_Plugin { $raw = $this->getConf('captchaSeed') . '|' . $_SERVER['SERVER_NAME'] . '|' . $_SERVER['REMOTE_ADDR'] . '|' . $today; $expected = hash('sha256', $raw); - //echo '' . NL; + // for debugging: write captcha data to the log: + $this->writeCaptchaLog($_SERVER['REMOTE_ADDR'], $cookieVal, $_SERVER['SERVER_NAME'], $expected); return $cookieVal == $expected; } + /** + * Writes data to the captcha log. + * + * @return void + */ + private function writeCaptchaLog($remote_addr, $cookieVal, $serverName, $expected) { + + $logArr = Array( + $remote_addr, /* remote IP */ + $cookieVal, /* cookie value */ + $this->getConf('captchaSeed'), /* seed */ + $serverName, /* server name */ + $expected, /* expected cookie value */ + $cookieVal == $expected /* cookie matches expected value? */ + ); + + //* create the log line */ + $filename = __DIR__ .'/logs/' . gmdate('Y-m-d') . '.captcha.txt'; /* use GMT date for filename */ + $logline = gmdate('Y-m-d H:i:s'); /* use GMT time for log entries */ + foreach ($logArr as $tab) { + $logline .= "\t" . $tab; + }; + + /* write the log line to the file */ + $logfile = fopen($filename, 'a'); + if (!$logfile) die(); + if (fwrite($logfile, $logline . "\n") === false) { + fclose($logfile); + die(); + } + + /* Done */ + fclose($logfile); + } + + // check if the visitor's IP is on a whitelist: private function captchaWhitelisted() {