From e7975ecb7a05d2f4f9d24e58eb4393512f0b3718 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Sun, 28 Dec 2025 02:35:57 +0100 Subject: [PATCH] refactor: Simplify enable/disable to only manage UCI config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The enable_module() and disable_module() functions were incorrectly also starting/stopping services. They should only manage UCI configuration flags. Service lifecycle (start/stop/restart) should be handled by dedicated functions. **Changes:** **enable_module():** - ✅ Sets UCI `secubox.{module}.enabled = '1'` - ✅ Commits UCI changes - ❌ Removed: Service enable/start commands - ✅ Returns success with note to use start_module() **disable_module():** - ✅ Sets UCI `secubox.{module}.enabled = '0'` - ✅ Commits UCI changes - ❌ Removed: Service stop/disable commands - ✅ Returns success with note to use stop_module() **Behavior:** Before: ```bash ubus call luci.secubox enable_module '{"module":"example"}' # Would: Set enabled=1 + Enable service + Start service ``` After: ```bash ubus call luci.secubox enable_module '{"module":"example"}' # Only: Set enabled=1 in UCI config ubus call luci.secubox start_module '{"module":"example"}' # Separately: Start the actual service ``` **Benefits:** - ✅ Clear separation of concerns - ✅ Enable/disable = logical flag in UCI - ✅ Start/stop/restart = actual service control - ✅ More predictable behavior - ✅ Aligns with user expectations **Testing:** ```bash # Enable in config ubus call luci.secubox enable_module '{"module":"network_modes"}' → UCI: enabled='1' ✓ # Disable in config ubus call luci.secubox disable_module '{"module":"network_modes"}' → UCI: enabled='0' ✓ # Services not affected, use start/stop separately ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../root/usr/libexec/rpcd/luci.secubox | 56 ++++++------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/luci-app-secubox/root/usr/libexec/rpcd/luci.secubox b/luci-app-secubox/root/usr/libexec/rpcd/luci.secubox index 10575430..7c1fcef1 100755 --- a/luci-app-secubox/root/usr/libexec/rpcd/luci.secubox +++ b/luci-app-secubox/root/usr/libexec/rpcd/luci.secubox @@ -530,59 +530,35 @@ restart_module() { # Enable a module (NEW v0.3.1) enable_module() { local module="$1" - local config - config_load secubox - config_get config "$module" config "" - - # Set enabled flag in UCI + # Set enabled flag in UCI (v0.3.1) + # This only activates the module in configuration + # Use start_module() to actually start the service uci set secubox.${module}.enabled='1' uci commit secubox - # Enable and start service if init script exists - if [ -x "/etc/init.d/${config}" ]; then - /etc/init.d/${config} enable - /etc/init.d/${config} start - - json_init - json_add_boolean "success" 1 - json_add_string "message" "Module activé" - json_dump - else - json_init - json_add_boolean "success" 0 - json_add_string "message" "Init script not found" - json_dump - fi + json_init + json_add_boolean "success" 1 + json_add_string "message" "Module activé dans la configuration" + json_add_string "note" "Utilisez 'Démarrer' pour lancer le service" + json_dump } # Disable a module (NEW v0.3.1) disable_module() { local module="$1" - local config - config_load secubox - config_get config "$module" config "" - - # Set disabled flag in UCI + # Set disabled flag in UCI (v0.3.1) + # This only deactivates the module in configuration + # Use stop_module() to actually stop the service uci set secubox.${module}.enabled='0' uci commit secubox - # Disable and stop service if init script exists - if [ -x "/etc/init.d/${config}" ]; then - /etc/init.d/${config} stop - /etc/init.d/${config} disable - - json_init - json_add_boolean "success" 1 - json_add_string "message" "Module désactivé" - json_dump - else - json_init - json_add_boolean "success" 0 - json_add_string "message" "Init script not found" - json_dump - fi + json_init + json_add_boolean "success" 1 + json_add_string "message" "Module désactivé dans la configuration" + json_add_string "note" "Utilisez 'Arrêter' pour stopper le service" + json_dump } # Get health report