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
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -90,6 +91,8 @@ func (h *wsHub) dispatch(c *wsClient, cmd string, raw []byte) {
|
||||
// Admin operations (Phase 7).
|
||||
case "delete_device":
|
||||
h.handleDeleteDevice(c, raw)
|
||||
case "transfer_device":
|
||||
h.handleTransferDevice(c, raw)
|
||||
case "create_user":
|
||||
h.handleCreateUser(c, raw)
|
||||
case "delete_user":
|
||||
@@ -790,6 +793,13 @@ func (h *wsHub) handleGetDevices(c *wsClient, raw []byte) {
|
||||
"devices": h.listVisibleDevices(c),
|
||||
"username": c.user,
|
||||
"role": c.role,
|
||||
// Presence of this object is what tells the shared page that this
|
||||
// backend implements "transfer host" (the MFC server omits it), so the
|
||||
// button never appears where the command would go nowhere.
|
||||
"transfer": map[string]any{
|
||||
"target": h.transferTarget,
|
||||
"days": h.transferDays,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -799,6 +809,11 @@ func (h *wsHub) handleGetDevices(c *wsClient, raw []byte) {
|
||||
type deviceListItem struct {
|
||||
hub.DeviceInfo
|
||||
Owner string `json:"owner,omitempty"`
|
||||
// TransferTo / TransferUntil carry the "handed over to another master"
|
||||
// marker so the card can say where the host went and how long it stays
|
||||
// there. Absent for a host that was never transferred.
|
||||
TransferTo string `json:"transferTo,omitempty"`
|
||||
TransferUntil int64 `json:"transferUntil,omitempty"`
|
||||
}
|
||||
|
||||
// listVisibleDevices applies the device ACL to the online + offline snapshot.
|
||||
@@ -815,7 +830,13 @@ func (h *wsHub) listVisibleDevices(c *wsClient) []deviceListItem {
|
||||
if h.acl != nil && c.isSuperAdmin() {
|
||||
owner = h.acl.Owner(d.ID)
|
||||
}
|
||||
out = append(out, deviceListItem{DeviceInfo: d, Owner: owner})
|
||||
item := deviceListItem{DeviceInfo: d, Owner: owner}
|
||||
if h.history != nil {
|
||||
if target, until, ok := h.history.Transfer(d.ID); ok {
|
||||
item.TransferTo, item.TransferUntil = target, until
|
||||
}
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -1314,6 +1335,124 @@ func (h *wsHub) handleDeleteDevice(c *wsClient, raw []byte) {
|
||||
}))
|
||||
}
|
||||
|
||||
// maxTransferDays bounds the dialog input. A handover that outlives a year is
|
||||
// indistinguishable from "lost the host": the client would sit on the other
|
||||
// master long after whatever upgrade it was sent there for.
|
||||
const maxTransferDays = 365
|
||||
|
||||
// handleTransferDevice hands one online host over to another master
|
||||
// (COMMAND_ASSIGN_MASTER + SHARE_TYPE_YAMA_FOREVER) — the path that lets a Go
|
||||
// server's host be upgraded by the MFC master: only a master the host is
|
||||
// actually online on can push a new client build to it.
|
||||
//
|
||||
// The deadline is the client's business. It stored the master it booted
|
||||
// against and reconnects there when the days run out, so nothing here
|
||||
// schedules a restore; the server only keeps a marker so the card can read
|
||||
// "transferred → host:port, N left" instead of silently going offline.
|
||||
//
|
||||
// Admin-only: this moves a host off this master.
|
||||
func (h *wsHub) handleTransferDevice(c *wsClient, raw []byte) {
|
||||
const replyCmd = "transfer_device_result"
|
||||
if !h.requireAdmin(c, raw, replyCmd) {
|
||||
return
|
||||
}
|
||||
var in struct {
|
||||
ID string `json:"id"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Days float64 `json:"days"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
h.audit(c, true, auditDeviceTransfer, map[string]any{
|
||||
"ok": false,
|
||||
"reason": "bad_payload",
|
||||
})
|
||||
c.queue(mustJSON(map[string]any{
|
||||
"cmd": replyCmd, "ok": false, "msg": "Invalid transfer payload",
|
||||
}))
|
||||
return
|
||||
}
|
||||
in.ID = strings.TrimSpace(in.ID)
|
||||
in.Host = strings.TrimSpace(in.Host)
|
||||
|
||||
// A ':' in the host would shift every following payload field, and the
|
||||
// whole packet has to stay inside the 260-byte buffer both clients parse
|
||||
// (MFC's assignFunction uses bToken[_MAX_PATH]).
|
||||
if in.ID == "" || in.Host == "" || strings.Contains(in.Host, ":") || len(in.Host) > 200 ||
|
||||
in.Port <= 0 || in.Port > 65535 || in.Days <= 0 || in.Days > maxTransferDays {
|
||||
h.audit(c, true, auditDeviceTransfer, map[string]any{
|
||||
"device_id": in.ID,
|
||||
"host": in.Host,
|
||||
"port": in.Port,
|
||||
"days": in.Days,
|
||||
"ok": false,
|
||||
"reason": "invalid_target",
|
||||
})
|
||||
c.queue(mustJSON(map[string]any{
|
||||
"cmd": replyCmd, "ok": false,
|
||||
"msg": "Invalid target address or days (1-365)",
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
// The Windows client ignores a second assignment while the first one is
|
||||
// still live ("Avoid assign again"), so accepting it here would report a
|
||||
// success the host never acted on.
|
||||
target := in.Host + ":" + strconv.Itoa(in.Port)
|
||||
if h.history != nil {
|
||||
if prev, until, active := h.history.Transfer(in.ID); active {
|
||||
h.audit(c, true, auditDeviceTransfer, map[string]any{
|
||||
"device_id": in.ID,
|
||||
"target": prev,
|
||||
"ok": false,
|
||||
"reason": "already_transferred",
|
||||
})
|
||||
c.queue(mustJSON(map[string]any{
|
||||
"cmd": replyCmd, "ok": false,
|
||||
"msg": "Host is already transferred to " + prev + " until it expires",
|
||||
"target": prev, "until": until,
|
||||
}))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := h.devices.SendToDevice(in.ID, protocol.BuildAssignMasterPacket(in.Host, in.Port, in.Days, h.transferTransport)); err != nil {
|
||||
reason := "send_failed"
|
||||
if errors.Is(err, hub.ErrDeviceOffline) {
|
||||
reason = "offline"
|
||||
}
|
||||
h.audit(c, true, auditDeviceTransfer, map[string]any{
|
||||
"device_id": in.ID,
|
||||
"target": target,
|
||||
"ok": false,
|
||||
"reason": reason,
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.queue(mustJSON(map[string]any{
|
||||
"cmd": replyCmd, "ok": false, "msg": "Host is offline",
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
until := time.Now().Add(time.Duration(in.Days * 24 * float64(time.Hour))).Unix()
|
||||
if h.history != nil {
|
||||
// Display-only: a device whose login event has not landed yet still got
|
||||
// the command, so a missing record must not turn this into a failure.
|
||||
h.history.SetTransfer(in.ID, target, until)
|
||||
}
|
||||
h.audit(c, false, auditDeviceTransfer, map[string]any{
|
||||
"device_id": in.ID,
|
||||
"target": target,
|
||||
"days": in.Days,
|
||||
"until": until,
|
||||
"ok": true,
|
||||
})
|
||||
h.broadcastAuthenticated(`{"cmd":"devices_changed"}`)
|
||||
c.queue(mustJSON(map[string]any{
|
||||
"cmd": replyCmd, "ok": true, "id": in.ID, "target": target, "until": until,
|
||||
}))
|
||||
}
|
||||
|
||||
// handleDeleteUser removes an account and revokes any of its live sessions.
|
||||
// Admin-only. The bootstrap "admin" account is rejected at the wsauth layer.
|
||||
func (h *wsHub) handleDeleteUser(c *wsClient, raw []byte) {
|
||||
|
||||
Reference in new issue
Block a user