$ show vernesong/OpenClash
OpenClash is an OpenWrt/LuCI application that turns a router's admin interface into a full Clash/Mihomo proxy management system. The production code is mostly Lua CBI/controller modules, view templates with embedded JavaScript, and shell/Ruby orchestration scripts. It manages subscription downloads, YAML config generation and overwrite, core binary updates, GeoIP/GeoSite/China-route database updates, DNS/firewall integration, streaming-unlock probe and selection, and optional OIX managed-service integration. It also bundles the MetaCubeXD and zashboard single-page dashboards for live proxy monitoring and connection inspection. Architecturally, the project is an OpenWrt package: UCI configuration, an init.d service, and watchdog/procd lifecycle management. The LuCI controller exposes around 80 JSON/AJAX actions and uses low-level nixio fork/poll/pipe helpers for streaming subprocess output. The backend repeatedly combines shell scripts with Ruby-based YAML parsing and mutation to handle Clash configuration. External dependencies are significant: GitHub releases/CDNs for core and GEO data, subconverter services, the OIX API, and several IP-info services. Hardcoded URLs, vendored minified dashboard bundles, and multi-language shell/Ruby/Lua/C tooling are the main technical-drift risks. This is not a data-research repository; the data handled is operational proxy/node/routing state rather than analyzable datasets. No automated test suite is apparent in the tree; quality comes from defensive shell patterns (flock locks, ETag caching, retry loops) and feature depth rather than automated verification. The most reusable pieces are YAML.rb's merge/encryption layer, the server_url share-link parser widget, and the controller's streaming subprocess helpers.
The LLM identified 3 files worth highlighting for reuse:
A self-contained Ruby extension that centralizes YAML loading, dumping, and mutation with age-encryption support, base64 subscription decoding, short-id workarounds, and rich merge/overwrite operations. It is called from shell scripts through ruby.sh, making YAML manipulation from shell safer and more idempotent. The core merge logic could be extracted and reused by any Ruby or shell-based configuration system that needs safe YAML overwrite semantics.
A reusable LuCI CBI valueheader/valuefooter widget that parses and exports proxy share links for more than a dozen protocols including SS, SSR, VMess, VLESS, Trojan, Hysteria, Hysteria2, TUIC, SOCKS5, and HTTP/HTTPS. It implements base64url-safe helpers, generic URL/query parsing with fallback handling, setFormValue/getFormValue retry logic, and merging of unknown URL parameters into YAML. This is an isolated UI pattern that can be embedded in any LuCI form needing protocol-aware server URL import/export.
The ltn12_popen() helper in the main controller wraps nixio.pipe plus fork to create a streaming subprocess reader with kill capability, non-blocking reads via nixio.poll, and padded NDJSON line streaming for nginx/LuCI compatibility. It demonstrates a robust pattern for streaming live command output from an embedded web UI. The helper itself is small and well-encapsulated enough to be extracted as a Lua utility for other LuCI applications that need concurrent subprocess output.