Files
itflow/admin/post/managed_by.php
johnnyq 3b5c11c552 Add managed mode, so one ITFlow can manage others - Admin > Managed Instances adds an instance and gives a one-time connection code (a week) that the other ITFlow pastes into the new Admin > Managed By, after which it checks in every minute from the new Manager Check-in cron job with a health report (versions, update waiting and whether it has security fixes, cron, last backup, errors today, agents against the seat limit, clients, storage) and takes back what the manager sets; the manager lists each instance's version, health, seats and last check-in with a page per instance showing what needs a look, its requests and everything it reported, can update it by hand or automatically after a set number of days (security releases straight away, not retried for six hours after a failure), set its seat limit and white-label key (locked on the instance while set), make it read-only (look, export and download only, across agents, portal, guest links and the API) or suspended (a notice with the manager's message and contact, 503 for the API) with other cron jobs paused until it is active again, sign in to it as support through a signed one-time two-minute link into a two-hour session that takes no seat, can't open the vault and can't set passwords or make API keys, and remove it, while the new Managed Instances job notifies when one stops checking in and closes requests never answered; instances only call the manager, can disconnect unless config.php sets $config_manager_required, and the Update page and queue_update defer to the manager; database 3.5.8 adds managed_instances, managed_instance_commands, settings.config_manager_keys and settings.config_managed, the logic is in the new functions/managed.php with api/managed/enroll.php, api/managed/checkin.php, login_support.php and includes/managed_blocked.php, cronJobClaim() takes a paused reason that leaves a due job due, getAgentUserLimit() and getActiveAgentUserCount() honour the manager's limit and leave out the support user, the vault helpers read a missing session key as empty, the audit log knows the new types and actions, and the email parser no longer logs an App Logs error every minute while parsing is switched off; changelog updated
2026-11-05 15:22:41 -05:00

89 lines
2.7 KiB
PHP

<?php
/*
* Managed By (Admin > Managed By) - connecting this ITFlow to a manager with its code,
* checking in straight away, and disconnecting. The workings are in functions/managed.php.
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
if (isset($_POST['managed_connect'])) {
validateCSRFToken();
if (!settingsColumnExists($mysqli, 'config_managed')) {
flashAlert("Apply the database update first", 'error');
redirect();
}
if (managedIsManaged()) {
flashAlert("This ITFlow is already managed by <strong>" . escapeHtml(managedManagerName()) . "</strong> - disconnect it first", 'error');
redirect();
}
$url = rtrim(trim((string) ($_POST['url'] ?? '')), '/');
if (!preg_match('#^https?://[^\s/]+(/[^\s]*)?$#', $url)) {
flashAlert("That isn't an address - it starts https://", 'error');
redirect();
}
$error = '';
if (!managedEnroll((string) ($_POST['code'] ?? ''), $url, $error)) {
flashAlert("Not connected - " . escapeHtml($error), 'error');
redirect();
}
$manager = managedManagerName();
logAudit("Management", "Connect", "$session_name connected this ITFlow to " . escapeSql($manager) . " to be managed");
flashAlert("Connected - <strong>" . escapeHtml($manager) . "</strong> manages this ITFlow now");
redirect();
}
if (isset($_POST['managed_checkin_now'])) {
validateCSRFToken();
if (!managedIsManaged()) {
flashAlert("This ITFlow isn't managed", 'error');
redirect();
}
$result = managedCheckin();
if (!$result['ok']) {
flashAlert("The check-in didn't get through - " . escapeHtml($result['error']), 'error');
} elseif (!managedIsManaged()) {
flashAlert("Checked in - the manager has removed this ITFlow, so it is no longer managed", 'info');
} else {
flashAlert("Checked in with <strong>" . escapeHtml(managedManagerName()) . "</strong>" . ($result['commands'] ? ' - it had ' . $result['commands'] . ' request' . ($result['commands'] === 1 ? '' : 's') : ''));
}
redirect();
}
if (isset($_POST['managed_disconnect'])) {
validateCSRFToken();
if (!managedIsManaged()) {
flashAlert("This ITFlow isn't managed", 'error');
redirect();
}
if (managedRequired()) {
flashAlert("This install's config.php keeps it managed, so it can't be disconnected here", 'error');
redirect();
}
$manager = managedManagerName();
managedDisconnect('disconnected');
logAudit("Management", "Disconnect", "$session_name disconnected this ITFlow from " . escapeSql($manager));
flashAlert("Disconnected - <strong>" . escapeHtml($manager) . "</strong> no longer manages this ITFlow", 'error');
redirect();
}