]>
Commit | Line | Data |
---|---|---|
4a9a952e | 1 | |
30a4f2a8 | 2 | /* |
e92d33a5 | 3 | * $Id: errorpage.cc,v 1.37 1996/09/11 22:31:06 wessels Exp $ |
30a4f2a8 | 4 | * |
5 | * DEBUG: section 4 Error Generation | |
6 | * AUTHOR: Duane Wessels | |
7 | * | |
8 | * SQUID Internet Object Cache http://www.nlanr.net/Squid/ | |
9 | * -------------------------------------------------------- | |
10 | * | |
11 | * Squid is the result of efforts by numerous individuals from the | |
12 | * Internet community. Development is led by Duane Wessels of the | |
13 | * National Laboratory for Applied Network Research and funded by | |
14 | * the National Science Foundation. | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or modify | |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
29 | * | |
30 | */ | |
1e74c110 | 31 | |
44a47c6e | 32 | #include "squid.h" |
1e74c110 | 33 | |
b8de7ebe | 34 | #define SQUID_ERROR_MSG_P1 "\ |
a8f7d3ee | 35 | <HTML><HEAD>\n\ |
1e74c110 | 36 | <TITLE>ERROR: The requested URL could not be retrieved</TITLE>\n\ |
a8f7d3ee | 37 | </HEAD><BODY>\n\ |
38 | <H1>ERROR</H1>\n\ | |
1e74c110 | 39 | <H2>The requested URL could not be retrieved</H2>\n\ |
40 | <HR>\n\ | |
41 | <P>\n\ | |
42 | While trying to retrieve the URL:\n\ | |
43 | <A HREF=\"%s\">%s</A>\n\ | |
44 | <P>\n\ | |
45 | The following error was encountered:\n\ | |
46 | <UL>\n\ | |
47 | <LI><STRONG>%s</STRONG>\n\ | |
48 | </UL>\n\ | |
49 | " | |
50 | ||
b8de7ebe | 51 | #define SQUID_ERROR_MSG_P2 "\ |
1e74c110 | 52 | <P>The system returned:\n\ |
53 | <PRE><I> %s</I></PRE>\n\ | |
54 | " | |
55 | ||
b8de7ebe | 56 | #define SQUID_ERROR_MSG_P3 "\ |
1e74c110 | 57 | <P>This means that:\n\ |
58 | <PRE>\n\ | |
59 | %s\n\ | |
60 | </PRE>\n\ | |
6e40f263 | 61 | <P>\n\ |
62 | %s\n\ | |
63 | <HR>\n\ | |
1e74c110 | 64 | <ADDRESS>\n\ |
b8de7ebe | 65 | Generated by %s/%s@%s\n\ |
a8f7d3ee | 66 | </ADDRESS></BODY></HTML>\n\ |
1e74c110 | 67 | \n" |
68 | ||
69 | typedef struct { | |
70 | char *tag; | |
71 | char *shrt; | |
72 | char *lng; | |
73 | } error_data; | |
74 | ||
75 | error_data ErrorData[] = | |
76 | { | |
1e74c110 | 77 | {"ERR_READ_TIMEOUT", |
78 | "Read Timeout", | |
79 | "The remote site or network may be down. Please try again."}, | |
80 | {"ERR_LIFETIME_EXP", | |
81 | "Transaction Timeout", | |
82 | "The network or remote site may be down or too slow. Try again later."}, | |
83 | {"ERR_NO_CLIENTS_BIG_OBJ", | |
84 | "No Client", | |
85 | "All Clients went away before tranmission completed and the object is too big to cache."}, | |
86 | {"ERR_READ_ERROR", | |
87 | "Read Error", | |
88 | "The remote site or network may be down. Please try again."}, | |
89 | {"ERR_CLIENT_ABORT", | |
90 | "Client Aborted", | |
91 | "Client(s) dropped connection before transmission completed.\nObject fetching is aborted.",}, | |
92 | {"ERR_CONNECT_FAIL", | |
93 | "Connection Failed", | |
94 | "The remote site or server may be down. Please try again soon."}, | |
6eb42cae | 95 | {"ERR_INVALID_REQUEST", |
96 | "Invalid HTTP request", | |
97 | "Please double check it, or ask for assistance."}, | |
a8f7d3ee | 98 | {"ERR_UNSUP_REQUEST", |
99 | "Unsupported request", | |
100 | "This request method is not supported for this protocol."}, | |
1e74c110 | 101 | {"ERR_INVALID_URL", |
102 | "Invalid URL syntax", | |
103 | "Please double check it, or ask for assistance."}, | |
104 | {"ERR_NO_FDS", | |
105 | "Out of file descriptors", | |
106 | "The cache is currently very busy. Please try again."}, | |
107 | {"ERR_DNS_FAIL", | |
108 | "DNS name lookup failure", | |
109 | "The named host probably does not exist."}, | |
110 | {"ERR_NOT_IMPLEMENTED", | |
3988ba3f | 111 | "Protocol Not Supported", |
112 | "The cache does not know about the requested protocol."}, | |
1e74c110 | 113 | {"ERR_CANNOT_FETCH", |
3988ba3f | 114 | "Unable to Retrieve", |
115 | "The requested URL can not currently be retrieved."}, | |
1e74c110 | 116 | {"ERR_NO_RELAY", |
3988ba3f | 117 | "No WAIS Relay", |
118 | "There is no WAIS relay host defined for this cache."}, | |
1e74c110 | 119 | {"ERR_DISK_IO", |
120 | "Cache Disk I/O Failure", | |
121 | "The system disk is out of space or failing."}, | |
ba718c8f | 122 | {"ERR_ZERO_SIZE_OBJECT", |
123 | "No Object Data", | |
a8f7d3ee | 124 | "The remote server closed the connection before sending any data."}, |
125 | {"ERR_PROXY_DENIED", | |
126 | "Access Denied", | |
127 | "You must authenticate yourself before accessing this cache."} | |
1e74c110 | 128 | }; |
129 | ||
44a47c6e | 130 | /* GLOBAL */ |
1e69e30f | 131 | char *tmp_error_buf; |
44a47c6e | 132 | |
133 | /* LOCAL */ | |
30a4f2a8 | 134 | static char *tbuf = NULL; |
1b0124ff | 135 | static char *auth_msg = NULL; |
1e74c110 | 136 | |
fa966b74 | 137 | void errorInitialize() |
138 | { | |
e81957b7 | 139 | #ifndef USE_PROXY_AUTH |
30a4f2a8 | 140 | tmp_error_buf = xmalloc(MAX_URL * 4); |
e81957b7 | 141 | #else |
142 | tmp_error_buf = xmalloc(8192); | |
143 | #endif /* USE_PROXY_AUTH */ | |
5162fc3c | 144 | meta_data.misc += MAX_URL * 4; |
30a4f2a8 | 145 | tbuf = xmalloc(MAX_URL * 3); |
5162fc3c | 146 | meta_data.misc += MAX_URL * 3; |
e381a13d | 147 | auth_msg = xmalloc(MAX_URL * 3); |
148 | meta_data.misc += MAX_URL * 3; | |
1e69e30f | 149 | } |
150 | ||
b8de7ebe | 151 | void squid_error_entry(entry, type, msg) |
1e74c110 | 152 | StoreEntry *entry; |
620da955 | 153 | log_type type; |
1e74c110 | 154 | char *msg; |
155 | { | |
6350239f | 156 | int index; |
e92d33a5 | 157 | |
6350239f | 158 | if (type < ERR_MIN || type > ERR_MAX) |
b8de7ebe | 159 | fatal_dump("squid_error_entry: type out of range."); |
6350239f | 160 | index = (int) (type - ERR_MIN); |
e4209be8 | 161 | debug(4, 1, "%s: %s\n", ErrorData[index].tag, entry->url); |
b8de7ebe | 162 | sprintf(tmp_error_buf, SQUID_ERROR_MSG_P1, |
1e74c110 | 163 | entry->url, |
164 | entry->url, | |
6350239f | 165 | ErrorData[index].shrt); |
1e74c110 | 166 | if (msg) { |
b8de7ebe | 167 | sprintf(tbuf, SQUID_ERROR_MSG_P2, msg); |
1e74c110 | 168 | strcat(tmp_error_buf, tbuf); |
169 | } | |
b8de7ebe | 170 | sprintf(tbuf, SQUID_ERROR_MSG_P3, |
6350239f | 171 | ErrorData[index].lng, |
6e40f263 | 172 | Config.errHtmlText, |
b8de7ebe | 173 | appname, |
8213067d | 174 | version_string, |
44a47c6e | 175 | getMyHostname()); |
1e74c110 | 176 | strcat(tmp_error_buf, tbuf); |
6e40f263 | 177 | if (entry->mem_obj) { |
178 | entry->mem_obj->abort_code = type; | |
179 | if (entry->mem_obj->reply->code == 0) | |
180 | entry->mem_obj->reply->code = 400; | |
181 | } | |
1e74c110 | 182 | storeAbort(entry, tmp_error_buf); |
1e74c110 | 183 | } |
184 | ||
185 | ||
186 | ||
b8de7ebe | 187 | char *squid_error_url(url, method, type, address, code, msg) |
1e74c110 | 188 | char *url; |
6eb42cae | 189 | int method; |
6350239f | 190 | int type; |
6eb42cae | 191 | char *address; |
f98fc672 | 192 | int code; |
1e74c110 | 193 | char *msg; |
194 | { | |
6350239f | 195 | int index; |
e92d33a5 | 196 | |
1e69e30f | 197 | *tmp_error_buf = '\0'; |
234967c9 | 198 | if (type < ERR_MIN || type > ERR_MAX) |
b8de7ebe | 199 | fatal_dump("squid_error_url: type out of range."); |
6350239f | 200 | index = (int) (type - ERR_MIN); |
e4209be8 | 201 | debug(4, 1, "%s: %s\n", ErrorData[index].tag, url); |
f98fc672 | 202 | sprintf(tmp_error_buf, "HTTP/1.0 %d Cache Detected Error\r\nContent-type: text/html\r\n\r\n", code); |
b8de7ebe | 203 | sprintf(tbuf, SQUID_ERROR_MSG_P1, |
1e74c110 | 204 | url, |
205 | url, | |
6350239f | 206 | ErrorData[index].shrt); |
f98fc672 | 207 | strcat(tmp_error_buf, tbuf); |
1e74c110 | 208 | if (msg) { |
b8de7ebe | 209 | sprintf(tbuf, SQUID_ERROR_MSG_P2, msg); |
1e74c110 | 210 | strcat(tmp_error_buf, tbuf); |
211 | } | |
b8de7ebe | 212 | sprintf(tbuf, SQUID_ERROR_MSG_P3, |
6350239f | 213 | ErrorData[index].lng, |
6e40f263 | 214 | Config.errHtmlText, |
b8de7ebe | 215 | appname, |
8213067d | 216 | version_string, |
44a47c6e | 217 | getMyHostname()); |
30a4f2a8 | 218 | strcat(tmp_error_buf, tbuf); |
6eb42cae | 219 | return tmp_error_buf; |
220 | } | |
221 | ||
222 | ||
b8de7ebe | 223 | #define SQUID_REQUEST_ERROR_MSG "\ |
a8f7d3ee | 224 | <HTML><HEAD><TITLE>ERROR: Invalid HTTP Request</TITLE></HEAD>\n\ |
225 | <BODY><H1>ERROR</H1>\n\ | |
6eb42cae | 226 | <H2>Invalid HTTP Request</H2>\n\ |
227 | <HR>\n\ | |
228 | <PRE>\n\ | |
229 | %s\n\ | |
230 | </PRE>\n\ | |
6e40f263 | 231 | <P>\n\ |
232 | %s\n\ | |
6eb42cae | 233 | <HR>\n\ |
234 | <ADDRESS>\n\ | |
b8de7ebe | 235 | Generated by %s/%s@%s\n\ |
a8f7d3ee | 236 | </ADDRESS></BODY></HTML>\n\ |
6eb42cae | 237 | \n" |
238 | ||
b8de7ebe | 239 | char *squid_error_request(request, type, address, code) |
6eb42cae | 240 | char *request; |
241 | int type; | |
242 | char *address; | |
f98fc672 | 243 | int code; |
6eb42cae | 244 | { |
0ed8bcfc | 245 | int index; |
e92d33a5 | 246 | |
1e69e30f | 247 | *tmp_error_buf = '\0'; |
234967c9 | 248 | if (type < ERR_MIN || type > ERR_MAX) |
30a4f2a8 | 249 | fatal_dump("squid_error_request: type out of range."); |
0ed8bcfc | 250 | index = (int) (type - ERR_MIN); |
e4209be8 | 251 | debug(4, 1, "%s: %s\n", ErrorData[index].tag, request); |
f98fc672 | 252 | sprintf(tmp_error_buf, "HTTP/1.0 %d Cache Detected Error\r\nContent-type: text/html\r\n\r\n", code); |
b8de7ebe | 253 | sprintf(tbuf, SQUID_REQUEST_ERROR_MSG, |
6eb42cae | 254 | request, |
6e40f263 | 255 | Config.errHtmlText, |
b8de7ebe | 256 | appname, |
8213067d | 257 | version_string, |
6eb42cae | 258 | getMyHostname()); |
f98fc672 | 259 | strcat(tmp_error_buf, tbuf); |
1e74c110 | 260 | return tmp_error_buf; |
261 | } | |
8213067d | 262 | |
20c9fc21 | 263 | char *access_denied_msg(code, method, url, client) |
264 | int code; | |
265 | int method; | |
266 | char *url; | |
267 | char *client; | |
8213067d | 268 | { |
20c9fc21 | 269 | sprintf(tmp_error_buf, "\ |
92a6f4b1 | 270 | HTTP/1.0 %d Cache Access Denied\r\n\ |
8213067d | 271 | Content-type: text/html\r\n\ |
272 | \r\n\ | |
a8f7d3ee | 273 | <HTML><HEAD><TITLE>Cache Access Denied</TITLE></HEAD>\n\ |
274 | <BODY><H1>Error</H1>\n\ | |
8213067d | 275 | <H2>Access Denied</H2>\n\ |
276 | <P>\n\ | |
92a6f4b1 | 277 | Sorry, you are not currently allowed to request\n\ |
8213067d | 278 | <PRE> %s</PRE>\n\ |
71f857d4 | 279 | From this cache. Please check with the\n\ |
4a9a952e | 280 | <A HREF=\"mailto:%s\">cache administrator</A>\n\ |
281 | if you believe this is incorrect.\n\ | |
6e40f263 | 282 | <P>\n\ |
283 | %s\n\ | |
8213067d | 284 | <HR>\n\ |
285 | <ADDRESS>\n\ | |
b8de7ebe | 286 | Generated by %s/%s@%s\n\ |
8213067d | 287 | </ADDRESS>\n\ |
288 | \n", | |
289 | code, | |
290 | url, | |
b6f794d6 | 291 | Config.adminEmail, |
6e40f263 | 292 | Config.errHtmlText, |
b8de7ebe | 293 | appname, |
8213067d | 294 | version_string, |
295 | getMyHostname()); | |
20c9fc21 | 296 | return tmp_error_buf; |
8213067d | 297 | } |
e381a13d | 298 | |
e92d33a5 | 299 | /* maex@space.net (06.09.1996) |
300 | * the message that is sent on deny_info | |
301 | * add a Location: and for old browsers a HREF to the info page | |
302 | */ | |
303 | char *access_denied_redirect(code, method, url, client, redirect) | |
304 | int code; | |
305 | int method; | |
306 | char *url; | |
307 | char *client; | |
308 | char *redirect; | |
309 | { | |
310 | sprintf(tmp_error_buf, "\ | |
311 | HTTP/1.0 %d Cache Access Deny Redirect\r\n\ | |
312 | Location: %s\r\n\ | |
313 | Content-type: text/html\r\n\ | |
314 | \r\n\ | |
315 | <HTML><HEAD><TITLE>Cache Access Denied</TITLE></HEAD>\n\ | |
316 | <BODY><H1>Error</H1>\n\ | |
317 | <H2>Access Denied</H2>\n\ | |
318 | <P>\n\ | |
319 | Sorry, you are not currently allowed to request\n\ | |
320 | <PRE> %s</PRE>\n\ | |
321 | from this cache.\n\ | |
322 | <P>\n\ | |
323 | You may take a look at\n\ | |
324 | <PRE> <A HREF=\"%s\">%s</A></PRE>\n\ | |
325 | or check with the cache administrator if you\n\ | |
326 | believe this is incorrect.\n\ | |
327 | <P>\n\ | |
328 | %s\n\ | |
329 | <HR>\n\ | |
330 | <ADDRESS>\n\ | |
331 | Generated by %s/%s@%s\n\ | |
332 | </ADDRESS></BODY></HTML>\n\ | |
333 | \n", | |
334 | code, | |
335 | redirect, | |
336 | url, | |
337 | redirect, | |
338 | redirect, | |
339 | Config.errHtmlText, | |
340 | appname, | |
341 | version_string, | |
342 | getMyHostname()); | |
343 | return tmp_error_buf; | |
344 | } | |
345 | ||
e381a13d | 346 | char *authorization_needed_msg(request, realm) |
347 | request_t *request; | |
348 | char *realm; | |
349 | { | |
db9f331f | 350 | sprintf(auth_msg, "<HTML><HEAD><TITLE>Authorization needed</TITLE>\n\ |
351 | </HEAD><BODY><H1>Authorization needed</H1>\n\ | |
352 | <P>Sorry, you have to authorize yourself to request\n\ | |
e381a13d | 353 | <PRE> ftp://%s@%s%s</PRE>\n\ |
db9f331f | 354 | <P>from this cache. Please check with the\n\ |
71f857d4 | 355 | <A HREF=\"mailto:%s\">cache administrator</A>\n\ |
356 | if you believe this is incorrect.\n\ | |
6e40f263 | 357 | <P>\n\ |
358 | %s\n\ | |
e381a13d | 359 | <HR>\n\ |
360 | <ADDRESS>\n\ | |
361 | Generated by %s/%s@%s\n\ | |
db9f331f | 362 | </ADDRESS></BODY></HTML>\n\ |
e381a13d | 363 | \n", |
364 | request->login, | |
365 | request->host, | |
366 | request->urlpath, | |
b6f794d6 | 367 | Config.adminEmail, |
6e40f263 | 368 | Config.errHtmlText, |
e381a13d | 369 | appname, |
370 | version_string, | |
371 | getMyHostname()); | |
372 | ||
373 | mk_mime_hdr(tbuf, | |
b6f794d6 | 374 | (time_t) Config.negativeTtl, |
e381a13d | 375 | strlen(auth_msg), |
376 | 0, | |
377 | "text/html"); | |
378 | sprintf(tmp_error_buf, "HTTP/1.0 401 Unauthorized\r\n\ | |
379 | %s\ | |
380 | WWW-Authenticate: Basic realm=\"%s\"\r\n\ | |
381 | \r\n\ | |
382 | %s", | |
383 | tbuf, realm, auth_msg); | |
384 | return tmp_error_buf; | |
385 | } | |
e81957b7 | 386 | |
387 | ||
388 | #define PROXY_AUTH_ERR_MSG "\ | |
389 | HTTP/1.0 %d Cache Access Denied\r\n\ | |
390 | Proxy-Authenticate: Basic realm=\"Squid proxy-caching web server\"\r\n\ | |
391 | Content-type: text/html\r\n\ | |
392 | \r\n\ | |
393 | <TITLE>Cache Access Denied</TITLE>\n\ | |
394 | <H2>Cache Access Denied</H2>\n\ | |
395 | <P>\n\ | |
396 | Sorry, you are not currently allowed to request\n\ | |
397 | <PRE> %s</PRE>\n\ | |
398 | from this cache until you have authenticated yourself.\n\ | |
399 | \n<p>\ | |
400 | You need to use Netscape version 2.0 or greater, or Microsoft Internet Explorer 3.0\n\ | |
401 | or an HTTP/1.1 compliant browser for this to work.\n\ | |
402 | Please contact the <a href=\"mailto:%s\">cache administrator</a>\n\ | |
403 | if you have difficulties authenticating yourself, or\n\ | |
404 | <a href=\"http://%s/cgi-bin/chpasswd.cgi\">change</a>\n\ | |
405 | your default password.\n\ | |
406 | <P>\n\ | |
407 | %s\n\ | |
408 | <HR>\n\ | |
409 | <ADDRESS>\n\ | |
410 | Generated by %s/%s@%s\n\ | |
411 | </ADDRESS>\n\ | |
412 | " | |
413 | ||
414 | char *proxy_denied_msg(code, method, url, client) | |
415 | int code; | |
416 | int method; | |
417 | char *url; | |
418 | char *client; | |
419 | { | |
420 | sprintf(tmp_error_buf, PROXY_AUTH_ERR_MSG, | |
421 | code, | |
422 | url, | |
423 | Config.adminEmail, | |
424 | getMyHostname(), | |
425 | Config.errHtmlText, | |
426 | appname, | |
427 | version_string, | |
428 | getMyHostname()); | |
429 | return tmp_error_buf; | |
430 | } |