Feature: let the web console move a host to another group
The Go server now keeps a per-device group override (device_groups.json) edited from the card's "..." menu below Edit remark. The override wins over the group the host reported (or the offline history record) in the device list, the group filter, get_groups and the MCP host tools, so offline records can be regrouped and the change survives restarts. An empty value clears the override; names are capped at 23 characters, matching the Win32 regroup dialog. The command is admin-only and honours the device ACL; it refuses IDs the server has never seen (online or in history) so a stale card cannot create an orphan entry, and the remark handler gets the same guard. Each change is audited as admin.device.group, deleting a device drops its override, and values loaded from disk are trimmed and capped like remarks. The menu entry is gated on the groupEdit capability, so the shared page hides it on the MFC server. Like remarks, the override is a Go-side label: no CMD_SET_GROUP is sent, so the host keeps reporting its own group to other masters. Verified with go test ./..., go vet, gofmt and a node --check pass on the page. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
5f764b2425
commit
034b11fa6a
16 files changed
+895
-54
No files matched your search
+95
-8
@@ -658,7 +658,7 @@
|
||||
flex-shrink: 1;
|
||||
}
|
||||
/* 卡片操作:右上角只留一个「…」按钮,点开才弹出菜单(终端 / 备注 /
|
||||
绑定 / 转移 / 删除),菜单项带简短功能说明。独立于卡片本体点击事件
|
||||
分组 / 绑定 / 转移 / 删除),菜单项带简短功能说明。独立于卡片本体点击事件
|
||||
(onclick stopPropagation)。List 视图卡片是一行,按钮垂直居中。 */
|
||||
.device-card .card-actions {
|
||||
position: absolute;
|
||||
@@ -2314,6 +2314,33 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 修改分组(Go 后端):覆盖主机上报的分组,仅影响本服务端的显示/过滤/MCP。 -->
|
||||
<div class="modal-overlay" id="group-device-modal" onclick="if(event.target===this)closeGroupModal()">
|
||||
<div class="modal-content" style="max-width:440px;">
|
||||
<div class="modal-header">
|
||||
<h3>Edit Group</h3>
|
||||
<button class="modal-close" onclick="closeGroupModal()">×</button>
|
||||
</div>
|
||||
<div class="user-form">
|
||||
<div id="group-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;">
|
||||
Group
|
||||
</label>
|
||||
<input type="text" id="group-input" list="group-options" maxlength="23"
|
||||
placeholder="e.g. Office" autocomplete="off">
|
||||
<datalist id="group-options"></datalist>
|
||||
<div style="font-size:12px;color:#888;margin-top:8px;">
|
||||
Changes how this server groups and filters the host. Leave it empty to use the
|
||||
group the host reports. Max 23 characters.
|
||||
</div>
|
||||
<div style="display:flex;gap:8px;margin-top:14px;">
|
||||
<button onclick="confirmSetGroup()">Save</button>
|
||||
<button class="cancel-btn" onclick="closeGroupModal()">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Generic alert / confirmation dialog. Replaces native alert()/confirm():
|
||||
their button labels come from the browser locale (e.g. German on a
|
||||
German system) and do not match the app. -->
|
||||
@@ -3045,8 +3072,9 @@
|
||||
// 只有实现了「转移主机」的后端(Go)才会带这个字段;
|
||||
// MFC 复用同一份页面但不下发它,按钮因此不会出现。
|
||||
transferCfg = msg.transfer || null;
|
||||
// 备注编辑同理由后端能力位决定(Go 才有;MFC 页面不显示)。
|
||||
// 备注/分组编辑同理由后端能力位决定(Go 才有;MFC 页面不显示)。
|
||||
remarkEditAvailable = msg.remarkEdit === true;
|
||||
groupEditAvailable = msg.groupEdit === true;
|
||||
// Keep current page (renderDeviceList adjusts if out of range)
|
||||
renderDeviceList();
|
||||
renderWallSidebar();
|
||||
@@ -3374,6 +3402,14 @@
|
||||
appAlert(msg.msg || 'Failed to save remark', 'Edit Remark');
|
||||
}
|
||||
break;
|
||||
case 'set_device_group_result':
|
||||
if (msg.ok) {
|
||||
closeGroupModal();
|
||||
getDevices();
|
||||
} else {
|
||||
appAlert(msg.msg || 'Failed to save group', 'Edit Group');
|
||||
}
|
||||
break;
|
||||
case 'device_revoked': {
|
||||
// The superadmin bound this device to someone else while we
|
||||
// were watching it. Stop streaming immediately.
|
||||
@@ -5145,7 +5181,7 @@
|
||||
|
||||
// ---- 卡片「…」操作菜单 ----
|
||||
// 无论有几个操作,卡片上只显示一个「…」;点开弹出的菜单里才是终端/备注/
|
||||
// 绑定/转移/删除,每项带一句功能说明。菜单项在点击时按设备实时生成,权限和
|
||||
// 分组/绑定/转移/删除,每项带一句功能说明。菜单项在点击时按设备实时生成,权限和
|
||||
// 在线状态不会因为列表渲染后变化而过期。
|
||||
let cardMenuEl = null;
|
||||
let cardMenuBtn = null;
|
||||
@@ -5154,6 +5190,8 @@
|
||||
'<polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>',
|
||||
edit: '<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="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>',
|
||||
group: '<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="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"/></svg>',
|
||||
bind: '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
|
||||
'<rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>',
|
||||
transfer: '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
|
||||
@@ -5163,17 +5201,22 @@
|
||||
'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>'
|
||||
};
|
||||
|
||||
// 备注编辑:只有实现了该功能的后端(Go)在 device_list 里报 remarkEdit
|
||||
// 才出现;MFC 复用同一份页面但不下发这个字段,菜单项因此不会出现。
|
||||
// 备注/分组编辑:只有实现了对应功能的后端(Go)在 device_list 里报
|
||||
// remarkEdit / groupEdit 才出现;MFC 复用同一份页面但不下发这些字段。
|
||||
let remarkEditAvailable = false;
|
||||
let groupEditAvailable = false;
|
||||
|
||||
function canEditRemark() {
|
||||
return remarkEditAvailable && currentUserRole === 'admin';
|
||||
}
|
||||
|
||||
function canEditGroup() {
|
||||
return groupEditAvailable && currentUserRole === 'admin';
|
||||
}
|
||||
|
||||
function hasCardActions(d) {
|
||||
if (d.online !== false) return true; // 在线设备至少有终端
|
||||
return canEditRemark() || canBindDevices() || canDeleteDevices();
|
||||
return canEditRemark() || canEditGroup() || canBindDevices() || canDeleteDevices();
|
||||
}
|
||||
|
||||
function cardMenuEntries(d) {
|
||||
@@ -5187,6 +5230,10 @@
|
||||
out.push({ kind: 'edit', label: 'Edit remark', desc: 'Set the label shown on the card',
|
||||
run: () => openRemarkModal(d.id) });
|
||||
}
|
||||
if (canEditGroup()) {
|
||||
out.push({ kind: 'group', label: 'Edit group', desc: 'Move this host to another group',
|
||||
run: () => openGroupModal(d.id) });
|
||||
}
|
||||
if (canBindDevices()) {
|
||||
out.push({ kind: 'bind', label: 'Bind owner', desc: 'Assign this host to a user',
|
||||
run: () => openBindModal(d.id) });
|
||||
@@ -5309,7 +5356,7 @@
|
||||
const rtt = d.rtt || '-';
|
||||
const ver = d.version || '-';
|
||||
const activeWin = d.activeWindow || '';
|
||||
// 操作全部收进右上角的「…」菜单(终端 / 备注 / 绑定 / 转移 / 删除),
|
||||
// 操作全部收进右上角的「…」菜单(终端 / 备注 / 分组 / 绑定 / 转移 / 删除),
|
||||
// 具体条目见 cardMenuEntries。这里只决定按钮是否出现。
|
||||
const actionsHtml = hasCardActions(d)
|
||||
? '<div class="card-actions">' +
|
||||
@@ -5668,6 +5715,45 @@
|
||||
}));
|
||||
}
|
||||
|
||||
// ===== 修改分组(Go 后端) =====
|
||||
// 覆盖主机上报的分组,影响本服务端的卡片分组、分组过滤与 MCP;不下发
|
||||
// CMD_SET_GROUP,主机对其它主控仍按自己上报的分组显示。留空 = 撤销覆盖。
|
||||
let pendingGroupDeviceId = null;
|
||||
|
||||
function openGroupModal(id) {
|
||||
if (!canEditGroup()) return;
|
||||
const d = devices.find(x => String(x.id) === String(id));
|
||||
if (!d) { appAlert('Device not found.', 'Edit Group'); return; }
|
||||
pendingGroupDeviceId = String(id);
|
||||
document.getElementById('group-device-name').textContent =
|
||||
displayName(d) + ' (' + String(id) + ')';
|
||||
// 建议值取当前列表里已有的分组(含覆盖后的)。
|
||||
const groups = Array.from(new Set(devices.map(x => x.group).filter(Boolean))).sort();
|
||||
document.getElementById('group-options').innerHTML =
|
||||
groups.map(g => '<option value="' + escapeAttr(g) + '"></option>').join('');
|
||||
// 只有覆盖值才预填。主机上报的分组只放进 placeholder:否则"打开即保存"
|
||||
// 会把上报值固化成覆盖,之后主机改了分组,控制台还停在旧值。
|
||||
const input = document.getElementById('group-input');
|
||||
input.value = d.groupOverride === true ? (d.group || '') : '';
|
||||
input.placeholder = d.group ? ('Current: ' + d.group) : 'e.g. Office';
|
||||
document.getElementById('group-device-modal').classList.add('active');
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
|
||||
function closeGroupModal() {
|
||||
pendingGroupDeviceId = null;
|
||||
document.getElementById('group-device-modal').classList.remove('active');
|
||||
}
|
||||
|
||||
function confirmSetGroup() {
|
||||
if (!pendingGroupDeviceId || !ws || ws.readyState !== WebSocket.OPEN) return;
|
||||
const group = document.getElementById('group-input').value.trim();
|
||||
ws.send(JSON.stringify({
|
||||
cmd: 'set_device_group', token, id: pendingGroupDeviceId, group,
|
||||
}));
|
||||
}
|
||||
|
||||
// ===== 删除设备 =====
|
||||
// 两种情况都删除服务端 devices.json 中的历史记录;在线设备额外按 MFC
|
||||
// 的做法发送单字节 TOKEN_UNINSTALL(卸载主机)。都先弹二次确认。
|
||||
@@ -5876,7 +5962,8 @@
|
||||
'remote.terminal.start', 'remote.terminal.stop', 'remote.terminal.denied',
|
||||
'remote.clipboard.set', 'remote.clipboard.get', 'remote.rdp_reset',
|
||||
'admin.user.create', 'admin.user.delete', 'admin.device.delete', 'admin.device.bind',
|
||||
'admin.device.unbind', 'admin.device.transfer', 'admin.device.remark', 'admin.audit.query',
|
||||
'admin.device.unbind', 'admin.device.transfer', 'admin.device.remark',
|
||||
'admin.device.group', 'admin.audit.query',
|
||||
'device.online', 'device.offline',
|
||||
'device.auth.success', 'device.auth.failure', 'device.auth.throttled',
|
||||
'device.auth.heartbeat.success',
|
||||
|
||||
Reference in new issue
Block a user