QuecManger 1.0.0

Release Notes:

Enhanced Web App Architecture:

- Optimized the structure for better scalability and maintainability.

- Refined Data Fetching Logic:
Improved the efficiency and reliability of data retrieval processes.

- Optimized AT Terminal: Enhanced functionality for smoother interaction with AT commands.

- Revamped UI/UX Design: Streamlined user interface and experience for improved accessibility and usability.

New Features:

- MTU Settings: Added customizable Maximum Transmission Unit (MTU) settings.

- APN and IMEI Profiles: Introduced the ability to configure APN and IMEI profiles for better device management.

- Persistent Cell Locking: Added native support for persistent cell locking, ensuring consistent network connections.

- QuecWatch: Connection monitoring with auto reconnect and reboot settable

Co-Authored-By: Russel Yasol <73575327+dr-dolomite@users.noreply.github.com>
This commit is contained in:
Cameron Thompson
2024-12-11 23:11:41 -05:00
parent 46f8e1af8b
commit bb4d75f560
271 changed files with 1791 additions and 108040 deletions

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in 'AT+CGMI' 'AT+CGMM' 'AT+CGMR' 'AT+CNUM' 'AT+CIMI' 'AT+ICCID' 'AT+CGSN' 'AT+QMAP="LANIP"' 'AT+QMAP="WWAN"' 'AT+QGETCAPABILITY'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in 'AT+QMAP="MPDN_RULE"' 'AT+QMAP="DHCPV4DNS"' 'AT+QCFG="usbnet"'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -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

View File

@@ -0,0 +1,90 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
mtu_firewall_file="/etc/firewall.user.mtu"
network_interface="rmnet_data0"
lan_utils_script="/etc/data/lanUtils.sh"
get_current_mtu() {
ip link show "$network_interface" | grep -o "mtu [0-9]*" | cut -d' ' -f2
}
update_lanutils_mtu_config() {
local action="$1"
if [ "$action" = "add" ]; then
# Add the MTU firewall file line if not already present
if ! grep -q "local mtu_firewall_file=/etc/firewall.user.mtu" "$lan_utils_script"; then
sed -i '/local ttl_firewall_file=\/etc\/firewall.user.ttl/a local mtu_firewall_file=/etc/firewall.user.mtu' "$lan_utils_script"
fi
elif [ "$action" = "remove" ]; then
# Remove the MTU firewall file line if present
sed -i '/local mtu_firewall_file=\/etc\/firewall.user.mtu/d' "$lan_utils_script"
fi
}
case "$REQUEST_METHOD" in
GET)
# Fetch current MTU
current_mtu=$(get_current_mtu)
current_mtu=${current_mtu:-1500}
# Check if custom MTU is configured
if [ -f "$mtu_firewall_file" ]; then
echo "{\"isEnabled\": true, \"currentValue\": $current_mtu}"
else
echo "{\"isEnabled\": false, \"currentValue\": $current_mtu}"
fi
;;
POST)
read -r post_data
mtu_value=$(echo "$post_data" | sed 's/mtu=//')
# Check for disable functionality
if [ "$mtu_value" = "disable" ]; then
# Remove the MTU configuration file
rm -f "$mtu_firewall_file"
# Remove the MTU configuration line from lanUtils.sh
update_lanutils_mtu_config "remove"
# Get the default MTU
default_mtu=$(get_current_mtu)
default_mtu=${default_mtu:-1500}
echo "{\"success\": true, \"message\": \"MTU configuration disabled\", \"currentValue\": $default_mtu}"
exit 0
fi
# Validate MTU input
if ! [[ "$mtu_value" =~ ^[0-9]+$ ]]; then
echo "{\"success\": false, \"error\": \"Invalid MTU value\"}"
exit 1
fi
# Create firewall MTU configuration file with individual interface commands
> "$mtu_firewall_file" # Clear the file
for iface in $(ls /sys/class/net | grep '^rmnet_data'); do
echo "ip link set $iface mtu $mtu_value" >> "$mtu_firewall_file"
done
# Immediately apply MTU change
for iface in $(ls /sys/class/net | grep '^rmnet_data'); do
ip link set "$iface" mtu "$mtu_value"
done
# Add the MTU configuration line to lanUtils.sh
update_lanutils_mtu_config "add"
# Run lanUtils.sh to update network configuration
if [ -f "$lan_utils_script" ]; then
. "$lan_utils_script"
fi
echo "{\"success\": true, \"message\": \"MTU configuration updated to $mtu_value\", \"currentValue\": $mtu_value}"
;;
*)
echo "{\"success\": false, \"error\": \"Invalid request method\"}"
;;
esac

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in 'AT+QMAP="MPDN_RULE"' 'AT+QMAP="DHCPV4DNS"' 'AT+QCFG="usbnet"'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -1,153 +0,0 @@
#!/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
# Create the directory structure
mkdir -p /etc/quecmanager
# 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")
# 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/smd11 "$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/smd11 "$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

View File

@@ -22,13 +22,48 @@ COMMAND=$(urldecode "$RAW_COMMAND")
# Define unique input/output files and AT port
INPUT_FILE="/tmp/custom_input_$$.txt"
OUTPUT_FILE="/tmp/custom_output_$$.txt"
AT_PORT="/dev/smd7"
# 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" "$AT_PORT" "$OUTPUT_FILE"
atinout "$INPUT_FILE" "/dev/$AT_PORT" "$OUTPUT_FILE"
# Read the output from output.txt
OUTPUT=$(cat "$OUTPUT_FILE")

View File

@@ -7,6 +7,9 @@ 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')
@@ -14,9 +17,6 @@ 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")
# Log received password for debugging (remove in production)
# echo "Received password: $INPUT_PASSWORD" >&2
# Extract the hashed password from /etc/shadow for the specified user
USER_SHADOW_ENTRY=$(grep "^$USER:" /etc/shadow)
@@ -35,11 +35,11 @@ SALT=$(echo "$USER_HASH" | cut -d'$' -f3)
GENERATED_HASH=$(echo "$INPUT_PASSWORD" | openssl passwd -1 -salt "$SALT" -stdin)
# Log generated hash for debugging
echo "Generated hash: $GENERATED_HASH" >&2
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", "hashed_password":"'"$GENERATED_HASH"'"}'
echo '{"state":"success"}'
else
echo '{"state":"failed", "hashed_password":"'"$GENERATED_HASH"'"}'
echo '{"state":"failed"}'
fi

View File

@@ -1,258 +0,0 @@
#!/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')"
}
# Function to send AT commands silently
send_at_command() {
echo "$1" | atinout - /dev/smd7 - >/dev/null 2>&1
}
# Extract reset flags
reset_lte=$(echo "$QUERY_STRING" | grep -o 'reset_lte=[^&]*' | cut -d= -f2)
reset_5g=$(echo "$QUERY_STRING" | grep -o 'reset_5g=[^&]*' | cut -d= -f2)
# Extract LTE values from POST data
earfcn1=$(echo "$QUERY_STRING" | grep -o 'earfcn1=[^&]*' | cut -d= -f2)
pci1=$(echo "$QUERY_STRING" | grep -o 'pci1=[^&]*' | cut -d= -f2)
earfcn2=$(echo "$QUERY_STRING" | grep -o 'earfcn2=[^&]*' | cut -d= -f2)
pci2=$(echo "$QUERY_STRING" | grep -o 'pci2=[^&]*' | cut -d= -f2)
earfcn3=$(echo "$QUERY_STRING" | grep -o 'earfcn3=[^&]*' | cut -d= -f2)
pci3=$(echo "$QUERY_STRING" | grep -o 'pci3=[^&]*' | cut -d= -f2)
# Extract 5G-SA values from POST data
nrarfcn=$(echo "$QUERY_STRING" | grep -o 'nrarfcn=[^&]*' | cut -d= -f2)
nrpci=$(echo "$QUERY_STRING" | grep -o 'nrpci=[^&]*' | cut -d= -f2)
scs=$(echo "$QUERY_STRING" | grep -o 'scs=[^&]*' | cut -d= -f2)
band=$(echo "$QUERY_STRING" | grep -o 'band=[^&]*' | cut -d= -f2)
# URL decode all values
reset_lte=$(urldecode "$reset_lte")
reset_5g=$(urldecode "$reset_5g")
earfcn1=$(urldecode "$earfcn1")
pci1=$(urldecode "$pci1")
earfcn2=$(urldecode "$earfcn2")
pci2=$(urldecode "$pci2")
earfcn3=$(urldecode "$earfcn3")
pci3=$(urldecode "$pci3")
nrarfcn=$(urldecode "$nrarfcn")
nrpci=$(urldecode "$nrpci")
scs=$(urldecode "$scs")
band=$(urldecode "$band")
# Send Content-type header before any other output
echo "Content-type: application/json"
echo ""
# Handle reset requests
if [ "$reset_lte" = "1" ] || [ "$reset_5g" = "1" ]; then
# Remove configuration files
rm -f /etc/quecmanager/cell_lock_config.txt
rm -f /etc/quecmanager/apply_cell_lock.sh
# Remove from rc.local if present
sed -i '/\/etc\/quecmanager\/apply_cell_lock.sh/d' /etc/rc.local
if [ "$reset_lte" = "1" ] && [ "$reset_5g" = "1" ]; then
send_at_command "AT+QNWLOCK=\"common/4g\",0"
send_at_command "AT+QNWLOCK=\"common/5g\",0"
send_at_command "AT+QNWPREFCFG=\"mode_pref\",AUTO"
sleep 1
send_at_command "AT+COPS=2"
sleep 1
send_at_command "AT+COPS=0"
echo '{"status": "success", "message": "All cell lock configurations removed"}'
elif [ "$reset_lte" = "1" ]; then
send_at_command "AT+QNWLOCK=\"common/4g\",0"
sleep 1
send_at_command "AT+COPS=2"
sleep 1
send_at_command "AT+COPS=0"
echo '{"status": "success", "message": "LTE cell lock configuration removed"}'
else
send_at_command "AT+QNWLOCK=\"common/5g\",0"
send_at_command "AT+QNWPREFCFG=\"mode_pref\",AUTO"
sleep 1
send_at_command "AT+COPS=2"
sleep 1
send_at_command "AT+COPS=0"
echo '{"status": "success", "message": "5G cell lock configuration removed"}'
fi
exit 0
fi
# Create the directory structure if it doesn't exist
mkdir -p /etc/quecmanager /var/log/quecmanager
# Create a configuration file to store cell locking profiles
cat >/etc/quecmanager/cell_lock_config.txt <<EOF
# LTE Cell Locking Configuration
earfcn1=$earfcn1
pci1=$pci1
earfcn2=$earfcn2
pci2=$pci2
earfcn3=$earfcn3
pci3=$pci3
# 5G-SA Cell Locking Configuration
nrarfcn=$nrarfcn
nrpci=$nrpci
scs=$scs
band=$band
EOF
# Create the apply_cell_lock.sh script
cat >/etc/quecmanager/apply_cell_lock.sh <<'EOF'
#!/bin/sh
# Create log directory if it doesn't exist
LOG_DIR="/var/log/quecmanager"
mkdir -p "$LOG_DIR"
DEBUG_LOG="$LOG_DIR/cell_lock_debug.log"
# Function to log messages
log_message() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "$timestamp - $message" >> "$DEBUG_LOG"
}
# Verify required tools
if ! command -v atinout >/dev/null 2>&1; then
log_message "Error: atinout command not found"
exit 1
fi
if [ ! -c "/dev/smd7" ]; then
log_message "Error: Modem device /dev/smd7 not found"
exit 1
fi
# Function to send AT commands
send_at_command() {
local command="$1"
local description="$2"
local retry_count=0
local max_retries=3
log_message "Attempting to send command: $command ($description)"
while [ $retry_count -lt $max_retries ]; do
echo "$command" | atinout - /dev/smd7 - > /tmp/at_response.txt 2>&1
local result=$(cat /tmp/at_response.txt)
log_message "Attempt $((retry_count + 1)) - Response: $result"
if echo "$result" | grep -q "OK"; then
log_message "Command successful: $description"
return 0
fi
retry_count=$((retry_count + 1))
log_message "Command failed, retry $retry_count of $max_retries"
sleep 2
done
log_message "Command failed after $max_retries retries: $description"
return 1
}
# Function to apply cell lock configuration
apply_cell_lock() {
local config_file="/etc/quecmanager/cell_lock_config.txt"
if [ ! -f "$config_file" ]; then
log_message "Configuration file not found"
return 1
fi
# Read configuration values
. "$config_file"
# Test modem responsiveness
if ! send_at_command "AT" "Testing modem responsiveness"; then
return 1
fi
# Apply LTE configuration if present
if [ -n "$earfcn1" ] && [ -n "$pci1" ]; then
if [ -n "$earfcn2" ] && [ -n "$pci2" ]; then
if [ -n "$earfcn3" ] && [ -n "$pci3" ]; then
send_at_command "AT+QNWLOCK=\"common/4g\",3,$earfcn1,$pci1,$earfcn2,$pci2,$earfcn3,$pci3" "Setting LTE lock (3 cells)"
else
send_at_command "AT+QNWLOCK=\"common/4g\",2,$earfcn1,$pci1,$earfcn2,$pci2" "Setting LTE lock (2 cells)"
fi
else
send_at_command "AT+QNWLOCK=\"common/4g\",1,$earfcn1,$pci1" "Setting LTE lock (1 cell)"
fi
sleep 1
if ! send_at_command "AT+COPS=2" "Network Disconnected"; then
return 1
fi
sleep 1
if ! send_at_command "AT+COPS=0" "Network Reconnected"; then
return 1
fi
fi
# Apply 5G configuration if present
if [ -n "$nrpci" ] && [ -n "$nrarfcn" ] && [ -n "$scs" ] && [ -n "$band" ]; then
if ! send_at_command "AT+QNWPREFCFG=\"mode_pref\",NR5G" "Setting network to SA only"; then
return 1
fi
sleep 1
if ! send_at_command "AT+QNWLOCK=\"common/5g\",$nrpci,$nrarfcn,$scs,$band" "Setting 5G lock"; then
return 1
fi
sleep 1
if ! send_at_command "AT+COPS=2" "Network Disconnected"; then
return 1
fi
sleep 1
if ! send_at_command "AT+COPS=0" "Network Reconnected"; then
return 1
fi
fi
return 0
}
# Main execution
log_message "Starting cell lock configuration"
if apply_cell_lock; then
log_message "Cell lock configuration applied successfully"
exit 0
else
log_message "Failed to apply cell lock configuration"
exit 1
fi
EOF
# Make the script executable
chmod +x /etc/quecmanager/apply_cell_lock.sh
# Add to rc.local if not already present
if ! grep -q "/etc/quecmanager/apply_cell_lock.sh" /etc/rc.local; then
sed -i '/exit 0/i sleep 30\n\/etc\/quecmanager\/apply_cell_lock.sh' /etc/rc.local
fi
# Run the script immediately
/etc/quecmanager/apply_cell_lock.sh
result=$?
if [ $result -eq 0 ]; then
echo '{"status": "success", "message": "Cell lock configurations saved and applied successfully"}'
else
echo '{"status": "error", "message": "Cell lock configurations saved but failed to apply"}'
fi

View File

@@ -1,60 +0,0 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
CONFIG_FILE="/etc/quecmanager/cell_lock_config.txt"
if [ ! -f "$CONFIG_FILE" ]; then
echo '{"status": "error", "message": "No cell lock configurations found", "configurations": {}}'
exit 0
fi
# Function to read config values
get_config_value() {
local key=$1
local value=$(grep "^$key=" "$CONFIG_FILE" | sed "s/^$key=//")
# Remove any trailing whitespace or comments
value=$(echo "$value" | sed 's/[[:space:]]*#.*$//' | sed 's/[[:space:]]*$//')
echo "$value"
}
# Read LTE configuration values
earfcn1=$(get_config_value "earfcn1")
pci1=$(get_config_value "pci1")
earfcn2=$(get_config_value "earfcn2")
pci2=$(get_config_value "pci2")
earfcn3=$(get_config_value "earfcn3")
pci3=$(get_config_value "pci3")
# Read 5G-SA configuration values
nrarfcn=$(get_config_value "nrarfcn")
nrpci=$(get_config_value "nrpci")
scs=$(get_config_value "scs")
band=$(get_config_value "band")
# Debug output to syslog
logger "fetch-cell-lock: earfcn1=$earfcn1 pci1=$pci1 nrarfcn=$nrarfcn nrpci=$nrpci"
# Construct JSON response
cat << EOF
{
"status": "success",
"configurations": {
"lte": {
"earfcn1": "${earfcn1:-}",
"pci1": "${pci1:-}",
"earfcn2": "${earfcn2:-}",
"pci2": "${pci2:-}",
"earfcn3": "${earfcn3:-}",
"pci3": "${pci3:-}"
},
"sa": {
"nrarfcn": "${nrarfcn:-}",
"nrpci": "${nrpci:-}",
"scs": "${scs:-}",
"band": "${band:-}"
}
}
}
EOF

View File

@@ -1,120 +0,0 @@
#!/bin/sh
# Enable debug logging
# exec 1> >(logger -s -t $(basename $0)) 2>&1
# Create log directory if it doesn't exist
LOG_DIR="/var/log/quecmanager"
mkdir -p "$LOG_DIR"
DEBUG_LOG="$LOG_DIR/cell_lock_debug.log"
# Function to log messages
log_message() {
local message="$1"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "$timestamp - $message" >> "$DEBUG_LOG"
}
# Verify required tools
if ! command -v atinout >/dev/null 2>&1; then
log_message "Error: atinout command not found"
exit 1
fi
if [ ! -c "/dev/smd11" ]; then
log_message "Error: Modem device /dev/smd11 not found"
exit 1
fi
# Function to send AT commands
send_at_command() {
local command="$1"
local description="$2"
local retry_count=0
local max_retries=3
log_message "Attempting to send command: $command ($description)"
while [ $retry_count -lt $max_retries ]; do
echo "$command" | atinout - /dev/smd11 - > /tmp/at_response.txt 2>&1
local result=$(cat /tmp/at_response.txt)
log_message "Attempt $((retry_count + 1)) - Response: $result"
if echo "$result" | grep -q "OK"; then
log_message "Command successful: $description"
return 0
fi
retry_count=$((retry_count + 1))
log_message "Command failed, retry $retry_count of $max_retries"
sleep 2
done
log_message "Command failed after $max_retries retries: $description"
return 1
}
# Function to apply cell lock configuration
apply_cell_lock() {
local config_file="/etc/quecmanager/cell_lock_config.txt"
if [ ! -f "$config_file" ]; then
log_message "Configuration file not found"
return 1
fi
# Read configuration values
. "$config_file"
# Test modem responsiveness
if ! send_at_command "AT" "Testing modem responsiveness"; then
return 1
fi
# Apply LTE configuration if present
if [ -n "$earfcn1" ] && [ -n "$pci1" ]; then
if ! send_at_command "AT+CFUN=0" "Setting radio off"; then
return 1
fi
sleep 2
if [ -n "$earfcn2" ] && [ -n "$pci2" ]; then
if [ -n "$earfcn3" ] && [ -n "$pci3" ]; then
send_at_command "AT+QNWLOCK=\"common/4g\",3,$earfcn1,$pci1,$earfcn2,$pci2,$earfcn3,$pci3" "Setting LTE lock (3 cells)"
else
send_at_command "AT+QNWLOCK=\"common/4g\",2,$earfcn1,$pci1,$earfcn2,$pci2" "Setting LTE lock (2 cells)"
fi
else
send_at_command "AT+QNWLOCK=\"common/4g\",1,$earfcn1,$pci1" "Setting LTE lock (1 cell)"
fi
sleep 2
if ! send_at_command "AT+CFUN=1" "Setting radio on"; then
return 1
fi
fi
# Apply 5G configuration if present
if [ -n "$nrpci" ] && [ -n "$nrarfcn" ] && [ -n "$scs" ] && [ -n "$band" ]; then
if ! send_at_command "AT+CFUN=0" "Setting radio off"; then
return 1
fi
sleep 2
if ! send_at_command "AT+QNWLOCK=\"common/5g\",$nrpci,$nrarfcn,$scs,$band" "Setting 5G lock"; then
return 1
fi
sleep 2
if ! send_at_command "AT+CFUN=1" "Setting radio on"; then
return 1
fi
fi
}
# Main execution
log_message "Starting cell lock configuration"
if apply_cell_lock; then
log_message "Cell lock configuration applied successfully"
exit 0
else
log_message "Failed to apply cell lock configuration"
exit 1
fi

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in 'AT+CGDCONT?' 'AT+QNWPREFCFG="mode_pref"' 'AT+QNWPREFCFG="nr5g_disable_mode"'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -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/apn_profile/" ]; then
rm -rf /etc/quecmanager/apn_profile/
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

View File

@@ -0,0 +1,45 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
CONFIG_FILE="/etc/quecmanager/apn_profile/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 "}"

View File

@@ -33,11 +33,12 @@ if [ -z "$iccidProfile1" ] || [ -z "$apnProfile1" ] || [ -z "$pdpType1" ]; then
exit 1
fi
# Create the directory structure
mkdir -p /etc/quecmanager
if [ ! -d /etc/quecmanager/apn_profile ]; then
mkdir -p /etc/quecmanager/apn_profile
fi
# Create a configuration file to store APN profiles (as plain text)
cat > /etc/quecmanager/apn_config.txt << EOF
cat > /etc/quecmanager/apn_profile/apn_config.txt << EOF
iccidProfile1=$iccidProfile1
apnProfile1=$apnProfile1
pdpType1=$pdpType1
@@ -45,7 +46,7 @@ EOF
# Add second profile only if ICCID is provided
if [ -n "$iccidProfile2" ]; then
cat >> /etc/quecmanager/apn_config.txt << EOF
cat >> /etc/quecmanager/apn_profile/apn_config.txt << EOF
iccidProfile2=$iccidProfile2
apnProfile2=$apnProfile2
pdpType2=$pdpType2
@@ -53,13 +54,13 @@ EOF
fi
# Create the apnProfiles.sh script
cat > /etc/quecmanager/apnProfiles.sh << 'EOF'
cat > /etc/quecmanager/apn_profile/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
grep "^${key}=" /etc/quecmanager/apn_profile/apn_config.txt | cut -d'=' -f2
}
# Read configuration
@@ -70,13 +71,48 @@ 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/smd11 "$output_file"
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
iccid=$(cat "$output_file" | grep "+ICCID:" | cut -d' ' -f2)
@@ -92,7 +128,7 @@ set_apn() {
local output_file="/tmp/outputAPN.txt"
echo "AT+CGDCONT=1,\"$pdp_type\",\"$apn\";+COPS=2;+COPS=0" > "$input_file"
atinout "$input_file" /dev/smd11 "$output_file"
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
local result=$(cat "$output_file")
rm -f "$input_file" "$output_file"
@@ -128,15 +164,15 @@ fi
EOF
# Make the script executable
chmod +x /etc/quecmanager/apnProfiles.sh
chmod +x /etc/quecmanager/apn_profile/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
if ! grep -q "/etc/quecmanager/apn_profile/apnProfiles.sh" /etc/rc.local; then
sed -i '/^exit 0/i /etc/quecmanager/apn_profile/apnProfiles.sh' /etc/rc.local
fi
# Run the script immediately
/etc/quecmanager/apnProfiles.sh
/etc/quecmanager/apn_profile/apnProfiles.sh
# Check the result
if [ -f /tmp/apn_result.txt ]; then

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in 'AT+CGDCONT?' 'AT+QNWPREFCFG="mode_pref"' 'AT+QNWPREFCFG="nr5g_disable_mode"' 'AT+QUIMSLOT?'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -1,45 +0,0 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
CONFIG_FILE="/etc/quecmanager/apn_config.txt"
if [ ! -f "$CONFIG_FILE" ]; then
echo '{"status": "error", "message": "No APN profiles found", "profiles": {}}'
exit 0
fi
# Function to read config values
get_config_value() {
local key=$1
local value=$(grep "^${key}=" "$CONFIG_FILE" | cut -d'=' -f2)
echo "$value"
}
# Read all profile values
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")
# Construct JSON response
cat << EOF
{
"status": "success",
"profiles": {
"profile1": {
"iccid": "${iccidProfile1:-}",
"apn": "${apnProfile1:-}",
"pdpType": "${pdpType1:-}"
},
"profile2": {
"iccid": "${iccidProfile2:-}",
"apn": "${apnProfile2:-}",
"pdpType": "${pdpType2:-}"
}
}
}
EOF

View File

@@ -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/imei_profile/" ]; then
rm -rf /etc/quecmanager/imei_profile/
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

View File

@@ -0,0 +1,39 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
CONFIG_FILE="/etc/quecmanager/imei_profile/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 "}"

View File

@@ -0,0 +1,209 @@
#!/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/imei_profile ]; then
mkdir -p /etc/quecmanager/imei_profile
fi
# Create a configuration file to store IMEI profiles
cat >/etc/quecmanager/imei_profile/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_profile/imei_config.txt <<EOF
iccidProfile2=$iccidProfile2
imeiProfile2=$imeiProfile2
EOF
fi
# Create the imeiProfiles.sh script
cat >/etc/quecmanager/imei_profile/imeiProfiles.sh <<'EOF'
#!/bin/sh
# Function to read config values
get_config_value() {
local key=$1
grep "^${key}=" /etc/quecmanager/imei_profile/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 get current IMEI
get_current_imei() {
local input_file="/tmp/inputCGSN.txt"
local output_file="/tmp/outputCGSN.txt"
echo "AT+CGSN" > "$input_file"
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
# Extract IMEI from the response, removing any whitespace or newlines
imei=$(cat "$output_file" | grep -v "AT+CGSN" | grep -v "OK" | tr -d '\r\n[:space:]')
rm -f "$input_file" "$output_file"
echo "$imei"
}
# 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 and IMEI
current_iccid=$(get_current_iccid)
current_imei=$(get_current_imei)
success=false
echo "Current ICCID: $current_iccid" >> "$DEBUG_LOG"
echo "Current IMEI: $current_imei" >> "$DEBUG_LOG"
echo "Profile 1 - ICCID: $iccidProfile1, IMEI: $imeiProfile1" >> "$DEBUG_LOG"
echo "Profile 2 - ICCID: $iccidProfile2, IMEI: $imeiProfile2" >> "$DEBUG_LOG"
# Check ICCID against profile 1 (required)
if [ "$current_iccid" = "$iccidProfile1" ]; then
if [ "$current_imei" != "$imeiProfile1" ]; then
echo "ICCID matches profile 1, but IMEI needs updating" >> "$DEBUG_LOG"
if set_imei "$imeiProfile1"; then
success=true
fi
else
echo "ICCID and IMEI already match profile 1, no action needed" >> "$DEBUG_LOG"
success=true
fi
# Check ICCID against profile 2 (optional)
elif [ -n "$iccidProfile2" ] && [ "$current_iccid" = "$iccidProfile2" ]; then
if [ "$current_imei" != "$imeiProfile2" ]; then
echo "ICCID matches profile 2, but IMEI needs updating" >> "$DEBUG_LOG"
if set_imei "$imeiProfile2"; then
success=true
fi
else
echo "ICCID and IMEI already match profile 2, no action needed" >> "$DEBUG_LOG"
success=true
fi
fi
if [ "$success" = "true" ]; then
echo "IMEI check/update completed successfully" > /tmp/imei_result.txt
else
echo "Failed to check/update IMEI" > /tmp/imei_result.txt
fi
EOF
# Make the script executable
chmod +x /etc/quecmanager/imei_profile/imeiProfiles.sh
# Add to rc.local if not already present
if ! grep -q "/etc/quecmanager/imei_profile/imeiProfiles.sh" /etc/rc.local; then
sed -i '/^exit 0/i /etc/quecmanager/imei_profile/imeiProfiles.sh' /etc/rc.local
fi
# Run the script immediately
/etc/quecmanager/imei_profile/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

View File

@@ -1,14 +0,0 @@
#!/bin/sh
# Set the content type to JSON
echo "Content-Type: application/json"
echo ""
# Ping 8.8.8.8 and capture the result
if ping -c 1 8.8.8.8 > /dev/null 2>&1; then
# Ping was successful
echo '{"connection": "ACTIVE"}'
else
# Ping failed
echo '{"connection": "INACTIVE"}'
fi

View File

@@ -0,0 +1,61 @@
#!/bin/sh
# Configuration and log directories
CONFIG_DIR="/etc/quecmanager/quecwatch"
QUECWATCH_SCRIPT="${CONFIG_DIR}/quecwatch.sh"
RCLOCAL="/etc/rc.local"
LOG_DIR="/tmp/log/quecwatch"
DEBUG_LOG_FILE="${LOG_DIR}/debug.log"
# Log directory for cleaning process
CLEANUP_LOG_FILE="${LOG_DIR}/cleanup.log"
# Ensure log directory exists
mkdir -p "${LOG_DIR}"
# Function to log cleanup events
log_cleanup() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "${CLEANUP_LOG_FILE}"
}
# Default response headers
echo "Content-type: application/json"
echo ""
# Cleanup function
cleanup_quecwatch() {
# Start logging cleanup process
log_cleanup "Starting QuecWatch cleanup process"
# Stop any running QuecWatch processes
log_cleanup "Stopping QuecWatch processes"
pkill -f "${QUECWATCH_SCRIPT}" >> "${CLEANUP_LOG_FILE}" 2>&1
# Remove QuecWatch script from rc.local
if [ -f "${RCLOCAL}" ]; then
log_cleanup "Removing QuecWatch entries from rc.local"
sed -i '\|/etc/quecmanager/quecwatch/quecwatch.sh|d' "${RCLOCAL}" >> "${CLEANUP_LOG_FILE}" 2>&1
fi
# Remove configuration directory
if [ -d "${CONFIG_DIR}" ]; then
log_cleanup "Removing configuration directory: ${CONFIG_DIR}"
rm -rf "${CONFIG_DIR}" >> "${CLEANUP_LOG_FILE}" 2>&1
fi
# Remove log directory
if [ -d "${LOG_DIR}" ]; then
log_cleanup "Removing log directory: ${LOG_DIR}"
rm -rf "${LOG_DIR}" >> "${CLEANUP_LOG_FILE}" 2>&1
fi
log_cleanup "QuecWatch cleanup completed successfully"
# Optional: Output JSON response
echo '{"status": "success", "message": "QuecWatch disabled and removed"}'
}
# Execute cleanup
cleanup_quecwatch
exit 0

View File

@@ -0,0 +1,356 @@
#!/bin/sh
# Read 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')"
}
# Configuration directory
CONFIG_DIR="/etc/quecmanager/quecwatch"
QUECWATCH_CONFIG="${CONFIG_DIR}/quecwatch.conf"
QUECWATCH_SCRIPT="${CONFIG_DIR}/quecwatch.sh"
RCLOCAL="/etc/rc.local"
LOG_DIR="/tmp/log/quecwatch"
DEBUG_LOG_FILE="${LOG_DIR}/debug.log"
# Ensure log directory exists
mkdir -p "${LOG_DIR}"
# Extract values from POST data
action=$(echo "$QUERY_STRING" | grep -o 'action=[^&]*' | cut -d= -f2)
ping_target=$(echo "$QUERY_STRING" | grep -o 'ping_target=[^&]*' | cut -d= -f2)
ping_interval=$(echo "$QUERY_STRING" | grep -o 'ping_interval=[^&]*' | cut -d= -f2)
ping_failures=$(echo "$QUERY_STRING" | grep -o 'ping_failures=[^&]*' | cut -d= -f2)
max_retries=$(echo "$QUERY_STRING" | grep -o 'max_retries=[^&]*' | cut -d= -f2)
connection_refresh=$(echo "$QUERY_STRING" | grep -o 'connection_refresh=[^&]*' | cut -d= -f2)
auto_sim_failover=$(echo "$QUERY_STRING" | grep -o 'auto_sim_failover=[^&]*' | cut -d= -f2)
sim_failover_schedule=$(echo "$QUERY_STRING" | grep -o 'sim_failover_schedule=[^&]*' | cut -d= -f2)
mobile_data_reconnect=$(echo "$QUERY_STRING" | grep -o 'mobile_data_reconnect=[^&]*' | cut -d= -f2)
# URL decode the values
action=$(urldecode "$action")
ping_target=$(urldecode "$ping_target")
ping_interval=$(urldecode "$ping_interval")
ping_failures=$(urldecode "$ping_failures")
max_retries=$(urldecode "$max_retries")
connection_refresh=$(urldecode "$connection_refresh")
auto_sim_failover=$(urldecode "$auto_sim_failover")
sim_failover_schedule=$(urldecode "$sim_failover_schedule")
mobile_data_reconnect=$(urldecode "$mobile_data_reconnect")
# Default response headers
echo "Content-type: application/json"
echo ""
# Validate inputs
if [ -z "$ping_target" ]; then
echo '{"status": "error", "message": "Ping target is required"}'
exit 1
fi
# Initialize configuration function
initialize_config() {
# Create config directory if not exists
mkdir -p "${CONFIG_DIR}"
# Write configuration with defaults and user-provided values
cat >"${QUECWATCH_CONFIG}" <<EOL
# QuecWatch Configuration File
# Ping Target (IP or domain to ping)
PING_TARGET=${ping_target}
# Interval between ping checks (in seconds)
PING_INTERVAL=${ping_interval:-30}
# Number of consecutive ping failures before taking action
PING_FAILURES=${ping_failures:-3}
# Maximum number of retry attempts
MAX_RETRIES=${max_retries:-5}
# Current retry count (should start at 0)
CURRENT_RETRIES=0
# Enable/Disable Connection Refresh
CONNECTION_REFRESH=${connection_refresh:-false}
# Number of connection refresh attempts
REFRESH_COUNT=${connection_refresh:+3}
# Enable/Disable Auto SIM Failover
AUTO_SIM_FAILOVER=${auto_sim_failover:-false}
# Schedule for checking initial SIM (in minutes)
# 0 means no scheduled check
SIM_FAILOVER_SCHEDULE=${sim_failover_schedule:-0}
# Enable/Disable Mobile Data Reconnect
MOBILE_DATA_RECONNECT=${mobile_data_reconnect:-false}
# Indicate that QuecWatch is enabled
ENABLED=true
EOL
chmod 644 "${QUECWATCH_CONFIG}"
}
# Generate monitoring script function
generate_monitoring_script() {
cat >"${QUECWATCH_SCRIPT}" <<'EOL'
#!/bin/sh
# Load configuration
. /etc/quecmanager/quecwatch/quecwatch.conf
# Log directory
LOG_DIR="/tmp/log/quecwatch"
mkdir -p "${LOG_DIR}"
# Function to log events
log_event() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "${LOG_DIR}/quecwatch.log"
}
# Function to update retry count in config
update_retry_count() {
local new_retry_count=$1
sed -i "s/CURRENT_RETRIES=[0-9]*/CURRENT_RETRIES=${new_retry_count}/" /etc/quecmanager/quecwatch/quecwatch.conf
# Reload config to ensure latest values
. /etc/quecmanager/quecwatch/quecwatch.conf
}
# Function to switch SIM card
switch_sim_card() {
log_event "Attempting to switch SIM card"
# Create log directory if it doesn't exist
mkdir -p /tmp/log/quecwatch
# Get current SIM slot using AT command
echo AT+QUIMSLOT? | atinout - /dev/smd7 /tmp/log/quecwatch/current_sim.txt
# Extract numerical value from the output
current_sim_slot=$(grep "+QUIMSLOT:" /tmp/log/quecwatch/current_sim.txt | awk '{print $2}')
# Toggle between SIM slots (assuming 2 SIM slots)
if [ "${current_sim_slot}" = "1" ]; then
new_sim_slot=2
else
new_sim_slot=1
fi
# Explicitly set the new SIM slot
log_event "Switching from SIM slot ${current_sim_slot} to SIM slot ${new_sim_slot}"
# Add your SIM switching command here
# Example (adjust based on your modem's AT commands):
echo "AT+QUIMSLOT=${new_sim_slot}" | atinout - /dev/smd7 -
# Update current_sim_slot with the new value
current_sim_slot=${new_sim_slot}
}
# Function to toggle mobile data
toggle_mobile_data() {
log_event "Toggling mobile data"
# Use CFUN to restart mobile functionality
echo AT+CFUN=0 | atinout - /dev/smd7 -
#sleep 5
echo AT+CFUN=1 | atinout - /dev/smd7 -
}
# Function to perform connection recovery
perform_connection_recovery() {
local recovery_attempted=0
# 1. Try Connection Refresh first if enabled (when retry_trigger is 1)
if [ "${CONNECTION_REFRESH}" = "true" ] && [ "${retry_trigger}" -eq 1 ] && [ "${REFRESH_COUNT}" -gt 0 ]; then
log_event "Attempting connection refresh"
echo AT+COPS=2 | atinout - /dev/smd7 -
sleep 2
echo AT+COPS=0 | atinout - /dev/smd7 -
# Verify connection after refresh
if ping -c 3 ${PING_TARGET} > /dev/null 2>&1; then
log_event "Connection refresh successful"
return 0
fi
# Decrement refresh count
REFRESH_COUNT=$((REFRESH_COUNT - 1))
sed -i "s/REFRESH_COUNT=.*/REFRESH_COUNT=${REFRESH_COUNT}/" /etc/quecmanager/quecwatch/quecwatch.conf
recovery_attempted=1
fi
# 2. Try Auto SIM Failover when retry_trigger is 2 (or 1 if Connection Refresh is disabled)
local sim_failover_trigger=$((CONNECTION_REFRESH == "true" ? 2 : 1))
if [ "${AUTO_SIM_FAILOVER}" = "true" ] && [ "${retry_trigger}" -eq ${sim_failover_trigger} ]; then
log_event "Attempting SIM failover"
# Get current SIM slot
echo AT+QUIMSLOT? | atinout - /dev/smd7 /tmp/log/quecwatch/current_sim.txt
initial_sim_slot=$(grep "+QUIMSLOT:" /tmp/log/quecwatch/current_sim.txt | awk '{print $2}')
# Switch SIM card
switch_sim_card
# Verify connection after SIM switch
if ping -c 3 ${PING_TARGET} > /dev/null 2>&1; then
log_event "SIM failover successful"
return 0
fi
recovery_attempted=1
fi
# 3. Try Mobile Data Reconnect if enabled
if [ "${MOBILE_DATA_RECONNECT}" = "true" ]; then
log_event "Attempting mobile data reconnect"
toggle_mobile_data
# Verify connection after mobile data toggle
if ping -c 3 ${PING_TARGET} > /dev/null 2>&1; then
log_event "Mobile data reconnect successful"
return 0
fi
recovery_attempted=1
fi
# 4. If no recovery methods worked or none were enabled, return failure
if [ ${recovery_attempted} -eq 0 ]; then
log_event "No recovery methods enabled"
return 1
fi
return 1
}
while true; do
# Ping the target
if ! ping -c ${PING_FAILURES} ${PING_TARGET} > /dev/null 2>&1; then
failure_count=$((failure_count + 1))
log_event "Ping failed. Failure count: ${failure_count}"
# Check if failure threshold is reached
if [ ${failure_count} -ge ${PING_FAILURES} ]; then
# Reset failure count
failure_count=0
retry_trigger=$((retry_trigger + 1))
# Update retry count in config
update_retry_count ${retry_trigger}
log_event "Failure threshold reached. Retry trigger: ${retry_trigger}"
# Check if retry threshold is reached
if [ ${retry_trigger} -ge ${MAX_RETRIES} ]; then
log_event "Max retries exhausted. Removing QuecWatch."
# Remove the script from rc.local
sed -i '\|/etc/quecmanager/quecwatch/quecwatch.sh|d' /etc/rc.local
# Perform final system reboot
reboot
exit 0
fi
# Attempt connection recovery
if perform_connection_recovery; then
# Recovery successful
log_event "Connection recovery successful"
retry_trigger=0
failure_count=0
update_retry_count 0
else
# Recovery failed, choose recovery method based on configurations
if [ "${MOBILE_DATA_RECONNECT}" = "true" ]; then
log_event "Recovery failed. Attempting mobile data restart."
toggle_mobile_data
else
log_event "Recovery failed. Rebooting system."
reboot
fi
fi
fi
else
# Reset failure count and retry trigger if connection is good
failure_count=0
retry_trigger=0
update_retry_count 0
# Add success log message
log_event "Modem is connected to the internet"
# Check if SIM Failover Scheduler is enabled and interval has passed
if [ "${AUTO_SIM_FAILOVER}" = "true" ] && [ "${SIM_FAILOVER_SCHEDULE}" -gt 0 ]; then
sim_failover_interval=$((sim_failover_interval + 1))
# Check if it's time to switch back to initial SIM
if [ $((sim_failover_interval * ${PING_INTERVAL})) -ge $((${SIM_FAILOVER_SCHEDULE} * 60)) ]; then
log_event "Checking initial SIM card"
# Only switch back if max retries were NOT exhausted
if [ ${retry_trigger} -lt ${MAX_RETRIES} ]; then
# Switch back to initial SIM
echo AT+QUIMSLOT=${initial_sim_slot} | atinout - /dev/smd7 -
# Check connection on initial SIM
if ping -c 3 ${PING_TARGET} > /dev/null 2>&1; then
log_event "Initial SIM restored successfully"
current_sim_slot=${initial_sim_slot}
# Reset retry trigger when switching back
retry_trigger=0
failure_count=0
update_retry_count 0
else
log_event "Initial SIM still not working. Remaining on failover SIM."
fi
# Reset interval counter
sim_failover_interval=0
fi
fi
fi
fi
# Wait for specified interval before next check
sleep ${PING_INTERVAL}
done
EOL
chmod +x "${QUECWATCH_SCRIPT}"
# Run the script
"${QUECWATCH_SCRIPT}" &
}
# Enable QuecWatch
enable_quecwatch() {
# Initialize configuration
initialize_config
# Generate monitoring script
generate_monitoring_script
# Add to rc.local if not already present
if ! grep -q "${QUECWATCH_SCRIPT}" "${RCLOCAL}"; then
[ -f "${RCLOCAL}" ] || touch "${RCLOCAL}"
chmod +x "${RCLOCAL}"
sed -i '$i'"${QUECWATCH_SCRIPT} &" "${RCLOCAL}"
fi
# Output success JSON
echo '{"status": "success", "message": "QuecWatch enabled", "config": "'${QUECWATCH_CONFIG}'"}'
}
# Log debug information
{
echo "Timestamp: $(date)"
echo "Script Path: $0"
echo "Ping Target: $ping_target"
echo "Ping Interval: $ping_interval"
echo "Ping Failures: $ping_failures"
echo "Max Retries: $max_retries"
echo "Connection Refresh: $connection_refresh"
echo "Auto SIM Failover: $auto_sim_failover"
echo "SIM Failover Schedule: $sim_failover_schedule"
echo "Mobile Data Reconnect: $mobile_data_reconnect"
} >>"$DEBUG_LOG_FILE" 2>&1
# Enable QuecWatch
enable_quecwatch
exit 0

View File

@@ -0,0 +1,79 @@
#!/bin/sh
# Set headers for JSON response
echo "Content-type: application/json"
echo ""
# Configuration file path
CONFIG_FILE="/etc/quecmanager/quecwatch/quecwatch.conf"
# Check if configuration file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo '{"status": "inactive", "message": "QuecWatch is not configured"}'
exit 0
fi
# Function to safely get config value
get_config_value() {
grep "^$1=" "$CONFIG_FILE" | cut -d'=' -f2
}
# Check if QuecWatch is enabled
enabled=$(get_config_value "ENABLED")
if [ "$enabled" != "true" ]; then
echo '{"status": "inactive", "message": "QuecWatch is disabled"}'
exit 0
fi
# Fetch configuration values
ping_target=$(get_config_value "PING_TARGET")
ping_interval=$(get_config_value "PING_INTERVAL")
ping_failures=$(get_config_value "PING_FAILURES")
max_retries=$(get_config_value "MAX_RETRIES")
current_retries=$(get_config_value "CURRENT_RETRIES")
connection_refresh=$(get_config_value "CONNECTION_REFRESH")
refresh_count=$(get_config_value "REFRESH_COUNT")
# New configuration options
mobile_data_reconnect=$(get_config_value "MOBILE_DATA_RECONNECT")
auto_sim_failover=$(get_config_value "AUTO_SIM_FAILOVER")
sim_failover_schedule=$(get_config_value "SIM_FAILOVER_SCHEDULE")
# Default values if not set
mobile_data_reconnect=${mobile_data_reconnect:-false}
auto_sim_failover=${auto_sim_failover:-false}
sim_failover_schedule=${sim_failover_schedule:-30}
# Check monitoring script existence
QUECWATCH_SCRIPT="/etc/quecmanager/quecwatch/quecwatch.sh"
if [ ! -f "$QUECWATCH_SCRIPT" ]; then
echo '{"status": "error", "message": "Monitoring script is missing"}'
exit 0
fi
# Check log file for recent activity
LOG_FILE="/tmp/log/quecwatch/quecwatch.log"
last_log=""
if [ -f "$LOG_FILE" ]; then
last_log=$(tail -n 1 "$LOG_FILE")
fi
# Prepare JSON response
cat <<EOF
{
"status": "active",
"config": {
"pingTarget": "${ping_target}",
"pingInterval": ${ping_interval},
"pingFailures": ${ping_failures},
"maxRetries": ${max_retries},
"currentRetries": ${current_retries},
"connectionRefresh": ${connection_refresh},
"refreshCount": ${refresh_count:-0},
"mobileDataReconnect": ${mobile_data_reconnect},
"autoSimFailover": ${auto_sim_failover},
"simFailoverSchedule": ${sim_failover_schedule}
},
"lastActivity": "${last_log}"
}
EOF

View File

@@ -1,45 +0,0 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
CONFIG_FILE="/etc/quecmanager/apn_config.txt"
if [ ! -f "$CONFIG_FILE" ]; then
echo '{"status": "error", "message": "No APN profiles found", "profiles": {}}'
exit 0
fi
# Function to read config values
get_config_value() {
local key=$1
local value=$(grep "^${key}=" "$CONFIG_FILE" | cut -d'=' -f2)
echo "$value"
}
# Read all profile values
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")
# Construct JSON response
cat << EOF
{
"status": "success",
"profiles": {
"profile1": {
"iccid": "${iccidProfile1:-}",
"apn": "${apnProfile1:-}",
"pdpType": "${pdpType1:-}"
},
"profile2": {
"iccid": "${iccidProfile2:-}",
"apn": "${apnProfile2:-}",
"pdpType": "${pdpType2:-}"
}
}
}
EOF

View File

@@ -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"

View File

@@ -1,49 +0,0 @@
#!/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"

View File

@@ -4,8 +4,8 @@
echo "Content-Type: application/json"
echo ""
# Ping 8.8.8.8 and capture the result
if ping -c 1 8.8.8.8 > /dev/null 2>&1; then
# 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

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in "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"'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -1,16 +0,0 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
# Get RX and TX bytes from ifconfig eth0
data=$(ifconfig eth0 | grep "RX bytes")
# Extract download (RX) and upload (TX) values using awk
download=$(echo $data | awk '{print $2}' | cut -d':' -f2)
upload=$(echo $data | awk '{print $6}' | cut -d':' -f2)
# Return JSON response
echo "{"
echo " \"download\": \"$download\","
echo " \"upload\": \"$upload\""
echo "}"

View File

@@ -1,66 +0,0 @@
#!/bin/sh
# Set content-type for JSON response
echo "Content-type: application/json"
echo ""
# Define the lock file
LOCK_FILE="/tmp/home_data.lock"
# Acquire the lock (wait if needed)
exec 200>$LOCK_FILE
flock -x 200
# Temporary files for input/output and AT port
INPUT_FILE="/tmp/input_$$.txt"
OUTPUT_FILE="/tmp/output_$$.txt"
AT_PORT="/dev/smd11"
# Debug file path
DEBUG_FILE="/tmp/debug-json-result.txt"
# Function to escape JSON strings (handling quotes and newlines)
escape_json() {
# Escape newlines and double quotes
echo "$1" | sed ':a;N;$!ba;s/\n/\\n/g; s/"/\\"/g'
}
# Initialize JSON response array
JSON_RESPONSE="["
# List of AT commands to run, one by one
for COMMAND in "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"'; do
# Write the command to the input file
echo "$COMMAND" > "$INPUT_FILE"
# Run the command using atinout
atinout "$INPUT_FILE" "$AT_PORT" "$OUTPUT_FILE"
# Read the output from the output file
OUTPUT=$(cat "$OUTPUT_FILE")
# Escape special characters for JSON (escape only output)
ESCAPED_OUTPUT=$(escape_json "$OUTPUT")
# Append the response as an object to the JSON response array
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
# Write the JSON response to the debug file for troubleshooting
echo "$JSON_RESPONSE" > "$DEBUG_FILE"
# Return the output as a valid JSON response
echo "$JSON_RESPONSE"
# Clean up temporary files
rm "$INPUT_FILE" "$OUTPUT_FILE"
# Release the lock
flock -u 200

View File

@@ -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

View File

@@ -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 "}"

View File

@@ -0,0 +1,64 @@
#!/bin/sh
# Send CGI headers first
echo "Content-Type: application/json"
echo "Cache-Control: no-cache"
echo
# Initialize variables for file paths
APN_SCRIPT="/etc/quecmanager/apn_profile/apnProfiles.sh"
IMEI_SCRIPT="/etc/quecmanager/imei_profile/imeiProfiles.sh"
# Function to output JSON
output_json() {
local status="$1"
local message="$2"
echo "{\"status\": \"$status\", \"message\": \"$message\"}"
}
# Function to execute script if it exists
execute_if_exists() {
local script_path="$1"
if [ -f "$script_path" ] && [ -x "$script_path" ]; then
$script_path >/dev/null 2>&1
return $?
fi
return 2
}
# Main execution
main() {
scripts_executed=0
has_error=0
# Try to execute APN script
execute_if_exists "$APN_SCRIPT"
apn_result=$?
if [ $apn_result -eq 0 ]; then
scripts_executed=$(($scripts_executed + 1))
elif [ $apn_result -eq 1 ]; then
has_error=1
fi
# Try to execute IMEI script
execute_if_exists "$IMEI_SCRIPT"
imei_result=$?
if [ $imei_result -eq 0 ]; then
scripts_executed=$(($scripts_executed + 1))
elif [ $imei_result -eq 1 ]; then
has_error=1
fi
# Output appropriate message based on results
if [ $scripts_executed -eq 0 ]; then
output_json "info" "No scripts to restart"
elif [ $has_error -eq 1 ]; then
output_json "error" "Error executing one or more scripts"
else
output_json "success" "Scripts restarted successfully"
fi
}
# Run main function
main

View File

@@ -0,0 +1,11 @@
#!/bin/sh
# Set the content type to JSON
echo "Content-Type: application/json"
echo ""
# Get the IP address of the br-lan interface
brlan_ip=$(ip route | grep 'dev br-lan proto kernel scope link' | awk '{print $9}')
# Output the IP in JSON format
echo "{\"br_lan_ip\": \"$brlan_ip\"}"

View File

@@ -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

View File

@@ -0,0 +1,31 @@
#!/bin/sh
SPEEDTEST_OUTPUT=$(speedtest)
SERVER=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Server: [^(]' | cut -d':' -f2 | tr -d ' ')
SERVER_ID=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'id: [0-9]' | cut -d':' -f2 | tr -d ' ')
ISP=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'ISP: [^(]' | cut -d':' -f2 | tr -d ' ')
IDLE_LATENCY=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Idle Latency: [0-9.] ms' | cut -d':' -f2 | tr -d ' ms')
DOWNLOAD_LATENCY=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Download: [0-9.]* ms' | cut -d':' -f2 | tr -d ' ms')
DOWNLOAD_SPEED=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Download: [0-9.]* Mbps' | cut -d':' -f2 | tr -d ' Mbps')
DOWNLOAD_DATA_USED=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'data used: [0-9.]* MB' | cut -d':' -f2 | tr -d ' MB')
UPLOAD_LATENCY=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Upload: [0-9.]* ms' | cut -d':' -f2 | tr -d ' ms')
UPLOAD_SPEED=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Upload: [0-9.]* Mbps' | cut -d':' -f2 | tr -d ' Mbps')
UPLOAD_DATA_USED=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'data used: [0-9.]* MB' | cut -d':' -f2 | tr -d ' MB')
RESULT_URL=$(echo "$SPEEDTEST_OUTPUT" | grep -o -E 'Result URL: [^.]*' | cut -d':' -f2 | tr -d ' ')
echo "Content-Type: application/json"
echo ""
echo "{
"server": "$SERVER",
"serverId": "$SERVER_ID",
"isp": "$ISP",
"idleLatency": $IDLE_LATENCY,
"downloadLatency": $DOWNLOAD_LATENCY,
"downloadSpeed": $DOWNLOAD_SPEED,
"downloadDataUsed": $DOWNLOAD_DATA_USED,
"uploadLatency": $UPLOAD_LATENCY,
"uploadSpeed": $UPLOAD_SPEED,
"uploadDataUsed": $UPLOAD_DATA_USED,
"resultUrl": "$RESULT_URL"
}"

View File

@@ -1,16 +0,0 @@
#!/bin/sh
echo "Content-type: application/json"
echo ""
# Get RX and TX bytes from ifconfig eth0
data=$(ifconfig eth0 | grep "RX bytes")
# Extract download (RX) and upload (TX) values using awk
download=$(echo $data | awk '{print $2}' | cut -d':' -f2)
upload=$(echo $data | awk '{print $6}' | cut -d':' -f2)
# Return JSON response
echo "{"
echo " \"download\": \"$download\","
echo " \"upload\": \"$upload\""
echo "}"

View File

@@ -1,94 +0,0 @@
#!/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