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['add'].elements['user'].focus();} |
46 -onload => q{document.forms['passwd'].elements['user'].focus();} |
47 ), $q->h3({ -id => 'header' }, 'Befristeten WebDAV Zugang einrichten'), $q->hr; |
47 ), $q->h3({ -id => 'header' }, 'Befristete WebDAV Zugänge einrichten'), $q->hr; |
48 |
48 |
49 my ( $user, $pass, $expiry ) = |
49 my ( $user, $pass, $expiry ) = |
50 ( $q->param('user'), $q->param('pass'), $q->param('expiry') ); |
50 ( $q->param('user'), $q->param('pass'), $q->param('expiry') ); |
51 |
51 |
52 print $q->start_form(-id => 'add'), |
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'), |
56 $q->td($q->textfield('user')) |
56 $q->td($q->textfield('user')) |
57 ), |
57 ), |
58 $q->Tr( |
58 $q->Tr( |
59 $q->td('Gültigkeitsdauer in Tagen (default: 1)'), |
59 $q->td('Gültigkeitsdauer in Tagen (default: 1)'), |
60 $q->td($q->textfield('expiry')) |
60 $q->td($q->textfield('expiry')) |
61 ), |
61 ), |
62 $q->Tr( |
62 $q->Tr( |
63 $q->td($q->submit('Anlegen')) |
63 $q->td($q->submit({ -name => 'add', -value => 'Anlegen' })), |
|
64 $q->td($q->submit({ -name => 'del', -value => 'Löschen' })) |
64 ) |
65 ) |
65 ), |
66 ), |
66 $q->end_form; |
67 $q->end_form; |
67 |
68 |
68 my $doit = 0; |
69 my $doit = 0; |
69 for ($user, $pass, $expiry) { $doit = 1 and last if defined and $_ ne ''; } |
70 for ($user, $pass, $expiry) { $doit = 1 and last if defined and $_ ne ''; } |
70 |
71 |
71 if ($doit) { |
72 if ($doit) { |
72 |
73 |
73 my $conf = readconfig or die "Can't readconfig"; |
74 my $conf = readconfig or die "Can't readconfig"; |
74 my @cmd = ( qw(sudo ius-dav-htuseradd -u), $user ); |
75 my $add = $q->param('add'); |
75 push @cmd, '-e', $expiry if defined $expiry and $expiry ne ''; |
76 my $del = $q->param('del'); |
76 |
77 |
77 print $q->hr; |
78 if ($add) { |
78 if ( my $pass = qx(@cmd) ) { |
|
79 |
79 |
80 my $url = "$conf->{dav_base_remote}/$user"; |
80 print $q->hr; |
|
81 my @cmd = ( qw(sudo ius-dav-htuseradd -u), $user ); |
|
82 push @cmd, '-e', $expiry if defined $expiry and $expiry ne ''; |
81 |
83 |
82 chomp $pass; |
84 if ( my $pass = qx(@cmd) ) { |
83 |
85 |
84 print $q->table( |
86 my $url = "$conf->{dav_base_remote}/$user"; |
85 $q->Tr( |
87 |
86 $q->td('Url:'), |
88 chomp $pass; |
87 $q->td($q->a({ -href => $url }, $url)) |
89 |
88 ), |
90 print $q->table( |
89 $q->Tr( |
91 $q->Tr( |
90 $q->td('Passwort:'), |
92 $q->td('Url:'), |
91 $q->td($pass) |
93 $q->td($q->a({ -href => $url }, $url)) |
92 ) |
94 ), |
93 ) |
95 $q->Tr( |
94 } |
96 $q->td('Passwort:'), |
95 else { |
97 $q->td($pass) |
96 print $q->p('Something went wrong'); |
98 ) |
|
99 ); |
|
100 |
|
101 |
|
102 } |
|
103 else { |
|
104 print $q->p('Something went wrong'); |
|
105 } |
|
106 |
|
107 } elsif ($del) { |
|
108 |
|
109 my @cmd = ( qw(sudo ius-dav-htuserdel -u), $user ); |
|
110 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 |
97 } |
117 } |
98 |
118 |
99 } |
119 } |
100 |
120 |
101 print $q->hr, $q->end_html; |
121 print $q->hr, $q->end_html; |