bin/dav-htuseradd.cgi
changeset 10 059036ddb06d
parent 9 4227cf8872b8
child 11 2217a0f2ded2
equal deleted inserted replaced
9:4227cf8872b8 10:059036ddb06d
     1 #!/usr/bin/perl
       
     2 
       
     3 #    Copyright (C) 2011  Matthias Förste
       
     4 #
       
     5 #    This program is free software: you can redistribute it and/or modify
       
     6 #    it under the terms of the GNU General Public License as published by
       
     7 #    the Free Software Foundation, either version 3 of the License, or
       
     8 #    (at your option) any later version.
       
     9 #
       
    10 #    This program is distributed in the hope that it will be useful,
       
    11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 #    GNU General Public License for more details.
       
    14 #
       
    15 #    You should have received a copy of the GNU General Public License
       
    16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    17 #
       
    18 #    Matthias Förste <foerste@schlittermann.de>
       
    19 
       
    20 use warnings;
       
    21 
       
    22 #use CGI::Fast;
       
    23 #use POSIX;
       
    24 
       
    25 while (my $q = new CGI::Fast) {
       
    26 
       
    27     print $q->header(-charset => 'UTF-8');
       
    28     print $q->start_html(
       
    29         -title   => $0,
       
    30         -bgcolor => "white",
       
    31     );
       
    32 
       
    33     my ($user, $expiry) = (
       
    34         $q->param('user'),
       
    35         $q->param('expiry')
       
    36     );
       
    37 
       
    38     print $q->start_form, 'New User' => $q->textfield('user'), 'Expiry' => $q->textfield('expiry'), $q->submit, $q->end_form
       
    39         unless defined $user or defined $expiry;
       
    40 
       
    41     $expiry ||= $defaults->{expiry};
       
    42     if (_validate $q, $user, $expiry) {
       
    43 
       
    44         my $t = POSIX::strftime '%Y%m%d%H%M%S', time + 86400 * $expiry;
       
    45         my @at_cmd = ('at', $t
       
    46 
       
    47 
       
    48     } else {
       
    49         _error ($q, 'invalid input');
       
    50     }
       
    51 
       
    52     print $q->end_html;
       
    53 
       
    54 }
       
    55 
       
    56 sub _validate {
       
    57 
       
    58     my ($u, $e) = @_;
       
    59 
       
    60     return unless $u =~ /^[[:alpha:]_]+$/; 
       
    61     return unless $e =~ /^[0-9]+$/;
       
    62     return unless $e >= $defaults->{expiry_min} and $e <= $defaults->{expiry_max};
       
    63 
       
    64     return 1;
       
    65 
       
    66 }
       
    67 
       
    68 sub _notice {
       
    69 
       
    70     my ($q, @n) = @_;
       
    71     print @_;
       
    72 
       
    73 }
       
    74 
       
    75 sub _error {
       
    76 
       
    77     my ($q, @n) = @_;
       
    78     print @_;
       
    79 
       
    80 }