Copy QuecManager beta to non-beta

QM BETA --> regular/non-beta
This commit is contained in:
Cameron Thompson
2025-08-31 02:17:49 -04:00
parent 6d6a3775c4
commit 02dafc73ad
391 changed files with 4494 additions and 740 deletions

View File

@@ -1,5 +1,8 @@
#!/bin/sh
# Ethernet Hardware Details Fetch Script
# Provides ethernet interface information using ethtool
# Set common headers
echo "Content-Type: application/json"
echo "Access-Control-Allow-Origin: *"
@@ -8,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() {
@@ -57,63 +60,72 @@ cleanup() {
# Set trap for cleanup
trap cleanup EXIT INT TERM
# Function to get memory information
get_memory_info() {
free_output=$(free -b)
memory_info=$(echo "$free_output" | awk '/Mem:/ {print "{\"total\": " $2 ", \"used\": " $3 ", \"available\": " $7 "}"}')
echo "$memory_info"
}
# 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
# Acquire lock before proceeding
acquire_lock
# Parse query string for type and interface
type=$(echo "$QUERY_STRING" | sed -n 's/.*type=\([^&]*\).*/\1/p')
# Parse query string for interface parameter
interface=$(echo "$QUERY_STRING" | sed -n 's/.*interface=\([^&]*\).*/\1/p')
# Default interface if not specified
[ -z "$interface" ] && interface="eth0"
# Convert type to lowercase using tr
type=$(echo "$type" | tr '[:upper:]' '[:lower:]')
# Check type parameter and call appropriate function
case "$type" in
"memory")
get_memory_info
;;
"eth")
get_ethernet_info "$interface"
;;
*)
error_response "Invalid type. Use 'memory' or 'eth'"
;;
esac
# Get ethernet information for the specified interface
get_ethernet_info "$interface"
# Lock will be automatically released by the cleanup trap

View File

@@ -6,6 +6,15 @@
echo "Content-Type: application/json"
echo ""
# Check for internet connectivity by pinging 8.8.8.8 twice
ping -c 2 8.8.8.8 >/dev/null 2>&1
# If ping fails, return error immediately
if [ $? -ne 0 ]; then
echo '{"error": "Failed to fetch public IP"}'
exit 1
fi
# Fetch public IP using multiple fallback methods
PUBLIC_IP=$(
curl -s https://api.ipify.org 2>/dev/null || \

View File

@@ -0,0 +1,59 @@
#!/bin/sh
# Memory Data Fetch Script - Simplified and robust
# 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 "{\"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
MEMORY_JSON="/tmp/quecmanager/memory.json"
CONFIG_FILE="/etc/quecmanager/settings/memory_settings.conf"
# 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)
# 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 format\"}"
fi
else
echo "{\"status\":\"error\",\"message\":\"Memory data file is empty or corrupted\"}"
fi
else
# 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

@@ -0,0 +1,78 @@
#!/bin/sh
# Memory Service Fetch Script
# Returns current memory configuration and status
# Handle OPTIONS request first
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 ""
exit 0
fi
# Set content type and CORS headers
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 paths
CONFIG_FILE="/etc/quecmanager/settings/memory_settings.conf"
FALLBACK_CONFIG_FILE="/tmp/quecmanager/settings/memory_settings.conf"
# Get current configuration
get_config() {
# Defaults
ENABLED="false"
INTERVAL="1"
# Try primary config first, then fallback
local config_to_read=""
if [ -f "$CONFIG_FILE" ]; then
config_to_read="$CONFIG_FILE"
elif [ -f "$FALLBACK_CONFIG_FILE" ]; then
config_to_read="$FALLBACK_CONFIG_FILE"
fi
if [ -n "$config_to_read" ]; then
local enabled_val=$(grep "^MEMORY_ENABLED=" "$config_to_read" 2>/dev/null | tail -n1 | cut -d'=' -f2 | tr -d '"')
local interval_val=$(grep "^MEMORY_INTERVAL=" "$config_to_read" 2>/dev/null | tail -n1 | cut -d'=' -f2)
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 10 ]; then
INTERVAL="$interval_val"
fi
fi
}
# Check if memory daemon is running
is_memory_daemon_running() {
pgrep -f "memory_daemon.sh" >/dev/null 2>&1
}
# Handle GET request only
if [ "${REQUEST_METHOD:-GET}" != "GET" ]; then
echo "{\"status\":\"error\",\"code\":\"METHOD_NOT_ALLOWED\",\"message\":\"Only GET method is supported\"}"
exit 1
fi
# Get current configuration
get_config
# Check daemon status
running="false"
if is_memory_daemon_running; then
running="true"
fi
# Return configuration and status
echo "{\"status\":\"success\",\"data\":{\"enabled\":$ENABLED,\"interval\":$INTERVAL,\"running\":$running}}"

View File

@@ -0,0 +1,55 @@
#!/bin/sh
# Ping Data Fetch Script - Simplified and OpenWrt compatible
# 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
# Paths
PING_JSON="/tmp/quecmanager/ping_latency.json"
CONFIG_FILE="/etc/quecmanager/settings/ping_settings.conf"
# 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)
# 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
echo "{\"status\":\"error\",\"message\":\"Ping data file is empty or corrupted\"}"
fi
else
# 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

View File

@@ -1,24 +0,0 @@
#!/bin/sh
# Set the content type to JSON
echo "Content-Type: application/json"
echo ""
# Ping 8.8.8.8 with 5 packets and capture the full output
ping_result=$(ping -c 5 8.8.8.8)
# Check if ping was successful
if [ $? -eq 0 ]; then
# Extract the average latency using awk
avg_latency=$(echo "$ping_result" | awk '/avg/ {split($4, a, "/"); print int(a[2])}')
# If average latency was extracted, return it
if [ ! -z "$avg_latency" ]; then
echo "{\"connection\": \"ACTIVE\", \"latency\": $avg_latency}"
else
echo '{"connection": "ACTIVE", "latency": 0}'
fi
else
# Ping failed
echo '{"connection": "INACTIVE", "latency": 0}'
fi

View File

@@ -19,7 +19,7 @@ chmod 644 $STATUS_FILE
# Run speedtest in background and pipe output to status file
(
export HOME=/tmp/home
/usr/bin/speedtest --accept-license -f json -p yes --progress-update-interval=100 | \
/usr/bin/speedtest --accept-license --accept-gdpr -f json -p yes --progress-update-interval=100 | \
while IFS= read -r line; do
# Update status file with latest JSON data
echo "$line" > $STATUS_FILE