diff --git a/inc/config.php b/inc/config.php index e0950bc5..20ad77b4 100644 --- a/inc/config.php +++ b/inc/config.php @@ -33,6 +33,8 @@ // Enables captcha $config['securimage'] = false; + // Limits captcha to TOR users + $config['captcha_tor_only'] = false; // Global announcement -- the very simple version. // This used to be wrongly named $config['blotter'] (still exists as an alias). diff --git a/inc/functions.php b/inc/functions.php index d7192f43..b090798b 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2905,3 +2905,34 @@ function strategy_first($fun, $array) { return array('defer'); } } + +function ipIsLocal($ip) { + // Define the local IP ranges commonly used in private networks + $localRanges = [ + '10.0.0.0/8', // Private network range 10.0.0.0 to 10.255.255.255 + '172.16.0.0/12', // Private network range 172.16.0.0 to 172.31.255.255 + '192.168.0.0/16', // Private network range 192.168.0.0 to 192.168.255.255 + '127.0.0.0/8', // Loopback range for localhost + '169.254.0.0/16' // Link-local addresses + ]; + + foreach ($localRanges as $range) { + if (ipInRange($ip, $range)) { + return true; + } + } + + return false; +} + +function ipInRange($ip, $range) { + // Split the range to get the base IP and the netmask + list($baseIP, $netmask) = explode('/', $range); + // Convert IPs into long format for easy comparison + $ipLong = ip2long($ip); + $rangeLong = ip2long($baseIP); + $maskLong = ~((1 << (32 - $netmask)) - 1); + + // Check if the IP is in the given range + return (($ipLong & $maskLong) == ($rangeLong & $maskLong)); +} diff --git a/inc/instance-config.php b/inc/instance-config.php index 22c2d03a..9aad1cc8 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -142,7 +142,8 @@ $config['spam_noticer']['website_name'] = "leftychan"; /* * Basic captcha. See also: captchaconfig.php */ -$config['securimage'] = false; +$config['securimage'] = true; +$config['captcha_tor_only'] = true; /* * Permissions diff --git a/post.php b/post.php index 27c153da..22932166 100644 --- a/post.php +++ b/post.php @@ -511,7 +511,11 @@ function handle_post(){ } } - if(isset($config['securimage']) && $config['securimage']){ + if((isset($config['securimage']) && $config['securimage']) + && ( + !(isset($config['captcha_tor_only']) && $config['captcha_tor_only']) + || ipIsLocal($_SERVER['REMOTE_ADDR']) + )){ if(!isset($_POST['captcha'])){ error($config['error']['securimage']['missing']); diff --git a/templates/post_form.html b/templates/post_form.html index 5d9d3a2b..a8ddf51d 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -5,13 +5,10 @@ method="post" data-max-images="{{ config.max_images }}" > -{{ antibot.html() }} {% if id %}{% endif %} -{{ antibot.html() }} {% if board.uri not in config.overboards|keys %} {% endif %} -{{ antibot.html() }} {% if current_page %} {% endif %} @@ -103,15 +100,39 @@ {% endif %} {% if config.securimage %} -