cgi-bin/admin/dav-htuseradd.cgi
branchfoerste
changeset 16 44cdd9d6fd8c
parent 15 9c78a255a51e
child 17 7f24266dc25d
equal deleted inserted replaced
15:9c78a255a51e 16:44cdd9d6fd8c
     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 # Using CGI::Fast will result in an Internal Server Error because we are
       
    23 # restarting apache when everything else works
       
    24 # use CGI::Fast;
       
    25 use CGI;
       
    26 use Ius::Dav::Htpasswd qw(mkpasswd readconfig useradd);
       
    27 
       
    28 my $q = new CGI;
       
    29 
       
    30     print $q->header(-charset => 'UTF-8');
       
    31     print $q->start_html(
       
    32         -title   => $0,
       
    33         -bgcolor => "white",
       
    34     );
       
    35 
       
    36     my ($user, $pass, $expiry) = (
       
    37         $q->param('user'),
       
    38         $q->param('pass'),
       
    39         $q->param('expiry')
       
    40     );
       
    41 
       
    42     unless (defined $user or defined $pass or defined $expiry) {
       
    43 
       
    44         print $q->start_form,
       
    45             'New User' => $q->textfield('user'),
       
    46             'Password' => $q->password_field('pass'),
       
    47             'Expiry' => $q->textfield('expiry'),
       
    48             $q->submit,
       
    49             $q->end_form;
       
    50 
       
    51     } else {
       
    52 
       
    53         my @cmd = (qw(sudo dav-htuseradd -u), $user);
       
    54         push @cmd, '-e', $expiry if defined $expiry and $expiry ne ''; 
       
    55 
       
    56         if (my $pass = qx(@cmd)) {
       
    57             chomp $pass;
       
    58             print $q->p($pass);
       
    59         } else {
       
    60             print $q->p('Something went wrong');
       
    61         } 
       
    62 
       
    63     }
       
    64 
       
    65     print $q->end_html;