Update create_ticket.php

This commit is contained in:
Laurent Destailleur 2022-09-13 02:21:24 +02:00 committed by GitHub
parent c6144df397
commit 7c92a45cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,29 +232,34 @@ if (empty($reshook)) {
} }
if (!$error) { if (!$error) {
$object->db->begin();
$object->type_code = GETPOST("type_code", 'aZ09'); $object->type_code = GETPOST("type_code", 'aZ09');
$object->category_code = GETPOST("category_code", 'aZ09'); $object->category_code = GETPOST("category_code", 'aZ09');
$object->severity_code = GETPOST("severity_code", 'aZ09'); $object->severity_code = GETPOST("severity_code", 'aZ09');
$object->ip = getUserRemoteIP(); $object->ip = getUserRemoteIP();
$sql = "SELECT COUNT(ref) as nb_tickets"; $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 1000);
$sql .= " FROM ".MAIN_DB_PREFIX."ticket";
$sql .= " WHERE ip = '".$db->escape($object->ip)."'"; // Calculate nb of post for IP
$resql = $db->query($sql); $nb_post_ip = 0;
if ($resql) { if ($nb_post_max > 0) { // Calculate only if there is a limit to check
$num = $db->num_rows($resql); $sql = "SELECT COUNT(ref) as nb_tickets";
$i = 0; $sql .= " FROM ".MAIN_DB_PREFIX."ticket";
while ($i < $num) { $sql .= " WHERE ip = '".$db->escape($object->ip)."'";
$i++; $resql = $db->query($sql);
$obj = $db->fetch_object($resql); if ($resql) {
$nb_post_ip = $obj->nb_tickets; $num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$i++;
$obj = $db->fetch_object($resql);
$nb_post_ip = $obj->nb_tickets;
}
} }
} }
$object->track_id = generate_random_id(16); $object->track_id = generate_random_id(16);
$object->db->begin();
$object->subject = GETPOST("subject", "restricthtml"); $object->subject = GETPOST("subject", "restricthtml");
$object->message = GETPOST("message", "restricthtml"); $object->message = GETPOST("message", "restricthtml");
@ -321,7 +326,7 @@ if (empty($reshook)) {
$object->context['disableticketemail'] = 1; // Disable emails sent by ticket trigger when creation is done from this page, emails are already sent later $object->context['disableticketemail'] = 1; // Disable emails sent by ticket trigger when creation is done from this page, emails are already sent later
if ($nb_post_ip >= getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 1000)) { if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
$error++; $error++;
$errors = array($langs->trans("AlreadyTooMuchPostOnThisIPAdress")); $errors = array($langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
array_push($object->errors, array($langs->trans("AlreadyTooMuchPostOnThisIPAdress"))); array_push($object->errors, array($langs->trans("AlreadyTooMuchPostOnThisIPAdress")));