mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add quota support and small others changes
This commit is contained in:
parent
6fe07f493b
commit
b549503be7
23 changed files with 397 additions and 59 deletions
15
omr-quota/files/etc/config/omr-quota
Normal file
15
omr-quota/files/etc/config/omr-quota
Normal file
|
@ -0,0 +1,15 @@
|
|||
config interface 'wan1'
|
||||
option enabled '0'
|
||||
option txquota '100000'
|
||||
option rxquota '400000'
|
||||
option ttquota '500000'
|
||||
option interval '10'
|
||||
option interface 'wan1'
|
||||
|
||||
config interface 'wan2'
|
||||
option enabled '0'
|
||||
option txquota '100000'
|
||||
option rxquota '400000'
|
||||
option ttquota '500000'
|
||||
option interval '10'
|
||||
option interface 'wan2'
|
54
omr-quota/files/etc/init.d/omr-quota
Executable file
54
omr-quota/files/etc/init.d/omr-quota
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
{
|
||||
START=90
|
||||
STOP=10
|
||||
USE_PROCD=1
|
||||
}
|
||||
|
||||
_validate_section() {
|
||||
uci_validate_section omr-quota "$1" "$2" \
|
||||
'txquota:uinteger' \
|
||||
'rxquota:uinteger' \
|
||||
'ttquota:uinteger' \
|
||||
'interval:uinteger' \
|
||||
'interface:string' \
|
||||
'enabled:bool:0'
|
||||
}
|
||||
|
||||
_launch_quota() {
|
||||
local txquota rxquota ttquota interval enabled interface
|
||||
_validate_section "interface" "$1"
|
||||
|
||||
[ -z "$txquota" ] && [ -z "$rxquota" ] && [ -z "$ttquota" ] && return
|
||||
[ $enabled = 0 ] && return
|
||||
|
||||
[ "$(uci get vnstat.@vnstat[-1].interface | grep $interface)" = "" ] && {
|
||||
uci -q batch <<-EOF
|
||||
add_list vnstat.@vnstat[-1].interface=$interface
|
||||
EOF
|
||||
}
|
||||
procd_open_instance
|
||||
procd_set_param command /bin/omr-quota "$interface"
|
||||
procd_append_param env "OMR_QUOTA_TX=$txquota"
|
||||
procd_append_param env "OMR_QUOTA_RX=$rxquota"
|
||||
procd_append_param env "OMR_QUOTA_TT=$ttquota"
|
||||
procd_append_param env "OMR_QUOTA_INTERVAL=$interval"
|
||||
procd_set_param respawn 0 10 0
|
||||
procd_set_param stderr 1
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load omr-quota
|
||||
config_foreach _launch_quota interface
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger omr-quota network
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
8
omr-quota/files/etc/uci-defaults/omr-quota
Executable file
8
omr-quota/files/etc/uci-defaults/omr-quota
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
uci -q batch <<-EOF
|
||||
delete ucitrack.@omr-quota[-1]
|
||||
add ucitrack omr-quota
|
||||
set ucitrack.@omr-quota[-1].init="omr-quota"
|
||||
add_list ucitrack.@network[-1].affects="omr-quota"
|
||||
commit ucitrack
|
||||
EOF
|
Loading…
Add table
Add a link
Reference in a new issue