2025-12-11 18:32:55 -07:00
|
|
|
/**
|
|
|
|
|
* Controller API client for WROLPi.
|
|
|
|
|
*
|
|
|
|
|
* These functions call the Controller service endpoints.
|
|
|
|
|
* Controller handles system-level operations that need to work
|
|
|
|
|
* even when the main API is down.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Controller endpoints are served under /controller/api
|
|
|
|
|
const CONTROLLER_BASE = '/controller/api';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch with error handling for Controller endpoints.
|
|
|
|
|
*/
|
|
|
|
|
async function controllerFetch(endpoint, options = {}) {
|
|
|
|
|
const url = `${CONTROLLER_BASE}${endpoint}`;
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
...options,
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
...options.headers,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const error = await response.json().catch(() => ({detail: response.statusText}));
|
|
|
|
|
throw new Error(error.detail || 'Controller request failed');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Status Endpoints ---
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all system stats from the Controller.
|
|
|
|
|
* Returns CPU, memory, load, drives, network, power, iostat, processes,
|
|
|
|
|
* disk_bandwidth along with system info (dockerized, is_rpi, hotspot, throttle).
|
|
|
|
|
*/
|
|
|
|
|
export async function getControllerStats() {
|
|
|
|
|
return controllerFetch('/stats');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getCpuStatus() {
|
|
|
|
|
return controllerFetch('/status/cpu');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getMemoryStatus() {
|
|
|
|
|
return controllerFetch('/status/memory');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getLoadStatus() {
|
|
|
|
|
return controllerFetch('/status/load');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getDrivesStatus() {
|
|
|
|
|
return controllerFetch('/status/drives');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getPrimaryDriveStatus() {
|
|
|
|
|
return controllerFetch('/status/primary-drive');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getNetworkStatus() {
|
|
|
|
|
return controllerFetch('/status/network');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getPowerStatus() {
|
|
|
|
|
return controllerFetch('/status/power');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Admin Endpoints ---
|
|
|
|
|
|
|
|
|
|
export async function getHotspotStatus() {
|
|
|
|
|
return controllerFetch('/hotspot/status');
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-04 08:22:24 -06:00
|
|
|
export async function getHotspotDevices() {
|
|
|
|
|
return controllerFetch('/hotspot/devices');
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 19:52:39 -06:00
|
|
|
export async function getHotspotProtocols(device) {
|
|
|
|
|
const query = device ? `?device=${encodeURIComponent(device)}` : '';
|
|
|
|
|
return controllerFetch(`/hotspot/protocols${query}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-04 08:22:24 -06:00
|
|
|
export async function getHotspotSettings() {
|
|
|
|
|
return controllerFetch('/hotspot/settings');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateHotspotSettings(settings) {
|
|
|
|
|
return controllerFetch('/hotspot/settings', {method: 'POST', body: JSON.stringify(settings)});
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-29 14:57:28 -06:00
|
|
|
export async function startHotspot() {
|
|
|
|
|
return controllerFetch('/hotspot/start', {method: 'POST'});
|
2025-12-11 18:32:55 -07:00
|
|
|
}
|
|
|
|
|
|
2026-07-29 14:57:28 -06:00
|
|
|
export async function stopHotspot() {
|
|
|
|
|
return controllerFetch('/hotspot/stop', {method: 'POST'});
|
2025-12-11 18:32:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getThrottleStatus() {
|
|
|
|
|
return controllerFetch('/throttle/status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function enableThrottle() {
|
|
|
|
|
return controllerFetch('/throttle/enable', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function disableThrottle() {
|
|
|
|
|
return controllerFetch('/throttle/disable', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 10:09:58 -06:00
|
|
|
export async function getBluetoothStatus() {
|
|
|
|
|
return controllerFetch('/bluetooth/status');
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-29 14:57:28 -06:00
|
|
|
export async function unblockBluetooth() {
|
|
|
|
|
return controllerFetch('/bluetooth/unblock', {method: 'POST'});
|
2026-03-28 10:09:58 -06:00
|
|
|
}
|
|
|
|
|
|
2026-07-29 14:57:28 -06:00
|
|
|
export async function blockBluetooth() {
|
|
|
|
|
return controllerFetch('/bluetooth/block', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getDesktopStatus() {
|
|
|
|
|
return controllerFetch('/desktop/status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startDesktop() {
|
|
|
|
|
return controllerFetch('/desktop/start', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function stopDesktop() {
|
|
|
|
|
return controllerFetch('/desktop/stop', {method: 'POST'});
|
2026-03-28 10:09:58 -06:00
|
|
|
}
|
|
|
|
|
|
controller: VNC toggle, gated on the Desktop running
Add a VNC toggle to the Controller (both UIs) that starts/stops whichever VNC
backend is installed: wayvnc for Wayland (Raspberry Pi OS), RealVNC for X11.
Runtime-only, like the Desktop toggle: the unit is never enabled, so VNC does
not return after a reboot. Users who want it permanently on can enable it with
raspi-config.
VNC serves the desktop session, so starting it without a desktop gives clients
a blank screen. The gate lives in the backend, not just the UI, so curl callers
get it too (409, distinct from a systemctl failure). Stopping is never gated so
a running VNC server can't be stranded on with no way to turn it off.
Backend selection deliberately avoids raspi-config's live-compositor probe
(pgrep labwc), which reports X11 — and would pick the wrong backend — whenever
the desktop is stopped. wayvnc also requires its config to exist; that is
checked directly rather than via the unit's ConditionResult, which reports 'no'
for any unit that has never been started.
Extracts _unit_properties()/_systemctl_unit() so Desktop and VNC share one
systemd probe and start/stop path.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 16:53:45 -06:00
|
|
|
export async function getVncStatus() {
|
|
|
|
|
return controllerFetch('/vnc/status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startVnc() {
|
|
|
|
|
return controllerFetch('/vnc/start', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function stopVnc() {
|
|
|
|
|
return controllerFetch('/vnc/stop', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 16:28:47 -06:00
|
|
|
// --- Samba Endpoints ---
|
|
|
|
|
|
|
|
|
|
export async function getSambaStatus() {
|
|
|
|
|
return controllerFetch('/samba/status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addSambaShare(name, path, readOnly = true, comment = '') {
|
|
|
|
|
return controllerFetch('/samba/shares', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({name, path, read_only: readOnly, comment}),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function removeSambaShare(shareName) {
|
|
|
|
|
return controllerFetch(`/samba/shares/${encodeURIComponent(shareName)}`, {method: 'DELETE'});
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:32:55 -07:00
|
|
|
export async function shutdownSystem() {
|
|
|
|
|
return controllerFetch('/shutdown', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function rebootSystem() {
|
|
|
|
|
return controllerFetch('/reboot', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function restartServices() {
|
|
|
|
|
return controllerFetch('/restart', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Service Endpoints ---
|
|
|
|
|
|
|
|
|
|
export async function getServices() {
|
|
|
|
|
return controllerFetch('/services');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getServiceStatus(serviceName) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startService(serviceName) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}/start`, {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function stopService(serviceName) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}/stop`, {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function restartService(serviceName) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}/restart`, {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function enableService(serviceName) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}/enable`, {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function disableService(serviceName) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}/disable`, {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getServiceLogs(serviceName, lines = 100) {
|
|
|
|
|
return controllerFetch(`/services/${serviceName}/logs?lines=${lines}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Disk Endpoints ---
|
|
|
|
|
|
|
|
|
|
export async function getDisks() {
|
|
|
|
|
return controllerFetch('/disks');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getMounts() {
|
|
|
|
|
return controllerFetch('/disks/mounts');
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-14 16:38:02 -06:00
|
|
|
export async function mountDisk(device, mountPoint, fstype = null, options = 'defaults', persist = false, forceShadowed = false) {
|
2025-12-11 18:32:55 -07:00
|
|
|
return controllerFetch('/disks/mount', {
|
|
|
|
|
method: 'POST',
|
2026-05-14 16:38:02 -06:00
|
|
|
body: JSON.stringify({
|
|
|
|
|
device,
|
|
|
|
|
mount_point: mountPoint,
|
|
|
|
|
fstype,
|
|
|
|
|
options,
|
|
|
|
|
persist,
|
|
|
|
|
force_shadowed: forceShadowed,
|
|
|
|
|
}),
|
2025-12-11 18:32:55 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function unmountDisk(mountPoint, lazy = false) {
|
|
|
|
|
return controllerFetch('/disks/unmount', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({mount_point: mountPoint, lazy}),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function detectWrolpiDrives() {
|
|
|
|
|
return controllerFetch('/disks/detect-wrolpi');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSmartStatus() {
|
|
|
|
|
return controllerFetch('/disks/smart');
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-16 15:06:41 -07:00
|
|
|
// --- Fstab Endpoints ---
|
|
|
|
|
|
|
|
|
|
export async function getFstabEntries() {
|
|
|
|
|
return controllerFetch('/disks/fstab');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addFstabEntry(device, mountPoint, fstype, options = 'defaults,nofail,x-systemd.device-timeout=10s') {
|
|
|
|
|
return controllerFetch('/disks/fstab', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({device, mount_point: mountPoint, fstype, options}),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function removeFstabEntry(mountPoint) {
|
|
|
|
|
const encodedPath = encodeURIComponent(mountPoint.slice(1));
|
|
|
|
|
return controllerFetch(`/disks/fstab/${encodedPath}`, {method: 'DELETE'});
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:32:55 -07:00
|
|
|
// --- Health Check ---
|
|
|
|
|
|
|
|
|
|
export async function healthCheck() {
|
|
|
|
|
return controllerFetch('/health');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Controller Info ---
|
|
|
|
|
|
|
|
|
|
export async function getControllerInfo() {
|
|
|
|
|
return controllerFetch('/info');
|
|
|
|
|
}
|
A secondary syncs by rsync: the Controller runs it on its schedule, and both pages follow it (#995)
* A secondary syncs by rsync: the Controller runs it on its schedule, and both pages follow it
The third part of replacing the sync.
- The Controller syncs within the daily window (every 15 minutes after the last sync finished, in WROLPi's
timezone), as the API did. The API's loop no longer runs the old engine, and its /api/sync/run and
/api/sync/cancel ask the Controller.
- The Sync page and the overlay that covers the app read the sync's status from the Controller, which is the only
one that can answer while the API is stopped. The overlay is also shown when the settings cannot be read, as
happens while the API is stopped. Sync Now and Stop go to the Controller.
- The Controller's fallback page, where Caddy sends the browser while the API is down, shows the sync's progress
and a Stop button.
- New on the Sync page: how long files the primary deletes are kept (30 days by default, or never), and a note that
an excluded folder's files are still listed on a secondary.
The old engine's code is removed in the next part.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove SyncRunRequest, unused since a sync is asked of the Controller
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* In Docker, a sync's progress moves while a large file is copied
Docker's logs hold a line until it ends, and rsync's progress for one large file is a single line rewritten with
carriage returns, so the page showed 0% until the file was done (hours, for a large map). The rsync helper's
output is now read by attaching to it, before it is started so that nothing is missed.
Found by a sync between two Docker WROLPis.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync is recovered before the schedule can start another, and an empty days value is refused
Review found:
- The schedule and the recovery of an interrupted sync started side by side when the Controller started. The state
an interrupted sync leaves is due, so inside the window a new sync could start while the recovery restarted the
API and wrote over the new sync's status. Every tick of the schedule now recovers first, and only a status of
"running" with no sync holding the lock counts as interrupted. A sync records its outcome before it frees the
lock, so a tick between the two cannot mistake it for an interrupted one.
- The Controller may start before the drive is mounted. The empty record it read then was kept and saved over the
real one, losing the last successful sync. The state file is now read again until it can be.
- A cleared number of days was saved as 0, which empties the trash at the next sync. It is now refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 15:06:25 -07:00
|
|
|
|
|
|
|
|
// --- Sync (a secondary WROLPi copying its primary; the Controller runs it, because the API is stopped) ---
|
|
|
|
|
|
|
|
|
|
export async function getSyncStatus() {
|
|
|
|
|
return controllerFetch('/sync/status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Start a sync now. Throws with the reason a sync cannot start. */
|
|
|
|
|
export async function runSync() {
|
|
|
|
|
return controllerFetch('/sync/run', {method: 'POST'});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function cancelSync() {
|
|
|
|
|
return controllerFetch('/sync/cancel', {method: 'POST'});
|
|
|
|
|
}
|