From 30937e20ba76301af43571883b914752ab6e9f17 Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 18:12:26 +0800 Subject: [PATCH] added ttl log to console --- simpleadmin/www/cgi-bin/set_ttl | 64 ++++++++++++++++++++------------- simpleadmin/www/index.html | 14 +++++--- simpleadmin/www/settings.html | 55 +++++++++++++++++----------- 3 files changed, 84 insertions(+), 49 deletions(-) diff --git a/simpleadmin/www/cgi-bin/set_ttl b/simpleadmin/www/cgi-bin/set_ttl index cf2bb55..0d6402a 100644 --- a/simpleadmin/www/cgi-bin/set_ttl +++ b/simpleadmin/www/cgi-bin/set_ttl @@ -1,5 +1,13 @@ #!/bin/bash -PATH=/bin:/usr/sbin:/usr/bin:/sbin:/opt/sbin:/opt/bin:/usrdata/root/bin + +# Debug log function +log_debug() { + local message="$1" + debug_logs+=("$message") +} + +# Initialize debug logs array +declare -a debug_logs=() # Get query QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g') @@ -10,38 +18,44 @@ if [ "${QUERY_STRING}" ]; then key=$(echo $cmd | awk -F '=' '{print $1}') value=$(echo $cmd | awk -F '=' '{print $2}') eval $key=$value + log_debug "Received parameter: $key=$value" fi done fi -# Convert ttlvalue to integer -if [ "${ttlvalue}" ]; then - ttlvalue_int=$(echo "${ttlvalue}" | sed 's/[^0-9]*//g') +setTTL=$(printf '%b\n' "${ttlvalue//%/\\x}") +if [ -n "${setTTL}" ]; then + log_debug "Stopping service to remove rules" + /usrdata/simplefirewall/ttl-override stop + + # Convert ttlvalue to integer + if [ "${ttlvalue}" ]; then + ttlvalue_int=$(echo "${ttlvalue}" | sed 's/[^0-9]//g') + log_debug "Converted ttlvalue to integer: $ttlvalue_int" + fi + + # Call the sh script with the appropriate parameters + if [ "${ttlvalue_int}" != 0 ]; then + log_debug "Enabling TTL with value: ${setTTL}" + /usrdata/simpleadmin/script/ttl_script.sh enable "${setTTL}" + commandRan="/usrdata/simpleadmin/script/ttl_script.sh enable ${setTTL}" + ttlenabled=true + ttlvalue=$ttlvalue_int + elif [ "${ttlvalue_int}" = 0 ]; then + log_debug "Disabling TTL" + /usrdata/simpleadmin/script/ttl_script.sh disable 0 + commandRan="/usrdata/simpleadmin/script/ttl_script.sh disable 0" + ttlenabled=false + ttlvalue=0 + fi fi -# Call the sh script with the appropriate parameters. If ttlvalue_int is not 0, then enable the script with the value of ttlvalue_int. If ttlvalue is disable, then disable the script. - -if [ "${ttlvalue_int}" != 0 ]; then - /usrdata/simpleadmin/script/ttl_script.sh enable "${ttlvalue_int}" - # Set ttlenabled to true - ttlenabled=true - # Set ttlvalue to the value of ttlvalue_int - ttlvalue=$ttlvalue_int -elif [ "${ttlvalue_int}" = 0 ]; then - /usrdata/simpleadmin/script/ttl_script.sh disable 0 - # Set ttlenabled to false - ttlenabled=false - # Set ttlvalue to 0 - ttlvalue=0 -fi - -# Output the result in JSON format - -echo "Content-type: text/json" +echo "Content-type: text/text" echo "" cat < - + IPv4 @@ -311,6 +308,9 @@ x-show="rsrqLTEPercentage == '0'" x-text="rsrqLTE" > + + None + @@ -399,6 +399,9 @@ x-show="rsrpLTEPercentage == '0'" x-text="rsrpLTE" > + + None + @@ -490,6 +493,9 @@ x-text="sinrLTE" x-show="sinrLTEPercentage == '0'" > + + None + diff --git a/simpleadmin/www/settings.html b/simpleadmin/www/settings.html index 3dbc4dd..6e40946 100644 --- a/simpleadmin/www/settings.html +++ b/simpleadmin/www/settings.html @@ -6,9 +6,9 @@ Simple Admin - + - + @@ -101,7 +101,7 @@ placeholder="ATI" aria-describedby="atCommandInput" x-model="atcmd" - @keydown.enter = "sendATCommand()" + @keydown.enter="sendATCommand()" />
Seperate multiple commands with comma (,). @@ -554,21 +554,24 @@ case "LTE": this.atcmd = "AT+QSCAN=1,1"; this.scanStart = true; - this.atCommandResponse = "Scanning all available LTE networks... This might take a while." + this.atCommandResponse = + "Scanning all available LTE networks... This might take a while."; this.sendATCommand(); this.scanStart = false; break; case "NR5G": this.atcmd = "AT+QSCAN=2,1"; this.scanStart = true; - this.atCommandResponse = "Scanning all available NR5G-SA networks... This might take a while." + this.atCommandResponse = + "Scanning all available NR5G-SA networks... This might take a while."; this.sendATCommand(); this.scanStart = false; break; case "ALL": this.atcmd = "AT+QSCAN=3,1"; this.scanStart = true; - this.atCommandResponse = "Scanning all available networks... This might take a while." + this.atCommandResponse = + "Scanning all available networks... This might take a while."; this.sendATCommand(); this.scanStart = false; break; @@ -643,29 +646,41 @@ setTTL() { this.isLoading = true; // Set loading state while updating TTL - + const ttlval = this.newTTL; fetch( - "/cgi-bin/set_ttl?" + - new URLSearchParams({ - ttlvalue: this.newTTL, - }) + "/cgi-bin/set_ttl?" + new URLSearchParams({ ttlvalue: ttlval }) ) - .then((res) => res.json()) + .then((res) => res.text()) .then((data) => { - // Once TTL is updated, fetch the updated TTL data - this.fetchTTL(); - this.isLoading = false; // Set loading state back to false + // Split the response into JSON and non-JSON parts + const parts = data.trim().split("\n\n"); + const nonJsonPart = parts[0]; + const jsonPart = parts[1]; + + // Log the non-JSON part + console.log("Non-JSON response:", nonJsonPart); + + // Parse the JSON part + try { + const jsonData = JSON.parse(jsonPart); + console.log("JSON response:", jsonData); + + // Handle the JSON data as needed + // ... + + // Once TTL is updated, fetch the updated TTL data + this.fetchTTL(); + this.isLoading = false; // Set loading state back to false + } catch (error) { + console.error("Error parsing JSON:", error); + this.isLoading = false; // Ensure loading state is properly handled in case of error + } }) .catch((error) => { console.error("Error updating TTL: ", error); this.isLoading = false; // Ensure loading state is properly handled in case of error }); }, - - init() { - this.fetchTTL(); - this.fetchCurrentSettings(); - }, }; }