leigod-acc: add Leigod Game Accelerater package and luci

This commit is contained in:
coolsnowwolf 2024-08-01 18:32:40 +08:00
parent 576235b0f1
commit e958c5f2b3
20 changed files with 1488 additions and 0 deletions

View File

@ -0,0 +1,58 @@
#
# Copyright (C) 2015-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=leigod-acc
PKG_VERSION:=1.3.0.30
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=Powerful Leigod Game Accelerater
DEPENDS:=@(x86_64||arm||mipsel||aarch64)
URL:=https://www.leigod.com/
endef
define Package/$(PKG_NAME)/description
leigod-acc is a powerful game accelerater
endef
ifeq ($(ARCH),x86_64)
acc-arch:=amd64
endif
ifeq ($(ARCH),mipsel)
acc-arch:=mipsle
endif
ifeq ($(ARCH),arm)
acc-arch:=arm
endif
ifeq ($(ARCH),aarch64)
acc-arch:=arm64
endif
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/sbin/leigod
$(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/update_plugin $(1)/usr/sbin/leigod/update_plugin
$(INSTALL_DATA) ./files/version $(1)/usr/sbin/leigod/version
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,24 @@
#!/bin/sh
# this script is use to install leigod plugin
ver_name="version"
init_file_name="acc"
binary_prefix="acc-gw.linux"
common_file_name="plugin_common.sh"
download_base_url="http://119.3.40.126/router_plugin"
# include common file
. ${common_file_name}
# preinstall_check
# check and set env
preinstall_check
if [ ${is_openwrt} ]; then
echo "remove openwrt config"
remove_openwrt_series_config
remove_openwrt_series_init
fi
# remove_binary remove binary
remove_binary

View File

@ -0,0 +1,502 @@
# this script is use to install leigod plugin
# sbin_dir="/usr/sbin/leigod"
ver_name="version"
init_file_name="acc"
binary_prefix="acc-gw.linux"
common_file_name="plugin_common.sh"
uninstall_file_name="leigod_uninstall.sh"
download_base_url="http://119.3.40.126/router_plugin"
# get_device_os
# current support os: Linux
get_device_os() {
os=$(uname)
if [ $? == "0" ]; then
return 0
fi
echo "os cant be get"
return -1
}
# get_device_arch,
# current support arch: arm64 arm x86_64 mips
get_device_arch() {
arch=$(uname -m)
if [ $? == "0" ]; then
return 0
fi
echo "arch cant be get"
return -1
}
# get_xiaomi_name check if is xiaomi
get_xiaomi_name() {
local name=$(uci get misc.hardware.displayName)
if [[ $? == "0" && ${name} != "" ]]; then
echo "router is xiaomi series, name: ${name}"
sbin_dir="/userdisk/appdata/leigod"
init_dir="/userdisk/appdata/leigod"
is_xiaomi=true
return 0
fi
local name=$(uci get misc.hardware.model)
if [[ $? == "0" && ${name} != "" ]]; then
echo "router is xiaomi series, name: ${name}"
sbin_dir="/userdisk/appdata/leigod"
init_dir="/userdisk/appdata/leigod"
is_xiaomi=true
return 0
fi
local name=$(uci get misc.hardware.model)
if [[ $? == "0" && ${name} != "" ]]; then
echo "router is xiaomi series, name: ${name}"
sbin_dir="/userdisk/appdata/leigod"
init_dir="/userdisk/appdata/leigod"
is_xiaomi=true
return 0
fi
echo "router is not xiaomi, use general openwrt"
sbin_dir="/usr/sbin/leigod"
init_dir="/etc/init.d"
# stop openwrt service first
echo "stop openwrt acc service first, in casue install failed"
/etc/init.d/acc stop
sleep 1
show_openwrt_suggestion
return 0
}
# get_asus_name get asus name
get_merlin_party() {
if [[ -d "/koolshare" ]]; then
echo "router is merlin series, name: $(nvram get build_name)"
nvram set 3rd-party=merlin
is_merlin=true
sbin_dir="/koolshare/leigod/acc"
init_dir="/koolshare/init.d"
echo "message"
return 0
elif [[ -d "/jffs/softcenter" ]]; then
echo "router is swrt series, name: $(nvram get build_name)"
is_swrt=true
nvram set 3rd-party=swrt
sbin_dir="/jffs/softcenter/leigod/acc"
init_dir="/jffs/softcenter/init.d"
return 0
fi
# check merlin
echo "route is not merlin, use general asus"
return 0
}
# get_device_firmware get device firmware
# current support firmware: openwrt merlin
get_device_firmware() {
# openwrt file exist
if [ -f "/etc/openwrt_release" ]; then
echo "firmware is openwrt series"
is_openwrt=true
get_xiaomi_name
elif [[ -f "/etc/image_version" ]] || [[ -d "/koolshare" ]] || [[ -d "/jffs/softcenter" ]]; then
echo "firmware is asus series"
is_asus=true
echo "stop asus acc service first, in casue install failed"
PIDS=$(ps | grep acc | grep -v grep | awk '{print $1}')
# check if process exist
get_merlin_party
fi
}
# install_openwrt_package install openwrt
install_binary() {
# create sbin dir
mkdir -p ${sbin_dir}
# create name
local acc_name=${binary_prefix}.${arch}
local download_bin_url=${download_base_url}/${acc_name}
echo "install ${acc_name} to ${sbin_dir}"
# download file
curl -s -o ${sbin_dir}/${acc_name} ${download_bin_url}
if [ $? != "0" ]; then
echo "download and install binary failed"
return -1
fi
echo "install binary success"
chmod +x ${sbin_dir}/${acc_name}
if [ $? != "0" ]; then
echo "add binary permission failed"
return -1
fi
echo "add acc binary permission success"
# download common file
local download_common_url=${download_base_url}/${common_file_name}
curl -s -o ${sbin_dir}/${common_file_name} ${download_common_url}
if [ $? != "0" ]; then
echo "download and install common file failed"
return -1
fi
# remote uninstall_file_name
local remote_uninstall_file_name=${download_base_url}/"plugin_uninstall.sh"
curl -s -o ${sbin_dir}/${uninstall_file_name} ${remote_uninstall_file_name}
if [ $? != "0" ]; then
echo "download and install uninstall file failed"
return -1
fi
echo "add uninstall permission success"
local ver_file=${sbin_dir}/${ver_name}
touch ${ver_file}
if [ $? != "0" ]; then
echo "create version file failed"
return -1
fi
# add version to file
echo "version=1.3.0.30" > ${ver_file}
echo "add version file success"
}
# remove_binary remove binary
remove_binary() {
rm -r ${sbin_dir}
}
# install xiaomi monitor
install_xiaomi_monitor() {
local cron_path="/etc/crontabs/root"
local monitor_file_name="plugin_monitor.sh"
local download_monitor_url=${download_base_url}/${monitor_file_name}
curl -o ${sbin_dir}/${monitor_file_name} ${download_monitor_url}
if [ $? != "0" ]; then
echo "download monitor file failed"
return -1
fi
chmod +x ${sbin_dir}/${monitor_file_name}
# download
echo "download monitor file success"
echo "*/1 * * * * ${sbin_dir}/${monitor_file_name}" >> ${cron_path}
if [ $? != "0" ]; then
echo "add monitor to cron failed"
return -1
fi
echo "add monitor to cron success"
}
# install_openwrt_series_config save openwrt config
install_openwrt_series_config() {
# create accelerator config
touch /etc/config/accelerator
if [ $? != "0" ]; then
echo "make acc config file failed"
return -1
fi
if [ ${install_env} == "test" ]; then
# use uci to add config
uci set accelerator.base=system
uci set accelerator.bind=bind
uci set accelerator.device=hardware
uci set accelerator.Phone=acceleration
uci set accelerator.PC=acceleration
uci set accelerator.Game=acceleration
uci set accelerator.Unknown=acceleration
uci set accelerator.base.url='https://test-opapi.nn.com/speed/router/plug/check'
uci set accelerator.base.heart='https://test-opapi.nn.com/speed/router/heartbeat'
uci set accelerator.base.base_url='https://test-opapi.nn.com/speed'
uci commit accelerator
elif [ ${install_env} == "test1" ]; then
# use uci to add config
uci set accelerator.base=system
uci set accelerator.bind=bind
uci set accelerator.device=hardware
uci set accelerator.Phone=acceleration
uci set accelerator.PC=acceleration
uci set accelerator.Game=acceleration
uci set accelerator.Unknown=acceleration
uci set accelerator.base.url='https://test1-opapi.nn.com/speed/router/plug/check'
uci set accelerator.base.heart='https://test1-opapi.nn.com/speed/router/heartbeat'
uci set accelerator.base.base_url='https://test1-opapi.nn.com/speed'
uci commit accelerator
else
# use uci to add config
uci set accelerator.base=system
uci set accelerator.bind=bind
uci set accelerator.device=hardware
uci set accelerator.Phone=acceleration
uci set accelerator.PC=acceleration
uci set accelerator.Game=acceleration
uci set accelerator.Unknown=acceleration
uci set accelerator.base.url='https://opapi.nn.com/speed/router/plug/check'
uci set accelerator.base.heart='https://opapi.nn.com/speed/router/heartbeat'
uci set accelerator.base.base_url='https://opapi.nn.com/speed'
uci commit accelerator
fi
if [ $? != "0" ]; then
echo "create openwrt config unit failed"
return -1
fi
echo "create openwrt config unit success"
}
# install_openwrt_series_luasrc install openwrt lua src
install_openwrt_series_luasrc() {
lua_base="/usr/lib/lua/luci"
# download index file
curl --create-dirs -o ${lua_base}/controller/acc.lua ${download_base_url}/openwrt/controller/acc.lua
if [ $? != "0" ]; then
echo "download acc.lua failed"
return -1
fi
# download service view file
curl --create-dirs -o ${lua_base}/model/cbi/leigod/service.lua ${download_base_url}/openwrt/model/cbi/leigod/service.lua
if [ $? != "0" ]; then
echo "download service.lua failed"
return -1
fi
# download device view file
curl --create-dirs -o ${lua_base}/model/cbi/leigod/device.lua ${download_base_url}/openwrt/model/cbi/leigod/device.lua
if [ $? != "0" ]; then
echo "download device.lua failed"
return -1
fi
# download notice view file
curl --create-dirs -o ${lua_base}/model/cbi/leigod/notice.lua ${download_base_url}/openwrt/model/cbi/leigod/notice.lua
if [ $? != "0" ]; then
echo "download notice.lua failed"
return -1
fi
# download service view file
curl --create-dirs -o ${lua_base}/view/leigod/notice.htm ${download_base_url}/openwrt/view/leigod/notice.htm
if [ $? != "0" ]; then
echo "download notice.htm failed"
return -1
fi
# download service view file
curl --create-dirs -o ${lua_base}/view/leigod/service.htm ${download_base_url}/openwrt/view/leigod/service.htm
if [ $? != "0" ]; then
echo "download service.htm failed"
return -1
fi
# download service translate file
curl --create-dirs -o ${lua_base}/i18n/acc.zh-cn.lmo ${download_base_url}/openwrt/po/zh-cn/acc.zh-cn.lmo
if [ $? != "0" ]; then
echo "download acc.zh-cn.lmo failed"
return -1
fi
echo "download lua src success"
}
install_openwrt_series_web() {
local luci_base="/usr/lib/lua/luci"
}
# remove_openwrt_series_config remove openwrt config
remove_openwrt_series_config() {
rm /etc/config/accelerator
}
# install asus series config
install_asus_series_config() {
mkdir -p ${sbin_dir}/config
if [ ${install_env} == "test" ]; then
# install test asus config
echo "
[base]
url="https://test-opapi.nn.com/speed/router/plug/check"
channel="2"
appid="nnMobile_d0k3duup"
heart="https://test-opapi.nn.com/speed/router/heartbeat"
base_url="https://test-opapi.nn.com/speed"
[update]
domain="https://test-opapi.nn.com/nn-version/version/plug/upgrade"
[device]
" > ${sbin_dir}/config/accelerator
elif [ ${install_env} == "test1" ]; then
# install test1 asus config
echo "
[base]
url="https://test1-opapi.nn.com/speed/router/plug/check"
channel="2"
appid="nnMobile_d0k3duup"
heart="https://test1-opapi.nn.com/speed/router/heartbeat"
base_url="https://test1-opapi.nn.com/speed"
[update]
domain="https://test1-opapi.nn.com/nn-version/version/plug/upgrade"
[device]
" > ${sbin_dir}/config/accelerator
else
# install formel asus config
echo "
[base]
url="https://opapi.nn.com/speed/router/plug/check"
channel="2"
appid="nnMobile_d0k3duup"
heart="https://opapi.nn.com/speed/router/heartbeat"
base_url="https://opapi.nn.com/speed"
[update]
domain="https://opapi.nn.com/nn-version/version/plug/upgrade"
[device]
" > ${sbin_dir}/config/accelerator
fi
echo "create asus series config success"
}
# remove_asus_series_config remove asus config
remove_asus_series_config() {
rm -r ${init_dir}
}
# install_openwrt_init install openwrt to init
install_openwrt_series_init() {
local remote_init_name="openwrt_init.sh"
local download_init_url=${download_base_url}/${remote_init_name}
# download init file
curl -o ${init_dir}/${init_file_name} ${download_init_url}
if [ $? != "0" ]; then
echo "download init file failed"
return -1
fi
echo "download init file success"
# add permission to file
chmod +x ${init_dir}/${init_file_name}
if [ $? != "0" ]; then
echo "add init permission failed"
return -1
fi
echo "add init file permission success"
${init_dir}/${init_file_name} enable
echo "set accelerator autostart success"
${init_dir}/${init_file_name} start
if [ $? != "0" ]; then
echo "start accelerator failed"
return -1
fi
echo "start accelerator success"
}
# remove_openwrt_series_init remove openwrt init
remove_openwrt_series_init() {
${init_dir}/${init_file_name} disable
${init_dir}/${init_file_name} stop
rm ${init_dir}/${init_file_name}
}
# install merlin init
install_merlin_init() {
local remote_init_name="asus_init.sh"
local download_init_url=${download_base_url}/${remote_init_name}
# download init file
curl -o ${sbin_dir}/${init_file_name} ${download_init_url}
if [ $? != "0" ]; then
echo "download init file failed"
return -1
fi
# add permission
chmod +x ${sbin_dir}/${init_file_name}
# create link
local link_init_name="S99LeigodAcc.sh"
local link_init_file=${init_dir}/${link_init_name}
ln -sf ${sbin_dir}/${init_file_name} ${link_init_file}
if [ $? != "0" ]; then
echo "create merlin init link failed"
return -1
fi
echo "create merlin link file success"
${link_init_file} start
echo "acc start success"
}
# show_openwrt_suggestion show openwrt install suggest
show_openwrt_suggestion() {
echo "
雷神OpenWrt插件安装建议:
当前雷神路由器支持两种加速模式,
1. tproxy加速模式(速度更快, CPU占用率更低)
2. tun加速模式(需要依赖少, 安装灵活)
需要您根据以上的加速模式, 安装对应的依赖库,
如下列出两种模式对应的安装依赖:
1. TProxy模式: libpcap iptables kmod-ipt-nat iptables-mod-tproxy kmod-ipt-tproxy kmod-netem(可选) tc-full(可选) kmod-ipt-ipset ipset curl
2. Tun模式: libpcap iptables kmod-tun kmod-ipt-nat kmod-ipt-ipset ipset curl
如何安装依赖:
1. 升级依赖: opkg update
2. 安装依赖: opkg install xxx
为了安装方便, 请选择一个模式, 复制以下命令到终端运行:
Tproxy模式:
opkg update
opkg install libpcap iptables kmod-ipt-nat iptables-mod-tproxy kmod-ipt-tproxy kmod-netem tc-full kmod-ipt-ipset ipset
Tun模式:
opkg update
opkg install libpcap iptables kmod-tun kmod-ipt-nat kmod-ipt-ipset ipset curl
关于steamdeck的支持说明
steamdeck设备请选择加速电脑游戏
关于手机设备的支持:
1. 安卓支持说明
当前代理仅支持ipv4代理, 请更改dhcp配置更改完配置请重启路由器
配置路径在 /etc/config/dhcp
config dhcp 'lan'
... 此处是一些其他配置
ra 'disable'
dhcpv6 'disable'
list ra_flags 'none'
... 此处是一些其他配置
2. 关于ios设备的支持说明
ios设备, 安装完插件后, 为了精准识别, 请在ios上选择忘记wifi, 然后重新连接即可
"
}
# preinstall_check check env
preinstall_check() {
# check os
get_device_os
if [ ${os} != "Linux" ]; then
echo "current os not support, os: ${os}"
return -1
fi
# check arch
get_device_arch
if [[ ${arch} != "x86_64" && ${arch} != "aarch64" && ${arch} != "arm" && ${arch} != "mips" && ${arch} != "armv7l" ]];then
echo "current arch not support, arch: ${arch}"
return -1
fi
# fix arch
if [ ${arch} == "x86_64" ]; then
echo "match x86_64 -> amd64"
arch="amd64"
elif [ ${arch} == "aarch64" ]; then
echo "match aarch64 -> arm64"
arch="arm64"
elif [ ${arch} == "mips" ]; then
echo "match mips -> mipsle"
arch="mipsle"
elif [ ${arch} == "armv7l" ]; then
arch="arm"
fi
# support plugin
echo "current system support plugin, system: ${os}-${arch}"
get_device_firmware
return 0
}
# show_install_success show install has been installed
show_install_success() {
echo "install success"
echo "雷神路由器插件安装已完成"
echo "请加群632342113体验"
}

View File

@ -0,0 +1,175 @@
#!/usr/bin/lua
local util = require "luci.util"
local string = require "string"
local io = require "io"
local json = require "luci.jsonc"
local uci = require "luci.model.uci".cursor()
local client = require "luci.httpclient"
local helper = require "luci.helper"
-- get cloud version
function get_cloud_version()
-- get cloud url
local url = uci:get("easyupdate", "main", "domain")
-- get request channel
local channel = uci:get("easyupdate", "main", "channel")
-- appid
local appid = uci:get("easyupdate", "main", "appid")
-- read brand and model from file
local brand, model = helper.get_board_info()
-- platfrom
local platform = 11
-- create http request options
local options = {}
-- create http request method
options.method = "POST"
-- create http request headers
options.headers = {}
options.headers['appId'] = appid
options.headers['reqChannel'] = channel
options.headers['Content-Type'] = 'application/json'
-- create http request body
local body = {
--
['appId'] = 'spRouterPlugin_fhem2shgq9s5',
['brand'] = brand,
['model'] = model,
['platform'] = platform,
}
-- marshal to json
local buf = util.serialize_json(body)
options.body = buf
-- begin to query
local status, _, buffer, _ = client.request_raw(url, options)
-- check if query success
if not status then
io.write("status is nil \n")
return ""
end
-- check if request success
if status ~= 200 and status ~=206 then
io.write("status is not success, status: " .. status .. "\n")
return ""
end
-- begin to parse response
local info = json.parse(buffer)
-- get ret data
local data = info['retData']
-- check if data is nil
if data == nil then
io.write("response ret data is nil \n")
return ""
end
-- store url in config
local fw_url = data['url']
local version = data['versionName']
io.write("fw_url: " .. fw_url .. ", version: " .. version .. "\n")
-- get version success
return version, fw_url
end
-- get local version
function get_local_version()
-- run command to get acc version
local cmd = 'opkg info acc'
local buf = util.exec(cmd)
-- check exec result
if buf == nil then
io.write("exec command failed \n")
return ""
end
io.write("buf: " .. buf .. "\n")
-- read line
for line in string.gmatch(buf, "[^\r\n]+") do
io.write("read line: " .. line .. "\n")
line = string.gsub(line, " ", "")
local valueSl = string.gmatch(line, "[^:]+")
local key = valueSl()
local value = valueSl()
if key == "Version" then
io.write("get local version: " .. value .. "\n")
return value
end
end
io.write("local version cant found \n")
end
-- get file base name
function get_file_base_name(filepath)
local name = string.gmatch(filepath, "([^/]+)$")
io.write("get file base name: " .. name .. "\n")
return name
end
-- download cloud version
function download_cloud_app(url, name)
io.write("download app, url: " .. url .. ", name: " .. name .. "\n")
-- run download
local cmd = 'curl -s -o /tmp/' .. name ..' -w %{http_code}' .. ' ' .. url
-- exec download
local code = util.exec(cmd)
if code ~= "200" then
io.write("download cloud app failed, code: " .. code .. "\n")
return false
end
io.write("download cloud app success \n")
return code
end
-- install package name in tmp dir
function install_package(name)
io.write("install package, package name: " .. name .. "\n")
local cmd = "opkg install " .. "/tmp/" .. name .. " " .. "--force-overwrite"
local code = util.exec(cmd)
io.write("install package finish, package name: " .. name .. "\n")
return code
end
-- remove pkg
function remove_pkg(name)
io.write("remove package, package name: " .. name .. "\n")
local cmd = "rm -rf " .. "/tmp/" .. name
local code = util.exec(cmd)
io.write("remove package finish, package name: " .. name .. "\n")
return code
end
-- check network state
io.write("check network state \n")
while true do
local state_code = helper.get_network_state()
if state_code == 200 then
io.write("network available \n")
break
end
if state_code ~= nil then
io.write("network is not available, code: " .. state_code .. "\n")
end
end
io.write("network success")
-- exec command
local local_version = get_local_version()
local cloud_version, url = get_cloud_version()
-- check if need update
if local_version >= cloud_version then
io.write("local version is new, dont need update, local ver: " .. local_version ..
", cloud version:" .. cloud_version .. "\n")
return
end
-- need update
io.write("local version is lower, need update, local version: " .. local_version ..
", cloud version: " .. cloud_version .. "\n")
-- download url
local name = "acc.ipk"
local result = download_cloud_app(url, name)
if not result then
return
end
-- install package
install_package(name)
remove_pkg(name)

View File

@ -0,0 +1 @@
version=1.3.0.30

View File

@ -0,0 +1,18 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
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 +leigod-acc
PKG_VERSION:=1
PKG_RELEASE:=2
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,74 @@
module("luci.controller.acc", package.seeall)
function index()
require("luci.i18n")
entry({ "admin", "services", "acc" }, alias("admin", "services", "acc", "service"), translate("Leigod Acc"), 50)
entry({ "admin", "services", "acc", "service" }, cbi("leigod/service"), translate("Leigod Service"), 30).i18n = "acc"
entry({ "admin", "services", "acc", "device" }, cbi("leigod/device"), translate("Leigod Device"), 50).i18n = "acc"
entry({ "admin", "services", "acc", "notice" }, cbi("leigod/notice"), translate("Leigod Notice"), 80).i18n = "acc"
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"))
end
-- get_acc_status get acc status
function get_acc_status()
-- util module
local util = require "luci.util"
local uci = require "luci.model.uci".cursor()
local translate = luci.i18n.translate
-- init result
local resp = {}
-- init state
resp.service = translate("Acc Service Disabled")
resp.state = {}
-- check if exist
local exist = util.exec("ps | grep acc-gw | grep -v grep")
-- check if program is running
if exist ~= "" then
resp.service = translate("Acc Service Enabled")
end
-- get uci
local results = uci:get_all("accelerator")
for _, typ in pairs({ "Phone", "PC", "Game", "Unknown" }) do
local state = uci:get("accelerator", typ, "state")
-- check state
local state_text = "None"
if state == nil or state == '0' then
elseif state == '1' then
state_text = translate("Acc Catalog Started")
elseif state == '2' then
state_text = translate("Acc Catalog Stopped")
elseif state == '3' then
state_text = translate("Acc Catalog Paused")
end
-- store text
resp.state[translate(typ .. "_Catalog")] = state_text
end
luci.http.prepare_content("application/json")
luci.http.write_json(resp)
end
-- start_acc_service
function start_acc_service()
-- util module
local util = require "luci.util"
util.exec("/etc/init.d/acc enable")
util.exec("/etc/init.d/acc restart")
local resp = {}
resp.result = "OK"
luci.http.prepare_content("application/json")
luci.http.write_json(resp)
end
-- start_acc_service
function stop_acc_service()
-- util module
local util = require "luci.util"
util.exec("/etc/init.d/acc stop")
util.exec("/etc/init.d/acc disable")
local resp = {}
resp.result = "OK"
luci.http.prepare_content("application/json")
luci.http.write_json(resp)
end

View File

@ -0,0 +1,157 @@
local uci = require "luci.model.uci".cursor()
local util = require "luci.util"
local fs = require "nixio.fs"
local pairs = pairs
local io = io
-- config
m = Map("accelerator")
m.title = translate("Leigod Device Config")
m.description = translate("Control Device Config")
-- get neigh info
neigh = m:section(NamedSection, "base", "system", translate("Neigh Device"))
neigh_tab = neigh:option(ListValue, "neigh", translate("acc interface"))
local sys_dir = util.exec("ls /sys/class/net")
if sys_dir ~= nil then
neigh_tab:value("br-lan")
for ifc in string.gmatch(sys_dir, "[^\n]+") do
neigh_tab:value(ifc)
end
end
-- range all device
device = m:section(NamedSection, "device", "hardware", translate("Device Info"))
device:tab("none_catalog", translate("None_Catalog"))
device:tab("phone_catalog", translate("Phone_Catalog"))
device:tab("pc_catalog", translate("PC_Catalog"))
device:tab("game_catalog", translate("Game_Catalog"))
device:tab("vr_catalog", translate("VR_Catalog"))
device:tab("unknown_catalog", translate("Unknown_Catalog"))
local dhcp_map = {}
-- check dhcp file
if fs.access("/tmp/dhcp.leases") then
for line in io.lines("/tmp/dhcp.leases") do
-- check if read empty line
if line == "" then
break
end
-- split line
local valueSl = string.gmatch(line, "[^ ]+")
-- read time
valueSl()
-- read mac
local mac = valueSl()
-- get ip
local ip = valueSl()
-- get host name
local hostname = valueSl()
-- key
local key = string.gsub(mac, ":", "")
-- store key
dhcp_map[key] = {
["key"] = key,
["mac"] = mac,
["ip"] = ip,
["name"] = hostname
}
end
end
ifc = uci:get("accelerator", "base", "neigh")
if ifc == nil then
ifc = "br-lan"
end
local arp_map = {}
-- check if arp exist
if fs.access("/proc/net/arp") then
-- read all item from arp
for line in io.lines("/proc/net/arp") do
-- check if line is not exist
if line == "" then
break
end
-- split item
local valueSl = string.gmatch(line, "[^ ]+")
-- get ip
local ip = valueSl()
-- get type
valueSl()
-- get flag
local flag = valueSl()
-- get mac
local mac = valueSl()
-- get mask
valueSl()
-- get device
local dev = valueSl()
-- get key
local key = string.gsub(mac, ":", "")
-- check if device and flag state
if dev == ifc and flag == "0x2" then
-- get current name
local name = mac
if dhcp_map[key] ~= nil and dhcp_map[key] ~= "*" then
name = dhcp_map[key].name
end
arp_map[key] = {
["key"] = key,
["mac"] = mac,
["ip"] = ip,
["name"] = name
}
end
end
end
-- get device config
for key, item in pairs(arp_map) do
local typ = uci:get("accelerator", "device", key)
-- get device catalog from type
local catalog = "none_catalog"
-- default to unknown device
if typ == nil then
typ = 9
else
typ = tonumber(typ)
end
if typ == nil then
catalog = "unknown_catalog"
elseif typ >= 1 and typ <= 3 then
catalog = "game_catalog"
elseif typ >= 4 and typ <= 6 then
catalog = "pc_catalog"
elseif typ >= 7 and typ <= 8 then
catalog = "phone_catalog"
elseif typ >= 20 and typ <= 21 then
catalog = "vr_catalog"
else
catalog = "unknown_catalog"
end
-- device type
device_typ = device:taboption(catalog, ListValue, key, item.name)
device_typ:value("0", "None")
device_typ:value("1", "XBox")
device_typ:value("2", "Switch")
device_typ:value("3", "Play Station")
device_typ:value("4", "Steam Deck")
device_typ:value("5", "Windows")
device_typ:value("6", "MacBook")
device_typ:value("7", "Android")
device_typ:value("8", "iPhone")
device_typ:value("20", "Oculus")
device_typ:value("21", "HTC Vive")
device_typ:value("22", "Pico")
device_typ:value("9", "Unknown")
end
-- set
device.write = function()
util.exec("/etc/init.d/acc restart")
end
return m

View File

@ -0,0 +1,10 @@
local uci = require "luci.model.uci".cursor()
-- config
m = Map("accelerator")
m.title = translate("Leigod Notice")
m.description = translate("Leigod Accelerator Usage")
m:section(SimpleSection).template = "leigod/notice"
return m

View File

@ -0,0 +1,10 @@
local uci = require "luci.model.uci".cursor()
-- config
m = Map("accelerator")
m.title = translate("Leigod Accelerator Config")
m.description = translate("Control Accelerator Config")
m:section(SimpleSection).template = "leigod/service"
return m

View File

@ -0,0 +1,74 @@
<fieldset>
<legend><%:Declare%></legend>
此插件为 LEDE/QWRT 官方合作版插件, 需要配合雷神手机APP使用
</p>
<legend><%:Upgrade Info%></legend>
<p>
2024-8-1 <br>
支持LEDE/QWRT性能优化 <br>
2024-7-25 <br>
支持非桥接模式下的旁路由 <br>
2024-6-5 <br>
扩充ipset容量, 以支持大容量代理ip库 <br>
2024-1-22 <br>
新增自动选择低延迟线路 <br>
新增下载不限速(switch除外) <br>
设备名为*时, 显示mac地址 <br>
<hr/>
2023-11-28 <br>
新增对mips设备的支持 <br>
新增对旁路由的支持 <br>
解决翻译异常的问题 <br>
设备管理页面可以显示未识别设备 <br>
</p>
<legend><%:Install Dependence%></legend>
<p>
插件运行需要借助一些依赖才能运行, 一般第三方固件默认已经集成了大部分的依赖, <br>
如果使用的是openwrt官方的固件, 则需要确保依赖安装好了, 以下列出依赖包和注意事项 <br>
libpcap <br>
iptables <br>
kmod-ipt-nat <br>
iptables-mod-tproxy <br>
kmod-ipt-tproxy <br>
kmod-netem(非必须, 针对于一些icmp测速的游戏使用, 只影响界面显示, 实际游戏效果不影响) <br>
tc-full(非必须, 同kmod-netem) <br>
kmod-ipt-ipset <br>
ipset <br>
curl(谨慎更新, 某些三方固件升级curl, 会导致curl出现问题) <br>
</p>
<legend><%:Bridge Mode%></legend>
<p>
加速插件无法探知当前插件应该使用什么模式, <br>
当前默认使用网桥作为流量转发的设备, <br>
如果使用旁路由模式或者docker时, 此时默认设备不是网桥, <br>
此时需要手动调整接口, <br>
改变接口的地址在 设备管理->路由设备, 选择对应的设备 <br>
</p>
<legend><%:Acc Mode%></legend>
<p>
当前雷神路由器支持两种加速模式, tproxy 和 tun <br>
当前默认采用的是tproxy模式, 原因在于tproxy有更好的性能<br>
tun模式暂时屏蔽, 后续luci会完善一键切换模式
</p>
<legend><%:Acc Usage%></legend>
<p>
当前雷神加速插件是根据设备类型进行加速的, 也就是说, 如果加速了相应的类型后, 理论上只要连接该路由器的设备都将获得加速效果<br>
当前支持的设备类型有以下几种: <br>
手机: Android iPhone <br>
电脑: Windows MacOS SteamDeck <br>
主机: XBox Switch PlayStation <br>
未识别: Others <br>
可以在设备管理中, 插件自己的设备是否被成功识别成对应的设备, 如果不是, 可以选择对应的设备, 这样设备就能成功加速了 <br>
</p>
<p>
一些特殊的说明: <br>
关于ios设备, 最好是在安装插件之前, 先忘记网络, 等安装完插件后, 再重新连接网络 <br>
关于android设备, 需要关闭dhcpv6后, 手机重连网络, 以下给出一个 /etc/config/dhcp 的配置 <br>
config dhcp 'lan' <br>
... 此处是一些其他配置 <br>
ra 'disable' <br>
dhcpv6 'disable' <br>
list ra_flags 'none' <br>
... 此处是一些其他配置 <br>
</p>
</fieldset>

View File

@ -0,0 +1,61 @@
<!-- acc service state -->
<fieldset class="cbi-section">
<table class="cbi-section-table" id="acc_service_state_table">
<tr class="cbi-section-table-title">
<th class="cbi-section-table-cell"><%:Acc_Service_Name%></th>
<th class="cbi-section-table-cell"><%:Acc_Service_Status%></th>
<th class="cbi-section-table-cell"><%:Acc_Service_Operate%></th>
</tr>
<tr>
<td><%:Acc_Service%></td>
<td id="acc_service_state_cell"><%:Acc_Service_Status%></td>
<td id="acc_service_state_button"><%:Acc_Service_Operate%></td>
</tr>
</table>
</fieldset>
<!-- acc catalog state -->
<fieldset class="cbi-section">
<legend><%:Acc Catalog State%></legend>
<table class="cbi-section-table" id="acc_catalog_state_table">
<tr class="cbi-section-table-title">
<th class="cbi-section-table-cell"><%:Acc_Catalog%></th>
<th class="cbi-section-table-cell"><%:Acc_Catalog_Status%></th>
</tr>
</table>
</fieldset>
<script type="text/javascript">//<![CDATA[
// start acc service
function start_acc_service() {
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "acc", "start_acc_service")%>', null, function(x) {});
}
// start acc service
function stop_acc_service() {
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "acc", "stop_acc_service")%>', null, function(x) {});
}
XHR.poll(5, '<%=url('admin/services/acc/status')%>', null, function(x, st) {
var service_cell = document.getElementById("acc_service_state_cell");
var button_cell = document.getElementById("acc_service_state_button");
if (st && service_cell && button_cell) {
service_cell.innerHTML = st["service"];
if (st["service"] == "Acc Service Enabled" || st["service"] == "已启动" || st["service"] == "加速服务已启动")
button_cell.innerHTML = '<input type="button" class="btn cbi-button cbi-button-apply" value="<%:Stop Acc Service%>" onclick="return stop_acc_service()"/>';
else
button_cell.innerHTML = '<input type="button" class="btn cbi-button cbi-button-apply" value="<%:Start Acc Service%>" onclick="return start_acc_service()"/>';
}
var catalog_table = document.getElementById("acc_catalog_state_table");
if (st && catalog_table) {
while(catalog_table.rows.length > 1)
catalog_table.deleteRow(1);
var status_map = st["state"];
for (var typ in status_map) {
var tr = catalog_table.insertRow(-1);
tr.insertCell(-1).innerHTML = typ;
tr.insertCell(-1).innerHTML = status_map[typ];
}
}
});
//]]></script>

View File

@ -0,0 +1,120 @@
msgid "Leigod Acc"
msgstr "雷神加速器"
msgid "Leigod Service"
msgstr "服务控制"
msgid "Leigod Device"
msgstr "设备管理"
msgid "Leigod Notice"
msgstr "加速公告"
msgid "Leigod Accelerator Config"
msgstr "加速器配置"
msgid "Control Accelerator Config"
msgstr "控制加速配置选项"
msgid "Acc_Service_Name"
msgstr "服务名称"
msgid "Acc_Service_Status"
msgstr "启动状态"
msgid "Acc_Service_Operate"
msgstr "加速设置"
msgid "Acc Catalog State"
msgstr "加速状态"
msgid "Acc_Catalog"
msgstr "加速设备"
msgid "Acc_Catalog_Status"
msgstr "加速状态"
msgid "Declare"
msgstr "说明"
msgid "Upgrade Info"
msgstr "更新内容"
msgid "Install Dependence"
msgstr "安装依赖"
msgid "Bridge Mode"
msgstr "旁路由模式"
msgid "Acc Mode"
msgstr "加速模式"
msgid "Acc Usage"
msgstr "使用说明"
msgid "Leigod Accelerator Usage"
msgstr "雷神加速插件使用"
msgid "Leigod Device Config"
msgstr "设备管理配置"
msgid "Control Device Config"
msgstr "控制和改变设备类型"
msgid "Neigh Device"
msgstr "路由设置"
msgid "acc interface"
msgstr "代理接口"
msgid "Device Info"
msgstr "设备信息"
msgid "None_Catalog"
msgstr "未分类设备"
msgid "Phone_Catalog"
msgstr "手机设备"
msgid "None_Catalog"
msgstr "未分类设备"
msgid "PC_Catalog"
msgstr "PC设备"
msgid "Game_Catalog"
msgstr "游戏机"
msgid "VR_Catalog"
msgstr "VR设备"
msgid "Unknown_Catalog"
msgstr "未识别设备"
msgid "acc_service"
msgstr "雷神加速器服务"
msgid "Acc_Service"
msgstr "雷神加速器服务"
msgid "Stop Acc Service"
msgstr "停止加速服务"
msgid "Start Acc Service"
msgstr "启动加速服务"
msgid "Acc Service Disabled"
msgstr "加速服务已被禁用"
msgid "Acc Service Enabled"
msgstr "已启动"
msgid "Acc Catalog Started"
msgstr "已禁用"
msgid "Acc Catalog Stopped"
msgstr "该设备类别加速已停止"
msgid "Acc Catalog Paused"
msgstr "该设备类别加速已暂停"

View File

@ -0,0 +1,18 @@
config system 'base'
option url 'https://opapi.nn.com/speed/router/plug/check'
option heart 'https://opapi.nn.com/speed/router/heartbeat'
option base_url 'https://opapi.nn.com/speed'
config bind 'bind'
config hardware 'device'
config acceleration 'Phone'
config acceleration 'PC'
config acceleration 'Game'
config acceleration 'Unknown'

View File

@ -0,0 +1,162 @@
#!/bin/sh /etc/rc.common
# start prio
START=50
# use proc to start service
USE_PROCD=1
# package name
PACKAGE_NAME="acc.ipk"
# binary dir
sbin_dir="/usr/sbin/leigod"
# binary name
binary_prefix="acc-gw.linux"
# download acceleration binary
download_acc_binary() {
echo "begin to download file... ..."
# create download
local url="http://119.3.40.126/${PACKAGE_NAME}"
echo "download path: ${url}"
local path="/tmp/${PACKAGE_NAME}"
local code=$(curl --connect-timeout 2 -L -s -k -o "${path}" -w "%{http_code}" "${url}")
for i in $(seq 1 2)
do
if [ "$?" != "0" -o "${code}" != "200" -o ! -f "${path}" ]; then
echo "download failed: ${code}"
rm -f ${path}
sleep 5
continue
fi
echo "download success"
break
done
echo "download file success... ..."
}
# mkdir acc dir
mk_acc_dir() {
echo "begin to mkdir... ..."
# should make sure dir exist
local cmd="mkdir -p ${BINARY_DIR}"
echo "exec mkdir dir: ${cmd}"
local code=`$cmd`
echo "mkdir success... ..."
}
# decompress file
decompress_file() {
echo "begin to decompress file... ..."
# compress file path
local path="/tmp/${PACKAGE_NAME}"
# decompress command
local cmd="tar -zxvf ${path} -C ${BINARY_DIR}"
local code=`${cmd}`
echo "decompress file success... ..."
}
# install ipk
install_package() {
echo "begin to overwrite package"
# local cmd = "opkg install /tmp/${PACKAGE_NAME} --force-overwrite"
# `$cmd`
echo "overwrite finish, begin to start"
}
# main
prepare_env() {
# mkdir
mk_acc_dir
# download file
download_acc_binary
# decompress file
install_package
}
main() {
prepare_env
}
# get_device_arch,
# current support arch: arm64 arm x86_64 mips
get_device_arch() {
arch=$(uname -m)
if [ $? != "0" ]; then
echo "arch cant be get"
return -1
fi
# fix arch
if [ ${arch} == "x86_64" ]; then
echo "match x86_64 -> amd64"
arch="amd64"
elif [ ${arch} == "aarch64" ]; then
echo "match aarch64 -> arm64"
arch="arm64"
elif [ ${arch} == "mips" ]; then
echo "match mips -> mipsle"
arch="mipsle"
elif [ ${arch} == "armv7l" ]; then
echo "match armv7l -> arm"
arch="arm"
fi
return 0
}
# get_xiaomi_name check if is xiaomi
get_xiaomi_name() {
local name=$(uci get misc.hardware.displayName)
if [[ $? == "0" && ${name} != "" ]]; then
echo "router is xiaomi series, name: ${name}"
sbin_dir="/userdisk/appdata/leigod"
init_dir="/userdisk/appdata/leigod"
args="--mode tun"
is_xiaomi=true
return 0
fi
local name=$(uci get misc.hardware.model)
if [[ $? == "0" && ${name} != "" ]]; then
echo "router is xiaomi series, name: ${name}"
sbin_dir="/userdisk/appdata/leigod"
init_dir="/userdisk/appdata/leigod"
args="--mode tun"
is_xiaomi=true
return 0
fi
echo "router is not xiaomi, use general openwrt"
sbin_dir="/usr/sbin/leigod"
init_dir="/etc/init.d"
show_openwrt_suggestion
return 0
}
# run service as daemon
start_service_daemon() {
# open once instance
procd_open_instance
# run binary
local cmd="${sbin_dir}/${binary_prefix}.${arch} ${args}"
echo "start service: ${cmd}"
procd_set_param command ${cmd}
# auto start when failed
procd_set_param respawn
# close instance
procd_close_instance
# start check update
# update_plugin &
# start led light
# /etc/init.d/internetled start
}
# proc start service
start_service() {
# prepare env
# prepare_env
# run service as daemon
get_device_arch
get_xiaomi_name
start_service_daemon
}

View File

@ -0,0 +1,24 @@
#!/bin/sh
# check if file exist
if [ ! -f /etc/config/accelerator ]; then
echo "file not exist, should create..."
touch /etc/config/accelerator
uci set accelerator.base=system
uci set accelerator.device=hardware
uci set accelerator.Phone=acceleration
uci set accelerator.PC=acceleration
uci set accelerator.Game=acceleration
uci set accelerator.Unknown=acceleration
uci commit accelerator
fi
uci set accelerator.base.url='https://opapi.nn.com/speed/router/plug/check'
uci set accelerator.base.heart='https://opapi.nn.com/speed/router/heartbeat'
uci set accelerator.base.base_url='https://opapi.nn.com/speed'
uci commit accelerator
echo "Fistboot Disable "
/etc/init.d/acc stop
/etc/init.d/acc disable