Limit conference suggest on public page by ip adress

This commit is contained in:
Faustin 2022-11-23 20:26:26 +01:00
parent 7ee47b725b
commit c539ed9f57

View File

@ -359,7 +359,37 @@ if (empty($reshook) && $action == 'add') {
$conforbooth->tms = dol_now();
$conforbooth->firstname = $contact->firstname;
$conforbooth->lastname = $contact->lastname;
$resultconforbooth = $conforbooth->create($user);
$conforbooth->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_confs";
$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
$sql .= " WHERE ip = '".$db->escape($conforbooth->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_confs;
}
}
}
$resultconforbooth = 0;
if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
$error++;
$errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
array_push($conforbooth->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
setEventMessage($errmsg, 'errors');
} else {
$resultconforbooth = $conforbooth->create($user);
}
if ($resultconforbooth<=0) {
$error++;
$errmsg .= $conforbooth->error;