From: <rw...@pr...> - 2004-01-31 11:09:43
|
Update of /cvsroot/qmailadmin/qmailadmin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27962 Modified Files: NEWS TODO alias.c auth.c autorespond.c command.c forward.c limits.c mailinglist.c qmailadmin.c qmailadmin.h qmailadminx.h show.c template.c user.c util.c Log Message: Last of Rick's big block of changes. See NEWS and TODO for details. Index: NEWS =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/NEWS,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- NEWS 30 Jan 2004 08:30:58 -0000 1.4 +++ NEWS 31 Jan 2004 11:08:00 -0000 1.5 @@ -8,6 +8,36 @@ I built up a large number of changes and will commit them in batches, in the same order they were created. +################################################################# + +Changes from 040116 : + +Replace vclose(); exit(0); with return() so everything returns +to the caller and passes back a status value. DO NOT exit before +painting the footer.html file. The return value is often the +index into the lang/ file to retrieve the status message. + +Changes to the auth code, including moving session file handling +from qmailadmin.c to auth.c. + +Move the GetValues from command.c to qmailadmin.c so they are +only done once. + +Change ADMIN type values so they can be used with < and > rather +than checking == or != on each. + +Move processing header.html and footer.html to qmailadmin.c +instead of having send_template() and send_template_now(). +Remove send_template, rename send_template_now to send_template, +and change all calls to send_template_now() to send_template(). +Remember... we ALWAYS return on failure, and header.html and +footer.html will ALWAYS be processed. + + + + + + ################################################################# Index: TODO =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/TODO,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- TODO 10 Sep 2003 21:38:41 -0000 1.1.1.1 +++ TODO 31 Jan 2004 11:08:00 -0000 1.2 @@ -1,3 +1,70 @@ +*************************************************** +*************************************************** + +Rick's todo list: + +Add jump to first field javascript to templates. + +TMDA checkbox. + +CSS support in templates. + +Look through archives for other todo items, and add them +to this list. + +Verify we are actually using the latest build system, and that +all patches have been added. Check for patches between RC1 and +final, and verify they exist in new code. + +Eliminate as many global variables as possible. + +Move session handling from time based to a MD5 hash of some +random data. Move the session files into a single directory +and store login credentials of the current user in the +session file. + +Restructure form handling so each edit page uses the following +structure, and put it in its own file named for the .html file +it displays, and the menu choice that calls it. + +-------------------------------------------------------------- + +if( button not clicked ) { + + Get data from mail system + Set 'error' - + +} else { + + Get data from form // GetValue()s + + Check for errors +} + + +if( no errors ) { + + update mail system + send Location: header to next screen + +} else { + + Paint template + +} + + +-------------------------------------------------------------- + +Consider list instead of menu on first page. + + + +*************************************************** +*************************************************** + +Original TODO list follows + * Convert Alias/Forward code to use valias functions Heather L Sherman <he...@id...> Index: alias.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/alias.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- alias.c 30 Jan 2004 08:30:58 -0000 1.7 +++ alias.c 31 Jan 2004 11:08:00 -0000 1.8 @@ -61,9 +61,7 @@ struct dirent **namelist; if ( AdminType!=DOMAIN_ADMIN ) { - sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if (atoi(Pagenumber)==0) { @@ -76,7 +74,7 @@ if ( (mydir = opendir(".")) == NULL ) { strcpy(uBufA, "4"); sprintf(uBufB, "%s %d", get_html_text("143"), 1); - send_template_now("show_error_line.html"); + send_template("show_error_line.html"); return(0); } @@ -105,7 +103,7 @@ if ( (fs=fopen(mydirent->d_name,"r"))==NULL) { strcpy(uBufA, "4"); sprintf(uBufB, "SDQL %s %s", get_html_text("144"), mydirent->d_name); - send_template_now("show_error_line.html"); + send_template("show_error_line.html"); continue; } for(i=7,j=0;j<MAX_FILE_NAME-1&&mydirent->d_name[i]!=0;++i,++j) { @@ -184,7 +182,7 @@ } strcpy(uBufD, Buffer1); strcpy(Buffer1, ""); - send_template_now("show_forwards_line.html"); + send_template("show_forwards_line.html"); } fclose(fs); k++; @@ -215,9 +213,7 @@ int l,j; if ( AdminType!=DOMAIN_ADMIN ) { - sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } l = strlen(user); @@ -281,10 +277,7 @@ } if ( (fs=fopen(dot_file,"r"))==NULL) { - sprintf(StatusMessage,"%s %s<br>\n", get_html_text("144"), - dot_file); - vclose(); - exit(0); + return(144); } j=0; @@ -304,79 +297,67 @@ -void moddotqmail() +int moddotqmail() { if ( AdminType!=DOMAIN_ADMIN ) { - sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } send_template("mod_dotqmail.html"); } -void moddotqmailnow() +int moddotqmailnow() { struct vqpasswd *pw; if ( strcmp(ActionUser,"default")==0) { - sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if (strcmp(Action,"delentry")==0) { if (onevalidonly(ActionUser) ) { sprintf(StatusMessage, "%s\n", get_html_text("149")); moddotqmail(); - vclose(); - exit(0); + return(0); } if (dotqmail_del_line(ActionUser,LineData) ) { sprintf(StatusMessage, "%s %d\n", get_html_text("150"), 1); moddotqmail(); - vclose(); - exit(0); + return(150); } sprintf(StatusMessage, "%s\n", get_html_text("151") ); moddotqmail(); - vclose(); - exit(0); + return(151); } else if (strcmp(Action,"add")==0) { if( adddotqmail_shared(ActionUser, Newu, 0)) { moddotqmail(); - vclose(); - exit(0); + return(0); } else { sprintf(StatusMessage,"%s %s\n", get_html_text("152"), Newu); moddotqmail(); - vclose(); - exit(0); + return(0); } } else { sprintf(StatusMessage, "%s\n", get_html_text("155")); - vclose(); - exit(0); + return(0); } } -adddotqmail() +int adddotqmail() { if ( MaxForwards != -1 && CurForwards >= MaxForwards ) { - sprintf(StatusMessage, "%s %d\n", - get_html_text("157"), MaxForwards); + sprintf(StatusMessage, "%s %d\n", get_html_text("157"), MaxForwards); show_menu(); - vclose(); - exit(0); + return(157); } send_template( "add_forward.html" ); } -adddotqmailnow() +int adddotqmailnow() { char Buffer[MAX_BUFF]; struct vqpasswd *pw; @@ -384,23 +365,20 @@ if (AdminType!=DOMAIN_ADMIN && !(AdminType==USER_ADMIN && strcmp(ActionUser, Username)==0)) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( MaxForwards != -1 && CurForwards >= MaxForwards ) { sprintf(StatusMessage, "%s %d\n", get_html_text("157"), MaxForwards); send_template( "add_forward.html" ); - vclose(); - exit(0); + return(0); } if (adddotqmail_shared(Alias, ActionUser, -1)) { adddotqmail(); - vclose(); - exit(0); + return(0); } else { sprintf(StatusMessage, "%s\n", get_html_text("152")); @@ -458,27 +436,25 @@ return(0); } -deldotqmail() +int deldotqmail() { if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } send_template( "del_forward_confirm.html" ); } -deldotqmailnow() +int deldotqmailnow() { if (AdminType!=DOMAIN_ADMIN && !(AdminType==USER_ADMIN && !strcmp(ActionUser, Username))) { sprintf(StatusMessage,"%s", get_html_text("142")); show_menu(Username, Domain, Mytime); - vclose(); - exit(0); + return(142); } @@ -486,8 +462,7 @@ if (fixup_local_name(ActionUser)) { sprintf(StatusMessage,"%s %s\n", get_html_text("160"), Alias); deldotqmail(); - vclose(); - exit(0); + return(160); } if (!(dotqmail_delete_files(ActionUser))) { Index: auth.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/auth.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- auth.c 30 Jan 2004 08:30:58 -0000 1.5 +++ auth.c 31 Jan 2004 11:08:00 -0000 1.6 @@ -31,138 +31,141 @@ #include <vpopmail.h> #include <vauth.h> -extern char *crypt(); - -auth_system(ip_addr, pw) - char *ip_addr; - struct vqpasswd *pw; +set_admin_type() { - FILE *fs; - time_t time1; - time_t time2; - char ip_value[MAX_BUFF]; - char Buffer1[MAX_BUFF]; - char Buffer2[MAX_BUFF]; - - if( chdir(RealDir) < 0 ){ - sprintf(StatusMessage, "%s %s\n", get_html_text("171"), RealDir); - show_login(); - vclose(); - exit(0); + struct vqpasswd *vpw=NULL; + + vpw = vauth_getpw(Username, Domain); + AdminType = NO_ADMIN; + if ( strlen(Domain) > 0 ) { + if ( strcmp(Username,"postmaster")==0 ) { + AdminType = DOMAIN_ADMIN; + } else if ( vpw->pw_gid & QA_ADMIN ) { + AdminType = DOMAIN_ADMIN; + } else { + AdminType = USER_ADMIN; + } } +} - sprintf(Buffer1, "%s/Maildir/%s.qw", pw->pw_dir, Time); +void del_id_files( char *dirname ) +{ + DIR *mydir; + struct dirent *mydirent; + struct stat statbuf; + char DirName[MAX_BIG_BUFF]; + char FileName[MAX_BIG_BUFF]; - fs = fopen(Buffer1, "r"); - if ( fs == NULL ) { - sprintf(StatusMessage, "%s\n", get_html_text("172")); - show_login(); - vclose(); - exit(0); - } + sprintf(DirName, "%s/Maildir", dirname); - if ( fgets(Buffer2, sizeof(Buffer2), fs) == NULL ) { - sprintf(StatusMessage, "%s %d\n", get_html_text("150"), 4); - vclose(); - exit(0); + mydir = opendir(DirName); + if ( mydir == NULL ) return; + + while((mydirent=readdir(mydir))!=NULL){ + if ( strstr(mydirent->d_name,".qw")!=0 ) { + sprintf(FileName, "%s/%s", DirName, mydirent->d_name); + unlink(FileName); + } } - fclose(fs); + closedir(mydir); +} +int create_session_file( char *ip_addr, char *domaindir) +{ + FILE *fs; + char Buffer[MAX_BIG_BUFF]; + char returnhttp[MAX_BUFF]; + char returntext[MAX_BUFF]; + struct vqpasswd *vpw=NULL; -#ifdef IPAUTH - GetValue(Buffer2, ip_value, "ip_addr=", sizeof(ip_value)); - if ( strcmp(ip_addr, ip_value) != 0 ) { - unlink(Buffer1); - sprintf(StatusMessage,"invalid\n"); - show_login(); - vclose(); - exit(0); + del_id_files( domaindir ); + + memset(Buffer, 0, sizeof(Buffer)); + + Mytime = time(NULL); + sprintf(Buffer, "%s/Maildir/%d.qw", domaindir, Mytime); + fs = fopen(Buffer, "w"); + if ( fs == NULL ) { + fprintf(actout,"MAIN %s %s\n", get_html_text("144"), Buffer); + fprintf(stderr,"MAIN %s %s\n", get_html_text("144"), Buffer); + return(1); } -#endif - time1 = atoi(Time); time2 = time(NULL); - if ( time2 > time1 + 7200 ) { - unlink(Buffer1); - sprintf(StatusMessage, "%s\n", get_html_text("173")); - show_login(); - vclose(); - exit(0); + vpw = vauth_getpw(Username, Domain); + AdminType = NO_ADMIN; + if ( strlen(Domain) > 0 ) { + if ( strcmp(Username,"postmaster")==0 ) { + AdminType = DOMAIN_ADMIN; + } else if ( vpw->pw_gid & QA_ADMIN ) { + AdminType = DOMAIN_ADMIN; + } else { + AdminType = USER_ADMIN; + } } + memset(Buffer, 0, sizeof(Buffer)); + + /* set session vars */ + GetValue(TmpCGI, returntext, "returntext=", sizeof(returntext)); + GetValue(TmpCGI, returnhttp, "returnhttp=", sizeof(returnhttp)); + sprintf(Buffer, + "ip_addr=%s&returntext=%s&returnhttp=%s&admintype=%d\n", + ip_addr, returntext, returnhttp, AdminType); + fputs(Buffer,fs); + fclose(fs); + return(0); } -auth_user_domain(ip_addr,pw) +int get_session_data( Username, Domain, ip_addr) + char *Username; + char *Domain; char *ip_addr; - struct vqpasswd *pw; { FILE *fs; time_t time1; time_t time2; char ip_value[MAX_BUFF]; - char Buffer1[MAX_BUFF]; + char FileName[MAX_BUFF]; char Buffer2[MAX_BUFF]; + struct vqpasswd *pw; + + pw = vauth_getpw( Username, Domain ); if ( chdir(RealDir) < 0 ) { - sprintf(StatusMessage, "%s %s\n", get_html_text("171"), RealDir ); - show_login(); - vclose(); - exit(0); + /* can't cd to domain directory */ + return( 171 ); } - sprintf(Buffer1, "%s/Maildir/%s.qw", pw->pw_dir, Time); + /* Create filename for session file */ + sprintf(FileName, "%s/Maildir/%s.qw", pw->pw_dir, Time); + fprintf(stderr, "Session file name: %s\n", FileName ); - fs = fopen(Buffer1, "r"); - if ( fs == NULL ) { - sprintf(StatusMessage, "%s\n", get_html_text("172")); - show_login(); - vclose(); - exit(0); + /* Try to open file */ + if ( NULL == (fs = fopen(FileName, "r"))) { + fprintf(stderr, "Session file open failed\n" ); + return(172); } - if ( fgets(Buffer2, sizeof(Buffer2), fs) == NULL ) { - sprintf(StatusMessage, "%s %d\n", get_html_text("150"), 5); - vclose(); - exit(0); + + if ( NULL == ( fgets(Buffer2, sizeof(Buffer2), fs))) { + fprintf(stderr, "Session file read failed\n" ); + return(150); } + fclose(fs); #ifdef IPAUTH GetValue(Buffer2, ip_value, "ip_addr=", sizeof(ip_value)); if ( strcmp(ip_addr, ip_value) != 0 ) { - unlink(Buffer1); - sprintf(StatusMessage, "%s %d (%s != %s .. %s)\n", get_html_text("150"), 6, ip_addr, ip_value, Buffer2); - show_login(); - vclose(); - exit(0); + fprintf(stderr, "Session IP address check failed\n" ); + unlink(FileName); + return(150); } #endif time1 = atoi(Time); time2 = time(NULL); if ( time2 > time1 + 7200 ) { - unlink(Buffer1); - sprintf(StatusMessage, "%s\n", get_html_text("173")); - show_login(); - vclose(); - exit(0); + unlink(FileName); + return(173); } -} - -set_admin_type() -{ - struct vqpasswd *vpw=NULL; - - vpw = vauth_getpw(Username, Domain); - AdminType = NO_ADMIN; - if ( strlen(Domain) > 0 ) { - if ( strcmp(Username,"postmaster")==0 ) { - AdminType = DOMAIN_ADMIN; -#ifdef VQPASSWD_HAS_PW_FLAGS - } else if ( vpw->pw_flags & QA_ADMIN ) { -#else - } else if ( vpw->pw_gid & QA_ADMIN ) { -#endif - AdminType = DOMAIN_ADMIN; - } else { - AdminType = USER_ADMIN; - } - } +return(0); } Index: autorespond.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/autorespond.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- autorespond.c 30 Jan 2004 08:30:58 -0000 1.6 +++ autorespond.c 31 Jan 2004 11:08:00 -0000 1.7 @@ -72,7 +72,7 @@ if ( (fs=fopen(mydirent->d_name,"r"))==NULL) { strcpy(uBufA, "3"); sprintf(uBufB, "SAL %s %s\n", get_html_text("144"), mydirent->d_name); - send_template_now("show_error_line.html"); + send_template("show_error_line.html"); continue; } @@ -94,7 +94,7 @@ qmail_button(uBufA, "delautorespond", addr, "delete.png" ); qmail_button(uBufB, "modautorespond", addr, "modify.png" ); sprintf(uBufC, "%s@%s", addr, Domain); - send_template_now("show_autorespond_line.html"); + send_template("show_autorespond_line.html"); } sort_cleanup(); } @@ -104,15 +104,13 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( MaxAutoResponders != -1 && CurAutoResponders >= MaxAutoResponders ) { fprintf(actout, "%s %d\n", get_html_text("158"), MaxAutoResponders); show_menu(); - vclose(); - exit(0); + return(158); } send_template( "add_autorespond.html" ); @@ -129,58 +127,50 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( MaxAutoResponders != -1 && CurAutoResponders >= MaxAutoResponders ) { fprintf(actout, "%s %d\n", get_html_text("158"), MaxAutoResponders); show_menu(); - vclose(); - exit(0); + return(158); } if ( fixup_local_name(ActionUser) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("174"), ActionUser); addautorespond(); - vclose(); - exit(0); + return(174); } if ( check_local_user(ActionUser) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("175"), ActionUser); addautorespond(); - vclose(); - exit(0); + return(175); } if ( strlen(ActionUser) == 0 ) { sprintf(StatusMessage, "%s\n", get_html_text("176")); addautorespond(); - vclose(); - exit(0); + return(176); } if ( strlen(Newu)>0 && check_email_addr(Newu) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("177"), Newu); addautorespond(); - vclose(); - exit(0); + return(177); } if (strlen(Alias) <= 1) { sprintf(StatusMessage, "%s %s\n", get_html_text("178"), ActionUser); addautorespond(); - vclose(); - exit(0); + return(178); } if (strlen(Message) <= 1) { sprintf(StatusMessage, "%s %s\n", get_html_text("179"), ActionUser); addautorespond(); - vclose(); - exit(0); + return(179); } @@ -221,6 +211,7 @@ /* * Report success */ + CurAutoResponders++; sprintf(StatusMessage, "%s %s@%s\n", get_html_text("180"), ActionUser, Domain); show_autoresponders(Username,Domain); @@ -231,8 +222,7 @@ { if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } send_template( "del_autorespond_confirm.html" ); } @@ -246,8 +236,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } for(i=0;ActionUser[i]!=0;++i) if (ActionUser[i]=='.') ActionUser[i] = ':'; @@ -269,6 +258,7 @@ vdelfiles(Buffer1); sprintf(StatusMessage, "%s %s\n", get_html_text("182"), ActionUser); + CurAutoResponders--; if(CurAutoResponders == 0) { show_menu(Username, Domain, Mytime); } else { @@ -284,11 +274,12 @@ FILE *fs; int i,j; +/* if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } +*/ /* Build the .qmail file name */ sprintf(fqfn, ".qmail-%s", ActionUser); @@ -382,36 +373,31 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( fixup_local_name(ActionUser) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("174"), ActionUser); modautorespond(); - vclose(); - exit(0); + return(174); } if ( strlen(Newu)>0 && check_email_addr(Newu) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("177"), Newu); modautorespond(); - vclose(); - exit(0); + return(177); } if (strlen(Alias) <= 1) { sprintf(StatusMessage, "%s %s\n", get_html_text("177"), ActionUser); modautorespond(); - vclose(); - exit(0); + return(177); } if (strlen(Message) <= 1) { sprintf(StatusMessage, get_html_text("BODY_EMPTY"), ActionUser); modautorespond(); - vclose(); - exit(0); + return(0); } Index: command.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/command.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- command.c 30 Jan 2004 08:30:58 -0000 1.5 +++ command.c 31 Jan 2004 11:08:00 -0000 1.6 @@ -36,227 +36,212 @@ process_commands(char *command) { int pid; + int rv=0; // return value char Buffer[MAX_BUFF]; - if (strcmp(command, "showmenu") == 0 ) { - show_menu(Username, Domain, Mytime); + fprintf( stderr, "Process_commands: %s\n", command ); - } else if (strcmp(command, "showusers") == 0) { - GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber)); - GetValue(TmpCGI, SearchUser, "searchuser=", sizeof(SearchUser)); - show_users(Username, Domain, Mytime, command); +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* No rights */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - } else if (strcmp(command, "showforwards") == 0) { - GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber)); - show_forwards(Username, Domain, Mytime, command); + if (strcmp(command, "logout") == 0 ) { + sprintf(Buffer, "%s/%s/Maildir", RealDir, Username ); + del_id_files(Buffer); + show_login(); - } else if (strcmp(command, "showmailinglists") == 0) { - show_mailing_lists(Username, Domain, Mytime, command); +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* User rights */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + } else if (AdminType < USER_ADMIN ) { + rv = show_login(); + + } else if (strcmp(command, "showmenu") == 0 ) { + rv = show_menu(Username, Domain, Mytime); + + } else if (strcmp(command, "adddotqmail") == 0 ) { + rv = adddotqmail(); + + } else if (strcmp(command, "adddotqmailnow") == 0 ) { + GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); + rv = adddotqmailnow(); + + } else if (strcmp(command, "deldotqmail") == 0 ) { + rv = deldotqmail(); + + } else if (strcmp(command, "deldotqmailnow") == 0 ) { + rv = deldotqmailnow(); + + } else if (strcmp(command, "moddotqmail") == 0 ) { + rv = moddotqmail(); + + } else if (strcmp(command, "moddotqmailnow") == 0 ) { + GetValue(TmpCGI, Action, "action=", sizeof(Action)); + rv = moddotqmailnow(); + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Domain rights */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + } else if (AdminType < DOMAIN_ADMIN ) { + rv = show_menu(Username, Domain, Mytime); + +/* A U T O R E S P O N D E R S */ } else if (strcmp(command, "showautoresponders") == 0) { - show_autoresponders(Username, Domain, Mytime, command); + rv = show_autoresponders(Username, Domain, Mytime, command); - } else if (strcmp(command, "adduser") == 0 ) { - adduser(); + } else if (strcmp(command, "addautorespond") == 0 ) { + rv = addautorespond(); - } else if (strcmp(command, "addusernow") == 0 ) { - addusernow(); + } else if (strcmp(command, "addautorespondnow") == 0 ) { + GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); + GetValue(TmpCGI, Newu, "owner=", sizeof(Newu)); + rv = addautorespondnow(); - } else if (strcmp(command, "bounceall") == 0 ) { - bounceall(); + } else if (strcmp(command, "delautorespond") == 0 ) { + rv = delautorespond(); - } else if (strcmp(command, "deleteall") == 0 ) { - deleteall(); + } else if (strcmp(command, "delautorespondnow") == 0 ) { + rv = delautorespondnow(); - } else if (strcmp(command, "setremotecatchall") == 0 ) { - setremotecatchall(); + } else if (strcmp(command, "modautorespond") == 0 ) { + rv = modautorespond(); - } else if (strcmp(command, "setremotecatchallnow") == 0 ) { - setremotecatchallnow(); + } else if (strcmp(command, "modautorespondnow") == 0 ) { + GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); + GetValue(TmpCGI, Newu, "owner=", sizeof(Newu)); + rv = modautorespondnow(); + +/* F O R W A R D S */ + + } else if (strcmp(command, "showforwards") == 0) { + rv = show_forwards(Username, Domain, Mytime, command); + +/* M A I L I N G L I S T S */ + + } else if (strcmp(command, "showmailinglists") == 0) { + rv = show_mailing_lists(Username, Domain, Mytime, command); } else if (strcmp(command, "addlistmodnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - addlistgroupnow(1); + rv = addlistgroupnow(1); } else if (strcmp(command, "dellistmod") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - dellistgroup("del_listmod.html"); + rv = dellistgroup("del_listmod.html"); } else if (strcmp(command, "dellistmodnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - dellistgroupnow(1); + rv = dellistgroupnow(1); } else if (strcmp(command, "addlistmod") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - addlistgroup("add_listmod.html"); + rv = addlistgroup("add_listmod.html"); } else if (strcmp(command, "showlistmod") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - show_list_group("show_moderators.html"); + rv = show_list_group("show_moderators.html"); } else if (strcmp(command, "addlistdig") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - addlistgroup("add_listdig.html"); + rv = addlistgroup("add_listdig.html"); } else if (strcmp(command, "addlistdignow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - addlistgroupnow(2); + rv = addlistgroupnow(2); } else if (strcmp(command, "dellistdig") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - dellistgroup("del_listdig.html"); + rv = dellistgroup("del_listdig.html"); } else if (strcmp(command, "dellistdignow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - dellistgroupnow(2); + rv = dellistgroupnow(2); } else if (strcmp(command, "showlistdig") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - show_list_group("show_digest_subscribers.html"); - - } else if (strcmp(command, "moduser") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - moduser(); - - } else if (strcmp(command, "modusernow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Password1, "password1=", sizeof(Password1)); - GetValue(TmpCGI, Password2, "password2=", sizeof(Password2)); - GetValue(TmpCGI, Gecos, "gecos=", sizeof(Gecos)); - modusergo(); - - } else if (strcmp(command, "deluser") == 0 ) { - GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser)); - deluser(); - - } else if (strcmp(command, "delusernow") == 0 ) { - GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser)); - delusergo(); - - } else if (strcmp(command, "moddotqmail") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); - moddotqmail(); - - } else if (strcmp(command, "moddotqmailnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); - GetValue(TmpCGI, LineData, "linedata=", sizeof(LineData)); - GetValue(TmpCGI, Action, "action=", sizeof(Action)); - moddotqmailnow(); - - } else if (strcmp(command, "deldotqmail") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); - deldotqmail(); - - } else if (strcmp(command, "deldotqmailnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); - deldotqmailnow(); - - } else if (strcmp(command, "adddotqmail") == 0 ) { - GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); - adddotqmail(); - - } else if (strcmp(command, "adddotqmailnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); - GetValue(TmpCGI, Alias, "alias=", sizeof(Alias)); - GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); - adddotqmailnow(); + rv = show_list_group("show_digest_subscribers.html"); } else if (strcmp(command, "addmailinglist") == 0 ) { - addmailinglist(); + rv = addmailinglist(); } else if (strcmp(command, "delmailinglist") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - delmailinglist(); + rv = delmailinglist(); } else if (strcmp(command, "delmailinglistnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - delmailinglistnow(); + rv = delmailinglistnow(); } else if (strcmp(command, "addlistusernow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - addlistgroupnow(0); + rv = addlistgroupnow(0); } else if (strcmp(command, "dellistuser") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - dellistgroup("del_listuser.html"); + rv = dellistgroup("del_listuser.html"); } else if (strcmp(command, "dellistusernow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); - dellistgroupnow(0); + rv = dellistgroupnow(0); } else if (strcmp(command, "addlistuser") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - addlistgroup("add_listuser.html"); + rv = addlistgroup("add_listuser.html"); } else if (strcmp(command, "addmailinglistnow") == 0 ) { GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); - addmailinglistnow(); + rv = addmailinglistnow(); } else if (strcmp(command, "modmailinglist") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - modmailinglist(); + rv = modmailinglist(); } else if (strcmp(command, "modmailinglistnow") == 0 ) { GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); - modmailinglistnow(); + rv = modmailinglistnow(); - } else if (strcmp(command, "modautorespond") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - modautorespond(); + } else if (strcmp(command, "showlistusers") == 0 ) { + rv = show_list_group("show_subscribers.html"); - } else if (strcmp(command, "addautorespond") == 0 ) { - addautorespond(); + } else if (strcmp(command, "setdefault") == 0 ) { + rv = setdefaultaccount(); - } else if (strcmp(command, "addautorespondnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); - GetValue(TmpCGI, Alias, "alias=", sizeof(Alias)); - GetValue(TmpCGI, Message, "message=", sizeof(Message)); - GetValue(TmpCGI, Newu, "owner=", sizeof(Newu)); - addautorespondnow(); +/* U S E R S */ - } else if (strcmp(command, "modautorespondnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser)); - GetValue(TmpCGI, Alias, "alias=", sizeof(Alias)); - GetValue(TmpCGI, Message, "message=", sizeof(Message)); - GetValue(TmpCGI, Newu, "owner=", sizeof(Newu)); - modautorespondnow(); + } else if (strcmp(command, "showusers") == 0) { + rv = show_users(Username, Domain, Mytime, command); - } else if (strcmp(command, "showlistusers") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - show_list_group("show_subscribers.html"); + } else if (strcmp(command, "adduser") == 0 ) { + rv = adduser(); - } else if (strcmp(command, "setdefault") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber)); - setdefaultaccount(); + } else if (strcmp(command, "addusernow") == 0 ) { + rv = addusernow(); - } else if (strcmp(command, "delautorespond") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - delautorespond(); + } else if (strcmp(command, "deluser") == 0 ) { + GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser)); + rv = deluser(); - } else if (strcmp(command, "delautorespondnow") == 0 ) { - GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); - delautorespondnow(); + } else if (strcmp(command, "delusernow") == 0 ) { + GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser)); + rv = delusergo(); + + } else if (strcmp(command, "moduser") == 0 ) { + rv = moduser(); + + } else if (strcmp(command, "modusernow") == 0 ) { + rv = modusergo(); + + } else if (strcmp(command, "bounceall") == 0 ) { + rv = bounceall(); + + } else if (strcmp(command, "deleteall") == 0 ) { + rv = deleteall(); + + } else if (strcmp(command, "setremotecatchall") == 0 ) { + rv = setremotecatchall(); + + } else if (strcmp(command, "setremotecatchallnow") == 0 ) { + rv = setremotecatchallnow(); + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* System rights */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + } else { + fprintf(stderr, "Invalid command: %s\n", command); - } else if (strcmp(command, "logout") == 0 ) { - sprintf(Buffer, "%s/%s/Maildir", RealDir, Username ); - del_id_files(Buffer); - show_login(); } - vclose(); - exit(0); + if( rv > -1 ) { + printf( "Return Value: %d<BR>\n", rv ); + fprintf(stderr, "Return Value: %d<BR>\n", rv ); + } } setdefaultaccount() Index: forward.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/forward.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- forward.c 30 Jan 2004 08:30:58 -0000 1.5 +++ forward.c 31 Jan 2004 11:08:00 -0000 1.6 @@ -36,19 +36,21 @@ int show_forwards(char *user, char *dom, time_t mytime, char *dir) { + fprintf( stderr, "show_forwards\n" ); + if (AdminType != DOMAIN_ADMIN) { - fprintf(stderr, "%s", get_html_text("142")); - vclose(); - exit(0); + fprintf( stderr, "Not an admin\n" ); + sprintf(StatusMessage,"%s", get_html_text("142")); + return(142); } if(CurForwards == 0) { - fprintf(stderr, "%s", get_html_text("232")); + fprintf( stderr, "show_forwards - aint none\n" ); sprintf(StatusMessage,"%s", get_html_text("232")); show_menu(Username, Domain, Mytime); - vclose(); - exit(0); + return(232); } else { + fprintf( stderr, "show_forwards - send template\n" ); send_template("show_forwards.html"); } Index: limits.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/limits.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- limits.c 10 Oct 2003 16:36:24 -0000 1.2 +++ limits.c 31 Jan 2004 11:08:00 -0000 1.3 @@ -35,6 +35,9 @@ load_limits() { + + fprintf( stderr, "load_limits\n" ); + vget_limits(Domain, &Limits); MaxPopAccounts = Limits.maxpopaccounts; MaxAliases = Limits.maxaliases; @@ -48,4 +51,5 @@ DisablePasswordChanging = Limits.disable_passwordchanging; DisableWebmail = Limits.disable_webmail; DisableRelay = Limits.disable_relay; + } Index: mailinglist.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/mailinglist.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- mailinglist.c 30 Jan 2004 08:30:58 -0000 1.7 +++ mailinglist.c 31 Jan 2004 11:08:00 -0000 1.8 @@ -47,18 +47,17 @@ int show_mailing_lists(char *user, char *dom, time_t mytime) { + fprintf(stderr, "show_mailing_lists was called\n"); if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } /* see if there's anything to display */ if ( CurMailingLists == 0 ) { sprintf(StatusMessage,"%s", get_html_text("231")); show_menu(); - vclose(); - exit(0); + return(231); } if ( MaxMailingLists == 0 ) { @@ -79,8 +78,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( MaxMailingLists == 0 ) { return(0); @@ -104,7 +102,7 @@ strcpy(uBufA, "5"); #endif sprintf(uBufB, "SMLL %s %s\n", get_html_text("144"), mydirent->d_name); - send_template_now("show_error_line.html"); + send_template("show_error_line.html"); continue; } fgets(Buffer, sizeof(Buffer), fs); @@ -149,7 +147,7 @@ fclose(fs); } #endif - send_template_now("show_mailinglist_line.html"); + send_template("show_mailinglist_line.html"); } sort_cleanup(); } @@ -180,8 +178,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if (*EZMLMDIR == 'n' || MaxMailingLists == 0 ) { @@ -227,7 +224,7 @@ sprintf(uBufA,"%d", i); sprintf(uBufB,"%s", addr); sprintf(uBufC,"%s@%s", addr, Domain); - send_template_now("show_mailinglist_line2.html"); + send_template("show_mailinglist_line2.html"); } sort_cleanup(); @@ -239,16 +236,14 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( MaxMailingLists != -1 && CurMailingLists >= MaxMailingLists ) { fprintf(actout, "%s %d\n", get_html_text("184"), MaxMailingLists); show_menu(); - vclose(); - exit(0); + return(184); } /* set up default options for new list */ @@ -266,8 +261,7 @@ { if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } send_template( "del_mailinglist_confirm.html" ); @@ -283,8 +277,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( (mydir = opendir(".")) == NULL ) { @@ -322,6 +315,8 @@ sprintf(Buffer2, "%s/%s", RealDir, ActionUser); vdelfiles(Buffer2); + CurMailingLists--; + sprintf(StatusMessage, "%s %s\n", get_html_text("186"), ActionUser); if ( CurMailingLists == 0 ) { show_menu(); @@ -397,15 +392,13 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if ( fixup_local_name(ActionUser) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("188"), ActionUser); addmailinglist(); - vclose(); - exit(0); + return(188); } /* update listopt based on user selections */ @@ -577,18 +570,17 @@ fprintf(actout, "%s %d\n", get_html_text("184"), MaxMailingLists); show_menu(); - vclose(); - exit(0); + return(184); } if ( check_local_user(ActionUser) ) { sprintf(StatusMessage, "%s %s\n", get_html_text("175"), ActionUser); addmailinglist(); - vclose(); - exit(0); + return(175); } ezmlm_make(1); + CurMailingLists++; sprintf(StatusMessage, "%s %s@%s\n", get_html_text("187"), ActionUser, Domain); @@ -610,8 +602,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } lowerit(ActionUser); @@ -712,8 +703,7 @@ { if (AdminType != DOMAIN_ADMIN) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } if (MaxMailingLists == 0) { @@ -733,8 +723,7 @@ { if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } send_template(template); @@ -756,8 +745,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } lowerit(ActionUser); @@ -771,8 +759,7 @@ } else { addlistuser(); } - vclose(); - exit(0); + return(148); } pid=fork(); @@ -802,8 +789,7 @@ get_html_text("193"), ActionUser, Domain); send_template( "add_listuser.html" ); } - vclose(); - exit(0); + return(999); } /* @@ -816,8 +802,7 @@ { if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } send_template(template); @@ -837,8 +822,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } lowerit(Newu); @@ -868,8 +852,7 @@ ActionUser, Domain); } show_mailing_lists(Username, Domain, Mytime); - vclose(); - exit(0); + return(999); } /* @@ -889,8 +872,7 @@ if ( AdminType!=DOMAIN_ADMIN ) { sprintf(StatusMessage,"%s", get_html_text("142")); - vclose(); - exit(0); + return(142); } strcpy (Alias, ""); /* initialize Alias (list owner) to empty string */ Index: qmailadmin.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/qmailadmin.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- qmailadmin.c 30 Jan 2004 08:30:58 -0000 1.9 +++ qmailadmin.c 31 Jan 2004 11:08:00 -0000 1.10 @@ -43,6 +43,7 @@ char Gecos[MAX_BUFF]; char Quota[MAX_BUFF]; char Time[MAX_BUFF]; +char Action[MAX_BUFF]; char ActionUser[MAX_BUFF]; char Newu[MAX_BUFF]; char Password1[MAX_BUFF]; @@ -109,172 +110,218 @@ FILE *color_table; void del_id_files( char *); +int create_session_file( char *ip_addr, char *domaindir); -main(argc,argv) - int argc; - char *argv[]; +get_parms() { - const char *u; - const char *p; - const char *ip_addr=getenv("REMOTE_ADDR"); - const char *x_forward=getenv("HTTP_X_FORWARDED_FOR"); - char *pi; - int i,j; char *rm; - time_t time1; - time_t time2; - FILE *fs; - int pid; - char returnhttp[MAX_BUFF]; - char returntext[MAX_BUFF]; - char TmpBuf[MAX_BIG_BUFF]; - char TmpBuf1[MAX_BUFF]; - char TmpBuf2[MAX_BUFF]; - char TmpBuf3[MAX_BUFF]; +/* Get the REQUEST_METHOD */ + rm = getenv("REQUEST_METHOD"); + rm = (rm == NULL ? "" : strdup(rm)); - init_globals(); +/* Decide how to retrieve the data */ + if ( strncmp(rm , "POST", 4) == 0 ) { + get_cgi(); + } else { + TmpCGI = getenv("QUERY_STRING"); + TmpCGI = (TmpCGI == NULL ? "" : strdup(TmpCGI)); + } + +/* Now get common values out of TmpCGI */ + GetValue(TmpCGI, Username, "user=", sizeof(Username)); + GetValue(TmpCGI, Domain, "dom=", sizeof(Domain)); + GetValue(TmpCGI, Time, "time=", sizeof(Time)); + GetValue(TmpCGI, Action, "action=", sizeof(Time)); + GetValue(TmpCGI, Password, "password=", sizeof(Password)); + + Mytime = atoi(Time); + + GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber)); + GetValue(TmpCGI, SearchUser, "searchuser=", sizeof(SearchUser)); + GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser)); + GetValue(TmpCGI, Password1, "password1=", sizeof(Password1)); + GetValue(TmpCGI, Password2, "password2=", sizeof(Password2)); + GetValue(TmpCGI, Gecos, "gecos=", sizeof(Gecos)); + GetValue(TmpCGI, AliasType, "atype=", sizeof(AliasType)); + GetValue(TmpCGI, Alias, "alias=", sizeof(Alias)); + GetValue(TmpCGI, LineData, "linedata=", sizeof(LineData)); + GetValue(TmpCGI, Message, "message=", sizeof(Message)); + GetValue(TmpCGI, Newu, "newu=", sizeof(Newu)); + + fprintf(stderr, "GetParms: Username: %s Password: %s Domain: %s\n", + Username, Password, Domain); + +} + +setuidgid(char *Domain) +{ + /* get the real uid and gid and change to that user */ + vget_assign(Domain,RealDir,sizeof(RealDir),&Uid,&Gid); + + if ( geteuid() == 0 ) { + if ( setgid(Gid) != 0 ) perror("setgid"); + if ( setuid(Uid) != 0 ) perror("setuid"); + } + + if ( chdir(RealDir) < 0 ) { + fprintf(stderr, "MAIN %s %s\n", get_html_text("171"), RealDir ); + } +} + +int get_command_parms( char *commandparms, int parmsize ) +{ + char *pi; + int i,j; + + fprintf(stderr, "get_command_parms started\n" ); - if (x_forward) ip_addr = x_forward; - if (!ip_addr) ip_addr = "127.0.0.1"; pi=getenv("PATH_INFO"); if ( pi ) pi = strdup(pi); + fprintf(stderr, "get_command_parms pi: %s\n", pi ); + + memset(commandparms, 0, parmsize); + fprintf(stderr, "sizeof commandparms: %d", parmsize); + + /* Cut off the first five characters... '/com/' */ if (pi && strncmp(pi, "/com/", 5) == 0) { - /* /com/ found in URL so there is something to do */ - fprintf( stderr, "\nMystery if case #1\n" ); - struct vqpasswd *pw; + for(j=0,i=5;pi[i]!=0&&j<99;++i,++j) commandparms[j] = pi[i]; + fprintf(stderr, "get command parms - found it: %s\n", commandparms ); + return( 0 ); + } - memset(TmpBuf2, 0, sizeof(TmpBuf2)); - for(j=0,i=5;pi[i]!=0&&j<99;++i,++j) TmpBuf2[j] = pi[i]; - rm = getenv("REQUEST_METHOD"); - rm = (rm == NULL ? "" : strdup(rm)); + fprintf(stderr, "get command parms - nothing\n" ); + return(1); +} - if ( strncmp(rm , "POST", 4) == 0 ) { - get_cgi(); - } else { - TmpCGI = getenv("QUERY_STRING"); - TmpCGI = (TmpCGI == NULL ? "" : strdup(TmpCGI)); - } +get_my_ip( char *ip_address ) +{ - GetValue(TmpCGI, Username, "user=", sizeof(Username)); - GetValue(TmpCGI, Domain, "dom=", sizeof(Domain)); - GetValue(TmpCGI, Time, "time=", sizeof(Time)); - Mytime = atoi(Time); - pw = vauth_getpw( Username, Domain ); + const char *ip_addr=getenv("REMOTE_ADDR"); + const char *x_forward=getenv("HTTP_X_FORWARDED_FOR"); - /* get the real uid and gid and change to that user */ - vget_assign(Domain,RealDir,sizeof(RealDir),&Uid,&Gid); - if ( geteuid() == 0 ) { - if ( setgid(Gid) != 0 ) perror("setgid"); - if ( setuid(Uid) != 0 ) perror("setuid"); - } + if (x_forward) ip_addr = x_forward; + if (!ip_addr) ip_addr = "127.0.0.1"; - if ( chdir(RealDir) < 0 ) { - fprintf(stderr, "MAIN %s %s\n", get_html_text("171"), RealDir ); - } + strcpy(ip_address, ip_addr); +} + +serious_error_abort( int errors ) +{ +fprintf(stderr, "Serious internal error: %d\n", errors); + +printf("<HTML><BODY><H1>%s - %d</H1></BODY></HTML>", + "Serious internal error", errors ); +vclose(); +exit(0); +} + +get_pathinfo() +{ + + +} + +main(argc,argv) + int argc; + char *argv[]; +{ + char CommandParms[MAX_BUFF]; + char ip_addr[MAX_BUFF]; + struct vqpasswd *pw; + int errors = 0; + char err_code[4]; + + umask(VPOPMAIL_UMASK); + + init_globals(); + if( open_lang()) errors += 1; + if( open_colortable()) errors += 2; + get_parms(); + get_my_ip( ip_addr ); + + paint_headers(); + + /* If there are errors starting up, report them and exit */ + if( errors > 0 ) serious_error_abort( errors ); + + send_template("header.html"); + + if (!get_command_parms(CommandParms, sizeof(CommandParms))) { + + /* Have command - prepare to execute it */ + fprintf( stderr, "\nMystery if case #1\n" ); + setuidgid( Domain ); set_admin_type(); count_stuff(); - if ( AdminType == USER_ADMIN || AdminType == DOMAIN_ADMIN ) { - auth_user_domain(ip_addr, pw); + if( errors = get_session_data( Username, Domain, ip_addr )) { + + /* Error with session data - need to login */ + sprintf(err_code, "%3d\n", errors ); + fprintf( stderr, "Error code returned: %s", err_code); + sprintf(StatusMessage, "%s\n", get_html_text( err_code )); + show_login(); + } else { - auth_system(ip_addr, pw); + + /* Command requested, and session valid - do it */ + process_commands(CommandParms); + } - process_commands(TmpBuf2); - } else { - char *rm; - struct vqpasswd *pw; - FILE *fs; + } else if ( strlen(Action) == 0) { - fprintf( stderr, "\nMystery if case #3\n" ); + /* No button pressed... Show login page */ + show_login(); - /* Just logged in */ - rm = getenv("REQUEST_METHOD"); - if ( rm ) rm = strdup(rm); + } else if (0 == strlen(Username) || 0==strlen(Password)) { - if ( rm && ( strncmp(rm,"POST",4)==0 || strncmp(rm,"GET",3)==0)) { - if ( strncmp(rm , "POST", 4) == 0 ) { - get_cgi(); - } else { - TmpCGI = getenv("QUERY_STRING"); - TmpCGI = (TmpCGI == NULL ? "" : strdup(TmpCGI)); - } + /* If they left anything blank, don't bother to authenticate */ + sprintf(StatusMessage, "%s\n", get_html_text("316")); + show_login(); - GetValue(TmpCGI, Username, "username=", sizeof(Username)); - GetValue(TmpCGI, Domain, "domain=", sizeof(Domain)); - GetValue(TmpCGI, Password, "password=", sizeof(Password)); + } else if (NULL == (pw = vauth_user( Username, Domain, Password, "" ))) { - vget_assign(Domain,RealDir,sizeof(RealDir),&Uid,&Gid); - if ( geteuid() == 0 ) { - if ( setgid(Gid) != 0 ) perror("setgid"); - if ( setuid(Uid) != 0 ) perror("setuid"); - } + /* Invalid user/domain/password - show error message */ + sprintf(StatusMessage, "%s\n", get_html_text("198")); + show_login(); - /* Authenticate a user and domain admin */ - if ( strlen(Domain) > 0 ) { - chdir(RealDir); - load_limits(); + } else { - pw = vauth_user( Username, Domain, Password, "" ); - if ( pw == NULL ) { - sprintf(StatusMessage, "%s\n", get_html_text("198")); - show_login(); - vclose(); - exit(0); - } + /* Just logged in */ + setuidgid( Domain ); + if( create_session_file( ip_addr, pw->pw_dir )) { - sprintf(TmpBuf, "%s/Maildir", pw->pw_dir); - del_id_files( TmpBuf); + printf( "Unable to create session file" ); - Mytime = time(NULL); - sprintf(TmpBuf, "%s/Maildir/%d.qw", pw->pw_dir, Mytime); - fs = fopen(TmpBuf, "w"); - if ( fs == NULL ) { - fprintf(actout,"MAIN %s %s\n", get_html_text("144"), TmpBuf); - fprintf(stderr,"MAIN %s %s\n", get_html_text("144"), TmpBuf); - vclose(); - exit(0); - } - memset(TmpBuf, 0, sizeof(TmpBuf)); - /* set session vars */ - GetValue(TmpCGI, returntext, "returntext=", sizeof(returntext)); - GetValue(TmpCGI, returnhttp, "returnhttp=", sizeof(returnhttp)); - sprintf(TmpBuf, "ip_addr=%s&returntext=%s&returnhttp=%s\n", - ip_addr, returntext, returnhttp); - fputs(TmpBuf,fs); - // fputs(ip_addr, fs); - fclose(fs); - vget_assign(Domain, TmpBuf1, sizeof(TmpBuf1), &Uid, &Gid); - set_admin_type(); + } else { - /* show the main menu for domain admins, modify user page - for regular users */ - if (AdminType == DOMAIN_ADMIN) { - show_menu(Username, Domain, Mytime); - } else { - strcpy (ActionUser, Username); - moduser(); - } - vclose(); - exit(0); - } - } + load_limits(); + + if (AdminType == DOMAIN_ADMIN) { + + /* show the main menu for domain admins */ + show_menu(Username, Domain, Mytime); + + } else { + + /* show the modify user page for regular users */ + strcpy (ActionUser, Username); + moduser(); + + } + } } - show_login(); + + send_template("footer.html"); vclose(); } init_globals() { - int i,j; - struct vqpasswd *pw; - char *accept_lang; - char *langptr, *qptr; - int lang_err; - float maxq, thisq; memset(CGIValues, 0, sizeof(CGIValues)); CGIValues['0'] = 0; @@ -306,6 +353,7 @@ memset(Password, 0, sizeof(Password)); memset(Quota, 0, sizeof(Quota)); memset(Time, 0, sizeof(Time)); + memset(Action, 0, sizeof(Action)); memset(ActionUser, 0, sizeof(ActionUser)); memset(Newu, 0, sizeof(Newu)); memset(Password1, 0, sizeof(Password1)); @@ -315,68 +363,11 @@ memset(Message, 0, sizeof(Message)); AdminType = NO_ADMIN; +} - lang_fs = NULL; - - /* Parse HTTP_ACCEPT_LANGUAGE to find highest preferred language - * that we have a translation for. Example setting: - * de-de, ja;q=0.25, en;q=0.50, de;q=0.75 - * The q= lines determine which is most preferred, defaults to 1. - * Our routine starts with en at 0.0, and then would try de-de (1.00), - * de (1.00), ja (0.25), en (0.50), and then de (0.75). - */ - - /* default to English at 0.00 preference */ - maxq = 0.0; - strcpy (Lang, "en"); - - /* read in preferred languages */ - langptr = getenv("HTTP_ACCEPT_LANGUAGE"); - if (langptr != NULL) { - accept_lang = malloc (strlen(langptr)); - strcpy (accept_lang, langptr); - langptr = strtok(accept_lang, " ,\n"); - while (langptr != NULL) { - qptr = strstr (langptr, ";q="); - if (qptr != NULL) { - *qptr = '\0'; /* convert semicolon to NULL */ - thisq = (float) atof (qptr+3); - } else { - thisq = 1.0; - } - - /* if this is a better match than our previous best, try it */ - if (thisq > maxq) { - lang_err = open_lang (langptr); - - /* Remove this next section for strict interpretation of - * HTTP_ACCEPT_LANGUAGE. It will try language xx (with the - * same q value) if xx-yy fails. - */ - if ((lang_err == -1) && (langptr[2] == '-')) { - langptr[2] = '\0'; - lang_err = open_lang (langptr); - } - - if (lang_err == 0) { - maxq = thisq; - strcpy (Lang, langptr); - } - } - langptr = strtok (NULL, " ,\n"); - } - - free(accept_lang); - } - - /* open the best language choice */ - open_lang (Lang); - - /* open the color table */ - open_colortable(); - - umask(VPOPMAIL_UMASK); +paint_headers() +{ fprintf(actout,"Content-Type: text/html\n"); #ifdef NO_CACHE fprintf(actout,"Cache-Control: no-cache\n"); @@ -387,21 +378,3 @@ fprintf(actout,"\n"); } -void del_id_files( char *dirname ) -{ - DIR *mydir; - struct dirent *mydirent; - struct stat statbuf; - char Buffer[MAX_BUFF]; - - mydir = opendir(dirname); - if ( mydir == NULL ) return; - - while((mydirent=readdir(mydir))!=NULL){ - if ( strstr(mydirent->d_name,".qw")!=0 ) { - sprintf(Buffer, "%s/%s", dirname, mydirent->d_name); - unlink(Buffer); - } - } - closedir(mydir); -} Index: qmailadmin.h =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/qmailadmin.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- qmailadmin.h 30 Jan 2004 03:28:19 -0000 1.2 +++ qmailadmin.h 31 Jan 2004 11:08:00 -0000 1.3 @@ -28,16 +28,16 @@ #define QMAILADMIN_UNLIMITED -1 -#define NO_ADMIN 0 - -#define DOMAIN_ADMIN 2 -#define USER_ADMIN 3 +#define NO_ADMIN 0 // Just show the login page again +#define USER_ADMIN 1 // Access only own address +#define DOMAIN_ADMIN 2 // Access entire domain +#define SYSTEM_ADMIN 3 // Access all domains #define NUM_SQL_OPTIONS 6 char *get_html_text( char *index ); -int open_lang( char *lang); +int open_lang(); int quota_to_bytes(char[], char*); //jhopper prototype int quota_to_megabytes(char[], char*); //jhopper prototype Index: qmailadminx.h =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/qmailadminx.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- qmailadminx.h 30 Jan 2004 08:30:58 -0000 1.4 +++ qmailadminx.h 31 Jan 2004 11:08:00 -0000 1.5 @@ -24,6 +24,7 @@ extern char Gecos[MAX_BUFF]; extern char Quota[MAX_BUFF]; extern char Time[MAX_BUFF]; +extern char Action[MAX_BUFF]; extern char ActionUser[MAX_BUFF]; extern char Newu[MAX_BUFF]; extern char Password1[MAX_BUFF]; @@ -86,7 +87,7 @@ extern char uBufL[MAX_BUFF]; void del_id_files( char *); -int open_lang( char *lang); +int open_lang(); extern char *strstart(); extern char *safe_getenv(); Index: show.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/show.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- show.c 30 Jan 2004 08:30:58 -0000 1.3 +++ show.c 31 Jan 2004 11:08:00 -0000 1.4 @@ -34,7 +34,7 @@ char *dom; time_t mytime; { - send_template( "menu_main.html" ); + send_template( "main_menu.html" ); } show_login() Index: template.c =================================================================== RCS file: /cvsroot/qmailadmin/qmailadmin/template.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- template.c 30 Jan 2004 08:30:58 -0000 1.9 +++ template.c 31 Jan 2004 11:08:00 -0000 1.10 @@ -48,15 +48,7 @@ /* * send an html template to the browser */ -int send_template(char *actualfile) -{ - send_template_now("header.html"); - send_template_now(actualfile); - send_template_now("footer.html"); - return 0; -} - -int send_template_now(char *filename) +int send_template(char *filename) { FILE *fs; FILE *fs_qw; @@ -103,7 +95,7 @@ /* open the template */ fs = fopen( fqfn, "r" ); if (fs == NULL) { - fprintf(stderr,"%s %s\n", get_html_text("144"), fqfn); + fprintf(stderr,"STN1 %s %s\n", get_html_text("144"), fqfn); return 144; } @@ -267,7 +259,7 @@ if ((strstr(Buffer, "../")) != NULL) { fprintf(actout, "STN3 %s: %s", get_html_text("144"), Buffer); } else if((strcmp(Buffer, filename)) != 0) { - send_template_now(Buffer); + send_template(Buffer); } } break; @@ -390,7 +382,7 @@ sprintf( uBufB, "%s", QA_VERSION ); sprintf( uBufC, "%s", PACKAGE ); sprintf( uBufD, "%s", VERSION ); - send_template_now("version.html"); + send_template("version.html"); break; /* send the common URL parms */ @@ -406,7 +398,7 @@ printf("%s", get_html_text(dchar)); break; - /* exit / logout link/text */ + /* logout link/text */ case 'x': printf("<a href=\""); strcpy (value, get_session_val("returntext=")); @@ -463,7 +455,6 @@ } } } -/* fprintf(stderr, "Qmailadmin: below while\n"); */ fclose(fs); fflush(actout); @@ -585,43 +576,34 @@ } else if (fgets(Buffer,sizeof(Buffer),fs1)!=NULL) { /* Parse the first line of the .qmail file */ - + if( '&'==Buffer[0] ) { /* It is a forward */ - fprintf( stderr, "Forward\n" ); strcpy(IsForward, "checked "); strcpy(ForwardAddr, strtok(&Buffer[1], "\n")); } else if (strstr(Buffer, "autorespond")!=NULL ) { /* It is a mail robot */ - fprintf( stderr, "Vacation\n" ); strcpy(IsVacation, "checked "); } else if (strstr(Buffer, "|/bin/true delete")!=NULL ) { /* It is a black hole */ - fprintf( stderr, "Black Hole\n" ); strcpy(IsBlackHole, "checked "); } else if (strstr(Buffer, "#")!=NULL ) { /* It is a better black hole */ - fprintf( stderr, "Better Black Hole\n" ); strcpy(IsBlackHole, "checked "); } else if (strstr(Buffer, "preline")!=NULL ) { /* It is a spam checked simple delivery */ - ... [truncated message content] |