diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6024376e2..16c84a186 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. There are no database changes, and nothing else is required. This release has three security fixes - see Security.
+Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's one database change (3.6.6 to 3.6.7) in the same pass. It adds three tables for RMM providers and changes nothing that is there. Nothing else is required. This release has three security fixes - see Security.
### Security
@@ -14,8 +14,23 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Invites: with a login key required, the page behind an agent's invite link went on showing the sign-in address with the key in it after the invite had been cancelled or had run out. Someone whose invite was withdrawn could still read the key from their old link. The key signs no one in by itself - it only opens the agents' sign-in page, which still asks for an email and password. A cancelled or run-out link now leads to the plain sign-in page. Releases from 26.11 to 26.11.8 are affected. If you cancelled an invite because the person should never have had it, change the login key in Admin > Settings > Security.
- Client access: an agent limited to some clients could read a few names belonging to the others, by putting a record's number in a page's address - a project's name on the tickets list, a site's name, a ticket's subject and an invoice's number on Trips and its export window, a vendor's name in the domains export window, and a client's name on Update Prices and in the message when an AI request was turned away. Nothing else of those records showed, and nothing could be changed. These names now show only for clients the agent can open. Releases from 26.09 to 26.11.8 are affected.
+### New Features & Updates
+
+- RMM Providers: Admin > Integrations > RMM Providers brings in devices from your RMM - Tactical RMM is the first it knows. Add it with its API address and an API key, then on its Clients page link its clients to yours: a client with the same name is suggested, one click links it, and Link the suggested does them all. A linked client's devices come in as its assets straight away, then every 15 minutes or with Sync now. A device is matched to the asset you already have for it - same serial number, or the only asset with its name - and only what that asset is missing is filled in. Otherwise a new asset is made: its name, type (laptop, desktop, server or virtual machine), make and model, serial number, OS, IP, CPU and storage, at the location named like its site in the RMM.
+- RMM Providers: more than one can be set up - two Tactical servers, say, each with a name of its own. A device both have is matched to the same asset, which shows what each says.
+- RMM Providers: what the RMM says about a device keeps its asset up to date, field by field - until you change that field in ITFlow, which then stays as you set it. A blank from the RMM never clears anything.
+- RMM Providers: an asset from an RMM shows whether the device is online, offline or overdue, beside its status. It also gets a card named after its provider: when it was last seen, who is signed in, its public IP and site, and whether it needs a reboot, has patches waiting or has checks failing. For Tactical RMM, Take Control opens its remote session, and its menu has Open in Tactical RMM and Remote Background. The quick look has the state and Take Control too.
+- RMM Providers: on the assets list, a dot after a device's name says how it is, and the RMM filter - named after your provider when you have one - shows the online, offline or overdue ones, every device in it, or the assets that aren't in it.
+- RMM Providers: a device the RMM no longer has keeps its asset, marked as no longer in it. If you delete an asset in ITFlow, the next sync doesn't make it again - Bring back on the client's row does. A client linked to another of your clients brings its devices in there. The assets already made for the first client stay, no longer kept up. Each change is in the asset's history.
+- RMM Providers: the RMM Sync job is on Maintenance > Cron. Turning a provider off stops its syncs, and Delete forgets its links - the assets stay as they are either way. API keys are kept like other providers' keys and never shown again. A Tactical RMM key can do whatever its Tactical user can, so make it for a user whose role can see clients and agents and no more.
+
### Developer Updates
+- Database 3.6.7: `rmm_providers` (`rmm_provider_kind` - `tactical` for now - the name it goes by, `api_url`, `web_url`, `api_key`, `api_secret` for an RMM that signs in with an id and a secret, and how the last sync went), `rmm_clients` (each provider's clients, `rmm_client_client_id` 0 until linked, `rmm_client_removed_at` once the RMM stops listing one) and `rmm_devices` (one a device: its asset, what the RMM last said - status, last seen, signed-in user, reboot, patches, checks - and `rmm_device_synced`, JSON of what the sync last wrote to the asset). Re-runnable, like 3.6.0.
+- `functions/rmm.php` is what every RMM shares. A kind is an entry in `rmmProviderKinds()` and a file of its own - `functions/rmm_tactical.php` for Tactical. It names the connection fields it uses, with their labels and help (the window and its checks are built from them), hints added to errors, the device links it offers, and four functions: `clients`, `devices` (each device in the shape described above `rmmDeviceFacts()`), `dashboard` and `device_urls`. `rmmHttp()` makes the request and turns a refused key, a redirect, a 404 or an answer that isn't JSON into a sentence for the person; `rmmTacticalRequest()` adds Tactical's `X-API-KEY`. Another RMM is a file like `rmm_tactical.php`, a line in `rmmProviderKinds()` and a `require_once` in `functions.php`.
+- `rmmSync($provider, $only = 0, $max_seconds = 120)` asks the kind for its clients, then for each linked client's devices, longest since brought in first, and stops on time to pick up next run. `GET_LOCK('itflow_rmm_sync_')` keeps each provider to one sync at a time. Devices and clients are marked removed by what the RMM listed, never by time, and only for a client whose list came back whole. One client failing doesn't hold up the rest or mark its devices removed. `rmmDeviceSave()` matches (`rmmAssetMatch()` - serial, then a name only one asset has, among this client's unarchived assets no other device of the provider has), makes (`rmmAssetCreate()`) and follows (`rmmAssetFollow()`). The follow rule: a field is written when it is empty or still holds what `rmm_device_synced` says was last written, and a blank never writes. Values go through `rmmText()` first - what `escapeSql()` would store - so a value compares the same on both sides and isn't written again every run. CPU and storage are asset details (`asset_specs`) and are only written for a type that has them. A device two providers have is one asset with a row from each, and each follows only what it wrote.
+- `cron/rmm_sync.php` is the `rmm_sync` job in `includes/cron_jobs.php`, every 15 minutes: `rmmSyncAll()` syncs each provider that is on, sharing two minutes between them. It stops with the failing providers' notes, or when cron is off. Admin handlers are in `admin/post/rmm.php`; their request keys are in `DEMO_MODE_LOCKS`, and `admin/rmm_providers.php` and `admin/rmm_clients.php` are locked pages in the demo.
+- `agent/assets.php` takes `rmm` (`any`, `online`, `offline`, `overdue`, `none`) as a subquery on `rmm_devices`, in the list and the tab counts alike. The RMM select only shows once a provider is set up.
- `agent/ajax.php`: the seventeen GET answers that printed JSON under PHP's default `text/html` now send `Content-Type: application/json` first - `get_credential_via_id`, `get_totp_token_via_id`, `get_readable_pass`, `get_active_clients`, `get_client_contacts`, `get_client_assets`, `get_client_locations`, `get_client_vendors`, `get_client_projects`, `get_internal_users`, `get_document_content`, `get_canned_response`, `ticket_query_views`, `client_duplicate_check`, `contact_email_check`, `network_ip_check` and `domain_check`. Their callers read the body as text (`itflowGet()`) or with `res.json()`, so nothing changes for them. A new JSON answer sets the header the same way: a value that is not escaped for HTML, as a login's username and password are not, must never go out as `text/html`.
- `getFieldByIdInScope($table, $id, $field, $client_field)` (`functions/app.php`) is `getFieldById()` for a record that belongs to a client. It gives null unless `hasClientAccess()` passes for the record's client, as it does for a record that isn't there; a record with no client (0) is anyone's. Use it wherever a label is made from an id in the query string. The two labels read with their own query, on `agent/trips.php` and `agent/modals/trip/trip_export.php`, take `clientScopeSql()` instead.
- `join.php` puts the login key in its sign-in link only while the invite is `pending` or `accepted` (`userInviteState()`).
diff --git a/admin/database_updates/3.6.7.php b/admin/database_updates/3.6.7.php
new file mode 100644
index 000000000..660484ee1
--- /dev/null
+++ b/admin/database_updates/3.6.7.php
@@ -0,0 +1,90 @@
+Text Messaging
+ "$short clients",
+ 'icon' => $kind['icon'],
+ 'title' => escapeHtml($show === 'unlinked' ? "Every $short client is linked" : "No $short clients yet"),
+ 'text' => $show === 'unlinked' ? '' : escapeHtml($provider['rmm_provider_sync_at'] ? "$name has no clients this key can see." : "Sync now asks $name for its clients."),
+ 'actions' => $usable && !$provider['rmm_provider_sync_at'] ? [['label' => 'Sync now', 'href' => "post.php?sync_rmm=$provider_id&csrf_token=$csrf", 'icon' => 'fa-sync-alt']] : [],
+ 'filtered' => $q !== '',
+ ];
+ ?>
+
+
+
+
+
+ RMM Providers - the RMMs ITFlow brings devices in from (functions/rmm.php), Tactical
+ * RMM the first kind. Each row says which RMM it is, how many of its clients are linked to
+ * yours, how many of its devices are assets here and how its last sync went. Its clients are
+ * linked on its Clients page (rmm_clients.php). Add and Edit are one window
+ * (modals/rmm/rmm_provider_edit.php); the rest are admin/post/rmm.php.
+ */
+
+// Default Column Sortby Filter
+$sort = "rmm_provider_name";
+$order = "ASC";
+
+require_once "includes/inc_all_admin.php";
+
+// The tables arrive with the 3.6.7 database update
+if (!rmmTablesReady()) { ?>
+
RMM Providers arrive with a database update - run it in Maintenance > Update first.
+ "rmm_provider_name $order",
+ 'rmm_provider_kind' => "rmm_provider_kind $order, rmm_provider_name ASC",
+ 'clients_linked' => "clients_linked $order, rmm_provider_name ASC",
+ 'devices_in' => "devices_in $order, rmm_provider_name ASC",
+ 'rmm_provider_sync_at' => "rmm_provider_sync_at IS NULL, rmm_provider_sync_at $order, rmm_provider_name ASC",
+];
+if (!isset($sortable_columns[$sort])) {
+ $sort = 'rmm_provider_name';
+}
+
+// A search for "tactical" finds Tactical RMM's providers by their kind's name too
+$kinds_found = array_keys(array_filter($kinds, function ($kind) use ($q) {
+ return $q !== '' && stripos($kind['name'], stripslashes($q)) !== false;
+}));
+$kind_search = $kinds_found ? " OR rmm_provider_kind IN ('" . implode("', '", array_map('escapeSql', $kinds_found)) . "')" : '';
+
+$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS rmm_providers.*,
+ (SELECT COUNT(*) FROM rmm_clients WHERE rmm_client_provider_id = rmm_provider_id AND rmm_client_removed_at IS NULL) AS clients_total,
+ (SELECT COUNT(*) FROM rmm_clients WHERE rmm_client_provider_id = rmm_provider_id AND rmm_client_removed_at IS NULL AND rmm_client_client_id > 0) AS clients_linked,
+ (SELECT COUNT(*) FROM rmm_devices WHERE rmm_device_provider_id = rmm_provider_id AND rmm_device_removed_at IS NULL AND rmm_device_asset_id > 0) AS devices_in,
+ (SELECT COUNT(*) FROM rmm_devices WHERE rmm_device_provider_id = rmm_provider_id AND rmm_device_removed_at IS NULL AND rmm_device_asset_id > 0 AND rmm_device_status = 'overdue') AS devices_overdue
+ FROM rmm_providers
+ WHERE (rmm_provider_name LIKE '%$q%' OR rmm_provider_api_url LIKE '%$q%' OR rmm_provider_kind LIKE '%$q%'$kind_search)
+ ORDER BY {$sortable_columns[$sort]}, rmm_provider_id ASC
+ LIMIT $record_from, $record_to");
+
+$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
+
+// Syncing needs cron - say so while a provider is on and it isn't running
+$any_on = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM rmm_providers WHERE rmm_provider_active = 1"))[0]) > 0;
+$cron_on = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT config_enable_cron FROM settings WHERE company_id = 1"))[0] ?? 0) === 1;
+$job = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT cron_job_enabled FROM cron_jobs WHERE cron_job_name = 'rmm_sync' LIMIT 1"));
+$job_on = !$job || intval($job['cron_job_enabled']) === 1;
+
+$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
+ return ''
+ . $label . ($sort === $column ? " $order_icon" : '') . '';
+};
+
+$add_url = 'modals/rmm/rmm_provider_add.php';
+$csrf = $_SESSION['csrf_token'];
+
+?>
+
+
+
+
RMM Providers
+
+
+
+
+
+
+ = $cron_on ? 'The RMM Sync job is off in' : 'Cron is off in' ?> Maintenance > Cron - devices only come in with Sync now.
+
+ 'RMM providers',
+ 'icon' => 'fa-laptop-medical',
+ 'text' => 'Add ' . escapeHtml(implode(' or ', array_column($kinds, 'name'))) . ' and link its clients to yours: their devices come in as assets, matched to the ones you have, and each asset shows whether it is online, who is signed in and what needs attention - kept up every 15 minutes.',
+ 'actions' => [['label' => 'Add Provider', 'modal' => $add_url]],
+ ];
+ ?>
+
+
+
+
+
+= 1;
$can_credentials_edit = lookupUserPermission('module_credential') >= 2;
+ // Its devices in an RMM, if it came from one (functions/rmm.php) - the one that matters most first; its links go up top
+ $rmm_devices = rmmDevicesForAsset($asset_id);
+ $rmm_device = $rmm_devices[0] ?? null;
+ $rmm_urls = $rmm_device && $rmm_device['rmm_device_removed_at'] === null ? rmmDeviceUrls($rmm_device) : [];
+ $rmm_links = $rmm_device ? (rmmKind($rmm_device)['links'] ?? []) : [];
+ $rmm_first = $rmm_urls ? (isset($rmm_urls['control']) ? 'control' : (string) array_key_first($rmm_urls)) : '';
+ $rmm_icons = ['open' => 'fa-external-link-alt', 'control' => 'fa-desktop', 'background' => 'fa-terminal'];
+
// The rack it sits in, if any
$asset_rack = rackPositionForAsset($asset_id);
if ($asset_rack) {
@@ -270,6 +278,9 @@ if (mysqli_num_rows($sql) == 0) {
= $asset_status_pill ?>
+
+ = rmmDeviceStatePill($rmm_device) ?>
+
= escapeHtml($rmm_each_name) ?> stopped listing it = escapeHtml(timeAgo($rmm_each['rmm_device_removed_at'])) ?> - its agent was removed, or it moved to a client that isn't linked. = escapeHtml(preg_replace('/^[^:]*: /', '', $rmm_state['title'])) ?> there.
+
+
+
Status
+
= escapeHtml($rmm_state['label']) ?>
+
+ - last seen = escapeHtml(timeAgo($rmm_each['rmm_device_last_seen_at'])) ?>
+
+
All = intval($rmm_each['rmm_device_checks_total']) ?> checks passing
+
+
+
= escapeHtml($rmm_each_name) ?> has it under = escapeHtml($rmm_each['rmm_client_name']) ?>, which is linked to another client.
+
+
+
As = escapeHtml($rmm_each_kind['short'] ?? $rmm_each_name) ?> said = escapeHtml(timeAgo($rmm_each['rmm_device_synced_at'])) ?>.
+
+
+
+
diff --git a/agent/assets.php b/agent/assets.php
index 2c05afa42..88565941e 100644
--- a/agent/assets.php
+++ b/agent/assets.php
@@ -83,6 +83,23 @@ if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) {
$tag_query = '';
}
+// RMM Filter - only once an RMM provider is set up (functions/rmm.php): any of its devices, online, offline or overdue, or not one of them.
+// With one provider it goes by its name
+$rmm_set_up = (bool) rmmProviders();
+$rmm_name = $rmm_set_up ? rmmListLabel() : '';
+$rmm_short = $rmm_name === 'an RMM' ? 'RMM' : $rmm_name;
+$rmm_filters = ['any' => "In $rmm_name", 'online' => "$rmm_short: online", 'offline' => "$rmm_short: offline", 'overdue' => "$rmm_short: overdue", 'none' => "Not in $rmm_name"];
+$rmm_filter = $rmm_set_up && isset($rmm_filters[$_GET['rmm'] ?? '']) ? (string) $_GET['rmm'] : '';
+$rmm_in = "SELECT rmm_device_asset_id FROM rmm_devices WHERE rmm_device_asset_id > 0 AND rmm_device_removed_at IS NULL";
+$rmm_query = [
+ '' => '',
+ 'any' => "AND asset_id IN ($rmm_in)",
+ 'online' => "AND asset_id IN ($rmm_in AND rmm_device_status = 'online')",
+ 'offline' => "AND asset_id IN ($rmm_in AND rmm_device_status = 'offline')",
+ 'overdue' => "AND asset_id IN ($rmm_in AND rmm_device_status = 'overdue')",
+ 'none' => "AND asset_id NOT IN ($rmm_in)",
+][$rmm_filter];
+
// Expiring In Filter
if (!empty($_GET['expire_days'])) {
if ($_GET['expire_days'] == "expired") {
@@ -141,6 +158,7 @@ $row = mysqli_fetch_assoc(mysqli_query($mysqli, "
WHERE $archive_query
$status_query
$tag_query
+ $rmm_query
" . clientScopeSql('asset_client_id') . "
$client_query
"));
@@ -170,6 +188,7 @@ $sql = mysqli_query(
$status_query
$location_query
$expire_query
+ $rmm_query
$client_query
GROUP BY asset_id
ORDER BY $order_by LIMIT $record_from, $record_to"
@@ -184,8 +203,9 @@ while ($row = mysqli_fetch_assoc($sql)) {
// Each one's details - its type's (functions/asset_type.php): a UPS battery due is flagged like a warranty, and Details lists them
$asset_list_specs = assetSpecsFor(array_keys($assets));
-// Tags and rack positions for the whole page in two queries, not two per row
+// Tags, rack positions and what its RMM says of each for the whole page in three queries, not three per row
$assets_tags = tagsForRecords('asset', array_keys($assets));
+$assets_rmm = $rmm_set_up ? rmmDevicesForAssets(array_keys($assets)) : [];
$assets_racked = [];
if ($assets) {
$sql_racked = mysqli_query($mysqli, "SELECT unit_asset_id, unit_start_number, unit_end_number, rack_id, rack_name FROM rack_units
@@ -259,7 +279,7 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets'