Skip to content

Commit

Permalink
WIP Google captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Nov 6, 2024
1 parent 2775531 commit ac11003
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 52 deletions.
36 changes: 20 additions & 16 deletions htdocs/facturxutil/class/actions_facturx.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ public function doActions($parameters, &$object, &$action, $hookmanager)
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
// Do what you want here...
// You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
}

if (! $error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}

return 0;
}


Expand All @@ -135,16 +137,18 @@ public function doMassActions($parameters, &$object, &$action, $hookmanager)
foreach ($parameters['toselect'] as $objectid) {
// Do action on each object id
}
}

if (! $error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}

return 0;
}


Expand Down
2 changes: 1 addition & 1 deletion htdocs/google/class/actions_google.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function setContentSecurityPolicy($parameters, &$object, &$action, &$hookmanager
{
$tmp = ($hookmanager->resPrint ? $hookmanager->resPrint : $parameters['contentsecuritypolicy']);

// Add google to policies
// Add google to Content-Security-Policy
$tmp = preg_replace('/script-src \'self\'/', 'script-src \'self\' *.googleapis.com *.google.com *.google-analytics.com', $tmp);
$tmp = preg_replace('/font-src \'self\'/', 'font-src \'self\' *.google.com', $tmp);
$tmp = preg_replace('/connect-src \'self\'/', 'connect-src \'self\' *.google.com', $tmp);
Expand Down
4 changes: 3 additions & 1 deletion htdocs/google/core/modules/modGoogle.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function __construct($db)
// Defined if the directory /mymodule/inc/triggers/ contains triggers or not
$this->module_parts = array(
'triggers' => 1,
'hooks' => array('main','agenda','agendalist')
'hooks' => array('main','agenda','agendalist'),
// Set this to 1 if the module provides a captcha driver
'captcha' => 1
);

// Data directories to create when module is enabled
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/* Copyright (C) 2006-2011 Laurent Destailleur <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/

/**
* \file htdocs/core/modules/security/captcha/modCaptchaStandard.class.php
* \ingroup core
* \brief File to manage captcha generation according to dolibarr native code
*/

require_once DOL_DOCUMENT_ROOT.'/core/modules/security/captcha/modules_captcha.php';


/**
* Class to generate a password according to a dolibarr standard rule (12 random chars)
*/
class modCaptchaGoogle extends ModeleCaptcha

Check failure on line 32 in htdocs/google/core/modules/security/captcha/modCaptchaGoogle.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modCaptchaGoogle.class.php: PhanUndeclaredExtendedClass: Class extends undeclared class \ModeleCaptcha
{
/**
* @var string ID
*/
public $id;

public $picto = 'fa-shield-alt';

/**
* Constructor
*
* @param DoliDB $db Database handler
* @param Conf $conf Handler de conf
* @param Translate $langs Handler de langue
* @param User $user Handler du user connected
*/
public function __construct($db, $conf, $langs, $user)
{
$this->id = strtolower(preg_replace('/^modCaptcha/i', '', get_class()));

//$this->picto = 'fab-google';

$this->db = $db;

Check warning on line 55 in htdocs/google/core/modules/security/captcha/modCaptchaGoogle.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modCaptchaGoogle.class.php: PhanUndeclaredProperty: Reference to undeclared property \modCaptchaGoogle-&gt;db (Did you mean $db)
$this->conf = $conf;

Check warning on line 56 in htdocs/google/core/modules/security/captcha/modCaptchaGoogle.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modCaptchaGoogle.class.php: PhanUndeclaredProperty: Reference to undeclared property \modCaptchaGoogle-&gt;conf (Did you mean $conf)
$this->langs = $langs;

Check warning on line 57 in htdocs/google/core/modules/security/captcha/modCaptchaGoogle.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modCaptchaGoogle.class.php: PhanUndeclaredProperty: Reference to undeclared property \modCaptchaGoogle-&gt;langs (Did you mean $langs)
$this->user = $user;

Check warning on line 58 in htdocs/google/core/modules/security/captcha/modCaptchaGoogle.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modCaptchaGoogle.class.php: PhanUndeclaredProperty: Reference to undeclared property \modCaptchaGoogle-&gt;user (Did you mean $user)
}

/**
* Return description of module
*
* @return string Description of module
*/
public function getDescription()
{
global $langs;
return $langs->trans("GoogleCaptchaV3");
}

/**
* Return an example of password generated by this module
*
* @return string Example of password
*/
public function getExample()
{
return '';
}


/**
* Validate a captcha
* This function is called after a log to validate a captcha, before validating a password.
*
* @return int 0 if KO, >0 if OK
*/
public function validateCodeAfterLoginSubmit()
{
return 1;
}
}
36 changes: 20 additions & 16 deletions htdocs/helloasso/class/actions_helloasso.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,18 @@ public function doActions($parameters, &$object, &$action, $hookmanager)
foreach ($parameters['toselect'] as $objectid) {
// Do action on each object id
}
}

if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}

return 0;
}


Expand All @@ -145,16 +147,18 @@ public function doMassActions($parameters, &$object, &$action, $hookmanager)
foreach ($parameters['toselect'] as $objectid) {
// Do action on each object id
}
}

if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
if (!$error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}

return 0;
}

/**
Expand Down
36 changes: 20 additions & 16 deletions htdocs/prestashopget/class/actions_prestashopget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ public function doActions($parameters, &$object, &$action, $hookmanager)
if (in_array($parameters['currentcontext'], array('somecontext1','somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
// Do what you want here...
// You can for example call global vars like $fieldstosearchall to overwrite them, or update database depending on $action and $_POST values.
}

if (! $error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
if (! $error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}

return 0;
}


Expand All @@ -135,16 +137,18 @@ public function doMassActions($parameters, &$object, &$action, $hookmanager)
foreach ($parameters['toselect'] as $objectid) {
// Do action on each object id
}
}

if (! $error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
if (! $error) {
$this->results = array('myreturn' => 999);
$this->resprints = 'A text to show';
return 0; // or return 1 to replace standard code
} else {
$this->errors[] = 'Error message';
return -1;
}
}

return 0;
}


Expand Down
2 changes: 0 additions & 2 deletions htdocs/tawkto/class/actions_tawkto.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class ActionsTawkto
*/
function setContentSecurityPolicy($parameters, &$object, &$action, &$hookmanager)
{
global $conf,$user,$langs;

$tmp = ($hookmanager->resPrint ? $hookmanager->resPrint : $parameters['contentsecuritypolicy']);

$tmp = preg_replace('/script-src \'self\'/', 'script-src \'self\' *.tawk.to *.jsdelivr.net', $tmp);
Expand Down

0 comments on commit ac11003

Please sign in to comment.