summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohit Mehta <mohit.mehta@vyatta.com>2009-01-14 16:35:30 -0800
committerMohit Mehta <mohit.mehta@vyatta.com>2009-01-14 16:35:30 -0800
commitcc811731ba98e6b5f76cfea66960c2c8e2943532 (patch)
tree809743f684812fb8a0102ea20d42ae7e1f279a16
parentdf2b074630ef74748d8622515674915675c891f8 (diff)
downloadvyatta-cfg-firewall-cc811731ba98e6b5f76cfea66960c2c8e2943532.tar.gz
vyatta-cfg-firewall-cc811731ba98e6b5f76cfea66960c2c8e2943532.zip
Fix Bug 3653 Add the ability to configure time-based firewall rules
- make available the option to use time with startdate and stopdate
-rw-r--r--lib/Vyatta/IpTables/Rule.pm38
-rw-r--r--templates/firewall/modify/node.tag/rule/node.tag/time/startdate/node.def11
-rw-r--r--templates/firewall/modify/node.tag/rule/node.tag/time/stopdate/node.def11
-rw-r--r--templates/firewall/name/node.tag/rule/node.tag/time/startdate/node.def12
-rw-r--r--templates/firewall/name/node.tag/rule/node.tag/time/stopdate/node.def12
5 files changed, 62 insertions, 22 deletions
diff --git a/lib/Vyatta/IpTables/Rule.pm b/lib/Vyatta/IpTables/Rule.pm
index 890ff7c..23755a6 100644
--- a/lib/Vyatta/IpTables/Rule.pm
+++ b/lib/Vyatta/IpTables/Rule.pm
@@ -388,16 +388,18 @@ sub rule {
$time .= " --utc ";
}
if (defined($self->{_time}->{_startdate})) {
- return ("Invalid startdate $self->{_time}->{_startdate}.
-Date should use yyyy-mm-dd format and lie in between 1970-01-01 and 2038-01-19", )
- if (!validate_timevalues($self->{_time}->{_startdate}, "date"));
- $time .= " --datestart $self->{_time}->{_startdate} ";
+ my $check_date = validate_date($self->{_time}->{_startdate}, "startdate");
+ if (!($check_date eq "")) {
+ return ($check_date, );
+ }
+ $time .= " --datestart $self->{_time}->{_startdate} ";
}
if (defined($self->{_time}->{_stopdate})) {
- return ("Invalid stopdate $self->{_time}->{_stopdate}.
-Date should use yyyy-mm-dd format and lie in between 1970-01-01 and 2038-01-19", )
- if (!validate_timevalues($self->{_time}->{_stopdate}, "date"));
- $time .= " --datestop $self->{_time}->{_stopdate} ";
+ my $check_date = validate_date($self->{_time}->{_stopdate}, "stopdate");
+ if (!($check_date eq "")) {
+ return ($check_date, );
+ }
+ $time .= " --datestop $self->{_time}->{_stopdate} ";
}
if (defined($self->{_time}->{_starttime})) {
return ("Invalid starttime $self->{_time}->{_starttime}.
@@ -558,4 +560,24 @@ sub validate_timevalues {
return 1;
}
+sub validate_date {
+
+ my ($date, $string) = @_;
+ if ($date =~ m/T/) {
+ my $actualdate = substr $date, 0 , 10;
+ my $datetime = substr $date, 11;
+ return ("Invalid $string $actualdate.
+Date should use yyyy-mm-dd format and lie in between 1970-01-01 and 2038-01-19")
+ if (!validate_timevalues($actualdate, "date"));
+ return ("Invalid time $datetime for $string $actualdate.
+Time should use 24 hour notation hh:mm:ss and lie in between 00:00:00 and 23:59:59")
+ if (!validate_timevalues($datetime, "time"));
+ } else {
+ return ("Invalid $string $date.
+Date should use yyyy-mm-dd format and lie in between 1970-01-01 and 2038-01-19")
+ if (!validate_timevalues($date, "date"));
+ }
+ return ("");
+}
+
1;
diff --git a/templates/firewall/modify/node.tag/rule/node.tag/time/startdate/node.def b/templates/firewall/modify/node.tag/rule/node.tag/time/startdate/node.def
index 129b845..4d470f4 100644
--- a/templates/firewall/modify/node.tag/rule/node.tag/time/startdate/node.def
+++ b/templates/firewall/modify/node.tag/rule/node.tag/time/startdate/node.def
@@ -1,7 +1,12 @@
type: txt
help: Set to apply rule starting from specified date
-syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}$" ; \
- "Incorrect value for startdate. Date should be entered as yyyy-mm-dd"
+syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}(T[[:digit:]]\{2\}[:][[:digit:]]\{2\}[:][[:digit:]]\{2\})?$" ; \
+"Invalid value for startdate. Date should use yyyy-mm-dd format. To specify time
+of date with startdate, append 'T' to date followed by time in 24 hour notation
+hh:mm:ss. For example startdate value of 2009-01-21T13:30:00 refers to
+21st January 2009 with time 13:30:00"
-comp_help: Format for date : yyyy-mm-dd
+comp_help: Format for date : yyyy-mm-dd. To specify time of date with startdate, append
+'T' to date followed by time in 24 hour notation hh:mm:ss. For eg startdate
+value of 2009-01-21T13:30:00 refers to 21st Jan 2009 with time 13:30:00
diff --git a/templates/firewall/modify/node.tag/rule/node.tag/time/stopdate/node.def b/templates/firewall/modify/node.tag/rule/node.tag/time/stopdate/node.def
index 238e7a7..90dd684 100644
--- a/templates/firewall/modify/node.tag/rule/node.tag/time/stopdate/node.def
+++ b/templates/firewall/modify/node.tag/rule/node.tag/time/stopdate/node.def
@@ -1,7 +1,12 @@
type: txt
help: Set to apply rule till specified date
-syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}$" ; \
- "Incorrect value for stopdate. Date should be entered as yyyy-mm-dd"
+syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}(T[[:digit:]]\{2\}[:][[:digit:]]\{2\}[:][[:digit:]]\{2\})?$" ; \
+"Invalid value for stopdate. Date should use yyyy-mm-dd format. To specify time
+of date with stopdate, append 'T' to date followed by time in 24 hour notation
+hh:mm:ss. For example stopdate value of 2009-01-31T13:30:00 refers to
+31st Jan 2009 with time 13:30:00"
-comp_help: Format for date : yyyy-mm-dd
+comp_help: Format for date : yyyy-mm-dd. To specify time of date with stopdate,
+append 'T' to date followed by time in 24 hour notation hh:mm:ss. For eg
+stopdate value of 2009-01-31T13:30:00 refers to 31st Jan 2009 with time 13:30:00
diff --git a/templates/firewall/name/node.tag/rule/node.tag/time/startdate/node.def b/templates/firewall/name/node.tag/rule/node.tag/time/startdate/node.def
index 129b845..a971375 100644
--- a/templates/firewall/name/node.tag/rule/node.tag/time/startdate/node.def
+++ b/templates/firewall/name/node.tag/rule/node.tag/time/startdate/node.def
@@ -1,7 +1,11 @@
type: txt
help: Set to apply rule starting from specified date
-syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}$" ; \
- "Incorrect value for startdate. Date should be entered as yyyy-mm-dd"
-
-comp_help: Format for date : yyyy-mm-dd
+syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}(T[[:digit:]]\{2\}[:][[:digit:]]\{2\}[:][[:digit:]]\{2\})?$" ; \
+"Invalid value for startdate. Date should use yyyy-mm-dd format. To specify time
+of date with startdate, append 'T' to date followed by time in 24 hour notation
+hh:mm:ss. For example startdate value of 2009-01-21T13:30:00 refers to
+21st January 2009 with time 13:30:00"
+comp_help: Format for date : yyyy-mm-dd. To specify time of date with startdate, append
+'T' to date followed by time in 24 hour notation hh:mm:ss. For eg startdate
+value of 2009-01-21T13:30:00 refers to 21st Jan 2009 with time 13:30:00
diff --git a/templates/firewall/name/node.tag/rule/node.tag/time/stopdate/node.def b/templates/firewall/name/node.tag/rule/node.tag/time/stopdate/node.def
index 238e7a7..c99dd7b 100644
--- a/templates/firewall/name/node.tag/rule/node.tag/time/stopdate/node.def
+++ b/templates/firewall/name/node.tag/rule/node.tag/time/stopdate/node.def
@@ -1,7 +1,11 @@
type: txt
help: Set to apply rule till specified date
-syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}$" ; \
- "Incorrect value for stopdate. Date should be entered as yyyy-mm-dd"
-
-comp_help: Format for date : yyyy-mm-dd
+syntax:expression: pattern $VAR(@) "^[[:digit:]]\{4\}[-][[:digit:]]\{2\}[-][[:digit:]]\{2\}(T[[:digit:]]\{2\}[:][[:digit:]]\{2\}[:][[:digit:]]\{2\})?$" ; \
+"Invalid value for stopdate. Date should use yyyy-mm-dd format. To specify time
+of date with stopdate, append 'T' to date followed by time in 24 hour notation
+hh:mm:ss. For example stopdate value of 2009-01-31T13:30:00 refers to
+31st Jan 2009 with time 13:30:00"
+comp_help: Format for date : yyyy-mm-dd. To specify time of date with stopdate,
+append 'T' to date followed by time in 24 hour notation hh:mm:ss. For eg
+stopdate value of 2009-01-31T13:30:00 refers to 31st Jan 2009 with time 13:30:00