cgi-bin/ius-dav-htuseradd.cgi
branchfoerste
changeset 30 433042c33ad8
parent 25 8934ba3404bc
child 31 df24e0f202f1
equal deleted inserted replaced
29:6c8364b81a82 30:433042c33ad8
    23 # restarting apache when everything else works
    23 # restarting apache when everything else works
    24 # use CGI::Fast;
    24 # use CGI::Fast;
    25 use CGI;
    25 use CGI;
    26 use Ius::Dav::Htpasswd qw(mkpasswd readconfig useradd);
    26 use Ius::Dav::Htpasswd qw(mkpasswd readconfig useradd);
    27 
    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 
    28 my $q = new CGI;
    40 my $q = new CGI;
    29 
    41 
    30 print $q->header( -charset => 'UTF-8' );
    42 print $q->header( -charset => 'UTF-8' );
    31 print $q->start_html(
    43 print $q->start_html(
    32     -title   => $0,
    44     -title   => $0,
    33     -bgcolor => "white",
    45     -style   => { -code => $css },
    34 );
    46     -onload  => q{document.forms['add'].elements['user'].focus();}
       
    47 ), $q->h3({ -id => 'header' }, 'Befristeten WebDAV Zugang einrichten'), $q->hr;
    35 
    48 
    36 my ( $user, $pass, $expiry ) =
    49 my ( $user, $pass, $expiry ) =
    37   ( $q->param('user'), $q->param('pass'), $q->param('expiry') );
    50   ( $q->param('user'), $q->param('pass'), $q->param('expiry') );
    38 
    51 
    39 unless ( defined $user or defined $pass or defined $expiry ) {
    52 print $q->start_form(-id => 'add'),
       
    53   $q->table(
       
    54       $q->Tr(
       
    55           $q->td('Nutzername'),
       
    56           $q->td($q->textfield('user'))
       
    57       ),
       
    58       $q->Tr(
       
    59           $q->td('Gültigkeitsdauer in Tagen (default: 1)'),
       
    60           $q->td($q->textfield('expiry'))
       
    61       ),
       
    62       $q->Tr(
       
    63           $q->td($q->submit('Anlegen'))
       
    64       )
       
    65   ),
       
    66   $q->end_form;
    40 
    67 
    41     print $q->start_form,
    68 my $doit = 0;
    42       'New User' => $q->textfield('user'),
    69 for ($user, $pass, $expiry) { $doit = 1 and last if defined and $_ ne ''; }
    43       'Password' => $q->password_field('pass'),
       
    44       'Expiry'   => $q->textfield('expiry'),
       
    45       $q->submit,
       
    46       $q->end_form;
       
    47 
    70 
    48 }
    71 if ($doit) {
    49 else {
       
    50 
       
    51     my @cmd = ( qw(sudo ius-dav-htuseradd -u), $user );
    72     my @cmd = ( qw(sudo ius-dav-htuseradd -u), $user );
    52     push @cmd, '-e', $expiry if defined $expiry and $expiry ne '';
    73     push @cmd, '-e', $expiry if defined $expiry and $expiry ne '';
    53 
    74 
       
    75     print $q->hr;
    54     if ( my $pass = qx(@cmd) ) {
    76     if ( my $pass = qx(@cmd) ) {
    55         chomp $pass;
    77         chomp $pass;
    56         print $q->p($pass);
    78         print $q->table(
       
    79             $q->Tr(
       
    80                 $q->td('Url:'),
       
    81                 $q->td('not yet implemented')
       
    82             ),
       
    83             $q->Tr(
       
    84                 $q->td('Passwort:'),
       
    85                 $q->td($pass)
       
    86             )
       
    87         )
    57     }
    88     }
    58     else {
    89     else {
    59         print $q->p('Something went wrong');
    90         print $q->p('Something went wrong');
    60     }
    91     }
    61 
    92 
    62 }
    93 }
    63 
    94 
    64 print $q->end_html;
    95 print $q->hr, $q->end_html;