* Chris Chan <[EMAIL PROTECTED]> [001231 03:59]:
> Anyone know how to modify the qmailadmin pre1 4.0 to sort the Alias from a-z
A number of versions ago, I modified qmailadmin to do this and submitted a
patch. Lamentably, it didn't seem to make it into later versions.
Basically, you need to invoke scandir(3) on the directory before iterating
through the .qmail files. See the manpage for more.
I've attached my patch against qmailadmin-0.35. Since I'm not really
developing with vpopmail and its associated tools much anymore, I haven't
ported it, but it should be fairly straightforward.
Good luck!
/pg
--
Peter Green : Gospel Communications Network, SysAdmin : [EMAIL PROTECTED]
---
"A journey of a thousand miles continues with the second step."
--- Larry Wall
--- alias.c Tue Aug 8 14:42:47 2000
+++ alias.c.new Mon Aug 14 22:51:02 2000
@@ -56,7 +56,9 @@
char alias_user[MAX_FILE_NAME];
char alias_name[MAX_FILE_NAME];
char *alias_name_from_command;
- int i,j,stop,k,startnumber;
+ char *qmailfn;
+ struct dirent **dirlist;
+ int rc,i,j,stop,k,startnumber;
if ( AdminType!=SYSTEM_ADMIN && AdminType!=DOMAIN_ADMIN ) {
fprintf(actout,"<h2>No Authorization</h2>");
@@ -67,95 +69,99 @@
}
startnumber = MAXALIASESPERPAGE * (atoi(Pagenumber) - 1);
k=0;
- if ( (mydir = opendir(".")) == NULL ) {
- fprintf(actout,"show dotqmail, directory permission error<BR>\n");
+
+ rc = scandir(".", &dirlist, 0, alphasort);
+ if (rc < 0) {
+ fprintf(actout,"show dotqmail, directory error<BR>\n");
fprintf(actout,"</table>");
return(0);
}
+ else {
+ int cnt = 0;
+ while (cnt < rc) {
+ strcpy (qmailfn,dirlist[cnt++]->d_name);
+ if ( strncmp(".qmail-", qmailfn, 7) == 0 ) {
+ if ( k < startnumber ) {
+ k++;
+ continue;
+ }
+ if ( k >MAXALIASESPERPAGE + startnumber) {
+ break;
+ }
- while( (mydirent=readdir(mydir)) != NULL ) {
- if ( strncmp(".qmail-", mydirent->d_name, 7) == 0 ) {
- if ( k < startnumber ) {
- k++;
- continue;
- }
- if ( k >MAXALIASESPERPAGE + startnumber) {
- break;
- }
-
- if ( (fs=fopen(mydirent->d_name,"r"))==NULL) {
- fprintf(actout,"file permission error %s<BR>\n",
- mydirent->d_name);
- fclose(fs);
- continue;
- }
- memset(TmpBuf2,0,MAX_BUFF);
- fgets( TmpBuf2, MAX_BUFF, fs);
- alias_name_from_command = dotqmail_alias_command(TmpBuf2);
- if ( alias_name_from_command != NULL ) {
-
- /* first case checks if the file beginnning is an email
- * and the function is not being called to display
forwards,
- * the second case checks if the file beginning is an
user, and
- * the type is not an alias
- */
-
- if ((strstr(alias_name_from_command,"@")!=NULL) &&
- (strcmp(dottype, "forward"))) {
- fclose(fs);
- continue;
- } else if ((strstr(alias_name_from_command,"@")==NULL)
&&
- (strcmp(dottype, "alias"))) {
+ if ( (fs=fopen(qmailfn,"r"))==NULL) {
+ fprintf(actout,"file permission error
+%s<BR>\n",
+ qmailfn);
fclose(fs);
continue;
}
+ memset(TmpBuf2,0,MAX_BUFF);
+ fgets( TmpBuf2, MAX_BUFF, fs);
+ alias_name_from_command =
+dotqmail_alias_command(TmpBuf2);
+ if ( alias_name_from_command != NULL ) {
+
+ /* first case checks if the file beginnning is
+an email
+ * and the function is not being called to
+display forwards,
+ * the second case checks if the file
+beginning is an user, and
+ * the type is not an alias
+ */
+
+ if
+((strstr(alias_name_from_command,"@")!=NULL) &&
+ (strcmp(dottype, "forward"))) {
+ fclose(fs);
+ continue;
+ } else if
+((strstr(alias_name_from_command,"@")==NULL) &&
+ (strcmp(dottype,
+"alias"))) {
+ fclose(fs);
+ continue;
+ }
-
for(i=7,j=0;j<MAX_FILE_NAME-1&&mydirent->d_name[i]!=0;++i,++j) {
- alias_name[j] = mydirent->d_name[i];
- if ( alias_name[j] == ':' ) alias_name[j] =
'.';
- }
- alias_name[j] = 0;
- stop=0;
+
+for(i=7,j=0;j<MAX_FILE_NAME-1&&qmailfn[i]!=0;++i,++j) {
+ alias_name[j] = qmailfn[i];
+ if ( alias_name[j] == ':' )
+alias_name[j] = '.';
+ }
+ alias_name[j] = 0;
+ stop=0;
- fprintf(actout, "<TR><TD>%s</TD><TD align=center>",
alias_name);
- while (stop == 0) {
- alias_name_from_command =
dotqmail_alias_command(TmpBuf2);
+ fprintf(actout, "<TR><TD>%s</TD><TD
+align=center>", alias_name);
+ while (stop == 0) {
+ alias_name_from_command =
+dotqmail_alias_command(TmpBuf2);
- /* check to see if it is an invalid line ,
- * if so skip to next
- */
- if (alias_name_from_command == NULL ) {
- if (fgets(TmpBuf2, 500, fs)==NULL) {
- stop=1;
+ /* check to see if it is an invalid
+line ,
+ * if so skip to next
+ */
+ if (alias_name_from_command == NULL ) {
+ if (fgets(TmpBuf2, 500,
+fs)==NULL) {
+ stop=1;
+ }
+ continue;
}
- continue;
- }
- strcpy(alias_user, alias_name_from_command);
+ strcpy(alias_user,
+alias_name_from_command);
- if (fgets(TmpBuf2, 500, fs) == NULL) {
- stop=1;
- fprintf(actout, "%s ", alias_user);
- } else {
- fprintf(actout, "%s, ", alias_user);
+ if (fgets(TmpBuf2, 500, fs) == NULL) {
+ stop=1;
+ fprintf(actout, "%s ",
+alias_user);
+ } else {
+ fprintf(actout, "%s, ",
+alias_user);
+ }
}
- }
- fprintf(actout, "</TD>");
+ fprintf(actout, "</TD>");
- fprintf(actout,"<TD align=center><A
href=%s/com/moddotqmail?atype=%s&user=%s&dom=%s&time=%d&modu=%s>\
+ fprintf(actout,"<TD align=center><A
+href=%s/com/moddotqmail?atype=%s&user=%s&dom=%s&time=%d&modu=%s>\
<img src=\"/images/qmailadmin/delete.gif\" border=0></a></TD>",
- CGIPATH,dottype, user, dom, mytime, alias_name);
- fprintf(actout,"<TD align=center><A
href=%s/com/deldotqmail?atype=%s&user=%s&dom=%s&time=%d&modu=%s>\
+ CGIPATH,dottype, user, dom, mytime, alias_name);
+ fprintf(actout,"<TD align=center><A
+href=%s/com/deldotqmail?atype=%s&user=%s&dom=%s&time=%d&modu=%s>\
<img src=\"/images/qmailadmin/delete.gif\" border=0></a></TD>",
- CGIPATH,dottype, user, dom, mytime, alias_name);
+ CGIPATH,dottype, user, dom, mytime, alias_name);
+ }
+ fclose(fs);
+ k++;
}
- fclose(fs);
- k++;
}
}
- closedir(mydir);
fprintf(actout,"<tr><td colspan=5><center>\n");
if ( AdminType==SYSTEM_ADMIN || AdminType==DOMAIN_ADMIN ) {