added ttl log to console

This commit is contained in:
Russel Yasol
2024-05-10 18:12:26 +08:00
parent faae115732
commit 30937e20ba
3 changed files with 84 additions and 49 deletions

View File

@@ -1,5 +1,13 @@
#!/bin/bash #!/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 # Get query
QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g') QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g')
@@ -10,38 +18,44 @@ if [ "${QUERY_STRING}" ]; then
key=$(echo $cmd | awk -F '=' '{print $1}') key=$(echo $cmd | awk -F '=' '{print $1}')
value=$(echo $cmd | awk -F '=' '{print $2}') value=$(echo $cmd | awk -F '=' '{print $2}')
eval $key=$value eval $key=$value
log_debug "Received parameter: $key=$value"
fi fi
done done
fi fi
# Convert ttlvalue to integer setTTL=$(printf '%b\n' "${ttlvalue//%/\\x}")
if [ "${ttlvalue}" ]; then if [ -n "${setTTL}" ]; then
ttlvalue_int=$(echo "${ttlvalue}" | sed 's/[^0-9]*//g') 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 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. echo "Content-type: text/text"
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 "" echo ""
cat <<EOT cat <<EOT
{ {
"isEnabled": $ttlenabled, "debug_logs": [
"ttl": $ttlvalue $(printf '"%s",' "${debug_logs[@]}")
]
} }
EOT EOT

View File

@@ -192,10 +192,7 @@
x-text="pcc_pci + ', ' + scc_pci" x-text="pcc_pci + ', ' + scc_pci"
></td> ></td>
<td <td x-show="scc_pci == '-'" x-text="pcc_pci"></td>
x-show="scc_pci == '-'"
x-text="pcc_pci"
></td>
</tr> </tr>
<tr> <tr>
<th scope="row">IPv<sup>4</sup></th> <th scope="row">IPv<sup>4</sup></th>
@@ -311,6 +308,9 @@
x-show="rsrqLTEPercentage == '0'" x-show="rsrqLTEPercentage == '0'"
x-text="rsrqLTE" x-text="rsrqLTE"
></span> ></span>
<span x-show="rsrqLTE == '-'" class="fst-italic">
None
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -399,6 +399,9 @@
x-show="rsrpLTEPercentage == '0'" x-show="rsrpLTEPercentage == '0'"
x-text="rsrpLTE" x-text="rsrpLTE"
></span> ></span>
<span x-show="rsrpLTE == '-'" class="fst-italic">
None
</span>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -490,6 +493,9 @@
x-text="sinrLTE" x-text="sinrLTE"
x-show="sinrLTEPercentage == '0'" x-show="sinrLTEPercentage == '0'"
></span> ></span>
<span x-show="sinrLTE == '-'" class="fst-italic">
None
</span>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -8,7 +8,7 @@
<link rel="stylesheet" href="css/bootstrap.min.css" /> <link rel="stylesheet" href="css/bootstrap.min.css" />
<!-- Logo --> <!-- Logo -->
<link rel="simpleadmin-logo" href="favicon.ico"> <link rel="simpleadmin-logo" href="favicon.ico" />
<!-- Import BootStrap Javascript --> <!-- Import BootStrap Javascript -->
<script src="js/bootstrap.bundle.min.js"></script> <script src="js/bootstrap.bundle.min.js"></script>
@@ -101,7 +101,7 @@
placeholder="ATI" placeholder="ATI"
aria-describedby="atCommandInput" aria-describedby="atCommandInput"
x-model="atcmd" x-model="atcmd"
@keydown.enter = "sendATCommand()" @keydown.enter="sendATCommand()"
/> />
<div id="atCommandInputHelper" class="form-text"> <div id="atCommandInputHelper" class="form-text">
Seperate multiple commands with comma (,). Seperate multiple commands with comma (,).
@@ -554,21 +554,24 @@
case "LTE": case "LTE":
this.atcmd = "AT+QSCAN=1,1"; this.atcmd = "AT+QSCAN=1,1";
this.scanStart = true; 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.sendATCommand();
this.scanStart = false; this.scanStart = false;
break; break;
case "NR5G": case "NR5G":
this.atcmd = "AT+QSCAN=2,1"; this.atcmd = "AT+QSCAN=2,1";
this.scanStart = true; 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.sendATCommand();
this.scanStart = false; this.scanStart = false;
break; break;
case "ALL": case "ALL":
this.atcmd = "AT+QSCAN=3,1"; this.atcmd = "AT+QSCAN=3,1";
this.scanStart = true; 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.sendATCommand();
this.scanStart = false; this.scanStart = false;
break; break;
@@ -643,29 +646,41 @@
setTTL() { setTTL() {
this.isLoading = true; // Set loading state while updating TTL this.isLoading = true; // Set loading state while updating TTL
const ttlval = this.newTTL;
fetch( fetch(
"/cgi-bin/set_ttl?" + "/cgi-bin/set_ttl?" + new URLSearchParams({ ttlvalue: ttlval })
new URLSearchParams({
ttlvalue: this.newTTL,
})
) )
.then((res) => res.json()) .then((res) => res.text())
.then((data) => { .then((data) => {
// Once TTL is updated, fetch the updated TTL data // Split the response into JSON and non-JSON parts
this.fetchTTL(); const parts = data.trim().split("\n\n");
this.isLoading = false; // Set loading state back to false 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) => { .catch((error) => {
console.error("Error updating TTL: ", error); console.error("Error updating TTL: ", error);
this.isLoading = false; // Ensure loading state is properly handled in case of error this.isLoading = false; // Ensure loading state is properly handled in case of error
}); });
}, },
init() {
this.fetchTTL();
this.fetchCurrentSettings();
},
}; };
} }
</script> </script>