diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-12-15 23:08:17 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-12-15 23:08:17 +0100 |
commit | f25c4e07bc9642e0491d3a4ab3942a69545891e9 (patch) | |
tree | e61fe5d6376b55eb71754401ea4730675d4bd2b5 | |
parent | 19b85c34fcac8ad9b2829b4e034d7fefa42fb145 (diff) | |
parent | 986baa5ccee13692e9c1ef5a23535e15b7fcb948 (diff) |
Merge pull request #564 from cshore/pull-request-app-firewall-timedate
Pull request app firewall timedate
4 files changed, 117 insertions, 1 deletions
diff --git a/applications/luci-app-firewall/luasrc/model/cbi/firewall/rule-details.lua b/applications/luci-app-firewall/luasrc/model/cbi/firewall/rule-details.lua index 0cb30b5cd..60af531d5 100644 --- a/applications/luci-app-firewall/luasrc/model/cbi/firewall/rule-details.lua +++ b/applications/luci-app-firewall/luasrc/model/cbi/firewall/rule-details.lua @@ -316,4 +316,34 @@ else translate("Passes additional arguments to iptables. Use with care!")) end +o = s:option(MultiValue, "weekdays", translate("Week Days")) +o.oneline = true +o.widget = "checkbox" +o:value("sun", translate("Sunday")) +o:value("mon", translate("Monday")) +o:value("tue", translate("Tuesday")) +o:value("wed", translate("Wednesday")) +o:value("thu", translate("Thursday")) +o:value("fri", translate("Friday")) +o:value("sat", translate("Saturday")) + +o = s:option(MultiValue, "monthdays", translate("Month Days")) +o.oneline = true +o.widget = "checkbox" +for i = 1,31 do + o:value(translate(i)) +end + +o = s:option(Value, "start_time", translate("Start Time (hh:mm:ss)")) +o.datatype = "timehhmmss" +o = s:option(Value, "stop_time", translate("Stop Time (hh:mm:ss)")) +o.datatype = "timehhmmss" +o = s:option(Value, "start_date", translate("Start Date (yyyy-mm-dd)")) +o.datatype = "dateyyyymmdd" +o = s:option(Value, "stop_date", translate("Stop Date (yyyy-mm-dd)")) +o.datatype = "dateyyyymmdd" + +o = s:option(Flag, "utc_time", translate("Time in UTC")) +o.default = o.disabled + return m diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 8a3cb6fca..4b7227f1a 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -322,6 +322,47 @@ var cbi_validators = { 'phonedigit': function() { return (this.match(/^[0-9\*#!\.]+$/) != null); + }, + 'timehhmmss': function() + { + return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null); + }, + 'dateyyyymmdd': function() + { + if (this == null) { + return false; + } + if (this.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)) { + var year = RegExp.$1; + var month = RegExp.$2; + var day = RegExp.$2 + + var days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30 , 31, 30, 31 ]; + function is_leap_year(year) { + return ((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0); + } + function get_days_in_month(month, year) { + if ((month == 2) && is_leap_year(year)) { + return 29; + } else { + return days_in_month[month]; + } + } + /* Firewall rules in the past don't make sense */ + if (year < 2015) { + return false; + } + if ((month <= 0) || (month > 12)) { + return false; + } + if ((day <= 0) || (day > get_days_in_month(month, year))) { + return false; + } + return true; + + } else { + return false; + } } }; diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua index 52f90afee..4c003be2a 100644 --- a/modules/luci-base/luasrc/cbi/datatypes.lua +++ b/modules/luci-base/luasrc/cbi/datatypes.lua @@ -341,3 +341,48 @@ end function phonedigit(val) return (val:match("^[0-9\*#!%.]+$") ~= nil) end + +function timehhmmss(val) + return (val:match("^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$") ~= nil) +end + +function dateyyyymmdd(val) + if val ~= nil then + yearstr, monthstr, daystr = val:match("^(%d%d%d%d)-(%d%d)-(%d%d)$") + if (yearstr == nil) or (monthstr == nil) or (daystr == nil) then + return false; + end + year = tonumber(yearstr) + month = tonumber(monthstr) + day = tonumber(daystr) + if (year == nil) or (month == nil) or (day == nil) then + return false; + end + + local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } + + local function is_leap_year(year) + return (year % 4 == 0) and ((year % 100 ~= 0) or (year % 400 == 0)) + end + + function get_days_in_month(month, year) + if (month == 2) and is_leap_year(year) then + return 29 + else + return days_in_month[month] + end + end + if (year < 2015) then + return false + end + if ((month == 0) or (month > 12)) then + return false + end + if ((day == 0) or (day > get_days_in_month(month, year))) then + return false + end + return true + end + return false +end + diff --git a/modules/luci-base/luasrc/view/cbi/mvalue.htm b/modules/luci-base/luasrc/view/cbi/mvalue.htm index 6a0b3881d..5d092610e 100644 --- a/modules/luci-base/luasrc/view/cbi/mvalue.htm +++ b/modules/luci-base/luasrc/view/cbi/mvalue.htm @@ -12,7 +12,7 @@ c = c + 1 %> <input class="cbi-input-checkbox" type="checkbox" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"<%= attr("id", cbid..c) .. attr("name", cbid) .. attr("value", key) .. ifattr(luci.util.contains(v, key), "checked", "checked") %> /> - <label<%= attr("for", cbid..c) %>><%=self.vallist[i]%></label><br /> + <label<%= attr("for", cbid..c) %>><%=self.vallist[i]%></label><% if not self.oneline then %><br /><% else %> <% end %> <% if c == self.size then c = 0 %><br /> <% end end %> <% end %> |