Ready for version 1.1.2
PR for the main repository, version 1.1.2 with sms_tool as the major change
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
#!/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
|
||||
@@ -1,45 +0,0 @@
|
||||
#!/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 "}"
|
||||
@@ -1,189 +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
|
||||
|
||||
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_profile/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_profile/apn_config.txt << EOF
|
||||
iccidProfile2=$iccidProfile2
|
||||
apnProfile2=$apnProfile2
|
||||
pdpType2=$pdpType2
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Create the apnProfiles.sh script
|
||||
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_profile/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/apn_profile/apnProfiles.sh
|
||||
|
||||
# Add to rc.local if not already present
|
||||
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/apn_profile/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
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
# handle_sms.sh - CGI script to handle SMS web requests
|
||||
# Content type declaration for CGI
|
||||
echo "Content-type: application/json"
|
||||
echo ""
|
||||
|
||||
# Check if atinout and jq are installed
|
||||
if ! command -v atinout &> /dev/null || ! command -v jq &> /dev/null; then
|
||||
echo '{"error": "Required tools (atinout or jq) are not installed"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the device exists
|
||||
if [ ! -c "/dev/smd7" ]; then
|
||||
echo '{"error": "Device /dev/smd7 not found"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# # Fetch all SMS messages and update the JSON file
|
||||
# Disabled until the atinout bug is fixed
|
||||
# if ! echo "AT+CMGL=\"ALL\"" | atinout - /dev/smd7 - | jq -R -s '
|
||||
# split("\n") |
|
||||
# map(select(length > 0)) |
|
||||
# map(
|
||||
# select(startswith("+CMGL:") or (. != "OK" and . != "ERROR"))
|
||||
# ) |
|
||||
# {messages: .}
|
||||
# ' > /tmp/sms_inbox.json; then
|
||||
# echo '{"error": "Failed to fetch SMS messages"}'
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
# Return the contents of the JSON file
|
||||
if [ -f "/tmp/sms_inbox.json" ]; then
|
||||
cat /tmp/sms_inbox.json
|
||||
else
|
||||
echo '{"error": "SMS inbox file not found"}'
|
||||
fi
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/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
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/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 "}"
|
||||
@@ -1,209 +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)
|
||||
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
|
||||
@@ -1,201 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Configuration
|
||||
CONFIG_FILE="/etc/cell_lock_schedule.conf"
|
||||
STATUS_FILE="/tmp/cell_lock_status"
|
||||
CELL_LOCK_SCRIPT="/usr/bin/set_cell_lock.sh"
|
||||
|
||||
# Function to create set_cell_lock.sh script
|
||||
create_cell_lock_script() {
|
||||
# Only create the script if it doesn't exist
|
||||
if [ ! -f "$CELL_LOCK_SCRIPT" ]; then
|
||||
cat >"$CELL_LOCK_SCRIPT" <<'EOL'
|
||||
#!/bin/sh
|
||||
ACTION=$1
|
||||
LTE_PARAMS=$2
|
||||
NR5G_PARAMS=$3
|
||||
|
||||
case "$ACTION" in
|
||||
enable)
|
||||
# Enable LTE lock if parameters exist
|
||||
if [ -n "$LTE_PARAMS" ]; then
|
||||
echo "AT+QNWLOCK=\"common/4g\",$LTE_PARAMS" | atinout - /dev/smd11 -
|
||||
fi
|
||||
|
||||
# Enable NR5G lock if parameters exist
|
||||
if [ -n "$NR5G_PARAMS" ]; then
|
||||
echo "AT+QNWLOCK=\"common/5g\",$NR5G_PARAMS" | atinout - /dev/smd11 -
|
||||
fi
|
||||
;;
|
||||
|
||||
disable)
|
||||
# Disable LTE lock
|
||||
echo 'AT+QNWLOCK="common/4g",0' | atinout - /dev/smd11 -
|
||||
|
||||
# Disable NR5G lock
|
||||
echo 'AT+QNWLOCK="common/5g",0' | atinout - /dev/smd11 -
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Invalid action"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Restart network registration to apply changes
|
||||
echo "AT+COPS=2" | atinout - /dev/smd11 -
|
||||
sleep 2
|
||||
echo "AT+COPS=0" | atinout - /dev/smd11 -
|
||||
exit 0
|
||||
EOL
|
||||
|
||||
# Make the script executable
|
||||
chmod +x "$CELL_LOCK_SCRIPT"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to remove set_cell_lock.sh script
|
||||
remove_cell_lock_script() {
|
||||
if [ -f "$CELL_LOCK_SCRIPT" ]; then
|
||||
rm "$CELL_LOCK_SCRIPT"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to urldecode
|
||||
urldecode() {
|
||||
echo -e "$(echo "$1" | sed 's/+/ /g;s/%\([0-9A-F][0-9A-F]\)/\\x\1/g')"
|
||||
}
|
||||
|
||||
# Function to convert HH:MM to cron format
|
||||
convert_to_cron_time() {
|
||||
echo "$1" | awk -F: '{print $2, $1}'
|
||||
}
|
||||
|
||||
# Function to save configuration
|
||||
save_config() {
|
||||
echo "START_TIME=$1" >"$CONFIG_FILE"
|
||||
echo "END_TIME=$2" >>"$CONFIG_FILE"
|
||||
echo "ENABLED=1" >>"$CONFIG_FILE"
|
||||
}
|
||||
|
||||
# Function to disable scheduling
|
||||
disable_scheduling() {
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
sed -i 's/ENABLED=1/ENABLED=0/' "$CONFIG_FILE"
|
||||
fi
|
||||
# Remove any existing cron jobs
|
||||
crontab -l | grep -v "set_cell_lock.sh" | crontab -
|
||||
# Remove the set_cell_lock.sh script
|
||||
remove_cell_lock_script
|
||||
}
|
||||
|
||||
# Function to get current status
|
||||
get_status() {
|
||||
if [ -f "$CONFIG_FILE" ]; then
|
||||
ENABLED=$(grep "ENABLED=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
START_TIME=$(grep "START_TIME=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
END_TIME=$(grep "END_TIME=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||
|
||||
echo "Status: 200 OK"
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
echo "{\"enabled\":$ENABLED,\"start_time\":\"$START_TIME\",\"end_time\":\"$END_TIME\"}"
|
||||
else
|
||||
echo "Status: 200 OK"
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
echo "{\"enabled\":0,\"start_time\":\"\",\"end_time\":\"\"}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle POST requests
|
||||
if [ "$REQUEST_METHOD" = "POST" ]; then
|
||||
# Read POST data
|
||||
read -r POST_DATA
|
||||
|
||||
# Check if disabling is requested
|
||||
echo "$POST_DATA" | grep -q "disable=true"
|
||||
if [ $? -eq 0 ]; then
|
||||
disable_scheduling
|
||||
echo "Status: 200 OK"
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
echo "{\"status\":\"success\",\"message\":\"Scheduling disabled\"}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Extract start and end times
|
||||
START_TIME=$(echo "$POST_DATA" | grep -o 'start_time=[^&]*' | cut -d'=' -f2)
|
||||
END_TIME=$(echo "$POST_DATA" | grep -o 'end_time=[^&]*' | cut -d'=' -f2)
|
||||
|
||||
# Decode times
|
||||
START_TIME=$(urldecode "$START_TIME")
|
||||
END_TIME=$(urldecode "$END_TIME")
|
||||
|
||||
# Validate times
|
||||
if [ -z "$START_TIME" ] || [ -z "$END_TIME" ]; then
|
||||
echo "Status: 400 Bad Request"
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
echo "{\"error\":\"Missing start or end time\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create set_cell_lock.sh script
|
||||
create_cell_lock_script
|
||||
|
||||
# Convert times to cron format
|
||||
CRON_START=$(convert_to_cron_time "$START_TIME")
|
||||
CRON_END=$(convert_to_cron_time "$END_TIME")
|
||||
|
||||
# Save configuration
|
||||
save_config "$START_TIME" "$END_TIME"
|
||||
|
||||
# Check current cell lock status and get parameters
|
||||
LTE_STATUS=$(echo 'AT+QNWLOCK="common/4g"' | atinout - /dev/smd11 -)
|
||||
NR5G_STATUS=$(echo 'AT+QNWLOCK="common/5g"' | atinout - /dev/smd11 -)
|
||||
|
||||
# Extract LTE parameters if locked
|
||||
LTE_PARAMS=$(echo "$LTE_STATUS" | grep -o '"common/4g",[^[:space:]]*' | cut -d',' -f2-)
|
||||
NR5G_PARAMS=$(echo "$NR5G_STATUS" | grep -o '"common/5g",[^[:space:]]*' | cut -d',' -f2-)
|
||||
|
||||
# Create temporary file for new crontab
|
||||
TEMP_CRON=$(mktemp)
|
||||
|
||||
# Get existing crontab entries (excluding our script)
|
||||
crontab -l 2>/dev/null | grep -v "set_cell_lock.sh" >"$TEMP_CRON"
|
||||
|
||||
# Add new entries
|
||||
echo "$CRON_START * * * $CELL_LOCK_SCRIPT enable \"$LTE_PARAMS\" \"$NR5G_PARAMS\"" >>"$TEMP_CRON"
|
||||
echo "$CRON_END * * * $CELL_LOCK_SCRIPT disable" >>"$TEMP_CRON"
|
||||
|
||||
# Install new crontab
|
||||
crontab "$TEMP_CRON"
|
||||
rm "$TEMP_CRON"
|
||||
|
||||
echo "Status: 200 OK"
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
echo "{\"status\":\"success\",\"message\":\"Scheduling enabled\"}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Parse query string for GET requests
|
||||
if [ "$REQUEST_METHOD" = "GET" ]; then
|
||||
QUERY_STRING=$(echo "$QUERY_STRING" | sed 's/&/\n/g')
|
||||
for param in $QUERY_STRING; do
|
||||
case "$param" in
|
||||
status=*)
|
||||
get_status
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
# If no valid request is made
|
||||
echo "Status: 400 Bad Request"
|
||||
echo "Content-Type: application/json"
|
||||
echo ""
|
||||
echo "{\"error\":\"Invalid request\"}"
|
||||
exit 1
|
||||
Reference in New Issue
Block a user