From 7b7030629c4d55557b368a292d7f3e3d14b1923b Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Sat, 10 Nov 2012 20:55:50 +0000 Subject: [PATCH] Add some more datatype checks, patch by Eugene C., #499 --- applications/luci-ddns/luasrc/model/cbi/ddns/ddns.lua | 11 ++++++++--- applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpc.lua | 17 +++++++++++++---- .../luci-ntpc/luasrc/model/cbi/ntpc/ntpcmini.lua | 9 ++++++--- applications/luci-qos/luasrc/model/cbi/qos/qos.lua | 6 ++++-- applications/luci-qos/luasrc/model/cbi/qos/qosmini.lua | 8 ++++++-- .../admin-full/luasrc/model/cbi/admin_network/vlan.lua | 2 ++ 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/applications/luci-ddns/luasrc/model/cbi/ddns/ddns.lua b/applications/luci-ddns/luasrc/model/cbi/ddns/ddns.lua index 42fb4a61d..e477a245e 100644 --- a/applications/luci-ddns/luasrc/model/cbi/ddns/ddns.lua +++ b/applications/luci-ddns/luasrc/model/cbi/ddns/ddns.lua @@ -112,14 +112,19 @@ else end -s:option(Value, "check_interval", - translate("Check for changed IP every")).default = 10 +ci = s:option(Value, "check_interval", translate("Check for changed IP every")) +ci.datatype = "and(uinteger,min(1))" +ci.default = 10 + unit = s:option(ListValue, "check_unit", translate("Check-time unit")) unit.default = "minutes" unit:value("minutes", translate("min")) unit:value("hours", translate("h")) -s:option(Value, "force_interval", translate("Force update every")).default = 72 +fi = s:option(Value, "force_interval", translate("Force update every")) +fi.datatype = "and(uinteger,min(1))" +fi.default = 72 + unit = s:option(ListValue, "force_unit", translate("Force-time unit")) unit.default = "hours" unit:value("minutes", translate("min")) diff --git a/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpc.lua b/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpc.lua index ab7f73edb..5265359c6 100644 --- a/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpc.lua +++ b/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpc.lua @@ -20,14 +20,21 @@ s.addremove = false s:option(DummyValue, "_time", translate("Current system time")).value = os.date("%c") -s:option(Value, "interval", translate("Update interval (in seconds)")).rmempty = true -s:option(Value, "count", translate("Count of time measurements"), translate("empty = infinite")).rmempty = true +interval = s:option(Value, "interval", translate("Update interval (in seconds)")) +interval.datatype = "and(uinteger,min(1))" +interval.rmempty = true +count = s:option(Value, "count", translate("Count of time measurements"), translate("empty = infinite")) +count.datatype = "and(uinteger,min(1))" +count.rmempty = true s2 = m:section(TypedSection, "ntpdrift", translate("Clock Adjustment")) s2.anonymous = true s2.addremove = false -s2:option(Value, "freq", translate("Offset frequency")).rmempty = true + +freq = s2:option(Value, "freq", translate("Offset frequency")) +freq.datatype = "integer" +freq.rmempty = true s3 = m:section(TypedSection, "ntpserver", translate("Time Servers")) s3.anonymous = true @@ -35,6 +42,8 @@ s3.addremove = true s3.template = "cbi/tblsection" s3:option(Value, "hostname", translate("Hostname")) -s3:option(Value, "port", translate("Port")).rmempty = true +port = s3:option(Value, "port", translate("Port")) +port.datatype = "port" +port.rmempty = true return m diff --git a/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpcmini.lua b/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpcmini.lua index 9b5633762..2a6c41524 100644 --- a/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpcmini.lua +++ b/applications/luci-ntpc/luasrc/model/cbi/ntpc/ntpcmini.lua @@ -21,8 +21,9 @@ s.addremove = false s:option(DummyValue, "_time", translate("Current system time")).value = os.date("%c") -s:option(Value, "interval", translate("Update interval (in seconds)")).rmempty = true - +interval = s:option(Value, "interval", translate("Update interval (in seconds)")) +interval.datatype = "and(uinteger,min(1))" +interval.rmempty = true s3 = m:section(TypedSection, "ntpserver", translate("Time Server")) s3.anonymous = true @@ -30,6 +31,8 @@ s3.addremove = true s3.template = "cbi/tblsection" s3:option(Value, "hostname", translate("Hostname")) -s3:option(Value, "port", translate("Port")).rmempty = true +port = s3:option(Value, "port", translate("Port")) +port.datatype = "port" +port.rmempty = true return m diff --git a/applications/luci-qos/luasrc/model/cbi/qos/qos.lua b/applications/luci-qos/luasrc/model/cbi/qos/qos.lua index 98e9a2507..1af3bdbbd 100644 --- a/applications/luci-qos/luasrc/model/cbi/qos/qos.lua +++ b/applications/luci-qos/luasrc/model/cbi/qos/qos.lua @@ -35,9 +35,11 @@ s:option(Flag, "overhead", translate("Calculate overhead")) s:option(Flag, "halfduplex", translate("Half-duplex")) -s:option(Value, "download", translate("Download speed (kbit/s)")) +dl = s:option(Value, "download", translate("Download speed (kbit/s)")) +dl.datatype = "and(uinteger,min(1))" -s:option(Value, "upload", translate("Upload speed (kbit/s)")) +ul = s:option(Value, "upload", translate("Upload speed (kbit/s)")) +ul.datatype = "and(uinteger,min(1))" s = m:section(TypedSection, "classify", translate("Classification Rules")) s.template = "cbi/tblsection" diff --git a/applications/luci-qos/luasrc/model/cbi/qos/qosmini.lua b/applications/luci-qos/luasrc/model/cbi/qos/qosmini.lua index 9ffefec4f..0c5766f34 100644 --- a/applications/luci-qos/luasrc/model/cbi/qos/qosmini.lua +++ b/applications/luci-qos/luasrc/model/cbi/qos/qosmini.lua @@ -21,8 +21,12 @@ m = Map("qos") s = m:section(NamedSection, "wan", "interface", translate("Internet Connection")) s:option(Flag, "enabled", translate("Quality of Service")) -s:option(Value, "download", translate("Downlink"), "kbit/s") -s:option(Value, "upload", translate("Uplink"), "kbit/s") + +dl = s:option(Value, "download", translate("Downlink"), "kbit/s") +dl.datatype = "and(uinteger,min(1))" + +ul = s:option(Value, "upload", translate("Uplink"), "kbit/s") +ul.datatype = "and(uinteger,min(1))" s = m:section(TypedSection, "classify") s.template = "cbi/tblsection" diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua b/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua index b0de19133..0fa2696e8 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua @@ -202,10 +202,12 @@ m.uci:foreach("network", "switch", local vid = s:option(Value, has_vlan4k or "vlan", "VLAN ID", "
" % switch_name) + local mx_vid = has_vlan4k and 4094 or (num_vlans - 1) vid.rmempty = false vid.forcewrite = true vid.vlan_used = { } + vid.datatype = "and(uinteger,range("..min_vid..","..mx_vid.."))" -- Validate user provided VLAN ID, make sure its within the bounds -- allowed by the switch. -- 2.11.0