对于很多企业邮局提供商,他们提供了邮件空间这个服务。就是说企业可以买一定大小的邮件空间。自己可以任意的在指定大小的空间中任意添加、删除、修改用户。但是,总空间大小一定。这对于企业来说,是非常方便的。
一般提供这种功能的邮件,都是大型的商业邮件系统,但是qmail也完全可以实现。在这里,我是修改了qmailadmin,来实现这个功能的。我提供的只是一个初级的模型,大家可以自己再优化。这个软件的作者,是我的好朋友gadfly,感谢他的无私帮助。希望大家能受到一些启发,作出更好的程序。这样的话,也给我一份。:)
btw:这个软件我用了很长时间了,大家可以放心,经过我无数次测试和使用的。
功能说明:
针对qmailadmin-1.0.6
1、能够显示总共的域空间和已使用空间。现在只在修改用户(mod_user.html)和(add_user.html)中显示这个信息。
如要其它地方显示,只要将这行:
##x501 ##q ##x502 ##q
加到你想要的地方就可以。
2、在增加用户中,邮箱大小可以有缺省值,由.qmailadmin-limits中的default_quota决定,单位是字节
3.增加了域空间的限制,在.qmailadmin-limits中的参数default_domain_quota,以m为单位
4.在增加用户和修改用户中,会判断域限制。如果有这个限制,用户的大小设置就必须>0。如果没有,舍为<0时,
就是无限制。
安装方法。
1、将domain_quota.tgz放到qmailadmin的源码目录下, 这个目录必须先configure过,
# tar xzvf domain_quota.tgz
#make
2、将qmailadmin, en-us, mod_user.html, add_user.html覆盖相应的文件。
3、设置.qmailadmin-limits的各个参数。
4、测试qmailadmin. ok!
.qmailadmin-limits
增加一个参数
default_domain_quota: 以m为单位
修改en-us,500以后是新加的。
修改*user.html
1.显示已用空间和总空间
mod_user.html和add_user.html增加一下一行
##x501 ##q ##x502 ##q
在qmailadmin.h中增加:
#define byte2m(size) size/1048576
extern char defaultdomainquota[max_buff];
extern char defaultquota[max_buff];
在limits.c中增加
memset(defaultdomainquota, 0, max_buff);
else if ( strncmp(tmpstr, "default_domain_quota", 20) == 0 ) {
tmpstr = strtok(null," :\t\n");
if (tmpstr==null) continue;
strncpy(defaultdomainquota, tmpstr, max_buff);
}
在qmailadmin.c中增加:
char defaultdomainquota[max_buff];
在user.c中增加
/**
* @return: size m, if return value == -1, no limit.
*/
#define byte2m(size) size/1048576
int count_users_quota()
{
struct vqpasswd *pw;
int ret = 0;
pw = vauth_getall(domain,1,0);
while(pw!=null){
if (strcmp(pw->pw_shell, "noquota") == 0) return -1;
ret += byte2m(atol(pw->pw_shell));
pw = vauth_getall(domain,0,0);
}
return ret;
}
在template.c中增加
case q:
{
if (defaultdomainquota[0]) {
fprintf(actout, "%sm", defaultdomainquota);
} else {
fprintf(actout, "%s", nolimit_str);
}
}
break;
case q:
{
int usedquota = count_users_quota();
if (usedquota > -1) fprintf(actout, "%dm", usedquota);
else fprintf(actout, "%s", nolimit_str);
}
break;
2.增加和修改个人用户的时候,显示大小限制。
template.c中
在send_template_now中增加
case r:
{
if (defaultquota[0]) fprintf(actout, "%d", byte2m(atol(defaultquota)));
}
在check_user_forward_vacation中增加
if ( newchar==8) {
if (strcmp(vpw->pw_shell, "noquota") == 0) {
fprintf(actout, "%s", nolimit_str);
} else {
fprintf(actout, "%d", byte2m(atol(vpw->pw_shell)));
}
return;
}
3.增加用户中,设置邮箱大小
qmailadmin.c 增加
char quota[max_buff];
memset(quota,0, max_buff);
qmailadmin.h
#define byte2m(size) size/1048576
#define m2byte(size) size*1048576
extern char defaultdomainquota[max_buff];
extern char defaultquota[max_buff];
extern char quota[max_buff];
user.c 函数addusernow中增加
int user_quota;
getvalue(tmpcgi, quota, "quota=", max_buff);
user_quota = atoi(quota);
if (defaultdomainquota[0]) {
int used_quota = count_users_quota();
if ( (user_quota <= 0) || (used_quota < 0) ||
(used_quota + user_quota > atoi(defaultdomainquota)) ) {
sprintf(statusmessage, "%s\n", get_html_text("504"));
adduser();
vclose();
exit(0);
}
}
/* changed by gadfly@163.com.
if( defaultquota[0]!= 0 ) mypw->pw_shell = defaultquota;
*/
if( user_quota > 0 ) {
sprintf(quota, "%d", m2byte(user_quota));
mypw->pw_shell = quota;
}
4.修改用户中,设置邮件大小,
user.c 函数modusergo中增加
int user_quota = 0;
int old_quota = 0;
getvalue(tmpcgi, quota, "quota=", max_buff);
user_quota = atoi(quota);
old_quota = byte2m(atoi(vpw->pw_shell));
if (defaultdomainquota[0]) {
int used_quota = count_users_quota();
if ( (user_quota <= 0) || (used_quota < 0) ||
(used_quota + user_quota - old_quota > atoi(defaultdomainquota)) ) {
sprintf(statusmessage, "%s\n", get_html_text("504"));
moduser();
vclose();
exit(0);
}
}
if (old_quota != user_quota) {
if (user_quota < 0) vauth_setquota(actionuser, domain, "noquota");
else {
sprintf(quota, "%d", m2byte(user_quota));
vauth_setquota(actionuser, domain, quota);
}
}
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!


