#============================================================================# # vHost - one-step solution for all virtual hosting needs # # V30openwebmail - openwebmail 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 ################################################## ### webmail directory name on virtual hosts. virtual users will access their # web-based mail at "http://virtual.host.name/$wmDir". # $wmDir = "webmail"; $wmDir = "webmail"; ### openwebmail cgi directory on the main host. make sure it's accessible by # all users. # $owCgiRoot = "/var/www/cgi-bin/openwebmail"; $owCgiRoot = "/var/www/cgi-bin/openwebmail"; ### openwebmail html directory on the main host. make sure it's accessible by # the httpd user. # $owHtmlRoot = "/var/www/html/openwebmail"; $owHtmlRoot = "/var/www/html/openwebmail"; ### DO NOT TOUCH ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!! ### SanityChecking ########################################################### $ERR = 1, Error "$MOD: \$wmDir = '$wmDir'" if $wmDir eq $guiDir || !CheckN $wmDir; $ERR = 1, Error "$MOD: \$owCgiRoot = '$owCgiRoot'" if !-x "$owCgiRoot/openwebmail.pl"; $ERR = 1, Error "$MOD: \$owHtmlRoot = '$owHtmlRoot'" if !-f "$owHtmlRoot/openwebmail.html"; $wmRoot = "$VHOME/$H/var/$webDir/$urlDir/$wmDir"; $EVAL{'$wmRoot;'} = 4; }; $X eq "initialization" && do { ############################################### if ($ONCFG) { #`chown -Rh 0:$GHID $owCgiRoot $NERR` if !-o $owCgiRoot; #`chown -Rh 0:$GHID $owHtmlRoot $NERR` if !-o $owHtmlRoot; my $ok; my $conf = "$owCgiRoot/openwebmail.pl"; Flock $conf, "+<", 0 if -f $conf && !grep /^\s*$FOOT/, Cat $conf; BackupCf $conf; /^\s*loginmenu\s*\(/ && ($_ .= "\n$FOOT\n".<<'#'."\n", $ok = 1) && last for @FILE; my ($host, $user, $pass) = (cookie('VHOST_HOSTNAME'), cookie('VHOST_USERNAME'), cookie('VHOST_PASSWORD')); print <<"_" if $user && $pass; _ my $host = ($0 =~ /([^\/]+)\/(var|home)\//)[0]; my $guiDir = (`cat $config{'ow_sitesconfdir'}/$host 2>/dev/null` =~ /^\s*guiDir\s+(\S+)/m)[0] || $config{'guiDir'}; print "\n" if !$user || !$pass; # print FILE @FILE if $ok; Flock 0; my $ok; my $conf = "$owCgiRoot/openwebmail-main.pl"; Flock $conf, "+<", 0 if -f $conf && !grep /^\s*$FOOT/, Cat $conf; BackupCf $conf; s/^(\s*)(logout\s*\()/$1undef \$ENV{'HTTP_ACCEPT_ENCODING'};\n$1$2/ && ($_ .= "\n$FOOT\n".<<'#'."\n", $ok = 1) && last for @FILE; my $guiDir = $config{'guiDir'}; print "\n"; # print FILE @FILE if $ok; Flock 0; my $ok; my $conf = "$owCgiRoot/etc/openwebmail.conf"; Flock $conf, "+<", 0 if -f $conf && !grep /^\s*guiDir\s+\Q$guiDir\E\s*$/, Cat $conf; BackupCf $conf; s/^(\s*guiDir)\s.*/$1 $guiDir/ && ($ok = 1) for @FILE; $FILE[$#FILE+1] = "\n$FOOT\nguiDir $guiDir\n" if !$ok; print FILE @FILE; Flock 0; my $ok; Flock "$owCgiRoot/auth/auth_vhost.pl", ">", 0 if !-e "$owCgiRoot/auth/auth_vhost.pl"; s/^=auth_vhost\.pl .*//s && ($ok = 1), $ok && print FILE for Cat $MOD; Flock 0; my $conf = "openwebmail.conf"; $owCgiDir = ($owCgiRoot =~ /([^\/]+)\/?$/)[0]; $owHtmlDir = ($owHtmlRoot =~ /([^\/]+)\/?$/)[0]; $owEtcRoot = ((Cat ("$owCgiRoot/etc/$conf") . Cat ("$owCgiRoot/etc/defaults/$conf")) =~ /^\s*ow_etcdir\s+(\S+)/m)[0]; $owEtcRoot =~ s/%ow_cgidir%/$owCgiRoot/, $owEtcRoot ||= "$owCgiRoot/etc"; $owSiteRoot = ((Cat ("$owCgiRoot/etc/$conf") . Cat ("$owCgiRoot/etc/defaults/$conf")) =~ /^\s*ow_sitesconfdir\s+(\S+)/m)[0]; $owSiteRoot =~ s/%ow_etcdir%/$owEtcRoot/, $owSiteRoot ||= "$owCgiRoot/etc/sites.conf"; `mkdir -p $owSiteRoot $NERR` if !-e $owSiteRoot; `chown 0:$GHID $owSiteRoot $NERR` if !-o $owSiteRoot; `chmod 0711 $owSiteRoot $NERR` if ((stat $owSiteRoot)[2] & 07777) != 0711; } }; $X eq "addhost" && do { ###################################################### `touch $VHOME/$H/var/log/openwebmail.log $NERR`; `mkdir $wmRoot $NERR`; `rm -r $VHOME/$H/var/$webDir/$cgiDir/$owCgiDir $NERR`; `rm -r $VHOME/$H/var/$webDir/$urlDir/$owHtmlDir $NERR`; `ln -s $owCgiRoot $VHOME/$H/var/$webDir/$cgiDir/$owCgiDir $NERR`; `ln -s $owHtmlRoot $VHOME/$H/var/$webDir/$urlDir/$owHtmlDir $NERR`; my $maildir = $LOH && $mailDir || "$VHOME/$H/var/mail"; Flock "$owSiteRoot/$H", ">", 0; print FILE "$FOOT\n"; print FILE <<"#"; guiDir $guiDir domainnames auto auth_module auth_vhost.pl auth_withdomain yes auth_domain $H mailspooldir $maildir logfile $VHOME/$H/var/log/openwebmail.log use_hashedmailspools no use_homedirspools no enable_changepwd no enable_autoreply no # Flock 0; Flock "$wmRoot/index.php", ">", 0; print FILE "\n"; Flock 0; }; $X eq "delhost" && do { ###################################################### `rm $owSiteRoot/$H $NERR` if $_d; }; $X eq "finalization" && do { ################################################# if ($ARGV[0] eq "addhost" || $ARGV[0] eq "adduser" && $U eq $webDir) { `chown -h 0:$GUID $VHOME/$H/var/$webDir/$cgiDir/$owCgiDir $NERR`; `chown -h 0:$GUID $VHOME/$H/var/$webDir/$urlDir/$owHtmlDir $NERR`; } }; 1; =auth_vhost.pl ############################################################### package ow::auth_vhost; # # auth_vhost.pl - authenticate user with vHost # # Jake Fan # my $vhost = "/usr/sbin/vhost"; sub get_userinfo { my ($host, $user) = ($_[1] =~ /^([^@]*)@([^@]*)$/)[1,0]; return (0, "", $3, $1, $2, $4) if `cat /etc/vdata/passwd.$host 2>/dev/null` =~ /^\s*\Q$user\E:[^:]*:([^:]*):([^:]*):([^:]*):([^:]*):/m; return (-4, ""); } sub get_userlist { my $host = ($_[1] =~ /(.*)/)[0]; return (0, "", map {/^\s*([^:]*):/} `cat /etc/vdata/passwd.$host 2>/dev/null`); } sub check_userpassword { my ($host, $user, $pass) = (($_[1] =~ /^([^@]*)@([^@]*)$/)[1,0], ($_[2] =~ /(.*)/)[0]); return(0, "") if `cat /etc/vdata/shadow.$host 2>/dev/null` =~ /^\s*\Q$user\E:([^:]*):/m && $1 eq crypt $pass, $1; return (-4, ""); } sub change_userpassword { return (-1, ""); }