diff options
author | Mohit Mehta <mohit.mehta@vyatta.com> | 2009-01-14 16:35:30 -0800 |
---|---|---|
committer | Mohit Mehta <mohit.mehta@vyatta.com> | 2009-01-14 16:35:30 -0800 |
commit | cc811731ba98e6b5f76cfea66960c2c8e2943532 (patch) | |
tree | 809743f684812fb8a0102ea20d42ae7e1f279a16 /lib/Vyatta/IpTables | |
parent | df2b074630ef74748d8622515674915675c891f8 (diff) | |
download | vyatta-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
Diffstat (limited to 'lib/Vyatta/IpTables')
-rw-r--r-- | lib/Vyatta/IpTables/Rule.pm | 38 |
1 files changed, 30 insertions, 8 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; |