diff --git a/agent/ajax.php b/agent/ajax.php index 0b27f9b8..1fae441c 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -49,7 +49,7 @@ if (isset($_GET['merge_ticket_get_json_details'])) { $merge_into_ticket_number = intval(preg_replace('/[^0-9]/', '', $_GET['merge_into_ticket_number'])); $sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_number, ticket_prefix, ticket_subject, ticket_priority, ticket_status, ticket_status_name, client_name, contact_name FROM tickets - LEFT JOIN clients ON ticket_client_id = client_id + LEFT JOIN clients ON ticket_client_id = client_id LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id WHERE ticket_number = $merge_into_ticket_number"); @@ -86,7 +86,7 @@ if (isset($_POST['contact_set_notes'])) { $notes = sanitizeInput($_POST['notes']); // Get Contact Details and Client ID for Logging - $sql = mysqli_query($mysqli,"SELECT contact_name, contact_client_id + $sql = mysqli_query($mysqli,"SELECT contact_name, contact_client_id FROM contacts WHERE contact_id = $contact_id" ); $row = mysqli_fetch_array($sql); @@ -108,7 +108,7 @@ if (isset($_POST['asset_set_notes'])) { $notes = sanitizeInput($_POST['notes']); // Get Asset Details and Client ID for Logging - $sql = mysqli_query($mysqli,"SELECT asset_name, asset_client_id + $sql = mysqli_query($mysqli,"SELECT asset_name, asset_client_id FROM assets WHERE asset_id = $asset_id" ); $row = mysqli_fetch_array($sql); @@ -195,7 +195,7 @@ if (isset($_GET['share_generate_link'])) { $item_expires_friendly = "1 month"; } - $item_key = randomString(156); + $item_key = randomString(32); if ($item_type == "Document") { $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT document_name FROM documents WHERE document_id = $item_id AND document_client_id = $client_id LIMIT 1")); @@ -496,8 +496,8 @@ if (isset($_POST['update_kanban_ticket'])) { if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1) { // Get details - $ticket_sql = mysqli_query($mysqli, "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, ticket_status_name, ticket_assigned_to, ticket_url_key, ticket_client_id FROM tickets - LEFT JOIN clients ON ticket_client_id = client_id + $ticket_sql = mysqli_query($mysqli, "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, ticket_status_name, ticket_assigned_to, ticket_url_key, ticket_client_id FROM tickets + LEFT JOIN clients ON ticket_client_id = client_id LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id WHERE ticket_id = $ticket_id @@ -905,7 +905,7 @@ if (isset($_GET['ai_ticket_summary'])) { } $prompt = " - Summarize the following IT support ticket and its responses in a concise, clear, and professional manner. + Summarize the following IT support ticket and its responses in a concise, clear, and professional manner. The summary should include: 1. Main Issue: What was the problem reported by the user? diff --git a/agent/blank.php b/agent/blank.php index 30e47834..e69de29b 100644 --- a/agent/blank.php +++ b/agent/blank.php @@ -1,72 +0,0 @@ - - - - - - -

Blank Page

-
-

This is a great starting point for new custom pages.

-

- - -$start_date"; - -echo "

User Agent

"; -echo getUserAgent(); - - -?> -
- - - -
- - -
- -
-
Requester
-
Sam Adams
- -
Created
-
- -
Last activity
-
-
- - -
- - - - - -$date_time"; -?> - - - - 0) { @@ -228,7 +228,7 @@ if (isset($_GET['force_recurring_ticket'])) { $client_id = intval($row['recurring_ticket_client_id']); $asset_id = intval($row['recurring_ticket_asset_id']); $category = intval($row['recurring_ticket_category']); - $url_key = randomString(156); + $url_key = randomString(32); $ticket_status = 1; // Default if ($assigned_id > 0) { diff --git a/agent/post/ticket.php b/agent/post/ticket.php index 287a1055..48d6b0d7 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -68,7 +68,7 @@ if (isset($_POST['add_ticket'])) { $config_base_url = sanitizeInput($config_base_url); //Generate a unique URL key for clients to access - $url_key = randomString(156); + $url_key = randomString(32); mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_source = 'Agent', ticket_category = $category_id, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_billable = '$billable', ticket_status = '$ticket_status', ticket_vendor_ticket_number = '$vendor_ticket_number', ticket_vendor_id = $vendor_id, ticket_location_id = $location_id, ticket_asset_id = $asset_id, ticket_created_by = $session_user_id, ticket_assigned_to = $assigned_to, ticket_contact_id = $contact, ticket_url_key = '$url_key', ticket_due_at = $due, ticket_client_id = $client_id, ticket_invoice_id = 0, ticket_project_id = $project_id"); @@ -1521,7 +1521,7 @@ if (isset($_POST['bulk_add_asset_ticket'])) { $config_base_url = sanitizeInput($config_base_url); //Generate a unique URL key for clients to access - $url_key = randomString(156); + $url_key = randomString(32); mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_category = $category_id, ticket_subject = '$subject_asset_prepended', ticket_details = '$details', ticket_priority = '$priority', ticket_billable = $billable, ticket_status = $ticket_status, ticket_asset_id = $asset_id, ticket_created_by = $session_user_id, ticket_assigned_to = $assigned_to, ticket_url_key = '$url_key', ticket_client_id = $client_id, ticket_project_id = $project_id"); @@ -2167,7 +2167,7 @@ if (isset($_POST['add_invoice_from_ticket'])) { $invoice_number = mysqli_insert_id($mysqli); //Generate a unique URL key for clients to access - $url_key = randomString(156); + $url_key = randomString(32); mysqli_query($mysqli, "INSERT INTO invoices SET invoice_prefix = '$config_invoice_prefix', invoice_number = $invoice_number, invoice_scope = '$scope', invoice_date = '$date', invoice_due = DATE_ADD('$date', INTERVAL $client_net_terms day), invoice_currency_code = '$session_company_currency', invoice_category_id = $category, invoice_status = 'Draft', invoice_url_key = '$url_key', invoice_client_id = $client_id"); $invoice_id = mysqli_insert_id($mysqli); diff --git a/agent/user/post/profile.php b/agent/user/post/profile.php index ab781f7b..73827cd0 100644 --- a/agent/user/post/profile.php +++ b/agent/user/post/profile.php @@ -88,7 +88,7 @@ if (isset($_POST['edit_your_user_details'])) { } if (isset($_GET['clear_your_user_avatar'])) { - + validateCSRFToken($_GET['csrf_token']); mysqli_query($mysqli,"UPDATE users SET user_avatar = NULL WHERE user_id = $session_user_id"); @@ -96,7 +96,7 @@ if (isset($_GET['clear_your_user_avatar'])) { logAction("User Account", "Edit", "$session_name cleared their avatar"); flash_alert("Avatar cleared", 'error'); - + redirect(); } @@ -167,7 +167,7 @@ if (isset($_POST['edit_your_user_preferences'])) { // Enable extension access, only if it isn't already setup (user doesn't have cookie) if (isset($_POST['extension']) && $_POST['extension'] == 'Yes') { if (!isset($_COOKIE['user_extension_key'])) { - $extension_key = randomString(156); + $extension_key = randomString(32); mysqli_query($mysqli, "UPDATE users SET user_extension_key = '$extension_key' WHERE user_id = $session_user_id"); $extended_log_description .= "enabled browser extension access"; @@ -196,7 +196,7 @@ if (isset($_POST['enable_mfa'])) { require_once "../../plugins/totp/totp.php"; // Grab the code from the user - $verify_code = trim($_POST['verify_code']); + $verify_code = trim($_POST['verify_code']); // Ensure it's numeric if (!ctype_digit($verify_code)) { $verify_code = ''; @@ -227,9 +227,9 @@ if (isset($_POST['enable_mfa'])) { if ($previousPage === 'mfa_enforcement.php') { // Redirect back to mfa_enforcement.php redirect("../$config_start_page"); - + } - } + } } else { // FAILURE @@ -245,7 +245,7 @@ if (isset($_POST['enable_mfa'])) { // Redirect back to mfa_enforcement.php redirect(); } - } + } } redirect("user_security.php"); diff --git a/api/v1/tickets/create.php b/api/v1/tickets/create.php index 41ad29c8..9339003b 100644 --- a/api/v1/tickets/create.php +++ b/api/v1/tickets/create.php @@ -44,7 +44,7 @@ if (!empty($subject)) { $ticket_number = mysqli_insert_id($mysqli); // Insert ticket - $url_key = randomString(156); + $url_key = randomString(32); $insert_sql = mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_source = 'API', ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 1, ticket_billable = $billable, ticket_vendor_ticket_number = '$vendor_ticket_number', ticket_vendor_id = $vendor_id, ticket_created_by = 0, ticket_assigned_to = $assigned_to, ticket_contact_id = $contact, ticket_asset_id = $asset, ticket_url_key = '$url_key', ticket_client_id = $client_id"); // Check insert & get insert ID diff --git a/client/login_reset.php b/client/login_reset.php index 826cb040..e6133456 100644 --- a/client/login_reset.php +++ b/client/login_reset.php @@ -72,7 +72,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { $name = sanitizeInput($row['contact_name']); $client = intval($row['contact_client_id']); - $token = randomString(156); + $token = randomString(32); $url = "https://$config_base_url/client/login_reset.php?email=$email&token=$token&client=$client"; mysqli_query($mysqli, "UPDATE users SET user_password_reset_token = '$token' WHERE user_id = $user_id LIMIT 1"); mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Modify', log_description = 'Sent a portal password reset e-mail for $email.', log_ip = '$ip', log_user_agent = '$user_agent', log_client_id = $client"); diff --git a/client/post.php b/client/post.php index 7c7f25fc..39a6a7d2 100644 --- a/client/post.php +++ b/client/post.php @@ -25,7 +25,7 @@ if (isset($_POST['add_ticket'])) { $config_ticket_new_ticket_notification_email = filter_var($config_ticket_new_ticket_notification_email, FILTER_VALIDATE_EMAIL); //Generate a unique URL key for clients to access - $url_key = randomString(156); + $url_key = randomString(32); // Ensure priority is low/med/high (as can be user defined) if ($_POST['priority'] !== "Low" && $_POST['priority'] !== "Medium" && $_POST['priority'] !== "High") { diff --git a/cron/cron.php b/cron/cron.php index b3835c75..f21b180d 100644 --- a/cron/cron.php +++ b/cron/cron.php @@ -615,7 +615,7 @@ while ($row = mysqli_fetch_array($sql_recurring_invoices)) { $new_invoice_number = mysqli_insert_id($mysqli); //Generate a unique URL key for clients to access - $url_key = randomString(156); + $url_key = randomString(32); mysqli_query($mysqli, "INSERT INTO invoices SET invoice_prefix = '$config_invoice_prefix', invoice_number = $new_invoice_number, invoice_scope = '$recurring_invoice_scope', invoice_date = CURDATE(), invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), invoice_discount_amount = $recurring_invoice_discount_amount, invoice_amount = $recurring_invoice_amount, invoice_currency_code = '$recurring_invoice_currency_code', invoice_note = '$recurring_invoice_note', invoice_category_id = $category_id, invoice_status = 'Sent', invoice_url_key = '$url_key', invoice_recurring_invoice_id = $recurring_invoice_id, invoice_client_id = $client_id"); diff --git a/cron/ticket_email_parser.php b/cron/ticket_email_parser.php index 163e703b..00047104 100644 --- a/cron/ticket_email_parser.php +++ b/cron/ticket_email_parser.php @@ -106,7 +106,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date $contact_email_esc = mysqli_real_escape_string($mysqli, $contact_email); $client_id = intval($client_id); - $url_key = randomString(156); + $url_key = randomString(32); mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$ticket_prefix_esc', ticket_number = $ticket_number, ticket_source = 'Email', ticket_subject = '$subject', ticket_details = '$message_esc', ticket_priority = 'Low', ticket_status = 1, ticket_billable = $config_ticket_default_billable, ticket_created_by = 0, ticket_contact_id = $contact_id, ticket_url_key = '$url_key', ticket_client_id = $client_id"); $id = mysqli_insert_id($mysqli); diff --git a/functions.php b/functions.php index 94f35602..f6db0db6 100644 --- a/functions.php +++ b/functions.php @@ -4,20 +4,13 @@ DEFINE("WORDING_ROLECHECK_FAILED", "You are not permitted to do that!"); // Function to generate both crypto & URL safe random strings -function randomString($length = 16) { - // Generate some cryptographically safe random bytes - // Generate a little more than requested as we'll lose some later converting - $random_bytes = random_bytes($length + 5); - - // Convert the bytes to something somewhat human-readable - $random_base_64 = base64_encode($random_bytes); - - // Replace the nasty characters that come with base64 - $bad_chars = array("/", "+", "="); - $random_string = str_replace($bad_chars, random_int(0, 9), $random_base_64); - - // Truncate the string to the requested $length and return - return substr($random_string, 0, $length); +function randomString(int $length = 16): string { + $bytes = random_bytes((int) ceil($length * 3 / 4)); + return substr( + rtrim(strtr(base64_encode($bytes), '+/', '-_'), '='), + 0, + $length + ); } // Older keygen function - only used for TOTP currently diff --git a/login.php b/login.php index 7e69045a..a1d6a2bb 100644 --- a/login.php +++ b/login.php @@ -346,7 +346,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && (isset($_POST['login']) || isset($_ // Session info $_SESSION['user_id'] = $user_id; - $_SESSION['csrf_token'] = randomString(156); + $_SESSION['csrf_token'] = randomString(32); $_SESSION['logged'] = true; // Forcing MFA