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 my $title = 'Befristete WebDAV Zugänge einrichten'; |
|
42 |
|
43 print $q->header( -charset => 'UTF-8' ); |
|
44 print $q->start_html( |
|
45 -title => $title, |
|
46 -style => { -code => $css }, |
|
47 -onload => q{document.forms['passwd'].elements['user'].focus();} |
|
48 ), |
|
49 $q->h3( { -id => 'header' }, $title ), |
|
50 $q->hr; |
|
51 |
|
52 my $p; |
|
53 $p->{$_} = $q->param($_) for qw(user expiry add del); |
|
54 |
|
55 print $q->start_form( -id => 'passwd' ), |
|
56 $q->table( |
|
57 $q->Tr( $q->td('Nutzername'), $q->td( $q->textfield('user') ) ), |
|
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( { -name => 'add', -value => 'Anlegen' } ) ), |
|
64 $q->td( $q->submit( { -name => 'del', -value => 'Löschen' } ) ) |
|
65 ) |
|
66 ), |
|
67 $q->end_form; |
|
68 |
|
69 my $doit = 0; |
|
70 |
|
71 my $conf = readconfig or die "Can't readconfig"; |
|
72 |
|
73 if ( defined $p->{add} and $p->{add} ne '' ) { |
|
74 |
|
75 print $q->hr; |
|
76 my @cmd = ( qw(sudo ius-dav-htuseradd -u), $p->{user} ); |
|
77 push @cmd, '-e', $p->{expiry} |
|
78 if defined $p->{expiry} and $p->{expiry} ne ''; |
|
79 |
|
80 if ( my $pass = qx(@cmd) ) { |
|
81 |
|
82 my $url = "$conf->{dav_base_remote}/$p->{user}"; |
|
83 |
|
84 chomp $pass; |
|
85 |
|
86 print $q->table( |
|
87 $q->Tr( |
|
88 $q->td('Url:'), $q->td( $q->a( { -href => $url }, $url ) ) |
|
89 ), |
|
90 $q->Tr( $q->td('Passwort:'), $q->td($pass) ) |
|
91 ); |
|
92 |
|
93 } |
|
94 else { |
|
95 print $q->p('Something went wrong'); |
|
96 } |
|
97 |
|
98 } |
|
99 elsif ( defined $p->{del} and $p->{del} ne '' ) { |
|
100 |
|
101 my @cmd = ( qw(sudo ius-dav-htuserdel -u), $p->{user} ); |
|
102 print $q->hr, $q->p('Something went wrong') if system @cmd; |
|
103 |
|
104 } |
|
105 |
|
106 print $q->hr, $q->end_html; |
|