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