Search
j0ke.net Open Build Service
>
Projects
>
server:mail
>
vqadmin
> vqadmin-2.patch
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File vqadmin-2.patch of Package vqadmin
Index: cgi.c =================================================================== RCS file: /usr/local/cvs/root/vqadmin/cgi.c,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -r1.1.1.1 -r1.4 --- cgi.c 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ cgi.c 13 Dec 2003 04:18:38 -0000 1.4 @@ -23,6 +23,7 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> +#include <vpopmail.h> #include "global.h" struct var_t { @@ -380,4 +381,87 @@ val3 = val1 + (val2 * 15) + val2; return val3; +} + +void cgi_get_toggle(short *out, char *name) +{ + char *value = cgi_is_var(name); + + if (value != NULL) { + *out = 1; + } else { + *out = 0; + } +} + +void cgi_get_int(int *out, char *name) +{ + char *value = cgi_is_var(name); + + if (value != NULL && strlen(value) > 0) { + *out = atoi(value); + } +} + +int cgi_get_quota(char *qq) +{ + char *q; + int out = 0; + + if (qq == NULL || strlen(qq) == 0) { + return 0; + } + q = format_maildirquota(qq); + if (q == NULL || strlen(q) == 0) { + return 0; + } + while (q && *q) { + if (*q < '0' || *q > '9') { + ++q; + continue; + } + while (*q >= '0' && *q <= '9') { + out = out * 10 + (*q++ - '0'); + } + break; + } + return out; +} + +/* populate a vlimits struct with values from CGI, if they exist */ +void cgi_get_limits(struct vlimits *limits) +{ + char *q = cgi_is_var("quota"); + + cgi_get_int(&(limits->maxpopaccounts), "lusers"); + cgi_get_int(&(limits->maxaliases), "lalias"); + cgi_get_int(&(limits->maxforwards), "lfor"); + cgi_get_int(&(limits->maxautoresponders), "lresponder"); + cgi_get_int(&(limits->maxmailinglists), "llists"); + + if (q != NULL && strlen(q) > 0) { + limits->defaultquota = cgi_get_quota(q); + } + + cgi_get_toggle(&(limits->disable_pop), "upop"); + cgi_get_toggle(&(limits->disable_imap), "uimap"); + cgi_get_toggle(&(limits->disable_dialup), "udialup"); + cgi_get_toggle(&(limits->disable_passwordchanging), "upassc"); + cgi_get_toggle(&(limits->disable_webmail), "uweb"); + cgi_get_toggle(&(limits->disable_relay), "urelay"); +} + +char *cgi_pretty_quota(int q) +{ + static char buf[11]; + if (q > 1048576) { + snprintf(buf, 15, "%dM", q / 1048576); + } else if (q > 1024) { + snprintf(buf, 15, "%dK", q / 1024); + } else if (q == 0) { + sprintf(buf, "NOQUOTA"); + } else { + snprintf(buf, 15, "%d", q); + } + return buf; } Index: domain.c =================================================================== RCS file: /usr/local/cvs/root/vqadmin/domain.c,v retrieving revision 1.1.1.1 retrieving revision 1.4 diff -u -r1.1.1.1 -r1.4 --- domain.c 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ domain.c 12 Dec 2003 16:59:32 -0000 1.4 @@ -31,6 +31,7 @@ #include "vpopmail.h" #include "vpopmail_config.h" #include "vauth.h" +#include "vlimits.h" #define TOKENS " :\t\n\r" @@ -38,27 +39,26 @@ extern char WarningBuff[MAX_WARNING_BUFF]; extern vdir_type vdir; +static unsigned long count_users(char *domain) +{ + struct vqpasswd *pw; + unsigned long out = 0; + + pw = vauth_getall(domain,1,0); + while(pw!=NULL){ + ++out; + pw = vauth_getall(domain,0,0); + } + vauth_end_getall(); + return out; +} + void add_domain() { char *domain = NULL; char *passwd = NULL; - char *lusers = NULL; - char *lfor = NULL; - char *lalias = NULL; - char *lresponder = NULL; - char *llists = NULL; - char *quota = NULL; - char *upop = NULL; - char *uimap = NULL; - char *udialup = NULL; - char *upassc = NULL; - char *uweb = NULL; - char *urelay = NULL; int ret; - char dir[156]; - uid_t uid; - gid_t gid; - FILE *fs; + struct vlimits limits; if (!(acl_features & ACL_DOMAIN_CREATE)) { global_warning("Create Domain: Permission denied"); @@ -68,20 +68,6 @@ domain = cgi_is_var("dname"); passwd = cgi_is_var("pp"); - lusers = cgi_is_var("lusers"); - lfor = cgi_is_var("lfor"); - lalias = cgi_is_var("lalias"); - lresponder = cgi_is_var("lresponder"); - llists = cgi_is_var("llists"); - - quota = cgi_is_var("quota"); - upop = cgi_is_var("upop"); - uimap = cgi_is_var("uimap"); - udialup = cgi_is_var("udialup"); - upassc = cgi_is_var("upassc"); - uweb = cgi_is_var("uweb"); - urelay = cgi_is_var("urelay"); - /* get the domain name */ if (domain==NULL || strlen(domain)==0) { global_warning("Create Domain: Failed: Must supply domain name"); @@ -113,42 +99,18 @@ global_warning("Created Domain"); } - /* setup the .qmailadmin-limits file */ - vget_assign(domain,dir,156,&uid,&gid); - strncat(dir,"/.qmailadmin-limits", 156); - if ( (fs = fopen(dir,"w+")) == NULL ) { - global_warning("Create Domain: open .qmailadmin-limits failed"); - t_open(T_MAIN, 1); + /* setup the limits */ + if (vget_limits(domain, &limits) < 0) { + global_warning("Failed to get domain limits; continuing anyway"); + } else { + cgi_get_limits(&limits); + if (vset_limits(domain, (const struct vlimits *)&limits) < 0) { + global_warning("Failed to set domain limits; continuing anyway"); + } else { + global_warning("Domain limits set successfully"); + } } - if (lusers!=NULL&&strlen(lusers)>0) - fprintf(fs, "maxpopaccounts: %s\n", lusers); - - if (lalias!=NULL&&strlen(lalias)>0) - fprintf(fs, "maxaliases: %s\n", lalias); - - if (lfor!=NULL&&strlen(lfor)>0) - fprintf(fs, "maxforwards: %s\n", lfor); - - if (lresponder!=NULL&&strlen(lresponder)>0) - fprintf(fs, "maxautoresponders: %s\n", lresponder); - - if (llists!=NULL&&strlen(llists)>0) - fprintf(fs, "maxmailinglists: %s\n", llists); - - if (quota!=NULL && strlen(quota)>0) - fprintf(fs,"default_quota: %s\n",quota); - - if (upop!=NULL) fprintf(fs, "disable_pop\n"); - if (uimap!=NULL) fprintf(fs, "disable_imap\n"); - if (udialup!=NULL) fprintf(fs, "disable_dialup\n"); - if (upassc!=NULL) fprintf(fs, "disable_password_changing\n"); - if (uweb!=NULL) fprintf(fs, "disable_webmail\n"); - if (urelay!=NULL) fprintf(fs, "disable_external_relay\n"); - fclose(fs); - chown(dir,uid, gid); - chmod(dir, S_IRUSR | S_IWUSR); - ret = vadduser("postmaster", domain, passwd, "Postmaster", USE_POP ); if (ret != VA_SUCCESS) { global_warning(verror(ret)); @@ -229,23 +191,8 @@ { char *domain = NULL; char *ppass = NULL; - char *lusers = NULL; - char *lfor = NULL; - char *lalias = NULL; - char *lresponder = NULL; - char *llists = NULL; - char *quota = NULL; - char *upop = NULL; - char *uimap = NULL; - char *udialup = NULL; - char *upassc = NULL; - char *uweb = NULL; - char *urelay = NULL; int ret; - char dir[156]; - uid_t uid; - gid_t gid; - FILE *fs; + struct vlimits limits; if (!(acl_features & ACL_DOMAIN_MOD)) { global_warning("Mod Domain: Permission denied"); @@ -260,48 +207,17 @@ t_open("html/mod_domain.html", 1); } - lusers = cgi_is_var("lusers"); - lfor = cgi_is_var("lfor"); - lalias = cgi_is_var("lalias"); - lresponder = cgi_is_var("lresponder"); - llists = cgi_is_var("llists"); - quota = cgi_is_var("quota"); - upop = cgi_is_var("upop"); - uimap = cgi_is_var("uimap"); - udialup = cgi_is_var("udialup"); - upassc = cgi_is_var("upassc"); - uweb = cgi_is_var("uweb"); - urelay = cgi_is_var("urelay"); - - vget_assign(domain,dir,156,&uid,&gid); - strncat(dir,"/.qmailadmin-limits", 156); - if ( (fs = fopen(dir,"w+")) == NULL ) { - global_warning("Create Domain: open .qmailadmin-limits failed"); - t_open(T_MAIN, 1); + /* setup the limits */ + if (vget_limits(domain, &limits) < 0) { + global_warning("Failed to get domain limits; continuing anyway"); + } else { + cgi_get_limits(&limits); + if (vset_limits(domain, (const struct vlimits *)&limits) < 0) { + global_warning("Failed to set domain limits; continuing anyway"); + } else { + global_warning("Domain limits set successfully"); + } } - if ( lusers!=NULL && strlen(lusers) > 0 ) - fprintf(fs, "maxpopaccounts: %s\n", lusers); - if ( lalias!=NULL && strlen(lalias) > 0 ) - fprintf(fs, "maxaliases: %s\n", lalias); - if ( lfor!=NULL && strlen(lfor) > 0 ) - fprintf(fs, "maxforwards: %s\n", lfor); - if ( lresponder!=NULL && strlen(lresponder) > 0 ) - fprintf(fs, "maxautoresponders: %s\n", lresponder); - if ( llists!=NULL && strlen(llists) > 0 ) - fprintf(fs, "maxmailinglists: %s\n", llists); - if (quota!=NULL && strlen(quota)>0) - fprintf(fs,"default_quota: %s\n",quota); - - if (upop!=NULL) fprintf(fs, "disable_pop\n"); - if (uimap!=NULL) fprintf(fs, "disable_imap\n"); - if (udialup!=NULL) fprintf(fs, "disable_dialup\n"); - if (upassc!=NULL) fprintf(fs, "disable_password_changing\n"); - if (uweb!=NULL) fprintf(fs, "disable_webmail\n"); - if (urelay!=NULL) fprintf(fs, "disable_external_relay\n"); - - fclose(fs); - chown(dir,uid, gid); - chmod(dir, S_IRUSR | S_IWUSR); ppass = cgi_is_var("ppass"); if (ppass!=NULL && strlen(ppass)>0) { @@ -324,15 +240,13 @@ void post_domain_info(char *domain) { char Dir[156]; - char cuid[10]; - char cgid[10]; - char cusers[10]; - char *tmpstr1; - char *tmpstr2; + char cuid[11]; + char cgid[11]; + char cusers[11]; uid_t uid; gid_t gid; - FILE *fs; struct vqpasswd *vpw; + struct vlimits limits; if ( vget_assign(domain,Dir,156,&uid,&gid) == NULL ) { snprintf(WarningBuff, MAX_WARNING_BUFF, @@ -350,72 +264,46 @@ sprintf(cgid,"%lu", (long unsigned)gid); global_par("DG", cgid); - open_big_dir(domain, uid, gid); - close_big_dir(domain,uid,gid); - - sprintf(cusers,"%lu", (long unsigned)vdir.cur_users); + sprintf(cusers,"%lu", count_users(domain)); global_par("DS", cusers); vpw = vauth_getpw("postmaster", domain); if ( vpw != NULL ) global_par("DP", vpw->pw_clear_passwd); else global_par("DP", "Domain has no postmaster!!"); - strncat(Dir,"/.qmailadmin-limits", 156); - fs = fopen(Dir,"r"); - if ( fs != NULL ) { - global_par("QL", "CHECKED"); - while(fgets(Dir,156,fs)!=NULL) { - if ( (tmpstr1 = strtok(Dir,TOKENS))==NULL) continue; - - if ( strcmp(tmpstr1, "maxpopaccounts") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("MU", tmpstr2); - - } else if ( strcmp(tmpstr1, "maxaliases") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("MA", tmpstr2); - - } else if ( strcmp(tmpstr1, "maxforwards") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("MF", tmpstr2); - - } else if ( strcmp(tmpstr1, "maxautoresponders") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("MR", tmpstr2); - - } else if ( strcmp(tmpstr1, "maxmailinglists") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("ML", tmpstr2); - - } else if ( strcmp(tmpstr1, "quota") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("MQ", tmpstr2); - - } else if ( strcmp(tmpstr1, "default_quota") == 0 ) { - if ( (tmpstr2 = strtok(NULL,TOKENS))==NULL) continue; - global_par("MQ", tmpstr2); - - } else if ( strcmp(tmpstr1, "disable_pop") == 0 ) { - global_par("MP", "checked"); - - } else if ( strcmp(tmpstr1, "disable_imap") == 0 ) { - global_par("MI", "checked"); - - } else if ( strcmp(tmpstr1, "disable_dialup") == 0 ) { - global_par("MD", "checked"); - - } else if ( strcmp(tmpstr1, "disable_password_changing") == 0 ) { - global_par("MC", "checked"); - - } else if ( strcmp(tmpstr1, "disable_external_relay") == 0 ) { - global_par("MS", "checked"); - - } else if ( strcmp(tmpstr1, "disable_webmail") == 0 ) { - global_par("MW", "checked"); + if (vget_limits(domain, &limits) >= 0) { + struct { + char name[3]; + char fmt[5]; + int value; + } *v, vars[] = { + { "MU", "%d", limits.maxpopaccounts }, + { "MA", "%d", limits.maxaliases }, + { "MF", "%d", limits.maxforwards }, + { "MR", "%d", limits.maxautoresponders }, + { "ML", "%d", limits.maxmailinglists }, + { "MP", "%s", limits.disable_pop }, + { "MI", "%s", limits.disable_imap }, + { "MD", "%s", limits.disable_dialup }, + { "MC", "%s", limits.disable_passwordchanging }, + { "MW", "%s", limits.disable_webmail }, + { "MS", "%s", limits.disable_relay }, + { "", "", 0 } + }; + char buf[15]; + global_par("QL", "CHECKED"); + for (v = vars; strlen(v->name) > 0; v++) { + if (v->fmt[1] == 's') { + snprintf(buf, 15, v->fmt, v->value ? "checked" : ""); + } else { + snprintf(buf, 15, v->fmt, v->value); + } + if (strlen(buf) > 0) { + global_par(v->name, buf); } } - fclose(fs); + global_par("MQ", cgi_pretty_quota(limits.defaultquota)); } else { global_par("QU", "CHECKED"); } Index: global.h =================================================================== RCS file: /usr/local/cvs/root/vqadmin/global.h,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -u -r1.1.1.1 -r1.3 --- global.h 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ global.h 12 Dec 2003 18:05:45 -0000 1.3 @@ -23,6 +23,7 @@ #include <sys/types.h> #include <pwd.h> #include <vauth.h> +#include <vlimits.h> #include "config.h" #define MAX_WARNING_BUFF 500 @@ -96,6 +97,11 @@ char *cgi_is_var(char *); char matoh(char); unsigned char hex2asc(char, char); +void cgi_get_toggle(short *, char *); +void cgi_get_int(int *, char *); +int cgi_get_quota(char *); +void cgi_get_limits(struct vlimits *); +char *cgi_pretty_quota(int); /* template.c */ void t_code(char); Index: user.c =================================================================== RCS file: /usr/local/cvs/root/vqadmin/user.c,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -u -r1.1.1.1 -r1.3 --- user.c 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ user.c 12 Dec 2003 22:06:31 -0000 1.3 @@ -116,7 +116,7 @@ static char domain[156]; char *gecos; char *passwd; - char *shell; + int quota; char *udisable; char *uweb; char *uimap; @@ -137,7 +137,7 @@ eaddr = cgi_is_var("eaddr"); gecos = cgi_is_var("fname"); passwd = cgi_is_var("cpass"); - shell = cgi_is_var("quota"); + quota = cgi_get_quota(cgi_is_var("quota")); udisable = cgi_is_var("udisable"); uweb = cgi_is_var("uweb"); uimap = cgi_is_var("uimap"); @@ -172,8 +172,10 @@ vpw->pw_gecos = gecos; } - if ( shell!=NULL && strlen(shell)>0 ){ - vpw->pw_shell = shell; + if (quota) { + char buf[15]; + snprintf(buf, 15, "%dS", quota); + vpw->pw_shell = buf; } if (udisable!=NULL) GidFlag |= NO_POP; @@ -196,6 +198,7 @@ "Modify Account %s success", eaddr); global_warning(WarningBuff); } + (void)vsetuserquota(user, domain, vpw->pw_shell); post_email_info( eaddr, vpw, domain); t_open("html/mod_user.html", 1); @@ -211,7 +214,7 @@ global_par("UA", eaddr); global_par("UN", vpw->pw_gecos); - global_par("UQ", vpw->pw_shell); + global_par("UQ", cgi_pretty_quota(cgi_get_quota(vpw->pw_shell))); global_par("UD", vpw->pw_dir); #ifdef CLEAR_PASS @@ -329,7 +332,7 @@ printf("<th><FONT face=%s color=\"%s\">Domain Administrator</FONT></th>\n", face, fgcolor); printf("<th><FONT face=%s color=\"%s\">Last Logon</FONT></th></tr><BR>\n", - face, fgcolor); + face, fgcolor); } count = 0; while(vpw != NULL && count < 128000 ){ @@ -387,7 +390,7 @@ printf("<td align=middle><FONT face=%s color=\"%s\">%s</FONT></td>", - face, fgcolor, vpw->pw_shell); + face, fgcolor, cgi_pretty_quota(cgi_get_quota(vpw->pw_shell))); if (vpw->pw_gid & QA_ADMIN) { printf("<td align=middle><FONT face=%s color=%s><B>Yes</B></FONT></td>\n", face, fgcolor); @@ -515,7 +518,7 @@ static char domain[156]; char *gecos; char *passwd; - char *shell; + int quota; char *udisable; char *uweb; char *uimap; @@ -535,7 +538,7 @@ eaddr = cgi_is_var("eaddr"); gecos = cgi_is_var("fname"); passwd = cgi_is_var("cpass"); - shell = cgi_is_var("quota"); + quota = cgi_get_quota(cgi_is_var("quota")); udisable = cgi_is_var("udisable"); uweb = cgi_is_var("uweb"); uimap = cgi_is_var("uimap"); @@ -586,7 +589,11 @@ if (uqadmin!=NULL) GidFlag |= QA_ADMIN; vpw->pw_gid = GidFlag; - if ( shell != NULL && strlen(shell) > 0 ) vpw->pw_shell = shell; + if (quota) { + char buf[15]; + snprintf(buf, 15, "%dS", quota); + vpw->pw_shell = buf; + } ret = vauth_setpw(vpw, domain); if ( ret != VA_SUCCESS ) { @@ -594,6 +601,7 @@ "Add Account: Failure: %s set options", eaddr); global_warning(WarningBuff); } + (void)vsetuserquota(user, domain, vpw->pw_shell); post_email_info( eaddr, vpw, domain); t_open(T_MAIN, 1); Index: html/add_domain.html =================================================================== RCS file: /usr/local/cvs/root/vqadmin/html/add_domain.html,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- html/add_domain.html 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ html/add_domain.html 12 Dec 2003 18:05:11 -0000 1.2 @@ -35,7 +35,8 @@ <td><INPUT TYPE="TEXT" NAME="llists" SIZE="4" title="#-019"></td> <td class="clsInfo">#-050</td></tr> <tr><td class="clsLabelR">#-039</td> - <td><input type="text" name="quota" size="10" title="#-039"></td></tr> + <td><input type="text" name="quota" size="10" title="#-039"></td> + <td>#-070</td></tr> </table> <table border="0" cellspacing="0" cellpadding="0"> Index: html/en =================================================================== RCS file: /usr/local/cvs/root/vqadmin/html/en,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -u -r1.1.1.1 -r1.3 --- html/en 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ html/en 12 Dec 2003 18:05:11 -0000 1.3 @@ -37,7 +37,7 @@ 036 User ID 037 Group ID 038 Modify Email Account -039 Quota in bytes +039 Quota 040 Permissions 041 List Domains 042 Disable pop access @@ -48,7 +48,7 @@ 047 Disable email relay 048 Domain Administrator 049 Disable dialup access -050 0 disables this feature +050 0 = disabled; -1 = unlimited 051 Last authentication time 052 Last authentication ip 053 List Domains @@ -65,3 +65,4 @@ 067 user: 068 permission: 069 Domain Owner +070 examples: 10M, 500K, 5MB Index: html/en-us =================================================================== RCS file: /usr/local/cvs/root/vqadmin/html/en-us,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -u -r1.1.1.1 -r1.3 --- html/en-us 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ html/en-us 12 Dec 2003 18:05:11 -0000 1.3 @@ -37,7 +37,7 @@ 036 User ID 037 Group ID 038 Modify Email Account -039 Quota in bytes +039 Quota 040 Permissions 041 List Domains 042 Disable pop access @@ -48,7 +48,7 @@ 047 Disable email relay 048 Domain Administrator 049 Disable dialup access -050 0 disables this feature +050 0 = disabled; -1 = unlimited 051 Last authentication time 052 Last authentication ip 053 List Domains @@ -62,3 +62,7 @@ 061 Qmail Control Files 062 Modify Control File 063 Modify File +067 user: +068 permission: +069 Domain Owner +070 examples: 10M, 500K, 5MB Index: html/mod_domain.html =================================================================== RCS file: /usr/local/cvs/root/vqadmin/html/mod_domain.html,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -u -r1.1.1.1 -r1.3 --- html/mod_domain.html 21 Oct 2003 19:22:15 -0000 1.1.1.1 +++ html/mod_domain.html 12 Dec 2003 18:05:11 -0000 1.3 @@ -52,7 +52,8 @@ <td><input type="text" name="llists" value="$-ML" size="4" title="#-019"></td> <td class="clsInfo">#-050</td></tr> <tr><td class="clsLabelR">#-039</td> - <td><input type="text" name="quota" value="$-MQ" size="10" title="#-039"></td></tr> + <td><input type="text" name="quota" value="$-MQ" size="10" title="#-039"></td> + <td>#-070</td></tr> </table> <table border="0" cellspacing="0" cellpadding="0"> <tr><td><input TYPE="checkbox" NAME="upop" id="upop"$-MP title="#-042"><label for="upop" title="#-042">#-042</label></td></tr>