feat: Add version info to dashboard data endpoint

The get_dashboard_data endpoint was missing version information for modules.
Updated to include version extraction from package manager (apk/opkg).

**Changes:**
- Add package and version config variables in get_dashboard_data
- Extract real version from apk (OpenWrt 25.12+) or opkg (24.10)
- Include version field in JSON output for each module

**Dashboard Data Now Includes:**
- Module version for installed packages (e.g., "0.3.1")
- Default version "0.0.9" for non-installed modules
- Consistent version format across all endpoints

**Benefits:**
- Dashboard can display installed package versions
- Users can see which version of each module is running
- Consistent with modules endpoint behavior

Tested on OpenWrt 25.12.0-rc1 with apk package manager.

🤖 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:26:42 +01:00
parent c5152f5099
commit acdc7bc8d2

View File

@ -885,12 +885,14 @@ get_dashboard_data() {
local module_sections=$(uci -q show secubox | grep "=module$" | cut -d. -f2 | cut -d= -f1)
for module in $module_sections; do
local name desc category icon color
local name desc category icon color package version
config_get name "$module" name "$module"
config_get desc "$module" description ""
config_get category "$module" category "other"
config_get icon "$module" icon "box"
config_get color "$module" color "#64748b"
config_get package "$module" package ""
config_get version "$module" version "0.0.9"
local is_installed=$(check_module_installed "$module")
local is_enabled="0"
@ -905,6 +907,19 @@ get_dashboard_data() {
status=$(get_module_status "$is_enabled" "$is_running")
installed=$((installed + 1))
[ "$is_running" = "1" ] && running=$((running + 1))
# Get real version from package manager if installed
if [ -n "$package" ]; then
if [ -x "/usr/bin/apk" ]; then
# OpenWrt 25.12+ uses apk
local real_version=$(apk list --installed "$package" 2>/dev/null | head -1 | awk '{print $1}' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
[ -n "$real_version" ] && version="$real_version"
elif [ -x "/bin/opkg" ] || [ -x "/usr/bin/opkg" ]; then
# OpenWrt 24.10 and earlier uses opkg
local real_version=$(opkg list-installed "$package" 2>/dev/null | awk '{print $3}' | sed 's/-.*$//')
[ -n "$real_version" ] && version="$real_version"
fi
fi
fi
json_add_object ""
@ -914,6 +929,7 @@ get_dashboard_data() {
json_add_string "category" "$category"
json_add_string "icon" "$icon"
json_add_string "color" "$color"
json_add_string "version" "$version"
json_add_boolean "installed" "$is_installed"
json_add_boolean "enabled" "$is_enabled"
json_add_boolean "running" "$is_running"