🐶 Sync 2025-11-02 14:26:26

This commit is contained in:
actions-user
2025-11-02 14:26:26 +08:00
parent 64bcc56c2a
commit ac011db799
1557 changed files with 746465 additions and 0 deletions

View File

@@ -0,0 +1,147 @@
module("luci.controller.lucky", package.seeall)
function index()
if not nixio.fs.access("/etc/config/lucky") then
return
end
entry({"admin", "services", "lucky"}, alias("admin", "services", "lucky", "setting"),_("Lucky"), 57).dependent = true
entry({"admin", "services", "lucky", "setting"}, cbi("lucky/lucky"), _("Base Setting"), 20).leaf=true
entry({"admin", "services", "lucky_status"}, call("act_status"))
entry({"admin", "services", "lucky_info"}, call("lucky_info"))
entry({"admin", "services", "lucky_set_config"}, call("lucky_set_config"))
entry({"admin", "services", "lucky_service"}, call("lucky_service"))
end
function act_status()
local sys = require "luci.sys"
local e = { }
e.running = sys.call("pgrep -f 'lucky -c' >/dev/null") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function lucky_info()
local e = { }
local luckyInfo = luci.sys.exec("/usr/bin/lucky -info")
if (luckyInfo~=nil)
then
e.luckyInfo = luckyInfo
local configObj = GetLuckyConfigureObj()
if (configObj~=nil)
then
e.LuckyBaseConfigure = configObj["BaseConfigure"]
end
end
e.luckyArch = luci.sys.exec("/usr/bin/luckyarch")
--e.runStatus = luci.sys.call("pidof lucky >/dev/null") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function lucky_set_config()
local key = luci.http.formvalue("key")
local value = luci.http.formvalue("value")
local e = { }
e.ret = 1
if (key == "admin_http_port")
then
e.ret =setLuckyConf("AdminWebListenPort",value)
end
if(key=="admin_safe_url")
then
e.ret =setLuckyConf("SetSafeURL",value)
end
if(key=="reset_auth_info")
then
setLuckyConf("AdminAccount","666")
setLuckyConf("AdminPassword","666")
luci.sys.exec("/etc/init.d/lucky restart")
e.ret=0
end
if(key=="switch_Internetaccess")
then
e.ret =setLuckyConf("AllowInternetaccess",value)
end
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
function lucky_service()
local action = luci.http.formvalue("action")
if (action=="restart")
then
luci.sys.exec("uci set lucky.@lucky[0].enabled=1")
luci.sys.exec("uci commit")
luci.sys.exec("/etc/init.d/lucky restart")
end
if (action=="start")
then
luci.sys.exec("uci set lucky.@lucky[0].enabled=1")
luci.sys.exec("uci commit")
luci.sys.exec("/etc/init.d/lucky start")
end
if (action=="stop")
then
luci.sys.exec("uci set lucky.@lucky[0].enabled=0")
luci.sys.exec("uci commit")
luci.sys.exec("/etc/init.d/lucky stop")
end
end
function trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
function GetLuckyConfigureObj()
configPath = trim(luci.sys.exec("uci get lucky.@lucky[0].configdir"))
local configContent = luci.sys.exec("lucky -baseConfInfo -cd "..configPath)
configObj = luci.jsonc.parse(trim(configContent))
return configObj
end
function setLuckyConf(key,value)
configPath = trim(luci.sys.exec("uci get lucky.@lucky[0].configdir"))
cmd = "/usr/bin/lucky ".." -setconf ".."-key "..key.." -value "..value.." -cd "..configPath
if (value=="")
then
cmd = "/usr/bin/lucky ".." -setconf ".."-key "..key.." -cd "..configPath
end
luci.sys.exec(cmd)
return 0
end

View File

@@ -0,0 +1,25 @@
--
local m, s ,o
local m = Map("lucky", translate("Lucky"), translate("ipv4/ipv6 portforward,ddns,reverseproxy proxy,wake on lan,IOT and more...") )
m:section(SimpleSection).template = "lucky/lucky_status"
s = m:section(TypedSection, "lucky", translate("Basic Settings"))
s.addremove=false
s.anonymous=true
--o=s:option(Flag,"enabled",translate("Enable"))
--o.default=0
o = s:option( Value, "configdir", translate("Config dir path"),
translate("The path to store the config file"))
o.placeholder = "/etc/config/lucky.daji"
m.apply_on_parse = true
m.on_after_apply = function(self,map)
luci.sys.exec("/etc/init.d/lucky restart")
end
return m

View File

@@ -0,0 +1,355 @@
<style>
.mar-10 {
margin-left: 50px;
margin-right: 10px;
}
#_luckyAdminLink,#_luckyAdminOpen{
font-weight: bold;
}
</style>
<fieldset class="cbi-section">
<p id="_luckyAdminLink"></p>
</fieldset>
<style>
.cbi-section {
border: 1px solid #ccc;
padding: 10px;
}
.cbi-section td:first-child {
font-weight: bold;
}
</style>
<fieldset class="cbi-section">
<legend><%:Main Program Information%></legend>
<table>
<tr>
<td><%:Installation Status%></td>
<td id="_luckyInstallStatus"><%:Collecting data...%></td>
</tr>
<tr>
<td><%:Lucky Status%></td>
<td id="_luckyStatus"><%:Collecting data...%></td>
</tr>
<tr>
<td><%:Lucky Arch%></td>
<td id="_luckyArch"><%:Collecting data...%></td>
</tr>
<tr>
<td><%:Compilation Time%></td>
<td id="_luckyCompilationTime"><%:Collecting data...%></td>
</tr>
<tr>
<td><%:Lucky Version%></td>
<td id="_luckyVersion"><%:Collecting data...%></td>
</tr>
</table>
</fieldset>
<fieldset class="cbi-section">
<legend><%:Admin Panel Information%></legend>
<table>
<tr>
<td><%:Admin Panel%></td>
<td id="_luckyAdminOpen"><%:Collecting data...%></td>
</tr>
<tr>
<td><%:Admin Panel Login Info%></td>
<td id="_luckyLoginInfo"><%:Collecting data...%></td>
</tr>
</table>
</fieldset>
<script type="text/javascript">
var daip = document.getElementById('_daip');
var luckyInstallStatus = document.getElementById('_luckyInstallStatus')
//var luckyAdminPanelURL = document.getElementById('_luckyAdminPanelURL')
var luckyArch = document.getElementById('_luckyArch')
var luckyStatus = document.getElementById('_luckyStatus')
var luckyCompilationTime = document.getElementById('_luckyCompilationTime')
var luckyVersion = document.getElementById('_luckyVersion')
var luckyLoginInfo = document.getElementById('_luckyLoginInfo')
var luckyAdminOpen = document.getElementById('_luckyAdminOpen')
var luckyHttpPort = document.getElementById('_luckyHttpPort')
var luckyAllowInternetaccess = document.getElementById('_luckyAllowInternetaccess')
var luckySafeURL = document.getElementById('_luckySafeURL')
var luckyAdminLink = document.getElementById('_luckyAdminLink')
var luckyInstalled = false
var adminHttpURL = ""
FlushLuckyInfo()
MotitorLuckyState()
function flushLuckyStatus(status) {
if (status) {
luckyStatus.innerHTML = '<b style=color:green><%:The Lucky service is running.%></b>'
luckyStatus.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyStatus.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Stop%>" onclick="return StopService()"/>'
//luckyAdminOpen.innerHTML = '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Open AdminURL%>" onclick="return OpenAdminURL(this,adminHttpURL)"/>'
luckyAdminOpen.innerHTML = '<a href="' + adminHttpURL + '"' + ' target="_blank">' + adminHttpURL + '</a> '
luckyAdminLink.innerHTML = '<b><a href="' + adminHttpURL + '"' + ' target="_blank">' + adminHttpURL + '</a></b> '
} else {
if (luckyInstalled) {
luckyStatus.innerHTML = '<b style=color:red><%:The Lucky service is not running.%></b>'
luckyStatus.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyStatus.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Start%>" onclick="return StartService()"/>'
} else {
luckyStatus.innerHTML = '<b style=color:red><%:Not installed%></b>'
}
luckyAdminOpen.innerHTML = ''
luckyAdminLink.innerHTML = ''
}
}
function FlushLuckyInfo() {
XHR.get('<%=url([[admin]], [[services]], [[lucky_info]])%>', null,
function (x, info) {
if (info) {
luckyArch.innerHTML = '<b style=color:blue>' + info.luckyArch + '</b>'
if (info.luckyInfo == "") {
luckyInstalled = false
//console.log("没有安装")
luckyStatus.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyInstallStatus.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyHttpPort.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyCompilationTime.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyLoginInfo.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyAdminOpen.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyAllowInternetaccess.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckySafeURL.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyVersion.innerHTML = '<b style=color:red><%:Not installed%></b>'
luckyVersion.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyVersion.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:get latest version%>" onclick="return OpenGithub()"/>'
luckyAdminLink.innerHTML = ''
return
}
luckyInstalled = true
luckyInstallStatus.innerHTML = '<b style=color:green><%:Installed%></b>'
console.log("已经安装")
var luckyInfo = JSON.parse(info.luckyInfo)
luckyCompilationTime.innerHTML = "<b style=color:green>" + luckyInfo.Date + "</b>"
luckyVersion.innerHTML = "<b style=color:green>" + luckyInfo.Version + "</b>"
luckyVersion.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyVersion.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:get latest version%>" onclick="return OpenGithub()"/>'
adminHttpURL = "http://" + window.location.hostname + ":" + info.LuckyBaseConfigure.AdminWebListenPort
if (info.LuckyBaseConfigure.SafeURL != undefined) {
adminHttpURL += info.LuckyBaseConfigure.SafeURL
}
luckyLoginInfo.innerHTML =
"<b style=color:green><%:DefaultAuth%>:666" + "</b>"
luckyLoginInfo.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyLoginInfo.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Reset%>" onclick="return ResetAuthInfo(this)"/>'
luckyHttpPort.innerHTML = '<input disabled id="_luckyHttpPortInput" type="text" class="cbi-input-text"data-type="uinteger" style="width:30%" value="' + info.LuckyBaseConfigure.AdminWebListenPort + '"/>'
luckyHttpPort.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyHttpPort.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Change%>" onclick="return SetNewHttpPort(this)"/>'
luckySafeURL.innerHTML = '<input disabled id="_luckySafeURLInput" type="text" class="cbi-input-text"data-type="uinteger" style="width:30%" value="' + info.LuckyBaseConfigure.SafeURL + '"/>'
luckySafeURL.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckySafeURL.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Change%>" onclick="return SetNewSafeURL(this)"/>'
if (info.LuckyBaseConfigure.AllowInternetaccess) {
luckyAllowInternetaccess.innerHTML = '<b style=color:green><%:allow%></b>'
luckyAllowInternetaccess.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyAllowInternetaccess.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Disable%>" onclick="return SwitchAllowInternetaccess(false)"/>'
} else {
luckyAllowInternetaccess.innerHTML = '<b style=color:red><%:not allow%></b>'
luckyAllowInternetaccess.innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
luckyAllowInternetaccess.innerHTML += '<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Enable%>" onclick="return SwitchAllowInternetaccess(true)"/>'
}
}
}
);
}
function SwitchAllowInternetaccess(b) {
console.log("切换:" + b)
if (b) {
if (confirm("<%:Are you sure Enalbe Internetaccess?%>")) {
SetLuckyConfig("switch_Internetaccess", "true")
}
return
}
if (confirm("<%:Are you sure Disable Internetaccess?%>")) {
SetLuckyConfig("switch_Internetaccess", "false")
}
}
var luckyPreState = false
function MotitorLuckyState() {
XHR.poll(3, '<%=url([[admin]], [[services]], [[lucky_status]])%>', null,
function (x, data) {
if (data) {
if (luckyPreState != data.running) {
FlushLuckyInfo()
console.log("服务状态发生变化")
}
luckyPreState = data.running
flushLuckyStatus(data.running)
}
}
);
}
function OpenAdminURL(btn, url) {
winOpen(url)
}
function SetNewHttpPort(btn) {
var luckyHttpPortInput = document.getElementById('_luckyHttpPortInput')
console.log(luckyHttpPortInput.value)
var newPort = prompt("<%:NewHttpPort%>");
if (newPort == null) {
return
}
if (luckyHttpPortInput.value == newPort) {
return
}
if (!isNumber(newPort)) {
alert("<%:portValueError%>");
return
}
var newPortValue = parseInt(newPort)
if (newPortValue <= 0 || newPortValue > 65535) {
alert("<%:portValueError%>");
return
}
console.log("新端口:" + newPortValue)
SetLuckyConfig("admin_http_port", newPort)
}
function SetNewSafeURL(btn) {
var luckySafeURLInput = document.getElementById('_luckySafeURLInput')
console.log("fuckURL:" + luckySafeURLInput.value)
var newSafeURL = prompt("<%:NewHttpPort%>");
if (newSafeURL == null) {
return
}
if (newSafeURL == luckySafeURLInput.value) {
return
}
SetLuckyConfig("admin_safe_url", newSafeURL)
}
function ResetAuthInfo(btn) {
if (confirm("<%:Reset 666 as admin account and password?%>")) {
SetLuckyConfig("reset_auth_info", "")
}
}
function SetLuckyConfig(key, value) {
XHR.get('<%=url([[admin]], [[services]], [[lucky_set_config]])%>', { key: key, value: value },
function (x, res) {
if (res) {
//console.log(res)
if (res.ret != undefined && res.ret == 0) {
FlushLuckyInfo()
alert("<%:update success%>")
ControllLuckyService("restart")
setTimeout('document.location.reload()',2000)
} else {
alert("<%:update failed%>")
}
}
});
}
function ControllLuckyService(action) {
console.log("ControllLuckyService:" + action)
XHR.get('<%=url([[admin]], [[services]], [[lucky_service]])%>', { action: action },
function (x) {
});
}
function StopService() {
if (confirm("<%:are you sure stop lucky service?%>")) {
ControllLuckyService("stop")
}
}
function StartService() {
if (confirm("<%:are you sure start lucky service?%>")) {
ControllLuckyService("start")
}
}
function OpenGithub() {
winOpen("https://url21.ctfile.com/d/44547821-55537427-a5525e?p=16601")
}
function winOpen(url) {
var winOpen = window.open(url);
if (winOpen == null || typeof (winOpen) == 'undefined') {
window.location.href = url;
}
};
function isNumber(val) {
// negative or positive
return /^[-]?[\.\d]+$/.test(val);
}
</script>