#============================================================================# # vHost - one-step solution for all virtual hosting needs # # vmake - install/upgrade 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. # # # #============================================================================# ### install ################################################################## sub ToErr { print STDERR $_[0]; } sub ExOut { my $cmd = $_[0]; print "$cmd\n"; open FILE, ">> /tmp/.vhost/install.log" if !$_[1]; print FILE "$cmd\n"; close FILE; $cmd =~ s/(\s\|\||\s&&|;|$)/ 2>&1$1/g; system $cmd; } @new = split /r/, (split /\s+/, $VERSION)[1]; @old = split /r/, (split /\s+/, `/usr/sbin/vhost -v $NERR`)[1]; $new = $new[0] * 10000 + $new[1], $new = "$new"; $old = $old[0] * 10000 + $old[1], $old = "$old"; $cur = 33001; $pwd = (`pwd $NERR` =~ /(.*)/)[0]; $ERR = 1, Error "missing './vhost.cc'" if !-f "vhost.cc"; $ERR = 1, Error "missing './vhost.d'" if !-d "vhost.d"; $ERR = 1, Error "missing './vhost.pl'" if !-f "vhost.pl"; $ERR = 1, Error "missing './vhost.web'" if !-d "vhost.web"; $ERR && exit 1; ExOut "test -f vhost && rm vhost", 1 if $_d && $pwd ne "/usr/local/vhost"; ExOut "cd src/vmail && make clean", 1 if $_d && $pwd ne "/usr/local/vhost"; ExOut "cd src/Quota && test -f Makefile && make clean", 1 if $_d && $pwd ne "/usr/local/vhost"; ExOut "cd src/IO-Tty && test -f Makefile && make clean", 1 if $_d && $pwd ne "/usr/local/vhost"; $_d && exit 0; $rrc = 1 if $old < 30000; `rm -r /tmp/.vhost $NERR` if $old < 30000; `mkdir -p /tmp/.vhost $NERR`; `mkdir -p $SKEL $NERR`; `chown 0:$GHID /tmp/.vhost $NERR`; `chown 0:$GHID $SKEL $NERR`; `chmod 0710 /tmp/.vhost $NERR`; `chmod 0755 $SKEL $NERR`; `echo >>/tmp/.vhost/install.log $NERR` if -f "/tmp/.vhost/install.log"; `echo "# [$pwd] - v$new[0]r$new[1], $DATE" >>/tmp/.vhost/install.log $NERR`; `touch /etc/vhosts $NERR` if !-e "/etc/vhosts"; `touch /etc/vusers $NERR` if !-e "/etc/vusers"; Flock "/etc/vhost.conf.old", ">>", 2 if $cf1 = -f "/etc/vhost.conf"; printf FILE "# [/etc/vhost.conf] - v%.2fr%d, %s\n", $old[0], $old[1], $DATE; /^#!\// && next, /^\s*### DON'T TOUCH ANYTHING/ && last, /^\s*(\w+)=["']*([^\s"']+)/ && eval "\$$1 = \"$2\";", print FILE for Cat "/etc/vhost.conf"; print FILE "\n"; Flock 0; Flock "/etc/vhost.conf.old", ">>", 2 if $cf2 = -f "/etc/vhost.d/proftpd"; printf FILE "# [/etc/vhost.d/proftpd] - v%.2fr%d, %s\n", $old[0], $old[1], $DATE; /^\s*(\w+)=["']*([^\s"']+)/ && eval "\$$1 = \"$2\";", print FILE for Cat "/etc/vhost.d/proftpd"; print FILE "\n"; Flock 0; ToErr "vhost: /etc/vhost.conf has been saved in /etc/vhost.conf.old\n" if $cf1; ToErr "vhost: /etc/vhost.d/proftpd has been saved in /etc/vhost.conf.old\n" if $cf2; for my $d (grep !-l && -f "$_/V00hostconf", keys %HOME) { `mv $d/V30imap $d/V30squirrelmail $NERR` if $old < $cur; `mv $d/X30imap $d/X30squirrelmail $NERR` if $old < $cur; `mv $d.old/V30imap $d.old/V30squirrelmail $NERR` if $old < $cur; `mv $d.old/X30imap $d.old/X30squirrelmail $NERR` if $old < $cur; `cp -Rp $d/. $d.old $NERR` if $cf3 = $_f || $old < $new; ToErr "vhost: $d has been copied to $d.old\n" if $cf3; } ToErr ("Press ENTER to continue... "), if $cf1 || $cf2 || $cf3; ToErr "\n" if $cf1 || $cf2 || $cf3; ToErr ("vhost: add the main host as virtual (recommended)? (0 = no, 1 = yes): "), chomp ($vMain = ) while $vMain !~ /^[01]$/ && !-f "/tmp/.vhost/.ins.vmain" && !-c "/etc/vdata/vusers.$HNAM"; $nProf = grep !-l && -f "$_/V00hostconf", keys %HOME; $nProf >= 2 && ToErr ("vhost: multiple profiles detected. reconfigure all? (0 = no, 1 = yes): "), $nProf == 1 && ToErr ("vhost: existing profile detected. reconfigure? (0 = no, 1 = yes): "), chomp ($nConf = ) while $nConf !~ /^[01]$/ && $nProf; if (!$nProf || $nConf) { ToErr ("vhost: enable auto ip aliasing? (0 = no, 1 = yes): "), chomp ($nNet = ) while $nNet !~ /^[01]$/; ToErr ("vhost: enable virtual web? (0 = no, 1 = apache): "), chomp ($nWeb = ) while $nWeb !~ /^[01]$/; ToErr ("vhost: enable virtual ftp? (0 = no, 1 = wu-ftpd, 2 = proftpd): "), chomp ($nFtp = ) while $nFtp !~ /^[012]$/; ToErr ("vhost: enable virtual mail? (0 = no, 1 = sendmail, 2 = postfix): "), chomp ($nMail = ) while $nMail !~ /^[012]$/; ToErr ("vhost: enable virtual pop3? (0 = no, 1 = yes): "), $nMail && chomp ($nPop3 = ) || ToErr ($nPop3 = 0) && ToErr "\n" while $nPop3 !~ /^[01]$/; ToErr ("vhost: enable virtual webmail? (0 = no, 1 = squirrelmail, 2 = openwebmail): "), $nMail && $nWeb && chomp ($nImap = ) || ToErr ($nImap = 0) && ToErr "\n" while $nImap !~ /^[012]$/; ToErr ("vhost: enable virtual webstats? (0 = no, 1 = webalizer, 2 = awstats): "), $nWeb && chomp ($nStats = ) || ToErr ($nStats = 0) && ToErr "\n" while $nStats !~ /^[012]$/; @V01network = (["V01network", "X01network"], ["X01network", "V01network"], $nNet); @V10apache = (["V10apache", "X10apache"], ["X10apache", "V10apache"], $nWeb); @V15wu_ftpd = (["V15wu-ftpd", "X15wu-ftpd", "V15wu-ftpd"], ["X15wu-ftpd", "V15wu-ftpd", "X15wu-ftpd"], $nFtp); @V15proftpd = (["V15proftpd", "V15proftpd", "X15proftpd"], ["X15proftpd", "X15proftpd", "V15proftpd"], $nFtp); @V20sendmail = (["V20sendmail", "X20sendmail", "V20sendmail"], ["X20sendmail", "V20sendmail", "X20sendmail"], $nMail); @V20postfix = (["V20postfix", "V20postfix", "X20postfix"], ["X20postfix", "X20postfix", "V20postfix"], $nMail); @V25pop3d = (["V25pop3d", "X25pop3d"], ["X25pop3d", "V25pop3d"], $nPop3); @V30squirrelmail = (["V30squirrelmail", "X30squirrelmail", "V30squirrelmail"], ["X30squirrelmail", "V30squirrelmail", "X30squirrelmail"], $nImap); @V30openwebmail = (["V30openwebmail", "V30openwebmail", "X30openwebmail"], ["X30openwebmail", "X30openwebmail", "V30openwebmail"], $nImap); @V35webalizer = (["V35webalizer", "X35webalizer", "V35webalizer"], ["X35webalizer", "V35webalizer", "X35webalizer"], $nStats); @V35awstats = (["V35awstats", "V35awstats", "X35awstats"], ["X35awstats", "X35awstats", "V35awstats"], $nStats); } @Xxx = ("X30openwebmail", "X40mysql"); ToErr "\n"; ToErr "vhost: installation ready to start\n"; ToErr ("Press ENTER to continue... "), ; ToErr "\n"; `touch /tmp/.vhost/.ins.vmain $NERR` if $vMain; if ($_f || $old < $cur) { ExOut "mkdir bin" if !-d "bin"; ExOut "test -f vhost || g++ -v -o vhost vhost.cc"; $ERR = 1, Error "installation failed" if $?; $ERR && exit 1; ExOut "cd src/vmail && make install"; $ERR = 1, Error "installation failed" if $? && !$_f; $ERR && exit 1; ExOut "cd src/Quota && (test -f Makefile || perl Makefile.PL) && make install"; $ERR = 1, Error "installation failed" if $?; $ERR && exit 1; ExOut "cd src/IO-Tty && (test -f Makefile || perl Makefile.PL) && make install"; $ERR = 1, Error "installation failed" if $?; $ERR && exit 1; print "\n"; ExOut "chmod 0755 bin/*"; ExOut "rm -r /usr/local/vhost" if -e "/usr/local/vhost" && $pwd ne "/usr/local/vhost" && (stat "/usr/local/vhost/vhost")[9] < (stat "vhost")[9] && $old < 0; } ExOut "cp -Rp . /usr/local/vhost"; ExOut "chown -Rh 0:$GHID /usr/local/vhost"; ExOut "rm /etc/vhost.d" if -f "/etc/vhost.d"; ExOut "mkdir /etc/vhost.d" if !-d "/etc/vhost.d"; { $val{'TLDs'} = $tld; $val{'NIC'} = $nic; $val{'VHOME'} = $vhome; $val{'HTEMP'} = $template; $val{'RUSER'} = $vroot; $val{'SHELL'} = $adminShell; $val{'CMDLOG'} = $logFile; $val{'ftpDir'} = $ftpDir; $val{'webDir'} = $webDir; $val{'cgiDir'} = $cgiDir; $val{'urlDir'} = $urlDir; $val{'guiDir'} = $guiDir; $val{'ftpRoot'} = $ftpRoot; $val{'apacheCf'} = $httpdCf; $val{'wu_ftpdCf'} = $ftpdCf; $val{'sendmailCf'} = $mailCf; $val{'dnsCf'} = $dnsCf; $val{'revZf'} = $revZf; $val{'inetdRc'} = $inetdSs && "$inetdSs reload"; $val{'apacheRc'} = $httpdSs && "$httpdSs reload"; $val{'wu_ftpdRc'} = $ftpdSs && "$ftpdSs reload"; $val{'sendmailRc'} = $mailSs && "$mailSs reload"; $val{'dnsRc'} = $dnsSs && "$dnsSs reload"; $val{'proftpdRc'} = $servSs && "$servSs reload"; $val{'proftpdCf'} = $servCf; } for my $d (!$nProf && "/etc/vhost.d" || grep !-l && -f "$_/V00hostconf", keys %HOME) { for my $f (split /\s+/, `ls vhost.d/ $NERR`) { $f =~ s/^V//; my $cf = $f; $cf =~ s/[.-]/_/g; my @cf = eval "\@V$cf;"; my $n = $cf[2]; ExOut "mv $d/$cf[0][$n] $d/$cf[1][$n]" if @cf && !-f "$d/$cf[1][$n]" && -f "$d/$cf[0][$n]"; my ($end, $key, $val); my $eoc = "---eoc---eoc---eoc---"; my $cf = @cf && "$d/$cf[1][$n]" || -f "$d/V$f" && "$d/V$f" || (-f "$d/X$f" || grep /^\QX$f\E$/, @Xxx) && "$d/X$f" || "$d/V$f"; ExOut "cp -p vhost.d/V$f $cf" if !-f $cf || $_f || $old < $new; /^\s*\$(\w+)\s*=\s*(<<\s*)?["'](.*)["']\s*;\s*$/, $2 && ($end = $3, $key = $1), $1 && ($$1 = !$2 && $3), /^\Q$end\E/ && $end && ($end = ""), !/\Q$end\E[\s"';]*$/ && $end && ($$key .= $_), /^\s*### DO NOT TOUCH ANYTHING/ && last for Cat -f "$d.old/V$f" && "$d.old/V$f" || -f "$d.old/X$f" && "$d.old/X$f"; { $val{'smRoot'} = $wmRoot; $popRelay = "1" if $popRelay =~ /^\//; $proftpdC =~ s/^(\s*DefaultRoot\s+~\s+)\$GROUP/$1vuser/im if $f eq "15proftpd"; } Flock $cf, "+<", 0 if -f $cf && ($_f || $old < $new); /^\s*\$(\w+)\s*=\s*(<<\s*)?["'](.*)["']\s*;\s*$/, $2 && ($end = $3), $key = $1, !defined ($val = $$1) && ($val = $val{$1}), /^\Q$end\E/ && $end && ($end = $_ = ""), !/\Q$end\E[\s"';]*$/ && $end && ($_ = ""), $val =~ /\n$/ && ($_ = "\$$key = <<\"$eoc\";\n$val$eoc\n"), $key && !defined $val && ($end = ""), $val !~ /\n$/ && defined $val && ($_ = "\$$key = \"$val\";\n"), /^\s*### DO NOT TOUCH ANYTHING/ && last for @FILE; print FILE @FILE; Flock 0; } ExOut "chown -Rh 0:$GHID $d" if $_f || $old < $new; ExOut "chmod 0600 $d/V40mysql" if -f "$d/V40mysql" && ((stat "$d/V40mysql")[2] & 07777) != 0600; ExOut "chmod 0600 $d/X40mysql" if -f "$d/X40mysql" && ((stat "$d/X40mysql")[2] & 07777) != 0600; } ### update ################################################################### if ($old < 30000) { $vhome = $vhome || "/vhost"; $template = $template || "$vhome/template.vhost"; $gid = $gid || $GHID; $vroot = $vroot || "vhost"; $webDir = $webDir || "www"; $urlDir = $urlDir || "html"; $guiDir = $guiDir || "admin"; $logDir = $logDir || "log"; $cronJob = $cronJob || "/etc/cron.daily/vhost"; $vwlogCf = $vwlogCf || "/etc/logrotate.d/vweb"; $logrotCf = $logrotCf || "/etc/logrotate.d/vhost"; $ftpdCf = $ftpdCf || "/etc/ftpaccess"; $servCf = $servCf || "/etc/proftpd.conf"; $httpdCf = $httpdCf || "/etc/httpd/conf/httpd.conf"; @vroot = getpwnam $vroot; chomp, $ownr{$_} = (stat "$vhome/$_")[4] for `ls $vhome/ $NERR`; ExOut "rm /tmp/.r?.vhost" if `ls /tmp/.r?.vhost $NERR`; ExOut "rm /usr/sbin/vhost.sh" if -f "/usr/sbin/vhost.sh"; ExOut "rm /etc/vhosts.vhost.0" if -f "/etc/vhosts.vhost.0"; ExOut "rm /etc/vhosts.vhost.1" if -f "/etc/vhosts.vhost.1"; ExOut "rm /etc/vhost.conf" if -f "/etc/vhost.conf"; ExOut "rm /etc/vhost.d/sample" if -f "/etc/vhost.d/sample"; ExOut "rm /etc/vhost.d/proftpd" if -f "/etc/vhost.d/proftpd"; ExOut "rm /etc/cron.daily/vhost" if -f "/etc/cron.daily/vhost"; ExOut "rm /etc/logrotate.d/vweb" if -f "/etc/logrotate.d/vweb"; ExOut "rm /etc/logrotate.d/vhost" if -f "/etc/logrotate.d/vhost"; ExOut "rm $cronJob" if -f $cronJob; ExOut "rm $vwlogCf" if -f $vwlogCf; ExOut "rm $logrotCf" if -f $logrotCf; ExOut "rm $dnsCf.vhost.1" if -f "$dnsCf.vhost.1"; ExOut "rm $mailCf.vhost.1" if -f "$mailCf.vhost.1"; ExOut "rm $servCf.vhost.1" if -f "$servCf.vhost.1"; ExOut "rm $ftpdCf.vhost.1" if -f "$ftpdCf.vhost.1"; ExOut "rm $httpdCf.vhost.1" if -f "$httpdCf.vhost.1"; ExOut "rm $vhome/.login" if -f "$vhome/.login"; ExOut "rm $vhome/.profile" if -f "$vhome/.profile"; ExOut "rm $template/.login" if -f "$template/.login"; ExOut "rm $template/.profile" if -f "$template/.profile"; ExOut "rm -r $vhome/bin/log" if -d "$vhome/bin/log"; ExOut "rm -r $vhome/etc/log" if -d "$vhome/etc/log"; ExOut "rm -r $vhome/lib/log" if -d "$vhome/lib/log"; ExOut "rm -r $template/bin" if -d "$template/bin"; ExOut "rm -r $template/etc" if -d "$template/etc"; ExOut "rm -r $template/lib" if -d "$template/lib"; ExOut "rm -r $template/log" if -d "$template/log"; ExOut "rm -r $template/home/$webDir/log" if -d "$template/home/$webDir/log"; ExOut "rm -r $template/home/$webDir/$logDir" if -d "$template/home/$webDir/$logDir"; ExOut "mv $vhostCf /etc/vhosts" if -f $vhostCf && $vhostCf ne "/etc/vhosts"; ExOut Pw "groupadd vhost -g $GHID -o" if !getgrnam "vhost"; ExOut Pw "groupmod vhost -g $GHID -o" if getgrnam "vhost" != $GHID; ExOut Pw "groupadd vuser -g $GUID -o" if !getgrnam "vuser"; ExOut Pw "groupmod vuser -g $GUID -o" if getgrnam "vuser" != $GUID; ExOut Pw "useradd $vroot -c 'vhost ruser' -d /etc/vhost.d -m -k $SKEL -g $GHID -s /bin/sh" if !@vroot; ExOut Pw "usermod $vroot -c 'vhost ruser' -d /etc/vhost.d -g $GHID -s /bin/sh" if @vroot && ($vroot[3] != $GHID || $vroot[6] ne "vhost ruser"); ExOut "chown 0:$GHID /etc/vhost.d" if !@vroot; `${\(Pw "useradd vhost.vuser -c vhost.vuser -g $GUID")} $NERR` if !grep /^[^:]*\./, Cat "/etc/passwd"; my $ok; my $unl = $UNIX =~ /^Linux$/i? 31 : 16; Flock "/etc/vhost.d/V00hostconf", "+<", 0; s/^(\$unameLen =) "32";/$1 "$unl";/ && ($ok = 1), !grep (/^[^:]*\./, Cat "/etc/passwd") && s/^(\$dotChar =) "\.";/$1 "_";/ && ($ok = 1), -d "/var/mail" && !-d "/var/spool/mail" && s/^(\$mailDir =) "\/var\/spool\/mail";/$1 "\/var\/mail";/ && ($ok = 1), -f "/etc/master.passwd" && !-f "/etc/shadow" && s/^(\$shadowCf =) "\/etc\/shadow";/$1 "\/etc\/master.passwd";/ && ($ok = 1), -f "/etc/mail/aliases" && !-f "/etc/aliases" && s/^(\$aliasesCf =) "\/etc\/aliases";/$1 "\/etc\/mail\/aliases";/ && ($ok = 1), -d "/etc/xinetd.d" && !-f "/etc/inetd.conf" && s/^(\$inetdCf =) "\/etc\/inetd\.conf";/$1 "\/etc\/xinetd.d";/ && ($ok = 1), -d "/etc/xinetd.d" && !-f "/etc/inetd.conf" && s/^(\$inetdRc =) "(\S+)\/inetd reload";/$1 "$2\/xinetd reload";/ && ($ok = 1), -d "/var/named/chroot" && s/^(\$dnsRt =) "";/$1 "\/var\/named\/chroot";/ && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; `${\(Pw "userdel vhost.vuser -r")} $NERR` if (getpwnam "vhost.vuser")[6] eq "vhost.vuser"; my $ok; Flock "/etc/vhost.d/$V20sendmail[1][$nMail]", "+<", 0 if -f "/etc/vhost.d/$V20sendmail[1][$nMail]"; -f "/etc/sendmail.cf" && !-f "/etc/mail/sendmail.cf" && s/^(\$sendmailCf =) "\/etc\/mail\/sendmail\.cf";/$1 "\/etc\/sendmail.cf";/ && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; my $ok; Flock "/etc/vhost.d/$V30squirrelmail[1][$nImap]", "+<", 0 if -f "/etc/vhost.d/$V30squirrelmail[1][$nImap]"; -d "/usr/share/squirrelmail" && !($wmDir && -d "/var/www/html/$wmDir") && s/^(\$smRoot =) "\$docRoot\/\$wmDir";/$1 "\/usr\/share\/squirrelmail";/ && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; my ($h, $ok); Flock "/etc/vhosts", "+<", 0; !grep (/^### \/etc\/vhosts -/, @FILE) && ($ok = 1); print FILE "### /etc/vhosts - vhost host index, do not edit\n" if $ok; print FILE "#\n" if $ok; print FILE "# ip_address\thost_name mailbox_size #user #uali\n" if $ok; print FILE "\n" if $ok; print FILE "127.0.0.1\tlocalhost.localdomain localhost\n" if $ok; /^\s*$HEAD|^\s*$FOOT|^\s*# (\S+) $SIGN/ && ($h = $1), $ok && s/^\s*(### Created by vhost,|127\.0\.0\.1)\s.*//s, $h && s/^(\s*([^#\s]+)\s+\Q$h\E)\s*$/$1 0.0K 0 0\n/s && ($ok = 1, $host{$h} = $2) for @FILE; print FILE @FILE if $ok; Flock 0; my ($o, $ok); Flock "/etc/vusers", "+<", 0; print FILE "### /etc/vusers - vhost user index, do not edit\n" if !@FILE; print FILE "#\n" if !@FILE; print FILE "# user_name\tprofile_dir disk_space #host #hali vroot\n" if !@FILE; print FILE "\n" if !@FILE; $o = $_ && getpwuid $_, $o && !grep (/^\s*\Q$o\E\s/, @FILE) && ($ok = 1) && ($FILE[$#FILE+1] = sprintf "%-15s /etc/vhost.d 0.0K 0 0\n", $o) for (getpwnam $vroot)[2], values %ownr; print FILE @FILE if $ok; Flock 0; my ($h, $ok, $conf); Flock $httpdCf, "+<", 0 if -f $httpdCf; /^\s*$HEAD|^\s*$FOOT|^\s*# (\S+) $SIGN/ && ($h = $1), $h || next, grep (m"/\Q$h\E/home/\*/", @FILE) && ($h = "", next), m"^(\s*DocumentRoot\s+)(/\S+)/\Q$h\E/"i && ($vhome = $2), s"^(\s*ServerAlias\s+)\S+\s*$"$1www.$h mail.$h\n"is && ($ok = 1), s"/\Q$h\E/home/$webDir/$logDir/"/$h/var/log/" && ($ok = 1), s"/\Q$h\E/log/"/$h/var/log/" && ($ok = 1), $conf = <<"#", UserDir $vhome/$h/home/*/public_html SetHandler default-handler # s"^(\s*\n"is && ($log = $2, $ok = 1), $log = $log || "xferlog", $conf = <<"#", virtual $h logfile $vhome/$h/var/log/$log virtual $h passwd /etc/vdata/passwd.$h virtual $h shadow /etc/vdata/shadow.$h # s"^\s*<>\s*$"$conf"s && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 30001) { $RUSER = $RUSER || $vroot || "vhost"; $VHOME = $VHOME || $vhome || "/vhost"; $homeDir = $homeDir || "/home"; $mailDir = $mailDir || "/var/spool/mail"; $guiDir = $guiDir || "admin"; $usrDir = $usrDir || "public_html"; $wu_ftpdCf = $wu_ftpdCf || $ftpdCf || "/etc/ftpaccess"; $proftpdCf = $proftpdCf || $servCf || "/etc/proftpd.conf"; ExOut Pw "usermod $RUSER -s /bin/sh" if getpwnam $RUSER && (getpwnam $RUSER)[8] !~ /sh$/; ExOut "chown -Rh 0:$GHID /etc/vmail" if -d "/etc/vmail" && (stat "/etc/vmail")[5] != $GHID; my $ok; Flock "/etc/vhosts", "+<", 0; s/\s0K 0 0/ 0.0K 0 0/i && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; my $ok; Flock "/etc/vusers", "+<", 0; s/\s0K 0 0/ 0.0K 0 0/i && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; my ($h, $ok, $conf); Flock $wu_ftpdCf, "+<", 0 if -f $wu_ftpdCf; /^\s*$HEAD|^\s*$FOOT|^\s*# (\S+) $SIGN/ && ($h = $1), $h || next, s"^(\s*virtual\s+)([\d.]+)(\s)"$1$h$3"i && $2 ne $h && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; my ($h, $ok, $conf); $conf = <<"#"; # uncomment the line below for ip-based virtual hosts. # Flock $proftpdCf, "+<", 0 if -f $proftpdCf; /^\s*$HEAD|^\s*$FOOT|^\s*# (\S+) $SIGN/ && ($h = $1), $h || next, grep (m"$conf", @FILE) && ($h = "", next), s"^(\s*)(AuthUserFile\s+/etc/vdata/passwd\.\Q$h\E)\s*$"$conf$1# $2\n"is && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 30101) { $VHOME = $VHOME || $vhome || "/vhost"; $httpdCf = $httpdCf || "/etc/httpd/conf/httpd.conf"; my ($h, $ok); Flock $httpdCf, "+<", 0 if -f $httpdCf; /^\s*$HEAD|^\s*$FOOT|^\s*# (\S+) $SIGN/ && ($h = $1), $h || next, s"^(\s*ServerAlias\s+)\*\."$1www."i && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 30401) { $VHOME = $VHOME || $vhome || "/vhost"; $mailDir = $mailDir || "/var/spool/mail"; $webDir = $webDir || "www"; $urlDir = $urlDir || "html"; $guiDir = $guiDir || "admin"; $wmDir = $wmDir || "webmail"; $wsDir = $wsDir || "stats"; $guiRoot = "/var/$webDir/$urlDir/$guiDir"; $sendmailCv = -f "/etc/sendmail.cV" && "/etc/sendmail.cV" || "/etc/mail/sendmail.cV"; $postfixCv = -f "/etc/postfix.cV" && "/etc/postfix.cV" || "/etc/postfix/postfix.cV"; $wu_ftpdCf = $wu_ftpdCf || $ftpdCf || "/etc/ftpaccess"; $proftpdCf = $proftpdCf || $servCf || "/etc/proftpd.conf"; `rm /tmp/.vhost/.duh $NERR`; ExOut Pw "groupadd vuser -g $GUID -o" if !getgrnam "vuser"; ExOut Pw "groupmod vuser -g $GUID -o" if getgrnam "vuser" != $GUID; ExOut "chown -Rh 0:$GHID /etc/vmail" if -d "/etc/vmail" && (stat "/etc/vmail")[5] != $GHID; ExOut "chown -Rh 0:$GHID /var/spool/vmail" if -d "/var/spool/vmail" && (stat "/var/spool/vmail")[5] != $GHID; ExOut "chown 0:$GHID $guiRoot" if -d $guiRoot && (stat $guiRoot)[5] != $GHID; ExOut "chown 0:$GHID $sendmailCv" if -f $sendmailCv && (stat $sendmailCv)[5] != $GHID; ExOut "chown 0:$GHID $postfixCv" if -f $postfixCv && (stat $postfixCv)[5] != $GHID; (getpwnam $_)[3] == $GHID && (getpwnam $_)[6] ne "vhost ruser" && ExOut Pw "usermod $_ -g $GUID" for keys %USER; my $ok; Flock $wu_ftpdCf, "+<", 0 if -f $wu_ftpdCf; s"^(\s*guestgroup\s+)vhost\s*$"$1vuser\n"is && ($ok = 1), s"^(\s*class\s+)vhost(\s)"$1vuser$2"i && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; my $ok; Flock $proftpdCf, "+<", 0 if -f $proftpdCf; s"^(\s*DefaultRoot\s+~\s+)vhost\s*$"$1vuser\n"is && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 30501) { $proftpdCf = $proftpdCf || $servCf || "/etc/proftpd.conf"; $sendmailCf = $sendmailCf || -f "/etc/sendmail.cf" && "/etc/sendmail.cf" || "/etc/mail/sendmail.cf"; $postfixCf = $postfixCf || "/etc/postfix"; `touch /tmp/.vhost/.ins.squirrel $NERR` if grep -f "$_/V30squirrelmail", keys %HOME; ExOut Pw "groupdel ftp" if getgrnam "ftp" == 2000; my ($h, $ok, $conf); $conf = <<"#"; AllowOverwrite on # Flock $proftpdCf, "+<", 0 if -f $proftpdCf; /^\s*$HEAD|^\s*$FOOT|^\s*# (\S+) $SIGN/ && ($h = $1), $h || next, join ("", @FILE) =~ m"\s\Q$h\E\s.*AllowOverwrite\s+on.*/\Q$h\E/"is && ($h = "", next), s"^(\s*; } if ($old < 31001) { $VHOME = $VHOME || $vhome || "/vhost"; $postfixCf = $postfixCf || "/etc/postfix"; my %dir; for my $d (grep !$dir{$_}++, $VHOME, values %HOME) { next if !-d $d; ExOut "rm $d/.login" if -f "$d/.login"; ExOut "rm $d/.profile" if -f "$d/.profile"; ExOut "mkdir $d/home" if !-e "$d/home"; ExOut "chown 0:$GHID $d/home" if !-o "$d/home" || (stat "$d/home")[5] != $GHID; ExOut "chmod 0711 $d/home" if ((stat "$d/home")[2] & 07777) != 0711; } ExOut "rm /var/spool/vmail/poprelay" if -f "/var/spool/vmail/poprelay"; my $ok; Flock "$postfixCf/main.cf", "+<", 0 if -f "$postfixCf/main.cf"; s"^([^#]*[\s=,])/var/spool/vmail/(poprelay(,|\s|$))"$1/etc/$2" && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 31101) { $postfixCf = $postfixCf || "/etc/postfix"; $postfixCv = "$postfixCf/postfix.cV"; `rm $postfixCv.db $NERR`; `rm /etc/poprelay.db $NERR`; my $ok; Flock "$postfixCf/main.cf", "+<", 0 if -f "$postfixCf/main.cf"; s"^(\s*relay_domains\s*=.*[^:])(\Q$postfixCv\E(,|\s|$))"$1hash:$2" && ($ok = 1), s"^(\s*relay_domains\s*=.*)\s/etc/poprelay(,|\s|$)"$1$2" && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 31102) { $VHOME = $VHOME || $vhome || "/vhost"; $webDir = $webDir || "www"; $ftpDir = $ftpDir || "ftp"; # `cp -p $asCgiRoot/awstats.pl.vhost.0 $asCgiRoot/awstats.pl $NERR` if -d $asIconRoot; ExOut "chmod 0755 $asIconRoot" if -d $asIconRoot && ((stat $asIconRoot)[2] & 07777) != 0755; } if ($old < 32001) { $homeDir = $homeDir || "/home"; $mailDir = $mailDir || "/var/spool/mail"; $usrDir = $usrDir || "public_html"; $proftpdCf = $proftpdCf || $servCf || "/etc/proftpd.conf"; $inetdCf = $inetdCf || "/etc/inetd.conf"; $seboolCf = "/etc/selinux/targeted/booleans"; my ($ok, $ghid); for (split /\s+/, `ls $homeDir/ $NERR`) { next if !-d "$homeDir/$_/$usrDir" || (stat "$homeDir/$_")[5] == $GHID; ExOut "chown $_:$GHID $homeDir/$_"; ExOut "chmod 0750 $homeDir/$_"; } ExOut "chmod 0775 $mailDir" if ((stat $mailDir)[2] & 07777) != 0775; /^\Q$GHID\E$/ && ($ok = 1) || ($ghid .= "$_,") for split /\D+/, `id -G nobody $NERR`; $ok && $ghid =~ s/,$// && ExOut Pw "usermod nobody -G $ghid"; my ($ok, $conf); $conf = <<"#"; DefaultAddress 127.0.0.1 # Flock $proftpdCf, "+<", 0 if -f $proftpdCf && !grep /^\s*DefaultAddress\s/i, Cat $proftpdCf; s"^(\s*$FOOT.*)"$1$conf"s && ($ok = 1) && last for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; my $ok; Flock $inetdCf, "+<", 0 if -f $inetdCf && !grep /^[^#]*\svpop3d(\s|$)/, Cat $inetdCf; s"^([^#]*/vpop3d)(\s|$)"$1 vpop3d$2" && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; my $ok; Flock $seboolCf, "+<", 0 if -f $seboolCf && !grep /^\s*httpd_disable_trans\s*=\s*1\s*$/i, Cat $seboolCf; s"^(\s*httpd_disable_trans\s*=\s*).*"${1}1"i && ($ok = 1) for @FILE; $FILE[$#FILE+1] = "httpd_disable_trans=1\n" if !$ok; print FILE @FILE; Flock 0; } if ($old < 32101) { `touch /tmp/.vhost/.ins.squirrel $NERR` if grep -f "$_/V30squirrelmail", keys %HOME; ExOut ("rm /var/spool/cron/root"), ExOut "rm /var/spool/cron/root.vhost.0" if -f "/var/spool/cron/root.vhost.0" && !-s "/var/spool/cron/root.vhost.0" && (-d "/var/spool/cron/crontabs" || -d "/var/spool/cron/tabs"); ExOut ("rm /var/cron/root"), ExOut "rm /var/cron/root.vhost.0" if -f "/var/cron/root.vhost.0" && !-s "/var/cron/root.vhost.0" && (-d "/var/cron/crontabs" || -d "/var/cron/tabs"); for my $d (grep !-l && -f "$_/V00hostconf", keys %HOME) { my $ok; Flock "$d/V00hostconf", "+<", 0; -d "/var/spool/cron/crontabs" && s/^(\$cronDir =) "\/var\/(spool\/)+cron";/$1 "\/var\/spool\/cron\/crontabs";/ && ($ok = 1), -d "/var/spool/cron/tabs" && s/^(\$cronDir =) "\/var\/(spool\/)+cron";/$1 "\/var\/spool\/cron\/tabs";/ && ($ok = 1), -d "/var/cron/crontabs" && s/^(\$cronDir =) "\/var\/(spool\/)*cron";/$1 "\/var\/cron\/crontabs";/ && ($ok = 1), -d "/var/cron/tabs" && s/^(\$cronDir =) "\/var\/(spool\/)*cron";/$1 "\/var\/cron\/tabs";/ && ($ok = 1), -d "/var/cron" && !-d "/var/spool/cron" && s/^(\$cronDir =) "\/var\/spool\/cron";/$1 "\/var\/cron";/ && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; } my $ok; Flock "/etc/httpd/conf.d/squirrelmail.conf", "+<", 0 if grep /^\s*Alias\s*\//i, Cat "/etc/httpd/conf.d/squirrelmail.conf"; s"^(\s*Alias\s*/)"# $1"i && ($ok = 1) for @FILE; $rrc = 1, print FILE @FILE if $ok; Flock 0; } if ($old < 33001) { `touch /tmp/.vhost/.ins.squirrel $NERR` if grep -f "$_/V30squirrelmail", keys %HOME; my $ok = 1; `setsebool httpd_disable_trans 1 $NERR`, $ok &&= $?; `setsebool -P httpd_disable_trans 1 $NERR`, $ok &&= $?; `/etc/rc.d/init.d/httpd restart $NERR` if !$ok && -f "/etc/vhost.d/V10apache"; my $ok = 1; `setsebool ftpd_disable_trans 1 $NERR`, $ok &&= $?; `setsebool -P ftpd_disable_trans 1 $NERR`, $ok &&= $?; `/etc/rc.d/init.d/vsftpd restart $NERR` if !$ok && !; $rrc = 1; `rm /etc/poprelay.db $NERR`; } ### hosts #################################################################### for my $d ($old < 30000 && <$vhome/*>) { my ($u, $p, $n, $m, $a, $v, @u); my $h = (split /\//, $d)[-1]; my @o = getpwuid $ownr{$h}; my @w = getpwnam $vroot; my $o = $o[0] eq "root"? $w[0] : $o[0]; my $i = $o[0] eq "root"? $w[2] : $ownr{$h}; next if !$host{$h} && !$QHOST{$h} || !-d $d || -l $d || -e "/etc/vmail/vusers.$h" && !-f "/tmp/.vhost/.ins.30000.$h"; `touch /tmp/.vhost/.ins.30000.$h $NERR`; ExOut "mkdir $d/var" if !-d "$d/var"; ExOut "mkdir $d/var/log" if !-d "$d/var/log"; ExOut "mkdir $d/var/mail" if !-d "$d/var/mail"; ExOut "touch $d/var/log/access_log" if !-e "$d/var/log/access_log"; ExOut "touch $d/var/log/error_log" if !-e "$d/var/log/error_log"; ExOut "touch $d/var/log/xferlog" if !-e "$d/var/log/xferlog"; ExOut "mv $d/home/$webDir/$logDir/* $d/var/log" if -d "$d/home/$webDir/$logDir"; ExOut "mv $d/log/* $d/var/log" if -d "$d/log"; ExOut "rm -r $d/home/$webDir/$logDir" if -d "$d/home/$webDir/$logDir"; ExOut "rm -r $d/log" if -d "$d/log"; ExOut "ln -s /etc/vhost.d /etc/vmail/vhostd.$h" if !-e "/etc/vmail/vhostd.$h"; ExOut "touch /etc/vmail/vusers.$h" if !-e "/etc/vmail/vusers.$h"; ExOut "touch /etc/vmail/shadow.$h" if !-e "/etc/vmail/shadow.$h"; ExOut "touch /etc/vmail/passwd.$h" if !-e "/etc/vmail/passwd.$h"; ExOut "touch /etc/vmail/aliases.$h" if !-e "/etc/vmail/aliases.$h"; ExOut Pw "usermod $o[0] -c 'vhost admin' -g $GUID" if $o[3] == $gid && $o[7] =~ /^\Q$vhome\E(\/|$)/; if ($h eq $HNAM) { ExOut "rm -r /var/spool/vmail/$h" if -e "/var/spool/vmail/$h"; ExOut "ln -s /var/spool/mail /var/spool/vmail/$h" if !-l "/var/spool/vmail/$h"; ExOut "ln -sf /dev/null /etc/vmail/vusers.$h" if !-l "/etc/vmail/vusers.$h"; ExOut "ln -sf /etc/shadow /etc/vmail/shadow.$h" if !-l "/etc/vmail/shadow.$h"; ExOut "ln -sf /etc/passwd /etc/vmail/passwd.$h" if !-l "/etc/vmail/passwd.$h"; ExOut "ln -sf /etc/aliases /etc/vmail/aliases.$h" if !-l "/etc/vmail/aliases.$h"; for (Cat "/etc/passwd") { /^\s*([^#:]+):/ && ($u = $1, @u = getpwnam $u) && $u[7] eq "/home/$u" && $u[8] !~ /by vhost$/ || next; ExOut "mkdir /home/$u" if !-e "/home/$u"; ExOut "ln -s /home/$u $d/home/$u" if !-e "$d/home/$u"; ExOut "ln -s /var/spool/mail/$u $d/var/mail/$u" if !-e "$d/var/mail/$u"; # ExOut "touch /var/spool/mail/$u" if !-e "/var/spool/mail/$u"; ExOut "mkdir /home/$u/public_html" if !-d "/home/$u/public_html"; Flock "/home/$u/public_html/index.html", ">>", 2 if !`ls /home/$u/public_html/index.* $NERR`; print FILE "Home of $u\@$h\n"; Flock 0; ExOut "chown -Rh $u[2]:$u[3] /home/$u/public_html"; ExOut "chmod 0755 /home/$u"; } } else { ExOut "mv /var/spool/vmail/$h/* $d/var/mail" if !-l "/var/spool/vmail/$h"; ExOut "rm -r /var/spool/vmail/$h" if !-l "/var/spool/vmail/$h"; ExOut "ln -s $d/var/mail /var/spool/vmail/$h" if !-e "/var/spool/vmail/$h"; ExOut "ln -sf /var/spool/mail/$o $d/var/mail/$o" if $o; if ($o[0] eq "root") { my $days = int time / 86400; Flock "/etc/vmail/vusers.$h", "+<", 0; s/^\s*\Q$w[0]\E\s.*//s for @FILE; printf FILE "%-15s %s\n", $w[0], $w[0]; print FILE @FILE; Flock 0; Flock "/etc/vmail/shadow.$h", "+<", 0; s/^\s*\Q$w[0]\E:.*//s for @FILE; print FILE "$w[0]:$w[1]:$days:-1:99999:-1:-1:-1:\n"; print FILE @FILE; Flock 0; Flock "/etc/vmail/passwd.$h", "+<", 0; s/^\s*\Q$w[0]\E:.*//s for @FILE; print FILE "$w[0]:$w[1]:$w[2]:$GUID:vhost admin:$d:/bin/false\n"; print FILE @FILE; Flock 0; Flock "/etc/vmail/aliases.$h", "+<", 0; s/^\s*admin:.*//s for @FILE; print FILE "admin: $w[0] \n"; print FILE @FILE; Flock 0; } for (Cat "/etc/vmail/passwd.$h") { /^\s*([^#:]+):([^:]*:){3}([^:]*):.*\s#((\S+)\@[^\@\s]*)\s+- keep this, by vhost/ && ($u = $1, $n = $3, $m = "$d/home/$1", $a = $4, $v = $5, $v =~ s/\@/./, $v = substr $v, 0, 32) || next; /^\s*\Q$u\E:([^:]*):/ && ($p = $1) for Cat "/etc/vmail/shadow.$h"; $n = "vhost admin", $m = $d if $u eq $o[0]; Flock "/etc/vmail/vusers.$h", "+>>", 2; printf FILE "%-15s %s\n", $u, $v if !grep /^\s*\Q$u\E\s/, @FILE; Flock 0; my $ok; Flock "/etc/vmail/passwd.$h", "+<", 0; s/^\s*\Q$u\E:.*/$u:$p:$i:$GUID:$n:$m:\/bin\/false/ && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; my $ok; Flock "/etc/vmail/aliases.$h", "+<", 0; s/^\s*\Q$u\E:\s+\Q$a\E\s*(,|$)/$u: / && ($ok = 1), s/^\s*\Q$u\E:\s*$//s for @FILE; print FILE @FILE if $ok; Flock 0; $u ne $o[0] || next; ExOut Pw "useradd $v -c 'vhost vuser' -d $d/home/$u -m -k $SKEL -g $GUID -s /bin/false -u $i -o" if !getpwnam $v; ExOut Pw "usermod $v -c 'vhost vuser' -d $d/home/$u -g $GUID -s /bin/false -u $i -o" if getpwnam $v; ExOut "mkdir $d/home/$u" if !-d "$d/home/$u"; ExOut "cp -Rp /vhome/$h/home/$u/. $d/home/$u" if -d "/vhome/$h/home/$u"; ExOut "mv /var/spool/mail/$v $d/var/mail/$u" if !-l "/var/spool/mail/$v"; ExOut "ln -s $d/var/mail/$u /var/spool/mail/$v" if !-e "/var/spool/mail/$v"; ExOut "touch $d/var/mail/$u" if !-e "$d/var/mail/$u"; ExOut "mkdir $d/home/$u/public_html" if !-d "$d/home/$u/public_html"; Flock "$d/home/$u/public_html/index.html", ">>", 2 if !`ls $d/home/$u/public_html/index.* $NERR`; print FILE "Home of $u\@$h\n"; Flock 0; ExOut "chown -Rh $i:$GHID $d/home/$u/public_html"; ExOut "chmod 0755 $d/home/$u"; } } Flock "$d/.login", ">", 0 if !grep /pwd=`pwd`/, Cat "$d/.login"; print FILE "set pwd=`pwd`; set prompt=\"`basename \$pwd`> \"\nset path=(\$path /sbin /usr/sbin)\n"; Flock 0; Flock "$d/.profile", ">", 0 if !grep /pwd=`pwd`/, Cat "$d/.profile"; print FILE "pwd=`pwd`; PS1=\"`basename \$pwd`> \"\nPATH=\$PATH:/sbin:/usr/sbin\n"; Flock 0; ExOut "chown -Rh $i:$GHID $d"; ExOut "chown 0:$GHID $d/var"; ExOut "chown 0:$GHID $d/var/log"; ExOut "chown 0:$GHID $d/var/mail"; ExOut "chown 0:$GHID $d/home/$webDir/$urlDir/$guiDir"; `rm /tmp/.vhost/.ins.30000.$h $NERR`; } for my $h ($old < 30001 && (keys %host, keys %PROF)) { my ($u, @u); my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my @o = getpwuid ((stat $d)[4]); my @w = getpwnam $RUSER; my $o = $o[0] eq "root" && !-c "/etc/vmail/vusers.$h"? $w[0] : $o[0]; my $i = $o[0] eq "root" && !-c "/etc/vmail/vusers.$h"? $w[2] : (stat $d)[4]; next if !$h || !-d $d || -l $d || ((stat "$d/var/mail")[2] & 07777) == 01777 && !-f "/tmp/.vhost/.ins.30001.$h"; `touch /tmp/.vhost/.ins.30001.$h $NERR`; if (-c "/etc/vmail/vusers.$h") { my $maildir = $UNIX =~ /^Linux$/i? "/var/spool/mail" : $mailDir; for (Cat "/etc/passwd") { /^\s*([^#:]+):/ && ($u = $1, @u = getpwnam $u) || next; ExOut "rm -r $homeDir/$u" if -d "$homeDir/$u" && $u[7] ne "$homeDir/$u"; ExOut "rm $d/home/$u" if -l "$d/home/$u" && $u[7] ne "$homeDir/$u" && $u ne $o; ExOut "rm $d/var/mail/$u" if -l "$d/var/mail/$u" && $u[7] ne "$homeDir/$u" && $u ne $o; ExOut "chown $u[2]:$u[3] $homeDir/$u" if -d "$homeDir/$u" && (stat "$homeDir/$u")[4] != $u[2]; } ExOut "chmod 1777 $maildir" if ((stat $maildir)[2] & 07777) != 01777; } ExOut "mkdir -p $d/home/$o/$usrDir" if $o && !-d "$d/home/$o/$usrDir"; Flock "$d/home/$o/$usrDir/index.html", ">>", 2 if $o && !`ls $d/home/$o/$usrDir/index.* $NERR`; print FILE "Home of $o\@$h\n"; Flock 0; ExOut "chown -Rh $i:$GHID $d/home/$o" if $o && (stat "$d/home/$o/$usrDir")[4] != $i; ExOut "chmod 0755 $d/home/$o" if $o && ((stat "$d/home/$o")[2] & 07777) != 0755; ExOut "chown $i:$GHID $d" if (stat $d)[4] != $i; ExOut "chmod 0750 $d" if ((stat $d)[2] & 07777) != 0750; ExOut "chmod 1777 $d/var/mail" if ((stat "$d/var/mail")[2] & 07777) != 01777; `rm /tmp/.vhost/.ins.30001.$h $NERR`; } for my $h ($old < 30004 && (keys %host, keys %PROF)) { my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my $i = (stat $d)[4]; next if !$h || !-d $d || -l $d || -e "$d/var/log/.no-rotate" && !-f "/tmp/.vhost/.ins.30004.$h"; `touch /tmp/.vhost/.ins.30004.$h $NERR`; ExOut "touch $d/var/log/.no-rotate" if !-e "$d/var/log/.no-rotate"; ExOut "chown $i:$GHID $d/var/log/.no-rotate" if (stat "$d/var/log/.no-rotate")[4] != $i; `rm /tmp/.vhost/.ins.30004.$h $NERR`; } for my $h ($old < 30101 && (keys %host, keys %PROF)) { my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my $i = (stat $d)[4]; my $o = getpwuid $i; next if !$h || !-d $d || -l $d || (lstat "$d/var/mail/$o")[4] == 0 && (stat $d)[5] == $GHID && !-f "/tmp/.vhost/.ins.30101.$h"; `touch /tmp/.vhost/.ins.30101.$h $NERR`; for (split /\s+/, `ls $d/var/mail/ $NERR`) { ExOut "chown -h 0:$GHID $d/var/mail/$_" if -l "$d/var/mail/$_" && (lstat "$d/var/mail/$_")[4] != 0; ExOut "chown -h 0:$GHID $d/home/$_" if -l "$d/home/$_" && (lstat "$d/home/$_")[4] != 0; } ExOut "chown $i:$GHID $d" if (stat $d)[5] != $GHID; `rm /tmp/.vhost/.ins.30101.$h $NERR`; } for my $h ($old < 30401 && (keys %host, keys %PROF)) { my $v; my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my $i = (stat $d)[4]; my $o = getpwuid $i; next if !$h || !-d $d || -l $d || ((stat $d)[2] & 07777) == 0750 && (stat $d)[5] == $GHID && !-f "/tmp/.vhost/.ins.30401.$h"; `touch /tmp/.vhost/.ins.30401.$h $NERR`; if (!-c "/etc/vmail/vusers.$h") { for (Cat "/etc/vmail/vusers.$h") { /^\s*\S+\s+(\S+)/ && ($v = $1) && -l "$mailDir/$v" || next; ExOut "chown -h 0:$GHID $mailDir/$v" if (lstat "$mailDir/$v")[5] != $GHID; ExOut Pw "usermod $v -g $GUID" if (getpwnam $v)[3] != $GUID; } my $ok; Flock "/etc/vmail/passwd.$h", "+<", 0; s/^(\s*[^:]*:[^:]*:[^:]*):\Q$GHID\E:/$1:$GUID:/ && ($ok = 1) for @FILE; print FILE @FILE if $ok; Flock 0; } ExOut "chown $i:$GHID $d/home/$webDir/$urlDir/$wmDir/data" if -d "$d/home/$webDir/$urlDir/$wmDir/data" && (stat "$d/home/$webDir/$urlDir/$wmDir/data")[5] != $GHID; ExOut "chown $i:$GHID $d/home/$webDir/$urlDir/$wsDir" if -d "$d/home/$webDir/$urlDir/$wsDir" && (stat "$d/home/$webDir/$urlDir/$wsDir")[5] != $GHID; ExOut "chown $i:$GHID $d" if (stat $d)[5] != $GHID; ExOut "chmod 0750 $d" if ((stat $d)[2] & 07777) != 0750; ExOut Pw "usermod $o -g $GUID" if (getpwuid $i)[3] == $GHID && (getpwuid $i)[6] ne "vhost ruser"; `rm /tmp/.vhost/.ins.30401.$h $NERR`; } for my $h ($old < 30503 && (keys %host, keys %PROF)) { my $f; my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my @o = getpwuid ((stat $d)[4]); next if !$h || !-d $d || -l $d || !grep (($f = $_) && grep (/^\Q$f\E$/, `ls -A $d/ $d/home/*/ $NERR`), @etcSkel) && !-f "/tmp/.vhost/.ins.30503.$h"; `touch /tmp/.vhost/.ins.30503.$h $NERR`; for my $d (($o[7] ne $d || $o[8] eq "/bin/false") && $d, !-c "/etc/vmail/vusers.$h" && <$d/home/*>) { $d && $_ && -e "$d/$_" && ExOut "rm -r $d/$_" for @etcSkel; } `rm /tmp/.vhost/.ins.30503.$h $NERR`; } for my $h ($old < 31102 && (keys %host, keys %PROF)) { my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my $i = (stat $d)[4]; next if !$h || !-d $d || -l $d && (lstat $d)[4] == $i && !-f "/tmp/.vhost/.ins.31102.$h"; `touch /tmp/.vhost/.ins.31102.$h $NERR`; for (split /\s+/, `ls $d/home/ $NERR`) { ExOut "chown -h $_:$GUID $d/home/$_" if -l "$d/home/$_" && (lstat "$d/home/$_")[4] != getpwnam $_ && !/^(\Q$webDir\E|\Q$ftpDir\E)$/; } ExOut "chown -h $i:$GUID $d/home/$webDir" if -l "$d/home/$webDir" && (lstat "$d/home/$webDir")[4] != $i; ExOut "chown -h $i:$GUID $d/home/$ftpDir" if -l "$d/home/$ftpDir" && (lstat "$d/home/$ftpDir")[4] != $i; ExOut "chown -h $i:$GHID $d" if -l $d && (lstat $d)[4] != $i; `rm /tmp/.vhost/.ins.31102.$h $NERR`; } for my $h ($old < 32001 && (keys %host, keys %PROF)) { my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my $i = (stat $d)[4]; next if !$h || !-d $d || ((stat "$d/tmp")[2] & 07777) == 01777 && !-f "/tmp/.vhost/.ins.32001.$h"; `touch /tmp/.vhost/.ins.32001.$h $NERR`; for (split /\s+/, `ls $d/var/mail/ $NERR`) { ExOut "chown -h $_:$GUID $d/var/mail/$_" if -l "$d/var/mail/$_" && (lstat "$d/var/mail/$_")[4] != getpwnam $_; } ExOut "mkdir $d/tmp" if !-e "$d/tmp"; ExOut "chown $i:$GUID $d/tmp" if (stat "$d/tmp")[4] != $i; ExOut "chown $i:$GUID $d/var/mail" if (stat "$d/var/mail")[4] != $i; ExOut "chmod 1777 $d/tmp" if ((stat "$d/tmp")[2] & 07777) != 01777; ExOut "chmod 0755 $d/var/mail" if ((stat "$d/var/mail")[2] & 07777) != 0755; `rm /tmp/.vhost/.ins.32001.$h $NERR`; } for my $h ($old < 99999 && (keys %host, keys %PROF)) { my $d = ($HOME{$PROF{$h}} || $VHOME)."/$h"; my $o = getpwuid ((stat $d)[4]); next if !$h || !-d $d || -l $d || !$o || $QHOST{$h} && !CheckQ $QHOST{$h}; $rrc = 1, $uphost = 1, last; } ### exit ##################################################################### if ($_f || $old < $cur) { ExOut "cp -p vhost /usr/sbin/vhost"; ExOut "chown 0:$GHID /usr/sbin/vhost"; ExOut "chmod 4755 /usr/sbin/vhost"; } if ($_f || $old < $new) { ExOut "cp -p vhost.pl /usr/sbin/vhost.pl"; ExOut "chown 0:$GHID /usr/sbin/vhost.pl"; ExOut "chmod 0755 /usr/sbin/vhost.pl"; `touch /tmp/.vhost/.ins.webgui $NERR`; } ToErr "\n"; ToErr "vhost: please review /tmp/.vhost/install.log\n"; ToErr "vhost: installation completed\n"; ToErr ("Press ENTER to continue... "), ; ToErr "\n"; system "/usr/sbin/vhost -q"; $err = $? >> 8; print ("vhost --uphost -q -f\n"), system "/usr/sbin/vhost --uphost -i -q -f 2>&1; echo" if $err != 1 && $uphost; print ("vhost --reload -f\n"), system "/usr/sbin/vhost --reload -l -f 2>&1; echo" if $err != 1 && $rrc; system "/usr/sbin/vhost" if $err != 1; exit 0;