/* Copyright Julian H. Stacey, Munich 2002 & 2003 */ #include /* http://httpd.apache.org/docs/2.2/howto/cgi.html */ /* #include */ #ifdef BOOK #include #define MAX_ENTRIES 10000 typedef struct { char *name ; char *val ; } entry ; 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); #endif #include extern char *ctime(const time_t *); extern time_t time(time_t *) ; FILE *mail ; main(int argc, char **argv) { time_t log_time; char julian[50] ; char mailname[50]; char command[50]; #ifdef BOOK entry entries[MAX_ENTRIES]; int num_entries, i ; int cl; /* Parse params from stdin, & build a table of entries */ for (num_entries=0; !feof(stdin); num_entries++) { entries[num_entries].val = fmakeword(stdin, '&', &cl); plustospace(entries[num_entries].val); unescape_url(entries[num_entries].val); entries[num_entries].name = makeword(entries[num_entries].val, "="); } #else int ch, ch1, ch2; #endif /* Emit HTML header */ printf("Content-type: text/html\n\n"); printf("\n\n\n"); printf("Output from Julians Ski Form\n"); printf("\n\n\n"); sprintf(julian,"%s@%s","jhs","berklix.com"); /* address is split in 2 to defeat spammers' web harvesters, as src/ is on web */ printf("An email booking has been sent to \"Julian Stacey\" <%s>.\n",julian); printf("The content is shown below for your information,\n"); printf("& so if you want you can copy it with your mouse.\n"); printf("
Please check Julian manually emails you a confirmation copy on his\n"); printf("receipt of your data, Allow a day or so for that.
\n"); printf("

\n"); printf("Phone Julian \n"); printf("to arrange a mutualy convenient time to deliver your cash deposit,\n"); printf("see Information Sheet for details)."); printf("

\n"); printf("Push your browser's \"Back\" button, & you will return to the form,\n"); printf("Push the same \"Back\" again, & you will leave the form.\n"); printf("


\n"); printf("

  • \n"); #ifdef BOOK for ( i=0; i < num_entries; i++ ) printf("
  • %s = %s\n", entries[i].name, entries[i].val); #else strcpy(mailname,"/tmp/ski_form.XXXXXX"); mktemp(mailname); if ((mail = fopen(mailname, "w")) == (FILE *)NULL ) printf("%s%s\n", "Cannot open file to mail, ", "you must copy with mouse & mail yourself."); while (( ch = getchar()) != EOF ) { if (((char)ch) == '&') { printf("\n
  • "); fprintf(mail,"\n"); } /* This messy conversion below of scrambled data is probably un-necessary, now I've discovered P. 232 of O Reilly HTML Definitive Guide. Instead I should try emitting "MIME-Version: 1.0" "Content-Type: text/plain;" "Content-Transfer-Encoding: \ application/x-www-form-urlencoded" */ else if (((char)ch) == '+') jputchar((int)' '); else if (((char)ch) == ',') jputchar((int)'Z'); /* else if (((char)ch) == ' ') jputchar((int)'\n'); */ else if (((char)ch) == '%') { /* hexadecimal */ if ((ch1 = getchar())== EOF) { printf("Err. with %%%c\n", (char)ch1) ; fprintf(mail,"Err. with %%%c\n", (char)ch1) ; break ; } ch1 -= '0' ; ch1 *= 16 ; if ((ch2 = getchar())== EOF) { printf("Err. with %%%c%c\n", (char)ch1,(char)ch2) ; fprintf(mail,"Err. with %%%c%c\n", (char)ch1,(char)ch2) ; break ; } ch2 -= '0' ; ch1 += ch2 ; /* Errors: Input Wrong Output ^ e + 2D (or 2) = , A lot of these screw up !@#$%^&*()_-+={[}]:;"'|\<,>.?/ */ jputchar(ch1); } else jputchar(ch); } #endif printf("
\n"); (void) time(&log_time) ; fprintf(mail,"\nCreated %s\n",ctime(&log_time)); fclose(mail); sprintf(command, "/bin/sh /usr/local/www/cgi-bin/ski_form.sh %s", mailname); system(command); unlink(mailname); } int jputchar(int c) { fputc(c,mail); return (putchar(c)); }