cgi-bin/dav-htuseradd.cgi
changeset 10 059036ddb06d
parent 0 64e38b554da3
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 Ius::Dav::Htpasswd qw(mkpasswd readconfig useradd);
       
    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, $pass, $expiry) = (
       
    34         $q->param('user'),
       
    35         $q->param('pass'),
       
    36         $q->param('expiry')
       
    37     );
       
    38 
       
    39     unless (defined $user or defined $pass or defined $expiry) {
       
    40 
       
    41         print $q->start_form,
       
    42             'New User' => $q->textfield('user'),
       
    43             'Password' => $q->password_field('pass'),
       
    44             'Expiry' => $q->textfield('expiry'),
       
    45             $q->submit,
       
    46             $q->end_form;
       
    47 
       
    48     } else {
       
    49 
       
    50         my @cmd = (qw(sudo dav-htuseradd -u), $user);
       
    51         push @cmd, '-e', $expiry if defined $expiry and $expiry ne ''; 
       
    52 
       
    53         if (my $pass = qx(@cmd)) {
       
    54             chomp $pass;
       
    55             print $q->p($pass);
       
    56         } else {
       
    57             print $q->p('Something went wrong');
       
    58         } 
       
    59 
       
    60     }
       
    61 
       
    62     print $q->end_html;
       
    63 
       
    64 }