luci-app-eqos: add luci

This commit is contained in:
coolsnowwolf 2023-10-18 20:21:36 +08:00
parent b911c6b18d
commit f68ab8e4bf
10 changed files with 256 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#
# Copyright (C) 2006-2017 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for eqos.
LUCI_DESCRIPTION:=LuCI support for Easy QoS(Support speed limit based on IP address).
LUCI_DEPENDS:=+tc +kmod-sched-core +kmod-ifb
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-eqos
PKG_VERSION:=1.0.0
PKG_RELEASE:=2
PKG_MAINTAINER:=Jianhui Zhao <jianhuizhao329@gmail.com>
include ../../luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,11 @@
module("luci.controller.eqos", package.seeall)
function index()
if not nixio.fs.access("/etc/config/eqos") then
return
end
local page = entry({"admin", "network", "eqos"}, cbi("eqos"), "EQoS")
page.dependent = true
page.acl_depends = { "luci-app-eqos" }
end

View File

@ -0,0 +1,39 @@
local m = Map("eqos", translate("Network speed control service"))
local s = m:section(TypedSection, "eqos")
s.anonymous = true
local e = s:option(Flag, "enabled", translate("Enable"))
e.rmempty = false
local dl = s:option(Value, "download", translate("Download speed (Mbit/s)"))
dl.description = translate("Total bandwidth")
dl.datatype = "and(uinteger,min(1))"
local ul = s:option(Value, "upload", translate("Upload speed (Mbit/s)"))
ul.description = translate("Total bandwidth")
ul.datatype = "and(uinteger,min(1))"
s = m:section(TypedSection, "device", translate("Speed limit based on IP address"))
s.template = "cbi/tblsection"
s.anonymous = true
s.addremove = true
s.sortable = true
local ip = s:option(Value, "ip", translate("IP address"))
luci.ip.neighbors({family = 4, dev = "br-lan"}, function(n)
if n.mac and n.dest then
ip:value(n.dest:string(), "%s (%s)" %{ n.dest:string(), n.mac })
end
end)
dl = s:option(Value, "download", translate("Download speed (Mbit/s)"))
dl.datatype = "and(uinteger,min(1))"
ul = s:option(Value, "upload", translate("Upload speed (Mbit/s)"))
ul.datatype = "and(uinteger,min(1))"
comment = s:option(Value, "comment", translate("Comment"))
return m

View File

@ -0,0 +1,44 @@
msgid ""
msgstr ""
"Project-Id-Version: LuCi Chinese Translation\n"
"Report-Msgid-Bugs-To: \n"
"Language: zh_Hans\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Pootle 2.0.6\n"
msgid "EQoS"
msgstr "网速控制"
msgid "eqos"
msgstr "网速控制"
msgid "Comment"
msgstr "注解"
msgid "Download speed (Mbit/s)"
msgstr "下载速度 (Mbit/s)"
msgid "Enable"
msgstr "开启"
msgid "QoS"
msgstr "QoS"
msgid "Network speed control service"
msgstr "网速控制服务"
msgid "Upload speed (Mbit/s)"
msgstr "上传速度 (Mbit/s)"
msgid "Speed limit based on IP address"
msgstr "IP限速"
msgid "Total bandwidth"
msgstr "总带宽"
msgid "Flow control setting"
msgstr "流控设置"

View File

@ -0,0 +1,12 @@
# The bandwidth unit is Mbit/s
config eqos
option enabled 0
option download 100
option upload 20
# Limiting the bandwidth of a single Device
#config device
# option ip "192.168.1.100"
# option download 10
# option upload 5
# option comment "test"

View File

@ -0,0 +1,5 @@
#!/bin/sh
[ "$ACTION" = "ifup" ] || exit 0
[ "$INTERFACE" = "lan" ] || exit 0
/etc/init.d/eqos start

View File

@ -0,0 +1,39 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=50
parse_device() {
local cfg="$1" ip download upload
config_get ip "$cfg" ip
config_get download "$cfg" download
config_get upload "$cfg" upload
eqos add $ip $download $upload
}
eqos_start() {
local cfg="$1" enabled download upload
config_get_bool enabled "$cfg" enabled 0
[ $enabled -eq 0 ] && return 0
config_get download "$cfg" download
config_get upload "$cfg" upload
eqos start $download $upload
config_foreach parse_device device
}
start() {
eqos stop
config_load eqos
config_foreach eqos_start eqos
}
stop() {
eqos stop
}

View File

@ -0,0 +1,11 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@eqos[-1]
add ucitrack eqos
set ucitrack.@eqos[-1].init=eqos
commit ucitrack
EOF
rm -f /tmp/luci-indexcache
exit 0

View File

@ -0,0 +1,60 @@
#!/bin/sh
dev=br-lan
stop_qos() {
tc qdisc del dev $dev root 2>/dev/null
tc qdisc del dev $dev ingress 2>/dev/null
tc qdisc del dev ${dev}-ifb root 2>/dev/null
ip link del dev ${dev}-ifb 2>/dev/null
}
start_qos() {
local dl=$1
local up=$2
tc qdisc add dev $dev root handle 1: htb
tc class add dev $dev parent 1: classid 1:1 htb rate ${dl}mbit
ip link add dev ${dev}-ifb name ${dev}-ifb type ifb
ip link set dev ${dev}-ifb up
tc qdisc add dev ${dev}-ifb root handle 1: htb
tc class add dev ${dev}-ifb parent 1: classid 1:1 htb rate ${up}mbit
tc qdisc add dev $dev ingress
tc filter add dev $dev parent ffff: protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ${dev}-ifb
}
case "$1" in
"stop")
stop_qos
;;
"start")
stop_qos
start_qos $2 $3
;;
"add")
ip="$2"
dl="$3"
up="$4"
cnt=$(tc class show dev $dev | wc -l)
tc class add dev $dev parent 1:1 classid 1:1$cnt htb rate ${dl}mbit ceil ${dl}mbit
tc filter add dev $dev parent 1:0 protocol ip u32 match ip dst $ip flowid 1:1$cnt
tc class add dev ${dev}-ifb parent 1:1 classid 1:1$cnt htb rate ${up}mbit ceil ${up}mbit
tc filter add dev ${dev}-ifb parent 1:0 protocol ip u32 match ip src $ip flowid 1:1$cnt
;;
*)
echo "Usage: $0 <command> [options]"
echo "Commands:"
echo " start dl_rate up_rate #Total bandwidth (Mbit/s)"
echo " stop"
echo " add ip dl_rate up_rate #Limiting the bandwidth of a single IP (Mbit/s)"
echo "Example:"
echo " $0 start 30 20 # Total bandwidth: down 30Mbit/s up 20Mbit/s"
echo " $0 add 192.168.22.12 10 2 # down 10Mbit/s up 2Mbit/s"
;;
esac

View File

@ -0,0 +1,11 @@
{
"luci-app-eqos": {
"description": "Grant UCI access for luci-app-eqos",
"read": {
"uci": [ "eqos" ]
},
"write": {
"uci": [ "eqos" ]
}
}
}