diff --git a/package/lean/leigod-acc/Makefile b/package/lean/leigod-acc/Makefile index 65b57ce24fb0ad..becc1224c1f1b5 100644 --- a/package/lean/leigod-acc/Makefile +++ b/package/lean/leigod-acc/Makefile @@ -51,6 +51,7 @@ define Package/$(PKG_NAME)/install $(INSTALL_BIN) ./files/acc-gw.linux.$(acc-arch) $(1)/usr/sbin/leigod/acc-gw.linux.$(acc-arch) $(INSTALL_BIN) ./files/leigod_uninstall.sh $(1)/usr/sbin/leigod/leigod_uninstall.sh $(INSTALL_BIN) ./files/plugin_common.sh $(1)/usr/sbin/leigod/plugin_common.sh + $(INSTALL_BIN) ./files/leigod-helper.sh $(1)/usr/sbin/leigod/leigod-helper.sh $(INSTALL_BIN) ./files/update_plugin $(1)/usr/sbin/leigod/update_plugin $(INSTALL_DATA) ./files/version $(1)/usr/sbin/leigod/version endef diff --git a/package/lean/leigod-acc/files/leigod-helper.sh b/package/lean/leigod-acc/files/leigod-helper.sh new file mode 100644 index 00000000000000..1dab4ddb232b11 --- /dev/null +++ b/package/lean/leigod-acc/files/leigod-helper.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# https://github.com/isecret/leigod-helper/blob/main/leigod-helper.sh + +USERNAME="${USERNAME:-phone}" +PASSWORD="${PASSWORD:-password}" + +if ! command -v "jq" > /dev/null; then + echo "缺失 jq 依赖"; + exit; +fi + +if command -v md5sum > /dev/null; then + password_hash=$(echo -n "$PASSWORD" | md5sum | awk '{print $1}') +elif command -v md5 > /dev/null; then + password_hash=$(echo -n "$PASSWORD" | md5) +else + echo "缺失 md5 或 md5sum 依赖,请手动安装" + exit 1 +fi + +login=$(curl -Lks -X POST https://webapi.leigod.com/api/auth/login \ + -H 'content-type: application/json' \ + -d "{ + \"account_token\": null, + \"country_code\": 86, + \"lang\": \"zh_CN\", + \"password\": \"$password_hash\", + \"region_code\": 1, + \"src_channel\": \"guanwang\", + \"user_type\": \"0\", + \"username\": \"$USERNAME\" + }") + +login_code=$(echo $login | jq -r ".code" 2>&1) +login_msg=$(echo $login | jq -r ".msg" 2>&1) + +if [ "$login_code" -eq 0 ]; then + account_token=$(echo $login | jq -r ".data.login_info.account_token" 2>&1) + pause=$(curl -Lks -X POST https://webapi.leigod.com/api/user/pause \ + -H 'content-type: application/json' \ + -d "{ + \"account_token\": \"$account_token\", + \"lang\": \"zh_CN\" + }") + pause_code=$(echo $pause | jq -r ".code" 2>&1) + pause_msg=$(echo $pause | jq -r ".msg" 2>&1) + + echo "暂停结果: $pause_msg" +else + echo "登录失败...原因: $login_msg" +fi diff --git a/package/lean/luci-app-leigod-acc/Makefile b/package/lean/luci-app-leigod-acc/Makefile index 1e29281fdad2c6..a586c11e4a0705 100644 --- a/package/lean/luci-app-leigod-acc/Makefile +++ b/package/lean/luci-app-leigod-acc/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=Luci for Leigod Game Accelerater LUCI_PKGARCH:=all -LUCI_DEPENDS:=+libpcap +iptables +kmod-ipt-nat +iptables-mod-tproxy +kmod-ipt-tproxy +kmod-tun +kmod-netem +tc-full +kmod-ipt-ipset +ipset +curl +miniupnpd +conntrack +conntrackd +leigod-acc +LUCI_DEPENDS:=+libpcap +iptables +kmod-ipt-nat +iptables-mod-tproxy +kmod-ipt-tproxy +kmod-tun +kmod-netem +tc-full +kmod-ipt-ipset +ipset +curl +miniupnpd +conntrack +conntrackd +leigod-acc +jq PKG_VERSION:=1 PKG_RELEASE:=3 diff --git a/package/lean/luci-app-leigod-acc/luasrc/controller/acc.lua b/package/lean/luci-app-leigod-acc/luasrc/controller/acc.lua index b7c11cdd471387..6d71e89b07246d 100644 --- a/package/lean/luci-app-leigod-acc/luasrc/controller/acc.lua +++ b/package/lean/luci-app-leigod-acc/luasrc/controller/acc.lua @@ -10,6 +10,7 @@ function index() entry({ "admin", "services", "acc", "status" }, call("get_acc_status")).leaf = true entry({ "admin", "services", "acc", "start_acc_service" }, call("start_acc_service")) entry({ "admin", "services", "acc", "stop_acc_service" }, call("stop_acc_service")) + entry({ "admin", "services", "acc", "schedule_pause" }, call("schedule_pause")) end -- get_acc_status get acc status @@ -62,7 +63,7 @@ function start_acc_service() luci.http.write_json(resp) end --- start_acc_service +-- stop_acc_service function stop_acc_service() -- util module local util = require "luci.util" @@ -72,4 +73,32 @@ function stop_acc_service() resp.result = "OK" luci.http.prepare_content("application/json") luci.http.write_json(resp) -end \ No newline at end of file +end + +-- schedule_pause +function schedule_pause() + local util = require "luci.util" + local uci = require "luci.model.uci".cursor() + + local schedule_enabled = uci:get("accelerator", "system", "schedule_enabled") or "0" + local pause_time = uci:get("accelerator", "system", "pause_time") or "01:00" + local username = uci:get("accelerator", "system", "username") or "" + local password = uci:get("accelerator", "system", "password") or "" + + -- Remove existing cron jobs related to leigod-helper.sh + util.exec("sed -i '/\\/usr\\/sbin\\/leigod\\/leigod-helper.sh/d' /etc/crontabs/root") + + if schedule_enabled == "1" then + local hour, minute = pause_time:match("(%d+):(%d+)") + local cron_time = string.format("%s %s * * * USERNAME='%s' PASSWORD='%s' /usr/sbin/leigod/leigod-helper.sh", tonumber(minute), tonumber(hour), username, password) + + -- Add new cron job + local cron_command = string.format('echo "%s" >> /etc/crontabs/root', cron_time) + util.exec(cron_command) + util.exec("/etc/init.d/cron restart") + end + + local resp = { result = "OK" } + luci.http.prepare_content("application/json") + luci.http.write_json(resp) +end diff --git a/package/lean/luci-app-leigod-acc/luasrc/model/cbi/leigod/service.lua b/package/lean/luci-app-leigod-acc/luasrc/model/cbi/leigod/service.lua index d6953d772aa7a9..7a6878b30c3b79 100644 --- a/package/lean/luci-app-leigod-acc/luasrc/model/cbi/leigod/service.lua +++ b/package/lean/luci-app-leigod-acc/luasrc/model/cbi/leigod/service.lua @@ -16,6 +16,28 @@ enable.default = 0 tun = s:option(Flag,"tun" ,translate("Tunnel Mode")) tun.rmempty = false tun.default = 0 +tun.description = translate("Turning Leigod into Tunnel mode can make some proxy plugins available") + +schedule_enabled = s:option(Flag, "schedule_enabled", translate("Scheduled Pause")) +schedule_enabled.rmempty = false +schedule_enabled.default = 0 +schedule_enabled.description = translate("Enable scheduled pause for Leigod Accelerator") + +pause_time = s:option(ListValue, "pause_time", translate("Pause Time")) +pause_time:depends("schedule_enabled", 1) +for i = 0, 23 do + pause_time:value(string.format("%02d:00", i), string.format("%02d:00", i)) +end +pause_time.rmempty = true + +username = s:option(Value, "username", translate("Phone Number")) +username:depends("schedule_enabled", 1) +username.rmempty = true + +password = s:option(Value, "password", translate("Leigod Password")) +password:depends("schedule_enabled", 1) +password.password = true +password.rmempty = true m:section(SimpleSection).template = "leigod/service" diff --git a/package/lean/luci-app-leigod-acc/po/zh-cn/leigo-acc.po b/package/lean/luci-app-leigod-acc/po/zh-cn/leigo-acc.po index caeff7728b1f7e..f07de639366977 100644 --- a/package/lean/luci-app-leigod-acc/po/zh-cn/leigo-acc.po +++ b/package/lean/luci-app-leigod-acc/po/zh-cn/leigo-acc.po @@ -86,11 +86,26 @@ msgstr "未分类设备" msgid "Tunnel Mode" msgstr "TUN 模式" +msgid "Turning Leigod into Tunnel mode can make some proxy plugins available" +msgstr "将雷神加速器设为 TUN 模式可以使一些 proxy 插件可用" + +msgid "Enable scheduled pause for Leigod Accelerator" +msgstr "启用后将在预设时间执行暂停时长操作" + +msgid "Pause Time" +msgstr "设置计划定时暂停的时间" + +msgid "Phone Number" +msgstr "手机号码" + +msgid "Leigod Password" +msgstr "雷神密码" + msgid "PC_Catalog" msgstr "PC 设备" msgid "Game_Catalog" -msgstr "游戏机" +msgstr "游戏主机" msgid "VR_Catalog" msgstr "VR 设备" diff --git a/package/lean/luci-app-leigod-acc/root/etc/config/accelerator b/package/lean/luci-app-leigod-acc/root/etc/config/accelerator index 5cf62be95a175b..270c193c1d6286 100644 --- a/package/lean/luci-app-leigod-acc/root/etc/config/accelerator +++ b/package/lean/luci-app-leigod-acc/root/etc/config/accelerator @@ -5,6 +5,10 @@ config system 'base' option base_url 'https://opapi.nn.com/speed' option enabled '0' option tun '0' + option schedule_enabled '0' + option pause_time '01:00' + option username '' + option password '' config bind 'bind'