update 2024-10-10 00:24:05

This commit is contained in:
kenzok8 2024-10-10 00:24:05 +08:00
parent 3d43f40798
commit e5cf69c072
7 changed files with 118 additions and 2 deletions

View File

@ -12,8 +12,11 @@ function index()
e.dependent=false
e.acl_depends={ "luci-app-ddns-go" }
entry({"admin", "services", "ddns-go", "setting"}, cbi("ddns-go"), _("Base Setting"), 20).leaf=true
entry({"admin", "services", "ddns-go", "ddns-go"}, template("ddns-go"), _("DDNS-GO Control panel"), 30).leaf = true
entry({"admin", "services", "ddns-go", "ddns-go"}, template("ddns-go/ddns-go"), _("DDNS-GO Control panel"), 30).leaf = true
entry({"admin", "services", "ddnsgo_status"}, call("act_status"))
entry({"admin", "services", "ddns-go", "log"}, template("ddns-go/ddns-go_log"), _("Log"), 40).leaf = true
entry({"admin", "services", "ddns-go", "fetch_log"}, call("fetch_log"), nil).leaf = true
entry({"admin", "services", "ddns-go", "clear_log"}, call("clear_log")).leaf = true
end
function act_status()
@ -23,3 +26,20 @@ function act_status()
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function fetch_log()
local fs = require "nixio.fs"
local log_file = "/var/log/ddns-go.log"
local log_content = fs.readfile(log_file) or "No Log."
luci.http.write(log_content)
end
function clear_log()
local fs = require "nixio.fs"
local log_file = "/var/log/ddns-go.log"
local f = io.open(log_file, "w")
if f then
f:close()
luci.http.status(204, "No Content")
else
luci.http.status(500, "Internal Server Error")
end
end

View File

@ -6,7 +6,7 @@ m = Map("ddns-go")
m.title = translate("DDNS-GO")
m.description = translate("DDNS-GO automatically obtains your public IPv4 or IPv6 address and resolves it to the corresponding domain name service.")..translate("</br>For specific usage, see:")..translate("<a href=\'https://github.com/sirpdboy/luci-app-ddns-go.git' target=\'_blank\'>GitHub @sirpdboy/luci-app-ddns-go </a>")
m:section(SimpleSection).template = "ddns-go_status"
m:section(SimpleSection).template = "ddns-go/ddns-go_status"
s = m:section(TypedSection, "basic", translate("Global Settings"))
s.addremove = false

View File

@ -0,0 +1,90 @@
<%+header%>
<div>
<input class="btn cbi-button-action" type="button" onclick="clearLog()" value="清空日志">
<input class="btn cbi-button-action" type="button" onclick="toggleRefresh()" value="停止刷新">
</div>
<pre id="logContent">
<%
local fs = require "nixio.fs"
local log_file_path = "/var/log/ddns-go.log"
local raw_log_content = fs.readfile(log_file_path) or "No Log."
local log_lines = {}
for line in raw_log_content:gmatch("[^\r\n]+") do
table.insert(log_lines, line)
end
for i=1, math.floor(#log_lines / 2) do
log_lines[i], log_lines[#log_lines - i + 1] = log_lines[#log_lines - i + 1], log_lines[i]
end
local log_content = table.concat(log_lines, "\n")
%>
<%=log_content%>
</pre>
<%+footer%>
<style>
#logContent {
background-color: #ffffff;
border: 1px solid #ddd;
padding: 15px;
padding-top: 0px;
margin-top: 5px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
white-space: pre-wrap;
height: 100vh;
overflow-y: auto;
}
</style>
<script>
var refreshInterval = null;
function fetchLog() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/cgi-bin/luci/admin/services/ddns-go/fetch_log', true);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
var logLines = xhr.responseText.split("\n").reverse().join("\n");
document.getElementById('logContent').textContent = logLines;
} else {
document.getElementById('logContent').textContent = 'Failed to load log.';
}
};
xhr.onerror = function () {
document.getElementById('logContent').textContent = 'Error loading log.';
};
xhr.send();
}
function clearLog() {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/cgi-bin/luci/admin/services/ddns-go/clear_log', true);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
fetchLog(); // 刷新日志内容
} else {
alert('Failed to clear log.');
}
};
xhr.onerror = function () {
alert('Error clearing log.');
};
xhr.send();
}
function toggleRefresh() {
var refreshButton = document.querySelector("input[onclick='toggleRefresh()']");
if (refreshInterval) {
clearInterval(refreshInterval);
refreshInterval = null;
refreshButton.value = '开始刷新';
} else {
fetchLog(); // 立即获取一次日志
refreshInterval = setInterval(fetchLog, 1000);
refreshButton.value = '停止刷新';
}
}
// 页面加载完成后开始刷新日志
document.addEventListener('DOMContentLoaded', function () {
toggleRefresh();
});
</script>

View File

@ -16,6 +16,9 @@ msgstr "运行状态"
msgid "DDNS-GO Control panel"
msgstr "DDNS-GO操作台"
msgid "Log"
msgstr "日志"
msgid "The DDNS-GO service is running."
msgstr "DDNS-GO服务已启动"

View File

@ -16,6 +16,9 @@ msgstr "运行状态"
msgid "DDNS-GO Control panel"
msgstr "DDNS-GO操作台"
msgid "Log"
msgstr "日志"
msgid "The DDNS-GO service is running."
msgstr "DDNS-GO服务已启动"