#!/bin/sh # # RPCD backend for Glances LuCI interface # Copyright (C) 2025-2026 CyberMind.fr (SecuBox) # . /lib/functions.sh LXC_NAME="glances" # Get service status get_status() { local running=0 local pid="" local lxc_state="" local web_url="" # Check LXC container status if command -v lxc-info >/dev/null 2>&1; then lxc_state=$(lxc-info -n "$LXC_NAME" -s 2>/dev/null | grep -oE 'RUNNING|STOPPED' || echo "UNKNOWN") if [ "$lxc_state" = "RUNNING" ]; then running=1 pid=$(lxc-info -n "$LXC_NAME" -p 2>/dev/null | grep -oE '[0-9]+' || echo "0") fi fi local enabled=$(uci -q get glances.main.enabled || echo "0") local web_port=$(uci -q get glances.main.web_port || echo "61208") local router_ip=$(uci -q get network.lan.ipaddr || echo "192.168.1.1") [ "$running" = "1" ] && web_url="http://${router_ip}:${web_port}" cat </dev/null 2>&1 sleep 2 get_status } service_stop() { /etc/init.d/glances stop >/dev/null 2>&1 sleep 1 get_status } service_restart() { /etc/init.d/glances restart >/dev/null 2>&1 sleep 2 get_status } # Set configuration set_config() { local key="$1" local value="$2" local section="main" case "$key" in monitor_*) section="monitoring" ;; cpu_*|mem_*|disk_*) section="alerts" ;; esac # Handle boolean conversion case "$value" in true) value="1" ;; false) value="0" ;; esac uci set "glances.$section.$key=$value" uci commit glances echo '{"success":true}' } # RPCD list method case "$1" in list) cat </dev/null) value=$(echo "$input" | jsonfilter -e '@.value' 2>/dev/null) set_config "$key" "$value" ;; *) echo '{"error":"Unknown method"}' ;; esac ;; *) echo '{"error":"Unknown command"}' ;; esac