Limit partnership creation on public page by ip adress

This commit is contained in:
Faustin 2022-11-23 13:41:02 +01:00
parent 8f196c1214
commit 1b5bbf72fc
4 changed files with 38 additions and 6 deletions

View File

@ -244,6 +244,7 @@ ErrorObjectMustHaveStatusActiveToBeDisabled=Objects must have status 'Active' to
ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated=Objects must have status 'Draft' or 'Disabled' to be enabled ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated=Objects must have status 'Draft' or 'Disabled' to be enabled
ErrorNoFieldWithAttributeShowoncombobox=No fields has property 'showoncombobox' into definition of object '%s'. No way to show the combolist. ErrorNoFieldWithAttributeShowoncombobox=No fields has property 'showoncombobox' into definition of object '%s'. No way to show the combolist.
ErrorFieldRequiredForProduct=Field '%s' is required for product %s ErrorFieldRequiredForProduct=Field '%s' is required for product %s
AlreadyTooMuchPostOnThisIPAdress=You have already posted too much on this IP address.
ProblemIsInSetupOfTerminal=Problem is in setup of terminal %s. ProblemIsInSetupOfTerminal=Problem is in setup of terminal %s.
ErrorAddAtLeastOneLineFirst=Add at least one line first ErrorAddAtLeastOneLineFirst=Add at least one line first
ErrorRecordAlreadyInAccountingDeletionNotPossible=Error, record is already transferred in accounting, deletion is not possible. ErrorRecordAlreadyInAccountingDeletionNotPossible=Error, record is already transferred in accounting, deletion is not possible.

View File

@ -45,6 +45,7 @@ NoError=Aucune erreur
Error=Erreur Error=Erreur
Errors=Erreurs Errors=Erreurs
ErrorFieldRequired=Le champ '%s' est obligatoire ErrorFieldRequired=Le champ '%s' est obligatoire
AlreadyTooMuchPostOnThisIPAdress=Vous avez déjà posté trop de messages depuis cette adresse IP.
ErrorFieldFormat=Le champ '%s' a une valeur incorrecte ErrorFieldFormat=Le champ '%s' a une valeur incorrecte
ErrorFileDoesNotExists=Le fichier %s n'existe pas ErrorFileDoesNotExists=Le fichier %s n'existe pas
ErrorFailedToOpenFile=Impossible d'ouvrir le fichier %s ErrorFailedToOpenFile=Impossible d'ouvrir le fichier %s

View File

@ -22,6 +22,8 @@
* \brief This file is a CRUD class file for Partnership (Create/Read/Update/Delete) * \brief This file is a CRUD class file for Partnership (Create/Read/Update/Delete)
*/ */
use Illuminate\Support\Arr;
// Put here all includes required by your class file // Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
@ -124,6 +126,7 @@ class Partnership extends CommonObject
'last_check_backlink' => array('type'=>'datetime', 'label'=>'LastCheckBacklink', 'enabled'=>'1', 'position'=>72, 'notnull'=>0, 'visible'=>-2,), 'last_check_backlink' => array('type'=>'datetime', 'label'=>'LastCheckBacklink', 'enabled'=>'1', 'position'=>72, 'notnull'=>0, 'visible'=>-2,),
'reason_decline_or_cancel' => array('type'=>'text', 'label'=>'ReasonDeclineOrCancel', 'enabled'=>'1', 'position'=>73, 'notnull'=>0, 'visible'=>-2,), 'reason_decline_or_cancel' => array('type'=>'text', 'label'=>'ReasonDeclineOrCancel', 'enabled'=>'1', 'position'=>73, 'notnull'=>0, 'visible'=>-2,),
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'picto'=>'company', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150',), 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'picto'=>'company', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'css'=>'maxwidth500', 'csslist'=>'tdoverflowmax150',),
'ip' => array('type'=>'varchar(250)', 'label'=>'Ip', 'enabled'=>'1', 'position'=>74, 'notnull'=>0, 'visible'=>-2,),
); );
public $rowid; public $rowid;
public $ref; public $ref;

View File

@ -223,7 +223,27 @@ if (empty($reshook) && $action == 'add') {
$partnership->fk_user_creat = 0; $partnership->fk_user_creat = 0;
$partnership->fk_type = GETPOST('partnershiptype', 'int'); $partnership->fk_type = GETPOST('partnershiptype', 'int');
//$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int'); //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int');
$partnership->ip = getUserRemoteIP();
$nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 1000);
// Calculate nb of post for IP
$nb_post_ip = 0;
if ($nb_post_max > 0) { // Calculate only if there is a limit to check
$sql = "SELECT COUNT(ref) as nb_partnerships";
$sql .= " FROM ".MAIN_DB_PREFIX."partnership";
$sql .= " WHERE ip = '".$db->escape($partnership->ip)."'";
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$i++;
$obj = $db->fetch_object($resql);
$nb_post_ip = $obj->nb_partnerships;
}
}
}
// test if societe already exist // test if societe already exist
$company = new Societe($db); $company = new Societe($db);
$result = $company->fetch(0, GETPOST('societe')); $result = $company->fetch(0, GETPOST('societe'));
@ -290,6 +310,11 @@ if (empty($reshook) && $action == 'add') {
$error++; $error++;
} }
if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
$error++;
$errmsg = $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
array_push($partnership->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
}
if (!$error) { if (!$error) {
$result = $partnership->create($user); $result = $partnership->create($user);
if ($result > 0) { if ($result > 0) {
@ -464,6 +489,8 @@ if (empty($reshook) && $action == 'add') {
$error++; $error++;
$errmsg .= join('<br>', $partnership->errors); $errmsg .= join('<br>', $partnership->errors);
} }
} else {
setEventMessage($errmsg, 'errors');
} }
} }