From b2d8863607c84bf5bfa44f886697de3559b28294 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 4 Dec 2026 12:11:53 -0500 Subject: [PATCH] UniFi gateways come in as Firewall/Router whatever UniFi says: rmmUnifiGatewayModel knows Dream Machines, Dream Routers, Cloud Gateways, UXG, EFG and USG by model code or name for both the official Network API and a signed-in controller, a controller device with its own WAN is a gateway, in-wall access points come in as access points, and assets already brought in as a switch or Other are put right by the next sync unless changed by hand; 26.12.6 changelog --- CHANGELOG.md | 2 ++ functions/rmm_unifi.php | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47922318f..2a63ccdb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Update from Maintenance > Update as usual. There is no database change. ### Bug Fixes - Importing a CSV file with accented letters - ü, é, ñ, ø and the like - keeps them. A file saved from Excel as plain **CSV (Comma delimited)**, exported from Outlook, or saved from Excel for Mac as **Comma Separated Values** imported with a ? in place of each accented letter, and one with an accented letter in a heading didn't import at all. Every import - clients, contacts, locations, assets and the rest - now reads the file in whatever it was saved as, and a file whose columns are separated by tabs imports too. Bank statements imported on Expenses and Income read the same way, so one saved on a Mac or in Unicode now imports too. +- UniFi gateways come in as **Firewall/Router**. The Cloud Gateway Fiber, the Enterprise Fortress Gateway and other newer gateways came in as a switch or as Other, because UniFi doesn't always say a device is a gateway - ITFlow now knows them by their model too: the Dream Machines, Dream Routers and Dream Wall, the Cloud Gateways, the UXG Gateways, the Enterprise Fortress Gateway and the older Security Gateways. One already brought in as a switch or Other is put right by the next sync, unless you changed its type yourself, and when one goes offline its alert is the site's gateway alert. In-wall access points, which came in as switches, come in as access points. ### Developer Updates @@ -31,6 +32,7 @@ Update from Maintenance > Update as usual. There is no database change. - Cron: `cronJobModuleOff()` (`includes/cron_jobs.php`) and `not_in_use` checks on `ticket_email_parser`, `ticket_sla`, `ai_triage`, `ticket_pictures`, `domain_refresher`, `certificate_refresher` and `payment_provider_fees`; `cronJobSettings()` reads the whole settings row. `cron/nightly_tasks.php` skips contracts, recurring invoices, expenses and payments, reminders, quote and draft notices and card checks with accounting off, recurring tickets, auto-close and the pending-tickets notice with ticketing off, and the domain, certificate, warranty, asset date and service review notices with IT documentation off. - Pages: `agent/contact.php`, `location.php`, `asset.php`, `vendor.php`, `service.php`, `ticket.php`, `license.php`, `services.php`, `assets.php`, `calls.php`, `texts.php`, `invoice.php`, `invoices.php`, `quote.php`, `contract.php`, `trips.php`, `unbilled_time.php`, `client_overview.php`, `includes/client_actions_menu.php`, `reports/client_review.php`, `admin/includes/side_nav.php`, `rmm_clients.php`, `payment_methods.php`, `agent_banners.php`, `settings.php`, `settings_mail.php`, `settings_notification.php`, `settings_invoice.php`, `settings_default.php`, `tax_rates.php`, the contract and contract template windows (SLAs kept as hidden fields), the contact, location, vendor and ticket quick looks (`agent/modals/*/`), the offboarding window's open tickets note, `client/index.php`, `search.php`, `functions.php` (`portalNav()`) and `includes/header.php`. A switch or field hidden for a module that is off is kept as saved: `admin/post/settings_notification.php` only writes `config_enable_alert_domain_expire` with IT documentation on, and `tax_rates.php` posts `tax_time` and `tax_trips` hidden. - Imports: `csvTextToUtf8($text)` (`functions/import.php`) gives a CSV's text as UTF-8 - UTF-8 as it is with its BOM dropped, UTF-16 LE or BE by its BOM, and otherwise Windows-1252 or Mac Roman, whichever `csvTextMisreads()` finds fewer signs of a wrong reading in (C1 control characters, a capital or symbols in the middle of a word, an opening quote or `š`/`ˆ`/`fl` after a letter), Windows-1252 on a tie. `importFile()` reads the whole upload through it into `php://temp`, turns lone `\r` line ends into `\n`, and takes comma, semicolon or tab, whichever the heading line has most of; `expenseImportRead()` uses it in place of its own BOM strip and Windows-1252 fallback, which also let a UTF-16 statement fail its NUL check, and so do the network IP and interface imports in `agent/post/network_ip.php` and `agent/post/asset_interface.php`. Before, `importFile()` passed the bytes through: `importSqlText()`'s `mb_substr()` turned each invalid byte into `?` before `escapeSql()`'s Windows-1252 fallback could see it, and an invalid byte in a heading made `json_encode()` return false, so `import_check` answered with an empty body. `agent/post/import.php` now encodes its answer with `JSON_INVALID_UTF8_SUBSTITUTE`. CONTRIBUTING.md has the rule. +- UniFi: `rmmUnifiGatewayModel($model)` (`functions/rmm_unifi.php`) knows a gateway by its model code or name - UDM, UDR, UDW, UCG, UXG, EFG, USG, UGW, or a name starting Dream, Cloud Gateway or Gateway - but not the Express (UX, UX7), which is a site's gateway or an access point in someone else's network. The official Network API's `features` say `gateway` for some gateways only - a UCG Fiber comes as `switching`, an EFG with none - so `rmmUnifiNetworkDeviceType($features, $model)` takes `gateway` or the model, then `accessPoint` before `switching`, as an in-wall access point has both. `rmmUnifiControllerDevice()` takes a gateway by its `type` (`ugw`, `udm`, `uxg`), its model, or a `wan1` with an `ifname` or `ip`. Assets already brought in follow `rmmAssetFollow()`'s usual rule: a type the sync wrote is updated, one changed in ITFlow is left. ## [26.12.5] diff --git a/functions/rmm_unifi.php b/functions/rmm_unifi.php index d04ebadfc..61a80f0d9 100644 --- a/functions/rmm_unifi.php +++ b/functions/rmm_unifi.php @@ -947,7 +947,8 @@ function rmmUnifiControllerDevice(array $device): array $state = intval($device['state'] ?? -1); $status = in_array($state, [1, 4, 5], true) ? 'online' : (in_array($state, [0, 6, 10, 11], true) ? 'offline' : ''); $uptime = intval($device['uptime'] ?? 0); - $gateway = in_array($type, ['ugw', 'udm', 'uxg'], true); + // A gateway by its type, its model - newer gateways have types older controllers don't know - or a WAN of its own + $gateway = in_array($type, ['ugw', 'udm', 'uxg'], true) || rmmUnifiGatewayModel($model) || trim((string) ($device['wan1']['ifname'] ?? $device['wan1']['ip'] ?? '')) !== ''; $name = rmmText($device['name'] ?? '', 200); $ip = rmmText($device['ip'] ?? '', 100); return [ @@ -1001,7 +1002,7 @@ function rmmUnifiNetworkDevice(array $device): array 'patches_pending' => !empty($device['firmwareUpdatable']), 'agent_version' => '', 'asset' => [ - 'type' => in_array('gateway', $features, true) ? 'Firewall/Router' : (in_array('switching', $features, true) ? 'Switch' : (in_array('accessPoint', $features, true) ? 'Access Point' : 'Other')), + 'type' => rmmUnifiNetworkDeviceType($features, $model), 'make' => 'Ubiquiti', 'model' => $model, 'serial' => '', @@ -1012,6 +1013,34 @@ function rmmUnifiNetworkDevice(array $device): array ]; } +/** + * What the official Network API's device is. Its features say "gateway" for some gateways only - not + * a Cloud Gateway Fiber or an Enterprise Fortress Gateway, which come as "switching" or nothing - so + * its model says it too. An access point with ports of its own, an in-wall one, is an access point. + */ +function rmmUnifiNetworkDeviceType(array $features, string $model): string +{ + if (in_array('gateway', $features, true) || rmmUnifiGatewayModel($model)) { + return 'Firewall/Router'; + } + if (in_array('accessPoint', $features, true)) { + return 'Access Point'; + } + return in_array('switching', $features, true) ? 'Switch' : 'Other'; +} + +/** + * Whether a model is a gateway, by its code (UDMPRO, UXGPRO) or its name (UCG Fiber, UniFi Dream + * Router) - the Dream Machines, Dream Routers and Dream Wall, Cloud Gateways, Gateways (UXG), + * Enterprise Fortress Gateway and Security Gateways. Not the Express (UX, UX7): it's a site's gateway + * or an access point in someone else's network, and its model can't say which. + */ +function rmmUnifiGatewayModel(string $model): bool +{ + $model = strtoupper(preg_replace('/[^A-Za-z0-9]/', '', $model)); + return (bool) preg_match('/^(?:UNIFI)?(?:UDM|UDR|UDW|UCG|UXG|EFG|USG|UGW|DREAM|CLOUDGATEWAY|GATEWAY|ENTERPRISEFORTRESS|SECURITYGATEWAY)/', $model); +} + /** * A model code as people know it - U7PG2 is the UAP-AC-Pro. The code as it is for one not here, * and a name - the official Network API often says the name itself - as it is.