#!/usr/bin/perl -w # # This perl script provides an administration GUI # to help you administer your email server when using # postfix-style virtual domains with a MySQL database # backend. You can find a tutorial on setting up your # own server at: # http://workaround.org/ispmail.shtml # # You can use this script under the terms of the # GNU GPL (general public license). # # Version 1.0 # Christoph Haas (email@christoph-haas.de) # Configuration my $_sendmail = '/usr/sbin/sendmail'; my $_stylesheet = '/style.css'; my $_vmaildir = '/home/vmail'; # Load the utility class use sqlutil; my $sql = new sqlutil; use CGI; my $cgi = new CGI; my $Q = $cgi->import_names('Q'); my $loginuser = $ENV{'REMOTE_USER'}; die unless -x $_sendmail; # do the real work, but trap any errors eval '&main'; # if an error has occured, log it to stdout if($@) { print "Content-type: text/html\n\n"; print "
".`env`.""; $cgi->import_names('Q'); print "
© 2003 Christoph Haas - ';
print '";
print "$domain
\n";
my %pop3boxes = &get_pop3boxes($domain);
print "POP3 accounts
";
if (%pop3boxes)
{
print "
| User name"; for my $pop3 (sort keys %pop3boxes) { print " | ||
|---|---|---|
| $pop3"; print ' | Remove'; print ' | Change password'; } print " |
| Email address"; print " | will be forwarded to..."; for my $forward (sort keys %emailforwards) { my @printforwards=split(/,/,$emailforwards{$forward}); for $_ ( @printforwards ) { $_ = &nice_emailtarget($_); } print ' | ||
|---|---|---|---|
| '.$forward; print ' | '.join(' ',@printforwards); print ' | Delete'; # todo #print ' | Change'; } print " |
| Email address"; print ' | |
|---|---|
| '.&nice_emailtarget(&email_default($domain)); print ' | Change'; print " |
| Email address: | "; print $cgi->textfield ( -name=>'username', -size=>20, -maxlength=>20 ); print "\@$Q::domain"; print " |
This email address is already in use. Please choose another one.
"; &action_newpop3; return; } print "Email address is invalid. Please retry.
"; &action_newpop3; return; } # Create a random password my $passwort = &zufalls_passwort; # Create account in the 'users' table $sql->sql_doit( 'insert into users (email,password,maildir,homedir) values (?,encrypt(?),?,?)', "$Q::username\@$Q::domain", $passwort, "$Q::username\@$Q::domain/", $_vmaildir ); # Create account in the 'virtual' table $sql->sql_doit( 'insert into virtual (email,destination) values (?,?)', "$Q::username\@$Q::domain", "$Q::username\@$Q::domain", ); # Send a welcome mail to this account to get the mailbox created open (MAIL, "|$_sendmail -t") or die; { print MAIL "From: Administrator| Email address:"; print " | $Q::username\@$Q::domain"; print " |
| User name:"; print " | $Q::username\@$Q::domain"; print " |
| Password:"; print " | $passwort"; print " |
| POP3 server:"; print " | pop.$Q::domain"; #print " |
| Web mail access:"; #print " | https://ssl.$Q::domain/webmail/webmail"; print " |
The new email address can now be used.
"; print "The password for fetching email was changed to '$passwort'.
"; print "The email account is no longer accessible. However the email files \n"; print "are still on the server and can be fetched until the account is deleted \n"; print "from the hard disk. If you create a new POP3 account with the same \n"; print "email address the very same emails will be accessible again.
"; print ''; } # Create new email forwarding - print form sub action_newforward { # Security check... die "NOT YOUR DOMAIN!" unless &own_domain($Q::domain); print "This function allows you to create email addresses that will "; print "automatically forward email to another external email address "; print "or a local POP3 mailbox. You can name more than one target. "; print "Each recipient will receive a copy of the email then. However "; print "you do not need to fill all fields.
"; print $cgi->startform; $cgi->param('action','newforward2'); print $cgi->hidden('action'); print $cgi->hidden('domain'); print "| Email address: | "; print $cgi->textfield ( -name=>'from', -size=>20, -maxlength=>20 ); print "\@$Q::domain"; for ( 1 .. 9 ) { print " |
| is forwarded to email address ($_): | "; print $cgi->textfield ( -name=>'toemail'.$_, -size=>50, -maxlength=>50 ); } #print " |
| ...oder..."; #print " | |
| weiterleiten an POP3-Mailbox: | "; #my %pop3boxes = &get_pop3boxes($Q::domain); #my @pop3boxes = keys %pop3boxes; #unshift @pop3boxes, '-'; #print $cgi->popup_menu #( # -name=>'topop3', # -values=>[@pop3boxes] #); print " |
This email address is already in use. Please choose another one.
"; &action_newforward; return; } # Valid user name? if ( $Q::from !~ /^[\w\.-]+$/ ) { print "Email address invalid. Please retry.
"; &action_newforward; return; } # Forwarding given? my @forward; for ( 1 .. 9 ) { my $to = $cgi->param('toemail'.$_); if ( $to && $to !~ /^.+\@.+\...+/ ) { print "Forwarding address $_ invalid. Please retry.
"; &action_newforward; return; } push @forward,$to if $to; } ##print "All emails directed to '$Q::from' will now be forwarded to "; print "these recipients:
"; print "All emails directed to '$Q::forward' will no longer be forwarded.
"; print "The default forwarding defines who gets emails directed to "; print "this domain if there are no other email addresses specified. "; print "If there is no default forwarding then other mails will be "; print "rejected.
"; print $cgi->startform; $cgi->param('action','newcatchall2'); print $cgi->hidden('action'); print $cgi->hidden('domain'); print "| Email address: | "; print $cgi->textfield ( -name=>'catchall', -size=>50, -maxlength=>50 ); print " |
All emails directed to the '$Q::domain' will be rejected unless "; print "there is a specific email address defined elsewhere.
"; } else { # Invalid user name? if ( $Q::catchall !~ /^.+\@.+\...+/ ) { print "Email address invalid. Please retry.
"; &action_newcatchall; return; } print "All emails directed to the '$Q::domain' will be sent to "; print "'$Q::catchall' unless there is a specific email address "; print "defined elsewhere.
"; } print "This function allows you to create email addresses that will "; print "automatically forward email to another external email address "; print "or a local POP3 mailbox. You can name more than one target. "; print "Each recipient will receive a copy of the email then. However "; print "you do not need to fill all fields.
"; my $qhandle = $sql->sql_query("select * from virtual where email=?", $Q::forward ); my $destinations; if (my $entry = $sql->sql_result($qhandle)) { $destinations = $entry->{destination}; } else { die; } # Pre-set CGI fields with default forwardings my $i=1; for ( split /,/ , $destinations ) { $cgi->param('toemail'.$i , $_); #print "| Email address: | "; print $Q::forward; for ( 1 .. 9 ) { print " |
| will be forwarded to email address ($_): | "; print $cgi->textfield ( -name=>'toemail'.$_, -size=>50, -maxlength=>50 ); } print " |