refactor: clarify service boundaries and unify project tooling
This commit is contained in:
31 files changed
+832
-539
No files matched your search
+24
-21
@@ -1,35 +1,38 @@
|
||||
# Architecture
|
||||
|
||||
RouterShelf has independent web and SMB service executables within these operational layers:
|
||||
RouterShelf is one Go module with two independent commands. Each owns its configuration and process lifecycle. Small command-local files keep startup concerns together; only the HTTP response layer and the substantial SMB protocol implementation need separate internal packages.
|
||||
|
||||
| Layer | Responsibility | Repository location |
|
||||
| Component | Responsibility | Location |
|
||||
| --- | --- | --- |
|
||||
| Go application | Safe directory reads, HTTP responses, TLS and ACME, connection limits, privilege drop | `cmd/routershelf` |
|
||||
| Private SMB application | Independent account/config, selected root, signed SMB, write policy and privilege drop | `cmd/routershelf-smb`, `internal/smbwire` |
|
||||
| Embedded theme | NAIS styling, favicon, copied links, playlist generation | `internal/theme` |
|
||||
| Router lifecycle | USB checks, process restart, time startup, host firewall hooks, flash persistence | `deploy/padavan` |
|
||||
| Network gateway | Public DNS destination, destination NAT, LAN hairpin reply routing | Configuration documented in `docs/getting-started.md` |
|
||||
| Web command | Environment/flag validation, privilege drop, listeners, connection bounds, TLS and ACME | `cmd/routershelf` |
|
||||
| Public HTTP | Filesystem confinement, methods, listings, static pages, download headers and HTTPS redirects | `internal/web` |
|
||||
| Embedded theme | NAIS CSS/JavaScript, favicon, copied links and playlists | `internal/theme` |
|
||||
| SMB command | Private JSON validation, credentials CLI, listener/privilege setup, mount/root monitoring | `cmd/routershelf-smb` |
|
||||
| SMB protocol | Authentication, signing, permissions, bounded operations, locks and protected storage view | `internal/smbwire` |
|
||||
| Router lifecycle | Independently runnable firmware supervisors; web firewall/time hooks | `deploy/padavan` |
|
||||
| Gateway planning | Print administrator-reviewed public web NAT guidance; never apply it | `scripts/nat-plan.sh` |
|
||||
|
||||
## Dependencies and access policy
|
||||
|
||||
```text
|
||||
Browser -> gateway TCP 80/443 -> storage host TCP 10080/10443
|
||||
|
|
||||
RouterShelf
|
||||
/ \
|
||||
shared directory private ACME cache
|
||||
|
|
||||
USB filesystem
|
||||
routershelf command -> internal/web -> internal/theme
|
||||
-> x/crypto/acme/autocert
|
||||
|
||||
routershelf-smb command -> internal/smbwire -> x/crypto, x/sys
|
||||
```
|
||||
|
||||
The gateway plan is generated from `.env` by `scripts/nat-plan.sh`, rather than auto-applied: changing a gateway requires matching its actual interfaces, existing NAT/filter rules, and public address. The Go application does not change routing, configure DHCP, or provision FTP accounts.
|
||||
Neither executable imports the other service. There is no shared configuration or lifecycle abstraction: web environment/shell policy and SMB protected JSON have different compatibility and trust contracts. Similar-looking privilege handling also has different ordering: web drops before binding unprivileged ports; SMB binds its private listener before dropping so it can use TCP 445.
|
||||
|
||||
The `deploy/padavan` script loads a private environment file for one firmware family. Its installed names remain `public-share-service.sh`, `public-directory`, and `/tmp/public-share-*` for compatibility with the existing deployed system and instructions. Renaming the repository is not a live-router migration.
|
||||
The HTTP handler opens an `os.Root` per request and preserves current removable-storage behavior. SMB pins its selected root for a session-serving lifetime and exits when mount/root identity changes. Its protected disk-root view adds descriptor-based exclusions; see the [adaptation inventory](../internal/smbwire/UPSTREAM.md). Both may use the same physical disk, so resource pressure and explicitly overlapping data remain shared operational risks.
|
||||
|
||||
The legacy dashboard is a separate Netcat/shell example, with its own configuration and security assumptions. Its code remains in `examples/status-dashboard` and its guide in `docs/examples/status-dashboard.md`. It was removed from the original router and must never inherit the public server's port-forwarding policy.
|
||||
## Deployment boundaries
|
||||
|
||||
The Go module path is currently `routershelf`, a local standalone module identity. If a real repository remote is established later, change the module path and the `routershelf/internal/theme` import together if a hosted module path is desired. No remote namespace is assumed.
|
||||
Public web traffic can follow `Browser -> gateway TCP 80/443 -> storage-host HTTP/HTTPS listeners`. Certificate/account cache, binary and configuration belong outside the public root. The [configuration reference](configuration.md) describes the environment contract.
|
||||
|
||||
Read [setup](getting-started.md), [operations](operations.md), and [security](../SECURITY.md) for configuration and maintenance boundaries.
|
||||
Private access follows `Finder -> specific private IPv4 SMB listener -> selected USB directory`. It requires no domain, certificates, NTP startup or gateway forwarding. The SMB supervisor uses its own executable/config paths and `/tmp/routershelf-smb/` lock. It does not source the web environment, change firewall rules or signal the web service. Administrators restrict the listener with their own service-scoped firewall policy; see [SMB setup](smb.md).
|
||||
|
||||
## Independent private SMB path
|
||||
The web supervisor's installed compatibility names remain `public-share-service.sh`, `public-directory` and `/tmp/public-share-*`. Repository organization does not migrate deployed installations. Padavan hooks, flash persistence and BusyBox details remain platform-specific and should not become application responsibilities. The Go commands do not provision DHCP, alter routing/NAT or create FTP accounts.
|
||||
|
||||
`Finder -> specific private IPv4 SMB listener -> os.Root selected private USB folder`. This path needs no web server, certificates, NTP startup or gateway NAT. The SMB supervisor uses its own JSON path, executable, process tree and `/tmp/routershelf-smb/` lock. It never sources the web environment, changes firewall rules or signals the web service. The web binary does not import SMB code. Both may access USB storage, so resource pressure and deliberately overlapping data remain shared operational risks. See [SMB setup and lifecycle](smb.md) and [implementation decision](smb-implementation.md).
|
||||
The module path remains `routershelf`; no hosted namespace is assumed. The [legacy dashboard](../examples/status-dashboard/README.md) is a standalone historical tutorial with separate security assumptions and no Go dependency. It must not inherit public forwarding.
|
||||
|
||||
Read [web setup](getting-started.md), [web operation](operations.md), [SMB setup and operation](smb.md), and [security](../SECURITY.md) for user procedures. Validation history records observations; it is not the installation source of truth.
|
||||
@@ -14,7 +14,7 @@ LAN browser -> router TCP port 8080 -> Netcat -> shell request handler
|
||||
+-> HTTP headers + HTML response
|
||||
```
|
||||
|
||||
The router's management panel remains on its existing port. The new service does not change DHCP, routing, Wi-Fi settings, credentials, or the panel. Being in a directory opened by PhpStorm does not mean the router runs PHP.
|
||||
The router's management panel remains on its existing port. The new service does not change DHCP, routing, Wi-Fi settings, credentials, or the panel. The handler executes only the installed shell script; it does not run PHP.
|
||||
|
||||
The browser requests `/` or `/status`. The handler reads a fixed request path, gathers metrics, sends a response, and exits. Netcat waits for the next client. With no browser open, no periodic probe runs.
|
||||
|
||||
@@ -278,7 +278,7 @@ Remove only this project's directory after reviewing its contents, then save sto
|
||||
- Review `git status` and `git diff --cached` before committing.
|
||||
- `.gitignore` does not remove files already tracked. If a secret was committed, remove it from history as appropriate and rotate the exposed credential before publishing.
|
||||
- State compatibility and testing limits honestly. A sample based on one router is not universal support.
|
||||
- Choose a license. This project includes MIT; review that choice before publication.
|
||||
- Retain the project MIT license and applicable third-party notices in distributions.
|
||||
|
||||
For repository-wide contribution and publication guidance, return to the repository root and read [CONTRIBUTING.md](../../CONTRIBUTING.md). Keep this example under `examples/status-dashboard`; do not initialize a nested Git repository or publish private deployment configuration.
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
For authenticated Finder access without web setup, follow the independent [SMB installation guide](smb.md). This page installs the public web service.
|
||||
|
||||
|
||||
## Architecture and paths
|
||||
|
||||
```text
|
||||
@@ -32,10 +31,8 @@ The certificates directory is private administrative material, despite its locat
|
||||
Build on a computer with Go, not on the router. The tested build used Go 1.26.5 and pinned dependencies in `go.mod`/`go.sum`. Confirm the current toolchain's compatibility with the target's old kernel before upgrading. The program uses `os.OpenRoot` to enforce the shared-directory boundary.
|
||||
|
||||
```sh
|
||||
mkdir -p dist
|
||||
go test ./...
|
||||
GOOS=linux GOARCH=mipsle GOMIPS=softfloat CGO_ENABLED=0 \
|
||||
go build -trimpath -ldflags='-s -w' -o dist/routershelf-linux-mipsle ./cmd/routershelf
|
||||
make test
|
||||
make build-mipsle
|
||||
```
|
||||
|
||||
Use `mipsle` only for the matching target CPU. The binary has no PHP, nginx, or dynamically linked runtime requirement. Preserve dependency checksums. Rebuild and test for other devices rather than downloading an arbitrary executable.
|
||||
@@ -149,7 +146,7 @@ Compare the download with its source. Use normal trusted certificate validation.
|
||||
|
||||
The Go executable embeds the theme files under `internal/theme/nais`: `autoindex.css`, `autoindex.js`, and favicons. The listing references them under `/_nais/`. This reproduces the theme without nginx's `sub_filter` or its installer. Folder links remain navigable; regular files carry `data-file="true"` and download attributes. The script uses that marker for copied links and DPL playlists, including extensionless files.
|
||||
|
||||
The bundled integration adjusts row width and the mobile heading, changes the footer to read-only storage, and adds copy feedback/fallback handling. The HTML template escapes names. Assets have explicit MIME types; HTML and recognized CSS/JavaScript/image/font assets are served inline with explicit MIME types; other files use `application/octet-stream` and attachment disposition. A directory with a readable regular `index.html` displays that page instead of its listing. PHP/CGI are not executed. The listing retains its strict CSP; static pages permit inline scripts/styles and external assets, with object embedding and framing blocked.
|
||||
The bundled integration adjusts row width and the mobile heading, adds copy feedback, and uses a read-only footer. HTTP listing/rendering lives in `internal/web`; licensed assets remain in `internal/theme/nais`. See [static pages](static-pages.md) for index precedence, inline MIME types, downloads and content policy. These rules apply to the same public root.
|
||||
|
||||
To update the style, review upstream changes, copy the intended assets to this source tree, retain the NAIS license, preserve the integration changes, rebuild, and deploy using the rollback procedure. Do not publish the upstream landing page as the directory listing.
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,6 @@
|
||||
|
||||
This page covers the existing web installation. SMB has separate [status, update, rollback and removal procedures](smb.md#install-status-update-and-remove); stopping or updating one service does not operate the other.
|
||||
|
||||
|
||||
## Routine care
|
||||
|
||||
| Frequency / event | Check |
|
||||
@@ -102,6 +101,7 @@ If public access is malfunctioning or unintended, disable the service's TCP 80/4
|
||||
| Renewal fails | Service downtime, USB/cache unavailable, inaccurate time, old DNS/NAT address, blocked challenge, or CA rate limit |
|
||||
| Folder/file missing | Wrong root/mount, dot-prefixed name, outside symlink, nonregular file, read permission, or 5,000-entry truncation |
|
||||
| FTP login works but upload fails | Account path/write permissions, read-only disk, or passive data ports; perform a real upload/download test |
|
||||
| Request hangs on a special file | The web handler opens before checking file type; a named pipe can block on filesystems that support it. Keep special files out of the public root; this existing edge case needs a separate fix |
|
||||
| Style missing | Failed `/_nais/` asset request, MIME/CSP issue, stale browser cache, or binary built without intended assets |
|
||||
| Copy button reports failure | Browser clipboard permission/support; test paste manually and try a supported secure browser |
|
||||
| Service returns after stopping child | Expected supervisor restart; stop the parent to stop the whole service |
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ On the development computer, with Go 1.26+:
|
||||
make test
|
||||
make build-smb-mipsle
|
||||
# For a local desktop executable:
|
||||
go build -o dist/routershelf-smb ./cmd/routershelf-smb
|
||||
make dist/routershelf-smb
|
||||
umask 077
|
||||
cp .smb.example.json smb.json
|
||||
chmod 600 smb.json
|
||||
|
||||
Reference in new issue
Block a user