Skip to content

Commit

Permalink
add more info & service mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LazuliKao committed Oct 1, 2024
1 parent 2a3c3a2 commit ded0323
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 12 deletions.
5 changes: 4 additions & 1 deletion files/etc/init.d/nbtverify
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ start_instance() {
local cfg="$1" param
config_get_bool enabled $cfg enabled 0
[[ x$enabled = x1 ]] || return 1
xappend "-url /var/nbtverify/url.txt"
append_parm "$cfg" 'username' '-u' '0'
append_parm "$cfg" 'password' '-p' '0'
append_parm "$cfg" 'mobile' '-mobile' '0'
mkdir -p /var/nbtverify
xappend "-url /var/nbtverify/url.txt"
touch /var/nbtverify/url.txt
xappend "-s /var/log/nbtverify.log"
touch /var/log/nbtverify.log
procd_open_instance
echo ${PROG} ${param}
${PROG} ${param}
xappend "service"
procd_set_param command ${PROG} ${param}
procd_set_param respawn
procd_set_param pidfile $PIDFILE
Expand Down
Binary file modified files/usr/bin/nbtverify
Binary file not shown.
10 changes: 10 additions & 0 deletions files/usr/lib/lua/luci/controller/nbtverify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ module("luci.controller.nbtverify", package.seeall)

function index()
entry({"admin", "services", "nbtverify"}, cbi("nbtverify"), "NBT Verify", 60)
entry({"admin", "services", "nbtverify_status"}, call("act_status"))
end


function act_status()
local sys = require "luci.sys"
local e = { }
e.running = sys.call("pidof nbtverify >/dev/null") == 0
e.data = sys.exec("cat /var/log/nbtverify.log")
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
1 change: 1 addition & 0 deletions files/usr/lib/lua/luci/model/cbi/nbtverify.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require("luci.sys")

m = Map("nbtverify", translate("nbtverify Client"), translate("Configure nbtverify client."))
m:section(SimpleSection).template = "nbtverify_status"

s = m:section(TypedSection, "server", "")
s.addremove = false
Expand Down
89 changes: 89 additions & 0 deletions files/usr/lib/lua/luci/view/nbtverify_status.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<%
protocol="http://"
%>

<script type="text/javascript">

function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert('复制成功: ' + text);
window.location.reload();
}).catch(err => {
console.error('复制失败: ', err);
});
}
//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[nbtverify_status]])%>', null,
function(x, res) {
var tb = document.getElementById('nbtverify_status');
if (res && tb)
{
const data= JSON.parse(res.data)
console.log(JSON.stringify(data, null, 2));
if (res.running)
{
// var URL = "<%=protocol%>" + window.location.hostname +":<%=luci.model.uci.cursor():get_first("nbtverify", "basic", "port") %>";
// tb.innerHTML = '<em><b style=\"color:green\"><%:The DDNS-GO service is running.%></b></em>';
// tb.innerHTML +='<em> <br/><br/>' + ' <b > <%:Click the new page to open ddns-go%> </em>';
tb.innerHTML = '<em><b style=\"color:green\"><%:The nbtverify service is running.%></b></em>';
// tb.innerHTML += "<input class=\"cbi-button cbi-button-reload \" type=\"button\" value=\"跳转\" onclick=\"window.open('"+ URL+ "/')\"/>";
try {
const {result,detail}=data ?? {}
const {baseUrl,success}=result ?? {}
const {welcome,account,userIp,userMac,userName,deviceIp}=detail ?? {}
const html = `
<span style="color: ${success?'green':'red'}; font-weight: bold;"><%:Success%>: ${success}</span>
<br/>
<span style="color: blue;font-size: large;">${welcome}</span>
<br/>
<span style="color: darkorange;font-size: large;">${account}</span>
<br/>
<div style="font-family: Arial, sans-serif; display: grid; grid-template-columns: 100px 1fr; gap: 10px; line-height: 1.5; align-items: center;">
<span style="display: flex; align-items: center;"><%:校园网IP%>:</span>
<span style="font-weight: bold;">${userIp}
<button onclick="copyToClipboard('${userIp}')" style="margin-left: 8px;" class="cbi-button cbi-button-neutral">复制</button>
</span>
<span style="display: flex; align-items: center;"><%:MAC%>:</span>
<span style="font-weight: bold;">${userMac}
<button onclick="copyToClipboard('${userMac}')" style="margin-left: 8px;" class="cbi-button cbi-button-neutral">复制</button>
</span>
<span style="display: flex; align-items: center;"><%:用户名%>:</span>
<span style="font-weight: bold;">${userName}
<button onclick="copyToClipboard('${userName}')" style="margin-left: 8px;" class="cbi-button cbi-button-neutral">复制</button>
</span>
<span style="display: flex; align-items: center;"><%:上级路由%>:</span>
<span style="font-weight: bold;">${deviceIp}
<button onclick="copyToClipboard('${deviceIp}')" style="margin-left: 8px;" class="cbi-button cbi-button-neutral">复制</button>
</span>
<span style="display: flex; align-items: center;"><%:登录地址%>:</span>
<span style="font-weight: bold;">
<button onclick="copyToClipboard('${baseUrl}')" style="margin-left: 8px;" class="cbi-button cbi-button-neutral">复制</button>
</span>
</div>
`
tb.innerHTML += html

} catch (error) {
tb.innerHTML += '<br /><em style=\"color:red\"><%:backend error.%></em><br/>';
}
}
else
{
tb.innerHTML = '<em style=\"color:red\"><%:The nbtverify service is not running.%></em><br/>';
}
}
}
);
//]]></script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<legend><%:nbtverify status%></legend>
<p id="nbtverify_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>
5 changes: 4 additions & 1 deletion tools/pack.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ printfn "Args: %A" argv
let result = CommandLine.Parser.Default.ParseArguments<options>(argv)
let run (o: options) =
printfn "Parser success"
version <- o.version.TrimStart('v')
if o.version |> System.String.IsNullOrWhiteSpace then
printfn "Version not provided"
else
version <- o.version.TrimStart('v')
printfn "version = %s" version
let fail (e: IEnumerable<Error>) = failwithf "Parser failed with %A" e
match result with
Expand Down
20 changes: 10 additions & 10 deletions tools/sync.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ let doSync withDownload =
printfn "Updating %s" remotePath
upload file remotePath
else if withDownload then
printfn "Downloading %s" remotePath
download remotePath file
if remotePath <> "/etc/config/nbtverify" then
printfn "Downloading %s" remotePath
download remotePath file

let args = System.Environment.GetCommandLineArgs()

Expand All @@ -106,14 +107,13 @@ if args.Length > 2 then

System.Threading.Tasks.Task
.Delay(200)
.ContinueWith(fun _ ->
task {
try
doSync false
with ex ->
printfn "Error: %s" ex.Message
update ()
})
.ContinueWith(fun _ -> task {
try
doSync false
with ex ->
printfn "Error: %s" ex.Message
update ()
})
|> ignore


Expand Down

0 comments on commit ded0323

Please sign in to comment.