| 導購 | 订阅 | 在线投稿
分享
 
 
 

web界面添加email的Perl程序不完整版

2008-05-31 00:04:58  編輯來源:互聯網  简体版  手機版  評論  字體: ||
 
 
  ############################

  #说明: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
 
 
 
############################ #说明: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
󰈣󰈤
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号 wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味著赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有