Skip to content

Commit

Permalink
Added new function in api.pm (set_unreg_date)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdurand committed Mar 2, 2015
1 parent 49df771 commit 8f597b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/pf/api.pm
Expand Up @@ -441,6 +441,27 @@ sub node_information : Public {
return $node_info;
}

=head2 set_unreg_date
Set the unreg for a specific node
=cut

sub set_unreg_date : Public {
my ($class, %postdata) = @_;
my @require = qw(mac date);
my @found = grep {exists $postdata{$_}} @require;
return unless validate_argv(\@require, \@found);

my $unregdate;
if (pf::util::valid_date($postdata{'date'})) {
$unregdate = pf::config::dynamic_unreg_date($postdata{'date'});
} else {
$unregdate = pf::config::access_duration($postdata{'date'});
}
pf::node::node_modify($postdata{'mac'}, ('unregdate' => $unregdate));
}

=head2 validate_argv
Test if the required arguments are provided
Expand Down
2 changes: 1 addition & 1 deletion lib/pf/util.pm
Expand Up @@ -81,7 +81,7 @@ sub valid_date {
!~ /^\d{4}\-((0[1-9])|(1[0-2]))\-((0[1-9])|([12][0-9])|(3[0-1]))\s+(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}$/
)
{
$logger->error("invalid date $date");
$logger->warn("invalid date $date");
return (0);
} else {
return (1);
Expand Down

0 comments on commit 8f597b2

Please sign in to comment.