Update QuecManager to 0.0.9
- Added MTU settings - Added no SIM detected message Co-Authored-By: Russel Yasol <73575327+dr-dolomite@users.noreply.github.com>
This commit is contained in:
90
ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/advance/mtu.sh
Executable file
90
ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/advance/mtu.sh
Executable 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
|
||||
@@ -26,6 +26,9 @@ ping_interval=$(echo "$QUERY_STRING" | grep -o 'ping_interval=[^&]*' | cut -d= -
|
||||
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")
|
||||
@@ -34,6 +37,9 @@ 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"
|
||||
@@ -50,15 +56,31 @@ initialize_config() {
|
||||
# Create config directory if not exists
|
||||
mkdir -p "${CONFIG_DIR}"
|
||||
|
||||
# Write configuration with defaults
|
||||
# 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}
|
||||
CONNECTION_REFRESH=${connection_refresh:-false}
|
||||
# Current retry count (should start at 0)
|
||||
CURRENT_RETRIES=0
|
||||
REFRESH_COUNT=${connection_refresh:+1}
|
||||
# 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
|
||||
|
||||
@@ -90,12 +112,111 @@ update_retry_count() {
|
||||
. /etc/quecmanager/quecwatch/quecwatch.conf
|
||||
}
|
||||
|
||||
# Initialize failure and retry counters
|
||||
failure_count=0
|
||||
retry_trigger=0
|
||||
# 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}
|
||||
}
|
||||
|
||||
# Ensure CURRENT_RETRIES starts at 0
|
||||
update_retry_count 0
|
||||
# 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
|
||||
@@ -126,45 +247,63 @@ while true; do
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Connection refresh logic
|
||||
if [ "${CONNECTION_REFRESH}" = "true" ] && [ "${REFRESH_COUNT}" -gt 0 ]; then
|
||||
# Decrement refresh count
|
||||
. /etc/quecmanager/quecwatch/quecwatch.conf
|
||||
REFRESH_COUNT=$((REFRESH_COUNT - 1))
|
||||
|
||||
# Update config
|
||||
sed -i "s/REFRESH_COUNT=.*/REFRESH_COUNT=${REFRESH_COUNT}/" /etc/quecmanager/quecwatch/quecwatch.conf
|
||||
|
||||
log_event "Attempting connection refresh"
|
||||
# Add your modem connection refresh command here
|
||||
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 failed. Continuing with retry process."
|
||||
# Continue with retry process, no premature reboot or script removal
|
||||
else
|
||||
log_event "Connection refresh successful"
|
||||
# Reset retry trigger if connection is restored
|
||||
retry_trigger=0
|
||||
failure_count=0
|
||||
update_retry_count 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
|
||||
# Perform modem reboot
|
||||
log_event "Rebooting modem. Retry attempts: ${retry_trigger}"
|
||||
# Add your modem reboot command here
|
||||
reboot
|
||||
# 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
|
||||
log_event "Modem is connected to the internet"
|
||||
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
|
||||
@@ -206,9 +345,12 @@ enable_quecwatch() {
|
||||
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
|
||||
exit 0
|
||||
|
||||
@@ -34,6 +34,16 @@ 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
|
||||
@@ -59,7 +69,10 @@ cat <<EOF
|
||||
"maxRetries": ${max_retries},
|
||||
"currentRetries": ${current_retries},
|
||||
"connectionRefresh": ${connection_refresh},
|
||||
"refreshCount": ${refresh_count:-0}
|
||||
"refreshCount": ${refresh_count:-0},
|
||||
"mobileDataReconnect": ${mobile_data_reconnect},
|
||||
"autoSimFailover": ${auto_sim_failover},
|
||||
"simFailoverSchedule": ${sim_failover_schedule}
|
||||
},
|
||||
"lastActivity": "${last_log}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user