mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
luci-app-leigod-acc: add scheduled pause (#12404)
* Leigod-Acc: Add Scheduled Pause * luci-app-leigod-acc: add scheduled pause --------- Co-authored-by: 喵二 <2860950766@qq.com>
This commit is contained in:
parent
28e2e4d04a
commit
b9910de8d9
@ -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/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/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/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_BIN) ./files/update_plugin $(1)/usr/sbin/leigod/update_plugin
|
||||||
$(INSTALL_DATA) ./files/version $(1)/usr/sbin/leigod/version
|
$(INSTALL_DATA) ./files/version $(1)/usr/sbin/leigod/version
|
||||||
endef
|
endef
|
||||||
|
51
package/lean/leigod-acc/files/leigod-helper.sh
Normal file
51
package/lean/leigod-acc/files/leigod-helper.sh
Normal file
@ -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
|
@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
LUCI_TITLE:=Luci for Leigod Game Accelerater
|
LUCI_TITLE:=Luci for Leigod Game Accelerater
|
||||||
LUCI_PKGARCH:=all
|
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_VERSION:=1
|
||||||
PKG_RELEASE:=3
|
PKG_RELEASE:=3
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ function index()
|
|||||||
entry({ "admin", "services", "acc", "status" }, call("get_acc_status")).leaf = true
|
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", "start_acc_service" }, call("start_acc_service"))
|
||||||
entry({ "admin", "services", "acc", "stop_acc_service" }, call("stop_acc_service"))
|
entry({ "admin", "services", "acc", "stop_acc_service" }, call("stop_acc_service"))
|
||||||
|
entry({ "admin", "services", "acc", "schedule_pause" }, call("schedule_pause"))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get_acc_status get acc status
|
-- get_acc_status get acc status
|
||||||
@ -62,7 +63,7 @@ function start_acc_service()
|
|||||||
luci.http.write_json(resp)
|
luci.http.write_json(resp)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- start_acc_service
|
-- stop_acc_service
|
||||||
function stop_acc_service()
|
function stop_acc_service()
|
||||||
-- util module
|
-- util module
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
@ -72,4 +73,32 @@ function stop_acc_service()
|
|||||||
resp.result = "OK"
|
resp.result = "OK"
|
||||||
luci.http.prepare_content("application/json")
|
luci.http.prepare_content("application/json")
|
||||||
luci.http.write_json(resp)
|
luci.http.write_json(resp)
|
||||||
end
|
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
|
||||||
|
@ -16,6 +16,28 @@ enable.default = 0
|
|||||||
tun = s:option(Flag,"tun" ,translate("Tunnel Mode"))
|
tun = s:option(Flag,"tun" ,translate("Tunnel Mode"))
|
||||||
tun.rmempty = false
|
tun.rmempty = false
|
||||||
tun.default = 0
|
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"
|
m:section(SimpleSection).template = "leigod/service"
|
||||||
|
|
||||||
|
@ -86,11 +86,26 @@ msgstr "未分类设备"
|
|||||||
msgid "Tunnel Mode"
|
msgid "Tunnel Mode"
|
||||||
msgstr "TUN 模式"
|
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"
|
msgid "PC_Catalog"
|
||||||
msgstr "PC 设备"
|
msgstr "PC 设备"
|
||||||
|
|
||||||
msgid "Game_Catalog"
|
msgid "Game_Catalog"
|
||||||
msgstr "游戏机"
|
msgstr "游戏主机"
|
||||||
|
|
||||||
msgid "VR_Catalog"
|
msgid "VR_Catalog"
|
||||||
msgstr "VR 设备"
|
msgstr "VR 设备"
|
||||||
|
@ -5,6 +5,10 @@ config system 'base'
|
|||||||
option base_url 'https://opapi.nn.com/speed'
|
option base_url 'https://opapi.nn.com/speed'
|
||||||
option enabled '0'
|
option enabled '0'
|
||||||
option tun '0'
|
option tun '0'
|
||||||
|
option schedule_enabled '0'
|
||||||
|
option pause_time '01:00'
|
||||||
|
option username ''
|
||||||
|
option password ''
|
||||||
|
|
||||||
config bind 'bind'
|
config bind 'bind'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user