Blob


1 {!
2 /*
3 * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 *
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.
8 *
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.
16 */
18 #include <sys/queue.h>
19 #include <sys/tree.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
24 #include <event.h>
25 #include <limits.h>
26 #include <stdint.h>
27 #include <string.h>
29 #include "galileo.h"
31 !}
33 {{ define tp_head(struct template *tp, const char *lang,
34 const char *title) }}
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; !}
39 <!doctype html>
40 <html{{ if *lang != '\0' }}lang="{{ lang }}"{{ end }}>
41 <head>
42 <meta name="viewport" content="initial-scale=1" />
43 {{ if *stylesheet != '\0' }}
44 <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
45 {{ end }}
46 <title>
47 {{ if title }}
48 {{ title }}
49 {{ else }}
50 gemini://{{ pc->proxy_name }}{{ path }}
51 {{ end }}
52 </title>
53 </head>
54 <body>
55 {{ end }}
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; !}
63 <footer>
64 <hr />
65 <dl>
66 <dt>Original URL:</dt>
67 <dd>
68 <a href="gemini://{{ host | urlescape }}{{ path | urlescape }}">
69 gemini://{{ host }}{{ path }}
70 </a>
71 </dd>
72 </dl>
73 </footer>
74 </body>
75 </html>
76 {{ end }}
78 {{ define tp_figure(struct template *tp, const char *url,
79 const char *label) }}
80 {!
81 struct client *clt = tp->tp_arg;
82 const char *path = "";
83 int relativify;
85 relativify = *url == '/' || strstr(url, "//") == NULL;
86 if (relativify) {
87 path = clt->clt_script_name;
88 url++; /* skip leading / */
89 }
90 !}
91 <figure>
92 <a href="{{ path | urlescape }}{{ url | urlescape }}">
93 <img src="{{ path | urlescape }}{{ url | urlescape }}" />
94 </a>
95 <figcaption>
96 {{ label }}
97 </figcaption>
98 </figure>
99 {{ end }}
101 {{ define tp_error(struct template *tp, const char *reason) }}
102 {{ render tp_head(tp, "en", "Proxy error") }}
103 <main>
104 <h1>Proxy error</h1>
105 <p>Unable to serve the page due to:</p>
106 <pre>{{ reason }}</pre>
107 </main>
108 {{ render tp_foot(tp) }}
109 {{ end }}