#!/bin/bash customize_file () { if [ -f "$1" ]; then cp $1 $1.$$ sed "s/VIRTUAL_DOMAIN_NAME/$VIRTHOST/g" < $1 > $1.$$ mv $1.$$ $1 fi } #this function is called to create the virtual domain's root directory #and make sure the files contain the right data. # setup_directory(){ if [ "$SHELLACCESS" != "y" ]; then cd "/var/www/docs/$VIRTHOST/" rm .* 2>/dev/null fi cp -r /etc/ftp_skel/* "/var/www/docs/$VIRTHOST" cp -r /etc/cgi_skel "/var/www/docs/$VIRTHOST/cgi-bin" mkdir "/var/www/docs/$VIRTHOST/web" cp -r /etc/www_skel/* "/var/www/docs/$VIRTHOST/web" for FILE in `find /var/www/docs/$VIRTHOST/web -name "*" -print`; do customize_file $FILE done chown -R ${DOMUSER}.www-data /var/www/docs/$VIRTHOST/web chmod a+rx /var/www/docs/$VIRTHOST/web chmod -R a+r /var/www/docs/$VIRTHOST/web chmod -R a+rx /var/www/docs/$VIRTHOST/cgi-bin chmod -R a+x /var/www/docs/$VIRTHOST/bin chmod -R a+r /var/www/docs/$VIRTHOST/etc chmod a+x /var/www/docs/$VIRTHOST/etc chmod a+x /var/www/docs/$VIRTHOST/lib chmod a+rx /var/www/docs/$VIRTHOST/lib/* for FILE in `find /var/www/docs/$VIRTHOST/cgi-bin -name "*" -print`; do customize_file $FILE done chown -R ${DOMUSER}.www-data /var/www/docs/$VIRTHOST/cgi-bin for FILE in `find /var/www/docs/$VIRTHOST/cgi-bin -name "*" -print`; do customize_file $FILE done chown -R ${DOMUSER}.www-data /var/www/docs/$VIRTHOST/cgi-bin } #THE BEGINING OF THE MATTER clear echo " You will now be interactivly prompted for the information needed" echo "to establish a domain web account." echo echo "You will be asked two questions, the hostname of the web server" echo "and the user ID to associate with the hostname." echo "Please specify the fully qualified host name, I.E. www.domain.com," echo "or: webserver.customerdomain.root" echo echo "NOTE: THE DNS Must be set up for your host/domain before running." echo echo echo -n "Please enter hostname for virtual web server: " read VIRTHOST clear echo echo echo " The user ID can be any eight character name which begins with a" echo "letter. This is NOT an email address." echo echo -n "Please enter user ID: " read DOMUSER #Initial Setup CURENTHIGHDUMMY=`tail -1 /etc/init.d/virthosts| tr ':' ' ' | awk '{print($3)}'` DUMMY=`echo "$CURENTHIGHDUMMY + 1" | bc` DATE=`date` echo $DUMMY $DATE #verify the data HOSTACTIVE=`host $VIRTHOST 2>&1 | grep "A record not found" | awk '{print($3)}'` if [ "$HOSTACTIVE" == "record" ]; then HOSTACTIVE="Authoritative" else HOSTACTIVE=`host $VIRTHOST 2>&1 | grep Authoritative |tr '(' ' '| awk '{print($5)}'` fi if [ "$HOSTACTIVE" == "Authoritative" ];then VIRTDOM=`echo $VIRTHOST | tr '.' ' ' | awk '{print($2"."$3)}'` whois $VIRTDOM if [ -f /root/doDNS ]; then echo -n "Is this the correct domain? [N/y]: " read YESNO if [ "$YESNO" == "y" ]; then /root/doDNS $VIRTDOM else echo "OK, I'm gonna leave so you can figure out what to do..." exit fi else echo "You don't have the DNS set up, and you don't have any automatic" echo " way for me to set it up... So I'm bailing out here." echo " If you create a script in the /root directory called doDNS" echo " that takes an argument of the domain to create, I would have" echo " gone ahead and ran it to try to create the domain." echo " If DNS is on this machine, that script should be very easy to write" echo " If DNS is on another machine, and you are familiar with expect, you" echo " can write an expect script that logs into your DNS server and" echo " does the configuration for you." exit fi IPADDR=`host $VIRTHOST| awk '{print($3)}'` clear echo echo "OK, the host you specified has the IP address: $IPADDR" echo echo -n Is this the proper IP address [y/N] read CHOICE if [ "$CHOICE" != "y" ];then echo "OK, Exiting..." exit 1 fi if [ "`grep "^$DOMUSER:" /etc/passwd`" == "" ]; then clear echo -n "The user ID you specified does not exist, so we will now create it." sleep 1 echo -n . sleep 1 echo . adduser --home /var/www/docs/$VIRTHOST $DOMUSER clear echo echo "User quota defaulting to 10MB with 15MB grace." echo -n " Edit [N/y]: " read EDITQUOTA if [ "$EDITQUOTA" == "y" ]; then edquota $DOMUSER fi echo echo -n "Should user have shell access? [N/y]: " read SHELLACCESS if [ "$SHELLACCESS" != "y" ]; then chsh -s /bin/NoShell $DOMUSER fi fi sleep 3 setup_directory ifconfig eth0:$DUMMY $VIRTHOST echo "ifconfig eth0:$DUMMY $VIRTHOST" >>/etc/init.d/virthosts cat << eof >> /etc/apache/httpd.conf ##### START $VIRTHOST -- $DOMUSER ###### ##### CREATED: $DATE $USER ServerAdmin $DOMUSER@$VIRTHOST DocumentRoot /var/www/docs/$VIRTHOST/web ServerName $VIRTHOST ErrorLog logs/virtdomains/${VIRTHOST}-error_log TransferLog logs/virtdomains/${VIRTHOST}-transfer_log ScriptAlias /cgi-bin/ /var/www/docs/$VIRTHOST/cgi-bin/ ##### END $VIRTHOST -- $DOMUSER ######### eof killall -HUP apache clear echo echo "The virtual web page has been set up." echo "The following information should be written down and filed." echo "The customer may wish to keep a copy of this information for thier records" echo "================================================================================" finger $DOMUSER echo "--------------------------------------------------------------------------------" quota $DOMUSER echo "================================================================================" host $VIRTHOST VIRTDOM=`echo $VIRTHOST|tr '.' ' '| awk '{print($2"."$3)}'` host -t mx $VIRTDOM echo "================================================================================"