diff --git a/simpleadmin/script/create_watchcat.sh b/simpleadmin/script/create_watchcat.sh new file mode 100644 index 0000000..087f2c7 --- /dev/null +++ b/simpleadmin/script/create_watchcat.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# Function to create and run the Watchcat script +create_and_run_watchcat_script() { + local ip=$1 + local timeout=$2 + local failure_count=$3 + local script_path="/usrdata/simpleadmin/script/watchcat.sh" + + # Create the script with the watchcat logic + sudo cat << EOF > $script_path +#!/bin/sh + +failures=0 + +while :; do + if ping -c 1 $ip > /dev/null 2>&1; then + failures=0 + else + failures=\$((failures + 1)) + if [ "\$failures" -ge "$failure_count" ]; then + echo "Rebooting system due to \$failures consecutive ping failures." + /sbin/reboot + exit 0 + fi + fi + sleep $timeout +done +EOF + + # Make the watchcat script executable + chmod +x $script_path + + # Create a JSON to be fetched later + echo "{\"enabled\": true, \"track_ip\": \"$ip\", \"ping_timeout\": $timeout, \"ping_failure_count\": $failure_count}" > /usrdata/simpleadmin/script/watchcat.json + + # Check if the script was created successfully + if [ -f "$script_path" ]; then + # Make the script executable + chmod +x "$script_path" + + # Run the script in the background + # nohup /bin/sh "$script_path" & + /bin/sh "$script_path" & + + echo "Watchcat script created and running." + else + echo "Failed to create the Watchcat script." + echo "Please check the script path: $script_path" + fi +} + +# Check if the script is called with the required parameters +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Call the function with the provided arguments +create_and_run_watchcat_script "$1" "$2" "$3" \ No newline at end of file diff --git a/simpleadmin/script/remove_watchcat.sh b/simpleadmin/script/remove_watchcat.sh new file mode 100644 index 0000000..a217cb7 --- /dev/null +++ b/simpleadmin/script/remove_watchcat.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +# Function to remove the Watchcat script and JSON file +remove_watchcat_script() { + local script_path="/usrdata/simpleadmin/script/watchcat.sh" + local json_path="/usrdata/simpleadmin/script/watchcat.json" + + # Mount as read-write + mount -o remount,rw / + + # Remove the watchcat script if it exists + if [ -f "$script_path" ]; then + rm "$script_path" + echo "Removed $script_path" + else + echo "$script_path does not exist" + fi + + # Remove the JSON file if it exists + if [ -f "$json_path" ]; then + rm "$json_path" + echo "Removed $json_path" + else + echo "$json_path does not exist" + fi + + # Mount as read-only + mount -o remount,ro / +} + +# Call the function to remove the scripts +remove_watchcat_script \ No newline at end of file diff --git a/simpleadmin/www/cgi-bin/get_watchcat_status b/simpleadmin/www/cgi-bin/get_watchcat_status index 7180948..de30718 100644 --- a/simpleadmin/www/cgi-bin/get_watchcat_status +++ b/simpleadmin/www/cgi-bin/get_watchcat_status @@ -4,15 +4,14 @@ echo "Content-type: application/json" echo "" -# This script fetches the watchCat parameters from the /tmp/watchCatParams.json file and returns it as JSON +# This script fetches the watchCat parameters from the /tmp/watchcat.json and returns it as JSON +# Example content of /tmp/watchcat: +# {"watchcat": {"enabled": true, "track_ip": "1.1.1.1", "ping_timeout": 30, "ping_failure_count": 10}} # Check if the file exists -if [ -f /tmp/watchCatParams.json ]; then - # Read the file and return the content - cat /tmp/watchCatParams.json +if [ -f /tmp/watchcat.json ]; then + cat /tmp/watchcat.json else - # Return an empty JSON object + # return an empty JSON object echo "{}" fi - -exit 0 \ No newline at end of file diff --git a/simpleadmin/www/cgi-bin/set_ttl b/simpleadmin/www/cgi-bin/set_ttl index 0d6402a..ce4f910 100644 --- a/simpleadmin/www/cgi-bin/set_ttl +++ b/simpleadmin/www/cgi-bin/set_ttl @@ -48,6 +48,9 @@ if [ -n "${setTTL}" ]; then ttlenabled=false ttlvalue=0 fi + + log_debug "Starting service to apply rules" + /usrdata/simplefirewall/ttl-override start fi echo "Content-type: text/text" diff --git a/simpleadmin/www/cgi-bin/watchcat_maker b/simpleadmin/www/cgi-bin/watchcat_maker new file mode 100644 index 0000000..23ea3aa --- /dev/null +++ b/simpleadmin/www/cgi-bin/watchcat_maker @@ -0,0 +1,72 @@ +#!/bin/bash + +# Decode URL-encoded strings +function urldecode() { + local data=${1//+/ } + printf '%b' "${data//%/\\x}" +} + +# Parse QUERY_STRING +QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g') +if [ "${QUERY_STRING}" ]; then + export IFS="&" + for cmd in ${QUERY_STRING}; do + if [[ "$cmd" == *"="* ]]; then + key=$(echo $cmd | awk -F '=' '{print $1}') + value=$(echo $cmd | awk -F '=' '{print $2}') + eval $key=$(urldecode $value) + fi + done +fi + +# Set default values +WATCHCAT_ENABLED=${WATCHCAT_ENABLED:-"disable"} +TRACK_IP=${TRACK_IP:-"1.1.1.1"} +PING_TIMEOUT=${PING_TIMEOUT:-30} +PING_FAILURE_COUNT=${PING_FAILURE_COUNT:-3} + +# Validate input +if ! [[ "$WATCHCAT_ENABLED" =~ ^(enable|disable)$ ]]; then + echo "Content-type: text/plain" + echo "" + echo "Invalid value for WATCHCAT_ENABLED. Use 'enable' or 'disable'." + exit 1 +fi + +if ! [[ "$TRACK_IP" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then + echo "Content-type: text/plain" + echo "" + echo "Invalid IP address format for TRACK_IP." + exit 1 +fi + +if ! [[ "$PING_TIMEOUT" =~ ^[0-9]+$ ]] || [ "$PING_TIMEOUT" -le 0 ]; then + echo "Content-type: text/plain" + echo "" + echo "PING_TIMEOUT must be a positive integer." + exit 1 +fi + +if ! [[ "$PING_FAILURE_COUNT" =~ ^[0-9]+$ ]] || [ "$PING_FAILURE_COUNT" -le 0 ]; then + echo "Content-type: text/plain" + echo "" + echo "PING_FAILURE_COUNT must be a positive integer." + exit 1 +fi + +# Implement the Watchcat logic +if [ "$WATCHCAT_ENABLED" == "enable" ]; then + echo "Content-type: text/plain" + echo "" + echo "Watchcat is enabled. Tracking IP: $TRACK_IP, Ping timeout: $PING_TIMEOUT seconds, Ping failure count: $PING_FAILURE_COUNT" + # Call the create script here and use the needed parameters + sudo /usrdata/simpleadmin/script/create_watchcat.sh "$TRACK_IP" "$PING_TIMEOUT" "$PING_FAILURE_COUNT" +else + echo "Content-type: text/plain" + echo "" + echo "Watchcat is disabled." + # Call the remove script here + sudo /usrdata/simpleadmin/script/remove_watchcat.sh +fi + +exit 0 \ No newline at end of file diff --git a/simpleadmin/www/deviceinfo.html b/simpleadmin/www/deviceinfo.html index 985c3e1..95bbb15 100644 --- a/simpleadmin/www/deviceinfo.html +++ b/simpleadmin/www/deviceinfo.html @@ -45,6 +45,9 @@ + diff --git a/simpleadmin/www/index.html b/simpleadmin/www/index.html index 94166c0..cc64fd7 100644 --- a/simpleadmin/www/index.html +++ b/simpleadmin/www/index.html @@ -50,6 +50,9 @@ + @@ -275,6 +278,10 @@ Assesment + + Traffic Stats + + CSQ @@ -292,14 +299,12 @@ TAC4G/5G - + + SS_RSRQ4G - + SS_RSRQ5G + RSRP4G - + SS_RSRP5G - + SINR4G - + SINR5G line.includes('+QENG: "servingcell"')) .split(",")[2] .replace(/"/g, ""); - + const duplex_mode = lines .find((line) => line.includes('+QENG: "servingcell"')) .split(",")[3] @@ -842,7 +843,10 @@ } // --- Bandwidth --- - if (this.networkMode == "5G SA TDD" || this.networkMode == "5G SA FDD") { + if ( + this.networkMode == "5G SA TDD" || + this.networkMode == "5G SA FDD" + ) { // find this example value from lines "+QENG: \"servingcell\" const bandwidth_line = lines.find((line) => line.includes('+QENG: "servingcell"') @@ -906,7 +910,10 @@ } // --- E/ARFCN --- - if (this.networkMode == "5G SA TDD" || this.networkMode == "5G SA FDD") { + if ( + this.networkMode == "5G SA TDD" || + this.networkMode == "5G SA FDD" + ) { // find this value from lines "+QCAINFO: \"PCC\" const nr_pcc_arfcn = lines .find((line) => line.includes('+QCAINFO: "PCC"')) @@ -998,7 +1005,10 @@ } // --- PCI --- - if (this.networkMode == "5G SA TDD" || this.networkMode == "5G SA FDD") { + if ( + this.networkMode == "5G SA TDD" || + this.networkMode == "5G SA FDD" + ) { const nr_pcc_pci = lines .find((line) => line.includes('+QCAINFO: "PCC"')) .split(",")[4]; @@ -1111,6 +1121,44 @@ .split(",")[4] .replace(/"/g, ""); + // Traffic Stats + // for NR traffic stats: +QGDNRCNT: 3263753367,109876105 + this.nrDownload = lines + .find((line) => line.includes("+QGDNRCNT:")) + .split(",")[0] + // remove the +QGDNRCNT: part + .replace("+QGDNRCNT: ", ""); + + this.nrUpload = lines + .find((line) => line.includes("+QGDNRCNT:")) + .split(",")[1]; + + + // for non-NR traffic stats: +QGDCNT: 247357510,6864571506 + this.nonNrDownload = lines + .find((line) => line.includes("+QGDCNT:")) + .split(",")[1]; + + this.nonNrUpload = lines + .find((line) => line.includes("+QGDCNT:")) + .split(",")[0] + // remove the +QGDCNT: part + .replace("+QGDCNT: ", ""); + + + // Add the nrDownload and nonNrDownload together + this.downloadStat = parseInt(this.nrDownload) + parseInt(this.nonNrDownload); + + // Add the nrUpload and nonNrUpload together + this.uploadStat = parseInt(this.nrUpload) + parseInt(this.nonNrUpload); + + // Convert the downloadStat and uploadStat bytes to readable size + this.downloadStat = this.bytesToSize(this.downloadStat); + this.uploadStat = this.bytesToSize(this.uploadStat); + + console.log(this.downloadStat); + console.log(this.uploadStat); + // Signal Informations const currentNetworkMode = this.networkMode; @@ -1133,8 +1181,11 @@ // Get the short Cell ID (Last 2 characters of the Cell ID) const shortCID = longCID.substring(longCID.length - 2); - - if (currentNetworkMode == "5G SA TDD" || currentNetworkMode == "5G SA FDD") { + + if ( + currentNetworkMode == "5G SA TDD" || + currentNetworkMode == "5G SA FDD" + ) { // TAC this.tac = lines .find((line) => line.includes('+QENG: "servingcell"')) @@ -1214,11 +1265,11 @@ .split(",")[14] .replace(/"/g, ""); - // RSSI - this.rssi = lines - .find((line) => line.includes('+QENG: "servingcell"')) - .split(",")[15] - .replace(/"/g, ""); + // // RSSI + // this.rssi = lines + // .find((line) => line.includes('+QENG: "servingcell"')) + // .split(",")[15] + // .replace(/"/g, ""); // SINR this.sinrLTE = lines @@ -1318,11 +1369,11 @@ .split(",")[12] .replace(/"/g, ""); - // RSSI LTE - this.rssi = lines - .find((line) => line.includes('+QENG: "LTE"')) - .split(",")[13] - .replace(/"/g, ""); + // // RSSI LTE + // this.rssi = lines + // .find((line) => line.includes('+QENG: "LTE"')) + // .split(",")[13] + // .replace(/"/g, ""); // SINR LTE this.sinrLTE = lines @@ -1408,6 +1459,13 @@ }); }, + bytesToSize(bytes) { + const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; + if (bytes == 0) return "0 Byte"; + const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; + }, + requestPing() { return fetch("/cgi-bin/get_ping") .then((response) => response.text()) @@ -1759,4 +1817,4 @@ } - \ No newline at end of file + diff --git a/simpleadmin/www/logout.html b/simpleadmin/www/logout.html deleted file mode 100644 index 6566a50..0000000 --- a/simpleadmin/www/logout.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - Logging out... - - - - - - - - - - - - - - diff --git a/simpleadmin/www/network.html b/simpleadmin/www/network.html index e1aa427..9c03b54 100644 --- a/simpleadmin/www/network.html +++ b/simpleadmin/www/network.html @@ -53,6 +53,9 @@ >Simple Network + @@ -156,6 +159,28 @@ x-bind:placeholder="apn === '-' ? 'Fetching...' : apn" /> + + +
@@ -378,6 +403,10 @@
+ @@ -697,7 +726,7 @@ // If atcmd has QUIMSLOT, do a reboot instead if (atcmd.includes("QUIMSLOT")) { - atcmd = atcmd +"+CFUN=1,1"; + atcmd = atcmd + "+CFUN=1,1"; this.sendATcommand(atcmd); this.countdown = 45; diff --git a/simpleadmin/www/scanner.html b/simpleadmin/www/scanner.html index f5022e8..9ad19ad 100644 --- a/simpleadmin/www/scanner.html +++ b/simpleadmin/www/scanner.html @@ -20,6 +20,8 @@ + +
@@ -51,11 +53,14 @@ + @@ -76,6 +81,23 @@ + +
+
+
+
Live Signal
+
+
+

Signal Graph

+
+ +
+
+
+
+
+
+
@@ -128,7 +150,7 @@ class="btn btn-primary me-md-2" type="button" x-on:click="startCellScan()" - :disabled='isLoading === true || cellScanMode === "Unspecified" || cellScanMode === "Select Scan Mode"' + :disabled="isLoading === true || cellScanMode === 'Unspecified' || cellScanMode === 'Select Scan Mode'" x-text="isCellScanning ? 'Scanning... Please wait.' : 'Start Cell Scan'" >
- -
+ --> diff --git a/simpleadmin/www/sms.html b/simpleadmin/www/sms.html index 8c41fde..4ab01a9 100644 --- a/simpleadmin/www/sms.html +++ b/simpleadmin/www/sms.html @@ -35,6 +35,9 @@ + diff --git a/simpleadmin/www/watchcat.html b/simpleadmin/www/watchcat.html index ed2a6cf..923e60b 100644 --- a/simpleadmin/www/watchcat.html +++ b/simpleadmin/www/watchcat.html @@ -4,12 +4,6 @@ Simple Admin - @@ -17,14 +11,14 @@ - + @@ -55,6 +49,9 @@ +
+ + + + + +
+
+ +
+
+
+
Simple Watchcat
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+
+
+ + + + +
+
+ +
+
+
+
+
+
+
Simple Watchcat Logs
+
+
+
+ + +
+
+
+
+
+
+
+
+ + + + diff --git a/simpleupdates/scripts/update_simpleadmin.sh b/simpleupdates/scripts/update_simpleadmin.sh index a2fabe6..971dc5f 100644 --- a/simpleupdates/scripts/update_simpleadmin.sh +++ b/simpleupdates/scripts/update_simpleadmin.sh @@ -143,6 +143,8 @@ echo -e "\e[1;31m2) Installing simpleadmin from the $GITTREE branch\e[0m" sleep 1 cd $SIMPLE_ADMIN_DIR/script wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/script/ttl_script.sh + wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/script/remove_watchcat.sh + wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/script/create_watchcat.sh sleep 1 cd $SIMPLE_ADMIN_DIR/console wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/console/.profile @@ -160,7 +162,6 @@ echo -e "\e[1;31m2) Installing simpleadmin from the $GITTREE branch\e[0m" wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/network.html wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/settings.html wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/sms.html - wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/logout.html wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/scanner.html wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/watchcat.html sleep 1 @@ -186,6 +187,7 @@ echo -e "\e[1;31m2) Installing simpleadmin from the $GITTREE branch\e[0m" wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/get_uptime wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/get_watchcat_status wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/set_watchcat + wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/watchcat_maker sleep 1 cd / chmod +x $SIMPLE_ADMIN_DIR/www/cgi-bin/*