3 * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <sys/queue.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
33 {{ define tp_head(struct template *tp, const char *lang,
35 {! struct client *clt = tp->tp_arg; !}
36 {! struct proxy_config *pc = clt->clt_pc; !}
37 {! const char *stylesheet = pc->stylesheet; !}
38 {! const char *path = clt->clt_path_info; !}
40 <html{{ if *lang != '\0' }}lang="{{ lang }}"{{ end }}>
42 <meta name="viewport" content="initial-scale=1" />
43 {{ if *stylesheet != '\0' }}
44 <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
50 gemini://{{ pc->proxy_name }}{{ path }}
57 {{ define tp_foot(struct template *tp) }}
58 {! struct client *clt = tp->tp_arg; !}
59 {! struct proxy_config *pc = clt->clt_pc; !}
60 {! const char *host = pc->proxy_name; !}
61 {! const char *path = clt->clt_path_info; !}
66 <dt>Original URL:</dt>
68 <a href="gemini://{{ host | urlescape }}{{ path | urlescape }}">
69 gemini://{{ host }}{{ path }}
78 {{ define tp_figure(struct template *tp, const char *url,
81 struct client *clt = tp->tp_arg;
82 const char *path = "";
85 relativify = *url == '/' || strstr(url, "//") == NULL;
87 path = clt->clt_script_name;
88 url++; /* skip leading / */
92 <a href="{{ path | urlescape }}{{ url | urlescape }}">
93 <img src="{{ path | urlescape }}{{ url | urlescape }}" />
101 {{ define tp_error(struct template *tp, const char *reason) }}
102 {{ render tp_head(tp, "en", "Proxy error") }}
105 <p>Unable to serve the page due to:</p>
106 <pre>{{ reason }}</pre>
108 {{ render tp_foot(tp) }}