- 论坛徽章:
- 0
|
3) 下载qmailadmin最新版本
===============================================================================
参考网站: http://sourceforge.net/project/showfiles.php?group_id=6691
cd /usr/local/src/qmail/qmailadmin/;
wget http://jaist.dl.sourceforge.net/ ... admin-1.2.11.tar.gz;
tar -zxvf qmailadmin-1.2.11.tar.gz;
cd qmailadmin-1.2.11;
请注意: qmailadmin-1.2.11依然还不支持Domain Quota的动态分配和域名用户的自行調整,因此我们必须在configure之前手工修改原程序才能支持.关于修改的方法,请参考下一步骤所介绍的方法.為了簡化qmailadmin的安裝過程, 我將已經成功安裝的資源打包成一個名為qmailadmin-1.2.11.fixquota.tar.gz的壓縮檔案,可以直接使用.(若不想自己動手修改,就可以忽略下述第4步驟,直接跳到第5步驟開始安裝).
===============================================================================
4) 修改Domain Quota限制;
===============================================================================
qmailadmin源程序无法控制Domain Quota,邮件帐户可以设置任意大小的限制值而不受总Quota的控制.如要限制邮件帐户的Quota数值不能大于总的Domain Quota值,就必须在编译之前先修改qmailadmin的源程序.
-------------------------------------------------------------------------------
(a)如下是所需要修改的档案清单:
-------------------------------------------------------------------------------
所需修改的使用界面为:
html/add_user.html
html/mod_user.html
html/show_users.html
所需修改的各种语言的信息定义变量:
lang/en #英文语言的信息变量定义
lang/zh-cn #简体中文(gb2312)的信息变量定义
所需修改的原程序文件为:
limits.c
qmailadmin.c
qmailadminx.h
template.c
user.c #请注意新版中部分函数改名和参数调动问题
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
(b)修改使用界面;
-------------------------------------------------------------------------------
vi html/add_user.html; #第44行需添加支持Quota的标记:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<td align="left"><input type="text" size="16" name="quota" maxlength="128"> ##X901##+ ##X902##-</td>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi html/mod_user.html; #第98行(旧版为118行)改为如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##X901##+ ##X902##-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi html/show_users.html; #第42行改为如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##X901##+ ##X902##-[
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
请注意: 上述修改使用了+和-做Quota的标记,是因为新版(qmailadmin-1.2.11)在其源程序(template.c)中已经使用了所有英语符号来做标记,所以必须使用别的符号来做配额的标记.我们这里选择用+(Domain Quota)和-(Used Quota)来做标记,也就是在template.c中CASE中选择了+和-来标记相关限额,上述修改中的所有涉及这个标记的修改,均是为了配合template.c中的修改.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
(c) 修改各种语言的信息定义变量:
-------------------------------------------------------------------------------
vi lang/en; #最后面添加五行如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
901 Whole storage:
902 Applied storage:
903 Over storage quota
904 Whole storage was totally used
905 setted storage must larger than the used storage
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi lang/zh-cn; #参照说明补充两行,在最后面添加5行如下(注意用简体中文字):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
316 修改密码
317 你不能删除管理者帐户
#上述两个定义参照lang/en中的定义(可能原程序遗漏了):
901 整个域总容量:
902 已分配容量:
903 设置的容量超过可用容量
904 已分配的容量已达到整个域总容量
905 设置的容量一定要大于已使用容量
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
如果要修改其他所有语言信息定义文件,可以先建立一个lang_fixquota.patch文件:
vi lang_fixquota.patch;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
901 Whole storage:
902 Applied storage:
903 Over storage quota
904 Whole storage was totally used
905 setted storage must larger than the used storage
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
然后用 cat 命令将lang_fixquota.patch文件的内容添加到相关文件中:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cat fixquota.patch >> bg;
cat fixquota.patch >> cs;
cat fixquota.patch >> da;
cat fixquota.patch >> de;
cat fixquota.patch >> es;
cat fixquota.patch >> fi;
cat fixquota.patch >> fr;
cat fixquota.patch >> hu;
cat fixquota.patch >> it;
cat fixquota.patch >> ja;
cat fixquota.patch >> lt;
cat fixquota.patch >> nl;
cat fixquota.patch >> no;
cat fixquota.patch >> pl;
cat fixquota.patch >> pt-br;
cat fixquota.patch >> ru;
cat fixquota.patch >> sk;
cat fixquota.patch >> sv;
cat fixquota.patch >> tr;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
请注意: 上述语言信息定义格式采用阵列形式,左边数字是索引,右边文字为解释;在源程序中,语言信息定义是用阵列html_text[]来储存,因为新版qmailadmin改用数字来做索引,而且源程序中所定义的阵列长度是350。如果新添加的信息定义的索引数字大于350(例如我们上述所添加的索引数字为901,902,903,904 和 905,均大于350), 在某些系统下可能无法正确储存阵列(取决于C语言的编译特性),由此而导致调用到此语言定义信息的相关页面无法正常显示,因此需要修正(增大)阵列长度.
vi qmailadmin.h; #此头文件定义系统环境变数
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#define MAX_LANG_STR 350 // 找到定义MAX_LANG_STR的此行;
#define MAX_LANG_STR 950 // 将350修改为950;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
(d) 在limits.c, qmailadmin.c和qmailadminx.h中增加变量定义;
-------------------------------------------------------------------------------
vi limits.c; (旧程序46行附近插入如下行
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DefaultDomainQuota = Limits.diskquota;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi qmailadmin.c; (旧程序82行附近插入如下行
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int DefaultDomainQuota;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vi qmailadminx.h; (旧程序61行附近插入如下行
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern int DefaultDomainQuota;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
(e) 修改template.c源程序;
-------------------------------------------------------------------------------
vi template.c;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(e.1) 第41行处增加一行如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include "qmailadmin.h"
#include "qmailadminx.h"
#define NOLIMIT_STR get_html_text("229") #这是插入的新行
static char dchar[4];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(e.2) 第53行处增加一行如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static char NTmpBuf[500];
float count_users_quota(); #这是插入的新行
/*
* send an html template to the browser
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(e.3) 第79行处增加一行如下(send_template_now子函数):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
struct vqpasswd *vpw;
char value[MAX_BUFF];
float UsedQuota = (count_users_quota())/1048576.0; #这是插入的新行
if (strstr(filename, "/")!= NULL||strstr(filename,"..")!=NULL) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(e.4) 第578行处增加两个case(+和-)共16行,因为新版(qmailadmin-1.2.11)其源程序中已
经使用了所有文字符号来做标记,所以必须使用别的符号来做配额的标记.例如用+(Domain
Quota)和-(Used Quota)来做标记:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case '+': #这是新增加的case
{
if (DefaultDomainQuota > 0) {
fprintf(actout, "%dM", DefaultDomainQuota);
} else {
fprintf(actout, "%s", NOLIMIT_STR);
}
}
break;
case '-': #这是新增加的case
{
if (UsedQuota > 0.0) fprintf(actout, "%-2.2lfM", UsedQuota);
else fprintf(actout, "%s", NOLIMIT_STR);
}
break;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
提示: 可用如下的grep命令可查看当前版本中使用了那些符号作标记: grep 'case' template.c;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
(f) 修改user.c源程序;
-------------------------------------------------------------------------------
(f.1) 第56行处增加一行如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#endif
float count_users_quota(); #这是插入的新行
int show_users(char *Username, char *Domain, time_t Mytime)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(f.2) 第333行处(adduser()子函数)需增加一个变量和IF条件语句如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) {
sprintf(StatusMessage, sizeof(StatusMessage), "%s %d\n", html_text[199],
MaxPopAccounts);
show_menu(Username, Domain, Mytime);
vclose();
exit(0);
}
#这是插入的变量和IF条件语句开始处
float UsedQuota = count_users_quota();
if ((DefaultDomainQuota > 0 && UsedQuota) >= (DefaultDomainQuota*1048576.0)) {
snprintf (StatusMessage, sizeof(StatusMessage), "%s %dM\n", html_text[904],
DefaultDomainQuota);
show_menu(Username, Domain, Mytime);
vclose();
exit(0);
}
#这是新插入的IF条件的结束处
send_template( "add_user.html" );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
说明: 在旧版本中用get_html_text("###")函数来调用语言定义信息,show_menu()也无须
参数;但在新版本中,则用html_text[###]数组来储存语言定义信息,而且show_menu()函数
也带有三个参数,变为show_menu(Username, Domain, Mytime).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(f.3) 第391行处(addusernow()子函数)需增加一个变量和IF条件语句如下:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if ( MaxPopAccounts != -1 && CurPopAccounts >= MaxPopAccounts ) {
sprintf(StatusMessage, sizeof(StatusMessage), "%s %d\n", html_text[199],
MaxPopAccounts);
show_menu(Username, Domain, Mytime);
vclose();
exit(0);
}
#这是插入的变量和IF条件语句如下
float UsedQuota = count_users_quota();
if ((DefaultDomainQuota > 0) && (UsedQuota >= (DefaultDomainQuota*1048576.0))) {
sprintf(StatusMessage, sizeof(StatusMessage), "%s %dM\n", html_text[904],
DefaultDomainQuota);
show_menu(Username, Domain, Mytime);
vclose();
exit(0);
}
#这是新插入的IF条件的结束处
GetValue(TmpCGI,Newu, "newu=", sizeof(Newu));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(f.4) 第409行(addusernow()子函数)需增加一个IF条件语句如下
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Coded added by jhopper
#ifdef MODIFY_QUOTA
GetValue(TmpCGI, Quota, "quota=", sizeof(Quota));
#如下是新插入的行开始处,这是一个IF条件语句:
if ((atof(Quota) > 0.0) && (atof(Quota) <= 500.0)) {
if (quota_to_bytes(qconvert, Quota)) {
sprintf(StatusMessage, html_text[314"));
adduser();
vclose();
exit(0);
} else if ((UsedQuota + (atof(Quota)*1048576.0)) > (DefaultDomainQuota*1048576.0)) {
sprintf(StatusMessage, html_text[903"));
adduser();
vclose();
exit(0);
}
} else {
sprintf(StatusMessage, html_text[307"));
adduser();
vclose();
exit(0);
}
#这是新插入的IF条件语句的结束处:
#endif
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(f.5) 第503行需注释掉一个sprintf函数
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* report success */
/* snprinth (StatusMessage, sizeof(StatusMessage), "%s %H@%H (%H) %s",
html_text[2], Newu, Domain, Gecos,
html_text[119]);
*/
} else {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(f.6) 第785行处需修改多行程序,修改后如下 可将整个#ifdef - #endif 替换掉)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#ifdef MODIFY_QUOTA
/* strings used: 307 = "Invalid Quota", 308 = "Quota set to unlimited",
* 309 = "Quota set to %s bytes"
*/
if (AdminType == DOMAIN_ADMIN) {
GetValue(TmpCGI, Quota, "quota=", sizeof(Quota));
vpw = vauth_getpw(ActionUser, Domain);
if ((strlen(Quota) == 0) || (strcmp (vpw->pw_shell, Quota) == 0)) {
/* Blank or no change, do nothing */
} else if ((atof(Quota) > 0.0) && (atof(Quota) <= 500.0)) {
quotaptr = Quota;
if (quota_to_bytes(qconvert, quotaptr)) {
sprintf(StatusMessage, html_text[307"));
} else if(strcmp(qconvert, vpw->pw_shell)==0) {
/* unchanged, do nothing */
} else {
float UsedQuota = count_users_quota();
vpw = vauth_getpw(ActionUser, Domain);
float OldQuota = (atof(vpw->pw_shell));
char path[256];
long diskquota = 0, maxmsg = 0;
snprintf(path, sizeof(path), "%s/Maildir", vpw->pw_dir);
readuserquota(path, &diskquota, &maxmsg);
if ((float)diskquota >= (atof(Quota)*1048576.0)) {
sprintf(StatusMessage, html_text[905"));
} else {
if ((UsedQuota - OldQuota + (atof(Quota)*1048576.0)) > DefaultDomainQuota*1048576.0) {
sprintf(StatusMessage, html_text[903"));
} else if(vsetuserquota( ActionUser, Domain, qconvert )) {
sprintf(StatusMessage, html_text[307"));
} else {
sprintf(StatusMessage, html_text[309], qconvert);
}
}
}
} else {
sprintf(StatusMessage, html_text[307"));
}
}
#endif
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(f.7) 第1013行(最后面)增加一个函数
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float count_users_quota()
{
struct vqpasswd *pw;
float ret = 0.0;
pw = vauth_getall(Domain,1,0);
while(pw!=NULL){
if (strcmp(pw->pw_shell, "NOQUOTA") == 0) return -1.0;
ret += atof(pw->pw_shell);
pw = vauth_getall(Domain,0,0);
}
return ret;
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-------------------------------------------------------------------------------
请注意: 对于上述修改,我用diff命令(带 -ruN参数)做了一个patch档案,(请参考附录资源中的qmailadmin-1.2.11.fixquota.patch文档), 若有朋友嫌自己动手修改源程序麻烦, 也可以直接用下载此patch来使用.另外:Qmailadmin有关Quota限额的C源程序存在一个小小的BUG,它无法正确显示限额数值大于2048的数字(所有大于2048的数值都显示为2048),虽然真正有效的限额数值可以大于2048,但這個错误的显示却会使人相当困扰。 |
|