Blame


1 a80e4b65 2022-09-19 op {!
2 a80e4b65 2022-09-19 op /*
3 a80e4b65 2022-09-19 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 a80e4b65 2022-09-19 op *
5 a80e4b65 2022-09-19 op * Permission to use, copy, modify, and distribute this software for any
6 a80e4b65 2022-09-19 op * purpose with or without fee is hereby granted, provided that the above
7 a80e4b65 2022-09-19 op * copyright notice and this permission notice appear in all copies.
8 a80e4b65 2022-09-19 op *
9 a80e4b65 2022-09-19 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 a80e4b65 2022-09-19 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 a80e4b65 2022-09-19 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 a80e4b65 2022-09-19 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 a80e4b65 2022-09-19 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 a80e4b65 2022-09-19 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 a80e4b65 2022-09-19 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 a80e4b65 2022-09-19 op */
17 a80e4b65 2022-09-19 op
18 a80e4b65 2022-09-19 op #include <sys/queue.h>
19 a80e4b65 2022-09-19 op #include <sys/tree.h>
20 a80e4b65 2022-09-19 op
21 a80e4b65 2022-09-19 op #include <netinet/in.h>
22 a80e4b65 2022-09-19 op #include <arpa/inet.h>
23 a80e4b65 2022-09-19 op
24 a80e4b65 2022-09-19 op #include <event.h>
25 a80e4b65 2022-09-19 op #include <limits.h>
26 a80e4b65 2022-09-19 op #include <stdint.h>
27 abe17781 2022-09-20 op #include <stdio.h>
28 54acddc9 2022-09-19 op #include <string.h>
29 a80e4b65 2022-09-19 op
30 a80e4b65 2022-09-19 op #include "galileo.h"
31 8442fa67 2022-12-04 op #include "tmpl.h"
32 a80e4b65 2022-09-19 op
33 a80e4b65 2022-09-19 op !}
34 a80e4b65 2022-09-19 op
35 a80e4b65 2022-09-19 op {{ define tp_head(struct template *tp, const char *lang,
36 e3c1cbab 2022-09-20 op const char *title) }}
37 7b11f549 2022-09-23 op {!
38 7b11f549 2022-09-23 op struct client *clt = tp->tp_arg;
39 7b11f549 2022-09-23 op struct proxy_config *pc = clt->clt_pc;
40 f267a4be 2022-09-30 op const char *stylesheet = pc ? pc->stylesheet : "";
41 7905878b 2022-09-23 op const char *prfx = clt->clt_script_name;
42 7b11f549 2022-09-23 op const char *path = clt->clt_path_info;
43 7b11f549 2022-09-23 op !}
44 a80e4b65 2022-09-19 op <!doctype html>
45 db3f5b3d 2022-09-23 op <html{{ if *lang != '\0' }}{{ " " }}lang="{{ lang }}"{{ end }}>
46 a80e4b65 2022-09-19 op <head>
47 a80e4b65 2022-09-19 op <meta name="viewport" content="initial-scale=1" />
48 5188543c 2022-09-23 op
49 44ec372b 2022-09-23 op {{ if *stylesheet == 0 }}
50 44ec372b 2022-09-23 op <link rel="stylesheet" href="{{ prfx }}galileo.css" />
51 5188543c 2022-09-23 op {{ else }}
52 a80e4b65 2022-09-19 op <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
53 a80e4b65 2022-09-19 op {{ end }}
54 5188543c 2022-09-23 op
55 e3c1cbab 2022-09-20 op <title>
56 e3c1cbab 2022-09-20 op {{ if title }}
57 e3c1cbab 2022-09-20 op {{ title }}
58 f267a4be 2022-09-30 op {{ else if pc }}
59 e3c1cbab 2022-09-20 op gemini://{{ pc->proxy_name }}{{ path }}
60 e3c1cbab 2022-09-20 op {{ end }}
61 e3c1cbab 2022-09-20 op </title>
62 a80e4b65 2022-09-19 op </head>
63 a80e4b65 2022-09-19 op <body>
64 a80e4b65 2022-09-19 op {{ end }}
65 a80e4b65 2022-09-19 op
66 a80e4b65 2022-09-19 op {{ define tp_foot(struct template *tp) }}
67 7b11f549 2022-09-23 op {!
68 7b11f549 2022-09-23 op struct client *clt = tp->tp_arg;
69 7b11f549 2022-09-23 op struct proxy_config *pc = clt->clt_pc;
70 7b11f549 2022-09-23 op const char *path = clt->clt_path_info;
71 7b11f549 2022-09-23 op !}
72 f267a4be 2022-09-30 op {{ if pc }}
73 a80e4b65 2022-09-19 op <footer>
74 a80e4b65 2022-09-19 op <hr />
75 a80e4b65 2022-09-19 op <dl>
76 a80e4b65 2022-09-19 op <dt>Original URL:</dt>
77 a80e4b65 2022-09-19 op <dd>
78 f267a4be 2022-09-30 op <a href="gemini://{{ pc->proxy_name | urlescape }}{{ path | urlescape }}">
79 f267a4be 2022-09-30 op gemini://{{ pc->proxy_name }}{{ path }}
80 a80e4b65 2022-09-19 op </a>
81 a80e4b65 2022-09-19 op </dd>
82 a80e4b65 2022-09-19 op </dl>
83 a80e4b65 2022-09-19 op </footer>
84 f267a4be 2022-09-30 op {{ end }}
85 a80e4b65 2022-09-19 op </body>
86 a80e4b65 2022-09-19 op </html>
87 a80e4b65 2022-09-19 op {{ end }}
88 a80e4b65 2022-09-19 op
89 1a52bb7c 2022-12-04 op {{ define tp_figure(struct template *tp, const char *url, const char *label) }}
90 a80e4b65 2022-09-19 op <figure>
91 1d31253b 2022-11-11 op <a href="{{ url | urlescape }}">
92 1d31253b 2022-11-11 op <img src="{{ url | urlescape }}" />
93 a80e4b65 2022-09-19 op </a>
94 a80e4b65 2022-09-19 op <figcaption>
95 a80e4b65 2022-09-19 op {{ label }}
96 a80e4b65 2022-09-19 op </figcaption>
97 a80e4b65 2022-09-19 op </figure>
98 a80e4b65 2022-09-19 op {{ end }}
99 e3c1cbab 2022-09-20 op
100 ceb3f79c 2022-09-29 op {{ define tp_pre_open(struct template *tp, const char *label) }}
101 ceb3f79c 2022-09-29 op <figure>
102 ceb3f79c 2022-09-29 op {{ if label && *label != '\0' }}
103 ceb3f79c 2022-09-29 op <figcaption>{{ label }}</figcaption>
104 ceb3f79c 2022-09-29 op {{ end }}
105 ceb3f79c 2022-09-29 op <pre>
106 ceb3f79c 2022-09-29 op {{ end }}
107 ceb3f79c 2022-09-29 op
108 ceb3f79c 2022-09-29 op {{ define tp_pre_close(struct template *tp) }}
109 ceb3f79c 2022-09-29 op </pre>
110 ceb3f79c 2022-09-29 op </figure>
111 ceb3f79c 2022-09-29 op {{ end }}
112 ceb3f79c 2022-09-29 op
113 abe17781 2022-09-20 op {{ define tp_error(struct template *tp, int code, const char *reason) }}
114 abe17781 2022-09-20 op {!
115 abe17781 2022-09-20 op char scode[32];
116 abe17781 2022-09-20 op int r;
117 abe17781 2022-09-20 op
118 abe17781 2022-09-20 op r = snprintf(scode, sizeof(code), "%d", code);
119 abe17781 2022-09-20 op if (r < 0 || (size_t)r >= sizeof(code))
120 c9e6d547 2022-09-23 op return (0);
121 abe17781 2022-09-20 op
122 abe17781 2022-09-20 op !}
123 e3c1cbab 2022-09-20 op {{ render tp_head(tp, "en", "Proxy error") }}
124 e3c1cbab 2022-09-20 op <main>
125 e3c1cbab 2022-09-20 op <h1>Proxy error</h1>
126 abe17781 2022-09-20 op {{ if code != -1 }}
127 abe17781 2022-09-20 op <p>Request failed with code: <code>{{ scode }}</code>.</p>
128 abe17781 2022-09-20 op <p>The server says: {{ reason }}.</p>
129 abe17781 2022-09-20 op {{ else }}
130 abe17781 2022-09-20 op <p>Unable to serve the page due to: {{ reason }}.</p>
131 abe17781 2022-09-20 op {{ end }}
132 e3c1cbab 2022-09-20 op </main>
133 e3c1cbab 2022-09-20 op {{ render tp_foot(tp) }}
134 e3c1cbab 2022-09-20 op {{ end }}
135 8857131d 2022-09-20 op
136 8857131d 2022-09-20 op {{ define tp_inputpage(struct template *tp, const char *prompt) }}
137 8857131d 2022-09-20 op {{ render tp_head(tp, "en", "input request") }}
138 9c83d68a 2022-09-22 op <p>The server ask for input: <q>{{ prompt }}</q>.</p>
139 8857131d 2022-09-20 op <form method="post" enctype="{{ FORM_URLENCODED }}">
140 9c83d68a 2022-09-22 op <label for="reply">{{ "response " }}</label>
141 58b5d440 2022-11-11 op <input type="text" value="" id="reply" name="q" autofocus />
142 9c83d68a 2022-09-22 op {{ " " }}
143 9c83d68a 2022-09-22 op <button type="submit">Submit!</button>
144 8857131d 2022-09-20 op </form>
145 8857131d 2022-09-20 op {{ render tp_foot(tp) }}
146 8857131d 2022-09-20 op {{ end }}