#============================================================================# # vHost - one-step solution for all virtual hosting needs # # V10apache - apache virtualization module # # # # Copyright(c) Chaogic Systems, LLC. http://chaogic.com # # Author: Jake Fan # # # # This is Free Software; permission to use, copy, modify, and distribute # # this software and its documentation for any purpose - with or without fee # # - is hereby granted, provided that the above copyright information and # # this permission notice appear in all copies and documentations. This # # software is provided "as is" without express or implied warranty. For # # more details, see GNU General Public License as published by the Free # # Software Foundation. # # # #============================================================================# $X eq "configuration" && do { ################################################ ### EDITABLE CONFIGURATIONS ################################################## ### web root directory name on virtual hosts. usually contains virtual host # url root and "cgi-bin" (see $urlDir and $cgiDir below). will be created # under "var/". # $webDir = "www"; $webDir = "www"; ### url directory name on virtual hosts. the directory under $webDir which # corresponds to virtual host url root ("http://virtual.host.name"). # $urlDir = "html"; $urlDir = "html"; ### cgi directory name on virtual hosts. the directory under $webDir which # contains cgi scripts. # $cgiDir = "cgi-bin"; $cgiDir = "cgi-bin"; ### gui directory name on virtual hosts. the directory under $urlDir which # contains the vhost web gui. # $guiDir = "admin"; $guiDir = "admin"; ### public html directory name under virtual users' home directories. the # directory which corresponds to url "http://virtual.host.name/~user". # must be different than $urlDir. # $usrDir = "public_html"; $usrDir = "public_html"; ### html document root on the main host. when left blank, it will be # retrieved from $apacheCf. # $docRoot = ""; $docRoot = ""; ### the user which apache runs as. when left blank, it will be retrieved from # $apacheCf. # $webUser = ""; $webUser = ""; ### apache configuration file. # $apacheCf = "/etc/httpd/conf/httpd.conf"; $apacheCf = "/etc/httpd/conf/httpd.conf"; ### apache reload command sequence. separate multiple commands with shell # meta characters such as "|", ";", "||", "&&", etc. leave blank if invoked # by inetd. # $apacheRc = "/etc/rc.d/init.d/httpd reload"; $apacheRc = "/etc/rc.d/init.d/httpd reload"; ### $apacheCf virtual host configuration. vhost will replace "[HOST_NAME]", # "[OWNER_NAME]", and "[IP_ADDRESS]" with actual values. variables found # in "./V00hostconf" will also be expanded. # $apacheC = <<"---eoc---eoc---eoc---"; $apacheC = <<"---eoc---eoc---eoc---"; ServerName [HOST_NAME] ServerAlias www.[HOST_NAME] mail.[HOST_NAME] ServerAdmin $ADMIN@[HOST_NAME] DocumentRoot $VHOME/[HOST_NAME]/var/$webDir/$urlDir ScriptAlias /$cgiDir/ $VHOME/[HOST_NAME]/var/$webDir/$cgiDir/ UserDir $VHOME/[HOST_NAME]/home/*/$usrDir CustomLog $VHOME/[HOST_NAME]/var/log/access_log combined ErrorLog $VHOME/[HOST_NAME]/var/log/error_log Options IncludesNoExec Indexes MultiViews SymLinksIfOwnerMatch SetHandler default-handler ---eoc---eoc---eoc--- ### $apacheCf virtual host alias configuration. vhost will replace # "[HOST_NAME]", "[HOST_ALIAS]", "[OWNER_NAME]", and "[IP_ADDRESS]" with # actual values. variables found in "./V00hostconf" will also be expanded. # $apacheA = <<"---eoc---eoc---eoc---"; $apacheA = <<"---eoc---eoc---eoc---"; ServerName [HOST_ALIAS] ServerAlias www.[HOST_ALIAS] Redirect / http://[HOST_NAME]/ ---eoc---eoc---eoc--- ### DO NOT TOUCH ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!! ### SanityChecking ########################################################### /^\s*DocumentRoot[\s"']+([^\s"']+)/i && ($docRoot ||= $1), /^\s*User[\s"']+([^\s"']+)/i && ($webUser ||= $1) for !($docRoot && $webUser) && Cat $apacheCf; $ERR = 1, Error "$MOD: \$webDir = '$webDir'" if !CheckN $webDir; $ERR = 1, Error "$MOD: \$urlDir = '$urlDir'" if !CheckN $urlDir; $ERR = 1, Error "$MOD: \$cgiDir = '$cgiDir'" if !CheckN $cgiDir; $ERR = 1, Error "$MOD: \$guiDir = '$guiDir'" if !CheckN $guiDir; $ERR = 1, Error "$MOD: \$usrDir = '$usrDir'" if $usrDir eq $urlDir || !CheckN $usrDir; $ERR = 1, Error "$MOD: \$docRoot = '$docRoot'" if !-d $docRoot || $docRoot =~ /^\Q$VHOME\E\/[^\/]+\/(var|home)\/www\/html/; $ERR = 1, Error "$MOD: \$webUser = '$webUser'" if !getpwnam $webUser; $ERR = 1, Error "$MOD: \$apacheCf = '$apacheCf'" if !-f $apacheCf; $ERR = 1, Error "$MOD: \$apacheRc = '$apacheRc'" if $apacheRc && ($apacheRc !~ /^\// || !-x (split /[\s|&;]+/, $apacheRc)[0]); }; $X eq "initialization" && do { ############################################### if ($ONCFG) { `chown 0:$GHID $apacheCf $NERR` if !-o $apacheCf; `chmod 0600 $apacheCf $NERR` if ((stat $apacheCf)[2] & 07777) != 0600; GroupAdd $webUser; my $i; Flock $apacheCf, "+<", 0 if !grep /^\s*]/i, Cat $apacheCf; BackupCf $apacheCf; /^\s*$HEAD/ && (!$i || $FILE[$i-1] !~ /^\s*$/? $_ = "\n$_" : $i--, last), $i++ for @FILE; $FILE[$i] = ($i && "\n" || "")."\n\tOptions SymLinksIfOwnerMatch\n\tAllow from all\n\n$FILE[$i]"; print FILE @FILE; Flock 0; } `cp -Rp /usr/local/vhost/vhost.web/. $docRoot/$guiDir $NERR`, `cp -Rp /usr/local/vhost/src/phpWebFTP $docRoot/$guiDir $NERR`, `rm -r $docRoot/$guiDir/webftp $NERR`, `ln -s $docRoot/$guiDir/phpWebFTP $docRoot/$guiDir/webftp $NERR`, `rm /tmp/.vhost/.ins.webgui $NERR` if !-e "$docRoot/$guiDir/webftp" || -f "/tmp/.vhost/.ins.webgui"; Error5 "'$U' is a system user" if $ARGV[0] eq "deluser" && $U eq $webDir && $VPWD{$U}; }; $X eq "addhost" && do { ###################################################### `touch $VHOME/$H/var/log/access_log $NERR`; `touch $VHOME/$H/var/log/error_log $NERR`; `mkdir $VHOME/$H/var/$webDir $NERR`; `mkdir $VHOME/$H/var/$webDir/$urlDir $NERR`; `mkdir $VHOME/$H/var/$webDir/$cgiDir $NERR`; `touch $VHOME/$H/var/$webDir/$cgiDir/index.html $NERR`; `rm -r $VHOME/$H/var/$webDir/$urlDir/$guiDir $NERR`; `ln -s $docRoot/$guiDir $VHOME/$H/var/$webDir/$urlDir/$guiDir $NERR`; `mkdir $VHOME/home/$O/$usrDir $NERR`; `chown $O[2]:$GUID $VHOME/home/$O/$usrDir $NERR`; `cp -Rp $VHOME/$H/home/$webDir/. $VHOME/$H/var/$webDir $NERR`; `rm -r $VHOME/$H/home/$webDir $NERR`; `ln -s ../var/$webDir $VHOME/$H/home/$webDir $NERR`; my ($ok, $i, $j); my $ip = $apacheC !~ /^\s*\s*$'; Flock $apacheCf, "+<", 0 if $ip && !grep /^\s*NameVirtualHost[\s"']+\Q$ip\E[\s"':]/i, Cat $apacheCf; $ok && ($j = $i), !/^\s*#/ && ($ok = 0), /\bNameVirtualHost\b/i && ($ok = 1), $i++ for @FILE; $FILE[($j||$i||1)-1] .= "NameVirtualHost $ip\n"; print FILE @FILE; Flock 0; Flock "$VHOME/$H/var/$webDir/$urlDir/index.html", ">>", 2 if !`ls $VHOME/$H/var/$webDir/$urlDir/index.* $NERR`; print FILE "
$H
\n"; print FILE "
Created by vHost, $date
\n"; Flock 0; Flock "$VHOME/$H/home/$O/$usrDir/index.html", ">>", 2 if !`ls $VHOME/$H/home/$O/$usrDir/index.* $NERR`; print FILE "Home of $O\@$H\n"; Flock 0; ReloadRc 0; }; $X eq "delhost" && do { ###################################################### DelConf $apacheCf, $apacheC if $_d; Flock $apacheCf, "+<", 0 if !grep /^\s*]/i, Cat $apacheCf; s/^\s*NameVirtualHost[\s"']+\Q$I\E[\s"']*$//is for @FILE; print FILE @FILE; Flock 0; ReloadRc 0 if $_d; }; $X eq "addhali" && do { ###################################################### $apacheA =~ s/\[HOST_NAME\]/$H/g; $apacheA =~ s/\[HOST_ALIAS\]/$A/g; $apacheA =~ s/\[OWNER_NAME\]/$O/g; $apacheA =~ s/\[IP_ADDRESS\]/$HOST{$H}/g; my $ok; Flock $apacheCf, "+<", 0; $ok = $ok || /^\s*# \Q$H\E $SIGN/, $ok && s/^(\s*$FOOT)/$apacheA$1/ && last for @FILE; print FILE @FILE if !grep /^\s*ServerName[\s"']+\Q$A\E[\s"']*$/i, @FILE; Flock 0; ReloadRc 0; }; $X eq "delhali" && do { ###################################################### my ($ok, $i, $j); Flock $apacheCf, "+<", 0; $ok = $ok || /^\s*ServerName[\s"']+\Q$A\E[\s"']*$/i, $ok && /^\s*<\/VirtualHost\b/i && last, /^\s*>", 2 if !`ls $VHOME/$H/home/$U/$usrDir/index.* $NERR` && $QHOST{$H}; print FILE "Home of $U\@$H\n"; Flock 0; }; $X eq "reload" && do { ####################################################### ReloadRc 0 if $_f && $USER eq "root"; }; $X eq "uninstall" && do { #################################################### `rm -r $docRoot/$guiDir/vhost.* $NERR`; Flock "$docRoot/$guiDir/vhost.php", ">", 0; print FILE "Please reinstall vHost.\n"; Flock 0; }; $X eq "finalization" && do { ################################################# if ($ARGV[0] eq "addhost" || $ARGV[0] eq "adduser" && $U eq $webDir) { `chown -h $O[2]:$GUID $VHOME/$H/home/$webDir $NERR`; `chown -h 0:$GUID $VHOME/$H/var/$webDir/$urlDir/$guiDir $NERR`; `chcon -Rht user_home_t $VHOME/home/$O/$usrDir $NERR`; } ReloadRc $apacheRc if !$_q && $ARGV[0] =~ /^(addhost|delhost|addhali|delhali|reload)$/; }; 1;