From: Tom C. <tom...@us...> - 2006-02-05 16:49:18
|
Update of /cvsroot/qmailadmin/qmailadmin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15131 Modified Files: Tag: stable-1_2 ChangeLog alias.c command.c user.c util.c util.h Log Message: Add index and user search to the aliases page. When deleting an alias, return to the page that alias would have been on. This feature was sponsored by Marko Lerota. [894823, 877895] Index: ChangeLog =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/ChangeLog,v retrieving revision 1.15.2.77 retrieving revision 1.15.2.78 diff -u -d -r1.15.2.77 -r1.15.2.78 --- ChangeLog 23 Oct 2005 18:52:34 -0000 1.15.2.77 +++ ChangeLog 5 Feb 2006 16:49:08 -0000 1.15.2.78 @@ -6,6 +6,9 @@ Tom Collins - mailinglist.c: Fix problem with enable/disable ezmlm-cgi access to archives. + - alias.c: Add index and user search to the aliases page. When + deleting an alias, return to the page that alias would have been + on. This feature was sponsored by Marko Lerota. [894823, 877895] 1.2.9 - released 1-Sep-05 Index: alias.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/alias.c,v retrieving revision 1.4.2.12 retrieving revision 1.4.2.13 diff -u -d -r1.4.2.12 -r1.4.2.13 --- alias.c 23 Jan 2005 17:35:11 -0000 1.4.2.12 +++ alias.c 5 Feb 2006 16:49:08 -0000 1.4.2.13 @@ -130,9 +130,28 @@ if (page == 0) page = 1; startnumber = MAXALIASESPERPAGE * (page - 1); - k=0; - + k = 0; + #ifdef VALIAS + if (*SearchUser) { + startnumber = 0 + alias_line = valias_select_all(alias_name, Domain); + while (alias_line != NULL) { + strcpy (this_alias, alias_name); + alias_name_from_command = dotqmail_alias_command(alias_line); + if ( alias_name_from_command != NULL || *alias_line == '#') { + if (strcasecmp (SearchUser, alias_name) <= 0) break; + startnumber++; + } + /* burn through remaining lines for this alias, if necessary */ + while ((alias_line != NULL) && (strcmp (this_alias, alias_name) == 0)) { + alias_line = valias_select_all_next(alias_name); + } + } + page = startnumber / MAXALIASESPERPAGE + 1; + sprintf (Pagenumber, "%d", page); + } + alias_line = valias_select_all(alias_name, Domain); while (alias_line != NULL) { strcpy (this_alias, alias_name); @@ -174,6 +193,7 @@ } } #else + /* We can't use valias code here, because it doesn't return a sorted list of aliases. If we update vpopmail's vpalias.c to do that, then qmailadmin could use the single set of valias_ functions above. @@ -216,14 +236,31 @@ if ( alias_name_from_command != NULL || *TmpBuf2 == '#') { k++; - if ( k >MAXALIASESPERPAGE + startnumber) { - moreusers=1; - fclose(fs); - break; - } - if (k <= startnumber) { - fclose (fs); - continue; + if (*SearchUser) { + if (strcasecmp (SearchUser, alias_name) <= 0) { + if (startnumber == 0) { + startnumber = k; + page = (k/MAXALIASESPERPAGE)+1; + } + if (k >= MAXALIASESPERPAGE + startnumber) { + moreusers = 1; + fclose (fs); + break; + } + } else { + fclose (fs); + continue; + } + } else { + if ( k >MAXALIASESPERPAGE + startnumber) { + moreusers=1; + fclose(fs); + break; + } + if (k <= startnumber) { + fclose (fs); + continue; + } } if (*TmpBuf2 == '#') { @@ -252,6 +289,10 @@ /* free memory allocated by bkscandir */ for (m=0; m<n; m++) free(namelist[m]); free(namelist); + + if (*SearchUser && (startnumber == 0)) { + page = (k/MAXALIASESPERPAGE)+1; + } #endif curalias = firstalias; @@ -321,21 +362,37 @@ } if (AdminType == DOMAIN_ADMIN) { + + print_user_index ("showforwards", 4, user, dom, mytime); + printf ("<tr><td align=\"right\" colspan=\"4\">"); printf ("[ "); - if(page > 1 ) { + /* When searching for a user on systems using .qmail files, we make things + * easy by starting the page with the first matching address. As a result, + * the previous page will be 'page' and not 'page-1'. Refresh is accomplished + * by repeating the search. + */ + if (*SearchUser && ((startnumber % MAXALIASESPERPAGE) != 1)) { printh ("<a href=\"%s/com/showforwards?user=%C&dom=%C&time=%d&page=%d\">%s</a>", - CGIPATH,user,dom,mytime,page - 1, html_text[135]); + CGIPATH, user, dom, mytime, page, html_text[135]); printf (" | "); + printh ("<a href=\"%s/com/showforwards?user=%C&dom=%C&time=%d&searchuser=%C\">%s</a>", + CGIPATH, user, dom, mytime, SearchUser, html_text[136]); + } else { + if (page > 1) { + printh ("<a href=\"%s/com/showforwards?user=%C&dom=%C&time=%d&page=%d\">%s</a>", + CGIPATH, user, dom, mytime, page - 1, html_text[135]); + printf (" | "); + } + printh ("<a href=\"%s/com/showforwards?user=%C&dom=%C&time=%d&page=%d\">%s</a>", + CGIPATH, user, dom, mytime, page, html_text[136]); } - printh ("<a href=\"%s/com/showforwards?user=%C&dom=%C&time=%d&page=%d\">%s</a>", - CGIPATH,user,dom,mytime,page, html_text[136]); - printf (" | "); if (moreusers) { + printf (" | "); printh ("<a href=\"%s/com/showforwards?user=%C&dom=%C&time=%d&page=%d\">%s</a>", - CGIPATH,user,dom,mytime,page+1, html_text[137]); - printf (" ]"); + CGIPATH, user, dom, mytime, page + 1, html_text[137]); } + printf (" ]"); printf ("</td></tr>"); } } @@ -638,6 +695,7 @@ if(CurForwards == 0 && CurBlackholes == 0) { show_menu(Username, Domain, Mytime); } else { + snprintf (SearchUser, sizeof(SearchUser), "%s", ActionUser); show_forwards(Username,Domain,Mytime); } } Index: command.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/command.c,v retrieving revision 1.2.2.6 retrieving revision 1.2.2.7 diff -u -d -r1.2.2.6 -r1.2.2.7 --- command.c 23 Jan 2005 17:35:11 -0000 1.2.2.6 +++ command.c 5 Feb 2006 16:49:08 -0000 1.2.2.7 @@ -83,6 +83,7 @@ } else if (strcmp(TmpBuf2, "showforwards") == 0) { GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber)); + GetValue(TmpCGI, SearchUser, "searchuser=", sizeof(SearchUser)); show_forwards(Username, Domain, Mytime); } else if (strcmp(TmpBuf2, "showmailinglists") == 0) { Index: user.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/user.c,v retrieving revision 1.11.2.11 retrieving revision 1.11.2.12 diff -u -d -r1.11.2.11 -r1.11.2.12 --- user.c 23 Jan 2005 17:35:12 -0000 1.11.2.11 +++ user.c 5 Feb 2006 16:49:08 -0000 1.11.2.12 @@ -244,38 +244,7 @@ } if (AdminType == DOMAIN_ADMIN) { -#ifdef USER_INDEX - printf ("<tr bgcolor=%s>", get_color_text("000")); - printf ("<td colspan=\"%i\" align=\"center\">", colspan); - printf ("<hr>"); - printf ("<b>%s</b>", html_text[133]); - printf ("<br>"); - for (k = 'a'; k <= 'z'; k++) { - printh ("<a href=\"%s/com/showusers?user=%C&dom=%C&time=%d&searchuser=%c\">%c</a>\n", - CGIPATH,user,dom,mytime,k,k); - } - printf ("<br>"); - for (k = 0; k < 10; k++) { - printh ("<a href=\"%s/com/showusers?user=%C&dom=%C&time=%d&searchuser=%d\">%d</a>\n", - CGIPATH,user,dom,mytime,k,k); - } - printf ("</td>"); - printf ("</tr>\n"); - - printf ("<tr bgcolor=%s>", get_color_text("000")); - printf ("<td colspan=%i>", colspan); - printf ("<table border=0 cellpadding=3 cellspacing=0 width=\"100%%\"><tr><td align=\"center\"><br>"); - printf ("<form method=\"get\" action=\"%s/com/showusers\">", CGIPATH); - printh ("<input type=\"hidden\" name=\"user\" value=\"%H\">", user); - printh ("<input type=\"hidden\" name=\"dom\" value=\"%H\">", dom); - printf ("<input type=\"hidden\" name=\"time\" value=\"%u\">", (unsigned int) mytime); - printh ("<input type=\"text\" name=\"searchuser\" value=\"%H\"> ", SearchUser); - printf ("<input type=\"submit\" value=\"%s\">", html_text[204]); - printf ("</form>"); - printf ("</td></tr></table>"); - printf ("<hr>"); - printf ("</td></tr>\n"); -#endif + print_user_index ("showusers", colspan, user, dom, mytime); printf ("<tr bgcolor=%s>", get_color_text("000")); printf ("<td colspan=\"%i\" align=\"right\">", colspan); Index: util.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/util.c,v retrieving revision 1.4.2.6 retrieving revision 1.4.2.7 diff -u -d -r1.4.2.6 -r1.4.2.7 --- util.c 11 Jul 2005 06:08:46 -0000 1.4.2.6 +++ util.c 5 Feb 2006 16:49:08 -0000 1.4.2.7 @@ -390,6 +390,43 @@ return 0; } +void print_user_index (char *action, int colspan, char *user, char *dom, time_t mytime) +{ +#ifdef USER_INDEX + int k; + + printf ("<tr bgcolor=%s>", get_color_text("000")); + printf ("<td colspan=%d align=\"center\">", colspan); + printf ("<hr>"); + printf ("<b>%s</b> ", html_text[133]); + for (k = 0; k < 10; k++) { + printh ("<a href=\"%s/com/%s?user=%C&dom=%C&time=%d&searchuser=%d\">%d</a>\n", + CGIPATH, action, user, dom, mytime, k, k); + } + for (k = 'a'; k <= 'z'; k++) { + printh ("<a href=\"%s/com/%s?user=%C&dom=%C&time=%d&searchuser=%c\">%c</a>\n", + CGIPATH, action, user, dom, mytime, k, k); + } + printf ("</td>"); + printf ("</tr>\n"); + + printf ("<tr bgcolor=%s>", get_color_text("000")); + printf ("<td colspan=%d>", colspan); + printf ("<table border=0 cellpadding=3 cellspacing=0 width=\"100%%\"><tr><td align=\"center\"><br>"); + printf ("<form method=\"get\" action=\"%s/com/%s\">", CGIPATH, action); + printh ("<input type=\"hidden\" name=\"user\" value=\"%H\">", user); + printh ("<input type=\"hidden\" name=\"dom\" value=\"%H\">", dom); + printf ("<input type=\"hidden\" name=\"time\" value=\"%u\">", (unsigned int) mytime); + printh ("<input type=\"text\" name=\"searchuser\" value=\"%H\"> ", SearchUser); + printf ("<input type=\"submit\" value=\"%s\">", html_text[204]); + printf ("</form>"); + printf ("</td></tr></table>"); + printf ("<hr>"); + printf ("</td></tr>\n"); + +#endif +} + /* * Brian Kolaci * updated function that doesn't require fts_* Index: util.h =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/Attic/util.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- util.h 20 Nov 2004 01:10:41 -0000 1.1.2.1 +++ util.h 5 Feb 2006 16:49:08 -0000 1.1.2.2 @@ -27,3 +27,5 @@ int quota_to_bytes(char[], char*); //jhopper prototype int quota_to_megabytes(char[], char*); //jhopper prototype + +void print_user_index (char *action, int colspan, char *user, char *dom, time_t mytime); |