cgi-bin/ius-dav-htuseradd.cgi
changeset 37 fee44892ca1e
parent 36 a459cc790ed0
child 52 c892bf85383e
equal deleted inserted replaced
12:e0e126b7f06d 37:fee44892ca1e
       
     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 $css = <<EOC;
       
    29 body {
       
    30         font-family: Helvetica, Arial, sans-serif;
       
    31 }
       
    32 h3#header {
       
    33     background-color: #d60029;
       
    34     color: #fff;
       
    35     padding-top: 1em;
       
    36     padding-bottom: 1em;
       
    37 }
       
    38 EOC
       
    39 
       
    40 my $q = new CGI;
       
    41 
       
    42 print $q->header( -charset => 'UTF-8' );
       
    43 print $q->start_html(
       
    44     -title  => $0,
       
    45     -style  => { -code => $css },
       
    46     -onload => q{document.forms['passwd'].elements['user'].focus();}
       
    47   ),
       
    48   $q->h3( { -id => 'header' }, 'Befristete WebDAV Zugänge einrichten' ),
       
    49   $q->hr;
       
    50 
       
    51 my $p;
       
    52 $p->{$_} = $q->param($_) for qw(user expiry add del);
       
    53 
       
    54 print $q->start_form( -id => 'passwd' ),
       
    55   $q->table(
       
    56     $q->Tr( $q->td('Nutzername'), $q->td( $q->textfield('user') ) ),
       
    57     $q->Tr(
       
    58         $q->td('Gültigkeitsdauer in Tagen (default: 1)'),
       
    59         $q->td( $q->textfield('expiry') )
       
    60     ),
       
    61     $q->Tr(
       
    62         $q->td( $q->submit( { -name => 'add', -value => 'Anlegen' } ) ),
       
    63         $q->td( $q->submit( { -name => 'del', -value => 'Löschen' } ) )
       
    64     )
       
    65   ),
       
    66   $q->end_form;
       
    67 
       
    68 my $doit = 0;
       
    69 
       
    70 my $conf = readconfig or die "Can't readconfig";
       
    71 
       
    72 if ( defined $p->{add} and $p->{add} ne '' ) {
       
    73 
       
    74     print $q->hr;
       
    75     my @cmd = ( qw(sudo ius-dav-htuseradd -u), $p->{user} );
       
    76     push @cmd, '-e', $p->{expiry}
       
    77       if defined $p->{expiry} and $p->{expiry} ne '';
       
    78 
       
    79     if ( my $pass = qx(@cmd) ) {
       
    80 
       
    81         my $url = "$conf->{dav_base_remote}/$p->{user}";
       
    82 
       
    83         chomp $pass;
       
    84 
       
    85         print $q->table(
       
    86             $q->Tr(
       
    87                 $q->td('Url:'), $q->td( $q->a( { -href => $url }, $url ) )
       
    88             ),
       
    89             $q->Tr( $q->td('Passwort:'), $q->td($pass) )
       
    90         );
       
    91 
       
    92     }
       
    93     else {
       
    94         print $q->p('Something went wrong');
       
    95     }
       
    96 
       
    97 }
       
    98 elsif ( defined $p->{del} and $p->{del} ne '' ) {
       
    99 
       
   100     my @cmd = ( qw(sudo ius-dav-htuserdel -u), $p->{user} );
       
   101     print $q->hr, $q->p('Something went wrong') if system @cmd;
       
   102 
       
   103 }
       
   104 
       
   105 print $q->hr, $q->end_html;