mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-28 09:20:58 +01:00
custom captcha integration
This commit is contained in:
parent
1d0409e84b
commit
62a6dac022
@ -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", "<code><pre class=\'prettyprint\' style=\'display:inline-block\'>\$1</pre></code>");' : '';
|
||||
$katex = isset($_POST['katex']) ? '$config[\'katex\'] = true;$config[\'additional_javascript\'][] = \'js/katex/katex.min.js\'; $config[\'markup\'][] = array("/\[tex\](.+?)\[\/tex\]/ms", "<span class=\'tex\'>\$1</span>"); $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 = <<<OEKAKI
|
||||
\$config['additional_javascript'][] = 'js/jquery-ui.custom.min.js';
|
||||
@ -392,6 +395,8 @@ OEKAKI;
|
||||
\$config['blotter'] = base64_decode('$blotter');
|
||||
\$config['stylesheets']['Custom'] = 'board/$b.css';
|
||||
\$config['default_stylesheet'] = array('Custom', \$config['stylesheets']['Custom']);
|
||||
\$config['captcha']['enabled'] = $captcha;
|
||||
\$config['captcha']['extra'] = base64_decode('$captcha_charset');
|
||||
$code_tags $katex $oekaki $replace $multiimage $allow_flash $allow_pdf $user_flags
|
||||
if (\$config['disable_images'])
|
||||
\$config['max_pages'] = 10000;
|
||||
@ -412,7 +417,11 @@ EOT;
|
||||
openBoard($b);
|
||||
|
||||
// be smarter about rebuilds...only some changes really require us to rebuild all threads
|
||||
if ($_config['blotter'] != $config['blotter'] || $_config['field_disable_name'] != $config['field_disable_name'] || $_config['show_sages'] != $config['show_sages']) {
|
||||
if ($_config['captcha']['enabled'] != $config['captcha']['enabled']
|
||||
|| $_config['captcha']['extra'] != $config['captcha']['extra']
|
||||
|| $_config['blotter'] != $config['blotter']
|
||||
|| $_config['field_disable_name'] != $config['field_disable_name']
|
||||
|| $_config['show_sages'] != $config['show_sages']) {
|
||||
buildIndex();
|
||||
$query = query(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL", $b)) or error(db_error());
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
@ -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,
|
||||
|
@ -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';
|
||||
|
44
js/captcha.js
Normal file
44
js/captcha.js
Normal file
@ -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("<input class='captcha_text' type='text' name='captcha_text' size='25' maxlength='6' autocomplete='off'>"+
|
||||
"<input class='captcha_cookie' name='captcha_cookie' type='hidden'>"+
|
||||
"<div class='captcha_html'></div>");
|
||||
|
||||
$("#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); });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -149,14 +149,14 @@
|
||||
.removeAttr('size')
|
||||
.attr('placeholder', $th.clone().children().remove().end().text());
|
||||
}
|
||||
|
||||
|
||||
// Move anti-spam nonsense and remove <th>
|
||||
$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('<tr><th colspan="2">\
|
||||
|
15
post.php
15
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'] .
|
||||
'<script>if (actually_load_captcha !== undefined) actually_load_captcha("'.$config['captcha']['provider_get'].'", "'.$config['captcha']['extra'].'");</script>');
|
||||
}
|
||||
}
|
||||
|
||||
//if (!(($post['op'] && $_POST['post'] == $config['button_newtopic']) ||
|
||||
//(!$post['op'] && $_POST['post'] == $config['button_reply'])))
|
||||
//error($config['error']['bot']);
|
||||
|
@ -44,6 +44,8 @@
|
||||
<tr><th>{% trans %}Enable dice rolling{% endtrans %}</th><td><input type="checkbox" name="allow_roll" {% if config.allow_roll %}checked{% endif %}></td></tr>
|
||||
<tr><th>{% trans %}Don't allow users to repost images{% endtrans %}</th><td><input type="checkbox" name="image_reject_repost" {% if config.image_reject_repost %}checked{% endif %}></td></tr>
|
||||
<tr><th>{% trans %}Allow a poster to delete his own posts{% endtrans %}</th><td><input type="checkbox" name="allow_delete" {% if config.allow_delete %}checked{% endif %}></td></tr>
|
||||
<tr><th>{% trans %}Enable captcha{% endtrans %}</th><td><input type="checkbox" name="captcha" {% if config.captcha.enabled %}checked{% endif %}></td></tr>
|
||||
<tr><th>{% trans %}Captcha charset{% endtrans %}</th><td><input type="text" name="captcha_charset" value="{{ config.captcha.extra|e }}"></td></tr>
|
||||
<tr><th>{% trans %}Language{% endtrans %}<br/><span class="unimportant">{% trans %}To contribute translations, register at <a href="https://www.transifex.com/projects/p/tinyboard-vichan-devel/">Transifex</a>{% endtrans %}</span></th><td>
|
||||
<select name="locale">
|
||||
<option value="en" {% if "en" == config.locale %}selected{% endif %}>en</option>
|
||||
|
@ -80,6 +80,17 @@
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if config.captcha.enabled %}
|
||||
<tr class='captcha'>
|
||||
<th>
|
||||
{% trans %}Verification{% endtrans %}
|
||||
</th>
|
||||
<td>
|
||||
<script>load_captcha("{{ config.captcha.provider_get }}", "{{ config.captcha.extra }}");</script>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if config.user_flag %}
|
||||
<tr>
|
||||
<th>{% trans %}Flag{% endtrans %}</th>
|
||||
|
Loading…
Reference in New Issue
Block a user