-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjj-mod.c
276 lines (254 loc) · 10.6 KB
/
jj-mod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Submarine ordering form through FAX gateway
*
* Rob McCool
*
*/
#include <stdio.h>
#include <string.h>
#ifndef NO_STDLIB_H
#include <stdlib.h>
#else
char *getenv();
#endif
#if 1
#define JJ_FAX "[email protected]"
#else
#define JJ_FAX "[email protected]"
#endif
#define PASSWORD "HTTPdRocKs"
#define LF 10
void getword(char *word, char *line, char stop);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);
FILE * fssock;
char *sublist[] = {
"The Pepe Gourmet Sub",
"Big John Gourmet Sub",
"Sorry Charlie Gourmet Sub",
"Turkey Tom Gourmet Sub",
"Vito Gourmet Sub",
"Vegetarian Gourmet Sub",
"Gourmet Smoked Ham Club",
"Billy Club",
"Italian Night Club",
"Hunter's Club",
"Country Club",
"The Beach Club"
};
char *slimlist[] = {
"Ham and Cheese",
"Rare Roast Beef",
"California Tuna",
"Sliced Turkey",
"Salami and Capacola",
"Double Provolone"
};
char *sidelist[] = {
"Lay's Potato Chips",
"Jumbo Kosher Dill"
};
char *poplist[] = {
"Pepsi",
"Mountain Dew",
"Diet Pepsi",
"Iced Tea"
};
void dump_form() {
fprintf(fssock,"<TITLE>Form for Submarine Order</TITLE>%c",LF);
fprintf(fssock,"<H1>Jimmy John's Submarine Order Form</H1>%c",LF);
fprintf(fssock,"This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c",LF);
fprintf(fssock,"for order to be submitted, otherwise a copy of the order that would have been submitted will%c",LF);
fprintf(fssock,"will be displayed.<P>%c",LF);
fprintf(fssock,"<HR>%c",LF);
fprintf(fssock,"<FORM ACTION=\"http://sslab20.cs.purdue.edu:5555/cgi-bin/jj\">%c",LF);
fprintf(fssock,"Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\"><P>%c",LF);
fprintf(fssock,"<H3>Sub Type</H3>%c",LF);
fprintf(fssock,"Select which you would like of the following:<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c",sublist[0],LF);
fprintf(fssock,"Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c",sublist[1],LF);
fprintf(fssock,"Medium rare shaved roast beef topped with mayo, lettuce, and tomato.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c",sublist[2],LF);
fprintf(fssock,"Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c",LF);
fprintf(fssock,"tomato, and alfalfa sprouts.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c",sublist[3],LF);
fprintf(fssock,"Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c",sublist[4],LF);
fprintf(fssock,"Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c",sublist[5],LF);
fprintf(fssock,"Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c",sublist[6],LF);
fprintf(fssock,"1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c",LF);
fprintf(fssock,"tomato, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c",sublist[7],LF);
fprintf(fssock,"Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c",LF);
fprintf(fssock,"tomato, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c",sublist[8],LF);
fprintf(fssock,"Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c",LF);
fprintf(fssock,"tomato, onions, mayo, and Italian sauce.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c",sublist[9],LF);
fprintf(fssock,"1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c",sublist[10],LF);
fprintf(fssock,"Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c",sublist[11],LF);
fprintf(fssock,"Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.<P>%c",LF);
fprintf(fssock,"<H3>Slim Jim Subs</H3>%c",LF);
fprintf(fssock,"Subs without veggies or sauce.<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s<P>%c",slimlist[0],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s<P>%c",slimlist[1],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s<P>%c",slimlist[2],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s<P>%c",slimlist[3],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s<P>%c",slimlist[4],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s<P>%c",slimlist[5],LF);
fprintf(fssock,"<H3>Side orders</H3>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s<P>%c",sidelist[0],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s<P>%c",sidelist[1],LF);
fprintf(fssock,"<H3>Drinks</H3>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s<P>%c",poplist[0],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s<P>%c",poplist[1],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s<P>%c",poplist[2],LF);
fprintf(fssock,"<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s<P>%c",poplist[3],LF);
fprintf(fssock,"<H3>Your Address, Phone Number, and Name</H3>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address<P>%c",LF);
fprintf(fssock,"<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number<P>%c",LF);
fprintf(fssock,"<INPUT type=\"submit\">%c",LF);
fprintf(fssock,"</FORM>%c",LF);
fclose(fssock);
// exit(0);
}
void print_error(char *reason) {
fprintf(fssock,"<TITLE>Order Not Submitted</TITLE>%c",LF);
fprintf(fssock,"<H1>Order Not Submitted</H1>%c",LF);
fprintf(fssock,"Your order has not been submitted, because %s.<P>%c",reason,LF);
fclose(fssock);
// exit(1);
}
void httprun(int ssock, char* query_string){
fssock = fdopen( ssock, "r+");
if ( fssock == NULL ) {
perror("fdopen");
}
register int x,m=0;
char *cl;
char w[256];
char tfile[L_tmpnam];
int subs,slims,sides,drinks,allow;
char name[32];
char phone[10];
char address[64];
FILE *tfp,*order;
fprintf(fssock,"Content-type: text/html%c%c",LF,LF);
cl=getenv("QUERY_STRING");
if((!cl) || (!cl[0])){
dump_form();
return;
}
tmpnam(tfile);
if(!(tfp=fopen(tfile,"w"))) {
fprintf(fssock,"<TITLE>Server Error</TITLE>%c",LF);
fprintf(fssock,"<H1>Server Error</H1>%c",LF);
fprintf(fssock,"Server unable to get a temporary file. Please try again later.<P>%c",LF);
fclose(fssock);
return;
// exit(1);
}
subs=0;slims=0;sides=0;drinks=0;allow=0;
name[0]='\0';
phone[0]='\0';
address[0]='\0';
for(x=0;cl[0] != '\0'; x++) {
m=x;
getword(w,cl,'=');
plustospace(w);
unescape_url(w);
if(!strcmp(w,"pwd")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
allow=(strcmp(w,PASSWORD) ? 0 : 1);
}
if(!strcmp(w,"sub")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
subs |= (1 << atoi(w));
}
else if(!strcmp(w,"slj")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
slims |= (1 << atoi(w));
}
else if(!strcmp(w,"sde")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
sides |= (1 << atoi(w));
}
else if(!strcmp(w,"pop")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
drinks |= (1 << atoi(w));
}
else if(!strcmp(w,"name")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
strcpy(name,w);
}
else if(!strcmp(w,"phone")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
strcpy(phone,w);
}
else if(!strcmp(w,"adr")) {
getword(w,cl,'&');
plustospace(w);
unescape_url(w);
strcpy(address,w);
}
}
if(!name[0]) print_error("you didn't give your name");
if(!address[0]) print_error("you didn't give your address");
if(!phone[0]) print_error("you didn't give your phone number");
if((!subs) && (!slims) && (!sides) && (!drinks)) print_error("you didn't order anything");
if(allow) {
char t[256];
sprintf(t,"/bin/mail %s",JJ_FAX);
if(!(order=popen(t,"w")))
print_error("the server was unable to open a pipe to mail");
fprintf(fssock,"<TITLE>Order Sent</TITLE>%c",LF);
fprintf(fssock,"<H1>Order Sent</H1>%c",LF);
fprintf(fssock,"Your order has been sent to the UIUC e-mail to FAX gateway.<P>%c",LF);
} else {
fprintf(fssock,"<TITLE>Your Order</TITLE>%c",LF);
fprintf(fssock,"<H1>Your Order</H1>%c",LF);
fprintf(fssock,"This is how your order would have looked if it had been sent.<P><PLAINTEXT>%c",LF);
order=stdout;
}
fprintf(order,"My name is %s, and I would like to have the following%c",
name,LF);
fprintf(order,"order delivered to %s:%c%c",address,LF,LF);
for(x=0;x<12;x++)
if(subs & (1 << x))
fprintf(order,"\t(1) %s%c",sublist[x],LF);
for(x=0;x<6;x++)
if(slims & (1 << x))
fprintf(order,"\t(1) %s Slim Jim%c",slimlist[x],LF);
for(x=0;x<2;x++)
if(sides & (1 << x))
fprintf(order,"\t(1) %s%c",sidelist[x],LF);
for(x=0;x<4;x++)
if(drinks & (1 << x))
fprintf(order,"\t(1) %s%c",poplist[x],LF);
fprintf(order,"%cPlease feel free to call me at %s if there is any%c",LF,
phone,LF);
fprintf(order,"problem. Thank you.%c%c.%c",LF,LF,LF);
fclose(order);
// exit(0);
}