Updated scirpts for Hot Fix
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Windows Zone.Identifier files (created when downloading files from internet)
|
||||
*:Zone.Identifier
|
||||
*Zone.Identifier
|
||||
@@ -2,11 +2,40 @@
|
||||
# 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>"
|
||||
@@ -20,14 +49,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"
|
||||
logger -t at_queue -p daemon.debug "urldecode: input='$encoded'"
|
||||
log_at_queue_client "debug" "urldecode: input='$encoded'"
|
||||
|
||||
# Handle %2B -> + and %22 -> " conversions
|
||||
local decoded="${encoded//%2B/+}"
|
||||
@@ -35,10 +64,23 @@ urldecode() {
|
||||
# Then handle other encoded characters
|
||||
decoded=$(printf '%b' "${decoded//%/\\x}")
|
||||
|
||||
logger -t at_queue -p daemon.debug "urldecode: output='$decoded'"
|
||||
log_at_queue_client "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"
|
||||
@@ -72,19 +114,19 @@ get_command_id() {
|
||||
# Normalize AT command
|
||||
normalize_at_command() {
|
||||
local cmd="$1"
|
||||
logger -t at_queue -p daemon.debug "normalize: input='$cmd'"
|
||||
log_at_queue_client "debug" "normalize: input='$cmd'"
|
||||
|
||||
# URL decode the command
|
||||
cmd=$(urldecode "$cmd")
|
||||
logger -t at_queue -p daemon.debug "normalize: after urldecode='$cmd'"
|
||||
log_at_queue_client "debug" "normalize: after urldecode='$cmd'"
|
||||
|
||||
# Remove any carriage returns or newlines
|
||||
cmd=$(echo "$cmd" | tr -d '\r\n')
|
||||
logger -t at_queue -p daemon.debug "normalize: after cleanup='$cmd'"
|
||||
log_at_queue_client "debug" "normalize: after cleanup='$cmd'"
|
||||
|
||||
# Trim leading/trailing whitespace while preserving quotes
|
||||
cmd=$(echo "$cmd" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
logger -t at_queue -p daemon.debug "normalize: final output='$cmd'"
|
||||
log_at_queue_client "debug" "normalize: final output='$cmd'"
|
||||
|
||||
echo "$cmd"
|
||||
}
|
||||
@@ -101,7 +143,7 @@ submit_command() {
|
||||
|
||||
# Submit using appropriate method
|
||||
if [ "${SCRIPT_NAME}" != "" ]; then
|
||||
# CGI mode - direct execution
|
||||
# CGI mode - direct execution like the original working version
|
||||
local escaped_cmd=$(echo "$cmd" | sed 's/"/\\"/g')
|
||||
QUERY_STRING="action=enqueue&command=${escaped_cmd}&priority=$priority" "$QUEUE_MANAGER"
|
||||
else
|
||||
@@ -118,7 +160,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
|
||||
logger -t at_queue -p daemon.error "Empty result file for command ID: $cmd_id"
|
||||
log_at_queue_client "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
|
||||
|
||||
@@ -18,7 +18,7 @@ RESULTS_MAX_AGE=3600 # 1 hour in seconds
|
||||
POLL_INTERVAL=0.01
|
||||
PREEMPTION_THRESHOLD=2 # 3 seconds threshold for preemption
|
||||
TOKEN_TIMEOUT=30 # seconds before token expires
|
||||
SCRIPT_NAME="at_queue_manager"
|
||||
SCRIPT_NAME_LOG="at_queue_manager"
|
||||
|
||||
# Logging function - uses both centralized and system logging
|
||||
log_at_queue() {
|
||||
@@ -28,16 +28,16 @@ log_at_queue() {
|
||||
# Use centralized logging
|
||||
case "$level" in
|
||||
"error")
|
||||
qm_log_error "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_error "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
"warn")
|
||||
qm_log_warn "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_warn "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
"debug")
|
||||
qm_log_debug "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_debug "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
*)
|
||||
qm_log_info "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_info "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -81,20 +81,23 @@ acquire_lock() {
|
||||
}
|
||||
|
||||
release_lock() {
|
||||
if rmdir "$LOCK_DIR" 2>/dev/null; then
|
||||
if [ -d "$LOCK_DIR" ]; then
|
||||
rmdir "$LOCK_DIR" 2>/dev/null
|
||||
log_at_queue "debug" "Lock released"
|
||||
return 0
|
||||
else
|
||||
log_at_queue "error" "Lock directory doesn't exist"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_at_queue "error" "Lock directory doesn't exist"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Ensure required directories exist
|
||||
initialize_queue() {
|
||||
init_queue_system() {
|
||||
mkdir -p "$QUEUE_DIR" "$RESULTS_DIR"
|
||||
touch "$QUEUE_FILE" "$ACTIVE_FILE"
|
||||
chmod 666 "$QUEUE_FILE" "$ACTIVE_FILE"
|
||||
touch "$QUEUE_FILE"
|
||||
chmod 755 "$QUEUE_DIR"
|
||||
chmod 644 "$QUEUE_FILE"
|
||||
chmod 755 "$RESULTS_DIR"
|
||||
log_at_queue "info" "Queue system initialized"
|
||||
}
|
||||
|
||||
@@ -102,10 +105,13 @@ initialize_queue() {
|
||||
cleanup_old_results() {
|
||||
local current_time=$(date +%s)
|
||||
|
||||
# Remove old tracking files
|
||||
find "$QUEUE_DIR" -name "start_time.*" -o -name "pid.*" -type f -mmin +60 -delete 2>/dev/null
|
||||
# Clean up old execution tracking files
|
||||
find "$QUEUE_DIR" -name "pid.*" -type f -mmin +60 -delete 2>/dev/null
|
||||
find "$QUEUE_DIR" -name "*.exit" -type f -mmin +60 -delete 2>/dev/null
|
||||
find "$QUEUE_DIR" -name "start_time.*" -type f -mmin +60 -delete 2>/dev/null
|
||||
log_at_queue "debug" "Cleaned up old tracking files"
|
||||
|
||||
log_at_queue "debug" "Cleaned up old tracking files" # Use find with -delete and basic timestamp check for OpenWRT
|
||||
# Use find with -delete and basic timestamp check for OpenWRT
|
||||
find "$RESULTS_DIR" -name "*.json" -type f -mmin +60 -delete 2>/dev/null || {
|
||||
# Fallback method if find fails
|
||||
for file in "$RESULTS_DIR"/*.json; do
|
||||
@@ -635,24 +641,9 @@ if [ "${SCRIPT_NAME}" != "" ]; then
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Log the incoming request for debugging
|
||||
log_at_queue "debug" "CGI: Incoming request - QUERY_STRING='$QUERY_STRING', REQUEST_METHOD='$REQUEST_METHOD', HTTP_USER_AGENT='$HTTP_USER_AGENT'"
|
||||
|
||||
# Parse query string for CGI mode
|
||||
eval $(echo "$QUERY_STRING" | sed 's/&/;/g')
|
||||
|
||||
# Handle empty action parameter specifically
|
||||
if [ -z "$action" ]; then
|
||||
if [ -z "$QUERY_STRING" ]; then
|
||||
log_at_queue "warn" "CGI: No query string provided - possible health check or browser prefetch"
|
||||
echo "{\"error\":\"No action specified\",\"help\":\"Valid actions: enqueue, status, request_token, release_token\"}"
|
||||
else
|
||||
log_at_queue "warn" "CGI: Query string present but no action parameter: '$QUERY_STRING'"
|
||||
echo "{\"error\":\"Missing action parameter\",\"query_string\":\"$QUERY_STRING\"}"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$action" in
|
||||
"enqueue")
|
||||
if [ -n "$command" ]; then
|
||||
@@ -691,8 +682,8 @@ if [ "${SCRIPT_NAME}" != "" ]; then
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
log_at_queue "error" "CGI: Invalid action received: '$action' (QUERY_STRING: '$QUERY_STRING')"
|
||||
echo "{\"error\":\"Invalid action: $action\",\"valid_actions\":[\"enqueue\",\"status\",\"request_token\",\"release_token\"]}"
|
||||
log_at_queue "error" "CGI: Invalid action received: $action"
|
||||
echo "{\"error\":\"Invalid action\"}"
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -707,4 +698,4 @@ fi
|
||||
# If not run as CGI, start queue processing
|
||||
if [ "${SCRIPT_NAME}" = "" ] && [ -z "$1" ]; then
|
||||
process_queue
|
||||
fi
|
||||
fi
|
||||
@@ -12,39 +12,57 @@ TRACK_FILE="/tmp/quecprofiles_active"
|
||||
CHECK_TRIGGER="/tmp/quecprofiles_check"
|
||||
STATUS_FILE="/tmp/quecprofiles_status.json"
|
||||
APPLIED_FLAG="/tmp/quecprofiles_applied"
|
||||
DEBUG_LOG="/tmp/quecprofiles_debug.log"
|
||||
DETAILED_LOG="/tmp/quecprofiles_detailed.log"
|
||||
DEFAULT_CHECK_INTERVAL=60 # Default check interval in seconds
|
||||
COMMAND_TIMEOUT=10 # Default timeout for AT commands in seconds
|
||||
QUEUE_PRIORITY=3 # Medium-high priority (1 is highest for cell scan)
|
||||
MAX_TOKEN_WAIT=15 # Maximum seconds to wait for token acquisition
|
||||
SCRIPT_NAME="quecprofile"
|
||||
SCRIPT_NAME_LOG="quecprofiles_daemon"
|
||||
|
||||
# Initialize logging
|
||||
qm_log_info "service" "$SCRIPT_NAME" "Starting QuecProfiles daemon with SA/NSA NR5G and TTL support (PID: $$)"
|
||||
# Initialize log files and use centralized logging
|
||||
mkdir -p "$(dirname "$DEBUG_LOG")" "$(dirname "$DETAILED_LOG")"
|
||||
touch "$DEBUG_LOG" "$DETAILED_LOG"
|
||||
chmod 644 "$DEBUG_LOG" "$DETAILED_LOG"
|
||||
|
||||
# Function to log messages
|
||||
# Log startup message using centralized logging
|
||||
qm_log_info "service" "$SCRIPT_NAME_LOG" "Starting QuecProfiles daemon with SA/NSA NR5G and TTL support (PID: $$)"
|
||||
|
||||
# Also maintain file logging for compatibility
|
||||
echo "$(date) - Starting QuecProfiles daemon with SA/NSA NR5G and TTL support (PID: $$)" >"$DEBUG_LOG"
|
||||
echo "$(date) - Starting QuecProfiles daemon with SA/NSA NR5G and TTL support (PID: $$)" >"$DETAILED_LOG"
|
||||
|
||||
# Function to log messages - now uses centralized logging
|
||||
log_message() {
|
||||
local message="$1"
|
||||
local level="${2:-info}"
|
||||
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Use centralized logging
|
||||
case "$level" in
|
||||
"error")
|
||||
qm_log_error "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_error "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
"warn")
|
||||
qm_log_warn "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_warn "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
"debug")
|
||||
qm_log_debug "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_debug "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
*)
|
||||
qm_log_info "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_info "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Also log to system log for important messages
|
||||
if [ "$level" = "error" ] || [ "$level" = "warn" ] || [ "$level" = "info" ]; then
|
||||
logger -t quecprofiles_daemon -p "daemon.$level" "$message"
|
||||
# Also maintain system logging for compatibility
|
||||
logger -t quecprofiles_daemon -p "daemon.$level" "$message"
|
||||
|
||||
# Log to debug file (maintain existing behavior)
|
||||
echo "[$timestamp] [$level] $message" >>"$DEBUG_LOG"
|
||||
|
||||
# For detailed logs or errors (maintain existing behavior)
|
||||
if [ "$level" = "error" ] || [ "$level" = "debug" ]; then
|
||||
echo "[$timestamp] [$level] $message" >>"$DETAILED_LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -3,55 +3,59 @@
|
||||
# QuecWatch Daemon
|
||||
# Monitors cellular connectivity and performs recovery actions
|
||||
|
||||
# Load UCI configuration functions
|
||||
. /lib/functions.sh
|
||||
|
||||
# Load centralized logging
|
||||
. /www/cgi-bin/services/quecmanager_logger.sh
|
||||
|
||||
# Load UCI configuration functions
|
||||
. /lib/functions.sh
|
||||
|
||||
# Configuration
|
||||
QUEUE_DIR="/tmp/at_queue"
|
||||
TOKEN_FILE="$QUEUE_DIR/token"
|
||||
LOG_DIR="/tmp/log/quecwatch"
|
||||
LOG_FILE="$LOG_DIR/quecwatch.log"
|
||||
PID_FILE="/var/run/quecwatch.pid"
|
||||
STATUS_FILE="/tmp/quecwatch_status.json"
|
||||
RETRY_COUNT_FILE="/tmp/quecwatch_retry_count"
|
||||
UCI_CONFIG="quecmanager"
|
||||
MAX_TOKEN_WAIT=10 # Maximum seconds to wait for token acquisition
|
||||
TOKEN_PRIORITY=15 # Medium priority (between profiles and metrics)
|
||||
SCRIPT_NAME="quecwatch"
|
||||
SCRIPT_NAME_LOG="quecwatch"
|
||||
|
||||
# Ensure directories exist
|
||||
mkdir -p "$QUEUE_DIR"
|
||||
mkdir -p "$LOG_DIR" "$QUEUE_DIR"
|
||||
|
||||
# Store PID
|
||||
echo "$$" > "$PID_FILE"
|
||||
chmod 644 "$PID_FILE"
|
||||
|
||||
# Function to log messages
|
||||
# Function to log messages - now uses centralized logging
|
||||
log_message() {
|
||||
local level="${2:-info}"
|
||||
local message="$1"
|
||||
local timestamp=$(date "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Use centralized logging
|
||||
case "$level" in
|
||||
"error")
|
||||
qm_log_error "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_error "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
"warn")
|
||||
qm_log_warn "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_warn "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
"debug")
|
||||
qm_log_debug "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_debug "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
*)
|
||||
qm_log_info "service" "$SCRIPT_NAME" "$message"
|
||||
qm_log_info "service" "$SCRIPT_NAME_LOG" "$message"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Also log to system log for important messages
|
||||
if [ "$level" = "error" ] || [ "$level" = "warn" ] || [ "$level" = "info" ]; then
|
||||
logger -t quecwatch -p "daemon.$level" "$message"
|
||||
fi
|
||||
# Also maintain system logging for compatibility
|
||||
logger -t quecwatch -p "daemon.$level" "$message"
|
||||
|
||||
# Log to file (maintain existing behavior)
|
||||
echo "[$timestamp] [$level] $message" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Function to update status
|
||||
|
||||
Reference in New Issue
Block a user