Commit Graph
20 Commits
Author SHA1 Message Date
yuanyuanxiang 63c7cdf588 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.
2026-11-20 12:23:08 +01:00
yuanyuanxianganddeepseek-flash 80c7d1ed53 Fix(go): decode Windows host names with the system code page
The web console showed Chinese computer names as a run of U+FFFD.
ParseLoginInfo sent every string field through the UTF-8 decoder once a
client advertised CLIENT_CAP_UTF8, but szPCName and the OS string are not
covered by that bit: Windows fills them from gethostname(), a narrow API,
so they carry CP936/GBK even on modern clients. The MFC server decodes
these two fields with CP_ACP (HostJson.cpp::AnsiToUtf8), which is why the
Windows server and its web view were never affected.

A new DecodeLoginAnsiField picks by client type instead of capability:
LNX/MAC/macOS/APK are UTF-8 (they build the field from a UTF-8 host name
or, for Android, the device model), everything else is GBK. "macOS" is
what pre-1.0 macOS builds report; GetClientType sends "MAC" today and the
MFC WebService still accepts both. ASCII host names come out
byte-identical either way, and legacy clients keep the name they had.

Reserved keeps its capability-based decoding, so UTF-8 file paths and
locations are untouched; OS strings are ASCII in practice. The one case
that gets worse is a Windows machine running the "Beta: Use Unicode UTF-8"
locale, which will now mojibake there. Sniffing UTF-8 to cover it would
misfire on real GBK names -- 930 of 6763 GBK hanzi pass as a UTF-8
two-byte sequence, roughly 2% of two-character names -- so the
deterministic rule wins and the trade is written next to the function.

Tests cover GBK names from capable and legacy clients, UTF-8 names from
Linux, Android and legacy macOS, and Reserved still honoring the bit.

Co-Authored-By: deepseek-flash
2026-11-14 11:42:32 +01:00
yuanyuanxianganddeepseek-flash 9ce1a58bc3 Feature(Go): read_file over the V2 stream receiver
read_file reuses the list_files handshake: COMMAND_LIST_DRIVE opens the
file-manager sub-conn, which then gets
[CMD_DOWN_FILES_V2][targetDir\0][path\0][\0] and streams
COMMAND_SEND_FILE_V2 chunks plus a COMMAND_FILE_COMPLETE_V2 carrying the
whole-file SHA-256. Windows clients open a fresh authenticated sub-conn
for the chunks; POSIX clients stream on the file-manager conn itself, so
that conn is retired when the call ends rather than right after the
request. TOKEN_DOWNLOAD_ERROR on the file-manager conn maps to -32009 /
-32010 / -32000 like the Win32 server.

Bytes land only in a per-call os.MkdirTemp dir; the client name is
checked against the target dir (separator-normalised, path.Clean, so
..\.., absolute, UNC and mixed separators are refused) as
defence-in-depth, never used as a path. First chunk enforces the size
gate (ReadMax) and rejects multi-file batches, so an expanded directory
fails with -32602 instead of returning its first file. Chunks from a
sub-conn opened for an earlier call are dropped by connection ID, data
sub-conns are closed when the call ends, and a closed sub-conn fails the
call fast instead of waiting for the stall watchdog.

Text windowing, encoding detection (BOM / UTF-8 / GBK / explicit /
latin1) and EOL handling mirror McpServer.cpp. Verified with the Debug
ghost on Windows 11 and the WSL Ubuntu ghost: .env text plus newline is
byte-identical, sha256 equals SHA-256 over the file, windows/GBK/empty/
max_bytes/directory/size-gate/missing-path/POSIX-path cases all pass.

Co-Authored-By: deepseek-flash
2026-11-12 23:04:35 +01:00
yuanyuanxianganddeepseek-flash d7accf1d30 Feature(Go): list_files over the file-manager sub-connection
The MCP server could not browse a device's file system. It now sends
COMMAND_LIST_DRIVE on the main connection, waits for the client to open
its file-manager sub-connection and report drives, then reuses that same
sub-connection for COMMAND_LIST_FILES with the directory path. Replies
are TOKEN_DRIVE_LIST, TOKEN_FILE_LIST or TOKEN_FILE_LIST_ERROR, decoded
from the same GBK the C++ client writes on every platform.

An empty or missing path returns the drive list, matching the published
tool description. Any other path, including /, lists one level of that
directory; the Win32 server folds / into the drive list, but doing so
would make a POSIX root listing unreachable. Entries carry name, isDir,
size and an mtime converted from FILETIME, and the 500-entry cap matches
the served contract and the Win32 parser; a truncated listing says so in
the summary. The reply is paged with the usual limit/offset window.

Errors are translated like the Win32 server: win32 5 is a permission
error, 2 and 3 are not-found, anything else is internal. Legacy clients
stay silent instead of reporting an error, which surfaces as a timeout
with an explanation.

The sub-connection is a resource the client allocates per call, so one
deferred cancel is the single retirement point: it reports the sub-conn
it saw and that connection is closed on every exit path, including a
call that gives up while the drive list is already queued. Packets that
arrive after the call returned are treated as orphans and retired, and
only the connection that answered the drive-list phase may answer the
directory request.

Also add a uniqueness test over the command and token byte constants,
and SendToConn so sub-connections are written through the hub's framing
path instead of a raw conn write.

Co-Authored-By: deepseek-flash
2026-11-12 22:34:17 +01:00
yuanyuanxianganddeepseek-flash 5227d4d78e Feature(Go): get_screenshot over the main-connection preview RPC
COMMAND_SCREEN_PREVIEW_REQ (247) / TOKEN_SCREEN_PREVIEW_RSP (248) is a
request/reply pair on the device's main connection: the client captures,
scales and encodes the frame itself, so no sub-connection is opened and no
screen-session slot is taken. get_screenshot can therefore run while a
human is watching the same machine.

The server keeps one pending request per device in a small table, matches
replies by reqId and drops foreign or late ones, and bounds a round trip
with an 8s timer. A missing CLIENT_CAP_SCREEN_PREVIEW bit is refused with
-32005 before anything is sent; region/window/monitor parameters are
refused with the same code because the v2 CLIENT_CAP_SCREEN_REGION
extension is not implemented in this build. Status 4 maps to -32602
because the caller can fix the target, while capture/encode failures stay
-32000.

Windows clients return JPEG directly. Linux clients have no JPEG encoder
and return top-down BGRX, which the server converts (R/B swap, opaque
alpha) before wrapping the frame as an MCP image item. The image item is
new to the content envelope; text tools keep text-only items.

Verified live against x64\Debug\ghost.exe (JPEG FF D8 FF, decoded size
matches metadata, max_width clamped to 64) and against linux/ghost under
WSL (BGRX path, valid JPEG, black frame from the known Xwayland capture
limitation). gofmt/vet clean, unit and -race tests green.

Co-Authored-By: deepseek-flash
2026-11-12 22:07:07 +01:00
yuanyuanxianganddeepseek-flash 599c891c00 Feature(Go): terminal_exec with sentinel cleaning and polling
Implement M4b of the Go MCP minimal plan: terminal_exec runs one command in a
device's persistent shell and polls the rest of a timed-out command.

Wire format follows the Win32 server: ConPTY sends "@echo off & <cmd>" plus a
sentinel line carrying %errorlevel%; POSIX PTY clears PS1 and uses $?. Output
cleaning is a byte-faithful port of the MFC stages (ANSI, CRLF, echoed input,
sentinel remnants) and is shared by commands and polls.

A timed-out call leaves the session and the command running; the next call with
only session_id delivers from the cursor it left. Per-window output is bounded
by max_output_bytes, truncated on a line boundary, and ring evictions are
reported as dropped_bytes. When the shell dies mid-command the session stays
reachable until its buffered tail has been polled, then is released without
touching the hub, which may already belong to a new viewer.

Adds ClientCapTerminal (0x8000) for the Android gate; older APKs, macOS and
legacy non-PTY shells are refused with -32005.

Co-Authored-By: deepseek-flash
2026-11-12 21:38:00 +01:00
yuanyuanxianganddeepseek-flash 774c0d2545 Feature(Go): four local MCP read tools and a shared audit query package
Implement milestone M2 of the minimal MCP plan: the tools that answer from
the server's own state instead of opening a device channel.

- Extract the audit-log scanner from web into package auditquery so the
  admin page and get_audit_log share one implementation. The web handler
  keeps its 500-row cap, the MCP tool uses the protocol's 1000-row cap.
  Query gains json tags for the web snake_case wire format (device_id,
  warn_only) and reports TotalAll before filters.
- Add package buildinfo and inject Version/Commit with -X from build.ps1
  and the Makefile; go-winres refreshes Windows resources from the git tag
  when available. An unversioned build reports "", and only initialize
  substitutes "dev".
- list_hosts: online/offline pools, include_offline merge, every
  documented filter, limit/offset paging with total/totalAll/hasMore, and
  schema-named host fields (authStatus/tls/remark are never fabricated).
- get_host_detail: single id or a batch of up to 50, online lookup then
  the last history record, capabilities from protocol.SupportsCap plus the
  Windows/registry/virtual-desktop rules; v2 is not listed.
- get_server_status: version, uptime, online/offline counts, port and
  bind. sessions stays absent until the MCP session table lands in M3.
- get_audit_log: case-insensitive event substring, keyword, paging;
  hasMore turns false at the MaxOffset clamp so paging cannot loop.

Wire hub, history, audit path and listen address through mcp.Config from
cmd/main.go. Tests cover pools/filters/paging, capability bits, batch
failures, audit paging and the unversioned build.

Co-Authored-By: deepseek-flash
2026-11-12 20:55:18 +01:00
yuanyuanxianganddeepseek-flash 81f0d6c031 Fix(server,client): keep web terminal alive across heartbeat reconnects
The Go server answered TOKEN_HEARTBEAT with a 33-byte CMD_HEARTBEAT_ACK,
while the Linux and Android clients gate the ACK on 1 + sizeof(HeartbeatACK)
(1025 bytes) and silently drop anything shorter. Their application-level ACK
watchdog therefore never got fed and disconnected the main connection every
60s. Each re-login replaced the whole hub.Device, wiping the screen/shell
sub-conn bindings that ride their own TCP connections, so a web terminal kept
receiving shell output while every keystroke was dropped — the "terminal goes
unresponsive after a while" symptom — and the shell could no longer be torn
down (orphan bash + leaked sockets).

Clients now accept the 32-byte old ACK (Windows already did), and the server
sends the full 1024-byte struct. Hub.Register carries the sub-conn session
state across a re-login, and the disconnect cleanup is pinned to the
connection it belongs to so a stale OnDisconnect cannot tear down a
registration that has already replaced it. A shell sub-conn that can no
longer be bound now tells the viewer instead of leaving the pane waiting.

Verified on aa: RTT restored, zero "Heartbeat ACK timeout" lines, main-conn
port stable; Go build/vet/test pass. Server deploy to the Go host is still
pending, so un-upgraded clients will keep reconnecting until then.

Co-Authored-By: deepseek-flash
2026-11-12 11:03:57 +01:00
yuanyuanxianganddeepseek-flash b1ddec1b8a Feature: Offline device history with delete and remote uninstall
Persist every device that has ever logged in to the Go server in a small
JSON store (devices.json, overridable with YAMA_DEVICES_FILE and capped by
YAMA_DEVICES_MAX, default 1000 newest). The store follows the users.json
convention: atomic temp-file write with fsync and rename, a 500 ms debounce
for bursts of reconnects, first_seen preserved across logins, and pruning
that evicts offline records before devices that are still connected.
Devices connected at shutdown are stamped offline before the final flush so
last_seen stays accurate across restarts.

The server advertises an offlineDevices capability and device_list now
appends historical devices that are not online, marked with online:false and
last_seen. The web UI shows an Offline checkbox after Total/Showing (state
kept in localStorage), renders offline cards dimmed and dashed, and always
lists them in the screen-wall sidebar. Older servers without the capability
keep the online-only list.

Grid and List cards gain a delete button after the terminal button, admin
only, behind a confirmation dialog. Deleting an offline device removes its
history record; deleting an online device first sends the single-byte
TOKEN_UNINSTALL command (matching the MFC OnOnlineUninstall flow) and then
removes the record too, so the device does not come back as a dead offline
entry. The agent's own disconnect then runs the existing cleanup path:
screen and terminal sub-connections are closed, the hub entry is removed,
and browsers receive device_offline to release their watch sets, wall
sessions, and stream references. Wall mode exposes no delete action.

Tests cover history persistence/pruning/recovery, offline ordering, the
device_list merge, and all three delete outcomes (offline removal, online
uninstall with a single 0x3F byte, and viewer rejection).

Co-Authored-By: deepseek-flash
2026-10-18 17:54:30 +02:00
yuanyuanxianganddeepseek-flash 1922f87dd2 Feature: Multi-device screen wall on the Go server
Bring the Go web backend up to parity with the MFC server's screen wall.
A browser tab can now stream several devices over one WebSocket: the
single `watching` field becomes a per-connection watch set guarded by the
hub mutex, capped at 32 devices per socket. The challenge advertises
`caps.multiWatch` and `caps.keyframeRequest`, binary frames stay keyed by
the low 32 bits of the device ID, and connect/disconnect replies echo the
device id and request id so the wall can route concurrent responses.

Input commands (mouse, key, clipboard, rdp_reset) resolve their target
from the watch set: an explicit id must be a current subscription, and an
absent id is accepted only while exactly one device is watched. Legacy
frontends that do not send `multiWatch` keep replace-all semantics, so a
repeated device switch cannot grow the set without bound. Offline
devices are removed from every watch set, and teardown is computed from a
snapshot taken outside the hub lock to avoid re-entrant locking.

Add the `keyframe` command: it replays the cached IDR, then asks the
device to emit a fresh one, rate-limited to one request per device per
second. This exposed a Go-only corruption bug: the client answers the
request with TOKEN_KEYFRAME (134), which the dispatcher treated as a
no-op. That token only appears on forced IDRs because the client's GOP is
effectively infinite, so the dropped IDR left the browser decoding
P-frames against a reference chain it never received, producing
persistent garbling. Relay it as a keyframe instead. Also drop the
cached IDR when the resolution changes, mirroring the C++ server, so a
late joiner cannot receive an old-geometry keyframe.

Add tests for the watch-set transitions and for relaying TOKEN_KEYFRAME.

Co-Authored-By: deepseek-flash
2026-10-18 11:51:28 +02:00
yuanyuanxianganddeepseek-v4-pro 0c04f7516b Feature: Web remote desktop bidirectional text clipboard sync
Add keyboard-shortcut (Ctrl+C / Ctrl+X / Ctrl+V) text clipboard transfer
between the browser and the remote desktop, reusing the clipboard protocol
that already exists in the native viewer (COMMAND_SCREEN_GET_CLIPBOARD=24,
COMMAND_SCREEN_SET_CLIPBOARD=25, TOKEN_CLIPBOARD_TEXT=118) so the client
needs no change.

Local -> remote: pressing Ctrl+V reads the browser clipboard, pushes it to
the remote clipboard (UTF-8 -> GBK, matching the client's CF_TEXT/ANSI
handling) and then synthesizes a remote Ctrl+V so the pasted text is the
newly delivered one.

Remote -> local: Ctrl+C or Ctrl+X is forwarded to the remote as usual and,
after a short delay, the remote clipboard is pulled back and written to the
browser clipboard for a later local Ctrl+V.

Both the MFC and Go servers get the same three clipboard signaling paths
(clipboard_set, clipboard_get, clipboard_text) so the shared single-page
frontend behaves identically on either backend.

Co-Authored-By: deepseek-v4-pro
2026-10-17 19:52:38 +02:00
yuanyuanxianganddeepseek-v4-pro a447452521 Fix: Silence SOCKET_DLLLOADER log flood and tighten device-port logging
SOCKET_DLLLOADER (210) is the shellcode / memory-DLL loader asking the
server for the full DLL payload before it can load the client. The MFC
master console serves it via SendServerDll; the Go web device port has no
payload to hand out, so every memory-DLL client startup/reconnect fell
into the default dispatch branch and logged "Unhandled command 210",
flooding the log. Add a protocol constant and drop the command silently.

While auditing the device-port logging surface:

- Downgrade wrapTLS's per-connection hex-dump lines and the screen-spy
  "[timing]" cold-start line from Info to Debug (they fire once per TCP
  connection / screen view and are diagnostics, not operational events).

- Distinguish a sub-connection hijack attempt from a plain orphan: when a
  screen/terminal sub-conn claims a MasterID from a source IP other than
  the device's login conn, log a dedicated Warn instead of mislabeling it
  as "orphan ... unknown device".

Co-Authored-By: deepseek-v4-pro
2026-10-16 12:26:35 +02:00
yuanyuanxianganddeepseek-v4-pro 7651ee8602 Feat: ConnAuth HMAC verification gated by YAMA_CONN_AUTH_KEY
Verify the HMAC-SHA256 signature and timestamp of device sub-connections
(screen/terminal/file) when the YAMA_CONN_AUTH_KEY environment variable is
set. With the key set, a sub-connection whose signature or clock skew fails
is answered with a non-OK ConnAuth status and dropped; without the key the
legacy always-OK behavior is preserved.

The key is never compiled in: it is read from the environment at startup, so
no secret enters the repository. Source-IP binding in hub.BindScreenConn
remains in place as defense-in-depth.

Co-Authored-By: deepseek-v4-pro
2026-10-15 19:43:58 +02:00
yuanyuanxiang 8c7f612449 Feature: Implement H.264 and AV1 hardware encoding for remote control
Remark: Need to update FFmpeg static libraries to take effort
2026-05-30 00:12:38 +02:00
yuanyuanxiang d757c33bcb Fix(Go): stable device list ordering + RDP-reset handler
Fix UTF-8 login text decode + stale screen sub-conn retirement
2026-05-19 16:28:32 +02:00
yuanyuanxiang d7f38ecfdb Feature(Go): Web terminal relay with PTY mode and graceful close (Phase 6) 2026-05-18 22:06:07 +00:00
yuanyuanxiang 6485e800d6 Feature(Go): Mouse/keyboard input + user management with users.json (Phase 5 + 7) 2026-05-18 22:06:07 +00:00
yuanyuanxiang fba4143dd1 Feature(Go): Screen frame relay end-to-end with graceful client BYE (Phase 4) 2026-05-18 22:06:07 +00:00
yuanyuanxiang 4ea6ed252c Feature(Go): Web auth, WebSocket signaling and live device list (Phase 3) 2026-05-18 22:06:07 +00:00
yuanyuanxiang 5a325a202b Init: Migrate SimpleRemoter (Since v1.3.1) to Gitea 2026-04-19 22:55:21 +02:00