Feature: transfer a Go-managed host to the MFC master from the web console
A Go-managed host cannot receive the client upgrade that only the MFC master can push. Transfer moves its main link there and brings it back after N days; MFC has no reason to return it. Transfer is not share: ASSIGN writes the target and drops the current connection, so the old master sees the host go offline and the new master gets a normal main link it can remote control and upgrade. While a transfer is live the client refuses a second transfer and any share, so no host is handed to a third master that expiry would orphan. Server: admin-only `transfer_device` WS command, COMMAND_ASSIGN_MASTER + SHARE_TYPE_YAMA_FOREVER as `host:port:days::transport\0`, byte-compatible with the MFC dialog. The transport segment is always present (YAMA_TRANSFER_TRANSPORT, default 0/TCP) because clients keep their current link when it is missing: a WSS-managed host would otherwise retry WSS against the MFC master's raw TCP port and never connect. The empty shine segment keeps the host's header encryption. The button only renders when `device_list.transfer` is present, which MFC never sends, so no MFC change is needed. devicehistory keeps transfer_to/transfer_until for the card badge and drops the marker on expiry or on a fresh login here. Client: KernelManager.cpp writes the registry and disconnects; ClientDll.cpp re-reads the registry at the top of every reconnect, so a mid-session transfer lands on the next round. Expiry is checked before every connect attempt as well as inside the heartbeat loop, so an unreachable target cannot pin the host to an expired address until a restart; restoring rebuilds the link captured on entry (address, header encryption, transport). linux/main.cpp applies the transfer on the main loop and restores the captured endpoint at expiry; Android does the same; macOS has neither share nor transfer.
This commit is contained in:
1 parent
b466f568ab
commit
63c7cdf588
18 files changed
+1024
-177
No files matched your search
+147
-1
@@ -642,6 +642,21 @@
|
||||
max-width: 200px;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
/* 「已转移」标记:主机被转移到另一台主控(MFC),到期自己回来。
|
||||
只在 Go 后端出现——device_list 里没有 transfer 字段时整个功能都不渲染。 */
|
||||
.device-card .transfer-badge {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #d68910;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.device-grid.list-view .device-card .transfer-badge {
|
||||
margin-top: 0;
|
||||
max-width: 240px;
|
||||
flex-shrink: 1;
|
||||
}
|
||||
/* 卡片操作图标(终端 / 删除):右上角,独立于卡片本体点击事件
|
||||
(onclick stopPropagation)。List 视图卡片是一行,改为垂直居中。 */
|
||||
.device-card .card-actions {
|
||||
@@ -670,7 +685,12 @@
|
||||
.device-card .card-term-btn:hover { background: rgba(76, 175, 80, 0.25); color: #4caf50; }
|
||||
.device-card .card-del-btn:hover { background: rgba(231, 76, 60, 0.25); color: #e74c3c; }
|
||||
.device-card .card-bind-btn:hover { background: rgba(230, 126, 34, 0.25); color: #e67e22; }
|
||||
.device-card .card-transfer-btn:hover { background: rgba(214, 137, 16, 0.25); color: #d68910; }
|
||||
.device-card h3 { padding-right: 124px; } /* 给右上角操作图标让位 */
|
||||
/* 4 个操作图标(终端/绑定/转移/删除)= 4×32 + 3×6 + 右边距 12,比默认的
|
||||
3 个宽 38px;不让位标题会钻到图标底下。list-view 的 h3 padding-right:0
|
||||
选择器权重更高,不受影响。 */
|
||||
.device-card.many-actions h3 { padding-right: 162px; }
|
||||
.device-grid.list-view .device-card .card-actions {
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
@@ -2174,6 +2194,36 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Transfer Host Modal(仅 Go 后端:device_list 带 transfer 字段时才有入口) -->
|
||||
<div class="modal-overlay" id="transfer-device-modal" onclick="if(event.target===this)cancelTransferDevice()">
|
||||
<div class="modal-content" style="max-width:460px;">
|
||||
<div class="modal-header">
|
||||
<h3>Transfer Host</h3>
|
||||
<button class="modal-close" onclick="cancelTransferDevice()">×</button>
|
||||
</div>
|
||||
<div class="user-form">
|
||||
<div id="transfer-device-name" style="font-size:13px;color:#aaa;margin-bottom:10px;"></div>
|
||||
<label style="font-size:13px;color:#aaa;display:block;margin:8px 0 4px;">
|
||||
Target master (host:port)
|
||||
</label>
|
||||
<input type="text" id="transfer-target" placeholder="192.0.2.10:6543" autocomplete="off">
|
||||
<label style="font-size:13px;color:#aaa;display:block;margin:12px 0 4px;">
|
||||
Days until it comes back
|
||||
</label>
|
||||
<input type="number" id="transfer-days" min="0.5" max="365" step="0.5" value="1">
|
||||
<div style="font-size:12px;color:#888;margin-top:8px;">
|
||||
The host logs in on the target master and returns here by itself when the days
|
||||
run out. While it is away it shows as offline on this server. Use this to hand a
|
||||
host to the MFC master for a client upgrade.
|
||||
</div>
|
||||
<div style="display:flex;gap:8px;margin-top:14px;">
|
||||
<button onclick="confirmTransferDevice()">Transfer</button>
|
||||
<button class="cancel-btn" onclick="cancelTransferDevice()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Device Binding Modal(仅内置 admin 超级管理员可见) -->
|
||||
<div class="modal-overlay" id="bind-device-modal" onclick="if(event.target===this)closeBindModal()">
|
||||
<div class="modal-content" style="max-width:440px;">
|
||||
@@ -2930,6 +2980,9 @@
|
||||
}
|
||||
updateAdminButtons();
|
||||
devices = msg.devices || [];
|
||||
// 只有实现了「转移主机」的后端(Go)才会带这个字段;
|
||||
// MFC 复用同一份页面但不下发它,按钮因此不会出现。
|
||||
transferCfg = msg.transfer || null;
|
||||
// Keep current page (renderDeviceList adjusts if out of range)
|
||||
renderDeviceList();
|
||||
renderWallSidebar();
|
||||
@@ -3212,6 +3265,14 @@
|
||||
appAlert(msg.msg || 'Failed to delete device', 'Unable to Delete Device');
|
||||
}
|
||||
break;
|
||||
case 'transfer_device_result':
|
||||
if (msg.ok) {
|
||||
// 设备会转到新主控上线;刷新一次,卡片带上「已转移」标记。
|
||||
getDevices();
|
||||
} else {
|
||||
appAlert(msg.msg || 'Failed to transfer host', 'Unable to Transfer Host');
|
||||
}
|
||||
break;
|
||||
case 'list_users_result':
|
||||
if (msg.ok) {
|
||||
// The built-in admin is the superadmin, never a bind target.
|
||||
@@ -5061,6 +5122,16 @@
|
||||
'</svg>' +
|
||||
'</button>');
|
||||
}
|
||||
if (canTransferDevices() && !offline && !d.transferTo) {
|
||||
actions.push(
|
||||
'<button class="card-icon-btn card-transfer-btn" title="Transfer host" aria-label="Transfer" ' +
|
||||
'onclick="event.stopPropagation();openTransferModal(\'' + jsAttr(d.id) + '\')">' +
|
||||
'<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
|
||||
'<path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/>' +
|
||||
'<polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/>' +
|
||||
'</svg>' +
|
||||
'</button>');
|
||||
}
|
||||
if (canDeleteDevices()) {
|
||||
actions.push(
|
||||
'<button class="card-icon-btn card-del-btn" title="' +
|
||||
@@ -5076,7 +5147,9 @@
|
||||
}
|
||||
const actionsHtml = actions.length
|
||||
? '<div class="card-actions">' + actions.join('') + '</div>' : '';
|
||||
return '<div class="device-card' + (offline ? ' offline' : '') + '"' +
|
||||
// 4 个图标时标题要让出更多空间(见 .many-actions 的注释)。
|
||||
const manyActions = actions.length >= 4 ? ' many-actions' : '';
|
||||
return '<div class="device-card' + (offline ? ' offline' : '') + manyActions + '"' +
|
||||
(offline ? '' : ' onclick="connectDevice(\'' + jsAttr(d.id) + '\')"') + '>' +
|
||||
actionsHtml +
|
||||
'<h3>' + escapeHtml(displayName(d)) + '</h3>' +
|
||||
@@ -5096,6 +5169,11 @@
|
||||
'<span class="meta-item">' + screenInfo + '</span>' +
|
||||
'</div>' +
|
||||
(offline ? '<div class="last-seen">Last seen: ' + escapeHtml(formatLastSeen(d.last_seen)) + '</div>' : '') +
|
||||
(d.transferTo
|
||||
? '<div class="transfer-badge" title="Transferred to ' + escapeHtml(d.transferTo) + '">' +
|
||||
'Transferred → ' + escapeHtml(d.transferTo) + ' · ' +
|
||||
escapeHtml(formatTransferLeft(d.transferUntil)) + '</div>'
|
||||
: '') +
|
||||
(!offline && activeWin ? '<div class="active-window' + (isWindowBusy(activeWin) ? ' busy' : '') + '" title="' + escapeHtml(activeWin) + '">' + escapeHtml(activeWin) + '</div>' : '') +
|
||||
'</div>';
|
||||
}).join('');
|
||||
@@ -5427,6 +5505,74 @@
|
||||
ws.send(JSON.stringify({ cmd: 'delete_device', token, id }));
|
||||
}
|
||||
|
||||
// ===== 转移主机(仅 Go 后端) =====
|
||||
// 把一台主机临时交给另一台主控(MFC),让那台主控能给它下发客户端升级;
|
||||
// 到期后主机自己回到本主控(客户端记着启动时捕获的地址),服务端不参与还原。
|
||||
//
|
||||
// 入口的可见性完全取决于 device_list 里有没有 transfer 字段:Go 与 MFC 共用
|
||||
// 这一份页面,MFC 不下发该字段,于是没有按钮、也不会发出这条消息。
|
||||
let transferCfg = null; // {target, days} | null
|
||||
let pendingTransferDeviceId = null;
|
||||
|
||||
function canTransferDevices() {
|
||||
return !!transferCfg && currentUserRole === 'admin';
|
||||
}
|
||||
|
||||
// 卡片上的「剩余」只精确到分钟,够判断什么时候回来。
|
||||
function formatTransferLeft(until) {
|
||||
const left = (Number(until) || 0) * 1000 - Date.now();
|
||||
if (left <= 0) return 'returning now';
|
||||
const mins = Math.floor(left / 60000);
|
||||
if (mins < 60) return mins + 'm left';
|
||||
const hours = Math.floor(mins / 60);
|
||||
if (hours < 48) return hours + 'h ' + (mins % 60) + 'm left';
|
||||
return Math.floor(hours / 24) + 'd ' + (hours % 24) + 'h left';
|
||||
}
|
||||
|
||||
function openTransferModal(id) {
|
||||
if (!canTransferDevices()) return;
|
||||
const d = devices.find(x => String(x.id) === String(id));
|
||||
if (!d) { appAlert('Device not found.', 'Device Not Found'); return; }
|
||||
if (d.online === false) { appAlert('Device is offline.', 'Device Offline'); return; }
|
||||
pendingTransferDeviceId = String(id);
|
||||
document.getElementById('transfer-device-name').textContent =
|
||||
displayName(d) + ' (' + String(id) + ')';
|
||||
document.getElementById('transfer-target').value = transferCfg.target || '';
|
||||
document.getElementById('transfer-days').value = transferCfg.days || 1;
|
||||
document.getElementById('transfer-device-modal').classList.add('active');
|
||||
}
|
||||
|
||||
function cancelTransferDevice() {
|
||||
pendingTransferDeviceId = null;
|
||||
document.getElementById('transfer-device-modal').classList.remove('active');
|
||||
}
|
||||
|
||||
function confirmTransferDevice() {
|
||||
const id = pendingTransferDeviceId;
|
||||
const targetRaw = document.getElementById('transfer-target').value.trim();
|
||||
const days = parseFloat(document.getElementById('transfer-days').value);
|
||||
if (!id) return;
|
||||
|
||||
// 拆 host:port:最后一个冒号之后是端口,host 里不允许再出现冒号——
|
||||
// 服务端按 ':' 切字段,多一个冒号会把 days 读成端口。
|
||||
const cut = targetRaw.lastIndexOf(':');
|
||||
const host = cut > 0 ? targetRaw.slice(0, cut).trim() : '';
|
||||
const port = cut > 0 ? parseInt(targetRaw.slice(cut + 1), 10) : NaN;
|
||||
if (!host || host.indexOf(':') >= 0 || !(port >= 1 && port <= 65535)) {
|
||||
appAlert('Enter the target as host:port, e.g. 192.0.2.10:6543.', 'Invalid Target');
|
||||
return;
|
||||
}
|
||||
if (!(days > 0 && days <= 365)) {
|
||||
appAlert('Days must be between 0.5 and 365.', 'Invalid Duration');
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('transfer-device-modal').classList.remove('active');
|
||||
pendingTransferDeviceId = null;
|
||||
if (!ws || ws.readyState !== WebSocket.OPEN) return;
|
||||
ws.send(JSON.stringify({ cmd: 'transfer_device', token, id, host, port, days }));
|
||||
}
|
||||
|
||||
// User Management Functions
|
||||
let currentUserRole = 'viewer';
|
||||
// Username of the current session. Only the built-in "admin" account is
|
||||
|
||||
Reference in new issue
Block a user