Managed instances now report their agents and waiting invites (name, email, role, MFA, last sign-in) at check-in, the manager shows them in an Agents card on the instance page, and the Managed By privacy text lists what is sent

This commit is contained in:
johnnyq
2026-11-25 01:09:52 -05:00
parent 1b7a84de40
commit 42df246266
3 changed files with 101 additions and 3 deletions

View File

@@ -112,7 +112,7 @@ $lock = '<i class="fas fa-fw fa-lock text-body-secondary ms-1" title="Set by ' .
<h3 class="card-title"><i class="fas fa-fw fa-info-circle me-2"></i>What a manager can do</h3>
</div>
<ul class="list-group list-group-flush small">
<li class="list-group-item d-flex gap-2"><i class="fas fa-fw fa-heartbeat text-body-secondary mt-1"></i><span>See how it's doing - versions, updates, cron, backups, errors and seats. No client data leaves here.</span></li>
<li class="list-group-item d-flex gap-2"><i class="fas fa-fw fa-heartbeat text-body-secondary mt-1"></i><span>See how it's doing - versions, updates, cron, backups, errors, and who holds its seats. No client data leaves here.</span></li>
<li class="list-group-item d-flex gap-2"><i class="fas fa-fw fa-download text-body-secondary mt-1"></i><span>Update it, by hand or automatically - and then updates come only from there.</span></li>
<li class="list-group-item d-flex gap-2"><i class="fas fa-fw fa-users text-body-secondary mt-1"></i><span>Set how many agents it can have, and its white-label key.</span></li>
<li class="list-group-item d-flex gap-2"><i class="fas fa-fw fa-headset text-body-secondary mt-1"></i><span>Sign in as support, for two hours at a time - each time in the audit log, and you're notified.</span></li>
@@ -195,7 +195,8 @@ $lock = '<i class="fas fa-fw fa-lock text-body-secondary ms-1" title="Set by ' .
<li>its address, company name and time zone</li>
<li>its version, database version, PHP version and branch, and whether an update is waiting</li>
<li>how the last update went, whether cron is running, and when the last backup was</li>
<li>how many errors were logged today and the categories they were logged under - never what they say - how many agents and clients it has, and its storage</li>
<li>how many errors were logged today and the categories they were logged under - never what they say - how many clients it has, and its storage</li>
<li>its agents and the invites waiting - name, email, role, whether they sign in with MFA and when they last signed in</li>
</ul>
<p class="mb-0 text-body-secondary">No tickets, documents, credentials, invoices or contacts.</p>
</div>

View File

@@ -310,6 +310,68 @@ if ($error_count > 0) {
</div>
<?php } ?>
</div>
<!-- Who holds its seats - its active agents, then the invites waiting -->
<div class="card mb-3" data-managed-agents>
<div class="card-header py-3">
<h3 class="card-title"><i class="fas fa-fw fa-users me-2"></i>Agents</h3>
<?php if ($agents) { ?>
<div class="card-tools small text-body-secondary pt-1"><?= intval($agents['active'] ?? 0) + intval($agents['invites'] ?? 0) ?><?= intval($agents['limit'] ?? 0) > 0 ? ' of ' . intval($agents['limit']) : '' ?> seats taken</div>
<?php } ?>
</div>
<?php if (!is_array($agents['list'] ?? null)) { ?>
<div class="card-body text-body-secondary small">Who they are shows once it runs a version that sends them - until then, only how many.</div>
<?php } elseif (!$agents['list']) { ?>
<div class="card-body text-body-secondary small">No agents yet.</div>
<?php } else { ?>
<div class="table-responsive">
<table class="table table-sm align-middle mb-0 small">
<thead class="table-light">
<tr>
<th class="ps-3">Agent</th>
<th>Role</th>
<th class="text-center">MFA</th>
<th class="d-none d-md-table-cell">Last signed in</th>
</tr>
</thead>
<tbody>
<?php foreach ($agents['list'] as $agent) {
if (!is_array($agent)) {
continue;
}
$invited = !empty($agent['invited']); ?>
<tr>
<td class="ps-3">
<div class="fw-semibold"><?= escapeHtml((string) ($agent['name'] ?? '')) ?>
<?php if ($invited) { ?><span class="badge rounded-pill bg-info-subtle text-info-emphasis border border-info-subtle fw-normal ms-1">Invited</span><?php } ?>
<?php if (!empty($agent['service'])) { ?><span class="badge rounded-pill bg-secondary-subtle text-secondary-emphasis border border-secondary-subtle fw-normal ms-1">API account</span><?php } ?>
</div>
<div class="text-body-secondary text-break"><?= escapeHtml((string) ($agent['email'] ?? '')) ?></div>
</td>
<td><?= escapeHtml((string) ($agent['role'] ?? '')) ?></td>
<td class="text-center">
<?php if ($invited) { ?>
<span class="text-body-secondary">-</span>
<?php } elseif (!empty($agent['mfa'])) { ?>
<i class="fas fa-fw fa-lock text-success" title="Signs in with MFA"></i>
<?php } else { ?>
<i class="fas fa-fw fa-unlock text-warning" title="No MFA"></i>
<?php } ?>
</td>
<td class="d-none d-md-table-cell text-nowrap">
<?php if ($invited) { ?>
<span class="text-body-secondary"><?= !empty($agent['expires_at']) ? 'Invite runs out ' . escapeHtml(date('M j', strtotime((string) $agent['expires_at']))) : 'Invite waiting' ?></span>
<?php } else { ?>
<?= $when($agent['last_login'] ?? null) ?>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
</div>
<?php } ?>
<!-- What it has been asked, and how that went -->

View File

@@ -441,7 +441,7 @@ function managedDirMb(string $dir): float
/*
* How this ITFlow is doing, for its manager - versions, updates, cron, backups, errors,
* agents against the seat limit, and disk and database size (measured every half hour,
* agents against the seat limit and who they are, and disk and database size (measured every half hour,
* as walking the uploads folder isn't free). Times carry their offset (managedIsoTime()).
*/
function managedReport(): array
@@ -484,6 +484,40 @@ function managedReport(): array
}
}
$clients = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM clients WHERE client_archived_at IS NULL AND client_lead = 0"))[0] ?? 0);
// Who holds the seats - the active agents (not the support user, which takes none), then the
// invites waiting in date - as getAgentSeatsTaken() counts them
$agent_list = [];
$support_user_id = managedSupportUserId();
$service = function_exists('serviceAccountsReady') && serviceAccountsReady();
$result = mysqli_query($mysqli, "SELECT user_name, user_email, user_token, role_name" . ($service ? ', user_service_account' : '') . ",
(SELECT MAX(log_created_at) FROM logs WHERE log_user_id = users.user_id AND log_type = 'Login' AND log_action = 'Success') AS last_login
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" . ($support_user_id ? " AND user_id <> $support_user_id" : '') . "
ORDER BY user_name ASC LIMIT 500");
while ($user = mysqli_fetch_assoc($result)) {
$agent_list[] = [
'name' => mb_substr((string) $user['user_name'], 0, 120),
'email' => mb_substr((string) $user['user_email'], 0, 200),
'role' => mb_substr((string) ($user['role_name'] ?? ''), 0, 100),
'mfa' => trim((string) ($user['user_token'] ?? '')) !== '',
'service' => !empty($user['user_service_account']),
'last_login' => managedIsoTime($user['last_login']),
];
}
if (function_exists('userInvitesReady') && userInvitesReady()) {
$result = mysqli_query($mysqli, "SELECT invite_name, invite_email, role_name, invite_expires_at FROM user_invites LEFT JOIN user_roles ON role_id = invite_role_id
WHERE invite_accepted_at IS NULL AND invite_cancelled_at IS NULL AND invite_expires_at > NOW() ORDER BY invite_created_at ASC LIMIT 500");
while ($invite = mysqli_fetch_assoc($result)) {
$agent_list[] = [
'name' => mb_substr((string) $invite['invite_name'], 0, 120),
'email' => mb_substr((string) $invite['invite_email'], 0, 200),
'role' => mb_substr((string) ($invite['role_name'] ?? ''), 0, 100),
'invited' => true,
'expires_at' => managedIsoTime($invite['invite_expires_at']),
];
}
}
$company = (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT company_name FROM companies WHERE company_id = 1"))[0] ?? '');
// Disk and database size, every half hour
@@ -539,6 +573,7 @@ function managedReport(): array
'active' => getActiveAgentUserCount(),
'invites' => function_exists('userInvitesHoldingSeats') ? userInvitesHoldingSeats() : 0,
'limit' => getAgentUserLimit(),
'list' => $agent_list,
],
'clients' => $clients,
'disk' => ['measured_at' => managedIsoTime($metrics['measured_at'] ?? null)] + $metrics,