使用extman+extmail作为企业邮箱,如果需要添加某个邮箱对外域邮件的收发限制,那么需要对extman做一下相应的二次开发修改。默认开源方案没有这个功能,下面介绍一下如何增加这个功能。
1.修改/etc/postfix/main.cf文件,增加如下行
smtpd_restriction_classes = allow_send allow_receive allow_send = check_recipient_access mysql:/etc/postfix/receiver_access,reject allow_receive = check_sender_access mysql:/etc/postfix/sender_access,reject
并在smtpd_recipient_restrictions 部分修改为如下
smtpd_recipient_restrictions = check_sender_access mysql:/etc/postfix/sender_class, (新增行) check_recipient_access mysql:/etc/postfix/receiver_class, (新增行) permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, check_policy_service inet:127.0.0.1:10030
2.创建如下四个文件(注:这四个文件中的password = 后面要改成你自己的数据库用户密码,)
vi /etc/postfix/sender_class user = extmail password = seaman hosts = localhost dbname = extmail table = sender_class select_field = class where_field = sender additional_conditions = and active = 1 vi /etc/postfix/receiver_access user = extmail password = seaman hosts = localhost dbname = extmail table = receiver_access select_field = action where_field = receiver vi /etc/postfix/receiver_class user = extmail password = seaman hosts = localhost dbname = extmail table = receiver_class select_field = class where_field = receiver additional_conditions = and active = 1 vi /etc/postfix/sender_access user = extmail password = seaman hosts = localhost dbname = extmail table = sender_access select_field = action where_field = sender
3.创建如下四个数据库表,并分别向receiver_access和sender_access表插入一条记录
mysql>use extmail; mysql> create table sender_class( sender varchar(255) NOT NULL default "", class varchar(255) NOT NULL default "", ctime datetime NOT NULL default '0000-00-00 00:00:00', active tinyint(1) NOT NULL default '0', primary key (sender), key sender(sender)); Query OK, 0 rows affected (0.00 sec) mysql> create table receiver_access( receiver varchar(255) NOT NULL default "", action varchar(255) NOT NULL default "", primary key (receiver), key receiver(receiver)); Query OK, 0 rows affected (0.01 sec) mysql> create table receiver_class(receiver varchar(255) NOT NULL default "", class varchar(255) NOT NULL default "", ctime datetime NOT NULL default '0000-00-0000:00:00', active tinyint(1) NOT NULL default '0', primary key (receiver), key receiver(receiver)); Query OK, 0 rows affected (0.07 sec) mysql> create table sender_access(sender varchar(255) NOT NULL default "",action varchar(255) NOT NULL default "", primary key (sender), key sender(sender)); Query OK, 0 rows affected (0.00 sec)
插入数据
mysql> insert into receiver_access values("szl724.com","ok"); 此处的szl724.com 是你的邮件地址域名 Query OK, 1 row affected (0.00 sec) mysql> insert into sender_access values("szl724.com","ok"); 此处的szl724.com 是你的邮件地址域名 Query OK, 1 row affected (0.00 sec)
4.修改/var/www/extsuite/extman/lang/zh_CN 文件
在第186行即 services => ‘允许的服务’, 下面添加如下两行
sentset => ‘发送设置’,
receiveset => ‘接收设置’,
在第201行即 tab_service => ‘功能设置’, 下面添加如下一行
tab_other => ‘其他设置’,
5.修改/var/www/extsuite/extman/html/default/edit_user.html 文件
将第57-60行改为如下:
<td class="tab-selected b2" id="tab1" onclick="SelectTab('4','1');"><%tab_basic%></td> <td class="tab b1" id="tab2" onclick="SelectTab('4','2');"><%tab_pwd%></td> <td class="tab b1" id="tab3" onclick="SelectTab('4','3');"><%tab_service%></td> <td class="tab b1" id="tab4" onclick="SelectTab('4','4');"><%tab_other%></td>
在183行下添加如下内容
<div class="content" id="tbContent4" style="display: none"> <table cellspacing=0 cellpadding=5 border=0 class=etb> <tr> <td><%sentset%> </td><td><!-- IF LOCAL2EXTERNAL --><input type=radio name=sentset value="0" checked>允许给外域邮箱发邮件 <input type= radio name=sentset value="1">禁止给外域邮箱发邮件<!-- ELSE --><input type=radio name=sentset value="0">允许给外域邮箱发邮件 <input type=radio name=sentset value="1" checked>禁止给外域邮箱发邮件<!-- END LOCAL2EXTERNAL --> </td> </tr> <tr> <td><%receiveset%> </td><td><!-- IF EXTERNAL2LOCAL --><input type=radio name=receiveset value="0" checked>允许接收外域邮箱发来的邮件 <input type=radio name=receiveset value="1">禁止接收外域邮箱发来的邮件<!-- ELSE --><input type=radio name=receiveset value="0">允许接收外域邮箱发来的邮件 <input type=radio name=receiveset value="1" checked>禁止接收外域邮箱发来的邮件<!-- END EXTERNAL2LOCAL --></td> </tr> </table> </div>
6.修改vi /var/www/extsuite/extman/libs/Ext/MgrApp/User.pm 文件
在第92行即 GID => $sys->{SYS_DEFAULT_GID},这行后,添加如下两行:
LOCAL2EXTERNAL => 1, EXTERNAL2LOCAL => 1,
在第140行即my $ui = $mgr->get_user_info($user); 这行后,添加如下两行:
my $ui2 = $mgr->get_sender_class($user);
my $ui3 = $mgr->get_receiver_class($user);
在第171行即ANSWER => $ui->{answer},这行后,添加如下两行:
LOCAL2EXTERNAL => defined($ui2) ? $ui2->{active} : 1, EXTERNAL2LOCAL => defined($ui3) ? $ui3->{active} : 1,
在第269行即answer => $q->cgi(‘answer’),这行后,添加如下两行:
sentset => $q->cgi('sentset') ? 1 : 0, receiveset => $q->cgi('receiveset') ? 1 : 0,
在第346行即 answer => $q->cgi(‘answer’),这行后,添加如下两行:
sentset => $q->cgi('sentset') ? 1 : 0, receiveset => $q->cgi('receiveset') ? 1 : 0,
7. 修改vi /var/www/extsuite/extman/libs/Ext/Mgr/MySQL.pm 文件
修改sub add_user{} 子程序,在该子程序的尾部
if ($db->err) { return $db->errstr; } else { return 0; }
这一部分的前面,添加如下内容:
if ($opt{sentset}){
my $sth3 = $db->prepare(“INSERT INTO sender_class(
sender,
class,
ctime,
active) VALUES (?,?,?,?)”);
$sth3->execute(
“$opt{mail}”,
“allow_send”, 注:allow_send 是你在postfix的main.cf 配置文件里自定义的规范等级
“$opt{create}”,
“1”,
);
}
if ($opt{receiveset}){
my $sth4 = $db->prepare(“INSERT INTO receiver_class(
receiver,
class,
ctime,
active) VALUES (?,?,?,?)”);
$sth4->execute(
“$opt{mail}”,
“allow_receive”, 注:allow_receive 是你在postfix的main.cf 配置文件里自定义的规范等级
“$opt{create}”,
“$opt{receiveset}”,
);
}
修改sub delete_user {} 子程序,在该子程序的尾部
if ($db->err) {
return $db->errstr;
} else {
return 0;
}
这一部分的前面,添加如下内容:
my $sth2 = $db->prepare(“DELETE FROM sender_class where sender=?”);
$sth2->execute($user);
my $sth3 = $db->prepare(“DELETE FROM receiver_class where receiver=?”);
$sth3->execute($user);
修改sub modify_user 子程序,在该子程序的尾部
if ($db->err) {
return $db->errstr;
} else {
return 0;
}
这一部分的前面,添加如下内容:
my $sth2 = $db->prepare(“REPLACE INTO sender_class(
sender,
class,
ctime,
active) VALUES (?,?,now(),?)”);
$sth2->execute(
“$opt{user}”,
“allow_send”,
“$opt{sentset}”,
);
my $sth3 = $db->prepare(“REPLACE INTO receiver_class(
receiver,
class,
ctime,
active) VALUES (?,?,now(),?)”);
$sth3->execute(
“$opt{user}”,
“allow_receive”,
“$opt{receiveset}”,
);
在sub get_manager_info {} 子程序的后面添加如下内容:
sub get_sender_class {
my $self = shift;
my $user = $_[0];
my $SQL = “SELECT * FROM sender_class where sender = ? and active = 1”;
my $ref = $self->get_entry($SQL,$user);
return undef unless($ref);
return {
sender => $ref->{sender},
class => $ref->{class},
active => $ref->{active} ? 0 : 1,
}
}
sub get_receiver_class {
my $self = shift;
my $user = $_[0];
my $SQL = “SELECT * FROM receiver_class where receiver = ? and active =1”;
my $ref = $self->get_entry($SQL,$user);
return undef unless($ref);
return {
receiver => $ref->{receiver},
class => $ref->{class},
active => $ref->{active} ? 0 : 1,
}
}
修改这些之后就可以了。