diff --git a/CHANGELOG.md b/CHANGELOG.md index e06b886de..26f2bd4f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's fourteen database changes (3.6.6 to 3.8.0) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, and a table and a setting for labor costs, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's fifteen database changes (3.6.6 to 3.8.1) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, and a column on users for API / service accounts, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. ### Security @@ -95,6 +95,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Maintenance > Backup: restore a backup from the page - Restore in a backup's menu, or upload one under Restoring, from another ITFlow say, with its key. An upload of up to 5 GB goes up in pieces, joins the list as Uploaded and opens its Restore window. That window says what's in the backup and refuses one from a newer version, and you confirm with your password and by typing RESTORE. Cron does it within a minute: ITFlow backs itself up first, kept as Before restore so the restore can be undone, then restores the backup and brings its database up to this version. The top of the page shows it waiting (with Cancel), running, and how it went. The command line restore is still under Restoring, for a backup of any size. From Mountaineer IT's build of ITFlow. - Admin > Labor Costs, under Lists: what an hour of each agent costs your company - wage, payroll taxes and benefits - with the date each rate counts from, so a raise doesn't change what last year cost, and a company default for agents with none. Only admins see it, and the audit log never records the amounts. From Mountaineer IT's build of ITFlow. - Reports: Client Profitability, with labor costs set, shows each client's labor cost (their hours at the cost of the agent who worked them), parts cost (the products on their invoices, at cost), profit and margin, and for flat monthly fees the hours a month their fee pays for against the hours they take, marked Over when they take more. The totals along the top add labor, parts, profit, and how many clients lose money or go over. Paid and Invoiced switch income between money received, as before, and sales before tax on invoices dated in the period. Hours by agents with no cost and no default are flagged. From Mountaineer IT's build of ITFlow. +- Users: an API / service account is a login that API keys act as - for your RMM or a sync. Turn on API / service account on a user's Sign in tab (a new one needs Set a password now, as it isn't invited). It keeps its role, so its keys work as before, but it's left out of the calendar, the assign pickers, the reports and the other agent lists, gets no notifications or admin alerts, and can't sign in to ITFlow - a session it has is ended. Admin > Users lists them under API accounts, with an API badge, and leaves them out of the other tabs but Archived. It still takes a seat where there's a limit on agents. From Mountaineer IT's build of ITFlow. ### Bug Fixes @@ -216,6 +217,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Development mode (`functions/dev_mode.php`): `$config_dev_mode` and `$config_dev_mail_to` in config.php - `devModeOn()`, `devModeMailTo()`. `edit_dev_mode` (`admin/post/backup.php`, locked in the demo) writes both with `devModeConfigSet()`, which replaces each line or adds them at the end and invalidates opcache; when config.php can't be written, Admin > Backup shows the lines to add. `sendQueueEmail()` (`cron/mail_queue.php`) sends to `devModeMailTo()` with `[DEV to ]` in front of the subject, and with no test inbox the queue is cancelled as in the demo. `includes/stripe_init.php` calls `devModeBlockStripe()`, a `\Stripe\ApiRequestor::setHttpClient()` client that throws `ApiConnectionException`. `smsSendQueued()` leaves a text queued, `rmmDeviceAct()` refuses, `managedHttpJson()` answers not ok, and `logForwardQueue()` and `logForwardSend()` send nothing. `cron/ticket_email_parser.php`, `ai_triage.php`, `sms_queue.php`, `payment_provider_fees.php`, `manager_checkin.php` and `managed_instances.php` stop with `cronJobStop("Development mode - ...")`; `cron/nightly_tasks.php` skips autopay and telemetry. `includes/top_nav.php` shows `[data-dev-mode]`, a link to `admin/backup.php#dev-mode` for admins. From Mountaineer IT's build of ITFlow. - Restoring from Maintenance > Backup (`functions/backup_restore.php`): `restore_backup` (`admin/post/backup.php`) checks the password and RESTORE, then `backupRestoreQueue()` checks the archive with `backupRestoreCheck()` (`backupInspectArchive()`, refused when its database version is newer) and the disk (three times its size), writes `restore_queued.json` beside the backups - another install's key sealed with this one's (`backupRestoreSealKey()`, AES-256-GCM) - and `restore_status.json`, and sets the Backup job's `cron_job_run_now`. `cron/backup.php` calls `backupRestoreRunQueued()` after the queued backups: it deletes the request first, refuses one older than `BACKUP_RESTORE_WAIT_MINUTES`, makes a Full Backup with source `Before restore`, runs `backupRestoreArchive()`, puts that row and the restored one back in the restored `backups` (others found again by retention), marks `Running` and `Pending` rows `Failed`, runs `scripts/update_cli.php --update_db`, records the outcome and sets `$cron_dispatch_stop_cycle`. `cron/cron.php` exits before its heartbeat while `backupRestoreInProgress()`. `cancel_restore` removes a request. Uploads: `backup_upload` in one request, or `backup_upload_start`, `backup_upload_chunk` and `backup_upload_finish` from `js/backup_restore.js` (JSON, the upload in the session, pieces of `backupRestoreChunkBytes()` appended to `upload_.part`, retried smaller when a proxy refuses), then `backupRestoreAdopt()` lists it with source `Uploaded`. The Restore window is `admin/modals/backup/backup_restore.php`, opened from a row's menu or by `?restore=`; `backupMadeBy()` words a row's source. All locked in the demo. From Mountaineer IT's build of ITFlow. - Database 3.8.0: `user_cost_rates` (`user_cost_rate_user_id`, `_from`, `_hourly`, `_created_by`, `_created_at`, one a day per agent) and `config_labor_cost_default` (NULL leaves time uncosted) - `laborCostReady()`. `functions/labor_cost.php`: `laborCostRates()`, `laborCostRateOn()` (the newest rate on or before the day, the first also before it, else the default), `laborCostRateSave()`, `laborCostRateDelete()`, `laborCostParse()`. `admin/labor_costs.php`, `admin/modals/labor_cost/labor_cost_rates.php` and `labor_cost_default.php`, handlers `add_labor_cost_rate`, `delete_labor_cost_rate` and `edit_labor_cost_default` (`admin/post/labor_cost.php`). `agent/reports/client_profitability.php` calls `laborProfitAdd()` before net - `?basis=invoiced` replaces income with `item_subtotal` less `invoice_discount_amount` on Sent, Viewed, Partial and Paid invoices by `invoice_date`, plus revenue; labor by `ticket_reply_by` and day; parts as `product_cost * item_quantity` - and `laborProfitFinish()` after it for profit, margin, `hours_month` and `break_even`; the columns, totals, basis switch (`laborProfitBasis()`, paid by default) and second stats row are there only with 3.8.0. From Mountaineer IT's build of ITFlow. +- Database 3.8.1: `users.user_service_account` - `serviceAccountsReady()`, `serviceAccountIs()`, `serviceAccountSave()` (`functions/service_account.php`). `serviceAccountsOutSql($column)` adds ` AND user_service_account = 0` to the agent lists and pickers (tickets, recurring tickets, projects, contracts, calendar and events, ticket templates, bulk assign, exports, reports, client onboarding, Quick ticket, mentions, trips, expenses, labor costs, Getting Started's team, user archive's hand-over, incident response) and to `appNotify()`, `signInAdmins()`, `cronHealthRecipients()` and the last-admin checks (`userActiveAdminCount()` in `functions/user.php`, `roles.php`). Not to `apiKeyAgents()`, the API's own checks (`api/v1/enforce_api_rbac.php`) or `getActiveAgentUserCount()`. `login.php` matches agents with `user_service_account = 0`, and `includes/load_user_session.php` ends a service account's session. The switch is `service_account` with `service_account_present` on `admin/modals/user/user_form.php`'s Sign in tab, saved by `add_user` (an invite with it is refused) and `edit_user`. `admin/users.php` adds the `service` view and excludes them from the others but `archived`. From Mountaineer IT's build of ITFlow. ## [26.11.8] diff --git a/admin/database_updates/3.8.1.php b/admin/database_updates/3.8.1.php new file mode 100644 index 000000000..80b1f02ca --- /dev/null +++ b/admin/database_updates/3.8.1.php @@ -0,0 +1,25 @@ + 0; + }; + + if (!$itflow_column('users', 'user_service_account')) { + mysqli_query($mysqli, "ALTER TABLE `users` ADD `user_service_account` tinyint(1) NOT NULL DEFAULT 0 AFTER `user_type`"); + } diff --git a/admin/getting_started/team.php b/admin/getting_started/team.php index dfb55f0e9..6a38f9820 100644 --- a/admin/getting_started/team.php +++ b/admin/getting_started/team.php @@ -12,7 +12,7 @@ defined('FROM_GETTING_STARTED') || die("Direct file access is not allowed"); $gs_agents = mysqli_query($mysqli, "SELECT user_id, user_name, user_email, role_name, role_is_admin FROM users LEFT JOIN user_roles ON role_id = user_role_id - WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC"); + WHERE user_type = 1" . serviceAccountsOutSql() . " AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC"); $gs_roles = userRoles(); // Technician, when there is one - most people added are - or the first role that isn't an admin one $gs_role_default = ''; diff --git a/admin/labor_costs.php b/admin/labor_costs.php index bd3d53e55..3faaf186d 100644 --- a/admin/labor_costs.php +++ b/admin/labor_costs.php @@ -35,7 +35,7 @@ $today = date('Y-m-d'); $search = mb_strtolower(trim(stripslashes((string) ($q ?? '')))); $rows = []; $view_counts = ['' => 0, 'archived' => 0]; -$result = mysqli_query($mysqli, "SELECT user_id, user_name, user_email, user_avatar, user_archived_at FROM users WHERE user_type = 1 +$result = mysqli_query($mysqli, "SELECT user_id, user_name, user_email, user_avatar, user_archived_at FROM users WHERE user_type = 1" . serviceAccountsOutSql() . " AND (user_archived_at IS NULL OR user_id IN (SELECT user_cost_rate_user_id FROM user_cost_rates))"); while ($row = mysqli_fetch_assoc($result)) { if ($search !== '' && mb_strpos(mb_strtolower($row['user_name'] . ' ' . $row['user_email']), $search) === false) { diff --git a/admin/modals/ticket_template/ticket_template_form.php b/admin/modals/ticket_template/ticket_template_form.php index c03d6c668..2239982b9 100644 --- a/admin/modals/ticket_template/ticket_template_form.php +++ b/admin/modals/ticket_template/ticket_template_form.php @@ -129,7 +129,7 @@ $portal_client_ids = !empty($t['ticket_template_id']) ? ticketTemplatePortalClie +
+
+ > + +
+ For a login that API keys act as, for an integration. It keeps its role, so its keys work, but it's left out of the calendar, every assign picker, the reports and the other agent lists, gets no notifications, and can't sign in to ITFlow. + +
+
+
+ + diff --git a/admin/post/users.php b/admin/post/users.php index 91a8a6568..498095dc0 100644 --- a/admin/post/users.php +++ b/admin/post/users.php @@ -46,6 +46,12 @@ if (isset($_POST['add_user'])) { $password = (string) ($_POST['password'] ?? ''); $how = ($_POST['sign_in'] ?? ($password !== '' ? 'password' : 'invite')) === 'invite' && userInvitesReady() ? 'invite' : 'password'; + // An API / service account never signs in, so it has no one to invite (functions/service_account.php) + if ($how === 'invite' && !empty($_POST['service_account']) && serviceAccountsReady()) { + flashAlert("An API / service account isn't invited - choose Set a password now.", 'error'); + redirect(); + } + // An invite waiting for them holds a seat already - it is this one $open = userInviteFor($email); if (agentUserLimitReached($open && userInviteState($open) === 'pending' ? intval($open['invite_id']) : 0)) { @@ -114,7 +120,9 @@ if (isset($_POST['add_user'])) { $notes[] = 'the invite waiting for them is cancelled'; } - logAudit("User", "Create", "$session_name created user " . escapeSql($name), 0, $user_id); + $service_change = serviceAccountSave($user_id, $_POST); + + logAudit("User", "Create", "$session_name created user " . escapeSql($name) . ($service_change !== '' ? ' as an API / service account' : ''), 0, $user_id); flashAlert("User $name created - give them their password yourself" . ($notes ? ' - ' . implode('; ', $notes) : ''), $avatar_error ? 'warning' : 'success'); @@ -228,6 +236,11 @@ if (isset($_POST['edit_user'])) { } } + $service_change = serviceAccountSave($user_id, $_POST); + if ($service_change !== '') { + $changes[] = $service_change; + } + logAudit("User", "Edit", "$session_name edited user " . escapeSql($name) . ($changes ? ' - ' . escapeSql(implode(', ', $changes)) : ''), 0, $user_id); flashAlert("User $name saved" . ($changes ? ' - ' . implode(', ', $changes) : '') . ($avatar_error ? ". $avatar_error" : ''), $avatar_error ? 'warning' : 'success'); @@ -564,7 +577,7 @@ if (isset($_POST['ir_reset_user_password'])) { // Agents only - client portal logins have their own reset, and no vault key to rewrite $reset = []; - $sql_users = mysqli_query($mysqli, "SELECT user_id, user_name, user_email FROM users WHERE user_type = 1 AND user_archived_at IS NULL AND user_id <> $session_user_id ORDER BY user_name"); + $sql_users = mysqli_query($mysqli, "SELECT user_id, user_name, user_email FROM users WHERE user_type = 1" . serviceAccountsOutSql() . " AND user_archived_at IS NULL AND user_id <> $session_user_id ORDER BY user_name"); while ($row = mysqli_fetch_assoc($sql_users)) { $new_password = generateReadablePassword(4); userSetPassword($row['user_id'], $new_password); diff --git a/admin/users.php b/admin/users.php index 7e9c92b9d..4aba827de 100644 --- a/admin/users.php +++ b/admin/users.php @@ -56,6 +56,15 @@ $shows = [ if (!userInvitesReady()) { unset($shows['invited']); } +// API / service accounts (functions/service_account.php) - a view of their own, out of the others but Archived +if (serviceAccountsReady()) { + foreach (['', 'admins', 'nomfa', 'disabled'] as $view_key) { + $shows[$view_key]['where'] .= ' AND user_service_account = 0'; + } + $shows = array_slice($shows, 0, array_search('archived', array_keys($shows), true), true) + + ['service' => ['label' => 'API accounts', 'icon' => 'fa-plug', 'where' => 'user_archived_at IS NULL AND user_service_account = 1', 'title' => 'Logins only for API keys to act as - left out of every agent list, and unable to sign in']] + + $shows; +} $show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : ''; // Client portal - contacts, not agents, so a list of their own: narrowed to a client, and by how they sign in @@ -136,7 +145,7 @@ if ($show === 'portal') { } } else { $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS users.user_id, user_name, user_email, user_status, user_token, user_avatar, user_created_at, user_archived_at, - user_role_id, role_name, role_is_admin, user_config_force_mfa + user_role_id, role_name, role_is_admin, user_config_force_mfa" . (serviceAccountsReady() ? ', user_service_account' : '') . " FROM users $joins WHERE $filters AND {$shows[$show]['where']} ORDER BY {$sortable_columns[$sort]}, users.user_id ASC @@ -361,6 +370,10 @@ $csrf = $_SESSION['csrf_token'];