Add the on-box web UI: sidebar, editable dashboards, settings pages

The UI follows the Warden/FLARE console shape rather than inventing one: a
fixed sidebar of groups and items, hash-routed pages, and dashboards that are a
JSON document an operator edits in place, with a default template per deck and
server-side caps on what a save may contain.

Sections: Dashboard and Mining/Overview are editable dashboards (drag to
reorder, add a block, save, reset). Mining also serves Hashboards, Power Supply
and Fans from the hardware document. Settings serves System, Drivers, Security,
Services, Monitor, Logs, Files and Terminal. Files and Terminal are gated on a
token at /var/lib/alkane/ui-token so a shared network cannot use them.

Served on port 80 of the miner's own address (8080 if 80 cannot be bound), and
started from the runlevel so the page is up without an operator. The JSON API
remains the interface of record: every value shown is also at /api/, and nothing
is reachable only through the page.

Verified: 165 tests, clippy clean, all 13 pages answering, and on the bench S21
Pro the UI answers on port 80 after an unattended reboot.
This commit is contained in:
2026-11-04 14:06:24 -06:00
parent f6af71138c
commit 93c47d90ef
4 changed files with 1277 additions and 169 deletions
+46 -8
View File
@@ -38,10 +38,7 @@ fn sim_mine(mut args: impl Iterator<Item = String>) -> Result<(), Box<dyn Error>
.ok()
.map(|bind| bind.parse())
.transpose()?;
let web = std::env::var("ALKANE_WEB_LISTEN")
.ok()
.map(|bind| bind.parse())
.transpose()?;
let web = web_listen()?;
let servers = app::start(Arc::clone(&status), api, web)?;
let (api_address, web_address) = servers.addresses();
if let Some(address) = api_address {
@@ -212,10 +209,7 @@ fn boot_hal(mut args: impl Iterator<Item = String>) -> Result<(), Box<dyn Error>
.ok()
.map(|bind| bind.parse())
.transpose()?;
let web = std::env::var("ALKANE_WEB_LISTEN")
.ok()
.map(|bind| bind.parse())
.transpose()?;
let web = web_listen()?;
let servers = app::start(Arc::clone(&status), api, web)?;
let config = app::BootConfig {
@@ -303,6 +297,44 @@ fn boot_hal(mut args: impl Iterator<Item = String>) -> Result<(), Box<dyn Error>
Ok(())
}
/// Where the UI listens. The miner serves it on port 80 of its own address;
/// if that is not permitted (a non-root development run), fall back to 8080
/// rather than refusing to start.
fn web_listen() -> Result<Option<std::net::SocketAddr>, Box<dyn std::error::Error>> {
if let Ok(bind) = std::env::var("ALKANE_WEB_LISTEN") {
return Ok(Some(bind.parse()?));
}
let port = if std::net::TcpListener::bind("0.0.0.0:80").is_ok() {
80
} else {
8080
};
Ok(Some(std::net::SocketAddr::from(([0, 0, 0, 0], port))))
}
/// Serve the UI and the API without a mining backend. A board whose HAL
/// backend is not written yet still has to be reachable and observable; every
/// page says "not identified" rather than claiming hardware it cannot see.
fn serve_only() -> Result<(), Box<dyn std::error::Error>> {
let status = Arc::new(MiningStatus::new());
let api = std::env::var("ALKANE_API_LISTEN")
.ok()
.map(|bind| bind.parse())
.transpose()?;
let api = api.or(Some("0.0.0.0:4028".parse()?));
let servers = app::start(Arc::clone(&status), api, web_listen()?)?;
let (api_address, web_address) = servers.addresses();
if let Some(address) = api_address {
println!("management API on {address}");
}
if let Some(address) = web_address {
println!("web UI on http://{address}");
}
loop {
std::thread::sleep(Duration::from_secs(3600));
}
}
fn main() {
let mut args = std::env::args().skip(1);
match args.next().as_deref() {
@@ -316,6 +348,12 @@ fn main() {
}
}
Some("--version") => println!("alkane-os {}", env!("CARGO_PKG_VERSION")),
Some("--serve") => {
if let Err(error) = serve_only() {
eprintln!("serve failed: {error}");
std::process::exit(1);
}
}
Some("--boot") => {
if let Err(error) = boot_hal(args) {
eprintln!("boot failed: {error}");