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

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- 王朝網路 版權所有