Skip to content

Commit

Permalink
luci-app-leigod-acc: add scheduled pause (#12404)
Browse files Browse the repository at this point in the history
* Leigod-Acc: Add Scheduled Pause

* luci-app-leigod-acc: add scheduled pause

---------

Co-authored-by: 喵二 <[email protected]>
  • Loading branch information
miaoermua and 喵二 authored Oct 18, 2024
1 parent 28e2e4d commit b9910de
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
1 change: 1 addition & 0 deletions package/lean/leigod-acc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions package/lean/leigod-acc/files/leigod-helper.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package/lean/luci-app-leigod-acc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 31 additions & 2 deletions package/lean/luci-app-leigod-acc/luasrc/controller/acc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -72,4 +73,32 @@ function stop_acc_service()
resp.result = "OK"
luci.http.prepare_content("application/json")
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 16 additions & 1 deletion package/lean/luci-app-leigod-acc/po/zh-cn/leigo-acc.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 设备"
Expand Down
4 changes: 4 additions & 0 deletions package/lean/luci-app-leigod-acc/root/etc/config/accelerator
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit b9910de

Please sign in to comment.