Page 1 of 2

re-captcha 2 or 3 or question captcha

Posted: 25 Mar 2024, 14:03
by durangod
Hi,

I found some old topics regarding recaptcha but those mods (for a really old version) dont work anymore so has anyone implemented re-captcha or question captcha to the script successfully yet?

Mantis 2.26.1

Thanks :)

Re: re-captcha 2 or 3 or question captcha

Posted: 31 Mar 2024, 13:10
by cas
I have released a plugin that adds a captcha to the login page, have a look here: https://github.com/mantisbt-plugins/Captcha

Re: re-captcha 2 or 3 or question captcha

Posted: 10 Jun 2024, 18:58
by durangod
Hi, sorry so late with reply, i took some time away for healing and family. Thank you so much for this. I will get it uploaded soon. :)

Re: re-captcha 2 or 3 or question captcha

Posted: 11 Jun 2024, 19:31
by durangod
Hello again, i installed the plugin and got this..
Missing Plugin Base Class
A directory for this Plugin was found, but there was no corresponding Plugin code inside of it. Make sure the directory's name matches the Plugin's base name (case sensitive)
I could not find this in the install instructions - Select Install behind Captcha 2.1.0

i did check and the folder in plugins is Captcha-main and the name of the plugin is also Captcha-main. I will poke around a bit to see what i can discover. Thanks again for your help on this :)

I did not want to create a issue in GitHub until i knew it was an issue first :)

Re: re-captcha 2 or 3 or question captcha

Posted: 11 Jun 2024, 19:40
by atrol
The name of the folder must be Captcha.

Re: re-captcha 2 or 3 or question captcha

Posted: 11 Jun 2024, 19:51
by durangod
OK cool, thanks i did not take your instructions litterally and i should have.. :)
Copy the Captcha directory into the plugins folder of your installation.
Thanks so much :)

Re: re-captcha 2 or 3 or question captcha

Posted: 13 Jun 2024, 07:54
by durangod
If its ok with you, i would like to make a small mod to the plugin to allow for google captcha. I of course will share everything i change on this posting. :)

Re: re-captcha 2 or 3 or question captcha

Posted: 13 Jun 2024, 08:17
by cas
No problem, this is open source :D .
Why would you like to change?
Anyway please share your solution and I will adjust the plugin to support both methods.

Re: re-captcha 2 or 3 or question captcha

Posted: 13 Jun 2024, 17:43
by durangod
Its just nice to have more than one option. Ok thanks sounds great. :)

Re: re-captcha 2 or 3 or question captcha

Posted: 15 Jun 2024, 16:05
by durangod
The plugin works on signup but not on login, which is ok i like it that way, but i had the impression that this plugin showed it on login too. Its no problem if it does not. :) I can work with it like it is, i was just currious now if i missed something, is it suppose to work on login or just signup?

I have all the config part done for the google recaptcha which shows in the plugin config now with lang values and the values update and work just fine, now i need to work on the user experience to switch between default captcha and recaptcha, working on that today and tomorrow. :) I am also going over the admin guide and the developer guide to assist me with setting global values which i believe start with $g_

I thought alot of the configs were in the db but discovered today they are not, they all seem to be in the default config file or config_inc, is that correct? In other words this signup_use_captcha is only in the default config file and cannot be changed in the admin config, is that correct? If so i may need to add my global config to the default config or the config_inc as well. So i can grab the value from the signon page.

I have two new plugin configs i need to get the value from the users side as globals.

Code: Select all

config_get_string('recaptcha_key');
	         
config_get_string('recaptcha_theme');
dave :)

Re: re-captcha 2 or 3 or question captcha

Posted: 15 Jun 2024, 16:56
by cas
My plugin does not work on signup, only on login :roll: (for signup, Mantis has it's own routine)
As for you required confis, they need to be defined in the config of the plugin.
For now you can add them to config/config_inc.php
but I will transfer them into the plugin.
Just let me know once you are ready to share,

Re: re-captcha 2 or 3 or question captcha

Posted: 15 Jun 2024, 20:16
by durangod
Ok thanks...

I am having an issue with the Content Security Policy, i checked the developer guide but i must be missing something...

here is what i have for that so far (my added code) in Captcha.php file

See anything that pops out of you... ill keep digging..

It does work when i disable the whole CSP but i dont want to do that.

error in console
Content-Security-Policy: The page’s settings blocked an inline script (script-src-elem) from being executed because it violates the following directive: “script-src https://google.com 'self'”


Code: Select all


	function init() {
		plugin_event_hook( 'EVENT_LAYOUT_RESOURCES', 'resources' );
		plugin_event_hook( 'EVENT_AUTH_USER_FLAGS', 'auth_user_flags' );
		
		//dave mod
		plugin_event_hook('EVENT_CORE_HEADERS', 'addPolicy');
	}
	
	function config() {
		return array(
			'lifetime'		   => 20,
			'length'	       => 5,
			'recaptcha_enable' => 0,
			'recaptcha_key'    => '',
			'recaptcha_theme'  => 'light'
			);
	}


   //dave mod
   //add google to content security policy
   function addPolicy()
   {
     http_csp_add('script-src', 'google.com');  
     // i also tried add inline parameter  http_csp_add('script-src', 'google.com', 'inline');
   }
	
		
   # Loading needed styles and javascripts
    function resources() 
    {
       if ( is_page_name( 'plugin.php' ) ) {
            return "<script src='" . plugin_file( 'captcha_script.js' ) . "'></script>";
       }
       
       //dave mod
       if(is_page_name('signup_page.php') || is_page_name('login_page.php'))
       {
        return '<script src="https://www.google.com/recaptcha/api.js" async defer></script>';
       }
    }


Re: re-captcha 2 or 3 or question captcha

Posted: 16 Jun 2024, 08:16
by cas
Have a look @ my Statistics plugin(https://github.com/mantisbt-plugins/Statistics), there i had to do somethuing similar :mrgreen:

Re: re-captcha 2 or 3 or question captcha

Posted: 16 Jun 2024, 10:29
by durangod
Looking now... thanks

At first glance it appears all of your js calls are local so it looks like you were able to download the library and run it locally.

I could do the same i think and just copy the external js file to a local file and run that but here is what it says when i do that,

On the first line of the js code it shows
/* PLEASE DO NOT COPY AND PASTE THIS CODE. */
So not sure i can run it locally but ill try. If i can this also means that i have to update it all the time to get new version unless i run a file get contents on it every time it loads..

Today is outside stuff day, so ill get back to you when i finish reviewing your stats plugin :)

Thanks so much

Dave :)

Re: re-captcha 2 or 3 or question captcha

Posted: 17 Jun 2024, 19:53
by durangod
cas wrote: 16 Jun 2024, 08:16 Have a look @ my Statistics plugin(https://github.com/mantisbt-plugins/Statistics), there i had to do somethuing similar :mrgreen:
I went through the entire statistics plugin files, are you referring to the csp_support.php file ?