temporarily reverted back at_queue scripts
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# AT Queue Client for OpenWRT
|
||||
# Located in /www/cgi-bin/services/at_queue_client
|
||||
|
||||
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"
|
||||
@@ -184,10 +185,36 @@ if [ "${SCRIPT_NAME}" != "" ]; then
|
||||
# Output headers only once at the beginning
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Get Token from Authorization Header
|
||||
TOKEN="${HTTP_AUTHORIZATION}"
|
||||
if [ ! -f $AUTH_FILE ]; then
|
||||
output_json "{\"error\":\"Unauthenticated Request\"}" "0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$TOKEN" ] || "${TOKEN}" = "" || [ $(grep "${TOKEN}" "${AUTH_FILE}" | wc -l) -eq 0 ]; then
|
||||
output_json "{\"response\": { \"status\": \"error\", \"raw_output\": \"Not Authorized\" }, \"command\": {\"timestamp\": \"$(date +%Y%m%d'T'%H%M%S)\"}, \"error\":\"Not Authorized\"}" "0"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if token is within 2 hours
|
||||
TOKEN_LINE=$(grep "${TOKEN}" "${AUTH_FILE}")
|
||||
TOKEN_DATE=$(echo "$TOKEN_LINE" | awk '{print $1}' | sed 's/T/ /')
|
||||
TOKEN_TIME=$(date -d "$TOKEN_DATE" +%s 2>/dev/null)
|
||||
NOW_TIME=$(date +%s)
|
||||
MAX_AGE=$((2 * 3600)) # 2 hours in seconds
|
||||
|
||||
if [ -z "$TOKEN_TIME" ] || [ $((NOW_TIME - TOKEN_TIME)) -gt $MAX_AGE ]; then
|
||||
output_json "{ \"response\": { \"status\": \"error\", \"raw_output\": \"Token expired. Reauthenticate to get new token.\" }, \"command\": {\"timestamp\": \"$(date +%Y%m%d'T'%H%M%S)\"}, \"error\":\"Token expired\"}" "0"
|
||||
# Cleanup/Remove token from file
|
||||
sed -i -e "s/.*${TOKEN}.*//g" /tmp/auth_success 2>/dev/null
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse query string
|
||||
eval $(echo "$QUERY_STRING" | sed 's/&/;/g')
|
||||
|
||||
|
||||
# Handle different actions
|
||||
if [ -n "$command_id" ]; then
|
||||
# Get result for specific command ID
|
||||
@@ -196,13 +223,13 @@ if [ "${SCRIPT_NAME}" != "" ]; then
|
||||
# URL decode and normalize the command
|
||||
command=$(urldecode "$command")
|
||||
command=$(normalize_at_command "$command")
|
||||
|
||||
|
||||
# Check if it's a valid AT command
|
||||
if echo "$command" | grep -qi "^AT"; then
|
||||
# Submit command and get response
|
||||
response=$(submit_command "$command")
|
||||
cmd_id=$(get_command_id "$response")
|
||||
|
||||
|
||||
if [ "$wait" = "1" ]; then
|
||||
if [ -n "$cmd_id" ]; then
|
||||
wait_for_completion "$cmd_id" "${timeout:-180}" "0" # Don't show headers
|
||||
|
||||
Reference in New Issue
Block a user