From 038b80831309c4ecc51473b6cd82af791a70941a Mon Sep 17 00:00:00 2001 From: Daniel Winzen Date: Sat, 30 Aug 2025 19:30:03 +0200 Subject: [PATCH] Mark simple and moderate captchas as deprecated. Change extreme captcha to use random colours, instead of fixed ones. Change it to have lines to every character: the characters in the solution are now connected by dotted lines; characters not in the solution are connected by solid lines. Replace dots with polygons. Add new captchas with a TrueType font. The solution is obscured by small characters or by rectangles, ellipses, slices of ellipses, and polygons. These shapes are either filled or outlined. Fixes #13 --- chat.php | 226 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 199 insertions(+), 27 deletions(-) diff --git a/chat.php b/chat.php index 1c9b72d..5cd29f5 100644 --- a/chat.php +++ b/chat.php @@ -362,6 +362,7 @@ function route_setup(): void $C['text_settings']=[ 'dateformat' => _('Date formating'), 'captchachars' => _('Characters used in Captcha'), + 'captchattfont' => _('Font name or path and filename for TrueType font used in some captchas'), 'redirect' => _('Custom redirection script'), 'chatname' => _('Chat name'), 'mailsender' => _('Send mail using this address'), @@ -648,6 +649,11 @@ function send_captcha(): void if($difficulty===0 || !extension_loaded('gd')){ return; } + if(function_exists('putenv')) { + // from https://www.php.net/manual/en/function.imagefttext.php + // enables fonts to be loaded from the directory the script is in + putenv('GDFONTPATH=' . realpath('.')); + } $captchachars=get_setting('captchachars'); $length=strlen($captchachars)-1; $code=''; @@ -662,7 +668,14 @@ function send_captcha(): void $stmt=$db->prepare('INSERT INTO ' . PREFIX . 'captcha (id, time, code) VALUES (?, ?, ?);'); $stmt->execute([$randid, $time, $code]); } - echo ''._('Copy:').'
'; + echo ''; + if ($difficulty===4) { + echo _('Type the characters connected by dotted lines:'); + } elseif ($difficulty===7 || $difficulty===8) { + echo _('Type the five largest characters:'); + } else { + echo _('Type the characters in the image:'); + } if($difficulty===1){ $im=imagecreatetruecolor(55, 24); $bg=imagecolorallocate($im, 0, 0, 0); @@ -685,7 +698,7 @@ function send_captcha(): void imagesetpixel($im, mt_rand(0, 55), mt_rand(0, 24), $dots); } echo ''; - echo ''.hidden('challenge', $randid).''; + echo ''.hidden('challenge', $randid).''; } function send_setup(array $C): void @@ -912,12 +1060,12 @@ function send_setup(array $C): void if($captcha===1){ echo ' selected'; } - echo '>'._('Simple').''; + echo '>'._('Simple (deprecated)').''; echo ''; + echo '>'._('Moderate (deprecated)').''; echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; } echo ''; @@ -4256,6 +4424,7 @@ function init_chat(): void ['messageexpire', '14400'], ['messagelimit', '150'], ['maxmessage', 2000], + ['captchattfont', '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf'], ['captchatime', '600'], ['colbg', '000000'], ['coltxt', 'FFFFFF'], @@ -4707,6 +4876,9 @@ function update_db(): void $db->exec('INSERT INTO ' . PREFIX . "settings (setting, value) VALUES ('exitwait', '180'), ('exitingtxt', ' 🚪"); // door emoji $db->exec('ALTER TABLE ' . PREFIX . 'sessions ADD COLUMN exiting smallint NOT NULL DEFAULT 0;'); } + if($dbversion<49){ + $db->exec('INSERT INTO ' . PREFIX . "settings (setting, value) VALUES ('captchattfont', '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf');"); + } update_setting('dbversion', DBVERSION); if($msgencrypted!==MSGENCRYPTED){ if(!extension_loaded('sodium')){ @@ -4909,7 +5081,7 @@ function load_lang(): void function load_config(): void { define('VERSION', '1.24.1'); // Script version - define('DBVERSION', 48); // Database layout version + define('DBVERSION', 49); // Database layout version define('MSGENCRYPTED', false); // Store messages encrypted in the database to prevent other database users from reading them - true/false - visit the setup page after editing! define('ENCRYPTKEY_PASS', 'MY_SECRET_KEY'); // Recommended length: 32. Encryption key for messages define('AES_IV_PASS', '012345678912'); // Recommended length: 12. AES Encryption IV