############################
#说明:web界面添加email的Perl程序不完整版
#名称:webadmin.cgi
#系统环境:Freebsd、Mod_Perl、MySQL、Apache、Apache::DBI、PostFix 2.x、igenus for postfix 1.0
#作者:邱雄盛
#QQ:2263537
#MSN:sunboydavid#hotmail.com
#SkyPe:haoqiu
#时间:2005年5月26日
############################
#!/usr/bin/perl
use lib 'libs/';
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use Apache::DBI;
use IMail;
# Get CGI parameters
my $cgi = new CGI;
my $mail = $cgi-param('mail');
my $password = $cgi-param('password');
my $realname = $cgi-param('realname');
my ($username,$domain)=split(/\@/,$mail);
unless($domain){
print "Content-Type: text/html\n\n";
print qq~
邮件系统管理
添加邮件用户
Email地址:
密码:
真实姓名:
~;
exit;
}
# 数据分析
$mail or die "邮箱没填哦.\n\n";
$password or die "密码没填哦.\n\n";
$realname or die "真实姓名没填哦.\n\n";
# 连接数据库
my $dbh = connectDb();
# 添加用户
my $uid=125;
my $gid=125;
my $home="/var/mail";
my $size=10240000;
# 查询已有域
my $query = "SELECT COUNT(*) FROM transport WHERE domain = ?";
my $sth = $dbh-prepare_cached($query);
$sth-execute($domain) or dbError();
my $count=$sth-fetchrow_arrayref-[0];
$sth-finish;
unless ($count){
# 添加域
my $query = "INSERT INTO transport SET domain=?,transport=?";
my $sth = $dbh-prepare_cached($query);
$sth-execute($domain,'virtual:') or die"'数据库操作错误,域未添加成功.\n\n";
$sth-finish;
}
my $query = "INSERT INTO virtual_users SET email=?,password=?,uid=?,gid=?,home=?,maildir=?,regtime=NOW(),domain=?,username=?,quota=?";
my $sth = $dbh-prepare_cached($query);
$sth-execute($mail,$password,$uid,$gid,"$home/","$domain/$username/Maildir/",$domain,$realname,$size) or die"'数据库操作错误,用户未添加成功.\n\n";
$sth-finish;
# 域
if (! -e "$home/$domain") {
mkdir("$home/$domain", "0700");
`chmod 700 $home/$domain`;
}
# 用户
if (! -e "$home/$domain/$username") {
mkdir("$home/$domain/$username", "0700");
`chmod 700 $home/$domain/$username`;
}
# Maildir
if (! -e "$home/$domain/$username/Maildir") {
mkdir("$home/$domain/$username/Maildir", "0700");
`chmod 700 $home/$domain/$username/Maildir`;
}
# cur
if (! -e "$home/$domain/$username/Maildir/cur") {
mkdir("$home/$domain/$username/Maildir/cur", "0700");
`chmod 700 $home/$domain/$username/Maildir/cur`;
}
# tmp
if (! -e "$home/$domain/$username/Maildir/tmp") {
mkdir("$home/$domain/$username/Maildir/tmp", "0700");
`chmod 700 $home/$domain/$username/Maildir/tmp`;
}
# new
if (! -e "$home/$domain/$username/Maildir/new") {
mkdir("$home/$domain/$username/Maildir/new", "0700");
`chmod 700 $home/$domain/$username/Maildir/new`;
}
chown ($uid, $gid, "$home/$domain") or warn "couldn't chown $home/$domain";
# 页面跳转
print $cgi-header(-location="mail_admin.cgi");
#End