Skip to content

Commit

Permalink
luci-app-eqos: rewrite into JS
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Dec 6, 2023
1 parent 1b2ba1f commit 4b70437
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 112 deletions.
16 changes: 1 addition & 15 deletions applications/luci-app-eqos/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
#
# 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_TITLE:=LuCI support for Easy QoS
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 <[email protected]>

include ../../luci.mk

# call BuildPackage - OpenWrt buildroot signature

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';
'require form';
'require network';
'require uci';
'require view';

return view.extend({
load: function() {
return Promise.all([
uci.load('eqos'),
network.getHostHints()
]);
},

render: function(data) {
var m, s, o;

m = new form.Map('eqos', _('EQoS'),
_('Network speed control service.'));

s = m.section(form.NamedSection, 'config', 'eqos');

o = s.option(form.Flag, 'enabled', _('Enable'));
o.default = o.disabled;
o.rmempty = false;

o = s.option(form.Value, 'download', _('Download speed (Mbit/s)'),
_('Total download bandwidth.'));
o.datatype = 'and(uinteger,min(1))';
o.rmempty = false;

o = s.option(form.Value, 'upload', _('Upload speed (Mbit/s)'),
_('Total upload bandwidth.'));
o.datatype = 'and(uinteger,min(1))';
o.rmempty = false;

s = m.section(form.TableSection, 'device', _('Speed limit based on IP address'));
s.addremove = true;
s.anonymous = true;
s.sortable = true;

o = s.option(form.Flag, 'enabled', _('Enable'));
o.default = o.enabled;

o = s.option(form.Value, 'ip', _('IP address'));
o.datatype = 'ip4addr';
for (var i of Object.entries(data[1]?.hosts))
for (var v in i[1].ipaddrs)
if (i[1].ipaddrs[v]) {
var ip_addr = i[1].ipaddrs[v], ip_host = i[1].name;
o.value(ip_addr, ip_host ? String.format('%s (%s)', ip_host, ip_addr) : ip_addr)
}
o.rmempty = false;

o = s.option(form.Value, 'download', _('Download speed (Mbit/s)'));
o.datatype = 'and(uinteger,min(1))';
o.rmempty = false;

o = s.option(form.Value, 'upload', _('Upload speed (Mbit/s)'));
o.datatype = 'and(uinteger,min(1))';
o.rmempty = false;

o = s.option(form.Value, 'comment', _('Comment'));

return m.render();
}
});
11 changes: 0 additions & 11 deletions applications/luci-app-eqos/luasrc/controller/eqos.lua

This file was deleted.

39 changes: 0 additions & 39 deletions applications/luci-app-eqos/luasrc/model/cbi/eqos.lua

This file was deleted.

50 changes: 50 additions & 0 deletions applications/luci-app-eqos/po/templates/eqos.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:64
msgid "Comment"
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:28
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:56
msgid "Download speed (Mbit/s)"
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:18
#: applications/luci-app-eqos/root/usr/share/luci/menu.d/luci-app-eqos.json:3
msgid "EQoS"
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:24
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:43
msgid "Enable"
msgstr ""

#: applications/luci-app-eqos/root/usr/share/rpcd/acl.d/luci-app-eqos.json:3
msgid "Grant UCI access for luci-app-eqos"
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:46
msgid "IP address"
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:19
msgid "Network speed control service."
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:38
msgid "Speed limit based on IP address"
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:29
msgid "Total download bandwidth."
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:34
msgid "Total upload bandwidth."
msgstr ""

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:33
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:60
msgid "Upload speed (Mbit/s)"
msgstr ""
54 changes: 34 additions & 20 deletions applications/luci-app-eqos/po/zh_Hans/eqos.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,50 @@ msgstr ""
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Pootle 2.0.6\n"


msgid "EQoS"
msgstr "网速控制"

msgid "eqos"
msgstr "网速控制"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:64
msgid "Comment"
msgstr "注解"
msgstr "注释"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:28
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:56
msgid "Download speed (Mbit/s)"
msgstr "下载速度 (Mbit/s)"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:18
#: applications/luci-app-eqos/root/usr/share/luci/menu.d/luci-app-eqos.json:3
msgid "EQoS"
msgstr "网速控制"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:24
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:43
msgid "Enable"
msgstr "开启"
msgstr "启用"

msgid "QoS"
msgstr "QoS"
#: applications/luci-app-eqos/root/usr/share/rpcd/acl.d/luci-app-eqos.json:3
msgid "Grant UCI access for luci-app-eqos"
msgstr "授予 luci-app-eqos 访问 UCI 配置的权限"

msgid "Network speed control service"
msgstr "网速控制服务"
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:46
msgid "IP address"
msgstr "IP 地址"

msgid "Upload speed (Mbit/s)"
msgstr "上传速度 (Mbit/s)"
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:19
msgid "Network speed control service."
msgstr "网速控制服务。"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:38
msgid "Speed limit based on IP address"
msgstr "IP限速"
msgstr "基于 IP 限速"

msgid "Total bandwidth"
msgstr "总带宽"
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:29
msgid "Total download bandwidth."
msgstr "总下载带宽。"

msgid "Flow control setting"
msgstr "流控设置"
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:34
msgid "Total upload bandwidth."
msgstr "总上传带宽。"

#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:33
#: applications/luci-app-eqos/htdocs/luci-static/resources/view/eqos.js:60
msgid "Upload speed (Mbit/s)"
msgstr "上传速度 (Mbit/s)"
2 changes: 1 addition & 1 deletion applications/luci-app-eqos/root/etc/config/eqos
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The bandwidth unit is Mbit/s
config eqos
config eqos 'config'
option enabled 0
option download 100
option upload 20
Expand Down
58 changes: 34 additions & 24 deletions applications/luci-app-eqos/root/etc/init.d/eqos
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@
# Copyright (C) 2006 OpenWrt.org

START=50
USE_PROCD=1

parse_device() {
local cfg="$1" ip download upload

local cfg="$1"

local enabled
config_get_bool enabled "$cfg" "enabled" "1"
[ "$enabled" -eq "1" ] || return 1

local ip download upload
config_get ip "$cfg" ip
config_get download "$cfg" download
config_get upload "$cfg" upload
eqos add $ip $download $upload
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_service() {
config_load "eqos"

local enabled
config_get_bool enabled "config" "enabled" "0"
[ "$enabled" -eq "1" ] || return 1

local download upload
config_get download "config" "download"
config_get upload "config" "upload"

eqos start "$download" "$upload"

config_foreach parse_device "device"
}

start() {
stop_service() {
eqos stop

config_load eqos
config_foreach eqos_start eqos
}

stop() {
eqos stop
reload_service() {
stop
start
}

service_triggers() {
procd_add_reload_trigger "eqos"
}
2 changes: 0 additions & 2 deletions applications/luci-app-eqos/root/etc/uci-defaults/luci-eqos
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"admin/services/eqos": {
"title": "EQoS",
"action": {
"type": "view",
"path": "eqos"
},
"depends": {
"acl": [ "luci-app-eqos" ],
"uci": { "eqos": true }
}
}
}

0 comments on commit 4b70437

Please sign in to comment.