/* See the section just after the license for important configuration #defines! Email handler. This is based on the post_query.c code provided with the NCSA httpd 1.1 package, released to the public domain (see their policy, which follows). Original portions Copyright 1994 Cold Spring Harbor Labs. Permission granted to copy, modify and otherwise use this code in whatever manner you see fit, with no warranty expressed or implied. Plesae retain this notice; this is the only restriction. We also ask that you credit yourself for any changes so we are not asked to maintain versions of the code that are no longer recognizable to us. Original portions by Thomas Boutell. Portions developed at the National Center for Supercomputing Applications at the University of Illinois at Urbana-Champaign. THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. */ /* The only #define you will probably want to change: where the email configuration file is found. */ #define EMAIL_CONF_PATH "/user3/users/founar/public_html/cgi/email/email.conf" #include #include #include #define MAX_ENTRIES 10000 extern char *getenv(char *e); typedef struct { char *name; char *val; } entry; /* Removes trailing white space, etc */ void wsremove(char *s); char *makeword(char *line, char stop); char *fmakeword(FILE *f, char stop, int *len); char x2c(char *what); void unescape_url(char *url); void plustospace(char *str); main(int argc, char *argv[]) { entry entries[MAX_ENTRIES]; register int x,m=0; int ok = 0; int cl; int nameid = -1; int emailid = -1; int contentid = -1; int subjectid = -1; int recipientid = -1; FILE *out; FILE *in; char buf[81]; char recipientc[81]; char returnpage[81]; printf("Content-type: text/html%c%c",10,10); if(strcmp(getenv("REQUEST_METHOD"),"POST")) { printf("This script should be referenced with a METHOD of POST.\n"); printf("If you don't understand this, see this "); printf("forms overview.%c",10); exit(1); } if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) { printf("This script can only be used to decode form results. \n"); exit(1); } cl = atoi(getenv("CONTENT_LENGTH")); 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, "name")) && (strcmp(entries[x].val, ""))) { nameid = x; } else if ((!strcmp(entries[x].name, "email")) && (strcmp(entries[x].val, ""))) { emailid = x; } else if ((!strcmp(entries[x].name, "recipient")) && (strcmp(entries[x].val, ""))) { recipientid = x; } else if ((!strcmp(entries[x].name, "content")) && (strcmp(entries[x].val, ""))) { contentid = x; } else if ((!strcmp(entries[x].name, "subject")) && (strcmp(entries[x].val, ""))) { subjectid = x; } } if ((nameid == -1) || (emailid == -1) || (contentid == -1) || (recipientid == -1)) { printf("Email Rejected"); printf("

Email Rejected

"); printf("

Please fill out all fields provided.\n"); printf("Back up to the previous page to try again.\n"); return 0; } in = fopen(EMAIL_CONF_PATH, "r"); ok = 0; while(1) { if (!fgets(recipientc, 80, in)) { break; } wsremove(recipientc); if (!fgets(returnpage, 80, in)) { break; } wsremove(returnpage); if (!strcmp(entries[recipientid].val, recipientc)) { ok = 1; break; } } fclose(in); if (!ok) { printf("Email Rejected"); printf("

Email Rejected

"); printf("

%s is not one of the permitted email recipients.\n", entries[recipientid].val); printf("Back up to the previous page to try again.\n"); return 0; } sprintf(buf, "/usr/bin/mail %s", entries[recipientid].val); out = popen(buf, "w"); fprintf(out, "Subject: %s\n", entries[subjectid].val); fprintf(out, "Reply-To: %s\n", entries[emailid].val); fprintf(out, "Supposedly-From: %s\n", entries[nameid].val); fprintf(out, "[This message was sent through the www-email gateway.]\n"); fprintf(out, "--\n"); fprintf(out, "%s\n", entries[contentid].val); pclose(out); printf("Message Accepted\n"); printf("

Message Accepted

\n"); printf("Follow this link to continue.\n", returnpage); } /* Removes trailing white space, etc */ void wsremove(char *s) { while(1) { int l = strlen(s); if (!l) { break; } if (isspace(s[l-1])) { s[l-1] = '\0'; } else { break; } } }