reCAPTCHA v2 install on OTRS 6.0.17 (Centos 7)

Moderator: crythias

Post Reply
altronrain
Znuny newbie
Posts: 14
Joined: 15 Apr 2019, 11:07
Znuny Version: 6.0.17
Real Name: Kirill
Company: NumaTech

reCAPTCHA v2 install on OTRS 6.0.17 (Centos 7)

Post by altronrain »

Hello!
I'm pretty new to OTRS in terms of configuration/administration. I have a task to add reCAPTCHA to customer registration process. I tried to follow instructions from OTRS 5.0.X reCaptcha thread here (viewtopic.php?f=60&t=33699) but that not helped me.
So, what i've done:
1) Installed Captcha::reCAPTCHA module using cpan;
2) Copied Kernel/System/Web/InterfaceCustomer.pm to Custom directory (including subdirectory creation as Custom/Kernel...);
Same for Kernel/Output/HTML/Layout.pm and Kernel/Output/HTML/Templates/Standart/CustomerLogin.tt;
3) Implemented changes to Layout.pm as suggested:

Code: Select all

use Captcha::reCAPTCHA;

in use section and

Code: Select all

#begin recaptcha
        my $rc = Captcha::reCAPTCHA->new;
        my $rccustom = "<script type= \"text/javascript\">\n
var RecaptchaOptions = {\n
   lang : 'ru',
};\n
</script>\n";
        $Param{reCAPTCHA} = $rccustom . $rc->get_html("my_pub_key"); #public key
        #end recaptcha
inside /or after? account creation block;

Added

Code: Select all

<!--begin recaptcha -->
                    <div class="NewLine">

                        [% Data.reCAPTCHA %]

                    </div>
                    <!-- end recaptcha -->
inside CustomerLogin.tt before button CreateAccount lines;

And

Code: Select all

use Captcha::reCAPTCHA;
+

Code: Select all

#check reCAPTCHA
        my $rc = Captcha::reCAPTCHA->new;
        my $challenge = $ParamObject->GetParam(Param => 'recaptcha_challenge_field') || '';
        my $response = $ParamObject->GetParam(Param => 'recaptcha_response_field') || '';
        my $result = $rc->check_answer("my_sec_key", $ENV{'REMOTE_ADDR'}, # private key
           $challenge, $response
           );
        if ( !$result->{is_valid} ) {
            my $Output = $LayoutObject->CustomerHeader(
                Area  => 'Core',
                Title => 'Error'
            );
            $Output .= $LayoutObject->CustomerWarning(
                Message => 'reCAPTCHA entry failed.',
                Comment => 'Please press Back and try again.'
            );
            $Output .= $LayoutObject->CustomerFooter();
            $LayoutObject->Print( Output => \$Output );
            exit 0;
        }
        #end recaptcha
to InterfaceCustomer.pm

All changes made to Custom/Kernel... file copies.

4) After all manipulations all i get is 500 Internal error message on all otrs pages. What should i do to configure reCAPTCHA to OTRS 6 properly? (Can't find any instructions. Maybe smth in reCAPTCHA module changed or OTRS itself?)
altronrain
Znuny newbie
Posts: 14
Joined: 15 Apr 2019, 11:07
Znuny Version: 6.0.17
Real Name: Kirill
Company: NumaTech

Re: reCAPTCHA v2 install on OTRS 6.0.17 (Centos 7)

Post by altronrain »

Okay, I made a little progress. Apache log says that i missed Captcha/reCAPTCHA.pm e.t.c. (even when i installed it under root and under otrs user separately). So i just copied needed files to one of @INC directories. After this Captcha started to work correctly. BUTI figured out that its v1 that shutdown already... So I need help to deal with v2 now.
(And could someone tell me how to properly configure Core.Login.css with Slider and PreLogin values cause customers can see (New password request fields that way (400px both))
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: reCAPTCHA v2 install on OTRS 6.0.17 (Centos 7)

Post by crythias »

note the new stuff for v2:
https://metacpan.org/pod/Captcha::reCAPTCHA

get_html_v2 vs get_html
check_answer_v2 has a new format:
my $private_key = 'my_secure_key';
my $result = $rc->check_answer_v2($private_key, $response, $ENV{REMOTE_ADDR});

as for the slider ... maybe I can check another time.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
altronrain
Znuny newbie
Posts: 14
Joined: 15 Apr 2019, 11:07
Znuny Version: 6.0.17
Real Name: Kirill
Company: NumaTech

Re: reCAPTCHA v2 install on OTRS 6.0.17 (Centos 7)

Post by altronrain »

yeah. Also discovered this yesterday evening. There are even Captcha::reCAPTCHA::v2 module (but idk how to configure its syntax).
So, i reconfigured Layout.pm:

Code: Select all

#begin recaptcha
        my $rc = Captcha::reCAPTCHA->new;
        my $rccustom = "<script type= \"text/javascript\">\n
var RecaptchaOptions = {\n
   lang : 'ru',
};\n
</script>\n";
        #my $html = $rc->html ('pub_key', { theme => 'white' });
        $Param{reCAPTCHA} = $rccustom . $rc->get_html_v2('pub_key'); #public key
        #end recaptcha
Then tried to do the same to InterfaceCustomer:

Code: Select all

#check reCAPTCHA
        my $rc = Captcha::reCAPTCHA->new;
        #my $challenge = $ParamObject->GetParam(Param => 'recaptcha_challenge_field') || ''; 
        my $response = $ParamObject->GetParam(Param => 'recaptcha_response_field') || '';
        #my $
        my $result = $rc->check_answer_v2('sec_key', $response, $ENV{'REMOTE_ADDR'}#, # private key
           #$challenge, $response
           );
        if ( !$result->{is_valid} ) {
            my $Output = $LayoutObject->CustomerHeader(
                Area  => 'Core',
                Title => 'Error'
            );
            $Output .= $LayoutObject->CustomerWarning(
                Message => 'reCAPTCHA entry failed.',
                Comment => 'Please press Back and try again.'
            );
            $Output .= $LayoutObject->CustomerFooter();
            $LayoutObject->Print( Output => \$Output );
            exit 0;
        }
        #end recaptcha
Now i can see Login forms (not a 500 error 100% uptime! Yeah!). Even can check the @Checkbox@ of reCAPTCHA (but then nothing happens...). But then again i get 500 error. Apache says that response is required (so, i guess it's empty?). If I comment my $response line Apache syas that it must be defined. So i guess the whole problem in this line syntax. Or not. It's time to learn rerl, i suppose.
Post Reply