de:sysadmin:tools:apache

Apache: Download für generierte User, Upload mit Webdav (Stand ≤ 2013)

<VirtualHost *:80>
        ServerName upload.example.org
        DocumentRoot /var/www/server/download/docs
        #DirectoryIndex index.html index.php
        AddDefaultCharset utf-8
 
        DavLockDB /tmp/davLock_upload
 
        AddDefaultCharset utf-8
        <Location />
                DAV On
                Options FollowSymLinks
                AuthType Basic
                AuthName "Example Download Webdav Account (for Upload)"
                AuthUserFile ../www01/conf/apache/.passwd_upload
                Require valid-user
 
                # download von php-scripten
                ForceType text/plain
        </Location>
</VirtualHost>
<VirtualHost *:80>
        ServerName download.example.org
        DocumentRoot /var/www/server/download/docs
        DirectoryIndex index.php
        AddDefaultCharset utf-8
 
        Include ../www01/conf/apache/download_locations.conf
</VirtualHost>
#!/bin/bash
# /usr/local/bin/create-download-user
 
rechner=`hostname`
baseusername=kunde
pwfile=/var/www/server/www01/conf/apache/.passwd_download
basedir=/var/www/server/download/docs
location=/var/www/server/www01/conf/apache/download_locations.conf
apacheuser=wwwrun
apachegroup=wwwrun
baseurl="http://download.example.org/"
empfaenger=sysadmin@example.org
mailsubject="Passwoerter fuer download.example.org"
 
function pwcreate {
        pw=`pwgen -B -1 10`
}
 
function usercreate {
        user=`printf "$baseusername%04d" $n`
}
 
function locationcreate {
cat >> $location << _EOF_
<Location /$user/>
                AuthType Basic
                AuthName "$user"
                AuthUserFile ../www01/conf/apache/.passwd_download
                Require user $user
</Location>
_EOF_
 
mkdir -p $basedir/$user
 
ln -s $basedir/index.php $basedir/$user/index.php
 
cat > $basedir/$user/test.txt << _EOF2_
Welcome on this download-server as $user
 
This life is a test.  It is only a test.  Had this been an actual life
you would have received further instructions as to what to do and where to go
 
_EOF2_
 
chown -R $apacheuser:$apachegroup $basedir/$user
 
}
 
pwsammler=""
 
# gibt es die passwort-datei?
if [[ ! -f $pwfile ]]; then
        # nein? -> dann anlegen und ersten user anlegen
        pwcreate
        n=1
        usercreate
        locationcreate
        pwsammler="${pwsammler}${user};${pw};${baseurl}${user}\n"
        htpasswd -c -b $pwfile $user $pw 
fi
 
# suche nummer von letztem user
lastusernumber=`grep $baseusername $pwfile | tail -1 | sed "s/$baseusername//;s/:.*//"`
 
# weil das bei fuehrenden nullen als oktal interpretiert wird, erstmal wieder
# auf basis 10 bringen
lastusernumber=$((10#$lastusernumber))
 
for (( n=$((lastusernumber+1)); n<=$((lastusernumber+19)); n++ )); do
        pwcreate
        usercreate
        locationcreate
        #echo $user $pw
        pwsammler="${pwsammler}${user};${pw};${baseurl}${user}\n"
        htpasswd -b $pwfile $user $pw 
        # benutzer-verzeichnis anlegen + location-directive ergaenzen
done
 
echo "-------------------"
 
printf "Angelegte User mit Passwort und URL \n"
printf "$pwsammler"
printf "\nDie Liste wird auch als CSV an $empfaenger geschickt \n\n"
 
body="
Hier die neuen User fuer download.example.org
 
Beste Gruesse vom Script
 
$0 auf $rechner
 
"
 
(printf "%s\n%s\n" "$body" ; printf $pwsammler | uuencode download_example_org.csv ) |mailx -s "$mailsubject" $empfaenger
 
# ende
de/sysadmin/tools/apache.txt · Zuletzt geändert: 2019-09-28 09:44 von hella

Seiten-Werkzeuge