diff -r e0e126b7f06d -r fee44892ca1e cgi-bin/ius-dav-htuseradd.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/ius-dav-htuseradd.cgi Tue Jul 19 09:08:12 2011 +0200 @@ -0,0 +1,105 @@ +#!/usr/bin/perl + +# Copyright (C) 2011 Matthias Förste +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Matthias Förste + +use warnings; + +# Using CGI::Fast will result in an Internal Server Error because we are +# restarting apache when everything else works +# use CGI::Fast; +use CGI; +use Ius::Dav::Htpasswd qw(mkpasswd readconfig useradd); + +my $css = <header( -charset => 'UTF-8' ); +print $q->start_html( + -title => $0, + -style => { -code => $css }, + -onload => q{document.forms['passwd'].elements['user'].focus();} + ), + $q->h3( { -id => 'header' }, 'Befristete WebDAV Zugänge einrichten' ), + $q->hr; + +my $p; +$p->{$_} = $q->param($_) for qw(user expiry add del); + +print $q->start_form( -id => 'passwd' ), + $q->table( + $q->Tr( $q->td('Nutzername'), $q->td( $q->textfield('user') ) ), + $q->Tr( + $q->td('Gültigkeitsdauer in Tagen (default: 1)'), + $q->td( $q->textfield('expiry') ) + ), + $q->Tr( + $q->td( $q->submit( { -name => 'add', -value => 'Anlegen' } ) ), + $q->td( $q->submit( { -name => 'del', -value => 'Löschen' } ) ) + ) + ), + $q->end_form; + +my $doit = 0; + +my $conf = readconfig or die "Can't readconfig"; + +if ( defined $p->{add} and $p->{add} ne '' ) { + + print $q->hr; + my @cmd = ( qw(sudo ius-dav-htuseradd -u), $p->{user} ); + push @cmd, '-e', $p->{expiry} + if defined $p->{expiry} and $p->{expiry} ne ''; + + if ( my $pass = qx(@cmd) ) { + + my $url = "$conf->{dav_base_remote}/$p->{user}"; + + chomp $pass; + + print $q->table( + $q->Tr( + $q->td('Url:'), $q->td( $q->a( { -href => $url }, $url ) ) + ), + $q->Tr( $q->td('Passwort:'), $q->td($pass) ) + ); + + } + else { + print $q->p('Something went wrong'); + } + +} +elsif ( defined $p->{del} and $p->{del} ne '' ) { + + my @cmd = ( qw(sudo ius-dav-htuserdel -u), $p->{user} ); + print $q->hr, $q->p('Something went wrong') if system @cmd; + +} + +print $q->hr, $q->end_html;