Hot fixes for version 2.2.8

This commit is contained in:
Russel Yasol
2025-08-25 05:55:35 +08:00
parent 4a327bfcd8
commit 27f17eb874
113 changed files with 471 additions and 372 deletions

View File

@@ -11,7 +11,7 @@ echo ""
# Lock file path
LOCK_FILE="/tmp/hw_details.lock"
LOCK_TIMEOUT=10 # Maximum wait time in seconds
LOCK_TIMEOUT=10 # Maximum wait time in seconds
# Function to acquire lock
acquire_lock() {
@@ -63,26 +63,56 @@ trap cleanup EXIT INT TERM
# Function to get ethernet information
get_ethernet_info() {
interface=${1:-eth0}
# Check if ethtool is installed
if ! which ethtool >/dev/null 2>&1; then
error_response "ethtool not found"
# First check if interface exists at all
if ! ip link show "$interface" >/dev/null 2>&1; then
# Interface doesn't exist - return not connected state
echo "{\"link_speed\":\"Not Connected\",\"link_status\":\"no\",\"auto_negotiation\":\"off\",\"connected\":false}"
return 0
fi
# Check if interface exists
if ! ip link show "$interface" >/dev/null 2>&1; then
error_response "Interface $interface not found"
# Check if interface is up (administratively)
interface_state=$(ip link show "$interface" 2>/dev/null | grep -o "state [A-Z]*" | cut -d' ' -f2)
if [ "$interface_state" = "DOWN" ]; then
# Interface exists but is down - return not connected state
echo "{\"link_speed\":\"Not Connected\",\"link_status\":\"no\",\"auto_negotiation\":\"off\",\"connected\":false}"
return 0
fi
# Check if ethtool is available
if ! which ethtool >/dev/null 2>&1; then
# Fallback: basic interface info without ethtool
echo "{\"link_speed\":\"Unknown\",\"link_status\":\"unknown\",\"auto_negotiation\":\"unknown\",\"connected\":true}"
return 0
fi
# Run ethtool and capture output
ethtool_output=$(ethtool "$interface" 2>/dev/null) || error_response "Failed to get ethernet information"
ethtool_output=$(ethtool "$interface" 2>/dev/null)
if [ $? -ne 0 ]; then
# ethtool failed - likely no physical connection
echo "{\"link_speed\":\"Not Connected\",\"link_status\":\"no\",\"auto_negotiation\":\"off\",\"connected\":false}"
return 0
fi
# Extract values using sed instead of grep -P
speed=$(echo "$ethtool_output" | sed -n 's/.*Speed: \([^[:space:]]*\).*/\1/p' || echo "Unknown")
link_status=$(echo "$ethtool_output" | sed -n 's/.*Link detected: \(yes\|no\).*/\1/p' || echo "unknown")
auto_negotiation=$(echo "$ethtool_output" | sed -n 's/.*Auto-negotiation: \(on\|off\).*/\1/p' || echo "unknown")
speed=$(echo "$ethtool_output" | sed -n 's/.*Speed: \([^[:space:]]*\).*/\1/p')
link_status=$(echo "$ethtool_output" | sed -n 's/.*Link detected: \(yes\|no\).*/\1/p')
auto_negotiation=$(echo "$ethtool_output" | sed -n 's/.*Auto-negotiation: \(on\|off\).*/\1/p')
# Output JSON
echo "{\"link_speed\":\"$speed\",\"link_status\":\"$link_status\",\"auto_negotiation\":\"$auto_negotiation\"}"
# Set defaults if extraction failed
[ -z "$speed" ] && speed="Unknown"
[ -z "$link_status" ] && link_status="unknown"
[ -z "$auto_negotiation" ] && auto_negotiation="unknown"
# Check if link is actually detected
if [ "$link_status" = "no" ]; then
# Physical link not detected - return not connected state
echo "{\"link_speed\":\"Not Connected\",\"link_status\":\"no\",\"auto_negotiation\":\"$auto_negotiation\",\"connected\":false}"
return 0
fi
# Link is detected and active - return connected state
echo "{\"link_speed\":\"$speed\",\"link_status\":\"$link_status\",\"auto_negotiation\":\"$auto_negotiation\",\"connected\":true}"
}
# Main execution

View File

@@ -1,66 +1,59 @@
#!/bin/sh
# Memory Data Fetch Script - Simple OpenWrt/BusyBox compliant version
# Memory Data Fetch Script - Simplified and robust
# Handle OPTIONS request
# Always set CORS headers first (no conditional OPTIONS handling)
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: GET, OPTIONS"
echo "Access-Control-Allow-Headers: Content-Type"
echo ""
# Handle OPTIONS request and exit early
if [ "${REQUEST_METHOD:-GET}" = "OPTIONS" ]; then
echo "Content-Type: text/plain"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: GET, OPTIONS"
echo "Access-Control-Allow-Headers: Content-Type"
echo "Access-Control-Max-Age: 86400"
echo ""
echo "{\"status\":\"success\"}"
exit 0
fi
# Set CORS headers
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo ""
# Only handle GET requests
if [ "${REQUEST_METHOD:-GET}" != "GET" ]; then
echo "{\"status\":\"error\",\"message\":\"Only GET method supported\"}"
exit 1
echo "{\"status\":\"error\",\"message\":\"Method not allowed\"}"
exit 0
fi
# Configuration and data paths
# Paths
MEMORY_JSON="/tmp/quecmanager/memory.json"
CONFIG_FILE="/etc/quecmanager/settings/memory_settings.conf"
# Check if memory data file exists and read it
if [ -f "$MEMORY_JSON" ]; then
# Check if memory data file exists
if [ -f "$MEMORY_JSON" ] && [ -r "$MEMORY_JSON" ]; then
# Read the file content
memory_data=$(cat "$MEMORY_JSON" 2>/dev/null)
# Simple validation - check if it has the basic structure
if echo "$memory_data" | grep -q '"total"' && echo "$memory_data" | grep -q '"used"'; then
# Extract values using awk (more reliable in BusyBox)
total=$(echo "$memory_data" | awk -F'"total"[[:space:]]*:[[:space:]]*' '{print $2}' | awk -F'[,}]' '{print $1}')
used=$(echo "$memory_data" | awk -F'"used"[[:space:]]*:[[:space:]]*' '{print $2}' | awk -F'[,}]' '{print $1}')
available=$(echo "$memory_data" | awk -F'"available"[[:space:]]*:[[:space:]]*' '{print $2}' | awk -F'[,}]' '{print $1}')
# Basic validation
if [ -n "$total" ] && [ "$total" -gt 0 ] 2>/dev/null; then
echo "{\"status\":\"success\",\"data\":{\"total\":$total,\"used\":$used,\"available\":$available}}"
# Check if we got content and it looks like JSON
if [ -n "$memory_data" ] && echo "$memory_data" | grep -q '"total"'; then
# File exists and has content, return it as-is if it's valid JSON
if echo "$memory_data" | grep -q '"used"' && echo "$memory_data" | grep -q '"available"'; then
echo "{\"status\":\"success\",\"data\":$memory_data}"
else
echo "{\"status\":\"error\",\"message\":\"Invalid memory data\"}"
echo "{\"status\":\"error\",\"message\":\"Invalid memory data format\"}"
fi
else
echo "{\"status\":\"error\",\"message\":\"Memory data file corrupted\"}"
echo "{\"status\":\"error\",\"message\":\"Memory data file is empty or corrupted\"}"
fi
else
# No memory file - check if memory monitoring is enabled
if [ -f "$CONFIG_FILE" ]; then
enabled=$(awk -F'=' '/^MEMORY_ENABLED=/ {print $2}' "$CONFIG_FILE" 2>/dev/null | tr -d '"')
case "$enabled" in
true|1|on|yes|enabled)
echo "{\"status\":\"error\",\"message\":\"Memory daemon starting up, please wait...\"}"
;;
*)
echo "{\"status\":\"error\",\"message\":\"Memory monitoring disabled\"}"
;;
esac
# No memory file exists - check configuration
if [ -f "$CONFIG_FILE" ] && [ -r "$CONFIG_FILE" ]; then
# Check if memory monitoring is enabled
if grep -q "^MEMORY_ENABLED=true" "$CONFIG_FILE" 2>/dev/null; then
echo "{\"status\":\"error\",\"message\":\"Memory daemon starting up\"}"
else
echo "{\"status\":\"error\",\"message\":\"Memory monitoring disabled\"}"
fi
else
echo "{\"status\":\"error\",\"message\":\"Memory monitoring not configured\"}"
fi
fi
# Always exit cleanly
exit 0

View File

@@ -1,86 +1,55 @@
#!/bin/sh
# Fetch Ping Result (relocated under /home/ping)
# OpenWrt/BusyBox compatible version
# Ping Data Fetch Script - Simplified and OpenWrt compatible
# Handle OPTIONS first
if [ "${REQUEST_METHOD:-GET}" = "OPTIONS" ]; then
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: GET, OPTIONS"
echo "Access-Control-Allow-Headers: Content-Type"
echo ""
exit 0
fi
# Set headers for other requests
# Always set CORS headers first
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: GET, OPTIONS"
echo "Access-Control-Allow-Headers: Content-Type"
echo ""
# Configuration
OUT_JSON="/tmp/quecmanager/ping_latency.json"
# Handle OPTIONS request and exit early
if [ "${REQUEST_METHOD:-GET}" = "OPTIONS" ]; then
echo "{\"status\":\"success\"}"
exit 0
fi
# Only handle GET requests
if [ "${REQUEST_METHOD:-GET}" != "GET" ]; then
echo "{\"status\":\"error\",\"message\":\"Method not allowed\"}"
exit 0
fi
# Paths
PING_JSON="/tmp/quecmanager/ping_latency.json"
CONFIG_FILE="/etc/quecmanager/settings/ping_settings.conf"
[ -f "$CONFIG_FILE" ] || CONFIG_FILE="/tmp/quecmanager/settings/ping_settings.conf"
# Get enabled setting
get_enabled() {
local enabled="true"
if [ -f "$CONFIG_FILE" ]; then
val=$(grep -E "^PING_ENABLED=" "$CONFIG_FILE" 2>/dev/null | tail -n1 | cut -d'=' -f2 | tr -d '\r' || echo "")
case "${val:-}" in
true|1|on|yes|enabled) enabled="true" ;;
false|0|off|no|disabled) enabled="false" ;;
esac
fi
echo "$enabled"
}
# Get interval setting
get_interval() {
local interval="5"
if [ -f "$CONFIG_FILE" ]; then
val=$(grep -E "^PING_INTERVAL=" "$CONFIG_FILE" 2>/dev/null | tail -n1 | cut -d'=' -f2 | tr -d '\r' || echo "")
if [ -n "$val" ] && echo "$val" | grep -qE '^[0-9]+$'; then
interval="$val"
fi
fi
echo "$interval"
}
# Get host setting
get_host() {
local host="8.8.8.8"
if [ -f "$CONFIG_FILE" ]; then
val=$(grep -E "^PING_HOST=" "$CONFIG_FILE" 2>/dev/null | tail -n1 | cut -d'=' -f2 | tr -d '\r' || echo "")
if [ -n "$val" ]; then
host="$val"
fi
fi
echo "$host"
}
# Get config values
ENABLED=$(get_enabled)
INTERVAL=$(get_interval)
HOST=$(get_host)
# Check if daemon JSON exists and is readable
if [ -f "$OUT_JSON" ] && [ -r "$OUT_JSON" ]; then
# Read the daemon output
PING_DATA=$(cat "$OUT_JSON" 2>/dev/null || echo "")
# Check if ping data file exists
if [ -f "$PING_JSON" ] && [ -r "$PING_JSON" ]; then
# Read the file content
ping_data=$(cat "$PING_JSON" 2>/dev/null)
if [ -n "$PING_DATA" ]; then
# Simple approach: just wrap the daemon data with our response format
echo "{\"status\":\"success\",\"data\":$PING_DATA,\"config\":{\"enabled\":$ENABLED,\"interval\":$INTERVAL,\"host\":\"$HOST\"}}"
# Check if we got content and it looks like JSON
if [ -n "$ping_data" ] && echo "$ping_data" | grep -q '"timestamp"'; then
# File exists and has content, return it wrapped in success
echo "{\"status\":\"success\",\"data\":$ping_data}"
else
# JSON file exists but is empty/unreadable
echo "{\"status\":\"error\",\"message\":\"Ping data file exists but is empty or unreadable\"}"
echo "{\"status\":\"error\",\"message\":\"Ping data file is empty or corrupted\"}"
fi
else
# Fallback: return default structure when daemon file doesn't exist
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date +"%Y-%m-%dT%H:%M:%SZ")
echo "{\"status\":\"success\",\"data\":{\"timestamp\":\"$TIMESTAMP\",\"host\":\"$HOST\",\"latency\":null,\"ok\":false},\"config\":{\"enabled\":$ENABLED,\"interval\":$INTERVAL,\"host\":\"$HOST\"}}"
# No ping file exists - check configuration
if [ -f "$CONFIG_FILE" ] && [ -r "$CONFIG_FILE" ]; then
# Check if ping monitoring is enabled
if grep -q "^PING_ENABLED=true" "$CONFIG_FILE" 2>/dev/null; then
echo "{\"status\":\"error\",\"message\":\"Ping daemon starting up\"}"
else
echo "{\"status\":\"error\",\"message\":\"Ping monitoring disabled\"}"
fi
else
echo "{\"status\":\"error\",\"message\":\"Ping monitoring not configured\"}"
fi
fi
# Always exit cleanly
exit 0

View File

@@ -0,0 +1,62 @@
#!/bin/sh
# Ping Service Configuration Script - Simple OpenWrt compatible version
# Always set CORS headers first
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: GET, OPTIONS"
echo "Access-Control-Allow-Headers: Content-Type"
echo ""
# Handle OPTIONS request and exit early
if [ "${REQUEST_METHOD:-GET}" = "OPTIONS" ]; then
echo "{\"status\":\"success\"}"
exit 0
fi
# Only handle GET requests
if [ "${REQUEST_METHOD:-GET}" != "GET" ]; then
echo "{\"status\":\"error\",\"message\":\"Method not allowed\"}"
exit 0
fi
# Configuration path
CONFIG_FILE="/etc/quecmanager/settings/ping_settings.conf"
# Get current configuration
ENABLED="false"
INTERVAL="5"
HOST="8.8.8.8"
if [ -f "$CONFIG_FILE" ] && [ -r "$CONFIG_FILE" ]; then
# Parse config using awk (more reliable in BusyBox)
enabled_val=$(awk -F'=' '/^PING_ENABLED=/ {print $2}' "$CONFIG_FILE" 2>/dev/null | tr -d '"')
interval_val=$(awk -F'=' '/^PING_INTERVAL=/ {print $2}' "$CONFIG_FILE" 2>/dev/null)
host_val=$(awk -F'=' '/^PING_HOST=/ {print $2}' "$CONFIG_FILE" 2>/dev/null | tr -d '"')
case "$enabled_val" in
true|1|on|yes|enabled) ENABLED="true" ;;
*) ENABLED="false" ;;
esac
if echo "$interval_val" | grep -qE '^[0-9]+$' && [ "$interval_val" -ge 1 ] && [ "$interval_val" -le 3600 ]; then
INTERVAL="$interval_val"
fi
if [ -n "$host_val" ]; then
HOST="$host_val"
fi
fi
# Check if ping daemon is running
RUNNING="false"
if pgrep -f "ping_daemon.sh" >/dev/null 2>&1; then
RUNNING="true"
fi
# Return configuration and status
echo "{\"status\":\"success\",\"data\":{\"enabled\":$ENABLED,\"interval\":$INTERVAL,\"host\":\"$HOST\",\"running\":$RUNNING}}"
# Always exit cleanly
exit 0