Revert "temporarily reverted back at_queue scripts"
This reverts commit 5daf4bb388.
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
# AT Queue Client for OpenWRT
|
# AT Queue Client for OpenWRT
|
||||||
# Located in /www/cgi-bin/services/at_queue_client
|
# Located in /www/cgi-bin/services/at_queue_client
|
||||||
|
|
||||||
AUTH_FILE="/tmp/auth_success"
|
|
||||||
QUEUE_DIR="/tmp/at_queue"
|
QUEUE_DIR="/tmp/at_queue"
|
||||||
RESULTS_DIR="$QUEUE_DIR/results"
|
RESULTS_DIR="$QUEUE_DIR/results"
|
||||||
QUEUE_MANAGER="/www/cgi-bin/services/at_queue_manager.sh"
|
QUEUE_MANAGER="/www/cgi-bin/services/at_queue_manager.sh"
|
||||||
@@ -185,36 +184,10 @@ if [ "${SCRIPT_NAME}" != "" ]; then
|
|||||||
# Output headers only once at the beginning
|
# Output headers only once at the beginning
|
||||||
echo "Content-Type: application/json"
|
echo "Content-Type: application/json"
|
||||||
echo ""
|
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
|
# Parse query string
|
||||||
eval $(echo "$QUERY_STRING" | sed 's/&/;/g')
|
eval $(echo "$QUERY_STRING" | sed 's/&/;/g')
|
||||||
|
|
||||||
# Handle different actions
|
# Handle different actions
|
||||||
if [ -n "$command_id" ]; then
|
if [ -n "$command_id" ]; then
|
||||||
# Get result for specific command ID
|
# Get result for specific command ID
|
||||||
@@ -223,13 +196,13 @@ if [ "${SCRIPT_NAME}" != "" ]; then
|
|||||||
# URL decode and normalize the command
|
# URL decode and normalize the command
|
||||||
command=$(urldecode "$command")
|
command=$(urldecode "$command")
|
||||||
command=$(normalize_at_command "$command")
|
command=$(normalize_at_command "$command")
|
||||||
|
|
||||||
# Check if it's a valid AT command
|
# Check if it's a valid AT command
|
||||||
if echo "$command" | grep -qi "^AT"; then
|
if echo "$command" | grep -qi "^AT"; then
|
||||||
# Submit command and get response
|
# Submit command and get response
|
||||||
response=$(submit_command "$command")
|
response=$(submit_command "$command")
|
||||||
cmd_id=$(get_command_id "$response")
|
cmd_id=$(get_command_id "$response")
|
||||||
|
|
||||||
if [ "$wait" = "1" ]; then
|
if [ "$wait" = "1" ]; then
|
||||||
if [ -n "$cmd_id" ]; then
|
if [ -n "$cmd_id" ]; then
|
||||||
wait_for_completion "$cmd_id" "${timeout:-180}" "0" # Don't show headers
|
wait_for_completion "$cmd_id" "${timeout:-180}" "0" # Don't show headers
|
||||||
|
|||||||
Reference in New Issue
Block a user