From e08fdbe279632c634152501ba4b478065cf9739c Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 10:16:30 +0800 Subject: [PATCH 01/10] removed unnecessary console links and ttl files --- simpleadmin/script/sms.sh | 31 +++++++++++ simpleadmin/www/cgi-bin/get_ttl_status.old | 20 ------- simpleadmin/www/cgi-bin/set_ttl.old | 61 ---------------------- 3 files changed, 31 insertions(+), 81 deletions(-) create mode 100644 simpleadmin/script/sms.sh delete mode 100644 simpleadmin/www/cgi-bin/get_ttl_status.old delete mode 100644 simpleadmin/www/cgi-bin/set_ttl.old diff --git a/simpleadmin/script/sms.sh b/simpleadmin/script/sms.sh new file mode 100644 index 0000000..31497cb --- /dev/null +++ b/simpleadmin/script/sms.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# Check if the required parameters are provided +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Assign the provided parameters to variables +phone_number="$1" +message="$2" + +# Send the AT command to set the message format to text mode +echo -ne "AT+CMGF=1\r" > microcom /dev/ttyOUT2 +sleep 1 +echo -ne "AT+CNMI=2,1\r" > microcom /dev/ttyOUT2 +sleep 1 +echo -ne 'AT+CMGS="09938931024"\r' > microcom /dev/ttyOUT2 +sleep 1 + +# Send the message +echo -ne "$message" > microcom /dev/ttyOUT2 +echo -ne "\032" > microcom /dev/ttyOUT2 + +# Wait for the response +sleep 1 + +# Capture and output the response +runcmd=$(microcom /dev/ttyOUT2) +# echo "Content-type: text/plain" +echo "$runcmd" \ No newline at end of file diff --git a/simpleadmin/www/cgi-bin/get_ttl_status.old b/simpleadmin/www/cgi-bin/get_ttl_status.old deleted file mode 100644 index 03d366b..0000000 --- a/simpleadmin/www/cgi-bin/get_ttl_status.old +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Check iptables for ttlvalue -ttlvalue=$(iptables -t mangle -vnL | awk '/TTL/ {print $13; exit}') -ttlenabled=true; - -# Set Variables -if [ -z "${ttlvalue}" ]; then - ttlvalue=0 - ttlenabled=false -fi - -echo "Content-type: text/json" -echo "" -cat </dev/null || true - ip6tables -t mangle -D POSTROUTING -o rmnet+ -j HL --hl-set ${ttlcheck} &>/dev/null || true - fi - - # Echo TTL to file - echo $setTTL > /usrdata/simplefirewall/ttlvalue - - # Set Start Service - /usrdata/simplefirewall/ttl-override start -fi - - - -# Check iptables for ttlvalue -ttlvalue=$(iptables -t mangle -vnL | grep TTL | awk '{print $13}') -ttlenabled=true; - -# Set Variables -if [ -z "${ttlvalue}" ]; then - ttlvalue=0 - ttlenabled=false -fi - -echo "Content-type: text/json" -echo "" -cat < Date: Fri, 10 May 2024 10:18:48 +0800 Subject: [PATCH 02/10] changed simpleadmin version number and repo link --- simpleadmin/www/deviceinfo.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleadmin/www/deviceinfo.html b/simpleadmin/www/deviceinfo.html index 735dddb..940cce6 100644 --- a/simpleadmin/www/deviceinfo.html +++ b/simpleadmin/www/deviceinfo.html @@ -136,7 +136,7 @@ Simple Admin Version - SimpleAdminRev-Alpha-0.3 + SimpleAdminRev-Alpha-0.5 @@ -146,7 +146,7 @@ + @@ -316,7 +320,7 @@ } }" >
+ @@ -356,7 +364,7 @@ }" >
+ @@ -396,7 +408,7 @@ }" >
+ @@ -436,7 +452,7 @@ }" >
+ @@ -476,7 +496,7 @@ }" >
+ @@ -1043,7 +1067,7 @@ let RSRQ_max = -8; // If rsrq is null, return 0% - if (isNaN(rsrq)) { + if (isNaN(rsrq) || rsrq < -20) { return 0; } @@ -1061,7 +1085,7 @@ let RSRP_max = -60; // If rsrp is null, return 0% - if (isNaN(rsrp)) { + if (isNaN(rsrp) || rsrp < -140) { return 0; } @@ -1075,11 +1099,11 @@ }, calculateSINRPercentage(sinr) { - let SINR_min = 0; + let SINR_min = -10; // Changed from 0 let SINR_max = 35; - // If sinr is null or negative, return 0% - if (isNaN(sinr) || sinr < 0) { + // If sinr is null, return 0% + if (isNaN(sinr) || sinr < -10) { return 0; } From 97be66cfe7e0fc8e0b379052053d4bcb77015705 Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 11:29:22 +0800 Subject: [PATCH 05/10] improved some parsing to show relevant info --- simpleadmin/www/index.html | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index a2f2818..fab20c6 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -187,7 +187,15 @@ PCI - + + + IPv4 @@ -243,7 +251,8 @@ CSQ - + + NR-SA Mode CELL ID @@ -259,7 +268,8 @@ RSSI - + + NR-SA Mode SS_RSRQ4G @@ -342,6 +352,9 @@ x-show="rsrqNRPercentage == '0'" x-text="rsrqNR" > + + None + @@ -430,6 +443,9 @@ x-show="rsrpNRPercentage == '0'" x-text="rsrpNR" > + + None + @@ -518,6 +534,9 @@ x-text="sinrNR" x-show="sinrNRPercentage == '0'" > + + None + From 365925b2105e083b3d20c092cdf19ca513d3d2bc Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 11:34:34 +0800 Subject: [PATCH 06/10] updated refresh rate to 3 --- simpleadmin/www/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index fab20c6..acd81a4 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -603,7 +603,7 @@ internetConnection: "Disconnected", lastUpdate: new Date().toLocaleString(), newRefreshRate: null, - refreshRate: 5, + refreshRate: 3, intervalId: null, fetchNetworkInfo() { this.atcmd = @@ -1217,7 +1217,7 @@ // If a refresh rate is stored, use it; otherwise, use a default value this.refreshRate = storedRefreshRate ? parseInt(storedRefreshRate) - : 5; // Change 5 to your desired default value + : 3; // Change 5 to your desired default value this.fetchNetworkInfo(); // sleep for 2 seconds From faae115732a43b1d172e49d70c6c24f21a6eaded Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 11:35:58 +0800 Subject: [PATCH 07/10] changed parsed message from NR-SA to None --- simpleadmin/www/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index acd81a4..093139c 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -252,7 +252,7 @@ CSQ - NR-SA Mode + None CELL ID @@ -269,7 +269,7 @@ RSSI - NR-SA Mode + None SS_RSRQ4G From 30937e20ba76301af43571883b914752ab6e9f17 Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 18:12:26 +0800 Subject: [PATCH 08/10] 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(); - }, }; } From af05f087c70c715790adfe3cce26fa42ed6d68d7 Mon Sep 17 00:00:00 2001 From: Russel Yasol Date: Fri, 10 May 2024 18:18:04 +0800 Subject: [PATCH 09/10] fixed ttl return data parsing --- simpleadmin/www/settings.html | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/simpleadmin/www/settings.html b/simpleadmin/www/settings.html index 6e40946..660e45d 100644 --- a/simpleadmin/www/settings.html +++ b/simpleadmin/www/settings.html @@ -650,37 +650,25 @@ fetch( "/cgi-bin/set_ttl?" + new URLSearchParams({ ttlvalue: ttlval }) ) - .then((res) => res.text()) + .then((res) => res.text()) // Use res.text() instead of res.json() .then((data) => { - // Split the response into JSON and non-JSON parts - const parts = data.trim().split("\n\n"); - const nonJsonPart = parts[0]; - const jsonPart = parts[1]; + // Manually handle the response data + console.log("Response from server:", data); + // You can try to parse the JSON manually or handle the response as needed - // 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 - } + // 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 updating TTL: ", error); this.isLoading = false; // Ensure loading state is properly handled in case of error }); }, + init() { + this.fetchTTL(); + this.fetchCurrentSettings(); + }, }; } From 43e680697f286325cc1fe61dc8e45a5d23dae354 Mon Sep 17 00:00:00 2001 From: iamromulan <50184035+iamromulan@users.noreply.github.com> Date: Fri, 10 May 2024 14:53:31 -0400 Subject: [PATCH 10/10] Make /script/* executable --- simpleupdates/scripts/update_simpleadmin.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/simpleupdates/scripts/update_simpleadmin.sh b/simpleupdates/scripts/update_simpleadmin.sh index 4cbb45a..8a7d245 100644 --- a/simpleupdates/scripts/update_simpleadmin.sh +++ b/simpleupdates/scripts/update_simpleadmin.sh @@ -165,6 +165,7 @@ echo -e "\e[1;31m2) Installing simpleadmin from the $GITTREE branch\e[0m" sleep 1 cd / chmod +x $SIMPLE_ADMIN_DIR/www/cgi-bin/* + chmod +x $SIMPLE_ADMIN_DIR/script/* cp -rf $SIMPLE_ADMIN_DIR/systemd/* /lib/systemd/system sleep 1 systemctl daemon-reload