cgi-bin/ius-dav-htuseradd.cgi
branchfoerste
changeset 34 10c4e30a62af
parent 33 be97a7cbe807
child 36 a459cc790ed0
equal deleted inserted replaced
33:be97a7cbe807 34:10c4e30a62af
    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 ), $q->h3({ -id => 'header' }, 'Befristete WebDAV Zugänge einrichten'), $q->hr;
    48 
    48 
    49 my ( $user, $pass, $expiry ) =
    49 my $p;
    50   ( $q->param('user'), $q->param('pass'), $q->param('expiry') );
    50 $p->{$_} = $q->param($_) for qw(user expiry add del);
    51 
    51 
    52 print $q->start_form(-id => 'passwd'),
    52 print $q->start_form(-id => 'passwd'),
    53   $q->table(
    53   $q->table(
    54       $q->Tr(
    54       $q->Tr(
    55           $q->td('Nutzername'),
    55           $q->td('Nutzername'),
    65       )
    65       )
    66   ),
    66   ),
    67   $q->end_form;
    67   $q->end_form;
    68 
    68 
    69 my $doit = 0;
    69 my $doit = 0;
    70 for ($user, $pass, $expiry) { $doit = 1 and last if defined and $_ ne ''; }
       
    71 
    70 
    72 if ($doit) {
    71 my $conf = readconfig or die "Can't readconfig"; 
    73 
    72 
    74     my $conf = readconfig or die "Can't readconfig"; 
    73 if (defined $p->{add} and $p->{add} ne '') {
    75     my $add = $q->param('add');
       
    76     my $del = $q->param('del');
       
    77 
    74 
    78     if ($add) {
    75     print $q->hr;
       
    76     my @cmd = ( qw(sudo ius-dav-htuseradd -u), $p->{user} );
       
    77     push @cmd, '-e', $p->{expiry} if defined $p->{expiry} and $p->{expiry} ne '';
    79 
    78 
    80         print $q->hr;
    79     if ( my $pass = qx(@cmd) ) {
    81         my @cmd = ( qw(sudo ius-dav-htuseradd -u), $user );
       
    82         push @cmd, '-e', $expiry if defined $expiry and $expiry ne '';
       
    83 
    80 
    84         if ( my $pass = qx(@cmd) ) {
    81         my $url = "$conf->{dav_base_remote}/$p->{user}";
    85 
    82 
    86             my $url = "$conf->{dav_base_remote}/$user";
    83         chomp $pass;
    87 
    84 
    88             chomp $pass;
    85         print $q->table(
    89 
    86             $q->Tr(
    90             print $q->table(
    87                 $q->td('Url:'),
    91                 $q->Tr(
    88                 $q->td($q->a({ -href => $url }, $url))
    92                     $q->td('Url:'),
    89             ),
    93                     $q->td($q->a({ -href => $url }, $url))
    90             $q->Tr(
    94                 ),
    91                 $q->td('Passwort:'),
    95                 $q->Tr(
    92                 $q->td($pass)
    96                     $q->td('Passwort:'),
    93             )
    97                     $q->td($pass)
    94         );
    98                 )
       
    99             );
       
   100 
    95 
   101 
    96 
   102         }
    97     }
   103         else {
    98     else {
   104             print $q->p('Something went wrong');
    99         print $q->p('Something went wrong');
   105         }
   100     }
   106 
   101 
   107     } elsif ($del) {
   102 } elsif (defined $p->{del} and $p->{del} ne '') {
   108 
   103 
   109         my @cmd = ( qw(sudo ius-dav-htuserdel -u), $user );
   104     my @cmd = ( qw(sudo ius-dav-htuserdel -u), $p->{user} );
   110         print $q->hr, $q->p('Something went wrong') if system @cmd;
   105     print $q->hr, $q->p('Something went wrong') if system @cmd;
   111 
       
   112     } else {
       
   113 
       
   114         # should not happen
       
   115         print $q->hr, $q->('Something went wrong');
       
   116 
       
   117     }
       
   118 
   106 
   119 }
   107 }
   120 
   108 
   121 print $q->hr, $q->end_html;
   109 print $q->hr, $q->end_html;