2026-06-28 18:42:20 +00:00
|
|
|
pub mod config;
|
|
|
|
|
pub mod install;
|
|
|
|
|
pub mod wifi;
|
|
|
|
|
|
|
|
|
|
pub use config::TollGateConfig;
|
|
|
|
|
pub use install::install_tollgate;
|
|
|
|
|
pub use wifi::provision_ssid;
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use tracing::info;
|
|
|
|
|
|
2026-06-30 17:12:50 +00:00
|
|
|
use crate::{opkg::PkgManager, Router};
|
2026-06-28 18:42:20 +00:00
|
|
|
|
|
|
|
|
/// Full TollGate provisioning sequence:
|
2026-06-30 17:12:50 +00:00
|
|
|
/// 1. Install tollgate-module-basic-go
|
2026-06-28 18:42:20 +00:00
|
|
|
/// 2. Write TollGate UCI config (pricing, mint URL)
|
|
|
|
|
/// 3. Create the pay-as-you-go WiFi SSID
|
|
|
|
|
/// 4. Restart affected services
|
|
|
|
|
pub async fn provision(router: &Router, config: &TollGateConfig) -> Result<()> {
|
|
|
|
|
info!("[{}] Starting TollGate provisioning", router.host);
|
|
|
|
|
|
2026-06-30 17:12:50 +00:00
|
|
|
let pkg_mgr = router.opkg_check()?;
|
|
|
|
|
match pkg_mgr {
|
|
|
|
|
PkgManager::Opkg => {
|
|
|
|
|
router.opkg_update()?;
|
|
|
|
|
install_tollgate(router)?;
|
|
|
|
|
}
|
|
|
|
|
PkgManager::ApkNative => {
|
|
|
|
|
install::install_tollgate_apk_native(router)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-28 18:42:20 +00:00
|
|
|
config::apply(router, config)?;
|
|
|
|
|
wifi::provision_ssid(router, config)?;
|
fix(openwrt): fix TollGate provisioning pipeline, add reconfigure UI
Several compounding bugs were blocking end-to-end TollGate provisioning
on OpenWrt 25.x (apk-native) routers:
- install_ipk's non-ar fallback assumed a flat tarball, but some .ipks are
a gzip tar of the three classic ipk members one level deep; it was
dumping debian-binary/data.tar.gz/control.tar.gz straight into / instead
of unpacking the real payload.
- Manually-extracted packages never ran their pending /etc/uci-defaults/*
scripts (that only happens through opkg/apk's own postinst bookkeeping),
so nothing ever created /etc/config/tollgate.
- uci_apply() never ensured the target config file existed first — `uci
set` fails outright on a config namespace nothing has created yet, which
is true for a package-defined one like "tollgate" (unlike wireless/
network/dhcp, which ship by default).
- The installed-check and restart_services looked for a binary/init script
named after the opkg package ("tollgate-module-basic-go"/"tollgate"),
but the real on-disk names are tollgate-wrt — so status always reported
"not installed" and service restarts silently no-op'd.
- provision_ssid used `uci add`, creating a new wifi-iface section (and
therefore a new duplicate broadcast SSID) on every provision call instead
of updating one in place.
Also adds a TollGateConfig.enabled field so the enable/disable state is
actually applied to the running service and the SSID's own broadcast
(stop + disable at boot, or start + enable), not just written to UCI.
On the frontend, the OpenWrt Gateway page's TollGate panel was read-only
once installed — add an edit form (price, step size, min steps, mint URL,
enabled toggle) that reuses the same idempotent provision-tollgate call.
2026-07-01 11:59:43 +00:00
|
|
|
restart_services(router, config.enabled)?;
|
2026-06-28 18:42:20 +00:00
|
|
|
|
|
|
|
|
info!("[{}] TollGate provisioning complete", router.host);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
fix(openwrt): fix TollGate provisioning pipeline, add reconfigure UI
Several compounding bugs were blocking end-to-end TollGate provisioning
on OpenWrt 25.x (apk-native) routers:
- install_ipk's non-ar fallback assumed a flat tarball, but some .ipks are
a gzip tar of the three classic ipk members one level deep; it was
dumping debian-binary/data.tar.gz/control.tar.gz straight into / instead
of unpacking the real payload.
- Manually-extracted packages never ran their pending /etc/uci-defaults/*
scripts (that only happens through opkg/apk's own postinst bookkeeping),
so nothing ever created /etc/config/tollgate.
- uci_apply() never ensured the target config file existed first — `uci
set` fails outright on a config namespace nothing has created yet, which
is true for a package-defined one like "tollgate" (unlike wireless/
network/dhcp, which ship by default).
- The installed-check and restart_services looked for a binary/init script
named after the opkg package ("tollgate-module-basic-go"/"tollgate"),
but the real on-disk names are tollgate-wrt — so status always reported
"not installed" and service restarts silently no-op'd.
- provision_ssid used `uci add`, creating a new wifi-iface section (and
therefore a new duplicate broadcast SSID) on every provision call instead
of updating one in place.
Also adds a TollGateConfig.enabled field so the enable/disable state is
actually applied to the running service and the SSID's own broadcast
(stop + disable at boot, or start + enable), not just written to UCI.
On the frontend, the OpenWrt Gateway page's TollGate panel was read-only
once installed — add an edit form (price, step size, min steps, mint URL,
enabled toggle) that reuses the same idempotent provision-tollgate call.
2026-07-01 11:59:43 +00:00
|
|
|
/// Applies `enabled` to the actual running service, not just the UCI value —
|
|
|
|
|
/// the tollgate-wrt init script doesn't consult `tollgate.main.enabled`
|
|
|
|
|
/// itself, so toggling it requires an explicit enable/start or disable/stop.
|
|
|
|
|
///
|
|
|
|
|
/// The service's init script is `/etc/init.d/tollgate-wrt` (its actual
|
|
|
|
|
/// on-disk name — "tollgate" alone does not exist).
|
|
|
|
|
fn restart_services(router: &Router, enabled: bool) -> Result<()> {
|
|
|
|
|
if enabled {
|
|
|
|
|
router.run_ok("/etc/init.d/tollgate-wrt enable")?;
|
|
|
|
|
router.run_ok(
|
|
|
|
|
"/etc/init.d/tollgate-wrt restart || /etc/init.d/tollgate-wrt start"
|
|
|
|
|
)?;
|
|
|
|
|
} else {
|
|
|
|
|
router.run_ok("/etc/init.d/tollgate-wrt stop || true")?;
|
|
|
|
|
router.run_ok("/etc/init.d/tollgate-wrt disable || true")?;
|
|
|
|
|
}
|
2026-06-28 18:42:20 +00:00
|
|
|
router.run_ok("/etc/init.d/network restart")?;
|
fix(openwrt): fix TollGate provisioning pipeline, add reconfigure UI
Several compounding bugs were blocking end-to-end TollGate provisioning
on OpenWrt 25.x (apk-native) routers:
- install_ipk's non-ar fallback assumed a flat tarball, but some .ipks are
a gzip tar of the three classic ipk members one level deep; it was
dumping debian-binary/data.tar.gz/control.tar.gz straight into / instead
of unpacking the real payload.
- Manually-extracted packages never ran their pending /etc/uci-defaults/*
scripts (that only happens through opkg/apk's own postinst bookkeeping),
so nothing ever created /etc/config/tollgate.
- uci_apply() never ensured the target config file existed first — `uci
set` fails outright on a config namespace nothing has created yet, which
is true for a package-defined one like "tollgate" (unlike wireless/
network/dhcp, which ship by default).
- The installed-check and restart_services looked for a binary/init script
named after the opkg package ("tollgate-module-basic-go"/"tollgate"),
but the real on-disk names are tollgate-wrt — so status always reported
"not installed" and service restarts silently no-op'd.
- provision_ssid used `uci add`, creating a new wifi-iface section (and
therefore a new duplicate broadcast SSID) on every provision call instead
of updating one in place.
Also adds a TollGateConfig.enabled field so the enable/disable state is
actually applied to the running service and the SSID's own broadcast
(stop + disable at boot, or start + enable), not just written to UCI.
On the frontend, the OpenWrt Gateway page's TollGate panel was read-only
once installed — add an edit form (price, step size, min steps, mint URL,
enabled toggle) that reuses the same idempotent provision-tollgate call.
2026-07-01 11:59:43 +00:00
|
|
|
// Reload wireless so wireless.tollgate.disabled takes effect on the radio —
|
|
|
|
|
// `network restart` alone doesn't reliably reconfigure wifi interfaces.
|
|
|
|
|
router.run_ok("wifi down 2>&1; wifi up 2>&1")?;
|
2026-06-28 18:42:20 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|