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
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
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')
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 is not 0, then enable the script with the value of ttlvalue_int. If ttlvalue is disable, then disable the script.
# Call the sh script with the appropriate parameters
if [ "${ttlvalue_int}" != 0 ]; then
/usrdata/simpleadmin/script/ttl_script.sh enable "${ttlvalue_int}"
# Set ttlenabled to true
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
# Set ttlvalue to the value of ttlvalue_int
ttlvalue=$ttlvalue_int
elif [ "${ttlvalue_int}" = 0 ]; then
log_debug "Disabling TTL"
/usrdata/simpleadmin/script/ttl_script.sh disable 0
# Set ttlenabled to false
commandRan="/usrdata/simpleadmin/script/ttl_script.sh disable 0"
ttlenabled=false
# Set ttlvalue to 0
ttlvalue=0
fi
fi
# Output the result in JSON format
echo "Content-type: text/json"
echo "Content-type: text/text"
echo ""
cat <<EOT
{
"isEnabled": $ttlenabled,
"ttl": $ttlvalue
"debug_logs": [
$(printf '"%s",' "${debug_logs[@]}")
]
}
EOT

View File

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

View File

@@ -8,7 +8,7 @@
<link rel="stylesheet" href="css/bootstrap.min.css" />
<!-- Logo -->
<link rel="simpleadmin-logo" href="favicon.ico">
<link rel="simpleadmin-logo" href="favicon.ico" />
<!-- Import BootStrap Javascript -->
<script src="js/bootstrap.bundle.min.js"></script>
@@ -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) => {
// 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();
},
};
}
</script>