diff --git a/captcha.php b/captcha.php new file mode 100644 index 00000000..d4e5eb2a --- /dev/null +++ b/captcha.php @@ -0,0 +1,32 @@ +__DIR__ . '/inc/captchaconfig.php')); + +$image->show(); + +$code=$image->getCode(false, true); + +$ip=$_SERVER['REMOTE_ADDR']; + +$query=prepare('INSERT INTO captchas(ip, code, time) VALUES(:ip, :code, NOW())'); +$query->bindValue(':ip', $ip); +$query->bindValue(':code', $code); +$query->execute() or error(db_error($query)); + +$query=prepare('SELECT count(*) from captchas where ip=:ip'); +$query->bindValue(':ip', $ip); +$query->execute() or error(db_error($query)); + +$count=$query->fetch()[0]; +if($count>10){ + $query=prepare('DELETE from captchas where ip=:ip ORDER BY time asc LIMIT 1'); + $query->bindValue(':ip', $ip); + $query->execute()or error(db_error($query)); +} diff --git a/inc/captchaconfig.php b/inc/captchaconfig.php new file mode 100644 index 00000000..9c3f43f3 --- /dev/null +++ b/inc/captchaconfig.php @@ -0,0 +1,90 @@ + 275, // width of captcha image in pixels + 'image_height' => 100, // height of captcha image in pixels + 'code_length' => 6, // # of characters for captcha code + 'image_bg_color' => '#770000', // hex color for image background + 'text_color' => '#DDDD64', // hex color for captcha text + 'line_color' => '#DDDD64', // hex color for lines over text + 'noise_color' => '#DDDD64', // color of random noise to draw under text + 'num_lines' => 5, // # of lines to draw over text + 'noise_level' => 0.5, // how much random noise to add (0-10) + 'perturbation' => 0.75, // distoration level + + 'use_random_spaces' => true, + 'use_random_baseline' => true, + 'use_text_angles' => true, + 'use_random_boxes' => false, +'use_transparent_text' => false, + + 'wordlist_file' => 'words/words.txt', // text file for word captcha + 'use_wordlist' => false, // true to use word list + 'wordlist_file_encoding' => null, // character encoding of word file if other than ASCII (e.g. UTF-8, GB2312) + + // example UTF-8 charset (TTF file must support symbols being used + // 'charset' => "абвгдeжзийклмнопрстуфхцчшщъьюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ", + 'charset' => "2345689abdfgkmnpqsuwxyz", // capitals are more effort to type, removed confusable characters like o,O,0,1,l + + // 'ttf_file' => './AHGBold.ttf', // TTF file for captcha text + + //'captcha_type' => Securimage::SI_CAPTCHA_WORDS, // Securimage::SI_CAPTCHA_STRING || Securimage:: SI_CAPTCHA_MATHEMATIC || Securimage::SI_CAPTCHA_WORDS + + //'display_value' => 'ABC 123', // Draws custom text on captcha + + + /**** Code Storage & Database Options ****/ + + // true if you *DO NOT* want to use PHP sessions at all, false to use PHP sessions + 'no_session' => true, + + // the PHP session name to use (null for default PHP session name) + // do not change unless you know what you are doing + 'session_name' => null, + + // change to true to store codes in a database + 'use_database' => true, + + // database engine to use for storing codes. must have the PDO extension loaded + // Values choices are: + // Securimage::SI_DRIVER_MYSQL, Securimage::SI_DRIVER_SQLITE3, Securimage::SI_DRIVER_PGSQL + 'database_driver' => Securimage::SI_DRIVER_MYSQL, + + 'database_host' => 'localhost', // database server host to connect to + 'database_user' => 'lainchan', // database user to connect as + 'database_pass' => '', // database user password + 'database_name' => 'lainchan', // name of database to select (you must create this first or use an existing database) + 'database_table' => 'captcha_codes', // database table for storing codes, will be created automatically + + // Securimage will automatically create the database table if it is not found + // change to true for performance reasons once database table is up and running + 'skip_table_check' => false, + + /**** Audio Options ****/ + + //'audio_path' => __DIR__ . '/audio/en/', + //'audio_use_noise' => true, + //'audio_noise_path' => __DIR__ . '/audio/noise/', + //'degrade_audio' => true, + + 'no_exit'=>true, + + + 'log_file'=>'/dev/null', //This should be placed somewhere sensible. +); diff --git a/inc/config.php b/inc/config.php index 6324855f..1444c61b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1779,6 +1779,16 @@ * ==================== */ + //Securimage captcha + //Note from lainchan PR: "TODO move a bunch of things here" + + $config['spam']['valid_inputs'][]='captcha'; + $config['error']['securimage']=array( + 'missing'=>'The captcha field was missing. Please try again', + 'empty'=>'Please fill out the captcha', + 'bad'=>'Incorrect or expired captcha', + ); + // Meta keywords. It's probably best to include these in per-board configurations. // $config['meta_keywords'] = 'chan,anonymous discussion,imageboard,tinyboard'; diff --git a/inc/instance-config.php b/inc/instance-config.php index 0e0d7b1c..f470e2c8 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -117,6 +117,11 @@ $config['url_banner'] = '/banners.php'; */ $config['spam']['enabled'] = false; +/* + * Basic captcha. See also: captchaconfig.php + */ +$config['securimage'] = false; + /* * Permissions */ diff --git a/inc/lib/securimage/AHGBold.ttf b/inc/lib/securimage/AHGBold.ttf new file mode 100644 index 00000000..764b23d7 Binary files /dev/null and b/inc/lib/securimage/AHGBold.ttf differ diff --git a/inc/lib/securimage/securimage.php b/inc/lib/securimage/securimage.php new file mode 100644 index 00000000..23a8feaa --- /dev/null +++ b/inc/lib/securimage/securimage.php @@ -0,0 +1,3771 @@ + + * @version 3.6.7 (March 2018) + * @package Securimage + * + */ + +/** + + ChangeLog + 3.6.7 + - Merge changes from 4.0.1-nextgen + - Increase captcha difficulty + - Add setting "use_text_angles". Enable to select a random angle and step value and draw each character at an angle in a step like fashion + - Add setting "use_random_spaces". Enable to insert 1-3 spaces between a random group of letters some of the time + - Add setting "use_random_baseline". Enable to draw letters at a random height instead of centered. Each character's baseline is a step up or down from the previous (not totally random) + - Add setting "use_random_boxes". Enable to draw a bounding box around one or more characters at random + - Improve performance of captcha generation when using distortion (perturbation) and noise (noise_level) + - Enable image anti-aliasing + - Make all text functions multibyte safe when using UTF-8 or other encodings for charsets and wordlists (using mbstring) + + 3.6.6 + - Not critical: Fix potential HTML injection in example form via HTTP_USER_AGENT (CVE-2017-14077) + + 3.6.5 + - Fix regex in replaceElements in securimage.js + - Update examples + - Exclude certain examples from Git autogenerated archives + + 3.6.4 + - Fix XSS vulnerability in example_form.ajax.php (Discovered by RedTeam. advisory rt-sa-2016-002) + - Update example_form.ajax.php to use Securimage::getCaptchaHtml() + + 3.6.3 + - Add support for multibyte wordlist files + - Fix code generation issues with UTF-8 charsets + - Add parameter to getCaptchaHtml() method to control display components of captcha HTML + - Fix database audio storage issue with multiple namespaces + + 3.6.2 + - Support HTTP range requests with audio playback (iOS requirement) + - Add optional config.inc.php for storing global configuration settings + + 3.6.1 + - Fix copyElement bug in securimage.js for IE Flash fallback + + 3.6 + - Implement CAPTCHA audio using HTML5