Merge pull request #48 from dr-dolomite/development-socat

Fixed TTL Script and Removed Unnecessary Links and Files
This commit is contained in:
Cameron Thompson
2024-05-10 14:55:08 -04:00
committed by GitHub
8 changed files with 165 additions and 144 deletions

View File

@@ -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 <<EOT
{
"isEnabled": $ttlenabled,
"ttl": $ttlvalue
}
EOT

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
# 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 <<EOT
{
"isEnabled": $ttlenabled,
"ttl": $ttlvalue
"debug_logs": [
$(printf '"%s",' "${debug_logs[@]}")
]
}
EOT

View File

@@ -1,61 +0,0 @@
#!/bin/bash
# Get query
QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g')
if [ "${QUERY_STRING}" ]; then
export IFS="&"
for cmd in ${QUERY_STRING}; do
if [ "$(echo $cmd | grep '=')" ]; then
key=$(echo $cmd | awk -F '=' '{print $1}')
value=$(echo $cmd | awk -F '=' '{print $2}')
eval $key=$value
fi
done
fi
setTTL=$(printf '%b\n' "${ttlvalue//%/\\x}")
if [ -n "${setTTL}" ]; then
# Stop Service To Remove Rules
/usrdata/simplefirewall/ttl-override stop
# Check iptables is still set
ttlcheck=$(iptables -t mangle -vnL | grep TTL | awk '{print $13}')
# If TTL is still set manually remove values
if [ !-z "${ttlcheck}" ]; then
iptables -t mangle -D POSTROUTING -o rmnet+ -j TTL --ttl-set ${ttlcheck} &>/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 <<EOT
{
"isEnabled": $ttlenabled,
"ttl": $ttlvalue
}

View File

@@ -139,7 +139,7 @@
</tr>
<tr>
<th scope="row">Simple Admin Version</th>
<td class="col-md-2">SimpleAdminRev-Alpha-0.3</td>
<td class="col-md-2">SimpleAdminRev-Alpha-0.5</td>
</tr>
</tbody>
</table>
@@ -149,7 +149,7 @@
<div class="card-footer">
Visit our
<a
href="https://github.com/iamromulan/quectel-rgmii-toolkit.gits"
href="https://github.com/iamromulan/quectel-rgmii-toolkit/tree/development"
target="_blank"
class="text-reset"
>repository</a

View File

@@ -15,7 +15,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>
@@ -190,7 +190,12 @@
</tr>
<tr>
<th scope="row">PCI</th>
<td x-text="pcc_pci + ', ' + scc_pci"></td>
<td
x-show="scc_pci != '-'"
x-text="pcc_pci + ', ' + scc_pci"
></td>
<td x-show="scc_pci == '-'" x-text="pcc_pci"></td>
</tr>
<tr>
<th scope="row">IPv<sup>4</sup></th>
@@ -246,7 +251,8 @@
</tr>
<tr>
<th scope="row">CSQ</th>
<td x-text="csq"></td>
<td x-show="csq != '-'" x-text="csq"></td>
<td x-show="csq == '-'" class="fst-italic">None</td>
</tr>
<tr>
<th scope="row">CELL ID</th>
@@ -262,7 +268,8 @@
</tr>
<tr>
<th scope="row">RSSI</th>
<td x-text="rssi"></td>
<td x-show="rssi != '-'" x-text="rssi"></td>
<td x-show="rssi == '-'" class="fst-italic">None</td>
</tr>
<tr>
<th scope="row">SS_RSRQ<sup>4G</sup></th>
@@ -282,7 +289,7 @@
} }"
>
<div
x-show="rsrqLTE != '-'"
x-show="rsrqLTE != '-' && rsrqLTEPercentage != '0'"
class="progress w-100"
role="progressbar"
aria-label="RSRQ BAR"
@@ -300,6 +307,13 @@
></span>
</div>
</div>
<span
x-show="rsrqLTEPercentage == '0'"
x-text="rsrqLTE"
></span>
<span x-show="rsrqLTE == '-'" class="fst-italic">
None
</span>
</td>
</tr>
<tr>
@@ -319,7 +333,7 @@
} }"
>
<div
x-show="rsrqNR != '-'"
x-show="rsrqNR != '-' && rsrqNRPercentage != '0'"
class="progress w-100"
role="progressbar"
aria-label="RSRQ BAR"
@@ -337,6 +351,13 @@
></span>
</div>
</div>
<span
x-show="rsrqNRPercentage == '0'"
x-text="rsrqNR"
></span>
<span x-show="rsrqNR == '-'" class="fst-italic">
None
</span>
</td>
</tr>
<tr>
@@ -359,7 +380,7 @@
}"
>
<div
x-show="rsrpLTE != '-'"
x-show="rsrpLTE != '-' && rsrpLTEPercentage != '0'"
class="progress w-100"
role="progressbar"
aria-label="RSRP BAR"
@@ -377,6 +398,13 @@
></span>
</div>
</div>
<span
x-show="rsrpLTEPercentage == '0'"
x-text="rsrpLTE"
></span>
<span x-show="rsrpLTE == '-'" class="fst-italic">
None
</span>
</td>
</tr>
<tr>
@@ -399,7 +427,7 @@
}"
>
<div
x-show="rsrpNR != '-'"
x-show="rsrpNR != '-' && rsrpNRPercentage != '0'"
class="progress w-100"
role="progressbar"
aria-label="RSRP BAR"
@@ -417,6 +445,13 @@
></span>
</div>
</div>
<span
x-show="rsrpNRPercentage == '0'"
x-text="rsrpNR"
></span>
<span x-show="rsrpNR == '-'" class="fst-italic">
None
</span>
</td>
</tr>
<tr>
@@ -439,7 +474,7 @@
}"
>
<div
x-show="sinrLTE != '-'"
x-show="sinrLTE != '-' && sinrLTEPercentage != '0'"
class="progress w-100"
role="progressbar"
aria-label="SINR BAR"
@@ -457,6 +492,13 @@
></span>
</div>
</div>
<span
x-text="sinrLTE"
x-show="sinrLTEPercentage == '0'"
></span>
<span x-show="sinrLTE == '-'" class="fst-italic">
None
</span>
</td>
</tr>
<tr>
@@ -479,7 +521,7 @@
}"
>
<div
x-show="sinrNR != '-'"
x-show="sinrNR != '-' && sinrNRPercentage != '0'"
class="progress w-100"
role="progressbar"
aria-label="SINR BAR"
@@ -497,6 +539,13 @@
></span>
</div>
</div>
<span
x-text="sinrNR"
x-show="sinrNRPercentage == '0'"
></span>
<span x-show="sinrNR == '-'" class="fst-italic">
None
</span>
</td>
</tr>
</tbody>
@@ -563,7 +612,7 @@
internetConnection: "Disconnected",
lastUpdate: new Date().toLocaleString(),
newRefreshRate: null,
refreshRate: 5,
refreshRate: 3,
intervalId: null,
fetchNetworkInfo() {
this.atcmd =
@@ -627,9 +676,7 @@
if (networkMode1 === '"NR5G-SA"') {
this.network_mode = networkMode1;
this.network_mode = this.network_mode.replace(/"/g, "");
}
else {
} else {
let networkMode2, networkMode3;
if (
@@ -786,7 +833,10 @@
this.signalPercentage
);
} else {
if (this.network_mode.match(/LTE/) != null && this.network_mode.match(/NR5G-NSA/) == null) {
if (
this.network_mode.match(/LTE/) != null &&
this.network_mode.match(/NR5G-NSA/) == null
) {
let lte_bw_ul = lines[27].split(",")[10].replace(/"/g, "");
let lte_bw_dl = lines[27].split(",")[11].replace(/"/g, "");
@@ -795,9 +845,11 @@
// Calculate the LTE bandwidth
this.bandwidth =
"UL " + this.calculate_lte_bw(lte_bw_ul) +
"UL " +
this.calculate_lte_bw(lte_bw_ul) +
" MHz / " +
"DL " + this.calculate_lte_bw(lte_bw_dl) +
"DL " +
this.calculate_lte_bw(lte_bw_dl) +
" MHz";
// Get the Cell ID
@@ -878,7 +930,8 @@
this.bandwidth =
this.calculate_lte_bw(lte_bw_ul) +
" MHz, " +
"NR " + this.calculate_lte_bw(lte_bw_dl) +
"NR " +
this.calculate_lte_bw(lte_bw_dl) +
" MHz";
// Get the RSSI
@@ -1042,7 +1095,7 @@
let RSRQ_max = -8;
// If rsrq is null, return 0%
if (isNaN(rsrq)) {
if (isNaN(rsrq) || rsrq < -20) {
return 0;
}
@@ -1060,7 +1113,7 @@
let RSRP_max = -60;
// If rsrp is null, return 0%
if (isNaN(rsrp)) {
if (isNaN(rsrp) || rsrp < -140) {
return 0;
}
@@ -1074,11 +1127,11 @@
},
calculateSINRPercentage(sinr) {
let SINR_min = 0;
let SINR_min = -10; // Changed from 0
let SINR_max = 35;
// If sinr is null, return 0%
if (isNaN(sinr)) {
if (isNaN(sinr) || sinr < -10) {
return 0;
}
@@ -1173,7 +1226,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

View File

@@ -6,9 +6,9 @@
<title>Simple Admin</title>
<link rel="stylesheet" href="css/styles.css" />
<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>
@@ -104,7 +104,7 @@
placeholder="ATI"
aria-describedby="atCommandInput"
x-model="atcmd"
@keydown.enter = "sendATCommand()"
@keydown.enter="sendATCommand()"
/>
<div id="atCommandInputHelper" class="form-text">
Seperate multiple commands with comma (,).
@@ -557,21 +557,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;
@@ -646,15 +649,16 @@
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()) // Use res.text() instead of res.json()
.then((data) => {
// 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
// Once TTL is updated, fetch the updated TTL data
this.fetchTTL();
this.isLoading = false; // Set loading state back to false
@@ -664,7 +668,6 @@
this.isLoading = false; // Ensure loading state is properly handled in case of error
});
},
init() {
this.fetchTTL();
this.fetchCurrentSettings();