diff --git a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/delete-profile.sh b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/delete-profile.sh index 6bc8aae..abed318 100644 --- a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/delete-profile.sh +++ b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/delete-profile.sh @@ -18,8 +18,8 @@ append_error() { } # Remove the entire quecmanager directory -if [ -d "/etc/quecmanager" ]; then - rm -rf /etc/quecmanager +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 diff --git a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/fetch-profile.sh b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/fetch-profile.sh index 3d1955e..0b79f48 100644 --- a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/fetch-profile.sh +++ b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/fetch-profile.sh @@ -3,7 +3,7 @@ echo "Content-type: application/json" echo "" -CONFIG_FILE="/etc/quecmanager/apn_config.txt" +CONFIG_FILE="/etc/quecmanager/apn_profile/apn_config.txt" if [ ! -f "$CONFIG_FILE" ]; then echo "{}" diff --git a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/save-profile.sh b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/save-profile.sh index 93cb25b..d790464 100644 --- a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/save-profile.sh +++ b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/apn-profiles/save-profile.sh @@ -33,12 +33,12 @@ if [ -z "$iccidProfile1" ] || [ -z "$apnProfile1" ] || [ -z "$pdpType1" ]; then exit 1 fi -if [ ! -d /etc/quecmanager ]; then - 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 @@ -46,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 @@ -54,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 @@ -164,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 diff --git a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/delete-profile.sh b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/delete-profile.sh index b3a2d0f..d097cae 100644 --- a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/delete-profile.sh +++ b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/delete-profile.sh @@ -18,8 +18,8 @@ append_error() { } # Remove the entire quecmanager directory -if [ -d "/etc/quecmanager" ]; then - rm -rf /etc/quecmanager +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 diff --git a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/fetch-profile.sh b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/fetch-profile.sh new file mode 100644 index 0000000..82751b5 --- /dev/null +++ b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/fetch-profile.sh @@ -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 "}" \ No newline at end of file diff --git a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/save-profile.sh b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/save-profile.sh index 8f1f2c1..6ec04ef 100644 --- a/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/save-profile.sh +++ b/ipk-source/sdxpinn-quecmanager-beta/root/www/cgi-bin/cell-settings/imei-profiles/save-profile.sh @@ -30,32 +30,32 @@ if [ -z "$iccidProfile1" ] || [ -z "$imeiProfile1" ]; then fi # Check the directory if it exists, if not create it -if [ ! -d /etc/quecmanager ]; then - mkdir -p /etc/quecmanager +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_config.txt << EOF +cat >/etc/quecmanager/imei_profile/imei_config.txt <> /etc/quecmanager/imei_config.txt << EOF + cat >>/etc/quecmanager/imei_profile/imei_config.txt < /etc/quecmanager/imeiProfiles.sh << 'EOF' +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_config.txt | cut -d'=' -f2 + grep "^${key}=" /etc/quecmanager/imei_profile/imei_config.txt | cut -d'=' -f2 } # Read configuration @@ -108,6 +108,21 @@ get_current_iccid() { 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" @@ -127,45 +142,63 @@ set_imei() { fi } -# Get current ICCID +# 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 set_imei "$imeiProfile1"; 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 set_imei "$imeiProfile2"; 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 set successfully" > /tmp/imei_result.txt + echo "IMEI check/update completed successfully" > /tmp/imei_result.txt else - echo "Failed to set IMEI" > /tmp/imei_result.txt + echo "Failed to check/update IMEI" > /tmp/imei_result.txt fi EOF # Make the script executable -chmod +x /etc/quecmanager/imeiProfiles.sh +chmod +x /etc/quecmanager/imei_profile/imeiProfiles.sh # Add to rc.local if not already present -if ! grep -q "/etc/quecmanager/imeiProfiles.sh" /etc/rc.local; then - sed -i '/^exit 0/i /etc/quecmanager/imeiProfiles.sh' /etc/rc.local +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/imeiProfiles.sh +/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 @@ -173,4 +206,4 @@ if [ -f /tmp/imei_result.txt ]; then fi else echo '{"status": "error", "message": "Something went wrong while processing IMEI profiles"}' -fi \ No newline at end of file +fi