4.2 KiB
4.2 KiB
Architecture
High-Level View
The SecuBox suite is a collection of LuCI packages that all share the same pattern:
- LuCI Views (
htdocs/luci-static/resources/view/<module>/*.js) build the UI usingview.extend,ui, and DOM helpers. Views import per-module API helpers and shared CSS (system-hub/common.css, plus module-specific.css). - API Helpers (
htdocs/luci-static/resources/<module>/api.js) declare ubus calls withrpc.declareand export abaseclass.extendinstance that exposes typed methods (getStatus,listServices, etc.). - RPCD Backend (
root/usr/libexec/rpcd/luci.<module>) receiveslist/callrequests from ubus, executes shell or UCI logic, and emits JSON viajson_*helpers. - Navigation & ACL (
root/usr/share/luci/menu.d/*.json,root/usr/share/rpcd/acl.d/*.json) describe where the module appears in LuCI and who may access each ubus method. - Deployment Tooling (
deploy-module-template.sh,secubox-tools/*.sh) automates copying files to routers, backing up, fixing permissions, clearing caches, and restartingrpcd/uhttpd.
System Hub and SecuBox provide “umbrella” tabs (admin/secubox/...) but each module is otherwise isolated and should not reach into another module's files unless explicitly documented (e.g., System Hub reading SecuBox theme preferences via luci.secubox get_theme).
Data Flow
- User opens
admin/secubox/.../<tab>in LuCI. - Menu JSON loads
luci-static/resources/view/<module>/<view>.js. - The view's
load()issuesPromise.all([...API calls...])toapi.jshelpers. api.jsusesrpc.declare({object: 'luci.<module>', method: ...})to talk to ubus.- ubus dispatches to
/usr/libexec/rpcd/luci.<module>, which handleslist/callrequests, touches UCI/system services, and replies JSON. - View
render()updates DOM components, sets uppoll.addfor periodic refresh, and attaches event handlers that call more RPC actions. - Deploy scripts copy updated JS/CSS/RPC/menu/ACL to the router, fix permissions, and restart
rpcd/uhttpdto expose the changes.
Boundaries & Dependency Rules
- Modules must keep JS, CSS, RPC, menu, and ACL files self-contained under their own directory; shared assets go in
system-hub/common.cssortemplates/. - Do not import code from another module's
htdocs/.../viewfolder. Shared logic should be duplicated intentionally or moved into a common helper undersystem-hub/or a new shared location documented inDEVELOPMENT-GUIDELINES.md. - Any ubus interaction between modules must be explicitly documented (e.g., System Hub calling
luci.secubox get_theme). Otherwise, treat everyluci.<module>namespace as private. - Keep RPCD scripts shell-only unless the repo adds other interpreters; they must rely on standard OpenWrt utilities (
ubus,uci,/lib/functions.sh,/usr/share/libubox/jshn.sh).
Adding a New Module – Checklist
- Scaffold: Copy
templates/luci-app-templateor an existing module directory and rename files (PKG_NAME,LUCI_TITLE, etc.). - Implement RPCD: Create
/root/usr/libexec/rpcd/luci.<module>withlist/call, JSON helpers, and method coverage for every UI action. - Add API Helper: In
htdocs/luci-static/resources/<module>/api.jsextendbaseclassand declare each ubus call. - Build Views: Under
htdocs/luci-static/resources/view/<module>/addoverview.jsplus additional tabs as needed. Include CSS via<link>tosystem-hub/common.cssand module-specific files. Follow design system rules. - Wire Menu/ACL: Create
root/usr/share/luci/menu.d/luci-app-<module>.jsonwith the correctadmin/secubox/...path andfirstchildentry; createroot/usr/share/rpcd/acl.d/luci-app-<module>.jsonenumerating read/write ubus methods. - Docs: Write
luci-app-<module>/README.mddescribing purpose, features, install commands, and troubleshooting steps. - Permissions: Update
MakefilewithPKG_FILE_MODES:=/usr/libexec/rpcd/luci.<module>:755(and any other executables). Confirm CSS/JS remain 644. - Validation & Build: Run
./secubox-tools/fix-permissions.sh --local,./secubox-tools/validate-module-generation.sh luci-app-<module>, and./secubox-tools/local-build.sh build luci-app-<module>before submitting.