Skip to content

Commit 4876f61

Browse files
authored
Merge pull request #54 from Crizz0/issue/53
Repair use of recaptcha
2 parents a91216f + ed00012 commit 4876f61

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

controller/main.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,25 +324,18 @@ private function display_pb()
324324
$captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
325325
$captcha->init($this::CONFIRM_PASTEBIN);
326326

327-
if (!$captcha->is_solved())
327+
$vc_response = $captcha->validate($data);
328+
if ($vc_response !== false)
328329
{
329-
$error[] = $this->language->lang('PASTEBIN_CONFIRM_CODE_WRONG');
330-
}
331-
else if (!empty($error))
332-
{
333-
$captcha->new_attempt();
334-
}
335-
else
336-
{
337-
$captcha->garbage_collect($this::CONFIRM_PASTEBIN);
330+
$error[] = $vc_response;
338331
}
339332
}
340333

341334
if (!empty($error))
342335
{
343336
// Remove duplicate entries of the error array
344337
$error = array_unique($error);
345-
// We have errors, we don't insert here, but instead go back to the posting page and tell the user what he did wrong
338+
// We have errors, we don't insert here, but instead go back to the submit page and tell the user what he did wrong
346339
$s_error = implode('<br />', $error);
347340
}
348341
else
@@ -359,6 +352,12 @@ private function display_pb()
359352
'snippet_prune_on' => time() + $this::SECONDS_MONTH * $data['snippet_prune_on'],
360353
);
361354

355+
// Okay, captcha, your job is done.
356+
if (!$this->auth->acl_get('u_pastebin_post_novc') && isset($captcha) && $captcha->is_solved() === true)
357+
{
358+
$captcha->reset();
359+
}
360+
362361
$sql = 'INSERT INTO ' . $this->pastebin_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
363362
$this->db->sql_query($sql);
364363

@@ -543,16 +542,16 @@ private function display_pb()
543542
}
544543

545544
$s_hidden_fields['mode'] = 'post';
546-
547545
// Visual Confirmation - Show images (borrowed from includes/ucp/ucp_register.php)
548-
$confirm_image = '';
549546
if (!$this->auth->acl_get('u_pastebin_post_novc'))
550547
{
551548
if (!isset($captcha))
552549
{
553550
$captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
554551
$captcha->init($this::CONFIRM_PASTEBIN);
555552
}
553+
$s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
554+
556555
$this->template->assign_var('PASTEBIN_CAPTCHA_TEMPLATE', $captcha->get_template());
557556
}
558557

@@ -595,6 +594,9 @@ private function display_pb()
595594
}
596595
$highlight_select = $this->util->highlight_select($highlight);
597596

597+
$captcha_in_use = $this->config['captcha_plugin'];
598+
$is_recaptcha = strpos($captcha_in_use, 'recaptcha');
599+
598600
add_form_key('pastebinform');
599601

600602
$this->template->assign_vars(array(
@@ -608,12 +610,12 @@ private function display_pb()
608610

609611
'FILESIZE' => $this->config['max_filesize'],
610612

611-
'CONFIRM_IMG' => $confirm_image,
613+
'PASTEBIN_IS_RECAPTCHA' => $is_recaptcha,
612614

613615
'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"',
614616
'S_ERROR' => (isset($s_error)) ? $s_error : '',
615-
'S_HIDDEN_FIELDS' => (sizeof($s_hidden_fields)) ? build_hidden_fields($s_hidden_fields) : '',
616-
'S_CONFIRM_CODE' => (!$this->auth->acl_get('u_pastebin_post_novc')) ? true : false,
617+
'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields),
618+
'S_CONFIRM_CODE' => !$this->auth->acl_get('u_pastebin_post_novc'),
617619
));
618620
}
619621
}

language/de/pastebin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
'PASTEBIN' => 'Pastebin',
5858
'PASTEBIN_AUTH_NO_VIEW' => 'Du hast keine Berechtigung, die Seite anzuzeigen.',
5959
'PASTEBIN_AUTH_NO_POST' => 'Du hast keine Berechtigung, einen Eintrag zu erstellen.',
60-
'PASTEBIN_CONFIRM' => 'Visuelle Bestätigung',
61-
'PASTEBIN_CONFIRM_EXPLAIN' => 'Gib den Code genau so ein, wie du ihn siehst; Groß- und Kleinschreibung wird nicht unterschieden, Null wird nicht verwendet.',
60+
'PASTEBIN_CONFIRM' => 'Anti-Spam-Bot-Maßnahmen',
61+
'PASTEBIN_CONFIRM_EXPLAIN' => 'Bitte löse die Anti-Spam-Bot-Maßnahmen, damit dein Eintrag abgesendet werden kann.',
6262
'PASTEBIN_EMPTY_FILEUPLOAD' => 'Die hochgeladene Datei ist leer.',
6363
'PASTEBIN_EXPLAIN' => 'Im Pastebin kannst du Codeabschnitte oder auch ganze Dateien ablegen, um sie zum Beispiel später in einem Supportthema zu verlinken.',
6464
'PASTEBIN_HELLO' => 'Hat dich jemand hierher geschickt?',

language/en/pastebin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
'PASTEBIN' => 'Pastebin',
5757
'PASTEBIN_AUTH_NO_VIEW' => 'You are not authorized to view this page.',
5858
'PASTEBIN_AUTH_NO_POST' => 'You are not authorized to enter a new entry.',
59-
'PASTEBIN_CONFIRM' => 'Visual confirmation',
60-
'PASTEBIN_CONFIRM_EXPLAIN' => 'Enter the code exactly as you see it; capitalization will be ignored, zero is not used.',
59+
'PASTEBIN_CONFIRM' => 'Spambot countermeasures',
60+
'PASTEBIN_CONFIRM_EXPLAIN' => 'Please solve the spambot countermeasures to submit your entry.',
6161
'PASTEBIN_EMPTY_FILEUPLOAD' => 'The uploaded file is empty.',
6262
'PASTEBIN_EXPLAIN' => 'In the pastebin, you can paste code snippets or whole files, for example to add a link to them to a support topic.',
6363
'PASTEBIN_HELLO' => 'Did someone direct you here?',

styles/prosilver/template/pastebin_post.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ <h3>{{ lang('PASTEBIN_SNIPPET_TEXT') }}</h3>
5454
</fieldset>
5555

5656
{% if PASTEBIN_CAPTCHA_TEMPLATE %}
57-
<h3>{{ lang('PASTEBIN_CONFIRM') }}</h3>
58-
<p>{{ lang('PASTEBIN_CONFIRM_EXPLAIN') }}</p>
57+
{% if not PASTEBIN_IS_RECAPTCHA %}
58+
<h3>{{ lang('PASTEBIN_CONFIRM') }}</h3>
59+
<p>{{ lang('PASTEBIN_CONFIRM_EXPLAIN') }}</p>
60+
{% endif %}
5961

60-
6162
{% DEFINE CAPTCHA_TAB_INDEX = 8 %}
6263
{% INCLUDE ''~ PASTEBIN_CAPTCHA_TEMPLATE ~'' %}
6364

0 commit comments

Comments
 (0)