160 lines
5.4 KiB
HTML
160 lines
5.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<!-- change to a much simpler tab title -->
|
|
<title>SMS Viewer</title>
|
|
|
|
<script src="/js/alpinejs.min.js" defer></script>
|
|
<link rel="stylesheet" href="/css/bulma.css" />
|
|
<link rel="stylesheet" type="text/css" href="/css/admin.css" />
|
|
</head>
|
|
|
|
<body>
|
|
<!-- START NAV -->
|
|
<nav class="navbar is-black" x-data="{ isOpen: false }">
|
|
<div class="container">
|
|
<div class="navbar-brand">
|
|
<a class="navbar-item brand-text" href="/"> Simple Admin </a>
|
|
<a
|
|
role="button"
|
|
class="navbar-burger burger"
|
|
@click="isOpen = !isOpen"
|
|
>
|
|
<span aria-hidden="true"></span>
|
|
<span aria-hidden="true"></span>
|
|
<span aria-hidden="true"></span>
|
|
</a>
|
|
</div>
|
|
<div
|
|
id="navMenu"
|
|
class="navbar-menu"
|
|
:class="isOpen ? 'is-active' : ''"
|
|
>
|
|
<div class="navbar-start">
|
|
<a class="navbar-item" href="/"> Connection Info </a>
|
|
<a class="navbar-item" href="/atcommander.html"> AT Commands </a>
|
|
<a class="navbar-item" href="/sms.html"> SMS </a>
|
|
<a class="navbar-item" href="/ttl.html"> TTL Changer </a>
|
|
<a class="navbar-item" href="/speedtest.html"> Speedtest </a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
<!-- END NAV -->
|
|
<div class="container" x-data="atCommands()">
|
|
<div class="columns">
|
|
<div class="column is-12">
|
|
<div class="columns">
|
|
<div class="column is-8">
|
|
<div class="card">
|
|
<header class="card-header">
|
|
<p class="card-header-title">SMS Viewer</p>
|
|
<div class="field">
|
|
<p class="control">
|
|
<button
|
|
class="button is-success"
|
|
@click="sendAtCommand()"
|
|
:disabled="isLoading"
|
|
>
|
|
Refresh
|
|
</button>
|
|
</p>
|
|
</div>
|
|
<div class="field">
|
|
<p class="control">
|
|
<button
|
|
class="button is-danger"
|
|
@click="sendAtCommand()"
|
|
:disabled="isLoading"
|
|
>
|
|
Delete
|
|
</button>
|
|
</p>
|
|
</div>
|
|
</header>
|
|
<div class="card-content">
|
|
<div class="content">
|
|
<textarea
|
|
class="textarea"
|
|
placeholder="SMS Viewer (Make sure to run: AT+CMGF=1 first)"
|
|
readonly
|
|
rows="10"
|
|
cols="50"
|
|
x-model="atCommandResponse"
|
|
:disabled="isLoading"
|
|
></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function atCommands() {
|
|
return {
|
|
isLoading: false,
|
|
atcmd: 'AT+CMGL="ALL"',
|
|
atCommandResponse: null,
|
|
sendAtCommand() {
|
|
this.isLoading = true; // Set loading state to true before fetching data
|
|
fetch(
|
|
"/cgi-bin/get_atcommand?" +
|
|
new URLSearchParams({
|
|
atcmd: this.atcmd,
|
|
})
|
|
)
|
|
.then((res) => {
|
|
return res.text();
|
|
})
|
|
.then((data) => {
|
|
this.atCommandResponse = data;
|
|
// Split the response into individual messages
|
|
const messages = data.trim().split("\n\n");
|
|
|
|
// Parse each message and construct an array of objects
|
|
const parsedMessages = messages.map((message) => {
|
|
const lines = message.split("\n");
|
|
const sender = decodeHexString(
|
|
lines[1].split(",")[2].slice(1, -1)
|
|
);
|
|
const time = lines[2].split(',"')[1];
|
|
const messageText = decodeHexString(lines[3]);
|
|
return {
|
|
"Người gửi": sender,
|
|
"Thời gian": time,
|
|
"Tin nhắn": messageText,
|
|
};
|
|
});
|
|
|
|
// Log the parsed messages array as JSON to the console
|
|
console.log(JSON.stringify(parsedMessages, null, 2));
|
|
})
|
|
.catch((error) => {
|
|
console.error("Không thể tìm thấy dữ liệu:", error);
|
|
})
|
|
.finally(() => {
|
|
this.isLoading = false; // Set loading state to false after fetching data
|
|
});
|
|
},
|
|
};
|
|
}
|
|
// Hàm giải mã chuỗi hex sang văn bản
|
|
function decodeHexString(hexString) {
|
|
let decodedString = "";
|
|
for (let i = 0; i < hexString.length; i += 4) {
|
|
let hex = hexString.substr(i, 4);
|
|
let intValue = parseInt(hex, 16);
|
|
decodedString += String.fromCharCode(intValue);
|
|
}
|
|
return decodedString;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|