LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 598|回复: 1

通过qmailadmin来实现qmail下的域空间设置

[复制链接]
发表于 2004-8-11 21:18:11 | 显示全部楼层 |阅读模式
转自
http://anti-spam.org.cn/

功能说明:

针对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&nbsp;##X502 ##Q&nbsp;&nbsp;

在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);
}
}
 楼主| 发表于 2004-8-11 21:20:16 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表