1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-14 19:41:51 +00:00

Better quota and tracker interface

This commit is contained in:
Ycarus 2018-03-12 17:02:30 +01:00
parent 116dae3c40
commit 82e83780eb
5 changed files with 70 additions and 10 deletions

View file

@ -9,20 +9,18 @@ local ifaces = sys.net:devices()
m = Map("omr-quota", translate("Quota"), translate("Set quota, when quota is reached interface state is set to down"))
s = m:section(TypedSection, "interface", translate("Interfaces"))
s.template_addremove = "omr-quota/cbi-select-add"
s.addremove = true
s.anonymous = false
s.add_select_options = { }
for _, iface in ipairs(ifaces) do
if not (iface == "lo" or iface:match("^ifb.*")) then
s.add_select_options[iface] = iface
end
end
e = s:option(Flag, "enabled", translate("Enable"))
e.rmempty = false
intf = s:option(ListValue, "interface", translate("Interface name"))
for _, iface in ipairs(ifaces) do
if not (iface == "lo" or iface:match("^ifb.*")) then
intf:value(iface)
end
end
intf.rmempty = false
tx = s:option(Value, "txquota", translate("TX quota (kbit)"))
tx.datatype = "uinteger"

View file

@ -0,0 +1,10 @@
<div class="cbi-section-create">
<% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
<select class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.select">
<%- for k, v in luci.util.kspairs(self.add_select_options) do %>
<option value="<%=k%>"><%=luci.util.pcdata(v)%></option>
<% end -%>
</select>
<input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" title="<%:Add%>" />
<% if self.invalid_cts then %><br /><%:Invalid%></div><% end %>
</div>

View file

@ -1,3 +1,6 @@
local net = require "luci.model.network".init()
local sys = require "luci.sys"
local ifaces = sys.net:devices()
local m, s, o
m = Map("omr-tracker", translate("OMR-Tracker"), translate("OMR-Tracker detect when a connection is down and execute needed scripts"))
@ -33,4 +36,43 @@ o.placeholder = "4.2.2.1"
o.default = "4.2.2.1"
o.rmempty = false
s = m:section(TypedSection, "interface", translate("Interfaces"))
s.template_addremove = "omr-tracker/cbi-select-add"
s.addremove = true
s.add_select_options = { }
for _, iface in ipairs(ifaces) do
if not (iface == "lo" or iface:match("^ifb.*")) then
s.add_select_options[iface] = iface
end
end
o = s:option(Value, "timeout", translate("Timeout (s)"))
o.placeholder = "1"
o.default = "1"
o.datatype = "range(1, 100)"
o.rmempty = false
o = s:option(Value, "tries", translate("Tries"))
o.placeholder = "4"
o.default = "4"
o.datatype = "range(1, 10)"
o.rmempty = false
o = s:option(Value, "interval", translate("Retry interval (s)"))
o.placeholder = "2"
o.default = "2"
o.datatype = "range(1, 100)"
o.rmempty = false
o = s:option(ListValue, "type", translate("Type"), translate("Always ping gateway, then test connection by ping or dns. None mode only ping gateway."))
o:value("ping","ping")
o:value("dns","dns")
o:value("none","none")
o = s:option(DynamicList, "hosts", translate("Hosts"))
o.placeholder = "4.2.2.1"
o.default = "4.2.2.1"
o.rmempty = false
return m

View file

@ -0,0 +1,10 @@
<div class="cbi-section-create">
<% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
<select class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.select">
<%- for k, v in luci.util.kspairs(self.add_select_options) do %>
<option value="<%=k%>"><%=luci.util.pcdata(v)%></option>
<% end -%>
</select>
<input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" title="<%:Add%>" />
<% if self.invalid_cts then %><br /><%:Invalid%></div><% end %>
</div>

View file

@ -12,13 +12,13 @@ _validate_section() {
'rxquota:uinteger' \
'ttquota:uinteger' \
'interval:uinteger' \
'interface:string' \
'enabled:bool:0'
}
_launch_quota() {
local txquota rxquota ttquota interval enabled interface
_validate_section "interface" "$1"
interface=$1
[ -z "$txquota" ] && [ -z "$rxquota" ] && [ -z "$ttquota" ] && return
[ $enabled = 0 ] && return