initial test release for quecmanager-beta
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set content type for JSON response
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Check if the file exists
|
||||
if [ -f "/etc/config/atcommands.user" ]; then
|
||||
# Start JSON object
|
||||
printf "{\n"
|
||||
awk -F';' '
|
||||
BEGIN { first = 1 }
|
||||
{
|
||||
gsub(/\r/, "", $0)
|
||||
if (!first) printf ",\n "
|
||||
else printf " "
|
||||
gsub(/"/, "\\\"", $1)
|
||||
gsub(/"/, "\\\"", $2)
|
||||
printf "\"%s\": \"%s\"", $1, $2
|
||||
first = 0
|
||||
}
|
||||
' /etc/config/atcommands.user
|
||||
printf "\n}"
|
||||
else
|
||||
echo '{"error": "No Data"}'
|
||||
fi
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Create a temporary file to store the processed data
|
||||
temp_file=$(mktemp)
|
||||
|
||||
# Process ARP entries and store in temporary file
|
||||
arp -a | while IFS= read -r line; do
|
||||
if [ -n "$line" ]; then
|
||||
# Extract hostname (or IP if hostname is "?"), IP, and MAC
|
||||
hostname=$(echo "$line" | awk '{print $1}')
|
||||
ip=$(echo "$line" | awk -F '[()]' '{print $2}')
|
||||
mac=$(echo "$line" | awk '{print $4}')
|
||||
|
||||
# Skip entries without valid MAC addresses
|
||||
if [ "$mac" = "<incomplete>" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# If hostname is "?", use the IP address instead
|
||||
if [ "$hostname" = "?" ]; then
|
||||
hostname="$ip"
|
||||
fi
|
||||
|
||||
# Store each entry in the temp file
|
||||
echo "$hostname:$ip:$mac" >> "$temp_file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Initialize JSON array
|
||||
echo -n "["
|
||||
|
||||
# Process the temporary file to create JSON
|
||||
first=true
|
||||
while IFS=: read -r hostname ip mac; do
|
||||
if [ "$first" = true ]; then
|
||||
first=false
|
||||
else
|
||||
echo -n ","
|
||||
fi
|
||||
echo -n "{\"hostname\":\"$hostname\",\"ip\":\"$ip\",\"mac\":\"$mac\"}"
|
||||
done < "$temp_file"
|
||||
|
||||
# Close the JSON array
|
||||
echo "]"
|
||||
|
||||
# Clean up
|
||||
rm -f "$temp_file"
|
||||
@@ -0,0 +1,94 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
ttl_file="/etc/firewall.user.ttl"
|
||||
lan_utils_script="/etc/data/lanUtils.sh"
|
||||
|
||||
setup_persistent_config() {
|
||||
if [ ! -f "$lan_utils_script" ]; then
|
||||
echo "{\"success\": false, \"error\": \"lanUtils.sh not found\"}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Backup the original script if not already done
|
||||
if [ ! -f "${lan_utils_script}.bak" ]; then
|
||||
cp "$lan_utils_script" "${lan_utils_script}.bak"
|
||||
fi
|
||||
|
||||
# Add the local ttl_firewall_file line if it's not already present
|
||||
if ! grep -q "local ttl_firewall_file" "$lan_utils_script"; then
|
||||
sed -i '/local tcpmss_firewall_filev6/a \ local ttl_firewall_file=/etc/firewall.user.ttl' "$lan_utils_script"
|
||||
fi
|
||||
|
||||
# Add the condition to include the ttl_firewall_file if it's not already present
|
||||
if ! grep -q "if \[ -f \"\$ttl_firewall_file\" \]; then" "$lan_utils_script"; then
|
||||
sed -i '/if \[ -f "\$tcpmss_firewall_filev6" \]; then/i \ if [ -f "\$ttl_firewall_file" ]; then\n cat \$ttl_firewall_file >> \$firewall_file\n fi' "$lan_utils_script"
|
||||
fi
|
||||
}
|
||||
|
||||
clear_existing_rules() {
|
||||
local current_ttl=$1
|
||||
if [ -n "$current_ttl" ]; then
|
||||
iptables -t mangle -D POSTROUTING -o rmnet+ -j TTL --ttl-set "$current_ttl" 2>/dev/null
|
||||
ip6tables -t mangle -D POSTROUTING -o rmnet+ -j HL --hl-set "$current_ttl" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
case "$REQUEST_METHOD" in
|
||||
GET)
|
||||
# Ensure consistent JSON format for GET requests
|
||||
if [ -s "$ttl_file" ]; then
|
||||
ttl_value=$(grep 'iptables -t mangle -A POSTROUTING' "$ttl_file" | awk '{for(i=1;i<=NF;i++){if($i=="--ttl-set"){print $(i+1)}}}')
|
||||
# Ensure ttl_value is a number, default to 0 if not
|
||||
if ! [[ "$ttl_value" =~ ^[0-9]+$ ]]; then
|
||||
ttl_value=0
|
||||
fi
|
||||
echo "{\"isEnabled\": true, \"currentValue\": $ttl_value}"
|
||||
else
|
||||
echo "{\"isEnabled\": false, \"currentValue\": 0}"
|
||||
fi
|
||||
;;
|
||||
POST)
|
||||
read -r post_data
|
||||
ttl_value=$(echo "$post_data" | sed 's/ttl=//')
|
||||
|
||||
# Ensure ttl_file exists
|
||||
touch "$ttl_file" 2>/dev/null
|
||||
if [ ! -f "$ttl_file" ]; then
|
||||
echo "{\"success\": false, \"error\": \"Cannot create TTL file\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Setup persistent configuration
|
||||
setup_persistent_config
|
||||
|
||||
# Get current TTL value for cleanup
|
||||
current_ttl=$(grep 'iptables -t mangle -A POSTROUTING' "$ttl_file" | awk '{for(i=1;i<=NF;i++){if($i=="--ttl-set"){print $(i+1)}}}')
|
||||
|
||||
if ! [[ "$ttl_value" =~ ^[0-9]+$ ]]; then
|
||||
echo "{\"success\": false, \"error\": \"Invalid TTL value\"}"
|
||||
elif [ "$ttl_value" = "0" ]; then
|
||||
clear_existing_rules "$current_ttl"
|
||||
> "$ttl_file"
|
||||
echo "{\"success\": true}"
|
||||
else
|
||||
# Clear existing rules
|
||||
clear_existing_rules "$current_ttl"
|
||||
|
||||
# Set new rules
|
||||
echo "iptables -t mangle -A POSTROUTING -o rmnet+ -j TTL --ttl-set $ttl_value" > "$ttl_file"
|
||||
echo "ip6tables -t mangle -A POSTROUTING -o rmnet+ -j HL --hl-set $ttl_value" >> "$ttl_file"
|
||||
|
||||
# Apply the rules
|
||||
iptables -t mangle -A POSTROUTING -o rmnet+ -j TTL --ttl-set "$ttl_value"
|
||||
ip6tables -t mangle -A POSTROUTING -o rmnet+ -j HL --hl-set "$ttl_value"
|
||||
|
||||
echo "{\"success\": true}"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "{\"success\": false, \"error\": \"Invalid request method\"}"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Function to URL-decode the input
|
||||
urldecode() {
|
||||
local data="$1"
|
||||
echo -e "$(echo "$data" | sed 's/+/ /g;s/%\(..\)/\\x\1/g;')"
|
||||
}
|
||||
|
||||
# Set content-type for JSON response
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Read the input from POST data
|
||||
read INPUT_DATA
|
||||
|
||||
# Extract the command from the input data (format: command=AT+COMMAND)
|
||||
RAW_COMMAND=$(echo "$INPUT_DATA" | sed 's/command=//g')
|
||||
|
||||
# URL-decode the command
|
||||
COMMAND=$(urldecode "$RAW_COMMAND")
|
||||
|
||||
# Define unique input/output files and AT port
|
||||
INPUT_FILE="/tmp/custom_input_$$.txt"
|
||||
OUTPUT_FILE="/tmp/custom_output_$$.txt"
|
||||
|
||||
# Debug logging
|
||||
DEBUG_LOG="/tmp/debug.log"
|
||||
echo "Starting at_handler script at $(date)" > "$DEBUG_LOG"
|
||||
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
# Check config file
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Config file not found: $CONFIG_FILE" >> "$DEBUG_LOG"
|
||||
echo '{"error": "Config file not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get AT_PORT with debug logging
|
||||
# Get AT_PORT with debug logging
|
||||
AT_PORT=$(head -n 2 "$CONFIG_FILE" | tail -n 1 | cut -d'=' -f2 | tr -d ' \n\r' | sed 's|^dev/||')
|
||||
echo "Raw config line: $(head -n 1 "$CONFIG_FILE")" >> "$DEBUG_LOG"
|
||||
echo "Extracted AT_PORT: '$AT_PORT'" >> "$DEBUG_LOG"
|
||||
|
||||
# List available devices for debugging
|
||||
ls -l /dev/smd* >> "$DEBUG_LOG" 2>&1
|
||||
|
||||
if [ -z "$AT_PORT" ]; then
|
||||
echo "AT_PORT is empty" >> "$DEBUG_LOG"
|
||||
echo '{"error": "Failed to read AT_PORT from config"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if AT_PORT exists
|
||||
if [ ! -c "/dev/$AT_PORT" ]; then
|
||||
echo "AT_PORT device not found: /dev/$AT_PORT" >> "$DEBUG_LOG"
|
||||
echo "Available smd devices:" >> "$DEBUG_LOG"
|
||||
ls -l /dev/smd* >> "$DEBUG_LOG" 2>&1
|
||||
echo '{"error": "AT_PORT device not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Write the command directly to the input file
|
||||
echo "$COMMAND" > "$INPUT_FILE"
|
||||
|
||||
# Run the command using atinout
|
||||
atinout "$INPUT_FILE" "/dev/$AT_PORT" "$OUTPUT_FILE"
|
||||
|
||||
# Read the output from output.txt
|
||||
OUTPUT=$(cat "$OUTPUT_FILE")
|
||||
|
||||
# Escape special characters (like newlines and double quotes) for JSON compatibility
|
||||
ESCAPED_OUTPUT=$(echo "$OUTPUT" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g')
|
||||
|
||||
# Escape double quotes in the command for JSON compatibility
|
||||
ESCAPED_COMMAND=$(echo "$COMMAND" | sed 's/"/\\"/g')
|
||||
|
||||
# Create the JSON response
|
||||
JSON_RESPONSE=$(printf "{\"command\":\"%s\",\"output\":\"%s\"}" "$ESCAPED_COMMAND" "$ESCAPED_OUTPUT")
|
||||
|
||||
# Log the JSON response to the debug log
|
||||
echo "$JSON_RESPONSE" >> /tmp/cgi_debug.log
|
||||
|
||||
# Return the output as a valid JSON response
|
||||
echo "$JSON_RESPONSE"
|
||||
|
||||
# Clean up temporary files
|
||||
rm "$INPUT_FILE" "$OUTPUT_FILE"
|
||||
45
ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/auth.sh
Normal file
45
ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/auth.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set Content-Type for CGI script
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Read POST data
|
||||
read POST_DATA
|
||||
|
||||
# Debug log for generated hash
|
||||
DEBUG_LOG = "/tmp/auth.log"
|
||||
|
||||
# Extract the password from POST data (URL encoded)
|
||||
USER="root"
|
||||
INPUT_PASSWORD=$(echo "$POST_DATA" | sed -n 's/^.*password=\([^&]*\).*$/\1/p')
|
||||
|
||||
# URL-decode the password (replace + with space and decode %XX)
|
||||
INPUT_PASSWORD=$(echo "$INPUT_PASSWORD" | sed 's/+/ /g;s/%\(..\)/\\x\1/g' | xargs -0 printf "%b")
|
||||
|
||||
# Extract the hashed password from /etc/shadow for the specified user
|
||||
USER_SHADOW_ENTRY=$(grep "^$USER:" /etc/shadow)
|
||||
|
||||
if [ -z "$USER_SHADOW_ENTRY" ]; then
|
||||
echo '{"state":"failed", "message":"User not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the password hash (it's the second field, colon-separated)
|
||||
USER_HASH=$(echo "$USER_SHADOW_ENTRY" | cut -d: -f2)
|
||||
|
||||
# Extract the salt (MD5 uses the $1$ prefix followed by the salt)
|
||||
SALT=$(echo "$USER_HASH" | cut -d'$' -f3)
|
||||
|
||||
# Generate a hash from the input password using the same salt
|
||||
GENERATED_HASH=$(echo "$INPUT_PASSWORD" | openssl passwd -1 -salt "$SALT" -stdin)
|
||||
|
||||
# Log generated hash for debugging
|
||||
echo "Generated hash: $GENERATED_HASH" >> $DEBUG_LOG
|
||||
|
||||
# Compare the generated hash with the one in the shadow file
|
||||
if [ "$GENERATED_HASH" = "$USER_HASH" ]; then
|
||||
echo '{"state":"success"}'
|
||||
else
|
||||
echo '{"state":"failed"}'
|
||||
fi
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Initialize error flag
|
||||
has_error=false
|
||||
error_message=""
|
||||
|
||||
# Function to append to error message
|
||||
append_error() {
|
||||
if [ -z "$error_message" ]; then
|
||||
error_message="$1"
|
||||
else
|
||||
error_message="$error_message; $1"
|
||||
fi
|
||||
has_error=true
|
||||
}
|
||||
|
||||
# Remove the entire quecmanager directory
|
||||
if [ -d "/etc/quecmanager" ]; then
|
||||
rm -rf /etc/quecmanager
|
||||
if [ $? -ne 0 ]; then
|
||||
append_error "Failed to remove quecmanager directory"
|
||||
fi
|
||||
else
|
||||
append_error "quecmanager directory not found"
|
||||
fi
|
||||
|
||||
# Remove the line from rc.local
|
||||
if [ -f "/etc/rc.local" ]; then
|
||||
# Create a temporary file
|
||||
temp_file=$(mktemp)
|
||||
|
||||
# Remove the apnProfiles.sh line and copy to temp file
|
||||
sed '/\/etc\/quecmanager\/apnProfiles.sh/d' /etc/rc.local > "$temp_file"
|
||||
|
||||
# Check if sed command was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
# Replace original file with modified version
|
||||
mv "$temp_file" /etc/rc.local
|
||||
if [ $? -ne 0 ]; then
|
||||
append_error "Failed to update rc.local"
|
||||
fi
|
||||
else
|
||||
append_error "Failed to modify rc.local"
|
||||
rm -f "$temp_file"
|
||||
fi
|
||||
else
|
||||
append_error "rc.local file not found"
|
||||
fi
|
||||
|
||||
# Remove temporary files that might have been created
|
||||
rm -f /tmp/apn_result.txt
|
||||
rm -f /tmp/debug.log
|
||||
rm -f /tmp/inputICCID.txt
|
||||
rm -f /tmp/outputICCID.txt
|
||||
rm -f /tmp/inputAPN.txt
|
||||
rm -f /tmp/outputAPN.txt
|
||||
|
||||
# Return appropriate JSON response
|
||||
if [ "$has_error" = true ]; then
|
||||
echo "{\"status\": \"error\", \"message\": \"$error_message\"}"
|
||||
else
|
||||
echo "{\"status\": \"success\", \"message\": \"APN profiles and configuration successfully removed\"}"
|
||||
fi
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
CONFIG_FILE="/etc/quecmanager/apn_config.txt"
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "{}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Read the configuration file
|
||||
iccidProfile1=$(grep "^iccidProfile1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
apnProfile1=$(grep "^apnProfile1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
pdpType1=$(grep "^pdpType1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
iccidProfile2=$(grep "^iccidProfile2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
apnProfile2=$(grep "^apnProfile2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
pdpType2=$(grep "^pdpType2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
|
||||
# Build the JSON response
|
||||
echo "{"
|
||||
|
||||
# Add Profile 1 if it exists
|
||||
if [ -n "$iccidProfile1" ]; then
|
||||
echo " \"profile1\": {"
|
||||
echo " \"iccid\": \"$iccidProfile1\","
|
||||
echo " \"apn\": \"$apnProfile1\","
|
||||
echo " \"pdpType\": \"$pdpType1\""
|
||||
echo " }"
|
||||
|
||||
# Add comma if Profile 2 exists
|
||||
[ -n "$iccidProfile2" ] && echo " ,"
|
||||
fi
|
||||
|
||||
# Add Profile 2 if it exists
|
||||
if [ -n "$iccidProfile2" ]; then
|
||||
echo " \"profile2\": {"
|
||||
echo " \"iccid\": \"$iccidProfile2\","
|
||||
echo " \"apn\": \"$apnProfile2\","
|
||||
echo " \"pdpType\": \"$pdpType2\""
|
||||
echo " }"
|
||||
fi
|
||||
|
||||
echo "}"
|
||||
@@ -0,0 +1,189 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Parse POST data
|
||||
read -r QUERY_STRING
|
||||
|
||||
# Function to urldecode
|
||||
urldecode() {
|
||||
echo -e "$(echo "$1" | sed 's/+/ /g;s/%\([0-9A-F][0-9A-F]\)/\\x\1/g')"
|
||||
}
|
||||
|
||||
# Extract values from POST data
|
||||
iccidProfile1=$(echo "$QUERY_STRING" | grep -o 'iccidProfile1=[^&]*' | cut -d= -f2)
|
||||
apnProfile1=$(echo "$QUERY_STRING" | grep -o 'apnProfile1=[^&]*' | cut -d= -f2)
|
||||
pdpType1=$(echo "$QUERY_STRING" | grep -o 'pdpType1=[^&]*' | cut -d= -f2)
|
||||
iccidProfile2=$(echo "$QUERY_STRING" | grep -o 'iccidProfile2=[^&]*' | cut -d= -f2)
|
||||
apnProfile2=$(echo "$QUERY_STRING" | grep -o 'apnProfile2=[^&]*' | cut -d= -f2)
|
||||
pdpType2=$(echo "$QUERY_STRING" | grep -o 'pdpType2=[^&]*' | cut -d= -f2)
|
||||
|
||||
# URL decode the values
|
||||
iccidProfile1=$(urldecode "$iccidProfile1")
|
||||
apnProfile1=$(urldecode "$apnProfile1")
|
||||
pdpType1=$(urldecode "$pdpType1")
|
||||
iccidProfile2=$(urldecode "$iccidProfile2")
|
||||
apnProfile2=$(urldecode "$apnProfile2")
|
||||
pdpType2=$(urldecode "$pdpType2")
|
||||
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Validate required first profile
|
||||
if [ -z "$iccidProfile1" ] || [ -z "$apnProfile1" ] || [ -z "$pdpType1" ]; then
|
||||
echo '{"status": "error", "message": "Profile 1 is required"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d /etc/quecmanager ]; then
|
||||
mkdir -p /etc/quecmanager
|
||||
fi
|
||||
|
||||
# Create a configuration file to store APN profiles (as plain text)
|
||||
cat > /etc/quecmanager/apn_config.txt << EOF
|
||||
iccidProfile1=$iccidProfile1
|
||||
apnProfile1=$apnProfile1
|
||||
pdpType1=$pdpType1
|
||||
EOF
|
||||
|
||||
# Add second profile only if ICCID is provided
|
||||
if [ -n "$iccidProfile2" ]; then
|
||||
cat >> /etc/quecmanager/apn_config.txt << EOF
|
||||
iccidProfile2=$iccidProfile2
|
||||
apnProfile2=$apnProfile2
|
||||
pdpType2=$pdpType2
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Create the apnProfiles.sh script
|
||||
cat > /etc/quecmanager/apnProfiles.sh << 'EOF'
|
||||
#!/bin/sh
|
||||
|
||||
# Function to read config values
|
||||
get_config_value() {
|
||||
local key=$1
|
||||
grep "^${key}=" /etc/quecmanager/apn_config.txt | cut -d'=' -f2
|
||||
}
|
||||
|
||||
# Read configuration
|
||||
iccidProfile1=$(get_config_value "iccidProfile1")
|
||||
apnProfile1=$(get_config_value "apnProfile1")
|
||||
pdpType1=$(get_config_value "pdpType1")
|
||||
iccidProfile2=$(get_config_value "iccidProfile2")
|
||||
apnProfile2=$(get_config_value "apnProfile2")
|
||||
pdpType2=$(get_config_value "pdpType2")
|
||||
|
||||
# Debug logging
|
||||
DEBUG_LOG="/tmp/debug.log"
|
||||
echo "Starting script at $(date)" > "$DEBUG_LOG"
|
||||
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
# Check config file
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Config file not found: $CONFIG_FILE" >> "$DEBUG_LOG"
|
||||
echo '{"error": "Config file not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get AT_PORT with debug logging
|
||||
AT_PORT=$(head -n 1 "$CONFIG_FILE" | cut -d'=' -f2 | tr -d ' \n\r' | sed 's|^dev/||')
|
||||
echo "Raw config line: $(head -n 1 "$CONFIG_FILE")" >> "$DEBUG_LOG"
|
||||
echo "Extracted AT_PORT: '$AT_PORT'" >> "$DEBUG_LOG"
|
||||
|
||||
# List available devices for debugging
|
||||
ls -l /dev/smd* >> "$DEBUG_LOG" 2>&1
|
||||
|
||||
if [ -z "$AT_PORT" ]; then
|
||||
echo "AT_PORT is empty" >> "$DEBUG_LOG"
|
||||
echo '{"error": "Failed to read AT_PORT from config"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if AT_PORT exists
|
||||
if [ ! -c "/dev/$AT_PORT" ]; then
|
||||
echo "AT_PORT device not found: /dev/$AT_PORT" >> "$DEBUG_LOG"
|
||||
echo "Available smd devices:" >> "$DEBUG_LOG"
|
||||
ls -l /dev/smd* >> "$DEBUG_LOG" 2>&1
|
||||
echo '{"error": "AT_PORT device not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to get current ICCID
|
||||
get_current_iccid() {
|
||||
local input_file="/tmp/inputICCID.txt"
|
||||
local output_file="/tmp/outputICCID.txt"
|
||||
|
||||
echo "AT+ICCID" > "$input_file"
|
||||
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
|
||||
|
||||
iccid=$(cat "$output_file" | grep "+ICCID:" | cut -d' ' -f2)
|
||||
|
||||
rm -f "$input_file" "$output_file"
|
||||
echo "$iccid"
|
||||
}
|
||||
|
||||
# Function to set APN
|
||||
set_apn() {
|
||||
local pdp_type="$1"
|
||||
local apn="$2"
|
||||
local input_file="/tmp/inputAPN.txt"
|
||||
local output_file="/tmp/outputAPN.txt"
|
||||
|
||||
echo "AT+CGDCONT=1,\"$pdp_type\",\"$apn\";+COPS=2;+COPS=0" > "$input_file"
|
||||
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
|
||||
|
||||
local result=$(cat "$output_file")
|
||||
rm -f "$input_file" "$output_file"
|
||||
|
||||
if echo "$result" | grep -q "OK"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get current ICCID
|
||||
current_iccid=$(get_current_iccid)
|
||||
success=false
|
||||
|
||||
# Check ICCID against profile 1 (required)
|
||||
if [ "$current_iccid" = "$iccidProfile1" ]; then
|
||||
if set_apn "$pdpType1" "$apnProfile1"; then
|
||||
success=true
|
||||
fi
|
||||
# Check ICCID against profile 2 (optional)
|
||||
elif [ -n "$iccidProfile2" ] && [ "$current_iccid" = "$iccidProfile2" ]; then
|
||||
if set_apn "$pdpType2" "$apnProfile2"; then
|
||||
success=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$success" = "true" ]; then
|
||||
echo "APN set successfully" > /tmp/apn_result.txt
|
||||
else
|
||||
echo "Failed to set APN" > /tmp/apn_result.txt
|
||||
fi
|
||||
EOF
|
||||
|
||||
# Make the script executable
|
||||
chmod +x /etc/quecmanager/apnProfiles.sh
|
||||
|
||||
# Add to rc.local if not already present
|
||||
if ! grep -q "/etc/quecmanager/apnProfiles.sh" /etc/rc.local; then
|
||||
sed -i '/^exit 0/i /etc/quecmanager/apnProfiles.sh' /etc/rc.local
|
||||
fi
|
||||
|
||||
# Run the script immediately
|
||||
/etc/quecmanager/apnProfiles.sh
|
||||
|
||||
# Check the result
|
||||
if [ -f /tmp/apn_result.txt ]; then
|
||||
result=$(cat /tmp/apn_result.txt)
|
||||
rm -f /tmp/apn_result.txt
|
||||
|
||||
if [ "$result" = "APN set successfully" ]; then
|
||||
echo '{"status": "success", "message": "APN profiles saved and applied successfully"}'
|
||||
else
|
||||
echo '{"status": "error", "message": "APN profiles saved but failed to apply"}'
|
||||
fi
|
||||
else
|
||||
echo '{"status": "error", "message": "Something went wrong while processing APN profiles"}'
|
||||
fi
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Initialize error flag
|
||||
has_error=false
|
||||
error_message=""
|
||||
|
||||
# Function to append to error message
|
||||
append_error() {
|
||||
if [ -z "$error_message" ]; then
|
||||
error_message="$1"
|
||||
else
|
||||
error_message="$error_message; $1"
|
||||
fi
|
||||
has_error=true
|
||||
}
|
||||
|
||||
# Remove the entire quecmanager directory
|
||||
if [ -d "/etc/quecmanager" ]; then
|
||||
rm -rf /etc/quecmanager
|
||||
if [ $? -ne 0 ]; then
|
||||
append_error "Failed to remove quecmanager directory"
|
||||
fi
|
||||
else
|
||||
append_error "quecmanager directory not found"
|
||||
fi
|
||||
|
||||
# Remove the line from rc.local
|
||||
if [ -f "/etc/rc.local" ]; then
|
||||
# Create a temporary file
|
||||
temp_file=$(mktemp)
|
||||
|
||||
# Remove the imeiProfiles.sh line and copy to temp file
|
||||
sed '/\/etc\/quecmanager\/imeiProfiles.sh/d' /etc/rc.local > "$temp_file"
|
||||
|
||||
# Check if sed command was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
# Replace original file with modified version
|
||||
mv "$temp_file" /etc/rc.local
|
||||
if [ $? -ne 0 ]; then
|
||||
append_error "Failed to update rc.local"
|
||||
fi
|
||||
else
|
||||
append_error "Failed to modify rc.local"
|
||||
rm -f "$temp_file"
|
||||
fi
|
||||
else
|
||||
append_error "rc.local file not found"
|
||||
fi
|
||||
|
||||
# Remove temporary files that might have been created
|
||||
rm -f /tmp/imei_result.txt
|
||||
rm -f /tmp/debug.log
|
||||
rm -f /tmp/inputICCID.txt
|
||||
rm -f /tmp/outputICCID.txt
|
||||
rm -f /tmp/inputIMEI.txt
|
||||
rm -f /tmp/outputIMEI.txt
|
||||
|
||||
# Return appropriate JSON response
|
||||
if [ "$has_error" = true ]; then
|
||||
echo "{\"status\": \"error\", \"message\": \"$error_message\"}"
|
||||
else
|
||||
echo "{\"status\": \"success\", \"message\": \"IMEI profiles and configuration successfully removed\"}"
|
||||
fi
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
CONFIG_FILE="/etc/quecmanager/imei_config.txt"
|
||||
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "{}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Read the configuration file
|
||||
iccidProfile1=$(grep "^iccidProfile1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
imeiProfile1=$(grep "^imeiProfile1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
iccidProfile2=$(grep "^iccidProfile2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
imeiProfile2=$(grep "^imeiProfile2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
|
||||
# Build the JSON response
|
||||
echo "{"
|
||||
|
||||
# Add Profile 1 if it exists
|
||||
if [ -n "$iccidProfile1" ]; then
|
||||
echo " \"profile1\": {"
|
||||
echo " \"iccid\": \"$iccidProfile1\","
|
||||
echo " \"imei\": \"$imeiProfile1\""
|
||||
echo " }"
|
||||
# Add comma if Profile 2 exists
|
||||
[ -n "$iccidProfile2" ] && echo " ,"
|
||||
fi
|
||||
|
||||
# Add Profile 2 if it exists
|
||||
if [ -n "$iccidProfile2" ]; then
|
||||
echo " \"profile2\": {"
|
||||
echo " \"iccid\": \"$iccidProfile2\","
|
||||
echo " \"imei\": \"$imeiProfile2\""
|
||||
echo " }"
|
||||
fi
|
||||
|
||||
echo "}"
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Parse POST data
|
||||
read -r QUERY_STRING
|
||||
|
||||
# Function to urldecode
|
||||
urldecode() {
|
||||
echo -e "$(echo "$1" | sed 's/+/ /g;s/%\([0-9A-F][0-9A-F]\)/\\x\1/g')"
|
||||
}
|
||||
|
||||
# Extract values from POST data
|
||||
iccidProfile1=$(echo "$QUERY_STRING" | grep -o 'iccidProfile1=[^&]*' | cut -d= -f2)
|
||||
imeiProfile1=$(echo "$QUERY_STRING" | grep -o 'imeiProfile1=[^&]*' | cut -d= -f2)
|
||||
iccidProfile2=$(echo "$QUERY_STRING" | grep -o 'iccidProfile2=[^&]*' | cut -d= -f2)
|
||||
imeiProfile2=$(echo "$QUERY_STRING" | grep -o 'imeiProfile2=[^&]*' | cut -d= -f2)
|
||||
|
||||
# URL decode the values
|
||||
iccidProfile1=$(urldecode "$iccidProfile1")
|
||||
imeiProfile1=$(urldecode "$imeiProfile1")
|
||||
iccidProfile2=$(urldecode "$iccidProfile2")
|
||||
imeiProfile2=$(urldecode "$imeiProfile2")
|
||||
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Validate required first profile
|
||||
if [ -z "$iccidProfile1" ] || [ -z "$imeiProfile1" ]; then
|
||||
echo '{"status": "error", "message": "Profile 1 is required"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check the directory if it exists, if not create it
|
||||
if [ ! -d /etc/quecmanager ]; then
|
||||
mkdir -p /etc/quecmanager
|
||||
fi
|
||||
|
||||
# Create a configuration file to store IMEI profiles
|
||||
cat > /etc/quecmanager/imei_config.txt << EOF
|
||||
iccidProfile1=$iccidProfile1
|
||||
imeiProfile1=$imeiProfile1
|
||||
EOF
|
||||
|
||||
# Add second profile only if ICCID is provided
|
||||
if [ -n "$iccidProfile2" ]; then
|
||||
cat >> /etc/quecmanager/imei_config.txt << EOF
|
||||
iccidProfile2=$iccidProfile2
|
||||
imeiProfile2=$imeiProfile2
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Create the imeiProfiles.sh script
|
||||
cat > /etc/quecmanager/imeiProfiles.sh << 'EOF'
|
||||
#!/bin/sh
|
||||
|
||||
# Function to read config values
|
||||
get_config_value() {
|
||||
local key=$1
|
||||
grep "^${key}=" /etc/quecmanager/imei_config.txt | cut -d'=' -f2
|
||||
}
|
||||
|
||||
# Read configuration
|
||||
iccidProfile1=$(get_config_value "iccidProfile1")
|
||||
imeiProfile1=$(get_config_value "imeiProfile1")
|
||||
iccidProfile2=$(get_config_value "iccidProfile2")
|
||||
imeiProfile2=$(get_config_value "imeiProfile2")
|
||||
|
||||
# Debug logging
|
||||
DEBUG_LOG="/tmp/debug.log"
|
||||
echo "Starting IMEI profile script at $(date)" > "$DEBUG_LOG"
|
||||
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
# Check config file
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Config file not found: $CONFIG_FILE" >> "$DEBUG_LOG"
|
||||
echo '{"error": "Config file not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get AT_PORT with debug logging
|
||||
AT_PORT=$(head -n 1 "$CONFIG_FILE" | cut -d'=' -f2 | tr -d ' \n\r' | sed 's|^dev/||')
|
||||
echo "Raw config line: $(head -n 1 "$CONFIG_FILE")" >> "$DEBUG_LOG"
|
||||
echo "Extracted AT_PORT: '$AT_PORT'" >> "$DEBUG_LOG"
|
||||
|
||||
if [ -z "$AT_PORT" ]; then
|
||||
echo "AT_PORT is empty" >> "$DEBUG_LOG"
|
||||
echo '{"error": "Failed to read AT_PORT from config"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if AT_PORT exists
|
||||
if [ ! -c "/dev/$AT_PORT" ]; then
|
||||
echo "AT_PORT device not found: /dev/$AT_PORT" >> "$DEBUG_LOG"
|
||||
echo '{"error": "AT_PORT device not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to get current ICCID
|
||||
get_current_iccid() {
|
||||
local input_file="/tmp/inputICCID.txt"
|
||||
local output_file="/tmp/outputICCID.txt"
|
||||
|
||||
echo "AT+ICCID" > "$input_file"
|
||||
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
|
||||
|
||||
iccid=$(cat "$output_file" | grep "+ICCID:" | cut -d' ' -f2)
|
||||
|
||||
rm -f "$input_file" "$output_file"
|
||||
echo "$iccid"
|
||||
}
|
||||
|
||||
# Function to set IMEI
|
||||
set_imei() {
|
||||
local imei="$1"
|
||||
local input_file="/tmp/inputIMEI.txt"
|
||||
local output_file="/tmp/outputIMEI.txt"
|
||||
|
||||
echo "AT+EGMR=1,7,\"$imei\";+QPOWD=1" > "$input_file"
|
||||
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
|
||||
|
||||
local result=$(cat "$output_file")
|
||||
rm -f "$input_file" "$output_file"
|
||||
|
||||
if echo "$result" | grep -q "OK"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Get current ICCID
|
||||
current_iccid=$(get_current_iccid)
|
||||
success=false
|
||||
|
||||
# Check ICCID against profile 1 (required)
|
||||
if [ "$current_iccid" = "$iccidProfile1" ]; then
|
||||
if set_imei "$imeiProfile1"; then
|
||||
success=true
|
||||
fi
|
||||
# Check ICCID against profile 2 (optional)
|
||||
elif [ -n "$iccidProfile2" ] && [ "$current_iccid" = "$iccidProfile2" ]; then
|
||||
if set_imei "$imeiProfile2"; then
|
||||
success=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$success" = "true" ]; then
|
||||
echo "IMEI set successfully" > /tmp/imei_result.txt
|
||||
else
|
||||
echo "Failed to set IMEI" > /tmp/imei_result.txt
|
||||
fi
|
||||
EOF
|
||||
|
||||
# Make the script executable
|
||||
chmod +x /etc/quecmanager/imeiProfiles.sh
|
||||
|
||||
# Add to rc.local if not already present
|
||||
if ! grep -q "/etc/quecmanager/imeiProfiles.sh" /etc/rc.local; then
|
||||
sed -i '/^exit 0/i /etc/quecmanager/imeiProfiles.sh' /etc/rc.local
|
||||
fi
|
||||
|
||||
# Run the script immediately
|
||||
/etc/quecmanager/imeiProfiles.sh
|
||||
|
||||
# Check the result
|
||||
if [ -f /tmp/imei_result.txt ]; then
|
||||
result=$(cat /tmp/imei_result.txt)
|
||||
rm -f /tmp/imei_result.txt
|
||||
|
||||
if [ "$result" = "IMEI set successfully" ]; then
|
||||
echo '{"status": "success", "message": "IMEI profiles saved and applied successfully"}'
|
||||
else
|
||||
echo '{"status": "error", "message": "IMEI profiles saved but failed to apply"}'
|
||||
fi
|
||||
else
|
||||
echo '{"status": "error", "message": "Something went wrong while processing IMEI profiles"}'
|
||||
fi
|
||||
@@ -0,0 +1,141 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set content-type for JSON response
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Function to output error in JSON format
|
||||
output_error() {
|
||||
echo "{\"error\": \"$1\"}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Define command sets
|
||||
define_command_sets() {
|
||||
COMMAND_SET_1='AT+QUIMSLOT? AT+CNUM AT+COPS? AT+CIMI AT+ICCID AT+CGSN AT+CPIN? AT+CGDCONT? AT+CREG? AT+CFUN? AT+QENG="servingcell" AT+QTEMP AT+CGCONTRDP AT+QCAINFO AT+QRSRP AT+QMAP="WWAN" AT+C5GREG=2;+C5GREG? AT+CGREG=2;+CGREG? AT+QRSRQ AT+QSINR'
|
||||
|
||||
COMMAND_SET_2='AT+CGDCONT? AT+CGCONTRDP AT+QNWPREFCFG="mode_pref" AT+QNWPREFCFG="nr5g_disable_mode" AT+QUIMSLOT?'
|
||||
|
||||
COMMAND_SET_3='AT+CGMI AT+CGMM AT+QGMR AT+CNUM AT+CIMI AT+ICCID AT+CGSN AT+QMAP="LANIP" AT+QMAP="WWAN" AT+QGETCAPABILITY'
|
||||
|
||||
COMMAND_SET_4='AT+QMAP="MPDN_RULE" AT+QMAP="DHCPV4DNS" AT+QCFG="usbnet"'
|
||||
|
||||
COMMAND_SET_5='AT+QRSRP AT+QRSRQ AT+QSINR AT+QCAINFO AT+QSPN'
|
||||
|
||||
COMMAND_SET_6='AT+CEREG=2;+CEREG? AT+C5GREG=2;+C5GREG? AT+CPIN? AT+CGDCONT? AT+CGCONTRDP AT+QMAP="WWAN" AT+QRSRP AT+QTEMP AT+QNETRC?'
|
||||
}
|
||||
|
||||
# Define the lock file
|
||||
LOCK_FILE="/tmp/home_data.lock"
|
||||
|
||||
# Acquire the lock (wait if needed)
|
||||
exec 200>$LOCK_FILE
|
||||
flock -x 200 || output_error "Unable to acquire lock"
|
||||
|
||||
# Temporary files for input/output and AT port
|
||||
INPUT_FILE="/tmp/input_$$.txt"
|
||||
OUTPUT_FILE="/tmp/output_$$.txt"
|
||||
|
||||
# Debug logging
|
||||
DEBUG_LOG="/tmp/debug.log"
|
||||
echo "Starting script at $(date)" > "$DEBUG_LOG"
|
||||
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
# Check config file
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo "Config file not found: $CONFIG_FILE" >> "$DEBUG_LOG"
|
||||
output_error "Config file not found"
|
||||
fi
|
||||
|
||||
# Get AT_PORT with debug logging
|
||||
AT_PORT=$(head -n 1 "$CONFIG_FILE" | cut -d'=' -f2 | tr -d ' \n\r' | sed 's|^dev/||')
|
||||
echo "Raw config line: $(head -n 1 "$CONFIG_FILE")" >> "$DEBUG_LOG"
|
||||
echo "Extracted AT_PORT: '$AT_PORT'" >> "$DEBUG_LOG"
|
||||
|
||||
if [ -z "$AT_PORT" ]; then
|
||||
echo "AT_PORT is empty" >> "$DEBUG_LOG"
|
||||
output_error "Failed to read AT_PORT from config"
|
||||
fi
|
||||
|
||||
# Check if AT_PORT exists
|
||||
if [ ! -c "/dev/$AT_PORT" ]; then
|
||||
echo "AT_PORT device not found: /dev/$AT_PORT" >> "$DEBUG_LOG"
|
||||
echo "Available smd devices:" >> "$DEBUG_LOG"
|
||||
ls -l /dev/smd* >> "$DEBUG_LOG" 2>&1
|
||||
output_error "AT_PORT device not found"
|
||||
fi
|
||||
|
||||
# Function to escape JSON strings (handling quotes and newlines)
|
||||
escape_json() {
|
||||
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
|
||||
}
|
||||
|
||||
# Function to process AT commands
|
||||
process_commands() {
|
||||
local commands="$1"
|
||||
local json_response="["
|
||||
|
||||
for cmd in $commands; do
|
||||
echo "Processing command: $cmd" >> "$DEBUG_LOG"
|
||||
|
||||
# Write the command to the input file
|
||||
echo "$cmd" > "$INPUT_FILE"
|
||||
|
||||
# Run the command using atinout with full path to device
|
||||
if ! atinout "$INPUT_FILE" "/dev/$AT_PORT" "$OUTPUT_FILE" 2>> "$DEBUG_LOG"; then
|
||||
echo "Command failed: $cmd" >> "$DEBUG_LOG"
|
||||
OUTPUT="Error executing command"
|
||||
elif [ ! -f "$OUTPUT_FILE" ]; then
|
||||
echo "Output file not created for command: $cmd" >> "$DEBUG_LOG"
|
||||
OUTPUT="No output file"
|
||||
else
|
||||
OUTPUT=$(cat "$OUTPUT_FILE" 2>> "$DEBUG_LOG" || echo "Error reading output")
|
||||
echo "Command output: $OUTPUT" >> "$DEBUG_LOG"
|
||||
fi
|
||||
|
||||
# Escape special characters for JSON
|
||||
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
|
||||
|
||||
# Append the response
|
||||
json_response="${json_response}{\"response\":\"$ESCAPED_OUTPUT\"},"
|
||||
done
|
||||
|
||||
# Remove the trailing comma and close the JSON array
|
||||
if [ "${json_response: -1}" = "," ]; then
|
||||
json_response="${json_response%,}]"
|
||||
else
|
||||
json_response="${json_response}]"
|
||||
fi
|
||||
|
||||
echo "$json_response"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
define_command_sets
|
||||
|
||||
# Get command set from query string
|
||||
COMMAND_SET=$(echo "$QUERY_STRING" | grep -o 'set=[1-6]' | cut -d'=' -f2)
|
||||
|
||||
# Select the appropriate command set
|
||||
case "$COMMAND_SET" in
|
||||
1) COMMANDS="$COMMAND_SET_1";;
|
||||
2) COMMANDS="$COMMAND_SET_2";;
|
||||
3) COMMANDS="$COMMAND_SET_3";;
|
||||
4) COMMANDS="$COMMAND_SET_4";;
|
||||
5) COMMANDS="$COMMAND_SET_5";;
|
||||
6) COMMANDS="$COMMAND_SET_6";;
|
||||
*) COMMANDS="$COMMAND_SET_1";; # Default to set 1 if no valid set specified
|
||||
esac
|
||||
|
||||
# Process the selected commands and output the response
|
||||
JSON_RESPONSE=$(process_commands "$COMMANDS")
|
||||
echo "$JSON_RESPONSE" >> "$DEBUG_LOG"
|
||||
echo "$JSON_RESPONSE"
|
||||
|
||||
# Clean up temporary files
|
||||
rm -f "$INPUT_FILE" "$OUTPUT_FILE"
|
||||
|
||||
# Release the lock
|
||||
flock -u 200
|
||||
|
||||
echo "Script completed at $(date)" >> "$DEBUG_LOG"
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set the content type to JSON
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Ping 8.8.8.8 with 5 packets and capture the result
|
||||
if ping -c 5 8.8.8.8 > /dev/null 2>&1; then
|
||||
# Ping was successful
|
||||
echo '{"connection": "ACTIVE"}'
|
||||
else
|
||||
# Ping failed
|
||||
echo '{"connection": "INACTIVE"}'
|
||||
fi
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Set Content-Type for CGI script
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Read POST data
|
||||
read POST_DATA
|
||||
|
||||
# Debug log
|
||||
DEBUG_LOG="/tmp/password_change.log"
|
||||
|
||||
# Extract the passwords from POST data
|
||||
OLD_PASSWORD=$(echo "$POST_DATA" | sed -n 's/^.*oldPassword=\([^&]*\).*$/\1/p')
|
||||
NEW_PASSWORD=$(echo "$POST_DATA" | sed -n 's/^.*newPassword=\([^&]*\).*$/\1/p')
|
||||
|
||||
# URL-decode the passwords
|
||||
OLD_PASSWORD=$(echo "$OLD_PASSWORD" | sed 's/+/ /g;s/%\(..\)/\\x\1/g' | xargs -0 printf "%b")
|
||||
NEW_PASSWORD=$(echo "$NEW_PASSWORD" | sed 's/+/ /g;s/%\(..\)/\\x\1/g' | xargs -0 printf "%b")
|
||||
|
||||
# User to change password for
|
||||
USER="root"
|
||||
|
||||
# Verify old password first
|
||||
USER_SHADOW_ENTRY=$(grep "^$USER:" /etc/shadow)
|
||||
if [ -z "$USER_SHADOW_ENTRY" ]; then
|
||||
echo '{"state":"failed", "message":"User not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract current password hash and salt
|
||||
USER_HASH=$(echo "$USER_SHADOW_ENTRY" | cut -d: -f2)
|
||||
SALT=$(echo "$USER_HASH" | cut -d'$' -f3)
|
||||
|
||||
# Generate hash from old password
|
||||
OLD_GENERATED_HASH=$(echo "$OLD_PASSWORD" | openssl passwd -1 -salt "$SALT" -stdin)
|
||||
|
||||
# Verify old password
|
||||
if [ "$OLD_GENERATED_HASH" != "$USER_HASH" ]; then
|
||||
echo '{"state":"failed", "message":"Current password is incorrect"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Change password using passwd command
|
||||
# We need to pass both the new password and its confirmation
|
||||
(echo "$NEW_PASSWORD"; echo "$NEW_PASSWORD") | passwd $USER 2>> $DEBUG_LOG
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '{"state":"success", "message":"Password changed successfully"}'
|
||||
else
|
||||
echo '{"state":"failed", "message":"Failed to change password"}'
|
||||
fi
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
# Set the content type to JSON
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Configuration file path
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
|
||||
# Check if the config file exists
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
echo '{"error": "Configuration file not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Initialize variables
|
||||
AT_PORT=""
|
||||
AT_PORT_CUSTOM=""
|
||||
DATA_REFRESH_RATE=""
|
||||
|
||||
# Read the config file line by line and extract values
|
||||
while IFS='=' read -r key value; do
|
||||
# Remove leading/trailing whitespace
|
||||
key=$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
value=$(echo "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
|
||||
case "$key" in
|
||||
"AT_port") AT_PORT="$value" ;;
|
||||
"AT_port_custom") AT_PORT_CUSTOM="$value" ;;
|
||||
"data_refresh_rate") DATA_REFRESH_RATE="$value" ;;
|
||||
esac
|
||||
done <"$CONFIG_FILE"
|
||||
|
||||
# Output JSON
|
||||
echo "{"
|
||||
echo " \"AT_port\": \"$AT_PORT\","
|
||||
echo " \"AT_port_custom\": \"$AT_PORT_CUSTOM\","
|
||||
echo " \"data_refresh_rate\": $DATA_REFRESH_RATE"
|
||||
echo "}"
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# save-config.sh
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
|
||||
# Read POST data
|
||||
read -n $CONTENT_LENGTH POST_DATA
|
||||
|
||||
# Configuration file path
|
||||
CONFIG_FILE="/etc/quecManager.conf"
|
||||
|
||||
# Parse JSON input and update config file
|
||||
AT_PORT=$(echo "$POST_DATA" | grep -o '"AT_port":"[^"]*"' | cut -d'"' -f4)
|
||||
AT_PORT_CUSTOM=$(echo "$POST_DATA" | grep -o '"AT_port_custom":"[^"]*"' | cut -d'"' -f4)
|
||||
DATA_REFRESH_RATE=$(echo "$POST_DATA" | grep -o '"data_refresh_rate":"[^"]*"' | cut -d'"' -f4)
|
||||
|
||||
# Create new config content
|
||||
cat > "$CONFIG_FILE" << EOF
|
||||
AT_port = $AT_PORT
|
||||
AT_port_custom = $AT_PORT_CUSTOM
|
||||
data_refresh_rate = $DATA_REFRESH_RATE
|
||||
EOF
|
||||
|
||||
# Check if write was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '{"success": true, "message": "Configuration saved successfully"}'
|
||||
else
|
||||
echo '{"success": false, "error": "Failed to save configuration"}'
|
||||
fi
|
||||
Reference in New Issue
Block a user