[vox-tech] script for adding virtual domain to web/mail server

Tim Riley timriley at appahost.com
Fri Feb 24 09:52:39 PST 2006




---------- Original Message ----------------------------------
From: "Nick Schmalenberger" <nschmalenberger at fastmail.fm>
Reply-To: "lugod's technical discussion forum" <vox-tech at lists.lugod.org>
Date:  Fri, 24 Feb 2006 03:37:32 -0800

>list,
>I have written this script for adding a virtual domain to a web/mail
>server and I'd like some comments or suggestions.

This is a keeper. Thanks! Some comments:
Assign $1, $2, etc. to clear variable names. ($2 is assigned
to USERWEBROOT, but then $2 is referenced in the code.)
By the way, what is a "user web root"?

"/var/log/apache2" is probably an Apache variable that
can be changed in "/etc/apache/httpd.conf". Therefore,
it should be a constant in this script, in case it changes.

Hope that helps.

I have a question: What is the "user" when a virtual domain
is added to your system?

>
>
>#!/bin/sh
>
>if (($#==0)); then echo -e "Usage: vdomadd USERNAME DOMAIN
>[PASSWORD]\nIf password field is 'auto', password will be generated, if
>no argument is given login will be disabled, else PASSWORD will be set
>as the parameter. If set, the user password is also the postmaster
>password for that domain."; exit; fi
>
>USERDIRS=home
>USERWEBROOT=$2
>
>if grep $1 /etc/passwd > /dev/null ; then echo -e "Invalid, user
>exists."; else
># makes the new account and user web directory
>adduser --disabled-login $1
>if (($#==3)) 
>        if expr $3 : auto; then newpw=`pwgen`
>        else newpw=$3
>        echo "$1's password is: $newpw"
>        echo "$1:$newpw" | chpasswd
>else echo "Password parameter blank, login disabled."
>mkdir /$USERDIRS/$1/$USERWEBROOT
>chown -R $1:$1 /$USERDIRS/$1
>
>#adds new line to /etc/hosts
>echo -e "`getip.pl` $2 www.$2 mail.$2" >> /etc/hosts
>
># makes the apache virtual domain file
>echo -e "#virtual domain configuration for $1
><VirtualHost www.$2>
>ServerName www.$2
>ServerAlias $2
>DocumentRoot /$USERDIRS/$1/$USERWEBROOT/
>TransferLog /var/log/apache2/$2/www/access.log
>LogFormat combined
></VirtualHost>
>
><VirtualHost mail.$2>
>ServerName mail.$2
>DocumentRoot /usr/share/squirrelmail/
>TransferLog /var/log/apache2/$2/mail/access.log
>LogFormat combined
></VirtualHost>
>" > /etc/apache2/sites-available/$2
>mkdir /var/log/apache2/$2/www/
>mkdir /var/log/apache2/$2/mail/
>a2ensite $2
>/etc/init.d/apache2 reload
>
>touch /var/log/apache2/$2/www/access.log.0
>mkdir /$USERDIRS/$1/$USERWEBROOT/stats/
># makes the webalizer configuration file
>echo -e "#webalizer configuration for $2 virtual domain
>LogFile /var/log/apache2/$2/www/access.log.0
>OutputDir /$USERDIRS/$1/$USERWEBROOT/stats/
>Hostname www.$2
>" > /etc/webalizer.d/$2.conf
>
># adds domain to qmail
>/home/vpopmail/bin/vadddomain $2 $newpw
>
>fi
>
>
>Thanks,
>Nick
>
>-- 
>http://www.fastmail.fm - IMAP accessible web-mail
>
>_______________________________________________
>vox-tech mailing list
>vox-tech at lists.lugod.org
>http://lists.lugod.org/mailman/listinfo/vox-tech
>
 


More information about the vox-tech mailing list