release 0.92.3
[cntlm.git] / pages.c
blob2242f53e56cb5d4ce667cba10a8c9dc823e4f207
1 /*
2 * Static HTML page generators for CNTLM
4 * CNTLM is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
7 * version.
9 * CNTLM is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 * details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
16 * St, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Copyright (c) 2007 David Kubicek
22 #ifndef _PAGES_H
23 #define _PAGES_H
25 #include "utils.h"
26 #include "string.h"
27 #include "stdio.h"
29 char *gen_407_page(const char *http) {
30 char *tmp;
31 if (http == NULL)
32 http = "HTTP/1.0";
33 tmp = new(BUFSIZE);
34 snprintf(tmp, BUFSIZE-1,
35 "%s 407 Access denied\r\n"
36 "Proxy-Authenticate: Basic realm=\"Cntlm Proxy\"\r\n"
37 "Content-Type: text/html\r\n\r\n"
38 "<html><body><h1>407 Access denied</h1><p><a href='http://cntlm.sf.net/'>Cntlm</a> requests your credentials for proxy access.</p></body></html>",
39 http);
40 return tmp;
43 char *gen_401_page(const char *http, const char *host, int port) {
44 char *tmp;
45 if (http == NULL)
46 http = "HTTP/1.0";
47 tmp = new(BUFSIZE);
48 snprintf(tmp, BUFSIZE-1,
49 "%s 401 Access denied\r\n"
50 "WWW-Authenticate: Basic realm=\"%s:%d\"\r\n"
51 "Content-Type: text/html\r\n\r\n"
52 "<html><body><h1>401 Access denied</h1><p><a href='http://cntlm.sf.net/'>Cntlm</a> proxy requests your credentials for this URL.</p></body></html>",
53 http, host, port);
54 return tmp;
57 char *gen_denied_page(const char *ip) {
58 char *tmp;
59 if (ip == NULL)
60 ip = "client";
61 tmp = new(BUFSIZE);
62 snprintf(tmp, BUFSIZE-1,
63 "HTTP/1.0 407 Access denied\r\n"
64 "Content-Type: text/html\r\n\r\n"
65 "<html><body><h1>Access denied</h1><p>Your request has been declined, %s is not allowed to connect.</p></body></html>",
66 ip);
67 return tmp;
70 char *gen_502_page(const char *http, const char *msg) {
71 char *tmp;
72 if (http == NULL)
73 http = "HTTP/1.0";
74 if (msg == NULL)
75 msg = "Proxy error";
76 tmp = new(BUFSIZE);
77 snprintf(tmp, BUFSIZE-1,
78 "%s 502 %s\r\n"
79 "Content-Type: text/html\r\n\r\n"
80 "<html><body><h1>502 %s</h1><p><a href='http://cntlm.sf.net/'>Cntlm</a> proxy failed to complete the request.</p></body></html>",
81 http, msg, msg);
82 return tmp;
85 #endif /* _PAGES_H */