Duplicate...
Here's a patch to fix the ".00" in the quotas
as well as migrate the limits stuff to use the vget_limits() API.
I've also updated the quotas to use maildir++ quotas rather
than a du (recursive stat()'s). The old functions that actually
calculate the system quotas is still in there but commented out.
I'm not sure if you wanted to make a configure script to choose
one or the other, but I figured that vdelivermail uses maildir++
quotas to enforce the limit, so the maildir++ quotas may be the
way to go.
There's now a global called Limits that contains all the limits.
In load_limits() it now just fills in the old globals with
the values in the Limits structure. In the future, we can
replace the dozen or so globals to use the Limits structure.
Currently, there's no place to display the domain quota.
Where do you think it should go? On the main menu? Do you
think another template variable should be used for the
domain quota? We could then place it anywhere on any
template.
This patch requires the latest vpopmail distribution (5.3.19) to
work since it uses the maildir++ quota routines just added.
There's still alot to do with admin permissions & such, but
I just don't have the cycles lately. Got to make $$...
Brian
Common subdirectories: qmailadmin-1.0.12/html and qmailadmin-1.0.12.new/html
Common subdirectories: qmailadmin-1.0.12/images and qmailadmin-1.0.12.new/images
diff -c qmailadmin-1.0.12/limits.c qmailadmin-1.0.12.new/limits.c
*** qmailadmin-1.0.12/limits.c Tue Aug 6 18:04:59 2002
--- qmailadmin-1.0.12.new/limits.c Fri Mar 7 12:37:51 2003
***************
*** 34,110 ****
load_limits()
{
! FILE *fs;
! char *tmpstr;
! MaxPopAccounts = DEFAULT_MAX_POP_USERS;
! MaxAliases = DEFAULT_MAX_ALIASES;
! MaxForwards = DEFAULT_MAX_FORWARDS;
! MaxAutoResponders = DEFAULT_MAX_AUTORESPONDERS;
! MaxMailingLists = DEFAULT_MAX_MAILINGLISTS;
! DisablePOP = 0;
! DisableIMAP = 0;
! DisableDialup = 0;
! DisablePasswordChanging = 0;
! DisableWebmail = 0;
! DisableRelay = 0;
! memset(DefaultQuota, 0, MAX_BUFF);
!
! if ( (fs=fopen(".qmailadmin-limits","r"))==NULL) {
! return(0);
! }
!
! while( fgets(TmpBuf, MAX_BUFF, fs) != NULL ) {
! tmpstr = strtok(TmpBuf, LIMIT_TOKENS);
! if ( tmpstr == NULL ) continue;
!
! if ( strncmp(tmpstr, "maxpopaccounts", 14 ) == 0 ) {
! tmpstr = strtok(NULL," :\t\n");
! if (tmpstr==NULL) continue;
! MaxPopAccounts = atoi(tmpstr);
!
! } else if ( strncmp(tmpstr, "maxaliases", 10 ) == 0 ) {
! tmpstr = strtok(NULL,LIMIT_TOKENS);
! if (tmpstr==NULL) continue;
! MaxAliases = atoi(tmpstr);
!
! } else if ( strncmp(tmpstr, "maxforwards", 11 ) == 0 ) {
! tmpstr = strtok(NULL,LIMIT_TOKENS);
! if (tmpstr==NULL) continue;
! MaxForwards = atoi(tmpstr);
!
! } else if ( strncmp(tmpstr, "maxautoresponders", 17 ) == 0 ) {
! tmpstr = strtok(NULL,LIMIT_TOKENS);
! if (tmpstr==NULL) continue;
! MaxAutoResponders = atoi(tmpstr);
!
! } else if ( strncmp(tmpstr, "maxmailinglists", 15 ) == 0 ) {
! tmpstr = strtok(NULL,LIMIT_TOKENS);
! if (tmpstr==NULL) continue;
! MaxMailingLists = atoi(tmpstr);
!
! } else if ( strncmp(tmpstr, "disable_pop", 11 ) == 0 ) {
! DisablePOP = 1;
!
! } else if ( strncmp(tmpstr, "disable_imap", 12 ) == 0 ) {
! DisableIMAP = 1;
!
! } else if ( strncmp(tmpstr, "disable_dialup", 14 ) == 0 ) {
! DisableDialup = 1;
!
! } else if (strncmp(tmpstr,"disable_password_changing",24)==0){
! DisablePasswordChanging = 1;
!
! } else if ( strncmp(tmpstr, "disable_webmail", 15 ) == 0 ) {
! DisableWebmail = 1;
!
! } else if (strncmp(tmpstr,"disable_external_relay",22)==0) {
! DisableRelay = 1;
!
! } else if ( strncmp(tmpstr, "default_quota", 13 ) == 0 ) {
! tmpstr = strtok(NULL," :\t\n");
! if (tmpstr==NULL) continue;
! strncpy(DefaultQuota, tmpstr, MAX_BUFF);
! }
! }
}
--- 34,50 ----
load_limits()
{
! vget_limits(Domain, &Limits);
! MaxPopAccounts = Limits.maxpopaccounts;
! MaxAliases = Limits.maxaliases;
! MaxForwards = Limits.maxforwards;
! MaxAutoResponders = Limits.maxautoresponders;
! MaxMailingLists = Limits.maxmailinglists;
! DisablePOP = Limits.disable_pop;
! DisableIMAP = Limits.disable_imap;
! DisableDialup = Limits.disable_dialup;
! DisablePasswordChanging = Limits.disable_passwordchanging;
! DisableWebmail = Limits.disable_webmail;
! DisableRelay = Limits.disable_relay;
}
diff -c qmailadmin-1.0.12/qmailadmin.c qmailadmin-1.0.12.new/qmailadmin.c
*** qmailadmin-1.0.12/qmailadmin.c Thu Feb 27 15:38:17 2003
--- qmailadmin-1.0.12.new/qmailadmin.c Fri Mar 7 12:35:39 2003
***************
*** 28,33 ****
--- 28,34 ----
#include "qmailadmin.h"
#include <vpopmail.h>
#include <vauth.h>
+ #include <vlimits.h>
char Username[MAX_BUFF];
char Domain[MAX_BUFF];
***************
*** 62,67 ****
--- 63,69 ----
FILE *lang_fs;
FILE *color_table;
+ struct vlimits Limits;
int AdminType;
int MaxPopAccounts;
int MaxAliases;
***************
*** 75,81 ****
int DisablePasswordChanging;
int DisableWebmail;
int DisableRelay;
- char DefaultQuota[MAX_BUFF];
int CurPopAccounts;
int CurAliases;
--- 77,82 ----
diff -c qmailadmin-1.0.12/qmailadmin.h qmailadmin-1.0.12.new/qmailadmin.h
*** qmailadmin-1.0.12/qmailadmin.h Fri Jan 24 17:25:31 2003
--- qmailadmin-1.0.12.new/qmailadmin.h Fri Mar 7 13:11:56 2003
***************
*** 48,54 ****
char *get_html_text( char *index );
int open_lang( char *lang);
- char *get_quota_used(char*); //jhopper prototype
int quota_to_bytes(char[], char*); //jhopper prototype
int quota_to_megabytes(char[], char*); //jhopper prototype
- off_t get_du(const char*); //bk prototype
--- 48,52 ----
diff -c qmailadmin-1.0.12/qmailadminx.h qmailadmin-1.0.12.new/qmailadminx.h
*** qmailadmin-1.0.12/qmailadminx.h Fri Oct 25 04:33:42 2002
--- qmailadmin-1.0.12.new/qmailadminx.h Fri Mar 7 12:46:38 2003
***************
*** 15,20 ****
--- 15,21 ----
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+ #include <vlimits.h>
extern char Username[MAX_BUFF];
extern char Domain[MAX_BUFF];
***************
*** 46,51 ****
--- 47,53 ----
extern int Compressed;
extern FILE *actout;
+ extern struct vlimits Limits;
extern int num_of_mailinglist;
extern int AdminType;
extern int MaxPopAccounts;
***************
*** 61,67 ****
extern int DisablePasswordChanging;
extern int DisableWebmail;
extern int DisableRelay;
- extern char DefaultQuota[MAX_BUFF];
extern int CurPopAccounts;
extern int CurAliases;
--- 63,68 ----
diff -c qmailadmin-1.0.12/template.c qmailadmin-1.0.12.new/template.c
*** qmailadmin-1.0.12/template.c Tue Feb 25 13:30:30 2003
--- qmailadmin-1.0.12.new/template.c Fri Mar 7 13:14:44 2003
***************
*** 57,63 ****
int testint;
char *tmpstr;
struct stat mystat;
- char *quotaptr;
char qconvert[11];
char *qnote = " MB";
--- 57,62 ----
***************
*** 197,203 ****
get_html_text("080"));
}
} else {
! // Code added by jhopper
struct vqpasswd *vpw;
vpw = vauth_getpw(Username, Domain);
--- 196,202 ----
get_html_text("080"));
}
} else {
! long diskquota, maxmsg;
struct vqpasswd *vpw;
vpw = vauth_getpw(Username, Domain);
***************
*** 207,219 ****
fprintf(actout,
"<font size=\"2\" color=\"#000000\"><b>%s %s</b></font></a><br><br>",
get_html_text("111"), Username);
- // Code added by jhopper
if (strncmp(vpw->pw_shell, "NOQUOTA", 2) != 0) {
quota_to_megabytes(qconvert, vpw->pw_shell); }
else { sprintf(qconvert, "unlimited"); qnote = ""; }
fprintf(actout, "<font size=\"2\"
color=\"#000000\"><b>Quota:</b><br>%s %s %s", get_html_text("253"), qconvert, qnote);
fprintf(actout, "<br>%s ", get_html_text("254"));
! quotaptr = get_quota_used(vpw->pw_dir);
! fprintf(actout, "%s MB</font><br>", quotaptr);
}
if (AdminType == DOMAIN_ADMIN) {
--- 206,217 ----
fprintf(actout,
"<font size=\"2\" color=\"#000000\"><b>%s %s</b></font></a><br><br>",
get_html_text("111"), Username);
if (strncmp(vpw->pw_shell, "NOQUOTA", 2) != 0) {
quota_to_megabytes(qconvert, vpw->pw_shell); }
else { sprintf(qconvert, "unlimited"); qnote = ""; }
fprintf(actout, "<font size=\"2\"
color=\"#000000\"><b>Quota:</b><br>%s %s %s", get_html_text("253"), qconvert, qnote);
fprintf(actout, "<br>%s ", get_html_text("254"));
! readuserquota(vpw->pw_dir, &diskquota, &maxmsg);
! fprintf(actout, "%-2.2lf MB</font><br>",
((double)diskquota)/1048576.0); /* Convert to MB */
}
if (AdminType == DOMAIN_ADMIN) {
diff -c qmailadmin-1.0.12/user.c qmailadmin-1.0.12.new/user.c
*** qmailadmin-1.0.12/user.c Thu Feb 27 19:19:08 2003
--- qmailadmin-1.0.12.new/user.c Fri Mar 7 13:14:54 2003
***************
*** 142,154 ****
(AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)))) {
if (AdminType==DOMAIN_ADMIN ||
(AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)) {
fprintf(actout, "<tr bgcolor=%s>", get_color_text("000"));
fprintf(actout, "<td align=\"left\">%s</td>", pw->pw_name);
fprintf(actout, "<td align=\"left\">%s</td>", pw->pw_gecos);
! // Code added by jhopper
! fprintf(actout, "<td align=\"right\">%s / </td>",
get_quota_used(pw->pw_dir));
if (strncmp(pw->pw_shell, "NOQUOTA", 2) != 0) {
if(quota_to_megabytes(qconvert, pw->pw_shell)) {
fprintf(actout, "<td align=\"left\">(BAD)</td>");
--- 142,155 ----
(AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)))) {
if (AdminType==DOMAIN_ADMIN ||
(AdminType==USER_ADMIN && strcmp(pw->pw_name,Username)==0)) {
+ long diskquota, maxmsg;
fprintf(actout, "<tr bgcolor=%s>", get_color_text("000"));
fprintf(actout, "<td align=\"left\">%s</td>", pw->pw_name);
fprintf(actout, "<td align=\"left\">%s</td>", pw->pw_gecos);
! readuserquota(pw->pw_dir, &diskquota, &maxmsg);
! fprintf(actout, "<td align=\"right\">%-2.2lf / </td>",
((double)diskquota)/1048576.0); /* Convert to MB */
if (strncmp(pw->pw_shell, "NOQUOTA", 2) != 0) {
if(quota_to_megabytes(qconvert, pw->pw_shell)) {
fprintf(actout, "<td align=\"left\">(BAD)</td>");
***************
*** 368,373 ****
--- 369,375 ----
int tmpint;
int error;
struct vqpasswd *mypw;
+ char pw_shell[256];
c_num = malloc(MAX_BUFF);
***************
*** 485,491 ****
if( DisablePasswordChanging > 0 ) mypw->pw_gid |= NO_PASSWD_CHNG;
if( DisableWebmail > 0 ) mypw->pw_gid |= NO_WEBMAIL;
if( DisableRelay > 0 ) mypw->pw_gid |= NO_RELAY;
! if( DefaultQuota[0]!= 0 ) mypw->pw_shell = DefaultQuota;
// Code added by jhopper
#ifdef MODIFY_QUOTA
--- 487,501 ----
if( DisablePasswordChanging > 0 ) mypw->pw_gid |= NO_PASSWD_CHNG;
if( DisableWebmail > 0 ) mypw->pw_gid |= NO_WEBMAIL;
if( DisableRelay > 0 ) mypw->pw_gid |= NO_RELAY;
! if (Limits.defaultquota > 0) {
! if (Limits.defaultmaxmsgcount > 0)
! snprintf(pw_shell, sizeof(pw_shell), "%dS,%dC", Limits.defaultquota,
Limits.defaultmaxmsgcount);
! else
! snprintf(pw_shell, sizeof(pw_shell), "%dS", Limits.defaultquota);
! mypw->pw_shell = pw_shell;
! } else {
! strcpy(pw_shell, "NOQUOTA");
! }
// Code added by jhopper
#ifdef MODIFY_QUOTA
Only in qmailadmin-1.0.12: user.c.orig
diff -c qmailadmin-1.0.12/util.c qmailadmin-1.0.12.new/util.c
*** qmailadmin-1.0.12/util.c Fri Jan 24 17:25:31 2003
--- qmailadmin-1.0.12.new/util.c Fri Mar 7 13:00:11 2003
***************
*** 252,257 ****
--- 252,258 ----
}
return("");
}
+ /* bk - use maildir++ quotas now
char *get_quota_used(char *dir) {
char *tmpstr;
char tmpbuff[MAX_BUFF];
***************
*** 265,270 ****
--- 266,272 ----
tmpstr = tmpbuff;
return tmpstr;
}
+ */
int quota_to_bytes(char returnval[], char *quota) {
char *tmpstr;
double tmp;
***************
*** 272,278 ****
if (quota == NULL) { return 1; }
if (tmp = atol(quota)) { tmp *= 1048576; }
else { return 1; }
! sprintf(returnval, "%-2.2lf", tmp);
return 0;
}
int quota_to_megabytes(char returnval[], char *quota) {
--- 274,280 ----
if (quota == NULL) { return 1; }
if (tmp = atol(quota)) { tmp *= 1048576; }
else { return 1; }
! sprintf(returnval, "%-.0lf", tmp);
return 0;
}
int quota_to_megabytes(char returnval[], char *quota) {
***************
*** 292,297 ****
--- 294,300 ----
* Brian Kolaci
* updated function that doesn't require fts_*
*/
+ /* bk - use maildir++ quotas now
off_t get_du(const char *dir_name)
{
DIR *dirp;
***************
*** 323,325 ****
--- 326,329 ----
chdir("..");
return(file_size);
}
+ */