refactor: Simplify enable/disable to only manage UCI config

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 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2025-12-28 02:35:57 +01:00
parent 72a2b29e32
commit e7975ecb7a

View File

@ -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