diff --git a/common_config.php b/common_config.php index 007dc6d..cff8859 100644 --- a/common_config.php +++ b/common_config.php @@ -1,23 +1,4 @@ -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - // Configuration const DBHOST = 'localhost'; // Database host const DBUSER = 'www-data'; // Database user @@ -36,6 +17,7 @@ const VERSION = '1.1'; // Script version const DBVERSION = 8; // Database layout version const REQUIRE_APPROVAL = false; // require admin approval of new sites? true/false const CANONICAL_URL = 'https://onions.danwin1210.de'; // our preferred domain for search engines +const CAPTCHA = 0; // Captcha difficulty (0=off, 1=simple, 2=moderate, 3=extreme) //Categories - new links will always be put into the first one, leave it to Unsorted //once configured, only add new categories at the end or you have to manually adjust the database. $categories=['Unsorted', 'Adult/Porn', 'Communication/Social', 'Forums', 'Hacking/Programming/Software', 'Hosting', 'Libraries/Wikis', 'Link Lists', 'Market/Shop/Store', 'Other', 'Personal Sites/Blogs', 'Security/Privacy/Encryption', 'Whistleblowing', 'Empty/Error/Unknown', 'Cryptocurrencies', 'Scams', 'Fun/Games/Joke', 'Search']; diff --git a/www/index.php b/www/index.php index 68d0996..e85efaa 100644 --- a/www/index.php +++ b/www/index.php @@ -218,21 +218,23 @@ function send_html(): void echo ''; echo '

'.sprintf(_('A valid address looks like this: %s'), 'http://danielas3rtn54uwmofdo3x2bsdifr47huasnmbgqzfrec5ubupvtpid.onion') .'

'; }else{ - if(!isset($_REQUEST['challenge'])){ - send_error(_('Error: Wrong captcha')); - } - $stmt=$db->prepare('SELECT code FROM ' . PREFIX . 'captcha WHERE id=?;'); - $stmt->execute([$_REQUEST['challenge']]); - $stmt->bindColumn(1, $code); - if(!$stmt->fetch(PDO::FETCH_BOUND)){ - send_error(_('Error: Captcha expired')); - } - $time=time(); - $stmt=$db->prepare('DELETE FROM ' . PREFIX . 'captcha WHERE id=? OR timeexecute([$_REQUEST['challenge'], $time-3600]); - if($_REQUEST['captcha']!==$code){ - if(strrev($_REQUEST['captcha'])!==$code){ - send_error(_('Error: Wrong captcha')); + if(CAPTCHA !== 0) { + if ( ! isset( $_REQUEST[ 'challenge' ] ) ) { + send_error( _( 'Error: Wrong captcha' ) ); + } + $stmt = $db->prepare( 'SELECT code FROM ' . PREFIX . 'captcha WHERE id=?;' ); + $stmt->execute( [ $_REQUEST[ 'challenge' ] ] ); + $stmt->bindColumn( 1, $code ); + if ( ! $stmt->fetch( PDO::FETCH_BOUND ) ) { + send_error( _( 'Error: Captcha expired' ) ); + } + $time = time(); + $stmt = $db->prepare( 'DELETE FROM ' . PREFIX . 'captcha WHERE id=? OR timeexecute( [ $_REQUEST[ 'challenge' ], $time - 3600 ] ); + if ( $_REQUEST[ 'captcha' ] !== $code ) { + if ( strrev( $_REQUEST[ 'captcha' ] ) !== $code ) { + send_error( _( 'Error: Wrong captcha' ) ); + } } } $addr=strtolower($addr[4]); @@ -489,8 +491,7 @@ function get_pagination(int $category, int $pages) : string { function send_captcha(): void { global $db; - $difficulty=1; - if($difficulty===0 || !extension_loaded('gd')){ + if(CAPTCHA === 0 || !extension_loaded('gd')){ return; } $captchachars='ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789'; @@ -504,28 +505,80 @@ function send_captcha(): void $stmt=$db->prepare('INSERT INTO ' . PREFIX . 'captcha (id, time, code) VALUES (?, ?, ?);'); $stmt->execute([$randid, $time, $code]); echo '