From 19c09b670c96f115cda773293334814573c1801d Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 1 Dec 2026 18:40:48 -0500 Subject: [PATCH] Texts: tick texts and use Bulk Action to dismiss or mark as spam in Unmatched, clear in Codes, or say not spam or delete in Spam, or empty a tab with Dismiss All, Clear All or Delete All, which ask with the count and are hidden while searching - clearing a code wipes it and its words at once and works on one code from its menu too, the Codes list waits to refresh while codes are ticked, and each needs the permission the single action does and stays within the agent's clients (smsInboxBulk() in functions/sms.php); 26.12.4 changelog --- CHANGELOG.md | 5 +++ agent/post/texts.php | 66 +++++++++++++++++++++++++++- agent/texts.php | 101 ++++++++++++++++++++++++++++++++++++++----- functions/sms.php | 67 ++++++++++++++++++++++++++++ 4 files changed, 226 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2dae283f..31c949327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This file documents all notable changes made to ITFlow. Update from Maintenance > Update as usual. There are no database changes. +### New Features & Updates + +- Texts: tick texts and use Bulk Action - dismiss or mark as spam in Unmatched, clear in Codes, Not Spam or delete in Spam - or empty a tab with Dismiss All, Clear All or Delete All, which say how many first. A code can also be cleared on its own, which wipes it and its words straight away. While codes are ticked, the Codes list waits to refresh so they stay ticked. + ### Bug Fixes - Two-step sign-in no longer says "Your MFA session expired" right after the code is typed. The code boxes send the code on its sixth digit, so pressing Enter out of habit - or a password manager or phone keyboard sending it too, or a double click on Verify & Sign In - sent it a second time, and that second copy signed you out. Each form on the sign-in page now goes once, a second copy that still gets through takes you into ITFlow, and a wrong code sent twice says the code is wrong. @@ -19,6 +23,7 @@ Update from Maintenance > Update as usual. There are no database changes. - `signInNewSession()` in `functions/sign_in.php` replaces `session_regenerate_id(true)` at both sign-ins in `login.php`. After the role choice, the code or a passkey, the old session id is kept for `SIGN_IN_MOVED_SECONDS` (60) holding only the new id and a SHA-256 of that step's pending token; `signInMovedSession()` takes a request with the old id and the same token on to the signed-in session and sends its cookie, so a second copy of the form posted before the first answer came back isn't left with an empty session. An id planted before the sign-in has no token and gets nothing. A password-only or provider sign-in renews the id as before. - `login.php`: the role, code and passkey steps call `signInMovedOn()` when their pending sign-in is gone - into the app for a second copy or a browser already signed in, otherwise "expired" as before. The code step is recognized by `pending_mfa_token` as well as the `mfa_login` button, a retried code keeps its pending token, and `SIGN_IN_CODE_SECONDS` (300) is the code step's window. - `js/login_prevent_resubmit.js` lets each form on the sign-in page submit once (until the page comes back from history, or 10 seconds), and `js/otp_input.js` does the same for any form with a `data-otp-submit` code field - turning on MFA, the client portal's two-step setup and shared-link codes. +- Texts: `smsInboxBulk($action, $ids, $user_id)` in `functions/sms.php` runs an action from `SMS_INBOX_BULK` (dismiss, spam, clear, not_spam, delete => the status it takes texts from and the permission it needs) on the ticked inbound texts, or with `$ids` null on the whole tab, inside `clientScopeSql()`. Spam and not spam block or unblock the numbers and move every text from them, as the single actions do. Clearing a code sets it to dismissed with its body, code and media wiped, so the text log's search can't find its words. `agent/post/texts.php` takes `bulk_texts` (with `sms_message_ids[]`) and `bulk_texts_all`, plus `sms_clear_code` for one code. `agent/texts.php` uses the standard `js/bulk_actions.js` select-all and Bulk Action button. ## [26.12.3] diff --git a/agent/post/texts.php b/agent/post/texts.php index 41b490b77..c96e006a0 100644 --- a/agent/post/texts.php +++ b/agent/post/texts.php @@ -2,7 +2,8 @@ /* * Texts (agent/texts.php) - open a ticket from an unmatched text, dismiss one, mark one spam - * (which blocks its number) or not, say a code isn't one, name a number, and delete spam + * (which blocks its number) or not, say a code isn't one, name a number, and delete spam - + * and dismiss, mark spam, clear codes, say not spam or delete many at once, or a whole tab * (functions/sms.php). */ @@ -163,6 +164,69 @@ if (isset($_GET['sms_delete'])) { } +// Many texts at once - the ticked ones, or with bulk_texts_all every one in the tab (smsInboxBulk()) +if (isset($_POST['bulk_texts']) || isset($_POST['bulk_texts_all'])) { + + validateCSRFToken(); + + $all = isset($_POST['bulk_texts_all']); + $action = (string) ($all ? $_POST['bulk_texts_all'] : $_POST['bulk_texts']); + if (!isset(SMS_INBOX_BULK[$action])) { + flashAlert('That isn\'t something Texts can do.', 'error'); + redirect('texts.php'); + } + enforceUserPermission(SMS_INBOX_BULK[$action][1], 2); + + $ids = $all ? null : (array) ($_POST['sms_message_ids'] ?? []); + if (!$all && !$ids) { + flashAlert('Tick the texts first', 'error'); + redirect(); + } + + $done = smsInboxBulk($action, $ids, intval($session_user_id)); + $texts = $done['texts']; + $numbers = $done['numbers']; + if (!$texts) { + flashAlert('Nothing changed - those texts have moved on, someone may have dealt with them already.', 'error'); + redirect(); + } + $s = $texts === 1 ? '' : 's'; + $ns = $numbers === 1 ? '' : 's'; + + if ($action === 'dismiss') { + logAudit("Text Message", "Edit", "$session_name dismissed $texts text$s"); + flashAlert("$texts text$s dismissed - kept in the text log for " . SMS_SPAM_KEEP_DAYS . " days"); + } elseif ($action === 'clear') { + logAudit("Text Message", "Edit", "$session_name cleared $texts code$s from Texts, wiping them"); + flashAlert("$texts code$s cleared"); + } elseif ($action === 'delete') { + logAudit("Text Message", "Delete", "$session_name deleted $texts spam text$s"); + flashAlert("$texts spam text$s deleted", 'error'); + } elseif ($action === 'spam') { + logAudit("Text Message", "Edit", "$session_name marked texts from $numbers number$ns as spam and blocked them"); + flashAlert("$numbers number$ns blocked - $texts text$s moved to Spam, and what they send goes straight there"); + } else { + logAudit("Text Message", "Edit", "$session_name said texts from $numbers number$ns aren't spam and unblocked them"); + flashAlert("$numbers number$ns unblocked - $texts text$s moved to Unmatched"); + } + redirect(); + +} + +// One code cleared - its words and code wiped now, and out of Codes (smsInboxBulk()) +if (isset($_GET['sms_clear_code'])) { + + validateCSRFToken(); + enforceUserPermission('module_credential', 2); + + $row = textsForRequest($_GET['sms_clear_code'], ['code']); + smsInboxBulk('clear', [intval($row['sms_message_id'])], intval($session_user_id)); + logAudit("Text Message", "Edit", "$session_name cleared a code from " . escapeSql(smsNumberText($row['sms_message_number'])) . " from Texts, wiping it"); + flashAlert('Code cleared'); + redirect(); + +} + if (isset($_GET['sms_not_code'])) { validateCSRFToken(); diff --git a/agent/texts.php b/agent/texts.php index b8fc3d443..e6e30f311 100644 --- a/agent/texts.php +++ b/agent/texts.php @@ -8,7 +8,8 @@ * revealed one at a time (each reveal in the audit log) for SMS_CODE_MASK_MINUTES after * it came, and its words wiped after SMS_CODE_KEEP_HOURS * Spam - blocked numbers and what looks like bait, deleted after SMS_SPAM_KEEP_DAYS - * Texts from contacts, and on tickets, go on their tickets and never wait here. The actions + * Texts from contacts, and on tickets, go on their tickets and never wait here. Ticked texts, + * or a whole tab, can be dismissed, cleared or deleted at once (smsInboxBulk()). The actions * are agent/post/texts.php; revealing a code is ajax.php?sms_reveal_code. */ @@ -46,6 +47,15 @@ if (!isset($tabs[$show])) { $codes = $show === 'codes'; $can_work = lookupUserPermission('module_support') >= 2; $can_codes = lookupUserPermission('module_credential') >= 1; +$can_clear_codes = lookupUserPermission('module_credential') >= 2; +// Ticking texts, and the tab's All button: what it does, its label, icon and look, and what it asks first +$can_bulk = $codes ? $can_clear_codes : $can_work; +$searching = trim((string) ($_GET['q'] ?? '')) !== ''; +$all_action = [ + 'unmatched' => ['dismiss', 'Dismiss All', 'fa-check-double', 'btn-outline-secondary', 'Dismiss all %d unmatched texts?', 'They leave Texts and stay in the text log for ' . SMS_SPAM_KEEP_DAYS . ' days. No number is blocked.'], + 'codes' => ['clear', 'Clear All', 'fa-broom', 'btn-outline-secondary', 'Clear all %d codes?', 'Their words and codes are wiped now - ones that could still be revealed too.'], + 'spam' => ['delete', 'Delete All', 'fa-trash-alt', 'btn-outline-danger', 'Delete all %d spam texts?', 'They are gone for good. Their numbers stay blocked.'], +][$show]; // Only these sort - an unknown column would take the page down $sortable_columns = [ @@ -100,14 +110,52 @@ $provider = smsProvider(); -
- - A code can be revealed for minutes after it came - each reveal is in the audit log - and its words are wiped after a day. - - Texts from numbers that aren't a contact's. Texts from your contacts go on their tickets. - - From blocked numbers, or what looks like bait. Deleted after days. - +
+
+ + + + + + +
@@ -119,13 +167,25 @@ $provider = smsProvider(); +
+ A code can be revealed for minutes after it came - each reveal is in the audit log - and its words are wiped after a day.Texts from numbers that aren't a contact's. Texts from your contacts go on their tickets.From blocked numbers, or what looks like bait. Deleted after days. +
+
+
"> - + + + + @@ -143,7 +203,14 @@ $provider = smsProvider(); $fresh = $codes && smsCodeFresh($row); ?> - + +
+
+ +
+
Code Text
+ + +
+ +
+
@@ -199,6 +266,12 @@ $provider = smsProvider(); data-confirm-title="Not a code?" data-confirm-button="Move to Unmatched" data-confirm-text="It moves to Unmatched, where everyone who works tickets sees its words.">Not a Code + + + Clear + Not Spam @@ -213,6 +286,7 @@ $provider = smsProvider();
+
'texts', @@ -272,7 +346,8 @@ $provider = smsProvider(); fetch('ajax.php?sms_latest_code', { credentials: 'same-origin' }) .then(function (response) { return response.json(); }) .then(function (answer) { - if (answer.latest && answer.latest > latest) { + // Not while texts are ticked - the reload would untick them + if (answer.latest && answer.latest > latest && !document.querySelector('.bulk-select:checked')) { window.location.reload(); } }) @@ -282,5 +357,7 @@ $provider = smsProvider(); + + the tab's status it takes them from, and the permission it needs */ +const SMS_INBOX_BULK = [ + 'dismiss' => ['unmatched', 'module_support'], + 'spam' => ['unmatched', 'module_support'], + 'clear' => ['code', 'module_credential'], + 'not_spam' => ['spam', 'module_support'], + 'delete' => ['spam', 'module_support'], +]; + +/* + * Texts (agent/post/texts.php) on many texts at once: $action (SMS_INBOX_BULK) on the inbound texts + * $ids, or with $ids null on every one in its tab - only those the agent's clients allow, and still + * where the action takes them from. Dismiss leaves them in the text log for SMS_SPAM_KEEP_DAYS; + * clearing codes wipes their words and codes now, as a day would, and they go the same way; spam + * blocks the numbers, and not spam unblocks them, moving every text from them as one does; delete + * is spam gone for good. ['texts' => how many texts changed, 'numbers' => how many numbers]. + */ +function smsInboxBulk(string $action, ?array $ids, int $user_id): array +{ + global $mysqli; + $none = ['texts' => 0, 'numbers' => 0]; + if (!isset(SMS_INBOX_BULK[$action])) { + return $none; + } + $status = SMS_INBOX_BULK[$action][0]; + if ($ids !== null) { + $ids = array_values(array_unique(array_filter(array_map('intval', $ids)))); + if (!$ids) { + return $none; + } + } + $rows = mysqli_fetch_all(mysqli_query($mysqli, "SELECT sms_message_id, sms_message_number FROM sms_messages + WHERE sms_message_direction = 'in' AND sms_message_status = '$status' " . clientScopeSql('sms_message_client_id') + . ($ids !== null ? " AND sms_message_id IN (" . implode(',', $ids) . ")" : '')), MYSQLI_ASSOC); + if (!$rows) { + return $none; + } + $in = implode(',', array_map('intval', array_column($rows, 'sms_message_id'))); + $numbers = array_values(array_unique(array_map('strval', array_column($rows, 'sms_message_number')))); + $numbers_in = implode(',', array_map(function ($number) { + return "'" . escapeSql($number) . "'"; + }, $numbers)); + $handled = "sms_message_handled_at = NOW(), sms_message_handled_by = " . intval($user_id); + + if ($action === 'dismiss') { + mysqli_query($mysqli, "UPDATE sms_messages SET sms_message_status = 'dismissed', $handled WHERE sms_message_id IN ($in)"); + } elseif ($action === 'clear') { + mysqli_query($mysqli, "UPDATE sms_messages SET sms_message_status = 'dismissed', sms_message_body = NULL, sms_message_code = NULL, sms_message_media = NULL, + sms_message_error = 'A verification code - cleared from Texts', $handled WHERE sms_message_id IN ($in)"); + } elseif ($action === 'delete') { + mysqli_query($mysqli, "DELETE FROM sms_messages WHERE sms_message_id IN ($in)"); + } elseif ($action === 'spam') { + foreach ($numbers as $number) { + smsNumberSet($number, ['blocked_at' => 'NOW()', 'blocked_by' => intval($user_id)]); + } + mysqli_query($mysqli, "UPDATE sms_messages SET sms_message_status = 'spam', $handled + WHERE sms_message_direction = 'in' AND sms_message_number IN ($numbers_in) AND sms_message_status IN ('unmatched', 'dismissed')"); + } else { + foreach ($numbers as $number) { + smsNumberSet($number, ['blocked_at' => null, 'blocked_by' => 0]); + } + mysqli_query($mysqli, "UPDATE sms_messages SET sms_message_status = 'unmatched', sms_message_handled_at = NULL, sms_message_handled_by = 0 + WHERE sms_message_direction = 'in' AND sms_message_number IN ($numbers_in) AND sms_message_status = 'spam'"); + } + return ['texts' => max(0, mysqli_affected_rows($mysqli)), 'numbers' => count($numbers)]; +} + /* Whether a code can still be revealed - SMS_CODE_MASK_MINUTES after it came, and while it's kept */ function smsCodeFresh(array $row): bool {