diff --git a/inc/8chan-mod-pages.php b/inc/8chan-mod-pages.php index 1474cf20..3375820a 100644 --- a/inc/8chan-mod-pages.php +++ b/inc/8chan-mod-pages.php @@ -317,6 +317,9 @@ FLAGS; $code_tags = isset($_POST['code_tags']) ? '$config[\'additional_javascript\'][] = \'js/code_tags/run_prettify.js\';$config[\'markup\'][] = array("/\[code\](.+?)\[\/code\]/ms", "
\$1
");' : ''; $katex = isset($_POST['katex']) ? '$config[\'katex\'] = true;$config[\'additional_javascript\'][] = \'js/katex/katex.min.js\'; $config[\'markup\'][] = array("/\[tex\](.+?)\[\/tex\]/ms", "\$1"); $config[\'additional_javascript\'][] = \'js/katex-enable.js\';' : ''; $user_flags = isset($_POST['user_flags']) ? "if (file_exists('$b/flags.php')) { include 'flags.php'; }\n" : ''; + $captcha = isset($_POST['captcha']) ? 'true' : 'false'; + $captcha_charset = base64_encode(isset($_POST['captcha_charset']) && $_POST['captcha_charset'] ? $_POST['captcha_charset'] : 'abcdefghijklmnopqrstuvwxyz'); + $oekaki_js = <<fetch(PDO::FETCH_ASSOC)) { diff --git a/inc/config.php b/inc/config.php index ebbe31a2..3adabcc9 100644 --- a/inc/config.php +++ b/inc/config.php @@ -272,6 +272,8 @@ 'embed', 'recaptcha_challenge_field', 'recaptcha_response_field', + 'captcha_cookie', + 'captcha_text', 'spoiler', 'page', 'file_url', @@ -300,6 +302,19 @@ $config['recaptcha_public'] = '6LcXTcUSAAAAAKBxyFWIt2SO8jwx4W7wcSMRoN3f'; $config['recaptcha_private'] = '6LcXTcUSAAAAAOGVbVdhmEM1_SyRF4xTKe8jbzf_'; + $config['captcha'] = array(); + + // Enable custom captcha provider + $config['captcha']['enabled'] = false; + + // Custom captcha provider path + $config['captcha']['provider_get'] = 'http://8chan.vichan.net/captcha/entrypoint.php'; + $config['captcha']['provider_check'] = 'http://8chan.vichan.net/captcha/entrypoint.php'; + + // Custom captcha extra field (eg. charset) + $config['captcha']['extra'] = 'abcdefghijklmnopqrstuvwxyz'; + + /* * Custom filters detect certain posts and reject/ban accordingly. They are made up of a condition and an * action (for when ALL conditions are met). As every single post has to be put through each filter, diff --git a/inc/instance-config.php b/inc/instance-config.php index aa45f960..da57903c 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -91,6 +91,7 @@ $config['additional_javascript'][] = 'js/jquery.min.js'; $config['additional_javascript'][] = 'js/jquery.mixitup.min.js'; $config['additional_javascript'][] = 'js/catalog.js'; + $config['additional_javascript'][] = 'js/captcha.js'; $config['additional_javascript'][] = 'js/jquery.tablesorter.min.js'; $config['additional_javascript'][] = 'js/options.js'; $config['additional_javascript'][] = 'js/style-select.js'; diff --git a/js/captcha.js b/js/captcha.js new file mode 100644 index 00000000..1824214b --- /dev/null +++ b/js/captcha.js @@ -0,0 +1,44 @@ +var tout; + +function redo_events(provider, extra) { + $('.captcha .captcha_text, textarea[id="body"]').off("focus").one("focus", function() { actually_load_captcha(provider, extra); }); +} + +function actually_load_captcha(provider, extra) { + $('.captcha .captcha_text, textarea[id="body"]').off("focus"); + + if (tout !== undefined) { + clearTimeout(tout); + } + + $.getJSON(provider, {mode: 'get', extra: extra}, function(json) { + $(".captcha .captcha_cookie").val(json.cookie); + $(".captcha .captcha_html").html(json.captchahtml); + + setTimeout(function() { + redo_events(provider, extra); + }, json.expires_in * 1000); + }); +} + +function load_captcha(provider, extra) { + $(function() { + $(".captcha>td").html(""+ + ""+ + "
"); + + $("#quick-reply .captcha .captcha_text").prop("placeholder", _("Verification")); + + $(".captcha .captcha_html").on("click", function() { actually_load_captcha(provider, extra); }); + $(document).on("ajax_after_post", function() { actually_load_captcha(provider, extra); }); + redo_events(provider, extra); + + $(window).on("quick-reply", function() { + redo_events(provider, extra); + $("#quick-reply .captcha .captcha_html").html($("form:not(#quick-reply) .captcha .captcha_html").html()); + $("#quick-reply .captcha .captcha_cookie").val($("form:not(#quick-reply) .captcha .captcha_cookie").html()); + $("#quick-reply .captcha .captcha_html").on("click", function() { actually_load_captcha(provider, extra); }); + }); + }); +} + diff --git a/js/quick-reply.js b/js/quick-reply.js index 07fe4aef..85503dd8 100644 --- a/js/quick-reply.js +++ b/js/quick-reply.js @@ -149,14 +149,14 @@ .removeAttr('size') .attr('placeholder', $th.clone().children().remove().end().text()); } - + // Move anti-spam nonsense and remove $th.contents().filter(function() { return this.nodeType == 3; // Node.TEXT_NODE }).remove(); $th.contents().appendTo($dummyStuff); $th.remove(); - + if ($td.find('input[name="password"]').length) { // Hide password field $(this).hide(); @@ -280,7 +280,7 @@ $postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment')); - $postForm.find('textarea:not([name="body"]),input[type="hidden"]').removeAttr('id').appendTo($dummyStuff); + $postForm.find('textarea:not([name="body"]),input[type="hidden"]:not(.captcha_cookie)').removeAttr('id').appendTo($dummyStuff); $postForm.find('br').remove(); $postForm.find('table').prepend('\ diff --git a/post.php b/post.php index 650b431b..bffc91c0 100644 --- a/post.php +++ b/post.php @@ -232,6 +232,21 @@ elseif (isset($_POST['post'])) { } } + // Same, but now with our custom captcha provider + if ($config['captcha']['enabled']) { + $resp = file_get_contents($config['captcha']['provider_check'] . "?" . http_build_query([ + 'mode' => 'check', + 'text' => $_POST['captcha_text'], + 'extra' => $config['captcha']['extra'], + 'cookie' => $_POST['captcha_cookie'] + ])); + + if ($resp !== '1') { + error($config['error']['captcha'] . + ''); + } + } + //if (!(($post['op'] && $_POST['post'] == $config['button_newtopic']) || //(!$post['op'] && $_POST['post'] == $config['button_reply']))) //error($config['error']['bot']); diff --git a/templates/mod/settings.html b/templates/mod/settings.html index 487f82d8..74319aa4 100644 --- a/templates/mod/settings.html +++ b/templates/mod/settings.html @@ -44,6 +44,8 @@ {% trans %}Enable dice rolling{% endtrans %} {% trans %}Don't allow users to repost images{% endtrans %} {% trans %}Allow a poster to delete his own posts{% endtrans %} + {% trans %}Enable captcha{% endtrans %} + {% trans %}Captcha charset{% endtrans %} {% trans %}Language{% endtrans %}
{% trans %}To contribute translations, register at Transifex{% endtrans %}