Release Candidate v2.3.1

This commit is contained in:
Russel Yasol
2025-08-27 21:13:19 +08:00
parent 789cb0bc3a
commit e054ada872
83 changed files with 313 additions and 239 deletions

View File

@@ -2,40 +2,11 @@
# AT Queue Client for OpenWRT
# Located in /www/cgi-bin/services/at_queue_client
# Load centralized logging
. /www/cgi-bin/services/quecmanager_logger.sh
AUTH_FILE="/tmp/auth_success"
QUEUE_DIR="/tmp/at_queue"
RESULTS_DIR="$QUEUE_DIR/results"
QUEUE_MANAGER="/www/cgi-bin/services/at_queue_manager.sh"
POLL_INTERVAL=0.01
SCRIPT_NAME_LOG="at_queue_client"
# Logging function - uses both centralized and system logging
log_at_queue_client() {
local level="$1"
local message="$2"
# Use centralized logging
case "$level" in
"error")
qm_log_error "service" "$SCRIPT_NAME_LOG" "$message"
;;
"warn")
qm_log_warn "service" "$SCRIPT_NAME_LOG" "$message"
;;
"debug")
qm_log_debug "service" "$SCRIPT_NAME_LOG" "$message"
;;
*)
qm_log_info "service" "$SCRIPT_NAME_LOG" "$message"
;;
esac
# Also maintain system logging for compatibility
logger -t at_queue -p "daemon.$level" "$message"
}
usage() {
echo "Usage: $0 [options] <AT command>"
@@ -49,14 +20,14 @@ usage() {
# Output JSON response
output_json() {
local content="$1"
local headers="${2:-1}" # Default to showing headers
local headers="${2:-1}" # Default to showing headers
echo "$content"
}
# URL decode function
urldecode() {
local encoded="$1"
log_at_queue_client "debug" "urldecode: input='$encoded'"
logger -t at_queue -p daemon.debug "urldecode: input='$encoded'"
# Handle %2B -> + and %22 -> " conversions
local decoded="${encoded//%2B/+}"
@@ -64,23 +35,10 @@ urldecode() {
# Then handle other encoded characters
decoded=$(printf '%b' "${decoded//%/\\x}")
log_at_queue_client "debug" "urldecode: output='$decoded'"
logger -t at_queue -p daemon.debug "urldecode: output='$decoded'"
echo "$decoded"
}
# URL encode function (simplified for AT commands)
urlencode() {
local string="$1"
# Simple encoding for common AT command characters
string="${string// /%20}"
string="${string//+/%2B}"
string="${string//\"/%22}"
string="${string//=/%3D}"
string="${string//&/%26}"
string="${string//?/%3F}"
echo "$string"
}
# Extract command ID from response with improved error handling
get_command_id() {
local response="$1"
@@ -114,19 +72,19 @@ get_command_id() {
# Normalize AT command
normalize_at_command() {
local cmd="$1"
log_at_queue_client "debug" "normalize: input='$cmd'"
logger -t at_queue -p daemon.debug "normalize: input='$cmd'"
# URL decode the command
cmd=$(urldecode "$cmd")
log_at_queue_client "debug" "normalize: after urldecode='$cmd'"
logger -t at_queue -p daemon.debug "normalize: after urldecode='$cmd'"
# Remove any carriage returns or newlines
cmd=$(echo "$cmd" | tr -d '\r\n')
log_at_queue_client "debug" "normalize: after cleanup='$cmd'"
logger -t at_queue -p daemon.debug "normalize: after cleanup='$cmd'"
# Trim leading/trailing whitespace while preserving quotes
cmd=$(echo "$cmd" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
log_at_queue_client "debug" "normalize: final output='$cmd'"
logger -t at_queue -p daemon.debug "normalize: final output='$cmd'"
echo "$cmd"
}
@@ -143,7 +101,7 @@ submit_command() {
# Submit using appropriate method
if [ "${SCRIPT_NAME}" != "" ]; then
# CGI mode - direct execution like the original working version
# CGI mode - direct execution
local escaped_cmd=$(echo "$cmd" | sed 's/"/\\"/g')
QUERY_STRING="action=enqueue&command=${escaped_cmd}&priority=$priority" "$QUEUE_MANAGER"
else
@@ -160,7 +118,7 @@ check_result() {
if [ -f "$RESULTS_DIR/$cmd_id.json" ]; then
local result_content=$(cat "$RESULTS_DIR/$cmd_id.json")
if [ -z "$result_content" ]; then
log_at_queue_client "error" "Empty result file for command ID: $cmd_id"
logger -t at_queue -p daemon.error "Empty result file for command ID: $cmd_id"
local error_json="{\"error\":\"Empty result file\",\"command_id\":\"$cmd_id\"}"
output_json "$error_json" "$show_headers"
return 1

View File

@@ -0,0 +1,35 @@
#!/bin/sh
# Location: /www/cgi-bin/quecmanager/home/speedtest/check_speedtest.sh
echo "Content-Type: application/json"
echo ""
# Check if speedtest binary exists and is executable
if ! command -v speedtest >/dev/null 2>&1; then
echo '{"status":"error","message":"Speedtest binary not found in PATH","available":false}'
exit 1
fi
# Get speedtest binary location
SPEEDTEST_PATH=$(which speedtest 2>/dev/null)
# Check if binary is executable
if [ ! -x "$SPEEDTEST_PATH" ]; then
echo '{"status":"error","message":"Speedtest binary is not executable","available":false,"path":"'$SPEEDTEST_PATH'"}'
exit 1
fi
# Try to get version (this also checks if binary works)
VERSION_OUTPUT=$(speedtest --version 2>/dev/null | head -1)
if [ $? -ne 0 ]; then
echo '{"status":"error","message":"Speedtest binary exists but is not working properly","available":false,"path":"'$SPEEDTEST_PATH'"}'
exit 1
fi
# Check if license is already accepted
LICENSE_CHECK=$(timeout 5 speedtest --accept-license --help 2>/dev/null | grep -i "usage\|help" | head -1)
if [ -z "$LICENSE_CHECK" ]; then
echo '{"status":"warning","message":"Speedtest binary may need license acceptance","available":true,"path":"'$SPEEDTEST_PATH'","version":"'$VERSION_OUTPUT'"}'
else
echo '{"status":"ok","message":"Speedtest is properly installed and ready","available":true,"path":"'$SPEEDTEST_PATH'","version":"'$VERSION_OUTPUT'"}'
fi

View File

@@ -0,0 +1,55 @@
#!/bin/sh
# Location: /www/cgi-bin/quecmanager/home/speedtest/cleanup_speedtest.sh
echo "Content-Type: application/json"
echo ""
# Configuration
STATUS_FILE="/tmp/speedtest_status.json"
FINAL_RESULT="/tmp/speedtest_final.json"
PID_FILE="/tmp/speedtest.pid"
LOG_FILE="/tmp/speedtest.log"
CLEANED_FILES=""
KILLED_PROCESSES=""
# Kill any running speedtest processes
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE" 2>/dev/null)
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
kill -9 "$PID" 2>/dev/null
KILLED_PROCESSES="$PID"
fi
fi
# Also kill any speedtest processes that might be running without PID file
STRAY_PIDS=$(ps | grep speedtest | grep -v grep | awk '{print $1}' 2>/dev/null)
if [ -n "$STRAY_PIDS" ]; then
for pid in $STRAY_PIDS; do
kill -9 "$pid" 2>/dev/null
if [ -n "$KILLED_PROCESSES" ]; then
KILLED_PROCESSES="$KILLED_PROCESSES,$pid"
else
KILLED_PROCESSES="$pid"
fi
done
fi
# Remove all speedtest-related files
for file in "$STATUS_FILE" "$FINAL_RESULT" "$PID_FILE" "$LOG_FILE"; do
if [ -f "$file" ]; then
rm -f "$file"
if [ -n "$CLEANED_FILES" ]; then
CLEANED_FILES="$CLEANED_FILES,$(basename $file)"
else
CLEANED_FILES="$(basename $file)"
fi
fi
done
# Prepare response
if [ -n "$CLEANED_FILES" ] || [ -n "$KILLED_PROCESSES" ]; then
echo '{"status":"cleaned","message":"Cleanup completed","cleaned_files":"'$CLEANED_FILES'","killed_processes":"'$KILLED_PROCESSES'","timestamp":'$(date +%s)'}'
else
echo '{"status":"clean","message":"No cleanup needed","timestamp":'$(date +%s)'}'
fi

View File

@@ -0,0 +1,55 @@
#!/bin/sh
# Location: /www/cgi-bin/quecmanager/home/speedtest/stop_speedtest.sh
# Configuration
STATUS_FILE="/tmp/speedtest_status.json"
FINAL_RESULT="/tmp/speedtest_final.json"
PID_FILE="/tmp/speedtest.pid"
LOG_FILE="/tmp/speedtest.log"
# Set headers
echo "Content-Type: application/json"
echo ""
# Function to cleanup all speedtest files
cleanup_all() {
rm -f "$STATUS_FILE" "$FINAL_RESULT" "$PID_FILE" "$LOG_FILE"
}
# Check if speedtest is running
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE" 2>/dev/null)
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
# Kill the process
kill "$PID" 2>/dev/null
sleep 1
# Force kill if still running
if kill -0 "$PID" 2>/dev/null; then
kill -9 "$PID" 2>/dev/null
fi
# Wait for process to die
count=0
while kill -0 "$PID" 2>/dev/null && [ $count -lt 5 ]; do
sleep 1
count=$((count + 1))
done
# Log the cancellation
echo "Speedtest cancelled at $(date)" >> "$LOG_FILE" 2>/dev/null
# Cleanup files
cleanup_all
echo '{"status":"cancelled","message":"Speedtest cancelled successfully","timestamp":'$(date +%s)'}'
else
# PID file exists but process is not running
cleanup_all
echo '{"status":"not_running","message":"No active speedtest found","timestamp":'$(date +%s)'}'
fi
else
# No PID file, cleanup any stale files
cleanup_all
echo '{"status":"not_running","message":"No active speedtest found","timestamp":'$(date +%s)'}'
fi