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 static int tp_navigation(struct template *);
38 {{ define tp_head(struct template *tp, const char *lang,
41 struct client *clt = tp->tp_arg;
42 struct proxy_config *pc = clt->clt_pc;
43 const char *stylesheet = pc ? pc->stylesheet : "";
44 const char *prfx = clt->clt_script_name;
45 const char *path = clt->clt_path_info;
48 hidenav = pc ? pc->flags & PROXY_NO_NAVBAR : 0;
51 <html{{ if *lang != '\0' }}{{ " " }}lang="{{ lang }}"{{ end }}>
53 <meta name="viewport" content="initial-scale=1" />
55 {{ if *stylesheet == 0 }}
56 <link rel="stylesheet" href="{{ prfx }}galileo.css" />
58 <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
65 gemini://{{ pc->proxy_name }}{{ path }}
70 {{ if path && !hidenav }}
71 {{ render tp_navigation(tp) }}
75 {{ define tp_foot(struct template *tp) }}
77 struct client *clt = tp->tp_arg;
78 struct proxy_config *pc = clt->clt_pc;
79 const char *path = clt->clt_path_info;
82 hidefoot = pc ? pc->flags & PROXY_NO_FOOTER : 0;
84 {{ if pc && !hidefoot }}
88 <dt>Original URL:</dt>
90 <a href="gemini://{{ pc->proxy_name | urlescape }}{{ path | urlescape }}">
91 gemini://{{ pc->proxy_name }}{{ path }}
101 {{ define tp_navigation(struct template *tp) }}
103 struct client *clt = tp->tp_arg;
104 const char *dname, *dsufx = "/", *prfx = clt->clt_script_name;
105 char *path = clt->clt_path_info;
106 char *tilde, *t, home[GEMINI_MAXLEN], up[GEMINI_MAXLEN];
111 if ((tilde = strstr(path, "/~")) != NULL &&
112 (t = strchr(tilde + 1, '/')) != NULL) {
115 (void) strlcpy(home, path + 1, sizeof(home));
120 (void) strlcpy(usr, tilde + 2, sizeof(usr));
124 (void) strlcpy(up, path + 1, sizeof(up));
126 if (!strcmp(dname, ".")) {
134 <li><a href="{{ prfx }}">/ Root</a></li>
136 <li><a href="{{ prfx }}{{ dname }}{{ dsufx }}">
140 {{ if *home != '\0' }}
141 <li><a href="{{ prfx }}{{ home }}">
150 {{ define tp_figure(struct template *tp, const char *url, const char *label) }}
152 <a href="{{ url | urlescape }}">
153 <img src="{{ url | urlescape }}" />
161 {{ define tp_pre_open(struct template *tp, const char *label) }}
163 {{ if label && *label != '\0' }}
164 <figcaption>{{ label }}</figcaption>
169 {{ define tp_pre_close(struct template *tp) }}
174 {{ define tp_error(struct template *tp, int code, const char *reason) }}
179 r = snprintf(scode, sizeof(code), "%d", code);
180 if (r < 0 || (size_t)r >= sizeof(code))
184 {{ render tp_head(tp, "en", "Proxy error") }}
188 <p>Request failed with code: <code>{{ scode }}</code>.</p>
189 <p>The server says: {{ reason }}.</p>
191 <p>Unable to serve the page due to: {{ reason }}.</p>
194 {{ render tp_foot(tp) }}
197 {{ define tp_inputpage(struct template *tp, const char *prompt) }}
198 {{ render tp_head(tp, "en", "input request") }}
199 <p>The server ask for input: <q>{{ prompt }}</q>.</p>
200 <form method="post" enctype="{{ FORM_URLENCODED }}">
201 <label for="reply">{{ "response " }}</label>
202 <input type="text" value="" id="reply" name="q" autofocus />
204 <button type="submit">Submit!</button>
206 {{ render tp_foot(tp) }}