Combine Dependencies; Other Improvements
-Removed CPU intensive python based telnet server option -Removed Micropython -Renamed AT Telnet Daemon socat-at bridge -Moved TTL related files not part of the www/cgi-bin directory to /simplefirewall -Improved Simplefirewall menu, added ability to change TTL -Combined uninstall and install functions for simpleadmin and dependencies into single functions
This commit is contained in:
101
ttyd/scripts/ICCID_APN.sh
Normal file
101
ttyd/scripts/ICCID_APN.sh
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Configuration
|
||||
DEVICE_FILE="/dev/smd7"
|
||||
ICCID_FILE="/path/to/iccid_master_file" # Path to the ICCID-APN-IPType master file
|
||||
TMP_DIR="/tmp"
|
||||
TIMEOUT=4
|
||||
|
||||
# Start listening to device file
|
||||
start_listening() {
|
||||
cat "$DEVICE_FILE" > "$TMP_DIR/device_readout" &
|
||||
CAT_PID=$!
|
||||
}
|
||||
|
||||
# Send AT command
|
||||
send_at_command() {
|
||||
local command=$1
|
||||
echo -e "${command}\r" > "$DEVICE_FILE"
|
||||
}
|
||||
|
||||
# Wait for and process response
|
||||
wait_for_response() {
|
||||
local start_time=$(date +%s)
|
||||
local current_time
|
||||
local elapsed_time
|
||||
|
||||
while true; do
|
||||
if grep -q "OK" "$TMP_DIR/device_readout" || grep -q "ERROR" "$TMP_DIR/device_readout"; then
|
||||
RESPONSE=$(cat "$TMP_DIR/device_readout")
|
||||
echo "Response received: $RESPONSE"
|
||||
return 0
|
||||
fi
|
||||
current_time=$(date +%s)
|
||||
elapsed_time=$((current_time - start_time))
|
||||
if [ "$elapsed_time" -ge "$TIMEOUT" ]; then
|
||||
echo "Error: Response timed out."
|
||||
return 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
kill "$CAT_PID"
|
||||
wait "$CAT_PID" 2>/dev/null
|
||||
rm -f "$TMP_DIR/device_readout"
|
||||
}
|
||||
|
||||
# Function to send AT command and wait for response
|
||||
send_and_wait() {
|
||||
send_at_command "$1"
|
||||
wait_for_response
|
||||
}
|
||||
|
||||
# Function to update the APN
|
||||
update_apn() {
|
||||
local slot=$1
|
||||
local apn=$2
|
||||
local iptype=$3
|
||||
send_and_wait "AT+CGDCONT=$slot,\"$iptype\",\"$apn\""
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "APN updated successfully."
|
||||
else
|
||||
echo "Failed to update APN."
|
||||
fi
|
||||
}
|
||||
|
||||
# Main Execution
|
||||
if [ -c "$DEVICE_FILE" ]; then
|
||||
start_listening
|
||||
|
||||
# Get ICCID
|
||||
send_and_wait "AT+CCID"
|
||||
ICCID=$(echo "$RESPONSE" | grep "+CCID" | cut -d ':' -f2 | tr -d '[:space:]')
|
||||
echo "ICCID: $ICCID"
|
||||
|
||||
# Check ICCID in master file
|
||||
if grep -q "$ICCID" "$ICCID_FILE"; then
|
||||
APN=$(grep "$ICCID" "$ICCID_FILE" | cut -d ',' -f2)
|
||||
IP_TYPE=$(grep "$ICCID" "$ICCID_FILE" | cut -d ',' -f3)
|
||||
IP_TYPE=${IP_TYPE:-"IPV4V6"} # Default to IPV4V6 if not specified
|
||||
|
||||
# Get current APN settings
|
||||
send_and_wait "AT+CGDCONT?"
|
||||
CURRENT_APN=$(echo "$RESPONSE" | grep "+CGDCONT: 1" | cut -d ',' -f3 | tr -d '"')
|
||||
|
||||
# Compare and update APN if necessary
|
||||
if [ "$APN" != "$CURRENT_APN" ]; then
|
||||
update_apn 1 "$APN" "$IP_TYPE"
|
||||
else
|
||||
echo "No APN update needed."
|
||||
fi
|
||||
else
|
||||
echo "ICCID not found in the master file."
|
||||
fi
|
||||
|
||||
cleanup
|
||||
else
|
||||
echo "Error: Device $DEVICE_FILE does not exist or is not a character special file."
|
||||
fi
|
||||
21
ttyd/scripts/ICCIDfun.sh
Normal file
21
ttyd/scripts/ICCIDfun.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
edit_iccid_file() {
|
||||
local iccid_file="/path/to/iccid_master_file" # Path to the ICCID-APN-IPType master file
|
||||
|
||||
echo "Enter ICCID to add or edit:"
|
||||
read iccid
|
||||
echo "Enter APN for $iccid:"
|
||||
read apn
|
||||
echo "Enter IP Type (IPV4, IPV6, IPV4V6) for $iccid [Default: IPV4V6]:"
|
||||
read iptype
|
||||
iptype=${iptype:-"IPV4V6"} # Default to IPV4V6 if not specified
|
||||
|
||||
# Check if ICCID already exists
|
||||
if grep -q "$iccid" "$iccid_file"; then
|
||||
# Update existing ICCID's APN and IP Type
|
||||
sed -i "/$iccid/c\\$iccid,$apn,$iptype" "$iccid_file"
|
||||
else
|
||||
# Add new ICCID, APN, and IP Type
|
||||
echo "$iccid,$apn,$iptype" >> "$iccid_file"
|
||||
fi
|
||||
echo "ICCID file updated."
|
||||
}
|
||||
Reference in New Issue
Block a user