/* * Version 2.1 */ #include #include #include #define MAX_ENTRIES 10000 #define LF 10 #define CR 13 #define IS_BLANK 1 extern char *getenv(); char *makeword(); char *fmakeword(); char x2c(); void unescape_url(); void plustospace(); typedef struct { char *name; char *val; } entry; /**********************************************************************/ /**********************************************************************/ main(argc, argv) int argc; char *argv[]; { entry entries[MAX_ENTRIES]; register int x,m=0; int ok = 0; int cl; FILE *out; FILE *in; char buf[81]; int email_ident = -1, email_check = -1; int comment_ident = -1, comment_check = -1; int subject_ident = -1, subject_check = -1; printf("Content-type: text/html%c%c",10,10); /**************************/ /* Do some error checking */ /**************************/ if(strcmp(getenv("REQUEST_METHOD"),"POST")) { printf("Forum Refused"); printf("

Form Refused

"); printf("This script should be referenced with a METHOD of POST.

"); printf("Email POSTMASTER for more info.


"); printf("%c", 10); exit(1); } if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { printf("Forum Refused"); printf("

Form Refused

"); printf("This script can only be used to decode form results.

"); printf("Email POSTMASTER for more info.


"); printf("%c", 10); exit(1); } /* How long is the content? */ cl = atoi(getenv("CONTENT_LENGTH")); /********************************/ /* Main loop to extract content */ /********************************/ for(x=0;cl && (!feof(stdin));x++) { m=x; entries[x].val = fmakeword(stdin,'&',&cl); plustospace(entries[x].val); unescape_url(entries[x].val); entries[x].name = makeword(entries[x].val,'='); if( !strcmp(entries[x].name, "SUBJECT") ) { subject_ident = x; if( !strcmp(entries[subject_ident].val, "") ) { subject_check = IS_BLANK; } } if( !strcmp(entries[x].name, "EMAIL") ) { email_ident = x; if( !strcmp(entries[email_ident].val, "") ) { email_check = IS_BLANK; } } if( !strcmp(entries[x].name, "COMMENT") ) { comment_ident = x; if( !strcmp(entries[comment_ident].val, "") ) { comment_check = IS_BLANK; } } } /*** End of main extraction loop ***/ /***********************************************************/ /* actualy send the mail */ /***********************************************************/ sprintf(buf, "/usr/bin/mail POSTMASTER@xxx.edu"); out = popen(buf, "w"); if( subject_check == IS_BLANK ) fprintf(out, "Subject: WWW Feedback\n"); else fprintf(out, "Subject: %s\n", entries[subject_ident].val ); if( email_check == IS_BLANK ) fprintf(out, "Reply-To: lame_www_user@lamer.com\n"); else fprintf(out, "Reply-To: %s\n", entries[email_ident].val ); fprintf(out, "\n\n\n--- WWW Feedback\n\n"); fprintf(out, "Subject: %s\n", entries[subject_ident].val ); fprintf(out, " Email: %s\n", entries[email_ident].val ); fprintf(out, "\n\n-- Comment:\n\n"); fprintf(out, "%s", entries[comment_ident].val ); fprintf(out, "\n\n----------\n\n"); fprintf(out, "HTTP_USER_AGENT = %s\n", getenv("HTTP_USER_AGENT") ); fprintf(out, "HTTP_REFERER= %s\n", getenv("HTTP_REFERER") ); fprintf(out, "REMOTE_HOST = %s\n", getenv("REMOTE_HOST") ); fprintf(out, "REMOTE_ADDR = %s\n", getenv("REMOTE_ADDR") ); fprintf(out, "REMOTE_USER = %s\n", getenv("REMOTE_USER") ); fprintf(out, "REMOTE_IDENT = %s\n", getenv("REMOTE_IDENT") ); fprintf(out, "REFERER_URL = %s\n", getenv("REFERER_URL") ); fprintf(out, "HTTP_ACCEPT = %s\n", getenv("HTTP_ACCEPT") ); fprintf(out, "GATEWAY_INTERFACE = %s\n", getenv("GATEWAY_INTERFACE") ); fprintf(out, "SERVER_PROTOCOL = %s\n", getenv("SERVER_PROTOCOL") ); fprintf(out, "REQUEST_METHOD = %s\n", getenv("REQUEST_METHOD") ); fprintf(out, "PATH_INFO = %s\n", getenv("PATH_INFO") ); fprintf(out, "PATH_TRANSLATED = %s\n", getenv("PATH_TRANSLATED") ); fprintf(out, "QUERY_STRING = %s\n", getenv("QEURY_STRING") ); fprintf(out, "SCRIPT_NAME = %s\n", getenv("SCRIPT_NAME") ); fprintf(out, "AUTH_TYPE = %s\n\n---\n", getenv("AUTH_TYPE") ); pclose(out); /*******************************/ /* Send HTML page confirmation */ /*******************************/ printf("Thanks for the feedback"); printf("

Thanks

"); printf("


Thanks for the feedback. If you left a valid "); printf("email address I'll get back to you as soon as possible. "); printf("


"); printf(""); } /*** End of Main ***/ /*** The 'util.c' section ***/ /* Removes trailing white space void wsremove(s) char *s; { while(1) { int l = strlen(s); if (!l) { break; (isspace(s[l-1])) { s[l-1] = '\0'; } else { break; } } } */ void getword(word, line, stop) char *word, *line, stop; { int x = 0,y; for(x=0;((line[x]) && (line[x] != stop));x++) word[x] = line[x]; word[x] = '\0'; if(line[x]) ++x; y=0; while(line[y++] = line[x++]); } char *makeword(line, stop) char *line, stop; { int x = 0,y; char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); for(x=0;((line[x]) && (line[x] != stop));x++) word[x] = line[x]; word[x] = '\0'; if(line[x]) ++x; y=0; while(line[y++] = line[x++]); return word; } char *fmakeword(f, stop, cl) FILE *f; char stop; int *cl; { int wsize; char *word; int ll; wsize = 102400; ll=0; word = (char *) malloc(sizeof(char) * (wsize + 1)); while(1) { word[ll] = (char)fgetc(f); if(ll==wsize) { word[ll+1] = '\0'; wsize+=102400; word = (char *)realloc(word,sizeof(char)*(wsize+1)); } --(*cl); if((word[ll] == stop) || (feof(f)) || (!(*cl))) { if(word[ll] != stop) ll++; word[ll] = '\0'; return word; } ++ll; } } char x2c(what) char *what; { register char digit; digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); digit *= 16; digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); return(digit); } void unescape_url(url) char *url; { register int x,y; for(x=0,y=0;url[y];++x,++y) { if((url[x] = url[y]) == '%') { url[x] = x2c(&url[y+1]); y+=2; } } url[x] = '\0'; } void plustospace(str) char *str; { register int x; for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; } int rind(s,c) char *s,c; { register int x; for(x=strlen(s) - 1;x != -1; x--) if(s[x] == c) return x; return -1; } int getline(s, n, f) char *s; int n; FILE *f; { register int i=0; while(1) { s[i] = (char)fgetc(f); if(s[i] == CR) s[i] = fgetc(f); if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) { s[i] = '\0'; return (feof(f) ? 1 : 0); } ++i; } } void send_fd(f, fd) FILE *f, *fd; { int num_chars=0; char c; while (1) { c = fgetc(f); if(feof(f)) return; fputc(c,fd); } } /**** END ****/