📜 ⬆️ ⬇️

How I screwed reCaptcha to PHPBB 2 under Windows

In the previous note, I already wrote about the simple method of distorting the standard “captcha” PHPBB 2, for the purpose of protection against autoposting and bots, and, skeptically, some did not belong to this method, it still works and successfully fulfills its mission by separating “cutlets from flies. "

Today I would like to talk about another effective method of killing two birds with one stone. I will link reCaptcha to PHPBB 2, and even on the Windows platform.

What is reCaptcha ?
I doubt very much that you have not heard about it yet, but at least you could see the usual “captcha”. Those who are not familiar at all about how the method of recognizing human actions from computer actions (bot, spam posting programs, etc.) works out can be fluently familiar with the term Captcha and find out about reCaptcha and understand why you will kill two birds with one stone - yours and someone else's.

Too lazy to click? I can summarize:
')
reCaptcha was born at the university walls of Carnegie Mellon University and the indirect reason for its creation was the problem of digitizing books for the Internet Archive project, when OCR systems did not cope with their task due to the strong distortion of the source text and failed to perform 100% recognition.

The essence of the technique is as follows: two words are offered to you in the form of a standard captcha, one is known in advance by the system, i.e. already recognized, the other is not. If you correctly recognize the known, then the system assumes that you may have correctly entered the one that has not yet been recognized. For better accuracy, this word is proposed for recognition several more times by other users of the system. This way you help digitize books and protect against bots.

Actually, the idea itself is not new, I recall that Google, and in particular Google Images, has already actively used the solution for attracting human Internet resources for image recognition and tagging.

Thus, if you decide to tie this miracle to your PHPBB, and you can use it not only there, but wherever you want (the official site already has links to a bunch of ready-made modules for Wordpress, Drupal, vBulletin, etc.) , then you need to perform several steps , which will be discussed.

In general, two modules are now available for PHPBB - one for installation on the registration page and the other for guest posting. I will consider the installation only for the registration page, because guest posting is always disabled. (Principle: “If you want to say something sensible and you want something to listen to you, please introduce yourself,” removes many problems)

So, let's begin.
Download the latest module , unpack the archive and copy the files recaptchalib.php and usercp_register.patch to the PHPBB directory - includes, and the file profile_add_body.tpl.patch to the directory of your templates (skins, skins ... I don’t know what you call them), I have For example, this is without options - templates / subSilver /.
According to the instructions we are trying to patch the PHPBB code. Go to the includes, and without a hint of a catch, we launch the magic command:

patch -b usercp_register.php < usercp_register.patch

and get the answer:
"Patch" is not internal or external
command, executable program or batch file.

from which it is quite obvious that we are not such “cool programmers” who always have such wonderful utilities as patch, diff, etc. at hand, and the “manufacturers” of mods for PHPBB are probably so bogged down in Linux that they thought without needs to explain how this is easy to do under Windows.

Well, you will have to install a magic patch utility, if there is none. It can be taken either from the Cygwin project, or directly from here from GnuWin32.

Install it, run the command again and get a new error:
patching file usercp_register.php
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

In order to understand the cause of the problem, I had to very actively "dig" on the Internet. Although, as it turned out, the problem is in sight and lies in the Unix format of the usercp_register.patch and profile_add_body.tpl.patch files (Unix lines end with one LF character, whereas in Windows you need two CR + LF). Therefore, in Windows, the file format must be converted to the "desired", for example:

more usercp_register.patch >usercp_register.new.patch
more profile_add_body.tpl.patch >profile_add_body.tpl.new.patch


Everything, finally, after all this, you can safely perform the patching, adding a few parameters:

patch -lb usercp_register.php -i usercp_register.new.patch
patch -lb profile_add_body.tpl -i profile_add_body.tpl.new.patch


With the installation finished, proceed to configuration and launch.

We register on the reCaptcha site, add our domain to the profile and get private public and private keys, which we insert into the corresponding values ​​of the variables $ recaptcha_public_key and $ recaptcha_private_key, located in the usercp_register.php file (the one in the includes / folder).

Now the last important chord, we make reCaptcha look like in Russian ( you can even customize it at your leisure ).

I simply added the following to the top of the profile_add_body.tpl file:

<script>
var RecaptchaOptions = {
lang : 'ru'
};
</script>


That's all, you should get something like this reCaptch'i (be healthy :)):


Source: Notes on hand

Source: https://habr.com/ru/post/16297/


All Articles