init
This commit is contained in:
43 files changed
+2583
No files matched your search
@@ -0,0 +1,30 @@
|
||||
# Architecture
|
||||
|
||||
RouterShelf has four operational layers:
|
||||
|
||||
| Layer | Responsibility | Repository location |
|
||||
| --- | --- | --- |
|
||||
| Go application | Safe directory reads, HTTP responses, TLS and ACME, connection limits, privilege drop | `cmd/routershelf` |
|
||||
| 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` |
|
||||
|
||||
```text
|
||||
Browser -> gateway TCP 80/443 -> storage host TCP 10080/10443
|
||||
|
|
||||
RouterShelf
|
||||
/ \
|
||||
shared directory private ACME cache
|
||||
|
|
||||
USB filesystem
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
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 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.
|
||||
|
||||
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.
|
||||
|
||||
Read [setup](getting-started.md), [operations](operations.md), and [security](../SECURITY.md) for configuration and maintenance boundaries.
|
||||
@@ -0,0 +1,70 @@
|
||||
# Environment configuration
|
||||
|
||||
Network-specific settings live in a private `.env` file. The public `.env.example` contains only illustrative values. Changing a domain, subnet, USB mount, or port does not require editing Go or shell source and does not require rebuilding the application.
|
||||
|
||||
## Loading and precedence
|
||||
|
||||
The Padavan supervisor loads `/etc/storage/routershelf.env` by default. Override the path with `ROUTERSHELF_ENV_FILE=/absolute/path/to/config`. It exports the settings to the child application and supplies matching command-line values. Run `--check-config` to validate without starting NTP, changing firewall, or launching a process.
|
||||
|
||||
The supervisor **sources** the file as trusted shell configuration. Keep it administrator-owned, restrict its mode, and use simple `RS_KEY=value` assignments. A dotenv file from an untrusted person can execute commands when sourced. This format is not an arbitrary web input or a general dotenv parser; shell quoting rules apply.
|
||||
|
||||
The Go binary reads exported `RS_*` values; it does not automatically read or execute `.env`. Its flags take precedence over environment defaults. For local use:
|
||||
|
||||
```sh
|
||||
set -a
|
||||
. ./.env
|
||||
set +a
|
||||
go run ./cmd/routershelf
|
||||
```
|
||||
|
||||
With no configured IP, the standalone binary defaults to loopback. `RS_DOMAIN` enables HTTPS; without it, the standalone binary can serve plain HTTP for development. The deployment supervisor requires a domain and distinct unprivileged internal ports.
|
||||
|
||||
## Settings
|
||||
|
||||
| Variables | Purpose |
|
||||
| --- | --- |
|
||||
| `RS_DOMAIN` | Single HTTPS certificate hostname, without scheme or port |
|
||||
| `RS_LAN_IP`, `RS_LAN_SUBNET`, `RS_LAN_INTERFACE` | Bind address and modem firewall scope |
|
||||
| `RS_USB_MOUNT` | Exact expected USB mount point |
|
||||
| `RS_PUBLIC_SUBDIR`, `RS_SERVICE_SUBDIR` | Subdirectory names used to derive share/service paths |
|
||||
| `RS_ROOT`, `RS_BINARY`, `RS_CERT_CACHE`, `RS_CA_BUNDLE` | Optional absolute path overrides |
|
||||
| `RS_HTTP_PORT`, `RS_HTTPS_PORT` | Internal listener/firewall ports; default 10080 and 10443 |
|
||||
| `RS_PUBLIC_ACCESS` | `false`: LAN-only sources; `true`: also allow forwarded public sources |
|
||||
| `RS_DROP_PRIVILEGES` | Run application as UID/GID 65534; normally `true` |
|
||||
| `RS_MEMORY_LIMIT`, `RS_CPU_LIMIT` | Go GC memory target and GOMAXPROCS |
|
||||
| `RS_CHECK_INTERVAL`, `RS_MIN_YEAR` | Supervisor poll interval and coarse reset-clock guard |
|
||||
| `RS_NTP_SERVER1`, `RS_NTP_SERVER2` | NTP startup peers |
|
||||
| `RS_SUPERVISOR_PATH`, `RS_RUNTIME_DIR` | Installed script and runtime PID/log directory |
|
||||
| `RS_GATEWAY_*` | Public/LAN gateway addresses and interfaces, used by the NAT plan |
|
||||
| `RS_PUBLIC_HTTP_PORT`, `RS_PUBLIC_HTTPS_PORT` | Public standard ports: 80 and 443 |
|
||||
| `RS_PUBLIC_SSH_PORT`, `RS_SSH_TARGET_PORT` | Independent SSH mapping in the NAT plan |
|
||||
|
||||
The standard public 80/443 configuration is intended for ACME validation and normal redirects. Changing public HTTPS away from 443 requires redirect handling changes too; the current redirect targets the standard HTTPS hostname. These plan values do not change application redirects or DNS automatically.
|
||||
|
||||
Do not place the binary, trust bundle, or certificate cache inside the public root. Deployment paths are absolute and may not contain spaces or `..` in the supervisor. Private keys stay on USB outside the root; a filesystem/account policy must protect them from broad FTP/SFTP access.
|
||||
|
||||
## Installing your configuration
|
||||
|
||||
```sh
|
||||
cp .env.example .env
|
||||
# Edit values in .env; set RS_PUBLIC_ACCESS=true only if public sharing is intended.
|
||||
ROUTERSHELF_ENV_FILE="$PWD/.env" sh deploy/padavan/supervisor.example.sh --check-config
|
||||
make nat-plan
|
||||
ssh router 'cat > /etc/storage/routershelf.env; chmod 600 /etc/storage/routershelf.env' < .env
|
||||
```
|
||||
|
||||
Install the matching supervisor from `deploy/padavan/supervisor.example.sh`, validate it on the target, and keep the startup/firewall hooks pointing to its installed path. `mtd_storage.sh save` persists the private environment alongside the hooks on the observed firmware. Back it up privately; it is not a public example.
|
||||
|
||||
The obsolete `/etc/storage/public-share-public` marker is no longer used. `RS_PUBLIC_ACCESS` is the source of truth. Keeping an old marker does not grant access with this version.
|
||||
|
||||
## Applying changes
|
||||
|
||||
Editing the file alone does not reload a running supervisor or application's environment. Stop the verified supervisor, wait for its child and PID cleanup, then start one supervisor again. Save the edited env to flash. This can briefly interrupt downloads.
|
||||
|
||||
For domain/IP/port changes, review the printed gateway plan and update DNS/NAT manually as needed. For shared root or USB changes, verify mount and read permissions. Keep the existing certificate cache when the domain is unchanged. Rebuilding is required only for code/theme changes, not configuration changes.
|
||||
|
||||
The firewall reconciles its own IPv4 rules, including previous internal ports, while blocking traffic during replacement. IPv6 blocks on old ports are retained; review them during cleanup. A failure can leave temporary IPv4 DROP rules to keep the service closed. Inspect and resolve the failure before removing these blocks. Do not run simultaneous firewall managers.
|
||||
|
||||
## Git and archives
|
||||
|
||||
`.env` and private variants are ignored; `.env.example` is explicitly included. Public ZIPs must include only the example. `.gitignore` does not remove already committed secrets: check staged content before publication and rotate any exposed credentials.
|
||||
@@ -0,0 +1,80 @@
|
||||
# Deployment history and verification
|
||||
|
||||
This is a sanitized account of the work completed on the original home network. Example addresses are used throughout. It records the final behavior and the limits of validation, rather than implying that every suggested test was performed.
|
||||
|
||||
## 1. Network inspection and correction
|
||||
|
||||
The LHG5 was the Internet gateway. The NW-651D supplied Wi-Fi and additional LAN ports, with the gateway connected to a **LAN** port. Internet already worked on the user's computer. The empty modem WAN port explained the panel's disconnected-WAN indication.
|
||||
|
||||
We installed and saved the storage host's default route through the LHG5 on `br0`, metric 1. DHCP remained enabled on the NW-651D; clients were configured to use the LHG5 as their gateway and public DNS servers. Existing static leases and ARP bindings were retained. Bounded Internet and DNS-related reachability checks succeeded. Moving the cable to WAN was not necessary for this topology.
|
||||
|
||||
## 2. SSH discovery and temporary status dashboard
|
||||
|
||||
Authorized SSH access revealed BusyBox, OpenSSH/SFTP, vsftpd, curl, cron, and iperf3. A shell/Netcat dashboard was built on port 8080 to show uptime, approximate RAM use, load, and bounded connectivity probes. LAN firewall rules, IPv6 blocking, startup/firewall hooks, and flash saving were added. HTTP responses and browser rendering were checked.
|
||||
|
||||
At the user's request, this dashboard was completely removed from the router: scripts, hooks, dedicated firewall rules, runtime files, and installation backups were cleaned up, and flash was saved. The public documentation project and dashboard teaching templates were retained on the computer.
|
||||
|
||||
## 3. USB storage and transfer services
|
||||
|
||||
A roughly 1 TB USB disk was mounted read/write as exFAT. A temporary local file was written, read back, and removed successfully. FTP configuration allowed authenticated local users and writes, disabled anonymous access, and selected passive ports 50000–50100. An anonymous FTP attempt returned 530.
|
||||
|
||||
**An authenticated FTP upload/download was not completed**, because credentials were not provided for that test. Configured write support and successful local disk I/O do not prove authenticated FTP permissions. SFTP login through the existing SSH key was verified; an SFTP file-transfer test was not completed at that stage.
|
||||
|
||||
## 4. Gateway port forwarding cleanup
|
||||
|
||||
A WAN TCP 222 rule was created to forward SSH to the NW-651D's TCP 22. Eight old destination-NAT forwarding rules were removed at the user's request. The Internet source-NAT rule was preserved. This SSH forwarding rule remains separate from file sharing.
|
||||
|
||||
## 5. Public USB directory on port 8888
|
||||
|
||||
A Go directory server was compiled for Linux/MIPS little-endian and deployed from a hidden service directory outside `public-storage`. It listed folders and forced regular-file downloads. GET/HEAD were allowed; upload and deletion methods were rejected. Hidden paths, traversal, and escaping symlinks were blocked. A child supervisor, USB mount checks, bounded connections, firewall hooks, and flash persistence were installed.
|
||||
|
||||
A WAN TCP 8888 forward was created after explicit approval for unauthenticated public access. Listing and download of a small test file succeeded locally; its checksum matched. PUT returned 405 without creating a file; traversal returned 404. Initial resident memory was approximately 3 MiB. External download was not independently verified at this stage.
|
||||
|
||||
## 6. HTTPS and standard ports
|
||||
|
||||
DNS was confirmed to point to the LHG5's public IPv4 address. The router clock was corrected. NTP server settings and a BusyBox NTP startup command were added. A current CA root bundle was installed outside the public directory so the Go ACME client could validate its outbound TLS connection.
|
||||
|
||||
The Go server gained `autocert`, with a whitelist for one domain and a persistent certificate/account cache on USB. It listens internally on TCP 10443 for HTTPS and TCP 10080 for ACME HTTP challenges and redirects. A trusted Let's Encrypt certificate was issued. Automatic renewal support is enabled; a future renewal has not yet been observed.
|
||||
|
||||
The gateway forwards public TCP 443 to internal 10443 and TCP 80 to internal 10080. The rules match the deployment's public IPv4 address. A scoped LAN source-NAT rule enables hairpin access so the same domain works from inside the home. The old WAN 8888 rule was disabled; no server listens on 8888.
|
||||
|
||||
Validated: certificate hostname/issuer/expiry, trusted HTTPS without disabling validation, HTTP 308 redirect, listing, file download and byte equality, PUT 405, hidden-path 404, and browser rendering at the real domain. Certificate authority validation demonstrated inbound challenge reachability. A separate mobile-data or remote-client download remains an additional verification step. Resident memory after TLS was approximately 9 MiB. The server runs as UID/GID 65534 after dropping privileges.
|
||||
|
||||
NTP replies were observed during setup. A later documentation-time check did not return an NTP PID, although the clock remained correct. Do not assume that NTP remains running: verify it after firmware events and reboot, as described in the operations guide.
|
||||
|
||||
## 7. NAIS styling
|
||||
|
||||
NAIS CSS, JavaScript, and favicon assets were copied from the user's local clone and embedded in the Go binary. No nginx installation was needed. The HTML uses an autoindex-like heading and preformatted file rows. Theme assets are served from a reserved `/_nais/` namespace.
|
||||
|
||||
Small integration changes: fixed row alignment, mobile header wrapping, a read-only footer, explicit file markers so extensionless files enter copied links/playlists, and copy success/failure feedback. The original NAIS checkout was not edited.
|
||||
|
||||
The dark theme rendered in the browser. HTTPS file download stayed intact. A downloaded DPL playlist contained the correct HTTPS file URL. The Copy Links button reported `Copied!`; the automation clipboard readback did not independently confirm the OS clipboard content, so manually paste the result when checking a new browser.
|
||||
|
||||
## Current service inventory
|
||||
|
||||
| Component | State |
|
||||
| --- | --- |
|
||||
| LAN status dashboard, TCP 8080 | Removed from router; teaching source retained |
|
||||
| FTP | Configured for authenticated read/write; end-to-end authenticated transfer still requires verification |
|
||||
| SFTP/SSH | Key login checked; WAN TCP 222 forward retained |
|
||||
| Public HTTP, TCP 8888 | Old gateway rule disabled; listener replaced |
|
||||
| HTTP, public TCP 80 | ACME challenge responses and redirect to HTTPS |
|
||||
| HTTPS, public TCP 443 | Read-only directory server with NAIS |
|
||||
| Certificate renewal | Enabled in code; future renewal not yet exercised |
|
||||
| Boot persistence | Hooks and flash save checked; full reboot test outstanding |
|
||||
|
||||
Future checks should be recorded with dates and outcomes. Avoid promoting a configured feature to a tested guarantee.
|
||||
|
||||
## 8. Environment-based configuration
|
||||
|
||||
Network and installation values were moved into an ignored private `.env` on the computer and `/etc/storage/routershelf.env` on the router. A tracked `.env.example` supplies public placeholders. The same supervisor source now loads the configuration; the Go binary reads exported settings with CLI overrides.
|
||||
|
||||
The live router was migrated with the same domain, addresses, paths, and listener ports. The existing certificate cache was retained and a pre-migration script/binary backup kept privately. The old public-access marker no longer controls permissions; `RS_PUBLIC_ACCESS` does. Owned IPv4 firewall rules were rebuilt from the configuration, removing the unused 8888 jump.
|
||||
|
||||
Validated: example and live config checks, invalid-port rejection, Go environment/override and unsafe-config tests, MIPS build, live trusted HTTPS/download, HTTP redirect, PUT 405, private env path 404, live chain scope, dropped UID/GID, and flash save. The full reboot and future renewal checks remain outstanding. The NAT-plan utility prints configuration guidance without changing the gateway.
|
||||
|
||||
## 9. Static pages in the same shared root
|
||||
|
||||
The application now renders a directory's readable regular `index.html` before listing it, and serves direct HTML requests inline. Recognized CSS/JavaScript/image/font assets have explicit MIME types. Other files retain attachment downloads. No separate root or URL prefix, new env settings, or gateway rules were added.
|
||||
|
||||
The binary was deployed with the previous version kept for rollback. Tests covered folder/root index precedence, direct HTML and assets, HEAD, preserved downloads, listing link attributes, and an escaping index symlink. A temporary live page rendered over HTTPS with CSS and JavaScript; its direct HTML link rendered too. HEAD confirmed HTML without attachment disposition, a normal text file still had attachment disposition, and PUT remained 405. Temporary probe files were removed after testing. Static pages intentionally permit browser-side active content; no PHP/CGI/server-side execution was added.
|
||||
@@ -0,0 +1,289 @@
|
||||
# Build a Small LAN Web Service on a Linux Router
|
||||
|
||||
> Historical example: this LAN dashboard was removed from the original router. For the current public HTTPS/NAIS service, read [getting-started.md](../getting-started.md) and [operations.md](../operations.md). The two services have different access and security models.
|
||||
|
||||
This guide explains how to build, install, and maintain a service like the included router dashboard. It assumes you own or administer the router and have an authorized SSH account. The example is deliberately small enough to run without installing a language runtime.
|
||||
|
||||
## 1. Understand the architecture
|
||||
|
||||
```text
|
||||
LAN browser -> router TCP port 8080 -> Netcat -> shell request handler
|
||||
|
|
||||
+-> /proc status files
|
||||
+-> bounded ICMP probes
|
||||
+-> 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 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.
|
||||
|
||||
## 2. Inspect your target before designing the service
|
||||
|
||||
Use your own SSH alias. In the examples, `router` is an illustrative alias, not a credential bundled with this repository.
|
||||
|
||||
```sh
|
||||
ssh router
|
||||
uname -a
|
||||
busybox
|
||||
nc --help
|
||||
cat /proc/meminfo
|
||||
cat /proc/mtd
|
||||
mount
|
||||
df -h
|
||||
netstat -lnt
|
||||
iptables -S INPUT
|
||||
ip6tables -S INPUT
|
||||
```
|
||||
|
||||
Check these requirements:
|
||||
|
||||
- Linux exposes `/proc/uptime`, `/proc/meminfo`, and `/proc/loadavg`.
|
||||
- The installed shell supports `read -r -t`; this is an extension, not portable POSIX `sh` behavior.
|
||||
- Netcat supports persistent `-ll` listening with `-e PROGRAM`. Other Netcat implementations have different options.
|
||||
- `awk`, `ping -c ... -W ...`, `nohup`, `grep`, `iptables`, and `ip6tables` exist.
|
||||
- The chosen TCP port is unused.
|
||||
- You know the LAN bridge interface, LAN address, client subnet, and upstream gateway.
|
||||
- The firmware provides a writable configuration directory and an understood mechanism to save it across power cycles.
|
||||
|
||||
The original router had about 128 MiB RAM, a read-only SquashFS root, and a 512 KiB persistent Storage partition. Its runtime `/etc/storage` directory was backed by RAM. `df` alone does not reveal the persistent flash capacity: inspect `/proc/mtd` too. Do not fill flash or assume that a writable runtime file survives reboot.
|
||||
|
||||
Read the device's own help first. BusyBox builds can omit applets or features even when the same version is reported. If a suitable HTTP daemon is already installed, consider using it instead of Netcat; do not repurpose the management panel daemon without documentation.
|
||||
|
||||
## 3. Write a fixed, read-only request handler
|
||||
|
||||
See [`../../examples/status-dashboard/scripts/status-response.sh`](../../examples/status-dashboard/scripts/status-response.sh).
|
||||
|
||||
The script accepts only `GET /` and `GET /status`, returning 404 for other requests. It consumes the request headers before sending the page. Request text is never executed, passed to `eval`, or used as a filesystem path.
|
||||
|
||||
A minimal HTTP response needs a status line, headers, a blank line, and a body. Lines in the header section use CRLF:
|
||||
|
||||
```sh
|
||||
printf 'HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnection: close\r\n\r\n'
|
||||
```
|
||||
|
||||
The example does not send Content-Length for successful responses. Instead, it sends `Connection: close`; completion of the handler closes the response stream. Its empty 404 response includes `Content-Length: 0`.
|
||||
|
||||
The included headers disable browser caching, prevent MIME sniffing, block framing, and permit only the inline CSS used by the page. There are no cookies, external fonts, scripts, or analytics.
|
||||
|
||||
### Metrics and interpretation
|
||||
|
||||
| Metric | Source | Interpretation |
|
||||
| --- | --- | --- |
|
||||
| Uptime | `/proc/uptime` | Converted to days, hours, and minutes |
|
||||
| Memory | `/proc/meminfo` | Total minus free, buffers, and cached memory; approximate, not MemAvailable |
|
||||
| Load averages | `/proc/loadavg` | Workload averages over 1, 5, and 15 minutes; not CPU percentages |
|
||||
| Gateway reachability | `ping -c 1 -W 1` | One bounded ICMP probe |
|
||||
| Internet probe | `ping -c 1 -W 2` | One bounded probe to a chosen public IP |
|
||||
|
||||
A failed probe can mean blocked ICMP rather than an outage. The IP probe does not test DNS, HTTPS, or every website. Successful Internet access from the router also does not prove that every client has the correct DHCP lease.
|
||||
|
||||
The page refreshes through `<meta http-equiv="refresh" content="30">`. Every open tab generates its own requests. This is a live snapshot, not historical monitoring.
|
||||
|
||||
## 4. Prepare configuration on your computer
|
||||
|
||||
From the repository root, enter the standalone example directory first:
|
||||
|
||||
```sh
|
||||
cd examples/status-dashboard
|
||||
```
|
||||
|
||||
```sh
|
||||
cp config.example.sh config.sh
|
||||
```
|
||||
|
||||
Edit `config.sh` to match your router. The example subnet is illustrative:
|
||||
|
||||
```sh
|
||||
LAN_INTERFACE=br0
|
||||
LAN_IP=192.168.50.1
|
||||
LAN_SUBNET=192.168.50.0/24
|
||||
GATEWAY_IP=192.168.50.2
|
||||
PROBE_IP=1.1.1.1
|
||||
PORT=8080
|
||||
```
|
||||
|
||||
Use numeric IP addresses, a valid CIDR subnet, and an unused unprivileged TCP port. The configuration is sourced as shell code and must be treated as administrator-controlled code. Do not generate it from HTTP input. Do not commit the real configuration.
|
||||
|
||||
Before upload, check syntax:
|
||||
|
||||
```sh
|
||||
sh -n scripts/status-response.sh
|
||||
sh -n scripts/status-service.sh
|
||||
sh -n config.sh
|
||||
```
|
||||
|
||||
Syntax checks on a desktop do not prove support for BusyBox extensions. Repeat them on the router, then exercise the requests there.
|
||||
|
||||
## 5. Upload the files
|
||||
|
||||
The following commands assume the reviewed Padavan-style `/etc/storage` layout. Adapt them for other firmware; do not invent persistence paths.
|
||||
|
||||
```sh
|
||||
ssh router 'mkdir -p /etc/storage/router-status; chmod 700 /etc/storage/router-status'
|
||||
ssh router 'cat > /etc/storage/router-status/config.sh' < config.sh
|
||||
ssh router 'cat > /etc/storage/router-status/status-response.sh' < scripts/status-response.sh
|
||||
ssh router 'cat > /etc/storage/router-status/status-service.sh' < scripts/status-service.sh
|
||||
ssh router 'chmod 600 /etc/storage/router-status/config.sh; chmod 700 /etc/storage/router-status/status-response.sh /etc/storage/router-status/status-service.sh'
|
||||
```
|
||||
|
||||
Using SSH input redirection avoids depending on an SFTP subsystem. Do not replace unrelated files or upload an entire router backup into the repository.
|
||||
|
||||
Check syntax and file ownership on the router:
|
||||
|
||||
```sh
|
||||
ssh router 'sh -n /etc/storage/router-status/status-response.sh; sh -n /etc/storage/router-status/status-service.sh; ls -l /etc/storage/router-status'
|
||||
```
|
||||
|
||||
## 6. Restrict access before starting the listener
|
||||
|
||||
See [`../../examples/status-dashboard/scripts/status-service.sh`](../../examples/status-dashboard/scripts/status-service.sh). The service manager applies its firewall rules before starting Netcat. It uses a dedicated IPv4 chain, `RS_STATUS`, reached from INPUT for the configured port.
|
||||
|
||||
The only allow rule requires all three:
|
||||
|
||||
1. Arrival on the configured LAN interface.
|
||||
2. Source address in the configured client subnet.
|
||||
3. Destination address equal to the configured router LAN IP.
|
||||
|
||||
All other IPv4 traffic to the service is dropped. IPv6 traffic to its port is also dropped. The stock Netcat listener may bind all addresses, including an IPv6 wildcard socket; firewall enforcement is therefore essential.
|
||||
|
||||
Run and inspect the rules first:
|
||||
|
||||
```sh
|
||||
ssh router '/etc/storage/router-status/status-service.sh --firewall'
|
||||
ssh router 'iptables -S INPUT; iptables -S RS_STATUS; ip6tables -S INPUT'
|
||||
```
|
||||
|
||||
Do not continue if commands fail or the expected rules are missing. Some embedded firewall builds behave unexpectedly with `iptables -C`; this example checks listed rules instead. It requires `iptables -S` support.
|
||||
|
||||
The example does not automatically change an existing chain to new LAN settings. If configuration changes, stop the listener, remove the service's old rules using its old configuration, then apply the new settings. Do not flush the router's overall firewall.
|
||||
|
||||
There is no authentication. Any permitted LAN client can read the dashboard. See [the security model](../../SECURITY.md) for limitations. Keep it off public and untrusted guest networks.
|
||||
|
||||
## 7. Start and verify the service
|
||||
|
||||
```sh
|
||||
ssh router '/etc/storage/router-status/status-service.sh'
|
||||
```
|
||||
|
||||
The manager launches:
|
||||
|
||||
```sh
|
||||
nohup nc -ll -p "$PORT" -e "$SERVICE_DIR/status-response.sh" \
|
||||
</dev/null >/tmp/router-status.log 2>&1 &
|
||||
```
|
||||
|
||||
The PID goes into `/tmp/router-status.pid`. Logs and PID files are temporary; the executable scripts and configuration belong in persistent storage.
|
||||
|
||||
From a permitted LAN client, substitute your router's address and configured port:
|
||||
|
||||
```sh
|
||||
curl --max-time 10 -i http://192.168.50.1:8080/
|
||||
curl --max-time 10 -i http://192.168.50.1:8080/status
|
||||
curl --max-time 10 -i http://192.168.50.1:8080/missing
|
||||
```
|
||||
|
||||
Expect 200 and an HTML page for the first two, and 404 for the third. Open the page in a browser and check layout, metrics, and refresh behavior. If available, try from a guest/VLAN client outside the allow rule; it should not connect. Verify IPv6 is blocked too.
|
||||
|
||||
A request from the router itself may fail because it arrives on loopback rather than the permitted LAN interface. Test from a LAN client; do not weaken the access rule just to make a loopback test succeed.
|
||||
|
||||
To diagnose startup:
|
||||
|
||||
```sh
|
||||
ssh router 'cat /tmp/router-status.log; netstat -lnt; cat /tmp/router-status.pid'
|
||||
```
|
||||
|
||||
A running PID is not sufficient evidence that the listener is healthy. Check its command line and make an actual HTTP request.
|
||||
|
||||
## 8. Configure persistence without overwriting existing hooks
|
||||
|
||||
On the reviewed firmware, `/etc/storage/started_script.sh` runs after startup when networking is ready. `/etc/storage/post_iptables_script.sh` runs after firmware firewall rebuilds. Inspect both files before editing them. Back them up privately on the router or your own computer.
|
||||
|
||||
Add these lines once to `started_script.sh`, before any unconditional exit:
|
||||
|
||||
```sh
|
||||
# Router status service
|
||||
/etc/storage/router-status/status-service.sh
|
||||
```
|
||||
|
||||
Add these lines once to `post_iptables_script.sh`, also before any unconditional exit:
|
||||
|
||||
```sh
|
||||
# Router status service firewall
|
||||
/etc/storage/router-status/status-service.sh --firewall
|
||||
```
|
||||
|
||||
Preserve all existing custom behavior. Do not replace the whole hook or append duplicates during repeated installation. Keep hook permissions unchanged.
|
||||
|
||||
On this firmware, save the edited storage files with:
|
||||
|
||||
```sh
|
||||
ssh router 'mtd_storage.sh save'
|
||||
```
|
||||
|
||||
Check the success result. This writes the firmware's Storage partition; it is not a command to format or overwrite the firmware. Do not run it repeatedly for every page request or log update.
|
||||
|
||||
Reboot only during a suitable maintenance window. After reboot, verify HTTP access, firewall rules, and the PID. Until that test is done, describe persistence as configured, not reboot-tested.
|
||||
|
||||
## 9. Extend the example into another service
|
||||
|
||||
Keep the transport and handler responsibilities separate. For a new read-only page:
|
||||
|
||||
1. Decide exactly which information should be exposed.
|
||||
2. Collect only those values with bounded, predictable commands.
|
||||
3. Add a fixed route and render the result.
|
||||
4. Escape any text inserted into HTML. Numeric `/proc` values used here are controlled; arbitrary hostnames or log messages are not.
|
||||
5. Return the correct Content-Type. For JSON, correctly encode strings and escape control characters; do not interpolate arbitrary text into JSON.
|
||||
6. Test malformed paths, unsupported methods, missing data, timeouts, and access restrictions.
|
||||
|
||||
Do not add buttons that execute arbitrary commands. A service that changes router settings needs authentication, CSRF protection, authorization, and a more capable HTTP stack. Large applications, many clients, TLS, uploads, or public access should use a maintained server and an appropriate host.
|
||||
|
||||
## 10. Stop and remove the service
|
||||
|
||||
Use the actual port from the installed configuration. Before killing a PID, inspect its command line; a stale PID may belong to another process:
|
||||
|
||||
```sh
|
||||
ssh router
|
||||
pid=$(cat /tmp/router-status.pid)
|
||||
tr '\000' ' ' < "/proc/$pid/cmdline"
|
||||
```
|
||||
|
||||
Only after confirming it is this service's Netcat listener:
|
||||
|
||||
```sh
|
||||
kill "$pid"
|
||||
rm -f /tmp/router-status.pid
|
||||
```
|
||||
|
||||
Remove the two service calls from the startup and firewall hooks. Preserve unrelated edits made since installation rather than blindly restoring an old backup.
|
||||
|
||||
With the old configuration still present:
|
||||
|
||||
```sh
|
||||
. /etc/storage/router-status/config.sh
|
||||
iptables -D INPUT -p tcp --dport "$PORT" -j RS_STATUS
|
||||
iptables -F RS_STATUS
|
||||
iptables -X RS_STATUS
|
||||
ip6tables -D INPUT -p tcp --dport "$PORT" -j DROP
|
||||
```
|
||||
|
||||
These are service-owned rules; if a matching IPv6 DROP rule existed before installation, preserve it. Inspect rules and remove duplicate service-owned jumps individually if necessary. Do not use `iptables -F INPUT`.
|
||||
|
||||
Remove only this project's directory after reviewing its contents, then save storage with the firmware's tool. Verify the port no longer answers and the management panel still works.
|
||||
|
||||
## 11. Prepare a public repository
|
||||
|
||||
- Keep real configuration, keys, backups, log output, packet captures, and private screenshots out of Git.
|
||||
- Use placeholders in documentation; never include a real SSH password or private key.
|
||||
- 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.
|
||||
|
||||
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.
|
||||
|
||||
## References
|
||||
|
||||
- [BusyBox official applet documentation](https://busybox.net/downloads/BusyBox.html): builds vary; installed `--help` output is the authority for the target.
|
||||
- [Netfilter / iptables project](https://www.netfilter.org/projects/iptables/index.html): firewall tooling and upstream documentation.
|
||||
- Device-local firmware scripts and help output were used to establish the observed storage and startup behavior. The hook paths and save command are firmware-specific.
|
||||
@@ -0,0 +1,153 @@
|
||||
# Deploy the public HTTPS directory service
|
||||
|
||||
## Architecture and paths
|
||||
|
||||
```text
|
||||
Internet or LAN browser -> files.example.com
|
||||
public TCP 80 -> gateway DNAT -> storage host TCP 10080 (ACME/redirect)
|
||||
public TCP 443 -> gateway DNAT -> storage host TCP 10443 (HTTPS listing/download)
|
||||
```
|
||||
|
||||
The service shares only `/media/DISK_ID/public-storage`. Installation layout:
|
||||
|
||||
```text
|
||||
/media/DISK_ID/public-storage/ Published files
|
||||
/media/DISK_ID/.public-share-service/public-directory Executable
|
||||
/media/DISK_ID/.public-share-service/ca-certificates.pem
|
||||
/media/DISK_ID/.public-share-service/certificates/ Private ACME account/key cache
|
||||
/etc/storage/public-share-service.sh Supervisor/firewall script
|
||||
/etc/storage/routershelf.env Private configuration
|
||||
/tmp/public-share-supervisor.pid Runtime parent PID
|
||||
/tmp/public-share-child.pid Runtime child PID
|
||||
/tmp/public-share.log Runtime log
|
||||
```
|
||||
|
||||
The certificates directory is private administrative material, despite its location on the same disk. Never put it inside `public-storage`, include it in public backups, or symlink it into the shared root. The server reserves `/_nais/` for embedded theme assets; use a different name for a real directory that must be shared.
|
||||
|
||||
## 1. Prepare source and example configuration
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Copy `.env.example` to `.env` and set the actual domain, USB mount, LAN IP/subnet/interface, and internal ports there. Set `RS_PUBLIC_ACCESS=true` only for intentional public sharing. The supervisor and Go binary derive paths from these settings; there is no per-network source edit or rebuild. See [configuration](configuration.md).
|
||||
|
||||
```sh
|
||||
cp .env.example .env
|
||||
ROUTERSHELF_ENV_FILE="$PWD/.env" sh deploy/padavan/supervisor.example.sh --check-config
|
||||
make nat-plan
|
||||
```
|
||||
|
||||
The supervisor owns `NB_PUBLIC`. It reconciles this chain and its IPv4 INPUT jumps when settings change, temporarily blocking the affected ports while rebuilding. If a firewall operation fails, temporary blocks may remain; inspect rather than bypass them. Old IPv6 DROP rules are retained for safety and can be reviewed separately. The former 8888 IPv4 jump is removed during reconciliation.
|
||||
|
||||
## 2. Prepare clock and outbound trust
|
||||
|
||||
A correct clock is required for TLS and certificate operations. Configure the firmware's NTP servers, for example `time.cloudflare.com` and `pool.ntp.org`, and check actual replies. If the clock is badly wrong, set it once from an accurate trusted computer, then verify NTP synchronization.
|
||||
|
||||
The original supervisor creates `/tmp/ntpd` as a symlink to `/bin/busybox` and launches that path. This lets `pidof ntpd` find the process; starting `busybox ntpd` can leave the process named `busybox` and cause duplicate launches. Firmware events can still stop NTP, so monitor it separately. The service supervisor does not continuously restart NTP.
|
||||
|
||||
Install a trusted CA bundle from an authenticated source. The original used the [curl CA bundle](https://curl.se/docs/caextract.html), with certificate verification enabled for its download:
|
||||
|
||||
```sh
|
||||
curl --fail --show-error --silent https://curl.se/ca/cacert.pem -o ca-certificates.pem
|
||||
ssh router 'mkdir -p /media/DISK_ID/.public-share-service'
|
||||
ssh router 'cat > /media/DISK_ID/.public-share-service/ca-certificates.pem' < ca-certificates.pem
|
||||
```
|
||||
|
||||
The supervisor passes its path as `SSL_CERT_FILE`. This fixes outbound trust; it is different from the server certificate issued for your domain. Do not bypass TLS validation with `-k` or insecure Go settings.
|
||||
|
||||
## 3. Install and start
|
||||
|
||||
Upload to a new filename first:
|
||||
|
||||
```sh
|
||||
ssh router 'cat > /media/DISK_ID/.public-share-service/public-directory.new; chmod 755 /media/DISK_ID/.public-share-service/public-directory.new' < dist/routershelf-linux-mipsle
|
||||
ssh router 'mv /media/DISK_ID/.public-share-service/public-directory.new /media/DISK_ID/.public-share-service/public-directory'
|
||||
ssh router 'cat > /etc/storage/routershelf.env; chmod 600 /etc/storage/routershelf.env' < .env
|
||||
ssh router 'cat > /etc/storage/public-share-service.sh; chmod 755 /etc/storage/public-share-service.sh' < deploy/padavan/supervisor.example.sh
|
||||
ssh router '/etc/storage/public-share-service.sh --check-config'
|
||||
```
|
||||
|
||||
Do not overwrite a running binary in place; see the update procedure in the operations guide. These commands assume the intended shared directory already exists and that the paths match the mounted disk.
|
||||
|
||||
The supervisor checks for the exact mounted USB path every 10 seconds, stops the child when the mount disappears, and restarts it when available. It sets `GOMEMLIMIT=32MiB` and `GOMAXPROCS=2`; the memory limit is a Go garbage-collection target, **not** a hard process limit. The program then drops supplementary groups and runs as UID/GID 65534. Directory traversal permissions must allow that user to read the shared data and use its cache.
|
||||
|
||||
Enable public mode only when publishing all current and future shared-directory content is intended:
|
||||
|
||||
```sh
|
||||
# Set RS_PUBLIC_ACCESS=true in the private env for intentional public access.
|
||||
ssh router '/etc/storage/public-share-service.sh'
|
||||
```
|
||||
|
||||
The modem firewall uses `NB_PUBLIC` on INPUT for the internal service ports. Public mode accepts packets arriving on `br0` destined for the host address, including forwarded packets with Internet source addresses. A LAN-source-only allow rule would reject those DNAT connections. The final chain rule drops other traffic. IPv6 access is blocked; no IPv6 publication was implemented.
|
||||
|
||||
## 4. Save firmware hooks
|
||||
|
||||
Append each command **once**, retaining the existing script contents:
|
||||
|
||||
```sh
|
||||
# /etc/storage/started_script.sh, after network startup
|
||||
/etc/storage/public-share-service.sh
|
||||
|
||||
# /etc/storage/post_iptables_script.sh, after firewall rebuild
|
||||
/etc/storage/public-share-service.sh --firewall
|
||||
```
|
||||
|
||||
Back up these scripts privately before editing. The firmware's `/etc/storage` is a RAM-backed working directory. Persist changes with its supported helper:
|
||||
|
||||
```sh
|
||||
mtd_storage.sh save
|
||||
```
|
||||
|
||||
Use this command on the matching firmware only. It saves the small configuration hooks to flash; the binary, CA bundle, and ACME cache remain on USB. Avoid saving to flash for routine traffic, logs, or certificate renewal. A successful save is not a reboot test.
|
||||
|
||||
## 5. Configure DNS and gateway NAT
|
||||
|
||||
Point the public DNS A record for `files.example.com` to the gateway's public IPv4 address. Do not advertise AAAA unless you deliberately implement and test IPv6. Check `dig +short files.example.com A` and `dig +short files.example.com AAAA`.
|
||||
|
||||
Create the following RouterOS NAT rules through WebFig or an authorized RouterOS administrator session. Preserve the existing Internet source-NAT rule and separate SSH forward.
|
||||
|
||||
| Purpose | Chain and match | Action |
|
||||
| --- | --- | --- |
|
||||
| HTTPS | `dstnat`, destination `203.0.113.10`, TCP destination port 443 | `dst-nat` to `192.168.50.1:10443` |
|
||||
| HTTP/ACME | `dstnat`, destination `203.0.113.10`, TCP destination port 80 | `dst-nat` to `192.168.50.1:10080` |
|
||||
| LAN hairpin reply | `srcnat`, source `192.168.50.0/24`, destination `192.168.50.1`, TCP destination ports `10080,10443`, output `ether1` | `src-nat` to `192.168.50.2` |
|
||||
| Separate SSH | `dstnat`, input `pppoe-out1`, TCP destination port 222 | `dst-nat` to `192.168.50.1:22` |
|
||||
|
||||
The HTTPS/HTTP rules deliberately match the public address without a WAN-only input restriction, so LAN clients using the same public DNS answer can hit them too. Hairpin source NAT routes replies back through the gateway rather than directly to the LAN client. Restrict it to these service ports. Review filter rules as well: NAT alone does not authorize a packet that a forward-chain filter drops.
|
||||
|
||||
If the public IP changes, update both DNS and these two destination-address matches. Dynamic DNS alone does not update the hardcoded NAT rules. A private ISP address or CGNAT requires a different connectivity solution; port forwarding on the home router cannot bypass an upstream NAT you do not control.
|
||||
|
||||
## 6. Obtain and verify HTTPS
|
||||
|
||||
`autocert.Manager` whitelists the configured domain, accepts the CA terms in code, obtains a certificate on demand, stores its account/certificate cache on USB, and schedules renewal while running. Review the CA terms before enabling this configuration. Public certificates are recorded in certificate transparency logs.
|
||||
|
||||
The HTTP handler serves ACME challenges and redirects ordinary GET/HEAD requests to the fixed HTTPS domain with HTTP 308. Unknown HTTP hosts are rejected; redirects do not trust arbitrary Host headers. TLS uses a minimum of TLS 1.2. The application limits connections and header sizes and uses request timeouts.
|
||||
|
||||
Issue the first request at `https://files.example.com/`. Initial issuance may exceed the short handshake timeout and fail once; inspect logs and the cache, then retry after issuance completes. Do not repeatedly delete the cache or loop certificate requests, as CA rate limits apply.
|
||||
|
||||
```sh
|
||||
curl --fail --show-error https://files.example.com/
|
||||
curl -I http://files.example.com/
|
||||
curl --fail --show-error https://files.example.com/your-test-file.txt -o downloaded-test.txt
|
||||
openssl s_client -connect files.example.com:443 -servername files.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
|
||||
```
|
||||
|
||||
Compare the download with its source. Use normal trusted certificate validation. Test once from outside the LAN, such as mobile data with Wi-Fi disabled. A LAN success verifies hairpin behavior; a successful CA challenge verifies a challenge route, not every external client's full download path.
|
||||
|
||||
## 7. How NAIS is integrated
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
References: [Go autocert](https://pkg.go.dev/golang.org/x/crypto/acme/autocert), [Let's Encrypt challenges](https://letsencrypt.org/docs/challenge-types/), [NAIS](https://github.com/meghdadfadaee/nais).
|
||||
@@ -0,0 +1,101 @@
|
||||
# Network and USB transfer configuration
|
||||
|
||||
## Network roles
|
||||
|
||||
```text
|
||||
Internet / PPPoE
|
||||
|
|
||||
MikroTik LHG5: 192.168.50.2 (gateway)
|
||||
| LAN cable
|
||||
NW-651D LAN port: 192.168.50.1 (Wi-Fi, LAN switch, USB services)
|
||||
|
|
||||
Home computers and phones
|
||||
```
|
||||
|
||||
Use a LAN-to-LAN connection for this arrangement. Using the NW-651D WAN port would require a different routing design and can create a second NAT layer. The gateway handles Internet/PPPoE; the NW-651D is also a service host, not just a passive switch.
|
||||
|
||||
Keep both management addresses outside the DHCP pool. In the original configuration the storage host ran DHCP, rather than the gateway. Run only one intended DHCP server on a shared broadcast domain.
|
||||
|
||||
| Storage-host setting | Example |
|
||||
| --- | --- |
|
||||
| LAN address / mask | `192.168.50.1/24` |
|
||||
| Its default route | `0.0.0.0/0` via `192.168.50.2`, metric 1, `br0` |
|
||||
| DHCP pool | `192.168.50.100`–`192.168.50.244` |
|
||||
| DHCP default gateway | `192.168.50.2` |
|
||||
| DHCP DNS | `1.1.1.1`, `8.8.8.8` |
|
||||
| Gateway LAN address | `192.168.50.2/24` |
|
||||
| Gateway Internet interface | `pppoe-out1` |
|
||||
| Gateway LAN interface | `ether1` |
|
||||
|
||||
Save the static route and DHCP settings through the firmware's supported configuration mechanism. Renew client leases to receive changed DHCP options. A `route add` command alone normally does not survive reboot. Retain existing leases/ARP bindings unless deliberately changing them.
|
||||
|
||||
On the storage host, inspect `route -n`, the active dnsmasq configuration, and `ping -c 1 -W 2 192.168.50.2`. Check a known HTTPS website from both the host and a client. A panel may still report WAN disconnected because the WAN port is unused; do not change an otherwise working topology solely to change that badge.
|
||||
|
||||
## SSH and SFTP
|
||||
|
||||
Configure a private SSH alias on your computer, for example in `~/.ssh/config`:
|
||||
|
||||
```sshconfig
|
||||
Host router
|
||||
HostName 192.168.50.1
|
||||
Port 22
|
||||
User admin
|
||||
IdentityFile ~/.ssh/your_private_key
|
||||
```
|
||||
|
||||
Never commit the private key or a real SSH configuration to the repository. Verify the router's host key before first use. The observed firmware provided `/usr/libexec/sftp-server`.
|
||||
|
||||
```sh
|
||||
ssh router
|
||||
sftp router
|
||||
```
|
||||
|
||||
A separate gateway forward can map WAN TCP 222 to the storage host's TCP 22. Scope that rule to `pppoe-out1`, use key authentication, and inspect the existing SSH configuration before exposing it. This mapping does not configure SSH authentication by itself. An external SFTP client then uses the public hostname, port 222, and the authorized SSH account. Do not assume port 22 on the public address reaches the storage host.
|
||||
|
||||
SFTP encrypts credentials and transferred data. Plain FTP does not. For public or untrusted-network transfers, use SFTP rather than exposing the plain FTP service.
|
||||
|
||||
## Inspect USB storage
|
||||
|
||||
```sh
|
||||
mount
|
||||
cat /proc/mounts
|
||||
df -h /media/DISK_ID
|
||||
ls -ld /media/DISK_ID /media/DISK_ID/public-storage
|
||||
```
|
||||
|
||||
The original disk was exFAT, mounted read/write. The mount used `fmask=0000,dmask=0000`: Unix permission bits and `chmod 600` are not reliable isolation on this filesystem. Account restrictions and service path boundaries matter. An authenticated storage account that can read the whole disk may also read the service's private keys outside the public directory. Restrict account scope or use a filesystem with enforced permissions when stronger local isolation is needed.
|
||||
|
||||
Use a unique disposable probe, not an existing filename:
|
||||
|
||||
```sh
|
||||
probe_dir=/media/DISK_ID/usb-probe-CHOOSE_A_UNIQUE_SUFFIX
|
||||
mkdir "$probe_dir" || exit 1
|
||||
printf 'USB read/write probe\n' > "$probe_dir/probe.txt"
|
||||
cat "$probe_dir/probe.txt"
|
||||
rm "$probe_dir/probe.txt"
|
||||
rmdir "$probe_dir"
|
||||
```
|
||||
|
||||
Only remove files created for the test. If the disk is read-only, inspect mount flags and firmware logs before retrying. Back up valuable data and perform filesystem repair while unmounted, preferably on a computer with appropriate exFAT tools.
|
||||
|
||||
## FTP settings and a real transfer test
|
||||
|
||||
The observed vsftpd settings were:
|
||||
|
||||
```ini
|
||||
local_enable=YES
|
||||
anonymous_enable=NO
|
||||
write_enable=YES
|
||||
pasv_min_port=50000
|
||||
pasv_max_port=50100
|
||||
```
|
||||
|
||||
These flags permit the feature; they do not establish every user's effective directory permission. Firmware-generated configuration can overwrite direct edits, so use the panel's supported FTP and account settings. Anonymous login should fail. Do not turn it on to work around account problems.
|
||||
|
||||
For a LAN test, connect a client such as FileZilla to `192.168.50.1`, port 21, with an authorized FTP account. Use passive mode. Upload a unique small text file into a permitted test directory, list the directory, download it under a different local name, compare the bytes or checksum, then remove only the probe. A successful login alone is not a read/write test.
|
||||
|
||||
On the LAN, passive data ports must pass the host firewall. Publishing FTP would also require control/data-port forwarding and correct advertised passive addresses; this was **not configured** in the original work. Prefer SFTP for remote transfer.
|
||||
|
||||
To verify SFTP, use its interactive `put`, `ls`, `get`, and `rm` commands on a uniquely named probe, then compare the downloaded file locally. Resolve server filesystem/account permissions if writes fail; do not make the entire disk publicly writable.
|
||||
|
||||
Keep a test record stating which account, protocol, read, write, and cleanup operations succeeded. Omit passwords and private keys from that record.
|
||||
@@ -0,0 +1,123 @@
|
||||
# Maintenance and recovery
|
||||
|
||||
## Routine care
|
||||
|
||||
| Frequency / event | Check |
|
||||
| --- | --- |
|
||||
| After installation, reboot, or power loss | USB mounted at the expected path; accurate time; NTP replies; supervisor and child running; firewall rules reapplied; HTTPS download works |
|
||||
| Weekly | Disk free space, router memory, repeated errors/restarts, ordinary listing/download, account access |
|
||||
| Monthly and before expiry | Certificate expiry, renewal errors, DNS/public-IP match, router/toolchain/dependency security updates |
|
||||
| After changing ISP/public IP | Update DNS A record **and** the two public-IP destination NAT rules; test on mobile data and LAN |
|
||||
| After changing the disk or USB port | Verify mount ID, update supervisor paths if needed, restore private cache and executable, test restart |
|
||||
| After adding public files | Check the listing and encoded filenames; ensure that the entire file and its name are intended for publication |
|
||||
| Before firmware upgrade | Back up private configuration, verify hook compatibility and binary/kernel support, arrange a rollback path |
|
||||
|
||||
Do not interpret a successful HTTP request as proof of disk health, NTP synchronization, or renewal. The current implementation does not provide monitoring alerts, filesystem snapshots, or a hard resource quota.
|
||||
|
||||
## Read-only health checks
|
||||
|
||||
On the router:
|
||||
|
||||
```sh
|
||||
date -u
|
||||
pidof ntpd
|
||||
cat /tmp/public-share-supervisor.pid
|
||||
cat /tmp/public-share-child.pid
|
||||
cat /tmp/public-share.log
|
||||
cat /proc/mounts
|
||||
df -h /media/DISK_ID
|
||||
iptables -S NB_PUBLIC
|
||||
iptables -S INPUT
|
||||
ip6tables -S INPUT
|
||||
```
|
||||
|
||||
Before acting on a PID, inspect `/proc/PID/cmdline` and confirm it belongs to this service. PID files can be stale or reused. Read `/proc/PID/status` for UID/GID and `VmRSS`; do not treat the large virtual address size reported by `ps` as resident RAM use. The observed HTTPS process used around 9 MiB RSS, but traffic and file sizes affect resource use.
|
||||
|
||||
Check NTP replies as well as process existence. If `pidof ntpd` is empty, inspect the firmware behavior and start the configured `/tmp/ntpd` command deliberately. The current startup hook starts NTP once; it does not continuously supervise it. The daemon was observed absent during a later check, so reboot and firmware reconnect behavior require special attention. Correct any inaccurate clock before requesting new certificates.
|
||||
|
||||
From a client:
|
||||
|
||||
```sh
|
||||
curl -I http://files.example.com/
|
||||
curl --fail --show-error https://files.example.com/ -o listing.html
|
||||
curl --fail --show-error https://files.example.com/your-test-file.txt -o probe-download.txt
|
||||
```
|
||||
|
||||
Expected: HTTP redirects to the fixed HTTPS hostname, HTTPS succeeds with normal validation, file bytes match, and navigation works. Also verify that a PUT to a unique nonexistent path returns 405 without creating a file, and a hidden path returns 404. Never use an existing filename for mutation probes.
|
||||
|
||||
Check Copy Links by pasting into a local text editor. Check the DPL file contains the expected HTTPS URLs. The browser must allow clipboard access or the fallback may fail; the button shows success/failure. Long listings are truncated at 5,000 entries. The server supports HEAD and byte-range downloads for regular files.
|
||||
|
||||
## Certificates and CA trust
|
||||
|
||||
The persistent cache contains both the ACME account key and certificate private keys. Leave it intact across restarts and updates. Losing the cache can force new issuance and consume CA rate limits. Automatic renewal needs accurate time, DNS reaching the same public gateway, inbound challenge access, outbound HTTPS to the CA, a writable cache, and a running service. USB removal stops the service and prevents renewal.
|
||||
|
||||
Inspect expiry with the `openssl s_client` command in the deployment guide. Renewals run inside `autocert`; there is no separate cron job to edit. The original certificate had roughly a three-month validity, but always inspect the actual expiry instead of assuming a duration. A future automatic renewal has not yet been verified on hardware.
|
||||
|
||||
Refresh the CA root bundle periodically from a trusted source. Upload it to a temporary filename and rename it, then restart the child to make a running Go process load the new trust pool. Never solve trust failures by disabling certificate checks.
|
||||
|
||||
## Backups
|
||||
|
||||
Maintain two separate backup categories:
|
||||
|
||||
- **Public source:** this repository, example config, build notes, pinned dependencies, and licensed theme assets. Safe to publish after review.
|
||||
- **Private operational backup:** actual configuration/hooks, firmware version/settings export, router host-key information, SSH configuration, USB data, and the certificate/account cache. Encrypt it and restrict who can read it.
|
||||
|
||||
Copy `/etc/storage` configuration privately and use the firmware's supported settings export. Store the USB backup on another disk, not only alongside the original data. Test restoration to a private location. Exclude all private operational backups from Git and public ZIPs. Avoid backing up a live-changing file halfway through a transfer.
|
||||
|
||||
Never place backup archives in `public-storage` unless every byte is intended for public download. exFAT permission masks do not enforce meaningful Unix mode-based protection for the cache; review FTP/SFTP account scope.
|
||||
|
||||
## Updating the binary safely
|
||||
|
||||
1. Build and test on the computer. Keep the known-good source/toolchain version.
|
||||
2. Upload a new executable outside the shared root, using a `.new` filename.
|
||||
3. Check upload checksum/size and executable mode. Preserve a known-good installed binary under a private backup name.
|
||||
4. Rename the new binary into place. Replacing a pathname by rename leaves the old running process intact until stopped.
|
||||
5. Verify the child PID's command line, then terminate that child with TERM. The existing supervisor restarts it within its next 10-second check. Expect a brief interruption.
|
||||
6. Verify log startup, valid HTTPS, downloads, methods, navigation, theme assets, and certificate cache retention. Record the result.
|
||||
|
||||
Do not launch a second supervisor. If the supervisor itself needs replacement, stop it, wait until its trap has removed PID files and stopped the child, then start the new script. Starting immediately while the old parent still exits can cause PID detection/cleanup races. Inspect running commands rather than blindly deleting PID files.
|
||||
|
||||
The hooks call the installed script path after future startup/firewall rebuilds. Save changed hook/supervisor/env files with `mtd_storage.sh save`; a binary-only update on USB does not require a flash write.
|
||||
|
||||
## Rollback
|
||||
|
||||
For a binary regression, rename the known-good binary back into place, verify and terminate only the current child, and let the supervisor restart it. Keep the certificate cache. For a script regression, restore the saved script/hooks, reconcile only this service's firewall rules, restart one supervisor, and save flash.
|
||||
|
||||
If public access is malfunctioning or unintended, disable the service's TCP 80/443 gateway rules first; keep ordinary Internet NAT and unrelated SSH rules intact. Restore locally and test before re-enabling. Do not re-enable the old HTTP 8888 forward as an automatic rollback from TLS unless plaintext publication is intentionally acceptable.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Likely cause and next check |
|
||||
| --- | --- |
|
||||
| Modem panel says no Internet but clients work | Unused WAN port in LAN topology; verify actual default route and client gateway |
|
||||
| HTTPS connection refused | Child not running, wrong target ports, USB absent, or restart interval; read log and mount status |
|
||||
| HTTPS timeout from Internet | Incorrect DNS/NAT, forward filter, modem INPUT rule, ISP port filtering, or CGNAT |
|
||||
| Domain works outside but fails at home | Hairpin DNAT/source-NAT match or LAN routing; test the domain rather than the numeric TLS address |
|
||||
| Works at home but not on mobile data | LAN success is not external proof; inspect WAN rule counters and actual public-IP ownership |
|
||||
| Certificate issuance fails | Clock, CA roots, outbound HTTPS, domain whitelist, DNS A/AAAA, challenge reachability, or cache permissions |
|
||||
| First TLS request fails, next succeeds | Initial issuance exceeded handshake timeout; check for a newly cached certificate before retrying |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| NTP PID missing | Firmware stopped it or wrong process naming; inspect, restart deliberately, and verify replies |
|
||||
|
||||
Debug one layer at a time: DNS, gateway rule, forward filter, host firewall, listener, storage, and application. Keep logs private; they can contain addresses and errors identifying the installation.
|
||||
|
||||
## Removal without losing shared data
|
||||
|
||||
1. Disable/remove only this service's gateway 80/443 rules and scoped hairpin rule. The previously disabled 8888 rule can be removed too. Keep the Internet source-NAT and independent SSH rule unless separately removing them.
|
||||
2. Verify the supervisor PID and command, terminate it, and wait for its exit trap. Verify that its child stopped and the internal ports are no longer listening.
|
||||
3. Remove only the two inserted public-share calls/comments from `started_script.sh` and `post_iptables_script.sh`, preserving other firmware/user commands.
|
||||
4. Delete this service's INPUT jumps for 10080, 10443, and any retained 8888 hook. Remove the dedicated `NB_PUBLIC` chain only after all references are removed. Remove only the matching IPv6 DROP rules for these ports if they belong solely to this installation. Never flush entire tables.
|
||||
5. Remove the installed supervisor, private environment file, this installation's PID/log files, and private service directory/backups when no longer needed. Preserve `public-storage` and unrelated USB files. Decide separately whether to retain or securely retire the ACME key/cache.
|
||||
6. NTP is useful to the router beyond file sharing; leave it unless deliberately undoing its configuration. Revert only settings introduced for this deployment if a complete rollback is intended.
|
||||
7. Save the edited configuration to flash, check the panel/network/SSH still work, and perform a controlled reboot test when convenient.
|
||||
|
||||
For removal of the earlier status dashboard, use the separate original guide. That dashboard is already absent on the original router. Removing a service from the device does not remove its teaching source from this repository.
|
||||
|
||||
## Environment changes
|
||||
|
||||
Use [configuration.md](configuration.md) for configuration precedence and reload steps. The live environment lives at `/etc/storage/routershelf.env`, not in hardcoded source or the old public-access marker. Include this file in encrypted private backups. On config changes, restart the verified supervisor, not just the child, so new values are loaded. Code-only changes still require rebuilding; domain/path/IP changes do not.
|
||||
@@ -0,0 +1,27 @@
|
||||
# Static pages in the shared directory
|
||||
|
||||
No separate site directory or URL prefix is required. The existing `RS_ROOT` serves both directory listings and static pages.
|
||||
|
||||
- A directory request ending in `/` serves its regular, readable `index.html` when present. Otherwise, the NAIS listing appears.
|
||||
- Requests without a directory trailing slash redirect before rendering, so relative asset links work.
|
||||
- Direct `.html` and `.htm` requests render in the browser, including case-insensitive extensions.
|
||||
- CSS, JS/MJS, JSON/source maps, common images, web fonts and WASM use explicit inline MIME types. Other extensions remain attachment downloads.
|
||||
- HEAD and byte ranges are supported. PHP, CGI and other server-side code are never executed.
|
||||
|
||||
Example layout inside your existing share:
|
||||
|
||||
```text
|
||||
public-storage/
|
||||
test.txt
|
||||
brochure.html
|
||||
demo/
|
||||
index.html
|
||||
style.css
|
||||
app.js
|
||||
```
|
||||
|
||||
`/brochure.html` renders directly. `/demo/` renders its index and can use relative `style.css` and `app.js` references. Placing `index.html` at the share root makes `/` show that page; removing/renaming it restores the directory listing.
|
||||
|
||||
Publishing HTML intentionally permits browser-side code under this domain. Static pages can use inline scripts/styles and external assets. Only trusted administrators should place active content in the share. The listing retains its more restrictive content policy. No authentication or server-side execution was added; hidden paths, traversal, escaping symlinks and write methods remain blocked.
|
||||
|
||||
Deploy the new binary once using the normal update procedure. Afterwards, changing pages and assets on USB requires no rebuild or service restart; the next request reads the current files. No new env settings, gateway rules or TLS certificates are needed.
|
||||
Reference in new issue
Block a user