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>
34 {{ define tp_head(struct template *tp, const char *lang,
37 struct client *clt = tp->tp_arg;
38 struct proxy_config *pc = clt->clt_pc;
39 const char *stylesheet = pc->stylesheet;
40 const char *path = clt->clt_path_info;
43 <html{{ if *lang != '\0' }}lang="{{ lang }}"{{ end }}>
45 <meta name="viewport" content="initial-scale=1" />
47 {{ if *stylesheet == '\0' }}
48 <link rel="stylesheet" href="{{ prfx|urlescape }}/galileo.css" />
50 <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
57 gemini://{{ pc->proxy_name }}{{ path }}
64 {{ define tp_foot(struct template *tp) }}
66 struct client *clt = tp->tp_arg;
67 struct proxy_config *pc = clt->clt_pc;
68 const char *host = pc->proxy_name;
69 const char *path = clt->clt_path_info;
75 <dt>Original URL:</dt>
77 <a href="gemini://{{ host | urlescape }}{{ path | urlescape }}">
78 gemini://{{ host }}{{ path }}
87 {{ define tp_figure(struct template *tp, const char *url,
90 struct client *clt = tp->tp_arg;
91 const char *path = "";
94 relativify = *url == '/' || strstr(url, "//") == NULL;
96 path = clt->clt_script_name;
97 url++; /* skip leading / */
101 <a href="{{ path | urlescape }}{{ url | urlescape }}">
102 <img src="{{ path | urlescape }}{{ url | urlescape }}" />
110 {{ define tp_error(struct template *tp, int code, const char *reason) }}
115 r = snprintf(scode, sizeof(code), "%d", code);
116 if (r < 0 || (size_t)r >= sizeof(code))
120 {{ render tp_head(tp, "en", "Proxy error") }}
124 <p>Request failed with code: <code>{{ scode }}</code>.</p>
125 <p>The server says: {{ reason }}.</p>
127 <p>Unable to serve the page due to: {{ reason }}.</p>
130 {{ render tp_foot(tp) }}
133 {{ define tp_inputpage(struct template *tp, const char *prompt) }}
134 {{ render tp_head(tp, "en", "input request") }}
135 <p>The server ask for input: <q>{{ prompt }}</q>.</p>
136 <form method="post" enctype="{{ FORM_URLENCODED }}">
137 <label for="reply">{{ "response " }}</label>
138 <input type="text" value="" id="reply" name="q" />
140 <button type="submit">Submit!</button>
142 {{ render tp_foot(tp) }}