Commit Graph
100 Commits
Author SHA1 Message Date
bluebluesodaandCommandCodeBot 5169373918 fix(transfer): make the import work against a real Incus, and create the account
Everything below comes from running the feature against two real hosts, where
the assumptions that read fine in the source turned out not to hold.

The receiving side now creates the account instead of replacing one. That is
both simpler and safer: the name must be free, the account is built by the
same code `vps add` uses — same IP, port block, IPv6 assignment, firewall
rules and panel row — and the disk of the container that produced is then
replaced by the transferred one. Nothing that already exists is touched, so
every failure is undone by deleting what was created, and the host ends up
exactly as it was. It also drops the whole staging/rename dance the previous
shape needed.

What the real daemon taught us:

- A direct-stream export (Accept: application/octet-stream) refuses a backup
  name: no backup object is created, so the field must not be sent at all.
- Incus validates device configuration while it CREATES the instance, so the
  archive's own devices — the source host's IPv6 — are rejected before any
  later fix-up can run ("not within network incusbr0 subnet"). This host's
  devices therefore go in as part of the import, via X-Incus-devices. Without
  them the source's disk quota comes along too: an 8 GiB account arrived on a
  host that had allotted 5.
- A static IPv4 is handed out through a DHCP reservation held by the current
  lease, and Incus counts a static address as taken by ANY instance that
  declares it, stopped ones included. The container being replaced therefore
  has to be gone before the replacement starts, or the replacement is given a
  dynamic address from the pool — and then nothing can reach it, because the
  panel's records and the host's DNAT rules all name the static one.
- The re-key step appends this host's IPv6 address, routed block and gateway
  neighbour to the container's networkd file, checking only for its own
  values. A container that arrived from another host kept that host's address
  as a second global one, so the stanza is now cleared first.
- An archive carries the source's volatile.<nic>.hwaddr, so importing the same
  archive twice on one host failed outright with "MAC address ... already
  defined on another NIC". Per-instance volatile keys are now dropped, like
  the machine-id and SSH host keys before them.

Also from the field: the re-keyed container is checked to actually hold its
assigned IPv4, the quota travels in the printed receive command (--cpu/--mem/
--disk/--bandwidth/--days), and the receiving command's <user> must be free —
receiving onto a taken name is refused before the download rather than after.

Verified on two hosts (Ubuntu 24.04 and 26.04, Incus 7.0.1, zfs): a 316 MiB
container moved and took its data (files, setuid bits, modes, a custom user,
a 200 MiB file), a fresh hostname/machine-id/SSH host key, cleared
authorized_keys, the transferred quota, its assigned static IPv4 and only this
host's IPv6; reachable over its published SSH port. The same archive imported
twice into two accounts; --optimized (zfs-native) likewise; a wrong
certificate pin refused in under a second with nothing created; a mid-import
failure rolled back to no account, no container and no files; idle exit, SIGHUP
and a killed CLI all left no archive behind.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-18 17:54:22 +00:00
bluebluesodaandCommandCodeBot 01935f50a8 feat(transfer): move a container's disk between two hosts
Two vpsmgr hosts that share nothing but a network can now hand a container's
root disk over: `vps transfer send <user>` exports the stopped container to a
single archive and serves it from a temporary listener, and
`vps transfer receive <url> <user>` fetches it, verifies it, and rebuilds the
container from it. It is what an operator needs to move a customer between two
machines in different datacenters, where the existing snapshot sharing cannot
reach: that feature is a copy-on-write clone inside one pool, so no byte ever
leaves the host.

Only the disk travels. Domains, SSH keys, quotas, expiry, bandwidth and
resource history are configuration this host owns and deliberately keeps to
itself -- the two hosts do not share admin keys -- so the receiving side
re-homes the container onto its own address, ports and quota instead of
adopting the sender's.

Decisions worth recording:

- The archive is an instance backup streamed with Accept:
  application/octet-stream, so Incus sends the tarball straight down the
  socket and nothing is staged in the storage pool first. Publishing an image
  would have been the cleaner artefact but it materialises the whole rootfs
  inside the pool, which fails on exactly the nearly-full hosts a migration
  tends to involve.
- The transfer runs as root from the CLI and has no panel entry. It puts a
  user's disk on the network; no panel request should be able to do that.
- The certificate pin and the archive checksum both ride in the URL fragment,
  which HTTP clients never transmit, so the pasted command carries the whole
  trust decision and the listener never learns either value.
- An import parks the container it replaces under a temporary name and brings
  the new one into place only after it starts and provisions. A failure at any
  point puts the original back, rather than leaving the user with nothing.
- The listener stops after five idle minutes and the archive is deleted on
  every exit path, including SIGINT/SIGHUP during the export itself.

- lx: a deadline-free HTTP client for the transfer (the 60s cap would abort
  any real transfer), plus BackupExport/BackupImport/ReplaceConfig/DiskUsage
- lx: ReplaceConfig replaces an imported container's configuration wholesale
  while carrying the daemon's volatile.* keys through unchanged
- mgr: the export/import orchestration, including fresh machine-id and SSH
  host keys (a copied rootfs otherwise makes two hosts claim one identity)
- mgr: a temporary HTTPS listener with one path, Range support for resuming a
  dropped download, and a stalled-connection guard
- cli: `vps transfer send|receive`, live progress on both sides, space
  checked against the container's actual size before a long export starts
- tests: pinning, checksum, resume, unknown-token, URL parsing, idle exit

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-18 16:24:04 +00:00
bluebluesodaandCommandCodeBot e8c29c4a4e fix(db): ignore future-dated resource samples when reading history
A host whose RTC came up eight hours fast at boot -- systemd-timesyncd
corrected it seconds later -- took its very first resource sample before that
correction, so the row was written with a sample_minute eight hours in the
future. The sampler kept recording normally, but that single row won
MAX(sample_minute) forever, so every reader served the stale boot-time
snapshot: both panels showed all containers Stopped with no CPU or memory until
wall-clock caught up. Restarting does not help, because the row lives in the
database.

Reads cannot tell a mis-dated row from a legitimate one -- a clock jumped
forward and a machine powered off for hours look identical from inside -- so
the guard belongs on the read side, not the write side:

- LatestResourceSamples picks the newest sample at or before now rather than
  the newest overall, so one future-dated row can no longer freeze the panels
- ResourceHistory, behind the user panel's 24h chart, skips future-dated
  samples for the same reason
- the row is still stored, and the real sample overwrites it in place once
  wall-clock reaches that minute, so the series keeps no gap or duplicate
- tested: the future sample is persisted but never served by either reader

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-18 07:04:00 +00:00
bluebluesoda 18a680b924 Merge dev-webssh: a browser terminal for the container 2026-09-17 13:47:37 +00:00
bluebluesoda 9ad52438c6 fix(web-ssh): draw the cursor on the alternate screen, and keep focus
Two reports, one of them plainly a bug of mine.

The cursor was never drawn inside vi. The renderer skipped it whenever the
alternate screen was active, on the theory that a full-screen program draws its
own -- but that screen is exactly where a cursor matters most: vi, less and htop
all run there, and an editor without one tells you nothing about where you are
typing. It is drawn whenever the program has not hidden it.

The other report was that Escape left the terminal deaf until the window was
clicked. That does not reproduce here -- a bare Chrome types straight through
after Escape, in vi and at a prompt -- but the symptom is unmistakably focus
leaving the panel's own element, and clicking only helps because the click hands
it back. Since this window is nothing but the terminal, it now takes the
keystroke itself when focus has drifted, and restores focus on the way. Whether
the browser really moves focus on Escape on macOS is still unconfirmed; this
makes the question moot for the user either way.
2026-09-17 13:36:57 +00:00
bluebluesoda 08cc747b32 fix(web-ssh): stop private CSI sequences turning into SGR attributes
Typing in vi left the whole session underlined. The stream vi sends contains
xterm's modifyOtherKeys, which carries a private ">" prefix:

  CSI > 4 ; m      and      CSI > 4 ; 2 m

A CSI sequence has four private markers — ? < = > — and the parser only knew
"?". The others were dropped on the floor, so their parameters leaked into the
final byte and ">4;m" was read as SGR 4 (underline on) with nothing left to
turn it off. All four markers are recognised now, and a private sequence is
never treated as SGR. The secondary device-attributes query (CSI > c) also gets
its own reply, so a program asking for it does not sit out its timeout.

Found by capturing the real byte stream from vi over a PTY and replaying it
through the emulator: the flags now come out clean, while a plain CSI 4 m still
turns underline on as it should.

Reported alongside it: after leaving insert mode with Escape the shell seemed
to stop accepting keys until the window was clicked. That does not reproduce
against a bare browser here — the same sequence types ":wq" straight through —
so the likely culprit is an input method leaving its composing flag set, which
would swallow every later key. The guard now trusts our own compositionstart/end
tracking instead of the browser's flag, and a committed composition still
reaches the shell.
2026-09-17 13:18:35 +00:00
bluebluesoda e3c2b851e4 feat(web-ssh): a small key bar, and fix the paste shortcuts
The key bar carries only what a browser will not hand over: Ctrl+C, Ctrl+Z,
Ctrl+D, Escape, Tab and the arrows. It is a fallback, not the way to use the
terminal — typing works for everything else, and the bar deliberately does not
take focus so the keyboard keeps it. The arrow buttons ask the emulator for the
sequence, so they follow the mode a full-screen program requested just like the
real keys do.

Paste was broken on Windows and Linux. Ctrl+V fell through to the control-key
mapping and sent 0x16 with preventDefault, so the browser never got to fire a
paste event, and Shift+Insert did the same with the Insert sequence. Both, and
Ctrl+Shift+Insert, are now left to the platform; Cmd+V on macOS already worked.

The control keys were wrong in a way only running it showed: a control byte
cannot be written into an HTML attribute, so data-raw="&#92;u0003" arrived as
six literal characters and the buttons typed them instead of sending them.
They carry a name now and the byte is looked up in JavaScript.

Verified against a real container: the bar's bytes (003, 032, 004, 033, ESC[A-D),
arrows inside less, Tab completion, Ctrl+V and Shift+Insert pasting, Enter
running a two-line paste, and Ctrl+C copying when something is selected.
2026-09-17 12:44:36 +00:00
bluebluesoda 69f1e3a47b fix(web-ssh): send the physical key, and drop a protocol message nobody sends
Two things the key testing turned up.

Alt was wrong on macOS. Option+a arrives as the composed character "å", so
sending e.key put that in the shell instead of Meta-a. Both Alt and Ctrl now
take the letter from e.code (the physical key), falling back to e.key when a
browser does not report it; non-letters keep the plain ASCII mapping, which is
what makes Ctrl+[ an Escape.

The "bye" message was dead: the page never sends it, so the handler arm could
never run.
2026-09-17 12:33:00 +00:00
bluebluesoda 5e28fc2983 feat(web-ssh): make the terminal survive a bad connection, and gate it
A browser reaching this panel is often a long way away, so the session is now
built to survive the link rather than be torn down by it.

Liveness first, because the old numbers were wrong: pings every 20s with a 60s
deadline. The previous setting was a single 15-minute timer, and since the
browser answers pings automatically it never fired for an idle user — the one
thing it did do was take fifteen minutes to notice a peer that had vanished.

- the shell outlives the socket. When the client goes away the PTY keeps running
  for 120s with its output landing in a 256 KiB ring (with a notice if anything
  is dropped). A client that comes back with its token resumes the same shell, so
  a tunnel, a cell handover or a sleeping laptop no longer costs a running build.
  The token travels in the first frame rather than the URL, is bound to the user,
  and lives in sessionStorage — reloading resumes, closing the window lets go.
- the page has its own heartbeat: a browser cannot see protocol-level pings, so
  the server also sends a small JSON one and the page reconnects with exponential
  backoff and jitter after 45s of silence, up to eight attempts.
- a handshake that neither completes nor fails would otherwise stall the retry
  loop for good, so an attempt that has not opened in 15s is abandoned.
- at the per-user cap the client is offered its slots back instead of being
  refused, which is the only way to reclaim a window the user can no longer see.
  Where there is room, the count is just a notice.

Three bugs the browser testing turned up, all of them real:

- Pty writes had no deadline, so a wedged Incus connection blocked the handler
  forever — resume hung after any pause long enough to break that socket.
- a chunk whose write failed was neither delivered nor buffered.
- a session stayed resumable between Close and the end of its drain.

An operator can now turn the whole thing off with `vps config set panel.web_ssh
false`: the button is not rendered and the page, the script and the connection
all refuse. It defaults on, including for a config written before the setting
existed.
2026-09-17 12:13:02 +00:00
bluebluesoda 4a17a95d85 feat(panel): give Web SSH its own window and a shell-styled button
The terminal was a modal, which is the wrong container for it: a floating dialog
cannot be dragged to a larger size, moved to another screen or maximised, and
the terminal is exactly the thing that wants more room.

- the button moves up next to Start/Stop/Restart and is renamed Web SSH, which
  is what people look for. It is styled apart from every other control on the
  page on purpose: black key, green type, monospace, with a ">_" prompt in
  front, so it reads as a remote shell at a glance.
- clicking it opens /webssh in its own browser window. That window is resizable
  like any other, carries a Fullscreen button, and remembers the size it was
  last dragged to so the next open comes back the same way. A blocked popup says
  so instead of doing nothing.
- the overview page no longer loads the terminal engine at all; it only exists
  in the shell window now.

Verified against a real container in the popup: prompt, typing, and a window
resize reaching the PTY (stty size moved from 26 99 to 16 86 when the terminal
area changed), which is the thing a modal could never do.
2026-09-17 11:29:22 +00:00
bluebluesoda 51a451ab1e feat(panel): a terminal in the browser for the account's own container
Adds a Web SSH-style terminal to the user panel, opened from the overview page.

It is deliberately not SSH. The container runs on the same host, so Incus' own
exec API with a PTY is the transport: no sshd, no keys to distribute, no network
path to arrange, and none of the credential handling a real SSH hop needs.

- lx gains an interactive session beside the fire-and-collect Exec: stdin stays
  open, output streams as it is produced, and the window can be resized while the
  shell runs. Exec and Attach now share the request-and-dial path.
- the panel serves /terminal over a WebSocket. That handshake is a GET, so the
  panel's POST CSRF check never sees it, and SameSite does not cover it the way
  it covers a form post — csrf.SameOrigin is what stands in for both. The handler
  also takes the container from the session and never from the request, refuses
  expired accounts, caps concurrent shells per user, and closes idle ones.
- the browser side is a small VT emulator, hand-written because the panel ships
  as a single binary with no build step and a CSP that allows no third-party
  scripts. It covers the usual CSI/SGR set, the alternate screen, scrollback,
  UTF-8 including wide characters, and an IME via a hidden textarea so composed
  text (Chinese, Japanese) reaches the shell. Terminal output is escaped, never
  treated as markup.

Two protocol details were worked out against the running daemon rather than
assumed, and both are pinned by tests: an interactive exec returns only fds "0"
and "control" (stdout is folded back into "0"), and the resize message carries
its size as strings inside "args" — top-level width/height are silently ignored.

Checked against a real container: prompt, line wrapping, ANSI colour, CJK
output, less, a full-screen program (top), scrollback and window resize, with
the session ending and reporting its exit status when the shell exits.

Also fixes test isolation, which surfaced while running the suite on this host:
the panel and admin test servers used the default Incus socket, so tests that
drive /power, /reinstall and friends acted on whatever real instance shared a
fixture user's name — on this machine, restarting the real "alice" on every run.
Both now point the client at a socket that cannot exist. The suite also got
faster (panels 12s -> 7s) from no longer waiting on real timeouts.
2026-09-17 10:30:48 +00:00
bluebluesoda b703791d73 fix(ui): rework the knowledge-base blanks and trim the batch-create form
User-panel knowledge base:

- a blank is now an exam-style underline instead of a box: no background, no
  padding, and a height pinned to one line, so it no longer stretches the code
  line it sits in. The placeholder is a clear yellow and the value keeps the
  code's own colour;
- the width still follows the content, so a long pasted key extends the
  underline while the rest of the line stays readable;
- the copy button is always present now, not just once every blank is filled: a
  block may legitimately have optional or annotated blanks, and copying then
  yields the text with those parts left empty;
- it starts breathing as soon as any blank in that block has content, and the
  glow is actually visible (accent background plus a scale pulse) rather than
  the button simply appearing;
- "copy all" moved up next to Close on the same row, and says what it does.

The blank styling also had to be scoped to .kb-article: the panel's generic
input[type=text] rule is more specific than a bare class, so it was winning and
painting the blanks as form fields. Caught by looking at the rendered page.

Admin panel: the batch form carried a paragraph of explanation per field.
Dropped the parentheticals and the "either way is fine" notes, leaving one
short hint on the username box.
2026-09-17 09:45:04 +00:00
bluebluesoda fc59c7387d Merge dev-1.10: knowledge-base blanks, opt-in init script on shared reinstall, batch user creation 2026-09-17 03:45:02 +00:00
bluebluesodaandCommandCodeBot 3fb5cd9ea9 feat(admin): batch create users from a shared checkpoint
Creating users one at a time does not scale when they are all carved out of the
same prepared machine, so the admin panel now takes a list:

- one username per line, a shared snapshot UUID, the operator keys to activate
  on the new machines, and the resource quotas for the whole batch;
- the whole list is checked up front — syntax, duplicates, names already taken —
  and a single problem creates nothing, so a rejected batch never leaves a
  half-built account behind;
- the run happens in the background and the page polls for progress. It has to:
  each user is a serial clone that takes tens of seconds, while the panel's
  WriteTimeout is 60s, and a truncated response would also lose the one-time
  passwords, which exist only in memory;
- only one batch runs at a time (creations are serialized by the manager
  anyway) and the list is capped, so a pasted wall of text cannot churn the host.

Cloning is a new branch of Manager.Add rather than a parallel code path, so the
identity allocation (IPv4 slot, SSH port, user-port block, IPv6 block), the DB
row, the firewall and the rollback all stay in one tested place. Two clone-only
fixups are mandatory, not optional:

- the clone carries the source's /root/.ssh/authorized_keys, which would let the
  owner of the source checkpoint log straight into every new machine, so it is
  cleared even when no operator key was ticked;
- it also carries the source's machine-id, and a duplicate DUID makes dnsmasq
  drop DHCPv6 leases.

The ticked operator keys reuse the existing admin_keys / admin_key_grants pair:
the batch just writes the grants the user would otherwise tick themselves, and a
failure there is reported next to that user instead of failing the container,
which is already usable at that point.

Checked end to end against a real Incus on the test host: a clone of another
user's snapshot came up with its own machine-id, hostname, IP and SSH port, with
the source's key gone and the operator key written as Vpsmgr-Operator. The host
was left exactly as found (container, nftables files and ruleset all restored).

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-17 03:37:25 +00:00
bluebluesodaandCommandCodeBot 653866332e feat(reinstall): opt-in init script when installing from a shared checkpoint
A clone carries the source checkpoint's whole state, so its init script was
deliberately skipped — re-running it would duplicate whatever the checkpoint's
owner had already done. But someone importing another machine's image often
does want their own bootstrap to run on top of it, so make it a choice:

- the reinstall form gains a "运行初始化脚本" switch that follows the share-code
  box: typing a UUID reveals it, clicking back to a plain image clears the code
  and hides it again;
- the state is never remembered — it ships unticked, is forced off every time
  the modal opens (which also defeats browser form-state restoration), and an
  unticked box never reaches the request body;
- rolling back the user's own checkpoint ignores the switch: the state came
  back from the checkpoint, not from an image;
- best-effort like a plain reinstall: a delivery failure warns and never fails
  the rebuild, since the container is already usable at that point.

ReinstallFromShare takes the flag as a parameter rather than reading it from
anywhere global, so the caller stays the only thing that decodes the form.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-17 02:29:50 +00:00
bluebluesodaandCommandCodeBot aad0caa4d4 feat(knowledge): fill-in-the-blank code blocks and copy-all
An operator can now write a prompt inside a fenced code block, where the
reader fills in the machine-specific part:

  REGINNAME=*#*#填写地域信息#*#*

- the hand-written renderer splits the fence body on the directive, escapes
  the literal runs as before, and emits an inline text input whose placeholder
  and node id both come from the label. The id is a hash of the label (plus an
  occurrence counter for repeats), so it is stable across edits and reordering
  with no server-side storage, and no value is ever emitted — the answer lives
  only in the reader's browser;
- a block containing blanks keeps its copy button hidden until every blank in
  that block is filled, then pulses to draw the eye. The copied text is rebuilt
  by walking the DOM, because innerText cannot see an <input>'s value;
- a new "copy all" button copies the whole article as Markdown with the same
  substitution. It is fence-aware: a directive in prose renders no input, so
  substituting it would shift every answer after it;
- the admin editor gains a one-line mention of the syntax, and its preview
  styles the blanks so the author sees what the reader will get.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-17 02:29:01 +00:00
bluebluesoda 309de4f7df Merge dev-1.9: HAProxy must load the published generation 2026-09-16 14:18:02 +00:00
bluebluesodaandCommandCodeBot 5c76576ffb fix(haproxy): load the published generation in the unit, not just the entry config
The installed unit started HAProxy with the static entry config alone:

  -Ws -f /etc/haproxy/haproxy.cfg

That file declares the frontends, the reject backends and the timeouts; the
per-domain backends and the routing maps live in the generation the panel
publishes, and the maps' paths point at it. So HAProxy came up healthy, bound
80/443 and answered 404 on :80 and closed every :443 connection — no managed
domain was reachable. `haproxy -c` on the entry config alone passes, which is
why the install-time check did not catch it.

- the unit now passes both files, the generation through "current" so a reload
  picks up whatever the panel published last;
- 30-haproxy.sh validates exactly that command line (entry + generation) and
  requires domains.cfg AND both maps before it considers the bootstrap
  generation in place, so the pre-start check can no longer pass a setup that
  serves nothing;
- tests: TestUnitLoadsBothConfigFiles parses the unit's own ExecStart and fails
  if it does not pass two config files, and TestUnitCommandLineRoutesTraffic
  runs that command line against a real HAProxy and asserts a registered host
  reaches its backend. Both fail against the old unit.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 14:17:43 +00:00
bluebluesoda 8b837c6269 Merge dev-1.9: bandwidth reset-day label and explicit destructive change 2026-09-16 13:39:48 +00:00
bluebluesodaandCommandCodeBot bbc90fbf74 fix(bandwidth): name the right month in the quota label; make the reset-day change explicit
Two problems with `panel.bandwidth_reset_day`, both around its interaction
with the quota period:

- The user panel hardcoded "至次月 N 号", which is wrong whenever the reset day
  is still ahead of today: the period in force started on that day of the
  PREVIOUS month, so it ends on that day of THIS one (reset day 22 on the 16th
  ends on the 22nd of this month). mgr.BandwidthNextReset derives the real
  moment, the page flags whether it lands in this calendar month, and the label
  follows. A test also pins it against BandwidthPeriod, so the label and the
  rollover can never disagree about the boundary.

- Changing the day DISCARDS every user's accumulated bandwidth totals. That is
  not an explicit reset: the counters are keyed by a period derived from the
  day, so moving the day moves the key and the next sampler pass sees a new
  period. It stays that way (it is the period model), but it is no longer
  silent: the key is classified ApplyDestructive, so `vps config set` shows a
  confirmation naming the loss, repeats it on the --no-apply path (where the
  loss lands at the next panel restart instead), and prints it after applying.
  docs/configuration.md explains the mechanism and points at the admin panel's
  per-user "重置流量统计" button for a deliberate reset.

TestApplyBandwidthPeriodChangeDiscardsTotals pins the discard so the warning
cannot quietly become wrong, and TestBandwidthResetDayIsDestructive keeps the
classification from regressing to a plain restart.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 13:39:39 +00:00
bluebluesoda d2396df7a2 Merge dev-1.9: HAProxy domain proxy 2026-09-16 13:16:50 +00:00
bluebluesodaandCommandCodeBot 8d2d31041f docs(ipv6): pin the pre-responder ndppd upgrade path
A host can sit on a pre-1.6 release (distro ndppd, old oneshot vps-ipv6.service)
for a long time before upgrading, so document and lock down how install.sh
converges it:

- the old ndppd/npd6 daemons are disabled and stopped, the unit is replaced by
  the in-tree responder, and the legacy per-address kernel proxy_ndp entries
  are swept on ipv6-reapply;
- /etc/vpsmgr/ndppd.conf is read AS-IS, so the nested `iface <bridge>` block
  and its indentation written by the old panel must keep parsing. Adds
  TestLoadRulesAcceptsPreResponderFile to a regression guard, since every
  existing container would lose inbound IPv6 if that format ever diverged;
- the old sudoers grants disappear with the rewritten whitelist, and the
  distro ndppd package is left installed but inert.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 13:07:13 +00:00
bluebluesodaandCommandCodeBot 4c93ae4be3 feat(haproxy): replace Traefik with a pinned HAProxy domain proxy
The panel now fronts user domains with HAProxy 3.4 LTS (official performance
packages) instead of Traefik: about 100 MB of RSS and 200 MB of disk saved for
a feature set that never used more than Host routing on :80 and SNI passthrough
on :443.

- hpx: publish the proxy configuration as immutable GENERATIONS. Every domain
  mutation renders the whole set from the DB, validates it with the pinned
  `haproxy -c`, and only then repoints the `current` symlink, so a rejected
  candidate leaves the running proxy untouched and a stale domain can never
  survive into a later generation. Routing is carried by two map files
  (Host -> backend, SNI -> backend): per-domain frontend rules cannot work from
  a second file because HAProxy rejects duplicate section names since 3.3 and
  attaches bare directives to the section opened last.
- mgr: republish and reload (SIGUSR2, i.e. `systemctl reload`) after every
  domain change, so a change takes effect without dropping established HTTP or
  TLS connections. Rollback semantics (DB first, then publish) are unchanged.
- cfg,db: `net.traefik` is renamed to `net.haproxy` with identical values. A
  pre-rename config.yaml key and the legacy VPSMGR_TRAEFIK env var are still
  read (new name wins), and schema migration v18 moves the settings mirror from
  `traefik` to `haproxy`, keeping a newer value when both rows exist.
- 30-haproxy.sh: install the pinned branch from the vendor repository and
  migrate a Traefik host in one run — install and validate HAProxy first, then
  remove Traefik's binary, unit, service account and dynamic rules (only its
  config file is kept, inert). No fallback keeps both proxies alive.
- upgrade-haproxy.sh: follow the pinned branch to its newest patch, with a
  configuration check and a graceful reload; `install.sh --update` runs it.
- tests: generation publish/rollback, map rendering, config-key and settings
  migrations, plus real-binary tests (skipped unless
  VPSMGR_TEST_HAPROXY_BIN is set) that run the generated configuration through
  `haproxy -c` and start it in a network namespace.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 12:59:13 +00:00
bluebluesodaandCommandCodeBot f6e0727ca4 ci(release): fetch the tag object before reading its notes
The release body is the tag's own annotation, but the runner's checkout only
had the commit — no tag object — so `git cat-file -t` failed and every release
silently fell back to "fix some bugs" (v1.8.0 included). The publish job now
fetches tags, and the notes step fetches the tag ref explicitly before reading
it, so the annotation always makes it into the release body.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 07:41:27 +00:00
bluebluesodaandCommandCodeBot 1c6df157a5 fix(mgr,db): make an unpersisted CPU cap self-correcting; refuse a gapped schema
Addresses two review findings:

- the dynamic CPU limit applied a cap and only then saved the active state. A
  failed save left the cap in place with no record, so it could never expire
  and switching the rule off would not lift it — the container would stay
  pinned to the reduced quota. The caps applied by a pass are now held back
  until the state is written; if the write fails they are lifted again (each
  back to the user's own quota) and the failure is reported. The quota writer
  is behind a one-method interface so the failure path is covered by a test
  that fails the state write with a trigger and asserts cap-then-rollback, plus
  a test that a failed rollback is reported rather than swallowed
- migrations only compared the highest recorded version, so rows missing from
  schema_migrations silently skipped a step and surfaced later as obscure "no
  such column" failures. The recorded versions must now form the unbroken run
  2..cur (v1 is the baseline, created unconditionally and never recorded) or
  the database refuses to open

The third finding (a failed cross-container share install deleting the old
container before the new one is up) is left as is: the user confirms a
reinstall that discards the data, and the retry costs nothing — Delete treats
an already-missing container as success (verified against the live Incus
socket), so the user simply installs again.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 07:31:11 +00:00
bluebluesodaandCommandCodeBot c2009ddc69 chore(copy): tighten 1.8 wording, drop the "was X (not Y)" asides
- admin CPU card: the "what saving does depends on the checkbox" footnote is
  gone; the state line says it instead, and the state/description text is
  shorter
- user panel: the reinstall share field is just "或从分享的检查点安装" and its
  note "将从该检查点恢复,不安装系统。"; the share warning no longer parenthesises
  the contents ("拿到分享码的人可以读取该检查点内的全部数据,包括容器里的凭据。"),
  the second confirmation is "确认删除 / 更早的 N 个检查点会被删除,无法恢复。",
  the revoke prompt drops the repeated question, and the restore/reset prompts
  lose their "…,确认?"/"(重置后无法恢复)" tails
- the share toast only mentions removed checkpoints when there were some
  (previously "share code created (0 older checkpoints removed)")
- expiry: "账户已到期,机器已关机并锁定。" and "该账户已到期,仅可延期。";the
  "new deadline = max(now, current) + duration" footnote and "(0 = permanent)"
  parentheticals are gone
- knowledge editor: label is a plain "Markdown: headings, lists, …" legend and
  the empty preview is a dash instead of an instruction
- docs: the 1.8 sections (expiry, snapshot sharing, refquota, sessions, CPU
  rule, knowledge base) are cut roughly in half

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 07:12:06 +00:00
bluebluesodaandCommandCodeBot 3c48c27cc3 fix(admin): the CPU limit card no longer claims to be in effect while it is off
- with the rule disabled the parameter inputs are hidden entirely (they were
  shown with values that had no effect), and a state line says which of the two
  states the rule is in; ticking the box reveals the parameters again
- the parameter fields lost `required`: they are prefilled from the server, the
  server validates every range, and a hidden-but-required input makes the
  browser refuse to submit with a "not focusable" error
- the save message now matches what happened: "saved and applied now" only when
  the rule is enabled, otherwise "saved — it is disabled, so no container is
  capped" (nothing is applied, and any capped container was just restored)
- the button is a plain "Save"; the effect depends on the checkbox above it

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 07:00:27 +00:00
bluebluesodaandCommandCodeBot 83f0f02d45 feat(panel,admin): fix knowledge preview, panel-native confirms, CPU editor, persistent admin sessions
User panel:
- the reinstall modal drops the system highlight as soon as a share code is
  typed, so "nothing selected" is an explicit state that says the container is
  rebuilt from a checkpoint rather than from an image; clearing the code
  restores the default image, and clicking a tile drops a stale code instead of
  letting it silently override the visible selection
- the time-machine actions (share/restore/delete/revoke, plus the sticky-notes
  reset) confirm in an in-page dialog styled like the panel instead of
  window.confirm(); publishing still asks twice when it would delete the older
  checkpoints

Admin panel:
- the knowledge-base preview renders again: it posts a FormData body
  (multipart/form-data) and ParseForm alone ignores multipart bodies, so the
  server rendered the empty string and the preview box stayed blank
- the dynamic CPU limit rule moves back to the panel: an editable card on the
  overview saves into the DB (the single source of truth) and applies on the
  spot, restoring capped containers when it is switched off. The cpu_limit.*
  config keys and their `vps config set` entries are gone, and `vps install`
  no longer touches the rule, so an upgrade cannot reset it
- admin sessions are persisted (new admin_sessions table, hashed tokens) so a
  panel restart no longer logs the operator out; a password change from the
  panel or the CLI still invalidates every other session

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-16 06:51:35 +00:00
bluebluesodaandCommandCodeBot 627543da07 feat(panel,audit): keep panel-password access on expired accounts; fill audit gaps
- an expired account may still change its own panel password, and the admin
  may still reset it — only the container stays locked. Both routes are
  deliberately exempt from the read-only gate and both stay audited
- snapshot sharing is now OFF by default (new installs and upgrades alike):
  `snapshots.share` defaults to false and the panel re-derives its DB mirror
  from the config file at startup, so even a binary-only upgrade picks the
  default up. No admin-panel UI for it; enable with `vps config set
  snapshots.share true`
- publishing a checkpoint now asks twice when it would delete older
  checkpoints (first the exposure, then the irreversible deletion)
- audit completeness: distinct domain.add/domain.update/domain.delete,
  notes.update, and subject suffixes for snapshot.share.<checkpoint>,
  reinstall.share.<owner> and quota.expire.<user>, with matching labels in
  the audit viewer (knowledge.* labels added too)

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 17:41:19 +00:00
bluebluesodaandCommandCodeBot 1078e99cfa ci(release): take release notes from the tag annotation
- the publish job reads the tag's own message and uses it as the release
  body: `git tag -a vX.Y.Z -m "..."` writes the notes shown on the release
  page
- a lightweight tag carries no message, so the body falls back to
  "fix some bugs"; GitHub still appends its auto-generated compare link
  below whatever body is passed
- a signed tag's PGP block is stripped from the notes
- document the annotated-tag flow in docs/development.md

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 17:03:14 +00:00
bluebluesodaandCommandCodeBot 76e6b0990c feat(quota): per-container validity period with expiry lockdown
Port of dev-quota-expiry onto 1.8. The branch's other three commits are
already in main, so only this feature is new here; its migration is
renumbered to v16 (1.8 already uses v14/v15).

- users.expires_at (RFC3339 UTC, '' = permanent): the admin sets days at
  creation and extends from the users table (72h/30d/90d/180d/custom/forever;
  extend = max(now, current) + duration)
- the 60s loop force-stops expired containers (stop force:true) and disables
  boot.autostart; the account is locked to read-only — the user panel refuses
  every mutation (including the new snapshot-share/unshare routes) and the
  admin panel allows only extend + delete
- the user panel shows a live countdown and a locked banner; the admin users
  table dims expired rows and tags the name "(-Nd)"
- CLI: vps add --days N, vps quota --days N | --clear-expiry
- audit: quota.expiry (admin change) and quota.expire.<user> (auto stop)
- the container and its checkpoints are never deleted, so a checkpoint shared
  before expiry stays installable by others (cloning a stopped container's
  snapshot works — verified end to end)

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 16:58:37 +00:00
bluebluesodaandCommandCodeBot 8cb5c7cb82 feat(knowledge): admin-authored knowledge base with a user-side reader
- new `knowledge` table (schema v15) and an admin page (/knowledge) to create,
  edit, preview and delete Markdown articles; the Markdown source is capped at
  256 KiB and both title and content are required
- `internal/markdown`: a small, dependency-free Markdown renderer for a basic
  subset (headings, fenced code, inline code, bold/italic, links, lists,
  blockquotes, rules). It escapes HTML first and only allows http/https/mailto/
  #/ links, so an article can never inject markup
- the admin editor previews through POST /knowledge-preview, which returns the
  rendered HTML as JSON
- the user panel's machine card gains a "知识库 / Knowledge base" button that
  opens a large overlay (nearly fullscreen on phones): every article is
  embedded rendered, the list opens an article with a back button, and a copy
  button is added to each code block

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 16:40:26 +00:00
bluebluesodaandCommandCodeBot 3b8cfdcd93 refactor(settings): move snapshot sharing and CPU limit to config.yaml
- `snapshots.share` and `cpu_limit.*` are now config.yaml fields managed with
  `vps config set` (validated, shown by `vps config list/help`) instead of being
  panel/DB-only settings; the admin panel now shows the CPU rule read-only and
  the snapshot-sharing card is gone
- both apply immediately: `vps config set` writes the config file, mirrors the
  value into the DB and applies it right away — no panel restart — the same
  pattern as net.v4_forward. `vps install` refreshes the mirror from the file
- the CPU rule is read from the mirror (falling back to the config file) so the
  enforcer and the read-only card pick up a change live; the share toggle too
- drop the now-unused admin routes/handlers, the DB-only rule setting and the
  ConfigSet CPU form

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 16:25:00 +00:00
bluebluesodaandCommandCodeBot 65b54d7970 feat(snapshot): admin toggle for snapshot sharing
- add a snapshot_share_enabled setting with an admin-overview toggle;
  absent means ENABLED, so an upgraded host gets the feature on by default
- turning it off hides the user-side share/import entry points and makes
  the manager refuse new shares and installs, while existing containers and
  checkpoints are left untouched
- the stored codes are deliberately kept in the database (not deleted), so
  re-enabling restores them for as long as their checkpoint still exists;
  a code whose checkpoint has vanished is reported as invalid instead of
  building a half-container, and deleting a checkpoint still removes its code

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 16:08:37 +00:00
bluebluesodaandCommandCodeBot 2363b89743 feat(snapshot): share a checkpoint to install from it
- a user can publish one checkpoint behind a random v4-UUID code; another
  user enters that code in the reinstall dialog and gets a container cloned
  copy-on-write from the snapshot (no image is built, so no extra disk until
  it diverges), re-provisioned as their own: own IP/ports/disk quota and
  network, a fresh hostname/root password/machine-id, the source's
  authorized_keys cleared, and no init script run
- publishing deletes the older checkpoints (a clone pins its origin, so they
  could never be restored to again); the panel warns with the exact count.
  One share per container; deleting the checkpoint/container or reinstalling
  revokes it, and a code for the container itself is handled as a restore
- clone via POST /1.0/instances with source.type=copy, then delete the old
  container and rename the clone into place; new lx.CloneFromSnapshot /
  lx.RenameInstance and a shared instanceSpec() so a clone is configured
  exactly like a fresh container
- new snapshot_shares table (schema v14) and /snapshot-share /
  /snapshot-unshare panel routes plus the time-machine and reinstall UI
- also fix a refused restore (a checkpoint pinned by a clone) so the
  container is always left running, and recognise the "subsequent internal
  snapshot(s)" refusal message alongside the existing one
- also give new containers a HARD disk limit: the pool carries
  volume.zfs.use_refquota so a volume's usage counts the blocks it
  references (including inherited image/snapshot blocks); existing
  containers are untouched

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 15:57:30 +00:00
bluebluesodaandCommandCodeBot 0e4528ad85 feat(cpu): global dynamic CPU limit rule
- admin panel gains a global dynamic CPU limit card (default off, prefilled
  10/60/0.5/2/30): a container that keeps using over y% of its own quota for
  x consecutive minutes is capped to z cores for n hours m minutes, then its
  normal quota is restored automatically
- reuse lx.SetCPU (live instance-config PATCH) and the per-minute
  resource_samples.cpu_pct_x10 (already relative to the container's quota);
  the new EnforceCPULimits pass runs in sampleResourceLoop, and the rule plus
  the active-limit state live in DB settings so a vps.service restart keeps
  every countdown and still restores on expiry
- user panel shows the capped core count and a frontend countdown while a
  limit is active; containers whose own quota is <= z are skipped
- cover the rule validation, streak detection, active-state cleanup and the
  user-panel badge in unit tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-15 14:44:54 +00:00
bluebluesodaandCommandCodeBot 3df47aece0 fix(panel): show whole GiB for large switcher memory
- MachineSpecs keeps raw MiB up to 9600, then switches to a rounded whole
  GiB (e.g. 10000 -> "2c 10g")
- cover the boundary and rounding in the group tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-12 08:31:33 +00:00
bluebluesodaandCommandCodeBot 8a73d1bd0f fix(panel): use MiB for the switcher memory unit
- MachineSpecs now renders "<cpu>c <mem>m <disk>g" (e.g. "2c 2048m 15g")
  instead of converting memory to GiB
- update the pinned group/panel tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-12 08:19:02 +00:00
bluebluesodaandCommandCodeBot 209383806b feat(bandwidth): configurable monthly reset day
- new panel.bandwidth_reset_day (1-28, default 1); the monthly bandwidth
  period key now starts on that day (mgr.BandwidthPeriod), so counters
  roll over on the configured day instead of the 1st
- user panel quota label shows "流量配额(至次月 N 号)"
- docs + BandwidthPeriod/label tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-12 08:09:44 +00:00
bluebluesodaandCommandCodeBot 0c159ae504 fix(admin): attribute impersonated container switches to the operator
- handleSwitchUser logged the raw session username, so a container switch
  made under an operator ("log in as user") session was recorded as the
  user's own action; use auditActor to record "000+<user>"
- localize the session.switch.<target> and color.update audit actions,
  which rendered as raw action strings on the audit page
- add a regression test for the impersonated switch actor

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-12 07:15:25 +00:00
bluebluesodaandCommandCodeBot 2e2022fd1f fix(panel): space out group switcher spec labels
- render each switcher option as "<label> - <cpu>c <mem>g <disk>g"
  (e.g. "A - 2c 8g 60g") instead of the cramped "A-2c8g60g"
- update MachineSpecs and the pinned tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-12 07:15:22 +00:00
bluebluesodaandCommandCodeBot 44c3727ad3 docs: document multi-container user groups
- add a "User groups" section: name-derived grouping, name validation, the
  shared panel password and accent color, and the container switcher
- describe the switcher labels and the per-container sticky-notes tag
- note the accent color is group-wide in the color section
- list multi-container users in both READMEs

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-11 06:41:06 +00:00
bluebluesodaandCommandCodeBot 770b763d2a fix(cli): keep panel/ssh output when the group password is inherited
- vps add of a sibling inherited the group hash and blanked Result.Password,
  which also suppressed the ssh and panel lines in printAdded
- print an explicit inherited-password note and always emit ssh/panel

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-11 06:41:01 +00:00
bluebluesodaandCommandCodeBot 77b3fa927a feat(panel): compact machine labels in the group switcher
- label each switcher option "<label>-<cpu>c<mem>g<disk>g" (e.g. 2-4c8g40g)
  and drop the shared group-name prefix
- order members base-first then by numeric suffix (A, 1, 2, ... 10)
- tag the sticky-notes card title with the current machine on multi-container
  groups; single-container users keep a bare title
- add mgr.MachineSpecs and cover labels, order and the tag with tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-11 06:40:56 +00:00
bluebluesodaandCommandCodeBot 69d771d17d fix(admin): sort users by name by default
- make the initial user list order deterministic
- keep manual column sorting behavior intact

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-09 08:33:25 +00:00
bluebluesodaandCommandCodeBot bb4f9160d1 fix(admin): preserve create-form helper text
- keep the full username validation hint visible
- reserve a stable IPv6 pool usage row
- prevent helper text from shifting form controls

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-09 08:11:11 +00:00
bluebluesodaandCommandCodeBot 77a98d3824 fix(admin): improve create-user form layout
- keep username hints from shifting resource fields
- give IPv6 pool selection room to breathe
- align the create action and tighten responsive layout

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-09 08:04:02 +00:00
bluebluesodaandCommandCodeBot f5e26a376a fix(panel): show group-specific machine labels
- show A for the primary machine
- preserve numeric child suffixes including leading zeroes
- cover group label parsing with tests

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-09 07:54:32 +00:00
bluebluesodaandCommandCodeBot b327000001 fix(panel): clarify machine terminology and switching
- call user-facing containers machines in Chinese text
- keep impersonation state when switching machines
- align and narrow admin create-user controls

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-09 07:41:14 +00:00
bluebluesodaandCommandCodeBot e6bf390da0 feat(panel): add grouped multi-container users
- group sibling users by the username-number convention
- synchronize group credentials, colors, and session rotation
- add group switching and destructive-action warnings
- keep group updates transactional and validate names server-side

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-09 07:21:02 +00:00
bluebluesodaandCommandCodeBot 6856e510a4 feat(addon): add container transparent proxy templates
- add sing-box, nftables, and systemd deployment templates
- document external GeoIP rule-set setup

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-08 13:17:14 +00:00
bluebluesodaandCommandCodeBot a64df2ac96 feat(panel): show build version in user footer
- add configurable user footer visibility
- render the injected release or local-build version

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-08 13:15:58 +00:00
bluebluesodaandCommandCodeBot 9b68d7b7b6 fix(panel+admin): checkbox color clash and over-wide IPv6 column
- user/admin password rule checklists no longer reuse the global .ok
  button class (whose background turned whole rows green); ticks now use
  a dedicated .done state that only recolors the item text and mark
- admin user table in IPv6-pool mode shows 有/无 (Yes/No) instead of the
  full address, keeping the column narrow like the other two modes

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 12:52:54 +00:00
bluebluesodaandCommandCodeBot 602544c7bb feat(passwd+admin): real-time rule checks; usernames fold to lowercase
- pw.Validate now requires >=10 chars with an uppercase, a lowercase and a
  digit; messages and templates updated to match
- Change-password forms (user panel + admin) show a live checklist that
  ticks each rule off as the user types
- mgr.Add and `vps add` lowercase the username before validating and
  checking duplicates, so uppercase input is accepted and stored lowercase
- Create-user form folds the username to lowercase live and reports rule
  and duplicate problems before submit
- drop the wordy password-rule hints added in the last passwd commit

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 12:18:27 +00:00
bluebluesodaandCommandCodeBot e012352b31 feat(passwd): require >=10 chars with letters and digits on password change
Shared pw.Validate rule replaces the per-panel 14-char checks; user and
admin change-password handlers, templates and i18n messages all updated.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 10:03:31 +00:00
bluebluesodaandCommandCodeBot 7e87cfd373 fix(admin): reset-password modal login-as posts a blank name; panel borders 2px
- The modal "log in as this user" form carries class=inline, and the CSS
  rule form.inline{display:inline} overrides the hidden attribute, so the
  button was visible in every modal. It posted the stale/empty name input
  and failed with "user not found". Add form.inline[hidden]{display:none}
- Reset-panel-pass now attaches the username to the flash (kind
  user_created), so the reset modal's login-as button is shown only for
  that user and logs in correctly instead of submitting a blank name
- User panel: component borders (cards, buttons, inputs, quick-stat
  tiles, modal, spinner; login card and input) go from 1px back to 2px
- Tests: login-as form must render hidden + CSS guard present; reset flash
  must carry the username

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 06:14:03 +00:00
bluebluesodaandCommandCodeBot ba3d23af82 fix(panel): restore gray-blue light bg; bold port block; v4-off notice
- Restore the light-mode page background to the gray-blue #e6ebf1 (with
  white cards) that predates the all-white change, in the user overview,
  login page and the themed override, so light mode keeps its contrast
- Port-forwarding card: bold the three-digit block number and render the
  00/99 tails at the same size, un-bolded and faded (opacity only)
- When IPv4 forwarding is off the card now says "IPv4 转发已关闭 / IPv4
  forwarding is off" instead of leaving the slot empty
- Update tests for the new markup, v4-off notice and restored background

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 05:59:52 +00:00
bluebluesodaandCommandCodeBot c0ce7a422d fix(panel): style port block like IPs; hide it when v4 forwarding is off
- Render the port block in the same yellow code style as IP addresses,
  dropping the bold; de-emphasize the trailing 00/99 with a smaller,
  faded span
- Only advertise the port block while v4 forwarding is on — with it off
  (IPv6-only host) there is nothing to forward to, so the card hides it
- Update tests: v4-off renders no port-block line even when a start_port
  exists; zh/en assert the de-emphasized tails

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 05:43:48 +00:00
bluebluesodaandCommandCodeBot 9dc133f99a feat(panel): rework user overview connectivity UI
- Drop the "available ports" cell from the overview table; the IPV4 row
  now carries just the public IP across the row
- Rename the SSH row label to "SSH 端口" in zh (SSH port unchanged)
- Rename the Domains card to "端口转发 / Port forwarding": it now shows
  the user's port block (Available: <b>103</b>00-103<b>99</b>, block
  number bolded) followed by a "域名转发 / Domain forwarding" section
  with the existing domain table and add form unchanged
- pageData: replace the unused PortsShort with PortsPrefix (whole-hundred
  block number); update tests for the new layout and zh labels

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 05:21:53 +00:00
bluebluesodaandCommandCodeBot b46bd0a901 fix(panel): theme color only on admin impersonation; thin borders back to 1px
- Per-user accent color now tints the user panel only for operator
  impersonation sessions (handleOverview clears ThemeColor otherwise);
  users logging in with their own password see the default theme
- Restore 1px borders on user-panel cards, buttons, inputs, quick stats,
  modals and spinner, and on the login card/input (was 3px)
- Update docs and tests; add HTTP-level test covering both session kinds

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-06 04:52:37 +00:00
bluebluesodaandCommandCodeBot 01869464cb fix(panel): responsive layout for sticky notes on narrow screens
Stack the notes list above the editor below 640px instead of squeezing
the fixed 28% sidebar alongside the textarea; let the toolbar buttons
wrap so save/lock/delete no longer overflow on mobile.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-05 15:44:40 +00:00
bluebluesodaandCommandCodeBot b1d40a1107 chore(notes): halve sticky-notes plaintext cap to 256 KiB
Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-05 08:27:23 +00:00
bluebluesodaandCommandCodeBot 48d8cafe2f fix(install): skip 50-image when incus.image is a custom alias
Reinstall/upgrade with incus.image set to anything other than the
default vpsmgr/debian-sshd now skips the Debian 13 sshd image build —
a custom image operator does not launch the stock one, so pulling
Debian 13 and rebuilding it is wasted work (even when the default
image is missing).

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-04 13:33:12 +00:00
bluebluesodaandCommandCodeBot a8bc34a325 feat(admin): drop the plan-preset hint line
The explanation line above the S/M/L preset cards is unnecessary
chrome; remove it and its CSS/JS/labels.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-04 12:30:47 +00:00
bluebluesodaandCommandCodeBot 817b23c922 feat(admin): add S/M/L plan presets to the create-user form
Three fixed preset cards sit above the create form; each stores a
customizable name plus cpu/mem/disk/bandwidth specs in localStorage
(pure front-end, no backend change). "Edit" opens a modal, "Apply"
overwrites the current form values.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
2026-09-04 12:22:07 +00:00
bluebluesoda f2d3eee4d8 fix(install): fall back to IPv4 when go.dev download fails over IPv6
Some hosts resolve go.dev/dl through an IPv6 path that serves the site and
manifest fine but returns 404 for the tarball CDN (dl.google.com). curl
prefers IPv6 by default, so ensure_go's download loop failed on every
candidate and aborted the local build.

- add curl_retry: fetch with the default address family, fall back to
  'curl -4' on failure; use it for both the manifest and the tarball
- the IPv4 fallback is a pure retry — hosts with working IPv6 are
  unaffected, and pure-IPv4 hosts were never broken
- drop an unused 'latest' variable in the download loop
2026-09-04 08:53:34 +00:00
bluebluesoda e25e729de7 fix(ipv6): disable npd6 alongside ndppd to avoid competing NAs
The in-tree NDP responder relies on being the only NDP proxy on the host.
main.go already disabled ndppd.service at install; npd6 (an alternative
distro NDP proxy daemon) was left running, so a host that happened to have
npd6 installed would answer Neighbor Solicitations with a competing
link-local-source NA and break the global-address fix.

- main.go: also `systemctl disable --now npd6.service` at install
- uninstall.sh: also stop/disable npd6 in the IPv6 cleanup path
- docs: note both daemons are disabled (ipv6-ndp-responder.md, ipv6.md)
2026-09-04 08:47:36 +00:00
bluebluesoda c9b18ffee5 Merge remote-tracking branch 'origin/dev-ndp'
# Conflicts:
#	src/internal/admin/handlers.go
2026-09-04 08:33:56 +00:00
bluebluesoda 69f79187c8 feat(ports): replace net.slot_range with net.user_ports; probe SSH ports at add time
net.slot_range required operators to reason about IPv4 last-octet slots to
control the host's reserved port span. Replace it with net.user_ports, a
direct comma-separated set of user-port ranges (default 10000-29999) that a
new container's whole-hundred block is drawn from, auto-aligned to whole
hundreds and merged. Only-new-users effect; existing containers keep their
ports.

- cfg: ParseUserPorts/CanonicalUserPorts/UserPortRanges/UserPortCount/
  UserPortBlockStarts; legacy slot_range is migrated once on Load and the
  old key stays in the file, ignored, no longer editable.
- db: migration v13 adds a UNIQUE index on users.start_port (port blocks are
  no longer derived from idx, so uniqueness must be enforced directly);
  UsedStartPorts() feeds the allocator.
- mgr: port blocks are allocated independently of the IPv4 idx via
  allocUserPortBlock; admin capacity readout follows UserPortCount.
- installer: 00-ip-ask.sh asks for port ranges (default = no confirm, a
  changed value echoes capacity and asks Y/n) and converts legacy slot_range;
  00-check.sh scans only the effective user-port ranges.
- ssh: allocSSHPort now probes the host (bind test) before picking a port,
  reassigning on conflict; the install no longer hard-fails on an occupied
  30000-31999 port.
2026-09-04 08:32:13 +00:00
bluebluesoda 3fdb946baa Update 80-debian-dev-image.sh 2026-09-02 23:30:25 +08:00
bluebluesoda fd6448bd27 Update handlers.go 2026-09-02 19:04:21 +08:00
bluebluesoda 2f43b95b0f Update overview.html 2026-09-02 13:23:03 +08:00
bluebluesoda 888cf09a95 Update install.sh 2026-09-02 13:02:13 +08:00
bluebluesoda 3f5fffc961 Update README.md 2026-09-02 11:22:47 +08:00
bluebluesoda 430d6f77c4 feat(install): warn on a release install from a non-main branch
A plain ./install.sh downloads the prebuilt RELEASE binary, which always
comes from main regardless of the checked-out branch. If this is a real
git checkout on a non-main branch, prompt for confirmation before
continuing. Tarball / one-click pipe installs have no .git directory and
skip the check. The branch is read directly from .git/HEAD so git(1) is
not required; a detached HEAD is treated as non-main.
2026-08-31 23:53:01 +08:00
bluebluesoda 5f154728af feat(install): warn on a release install from a non-main branch
A plain ./install.sh downloads the prebuilt RELEASE binary, which always
comes from main regardless of the checked-out branch. If this is a real
git checkout on a non-main branch, prompt for confirmation before
continuing. Tarball / one-click pipe installs have no .git directory and
skip the check. The branch is read directly from .git/HEAD so git(1) is
not required; a detached HEAD is treated as non-main.
2026-08-31 23:52:51 +08:00
bluebluesoda 83f9214b72 fix(install): stop vps-ipv6.service too before replacing the binary
On the dev-ndp branch the prefix-mode boot unit vps-ipv6.service runs a
long-lived `vps ipv6-proxy` process that maps /usr/local/bin/vps, so
stopping only vps.service left the binary held and 40-panel.sh failed to
overwrite it with ETXTBSY ("Text file busy"). Stop every vpsmgr unit that
keeps the binary mapped (vps.service and vps-ipv6.service) before copying,
in both the local-build and prebuilt paths. Verified live: cp fails while
the panel runs, succeeds once it is stopped.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 22:04:42 +08:00
bluebluesoda da3f8b2105 fix(install): stop vps-ipv6.service too before replacing the binary
On the dev-ndp branch the prefix-mode boot unit vps-ipv6.service runs a
long-lived `vps ipv6-proxy` process that maps /usr/local/bin/vps, so
stopping only vps.service left the binary held and 40-panel.sh failed to
overwrite it with ETXTBSY ("Text file busy"). Stop every vpsmgr unit that
keeps the binary mapped (vps.service and vps-ipv6.service) before copying,
in both the local-build and prebuilt paths. Verified live: cp fails while
the panel runs, succeeds once it is stopped.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 22:04:31 +08:00
bluebluesoda 0548b50eb2 Merge main into dev-ndp
Bring in the two v6-unrelated features committed on main: the snapshot
size column in the time-machine modal, and tab-completion for `vps config
set`.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 21:55:07 +08:00
bluebluesoda 31143f2cf8 feat(cli): tab-complete config keys for vps config set
Typing a config key by hand was tedious, so `vps config set <TAB>` now
completes just the keys `vps config set` accepts. The completion script
(dropped into /usr/share/bash-completion/completions by 40-panel.sh) pulls
candidates live from a hidden `vps config completions` subcommand, which
returns EditableKeys() from the registry — so offered keys never drift from
what set actually enforces. Also completes top-level commands, config
subcommands and (for del/power/quota/passwd) container names.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 21:54:19 +08:00
bluebluesoda 4bc161c379 feat(panel): show snapshot disk usage in a wider time-machine modal
Incus's snapshot API already returns each snapshot's size, so the overview
now renders a Size column (via a newly exported HumanBytes) and the time
machine modal is bumped from 420px to the wide layout. The per-row value is
greeted only when snapshots exist; the header ships in the template.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 21:54:12 +08:00
bluebluesoda a3a81d943f docs: note how the NDP responder coexists with the isolation layer
Clarify that security.port_isolation + ipv4/ipv6_filtering gate east-west
traffic on the bridge while the responder handles north-south NA replies on
the upstream NIC, and document the gateway-neighbour pinning that plans
around the isolation filter's deliberate side effect on fe80::1 NDP.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 21:39:21 +08:00
bluebluesoda 9696752d25 docs: explain the in-tree NDP responder design and scale-test checklist
Add docs/ipv6-ndp-responder.md: why prefix mode replaced the distro ndppd
daemon with a project-owned responder (some providers drop link-local-source
NAs), the data-plane correctness guarantees, the A/B design hardening, what
changed on dev-ndp, and an 8-point checklist for wide-scale testing. Link it
from docs/README.md.
2026-08-31 17:51:14 +08:00
bluebluesoda 062cf9c4f5 feat(ipv6): in-tree NDP responder for global-address NA source
Some upstream IPv6 providers reject NDP replies whose source is a
link-local address (what ndppd and Linux proxy_ndp emit) and require the
advertised global address. Replace the distro ndppd prefix-mode data
plane with an in-tree raw AF_PACKET responder whose NA source is the
target's global address, re-reading a panel-writable rules file while it
runs so vps add/del never restarts it.

- add internal/ndp: minimal NDP responder (NS->NA, DAD handling, correct
  ICMPv6 checksum/hop-limit/flags); only answers for target blocks inside
  the operator's routed prefix (confines the root responder's trust surface)
- main: ipv6-proxy unit (prefix mode) + ipv6-proxy command + ethernetMAC
  pre-check at install so a broken ext_if never hot-loops under Restart=always
- ipv6.go: write ndppd.conf atomically (temp+rename), drop all ndppd daemon
  management and its sudoers grants
- mgr/routed_ipv6.go: configure guest v6 before publishing the NDP rule;
  pin fe80::1 gateway neighbor, UseGateway=false, local /112 route +
  vpsmgr-ipv6.service helper in the guest
- 50-image.sh/80-debian-dev-image.sh: bake UseGateway=false into [IPv6AcceptRA]
2026-08-31 17:45:24 +08:00
bluebluesoda f79ccb09f0 feat(install): add btrfs storage backend (native subvolume or loop file)
- VPSMGR_STORAGE now accepts btrfs alongside zfs and dir. On a btrfs root the
  pool is created as a native subvolume at /var/lib/incus/storage-pools/vpsmgr
  (Incus only allows that source path and requires it NOT to pre-exist); on any
  other host it becomes a sparse loop-file pool sized exactly like ZFS.
- install.sh asks for an explicit beta confirmation up front when the btrfs
  backend is selected (default yes — on a btrfs host there is no ZFS fallback).
  Non-interactive installs proceed; non-btrfs/default-zfs installs are
  unchanged.
- btrfs swap: on a btrfs root the swapfile is created with
  `btrfs filesystem mkswapfile` (btrfs-progs >= 6.1), falling back to
  truncate + chattr +C + dd for older tools — the generic fallocate+mkswap path
  fails on btrfs (swap must be NODATACOW and preallocated). Non-btrfs hosts
  keep the existing fallocate path.
- 00-check.sh installs btrfs-progs and skips the ZFS DKMS/kernel-header
  toolchain for btrfs and dir alike; 10-incus.sh verifies the final driver.
- Panel Go code is untouched: container management is storage-driver-
  transparent, and lx.EnsureZFSRemoveSnapshots is a no-op off ZFS.
- Docs (architecture, configuration, READMEs, AGENTS) updated for the new
  backend, including snapshot-restore semantics (btrfs keeps later snapshots).

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 17:00:03 +08:00
bluebluesoda 6eafac3274 fix(install): don't start traefik when IPv4 forwarding is off
30-traefik.sh enabled traefik whenever the adopted net.traefik was true, even
on an IPv6-only box (net.v4_forward false). The domain proxy is only served
while BOTH v4 ingress and net.traefik are on, so traefik must stay installed
but DISABLED (no start, no boot autostart) when v4 forwarding is off, regardless
of the kept net.traefik value; re-enabling v4 later restores it. The start
branch is now gated on VPSMGR_V4_FORWARD first, matching the panel's own
ApplyTraefikState (V4Forward && Traefik).

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 07:26:32 +00:00
bluebluesoda e0dd123dc1 feat(name): allow hyphens in usernames, require letter start+end
- Usernames may now contain hyphens (lowercase letters/digits/hyphens), but a
  new name must both start and end with a lowercase letter, max 31 unchanged.
  This drops digit-terminated names like "a1"/"vps12345678" at creation.
- The strict rule is enforced only when CREATING a user (ValidateName in
  Add/userAdd and the admin add-user form's pattern). An existing-user
  operation (del / quota / passwd) now uses ValidateExistingName, which accepts
  every historically-valid shape, so a legacy digit-ending username stays
  operable rather than being locked out by the new creation rule.
- Tests cover the strict rule, its new rejects, and the legacy-compatible
  existing-name check.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 07:06:59 +00:00
bluebluesoda 6fcc97b81b docs: document the snapshot "time machine" semantics
- architecture.md: new bullet under Users and resources explaining that
  restoring to an older checkpoint discards the later ones, done as a single
  Incus call via zfs.remove_snapshots on the ZFS root volume (recursive
  rollback), applied at add/reinstall and refreshed on every `vps install`
  (incl. --update), with the delete-and-retry fallback and the reinstall
  checkpoint-count warning.
- configuration.md: snapshots.limit row now notes that restoring to an older
  checkpoint auto-deletes the newer ones.
- README / README.en: list the time-machine (checkpoint) feature in the user
  panel feature lists.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-31 06:58:11 +00:00
bluebluesoda 2ff2144e1b feat(snapshot): one-call "time machine" restore via zfs.remove_snapshots
- A restore to an older checkpoint now relies on zfs.remove_snapshots set on
  the container root volume, so a single Incus restore auto-discards the later
  snapshots instead of failing with "subsequent snapshot(s)" and leaving a
  partially-executed rollback.
- The volume option is set at Add/Reinstall (on the fresh root volume) and by
  a new ApplyZFSRemoveSnapshotsToAll pass run during `vps install`, so a host
  updated via install.sh --update gets the behaviour immediately without
  reinstalling containers. ZFS-only: non-ZFS (dir test) pools are skipped, as
  they have no snapshots.
- SnapshotRestore keeps a fallback that deletes the newer snapshots by
  creation time and retries once, for a volume that somehow lacks the option.
- User panel adopts the time-machine metaphor: the button is now
  "时光机"/Time machine, individual snapshots are "检查点"/checkpoints, the
  reinstall modal warns with the exact checkpoint count, and the admin audit
  labels + success toasts use the same terms. Adds unit tests for the
  newer-snapshot selection and timestamp parsing.
2026-08-31 06:56:29 +00:00
bluebluesoda 366ceff41e Update 00-ip-ask.sh 2026-08-31 14:13:46 +08:00
bluebluesoda 8a74607bcf Update README.en.md 2026-08-30 19:46:40 +08:00
bluebluesoda 840dc52aac Update README.md 2026-08-30 19:46:17 +08:00
bluebluesoda 6e8dd6c4f8 feat(install): echo slot-range capacity + ports hint, don't prompt on upgrade
- ask_range now prints one line right after the slot range is finalized
  (env / adoption / non-interactive / interactive alike) with the computed
  container capacity and the usable user-port span it reserves, so the
  operator sees the effect immediately.
- An existing config WITHOUT a slot_range key (an upgrade from a
  pre-slot-range version) no longer prompts: it keeps the default 2-201
  (which the panel applies anyway) and returns, so a one-click upgrade of
  an already-deployed panel is never interrupted by the new question.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-30 09:43:44 +00:00
bluebluesoda fa151eaee4 feat(install): configurable slot range + auto-off Traefik on 80/443 conflict
Add net.slot_range, a shrinkable container slot range (read as the IPv4
last octet a new container may take; idx = octet-1) that bounds how many
containers can be created and, consequently, how much of the user-port
block 10000-29999 a host reserves. Default 2-201 = 200 slots; must always
be a sub-range of 2-201 (only-shrink rule). Affects ONLY new containers —
existing ones keep their slot/ports.

- cfg: add net.slot_range with strict ParseSlotRange validation
  (exactly one '-', both ends integers in 2..201, lo<=hi), SlotCount/
  SlotIdxBounds helpers, and VPSMGR_SLOT_RANGE env handling in FillAuto.
  Register net.slot_range as operator / next-add in the config registry.
- db/mgr: NextFreeIdx now picks from a caller-supplied [idxMin,idxMax]
  window instead of the fixed 1..cfg.MaxUsers; mgr.Add feeds it from the
  configured range. Existing users outside a narrowed range keep their
  slots.
- admin panel: capacity readout follows SlotCount() instead of a fixed
  200 (honestly shows over-capacity when pre-existing users fall outside
  a shrunken range).
- installer: 00-checklist asks the slot range right after the subnet
  octet (env/adoption/non-interactive branches, validated). The
  port-occupancy check now scans only the range's user-port span rather
  than the whole 10000-29999.
- 80/443 handling: if either is already bound by a non-vpsmgr process,
  the install no longer fails — it proceeds with Traefik installed but
  DISABLED (net.traefik false, no autostart). 00-check writes a marker
  that install.sh turns into VPSMGR_TRAEFIK=0 for 30-traefik and the
  panel. A belt-and-suspenders guard skips the force-off when our own
  traefik.service is already active (update/adoption). SSH 30000-31999
  and the user-port span remain hard failures.
- traefik: bump pinned version to 3.7.12 and rewrite 30-traefik's
  enable/disable decision to respect the effective net.traefik (forced
  env > adopted config > default), so a disabled traefik is never
  briefly started.
- docs: README(s), config example, architecture and configuration docs
  updated; tests added for slot-range parsing and the FillAuto env vars.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-30 09:36:29 +00:00
bluebluesoda 25758a6590 feat(install): swap prompt offers 1:1 RAM size via y
- prompt now shows [<RAM> GiB/y/N] with the auto size computed from
  host memory; answering y creates a swap file of RAM × 1:1
- custom sizes in GiB are still accepted, N/Enter aborts as before

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-30 08:30:53 +00:00
bluebluesoda 1b564a9900 feat(install): use container-only incus-base instead of full incus
- new installs pull incus-base (Zabbly lts-7.0) which ships the same
  incusd daemon without the QEMU/SPICE/Ceph VM stack (~240 MiB less
  download, 500 MiB+ less disk)
- leave hosts that already carry the full `incus` package untouched
- uninstall --purge now also removes the full-incus VM dependencies,
  guarded by an installed reverse-dependency check (never blanket autoremove)
- update the dev docs install snippet to incus-base

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-30 08:19:19 +00:00
bluebluesoda 07dedf9e9f Update 00-ip-ask.sh 2026-08-30 08:46:58 +08:00
bluebluesoda 4c0d1750a3 Update 00-ip-ask.sh 2026-08-30 08:44:36 +08:00
bluebluesoda 1158eb96da feat(config): add independent Traefik toggle
- add runtime net.traefik switch with live DB state\n- stop and disable Traefik when IPv4 forwarding is off\n- block new domains while Traefik is disabled
2026-08-29 14:34:47 +00:00
bluebluesoda 2e3dc7f3d2 Update 50-image.sh 2026-08-29 03:30:51 +08:00