QuecManager non-beta
Its about time I did this!
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set content type
|
||||
printf "Content-Type: application/json\n\n"
|
||||
|
||||
# URL decode function
|
||||
urldecode() {
|
||||
echo "$*" | sed 's/+/ /g;s/%\([0-9A-F][0-9A-F]\)/\\\\x\1/g' | xargs -0 printf '%b'
|
||||
}
|
||||
|
||||
# Extract indexes from query string
|
||||
query=$(echo "$QUERY_STRING" | grep -o 'indexes=[^&]*' | cut -d= -f2)
|
||||
indexes=$(urldecode "$query")
|
||||
|
||||
# Function to output JSON response
|
||||
send_json() {
|
||||
printf '{"status":"%s","message":"%s"}\n' "$1" "$2"
|
||||
}
|
||||
|
||||
# Validate input
|
||||
if [ -z "$indexes" ]; then
|
||||
send_json "error" "No indexes provided"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Initialize counters
|
||||
success=0
|
||||
failure=0
|
||||
|
||||
# Process each index
|
||||
echo "$indexes" | tr ',' '\n' | while read -r index; do
|
||||
if [ -n "$index" ] && [ "$index" -eq "$index" ] 2>/dev/null; then
|
||||
if sms_tool delete "$index" 2>/dev/null; then
|
||||
success=$((success + 1))
|
||||
else
|
||||
failure=$((failure + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Send response
|
||||
if [ $success -gt 0 ]; then
|
||||
if [ $failure -eq 0 ]; then
|
||||
send_json "success" "Successfully deleted $success message(s)"
|
||||
else
|
||||
send_json "partial" "Deleted $success message(s), failed to delete $failure message(s)"
|
||||
fi
|
||||
else
|
||||
send_json "error" "Failed to delete messages"
|
||||
fi
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
printf "Content-type: application/json\r\n\r\n"
|
||||
|
||||
# Execute the command and return the JSON response
|
||||
if command -v sms_tool > /dev/null 2>&1; then
|
||||
sms_tool -j recv
|
||||
else
|
||||
printf '{"error": "sms_tool not found"}\n'
|
||||
fi
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Content-Type: application/json"
|
||||
echo "Cache-Control: no-cache"
|
||||
echo ""
|
||||
|
||||
# Function to URL decode the string
|
||||
urldecode() {
|
||||
local url_encoded="${1//+/ }"
|
||||
printf '%b' "${url_encoded//%/\\x}"
|
||||
}
|
||||
|
||||
# Function to escape JSON string
|
||||
escape_json() {
|
||||
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g; s/\n/\\n/g; s/\r/\\r/g; s/\t/\\t/g'
|
||||
}
|
||||
|
||||
# Read POST data
|
||||
read -r QUERY_STRING
|
||||
|
||||
# Extract phone and message from POST data
|
||||
phone=$(echo "$QUERY_STRING" | grep -o 'phone=[^&]*' | cut -d= -f2)
|
||||
message=$(echo "$QUERY_STRING" | grep -o 'message=[^&]*' | cut -d= -f2)
|
||||
|
||||
# URL decode the message
|
||||
decoded_message=$(urldecode "$message")
|
||||
|
||||
# Validate inputs
|
||||
if [ -z "$phone" ] || [ -z "$message" ]; then
|
||||
echo '{"success":false,"error":"Phone number and message are required"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Validate phone number (only numbers allowed)
|
||||
if ! echo "$phone" | grep -q '^[0-9]\+$'; then
|
||||
echo '{"success":false,"error":"Invalid phone number format"}'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Try to send SMS and capture output
|
||||
result=$(sms_tool send "$phone" "$decoded_message" 2>&1)
|
||||
escaped_result=$(escape_json "$result")
|
||||
|
||||
# Check if SMS was sent successfully by looking for "sms sent sucessfully"
|
||||
if echo "$result" | grep -q "sms sent sucessfully"; then
|
||||
# Extract the message ID if present
|
||||
message_id=$(echo "$result" | grep -o '[0-9]*$')
|
||||
echo "{\"success\":true,\"message\":\"SMS sent successfully\",\"messageId\":\"$message_id\",\"raw\":\"$escaped_result\"}"
|
||||
elif echo "$result" | grep -q "sms not sent, code 350"; then
|
||||
# Kill any hanging sms_tool process
|
||||
pkill -f "sms_tool send"
|
||||
echo '{"success":false,"error":"No prepaid credit available"}'
|
||||
else
|
||||
# Kill any hanging sms_tool process
|
||||
pkill -f "sms_tool send"
|
||||
echo "{\"success\":false,\"error\":\"Failed to send SMS\",\"raw\":\"$escaped_result\"}"
|
||||
fi
|
||||
Reference in New Issue
Block a user