diff --git a/luci-app-lucky/Makefile b/luci-app-lucky/Makefile index dc88c7f20..381a8048c 100644 --- a/luci-app-lucky/Makefile +++ b/luci-app-lucky/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-lucky -PKG_VERSION:=1.0.4 +PKG_VERSION:=1.1.1 PKG_RELEASE:=5 LUCI_TITLE:=LuCI Support for Dynamic lucky Client diff --git a/luci-app-lucky/luasrc/controller/lucky.lua b/luci-app-lucky/luasrc/controller/lucky.lua index 90037b322..5ec361a37 100644 --- a/luci-app-lucky/luasrc/controller/lucky.lua +++ b/luci-app-lucky/luasrc/controller/lucky.lua @@ -1,32 +1,54 @@ -- Copyright (C) 2021-2022 sirpdboy https://github.com/sirpdboy/luci-app-lucky -- Licensed to the public under the Apache License 2.0. +local SYS = require "luci.sys" module("luci.controller.lucky", package.seeall) function index() - - entry({"admin", "services", "lucky"}, alias("admin", "services", "lucky", "setting"),_("Lucky"), 57).dependent = true + local e=entry({"admin", "services", "lucky"}, alias("admin", "services", "lucky", "setting"),_("Lucky"), 57) + e.dependent=false + e.acl_depends={ "luci-app-lucky" } entry({"admin", "services", "lucky", "setting"}, cbi("lucky"), _("Base Setting"), 20).leaf=true entry({"admin", "services", "lucky", "lucky"}, template("lucky"), _("Lucky"), 30).leaf = true - entry({"admin", "services", "lucky", "lucky_admin"}, call("lucky_admin")).leaf = true - entry({"admin", "services", "lucky_status"}, call("act_status")) + entry({"admin", "services", "lucky_status"}, call("lucky_status")) + entry({"admin", "services", "lucky_config"}, call("lucky_config")) end -function act_status() - local uci = require 'luci.model.uci'.cursor() - local port = tonumber(uci:get_first("lucky", "lucky", "port")) + +function lucky_config() local e = { } - e.running = luci.sys.call("pidof lucky >/dev/null") == 0 - e.port = (port or 16601) - e.safeurl = luci.sys.exec("cat /etc/lucky/lucky.conf | grep SafeURL | sed -e 's/,//g' -e 's/\"//g' -e 's/\ //g' | awk -F ':' '{print $2}' ") + local luckyInfo = SYS.exec("/usr/bin/lucky -info") + if (luckyInfo~=nil) + then + local configObj = ConfigureObj() + if (configObj~=nil) + then + e.BaseConfigure = configObj["BaseConfigure"] + end + end + e.luckyArch = SYS.exec("/usr/bin/luckyarch") + luci.http.prepare_content("application/json") + luci.http.write_json(e) +end + + +function lucky_status() + local e = { } + e.status = SYS.call("pgrep -f 'lucky -c' >/dev/null") == 0 luci.http.prepare_content("application/json") luci.http.write_json(e) end -function lucky_admin() - local e = { } - e.username = luci.sys.exec("cat /etc/lucky/lucky.conf | grep AdminAccount | sed -e 's/,//g' -e 's/\"//g' | awk -F ':' '{print $2}' ") - e.password = luci.sys.exec("cat /etc/lucky/lucky.conf | grep AdminPassword | sed -e 's/,//g' -e 's/\"//g' | awk -F ':' '{print $2}' ") - luci.http.prepare_content("application/json") - luci.http.write_json(e) + +function trim(s) + return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end + + +function ConfigureObj() + 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 + diff --git a/luci-app-lucky/luasrc/model/cbi/lucky.lua b/luci-app-lucky/luasrc/model/cbi/lucky.lua index a7b27a474..e5785b24d 100644 --- a/luci-app-lucky/luasrc/model/cbi/lucky.lua +++ b/luci-app-lucky/luasrc/model/cbi/lucky.lua @@ -4,7 +4,7 @@ local m, s ,o m = Map("lucky") m.title = translate("Lucky") -m.description = translate("Main functions of Lucky: dynamic domain name ddns-go service, which replaces socat. It is mainly used for public IPv6 tcp/udp to intranet ipv4, http/https reverse proxy frp")..translate("
For specific usage, see:")..translate("GitHub @sirpdboy/luci-app-lucky 。") +m.description = translate("ipv4/ipv6 portforward,ddns,reverseproxy proxy,wake on lan,IOT and more,Default username and password 666") m:section(SimpleSection).template = "lucky_status" @@ -19,12 +19,9 @@ o = s:option(Value, "port",translate("Set the Lucky access port")) o.datatype = "uinteger" o.default = 16601 -o = s:option(Flag, "AllowInternetaccess", translate("Enable Internet access")) -o.default=0 - -o = s:option(Button, "lucky_admin", translate("View Password")) -o.rawhtml = true -o.template = "lucky_admin" +o = s:option( Value, "configdir", translate("Config dir path"),translate("The path to store the config file")) +o.placeholder = "/etc/lucky" +o.default="/etc/lucky" m.apply_on_parse = true m.on_after_apply = function(self,map) diff --git a/luci-app-lucky/luasrc/view/lucky.htm b/luci-app-lucky/luasrc/view/lucky.htm index 2a665907e..dd040947d 100644 --- a/luci-app-lucky/luasrc/view/lucky.htm +++ b/luci-app-lucky/luasrc/view/lucky.htm @@ -2,36 +2,38 @@ Copyright 2021-2022 sirpdboy Wich https://github.com/sirpdboy/luci-app-lucky Licensed to the public under the Apache License 2.0. --%> - -<% - local safeURL = luci.sys.exec("cat /etc/lucky/lucky.conf | grep SafeURL | sed -e 's/,//g' -e 's/\"//g' -e 's/\ //g' | awk -F ':' '{print $2}' ") - local luckyHttpPort = luci.model.uci.cursor():get("lucky", "lucky", "port"); --%> +%> <%+header%> + +
-
- <%+footer%> diff --git a/luci-app-lucky/luasrc/view/lucky_admin.htm b/luci-app-lucky/luasrc/view/lucky_admin.htm deleted file mode 100644 index ca1946ac1..000000000 --- a/luci-app-lucky/luasrc/view/lucky_admin.htm +++ /dev/null @@ -1,26 +0,0 @@ -<%+cbi/valueheader%> - - -<%=self.value%> -<%+cbi/valuefooter%> \ No newline at end of file diff --git a/luci-app-lucky/luasrc/view/lucky_status.htm b/luci-app-lucky/luasrc/view/lucky_status.htm index db7b0bf7c..c545f0753 100644 --- a/luci-app-lucky/luasrc/view/lucky_status.htm +++ b/luci-app-lucky/luasrc/view/lucky_status.htm @@ -1,26 +1,45 @@ +<% +protocol="http://" +%>
diff --git a/luci-app-lucky/po/zh-cn/lucky.po b/luci-app-lucky/po/zh-cn/lucky.po index ce67dfe92..71fe5c50b 100644 --- a/luci-app-lucky/po/zh-cn/lucky.po +++ b/luci-app-lucky/po/zh-cn/lucky.po @@ -1,11 +1,14 @@ msgid "" msgstr "Content-Type: text/plain; charset=UTF-8" +msgid "Config dir path" +msgstr "配置文件夹位置" + msgid "Lucky" msgstr "Lucky大吉" -msgid "Main functions of Lucky: dynamic domain name ddns-go service, which replaces socat. It is mainly used for public IPv6 tcp/udp to intranet ipv4, http/https reverse proxy frp" -msgstr "大吉主要功能:动态域名ddns-go服务,替代socat主要用于公网IPv6 tcp/udp转内网ipv4,http/https反向代理,网络唤醒(可通过第三方物联网平台接入各大语音助手实现语音控制开关电脑)" +msgid "ipv4/ipv6 portforward,ddns,reverseproxy proxy,wake on lan,IOT and more,Default username and password 666" +msgstr "IPv4/IPv6端口转发,动态域名服务,http/https反向代理,默认用户名密码666.." msgid "Running state" msgstr "运行状态" @@ -28,29 +31,15 @@ msgstr "设置访问端口" msgid "Lucky configuration file" msgstr "Lucky 配置文件" +msgid "The path to store the config file" +msgstr "存放配置文件的位置" + msgid "
For specific usage, see:" msgstr "
具体使用方法参见:" msgid "Base Setting" msgstr "基本设置" -msgid "Enable Internet access" -msgstr "开启外网访问" - msgid "Click the new page to open Lucky" msgstr "点击新页面打开大吉" -msgid "View Password" -msgstr "查看密码" - -msgid "Username:" -msgstr "用户名:" - -msgid "Password:" -msgstr "密码:" - -msgid "Reading..." -msgstr "读取中..." - -msgid "Read" -msgstr "读取" \ No newline at end of file diff --git a/luci-app-lucky/po/zh_Hans b/luci-app-lucky/po/zh_Hans deleted file mode 120000 index 41451e4a1..000000000 --- a/luci-app-lucky/po/zh_Hans +++ /dev/null @@ -1 +0,0 @@ -zh-cn \ No newline at end of file diff --git a/luci-app-lucky/po/zh_Hans/lucky.po b/luci-app-lucky/po/zh_Hans/lucky.po new file mode 100644 index 000000000..71fe5c50b --- /dev/null +++ b/luci-app-lucky/po/zh_Hans/lucky.po @@ -0,0 +1,45 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "Config dir path" +msgstr "配置文件夹位置" + +msgid "Lucky" +msgstr "Lucky大吉" + +msgid "ipv4/ipv6 portforward,ddns,reverseproxy proxy,wake on lan,IOT and more,Default username and password 666" +msgstr "IPv4/IPv6端口转发,动态域名服务,http/https反向代理,默认用户名密码666.." + +msgid "Running state" +msgstr "运行状态" + +msgid "The Lucky service is running." +msgstr "大吉服务已启动" + +msgid "The Lucky service is not running." +msgstr "大吉服务未启动" + +msgid "Lucky Status" +msgstr "大吉服务状态" + +msgid "Collecting data..." +msgstr "收集数据..." + +msgid "Set the Lucky access port" +msgstr "设置访问端口" + +msgid "Lucky configuration file" +msgstr "Lucky 配置文件" + +msgid "The path to store the config file" +msgstr "存放配置文件的位置" + +msgid "
For specific usage, see:" +msgstr "
具体使用方法参见:" + +msgid "Base Setting" +msgstr "基本设置" + +msgid "Click the new page to open Lucky" +msgstr "点击新页面打开大吉" + diff --git a/luci-app-lucky/root/etc/config/lucky b/luci-app-lucky/root/etc/config/lucky index 86121ce03..03c96239c 100644 --- a/luci-app-lucky/root/etc/config/lucky +++ b/luci-app-lucky/root/etc/config/lucky @@ -1,5 +1,5 @@ config lucky 'lucky' - option enabled '0' option logger '1' option port '16601' - option AllowInternetaccess '0' + option configdir '/etc/lucky' + option enabled '0' diff --git a/luci-app-lucky/root/etc/init.d/lucky b/luci-app-lucky/root/etc/init.d/lucky old mode 100755 new mode 100644 index c3da3a9c8..6f245d93a --- a/luci-app-lucky/root/etc/init.d/lucky +++ b/luci-app-lucky/root/etc/init.d/lucky @@ -9,50 +9,52 @@ USE_PROCD=1 START=99 -STOP=10 +STOP=15 CONF="lucky" PROG=/usr/bin/lucky -LUCKYDIR=/etc/lucky -LUCKYCONF=/etc/lucky/lucky.conf +DEFAULT_DIR='/etc/config/lucky.daji/' + +get_tz() +{ + SET_TZ="" + + [ -e "/etc/localtime" ] && return + + for tzfile in /etc/TZ /var/etc/TZ + do + [ -e "$tzfile" ] || continue + tz="$(cat $tzfile 2>/dev/null)" + done + + [ -z "$tz" ] && return + + SET_TZ=$tz +} get_config() { config_get_bool enabled $1 enabled 1 - config_get_bool logger $1 logger 1 - config_get port $1 port 16601 - config_get AllowInternetaccess $1 AllowInternetaccess 0 + config_get_bool logger $1 logger 1 + config_get configdir $1 configdir $DEFAULT_DIR } -lucky_prepare() { - pgrep -f $PROG | xargs kill -9 >/dev/null 2>&1 -} - - start_service() { - stop_service config_load "$CONF" config_foreach get_config "$CONF" [ "x$enabled" = "x1" ] || return 1 - if [ "x$AllowInternetaccess" = "x1" ] ;then - sed -i 's/"AllowInternetaccess": false,/"AllowInternetaccess": true,/g' "$LUCKYCONF" - else - sed -i 's/"AllowInternetaccess": true,/"AllowInternetaccess": false,/g' "$LUCKYCONF" - fi - # set_firewall + [ ! -d $configdir ] && mkdir -p $configdir 2>/dev/null procd_open_instance - procd_set_param command "$PROG" - procd_append_param command -c "$LUCKYCONF" -p $port + get_tz + [[ -z "$SET_TZ" ]] || procd_set_param env TZ="$SET_TZ" + procd_set_param command $PROG -cd "$configdir" [ "x$logger" == x1 ] && procd_set_param stderr 1 procd_set_param respawn procd_close_instance } -stop_service() { - lucky_prepare -} service_triggers() { - procd_add_reload_trigger "$CONF" + procd_add_reload_trigger lucky } diff --git a/luci-app-lucky/root/etc/lucky/lucky.conf b/luci-app-lucky/root/etc/lucky/lucky.conf deleted file mode 100644 index 5220d5ae0..000000000 --- a/luci-app-lucky/root/etc/lucky/lucky.conf +++ /dev/null @@ -1,62 +0,0 @@ -{ - "BaseConfigure": { - "AdminWebListenPort": 16601, - "AdminWebListenTLS": false, - "AdminWebListenHttpsPort": 16626, - "AdminAccount": "666", - "AdminPassword": "666", - "AllowInternetaccess": false, - "LogMaxSize": 2048, - "HttpClientTimeout": 20, - "InsecureSkipVerify": false, - "DisableModules": null, - "SafeURL": "" - }, - "WhiteListConfigure": { - "BaseConfigure": { - "URL": "", - "ActivelifeDuration": 36, - "BasicAccount": "666", - "BasicPassword": "666" - }, - "WhiteList": null - }, - "BlackListConfigure": { - "BlackList": null - }, - "DDNSConfigure": { - "Enable": false, - "FirstCheckDelay": 0, - "Intervals": 0 - }, - "DDNSTaskList": null, - "ReverseProxyRuleList": null, - "SSLCertficateList": null, - "PortForwardsRuleList": null, - "PortForwardsConfigure": { - "PortForwardsLimit": 128, - "TCPPortforwardMaxConnections": 1024, - "UDPReadTargetDataMaxgoroutineCount": 1024 - }, - "WOLDeviceList": null, - "WOLServiceConfigure": { - "Server": { - "Enable": false, - "Token": "666666" - }, - "Client": { - "Enable": false, - "ServerURL": "", - "Token": "", - "Relay": false, - "Key": "", - "DeviceName": "", - "Mac": "", - "BroadcastIP": "", - "Port": 9, - "Repeat": 5, - "PowerOffCMD": "", - "UpdateTime": 0 - } - } -} diff --git a/luci-app-lucky/root/etc/uci-defaults/luci-lucky b/luci-app-lucky/root/etc/uci-defaults/luci-lucky index 09e0d28e2..7d165887d 100644 --- a/luci-app-lucky/root/etc/uci-defaults/luci-lucky +++ b/luci-app-lucky/root/etc/uci-defaults/luci-lucky @@ -6,6 +6,6 @@ uci -q batch <<-EOF >/dev/null set ucitrack.@lucky[-1].init=lucky commit ucitrack EOF - +[[ -f /etc/config/lucky ]] || echo "config lucky 'lucky' " > /etc/config/lucky rm -rf /tmp/luci* exit 0