added various changes

This commit is contained in:
Russel Yasol
2024-05-14 12:36:11 +08:00
parent b260cf369e
commit 12cebf6900
3 changed files with 265 additions and 105 deletions

View File

@@ -1211,37 +1211,134 @@
fetch("/cgi-bin/get_uptime")
.then((response) => response.text())
.then((data) => {
// Split the data by space
const uptimeArray = data.split(" ");
console.log(uptimeArray);
// If uptimeArray[3] is not empty, and the value doesnt have : in it
if (
uptimeArray[3] !== "" &&
uptimeArray[3].match(/:/) == null && uptimeArray[4].match(/days/) == null
) {
this.uptime =
uptimeArray[3] +
" days, " +
uptimeArray[5].split(":")[0] +
" hours, and " +
uptimeArray[5].split(":")[1].replace(",", "") +
" minutes";
} else if (uptimeArray[3].match(/:/) != null) {
this.uptime =
uptimeArray[3].split(":")[0] +
" hours and " +
uptimeArray[3].split(":")[1].replace(",", "") +
" minutes";
} else if (uptimeArray[5].match(/:/) == null && uptimeArray[4].match(/days/) != null) {
this.uptime = uptimeArray[3].replace(",", "") + " days and " + uptimeArray[5] + " minutes";
}
// Example result
// 01:17:02 up 3 days, 2:41, load average: 0.65, 0.66, 0.60
else {
// Look for xx days in the result
const days = data.match(/(\d+) day/);
// Do the same for hours
const hours = data.match(/(\d+) hour/);
// Do the same for minutes
const minutes = data.match(/(\d+) minute/);
// 2:41
const hoursAndMinutes = data.match(/(\d+):(\d+),/);
if (hoursAndMinutes != null) {
if (days != null) {
if (days[1] === "1") {
if (hoursAndMinutes[1] === "1") {
this.uptime =
uptimeArray[4].split(":")[0] +
" hours and " +
uptimeArray[4].split(":")[1].replace(",", "") +
days[1] +
" day, " +
hoursAndMinutes[1] +
" hour " +
hoursAndMinutes[2] +
" minutes";
} else if (hoursAndMinutes[2] === 1) {
this.uptime =
days[1] +
" day, " +
hoursAndMinutes[1] +
" hours " +
hoursAndMinutes[2] +
" minute";
} else {
this.uptime =
days[1] +
" day, " +
hoursAndMinutes[1] +
" hours " +
hoursAndMinutes[2] +
" minutes";
}
} else {
if (hoursAndMinutes[1] === "1") {
this.uptime =
days[1] +
" days, " +
hoursAndMinutes[1] +
" hour " +
hoursAndMinutes[2] +
" minutes";
} else if (hoursAndMinutes[2] === 1) {
this.uptime =
days[1] +
" days, " +
hoursAndMinutes[1] +
" hours " +
hoursAndMinutes[2] +
" minute";
} else {
this.uptime =
days[1] +
" days, " +
hoursAndMinutes[1] +
" hours " +
hoursAndMinutes[2] +
" minutes";
}
}
} else {
if (hoursAndMinutes[1] === "1") {
this.uptime =
hoursAndMinutes[1] +
" hour " +
hoursAndMinutes[2] +
" minutes";
} else if (hoursAndMinutes[2] === 1) {
this.uptime =
hoursAndMinutes[1] +
" hours " +
hoursAndMinutes[2] +
" minute";
} else {
this.uptime =
hoursAndMinutes[1] +
" hours " +
hoursAndMinutes[2] +
" minutes";
}
}
} else if (days != null) {
if (hours != null) {
if (days[1] === "1") {
if (hours[1] === "1") {
this.uptime = days[1] + " day, " + hours[1] + " hour";
} else {
this.uptime = days[1] + " day, " + hours[1] + " hours";
}
} else {
if (hours[1] === "1") {
this.uptime = days[1] + " days, " + hours[1] + " hour";
} else {
this.uptime = days[1] + " days, " + hours[1] + " hours";
}
}
} else if (minutes != null) {
if (days[1] === "1") {
if (minutes[1] === "1") {
this.uptime =
days[1] + " day, " + minutes[1] + " minute";
} else {
this.uptime =
days[1] + " day, " + minutes[1] + " minutes";
}
} else {
if (minutes[1] === "1") {
this.uptime =
days[1] + " days, " + minutes[1] + " minute";
} else {
this.uptime =
days[1] + " days, " + minutes[1] + " minutes";
}
}
} else {
if (days[1] === "1") {
this.uptime = days[1] + " day";
} else {
this.uptime = days[1] + " days";
}
}
}
});
},

View File

@@ -127,7 +127,7 @@
class="btn btn-primary me-md-2"
type="button"
x-on:click="startCellScan()"
:disabled="isLoading"
:disabled='isLoading === true || cellScanMode === "Unspecified" || cellScanMode === "Select Scan Mode"'
x-text="isCellScanning ? 'Scanning... Please wait.' : 'Start Cell Scan'"
>
</button>
@@ -135,7 +135,7 @@
class="btn btn-danger"
type="button"
x-on:click="clearTableRowsBodyCellScan()"
:disabled="isLoading"
:disabled="isLoading === true || resultDoneCell === false"
>
Clear
</button>
@@ -192,7 +192,7 @@
class="btn btn-primary me-md-2"
type="button"
x-on:click="getNeighbourcellLTEandNR5G()"
:disabled="isLoading"
:disabled="isLoading === true || neighbourCellsScanMode === 'Unspecified' || neighbourCellsScanMode === 'Select Scan Mode'"
>
Start Neighbour Cell Scan
</button>
@@ -200,7 +200,7 @@
class="btn btn-danger"
type="button"
x-on:click="clearTableRowsBodyNeighbourCells()"
:disabled="isLoading"
:disabled="isLoading === true || resultDoneNeighbourCell === false"
>
Clear
</button>
@@ -1830,10 +1830,12 @@
nr5g_neighbourCellsParsed: [],
lte_neighbourCellsParsed: [],
neighbourCellsTableRows: [],
cellScanMode: "",
neighbourCellsScanMode: "",
cellScanMode: "Unspecified",
neighbourCellsScanMode: "Unspecified",
isLoading: false,
isCellScanning: false,
resultDoneCell: false,
resultDoneNeighbourCell: false,
init() {
this.generateNeighbourCellsTableRow();
@@ -1903,6 +1905,7 @@
this.generateTableRow();
this.isLoading = false;
this.isCellScanning = false;
this.resultDoneCell = true;
});
},
parseNr5gCells() {
@@ -2090,6 +2093,7 @@
.then(() => {
this.generateNeighbourCellsTableRow();
this.isLoading = false;
this.resultDoneNeighbourCell = true;
});
},
@@ -2207,6 +2211,8 @@
this.nr5g_cells_parsed = [];
this.tableRows = [];
this.resultDoneCell = false;
const tableBody = document.getElementById("cellScanTableBody");
tableBody.innerHTML = "";
this.tableRows.push(`
@@ -2234,6 +2240,8 @@
this.nr5g_neighbourCellsParsed = [];
this.neighbourCellsTableRows = [];
this.resultDoneNeighbourCell = false;
const tableBody = document.getElementById("neighbourCellTableBody");
tableBody.innerHTML = "";
this.neighbourCellsTableRows.push(`

View File

@@ -169,13 +169,24 @@
</td>
</tr>
<tr>
<th scope="row">ETH IP Passthrough</th>
<th scope="row">IP Passthrough</th>
<td>
<select
class="form-select"
id="ipPassModeSelect"
x-model="ipPassMode"
>
<option selected>Passthrough Mode</option>
<option value="ETH">ETH</option>
<option value="USB">USB</option>
</select>
</td>
<td>
<button
type="submit"
class="btn btn-primary"
@click="ethPassthroughEnable()"
x-show="ethPassStatus === false"
@click="ipPassThroughEnable()"
x-show="ipPassStatus === false"
:disabled="isLoading"
>
Enable
@@ -183,14 +194,43 @@
<button
type="submit"
class="btn btn-danger"
@click="ethPassthroughDisable()"
x-show="ethPassStatus === true"
@click="ipPassThroughDisable()"
x-show="ipPassStatus === true"
:disabled="isLoading"
>
Disable
</button>
</td>
</tr>
<tr>
<th scope="row">Data Call Method</th>
<td>
<select
class="form-select"
id="usbNetModeSelect"
x-model="usbNetMode"
>
<option
selected
x-text="currentUsbNetMode"
></option>
<option value="RMNET">RMNET</option>
<option value="ECM">ECM (Recommended)</option>
<option value="MBIM">MBIM</option>
<option value="RNDIS">RNDIS</option>
</select>
</td>
<td>
<button
type="submit"
class="btn btn-primary"
@click="usbNetModeChanger()"
:disabled="isLoading"
>
Change
</button>
</td>
</tr>
<tr>
<th scope="row">Onboard DNS Proxy</th>
<td>
@@ -214,29 +254,6 @@
</button>
</td>
</tr>
<tr>
<th scope="row">USB Mode</th>
<td>
<button
type="submit"
class="btn btn-primary"
@click="usbModeEnable()"
x-show="USBModeStatus === true"
:disabled="isLoading"
>
Enable
</button>
<button
type="submit"
class="btn btn-danger"
@click="usbModeDisable()"
x-show="USBModeStatus === false"
:disabled="isLoading"
>
Disable
</button>
</td>
</tr>
</tbody>
</table>
</div>
@@ -384,9 +401,11 @@
ttlvalue: 0,
ttlStatus: false,
newTTL: null,
ethPassStatus: false,
ipPassMode: "Unspecified",
ipPassStatus: false,
usbNetMode: "Unspecified",
currentUsbNetMode: "Unknown",
DNSProxyStatus: true,
USBModeStatus: true,
closeModal() {
this.confirmModal = false;
@@ -421,6 +440,7 @@
this.atCommandResponse = data;
this.isLoading = false;
this.isClean = false;
this.fetchCurrentSettings();
})
.catch((error) => {
console.error("Error: ", error);
@@ -462,18 +482,27 @@
this.showRebootModal();
},
ethPassthroughEnable() {
this.atcmd = 'AT+QMAP="MPDN_RULE",0,1,0,1,1,"FF:FF:FF:FF:FF:FF"';
this.sendATCommand().then(() => {
this.fetchCurrentSettings();
});
ipPassThroughEnable() {
if (this.ipPassMode != "Unspecified") {
if (this.ipPassMode == "ETH") {
this.atcmd =
'AT+QMAP="MPDN_RULE",0,1,0,1,1,"FF:FF:FF:FF:FF:FF"';
this.sendATCommand();
} else if (this.ipPassMode == "USB") {
this.atcmd =
'AT+QMAP="MPDN_RULE",0,1,0,3,1,"FF:FF:FF:FF:FF:FF"';
this.sendATCommand();
} else {
console.error("Invalid IP Passthrough Mode");
}
} else {
console.error("IP Passthrough Mode not specified");
}
},
ethPassthroughDisable() {
ipPassThroughDisable() {
this.atcmd = 'AT+QMAP="MPDN_RULE",0';
this.sendATCommand().then(() => {
this.fetchCurrentSettings();
});
this.sendATCommand();
},
onBoardDNSProxyEnable() {
@@ -490,23 +519,39 @@
});
},
usbModeEnable() {
this.atcmd = "AT+QMAPWAC=1";
usbNetModeChanger() {
if (this.usbNetMode != "Unspecified") {
if (this.usbNetMode == "RMNET") {
this.atcmd = 'AT+QCFG="usbnet",0;';
this.sendATCommand().then(() => {
this.fetchCurrentSettings();
this.rebootDevice();
});
},
usbModeDisable() {
this.atcmd = "AT+QMAPWAC=0";
} else if (this.usbNetMode == "ECM") {
this.atcmd = 'AT+QCFG="usbnet",1;';
this.sendATCommand().then(() => {
this.fetchCurrentSettings();
this.rebootDevice();
});
} else if (this.usbNetMode == "MBIM") {
this.atcmd = 'AT+QCFG="usbnet",2;';
this.sendATCommand().then(() => {
this.rebootDevice();
});
} else if (this.usbNetMode == "RNDIS") {
this.atcmd = 'AT+QCFG="usbnet",3;';
this.sendATCommand().then(() => {
this.rebootDevice();
});
} else {
console.log("USB Net Mode Invalid");
}
} else {
console.error("USB Net Mode not specified");
}
},
fetchCurrentSettings() {
this.fetchATCommand =
'AT+QMAP="MPDN_RULE";+QMAP="DHCPV4DNS";+QMAPWAC?';
'AT+QMAP="MPDN_RULE";+QMAP="DHCPV4DNS";+QCFG="usbnet"';
fetch(
"/cgi-bin/get_atcommand?" +
new URLSearchParams({
@@ -520,15 +565,16 @@
// Set the value of currentSettingsResponse
this.currentSettingsResponse = data;
const currentData = data.split("\n");
console.log("Lines: ", currentData);
const testEthpass = currentData[1].match(
/\+QMAP: "MPDN_rule",0,0,0,0,0/
);
if (testEthpass) {
this.ethPassStatus = false;
this.ipPassStatus = false;
} else {
this.ethPassStatus = true;
this.ipPassStatus = true;
}
const testDNSProxy = currentData[6].match(
@@ -541,12 +587,20 @@
this.DNSProxyStatus = false;
}
const testUSBMode = currentData[8].match(/\+QMAPWAC: 1/);
const testUSBNet = currentData[8].match(
/\+QCFG: "usbnet",(\d)/
);
if (testUSBMode) {
this.USBModeStatus = true;
if (testUSBNet[1] == "0") {
this.currentUsbNetMode = "RMNET";
} else if (testUSBNet[1] == "1") {
this.currentUsbNetMode = "ECM";
} else if (testUSBNet[1] == "2") {
this.currentUsbNetMode = "MBIM";
} else if (testUSBNet[1] == "3") {
this.currentUsbNetMode = "RNDIS";
} else {
this.USBModeStatus = false;
this.currentUsbNetMode = "Unknown";
}
// clear atcmd
@@ -590,6 +644,7 @@
});
},
init() {
this.fetchCurrentSettings();
this.fetchTTL();
},
};