3 a80e4b65 2022-09-19 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
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.
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.
18 a80e4b65 2022-09-19 op #include <sys/queue.h>
19 a80e4b65 2022-09-19 op #include <sys/tree.h>
21 a80e4b65 2022-09-19 op #include <netinet/in.h>
22 a80e4b65 2022-09-19 op #include <arpa/inet.h>
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 54acddc9 2022-09-19 op #include <string.h>
29 a80e4b65 2022-09-19 op #include "galileo.h"
33 a80e4b65 2022-09-19 op {{ define tp_head(struct template *tp, const char *lang,
34 e3c1cbab 2022-09-20 op const char *title) }}
35 e3c1cbab 2022-09-20 op {! struct client *clt = tp->tp_arg; !}
36 e3c1cbab 2022-09-20 op {! struct proxy_config *pc = clt->clt_pc; !}
37 e3c1cbab 2022-09-20 op {! const char *stylesheet = pc->stylesheet; !}
38 e3c1cbab 2022-09-20 op {! const char *path = clt->clt_path_info; !}
39 a80e4b65 2022-09-19 op <!doctype html>
40 a80e4b65 2022-09-19 op <html{{ if *lang != '\0' }}lang="{{ lang }}"{{ end }}>
42 a80e4b65 2022-09-19 op <meta name="viewport" content="initial-scale=1" />
43 a80e4b65 2022-09-19 op {{ if *stylesheet != '\0' }}
44 a80e4b65 2022-09-19 op <link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
47 e3c1cbab 2022-09-20 op {{ if title }}
50 e3c1cbab 2022-09-20 op gemini://{{ pc->proxy_name }}{{ path }}
57 a80e4b65 2022-09-19 op {{ define tp_foot(struct template *tp) }}
58 a80e4b65 2022-09-19 op {! struct client *clt = tp->tp_arg; !}
59 a80e4b65 2022-09-19 op {! struct proxy_config *pc = clt->clt_pc; !}
60 a80e4b65 2022-09-19 op {! const char *host = pc->proxy_name; !}
61 a80e4b65 2022-09-19 op {! const char *path = clt->clt_path_info; !}
66 a80e4b65 2022-09-19 op <dt>Original URL:</dt>
68 a80e4b65 2022-09-19 op <a href="gemini://{{ host | urlescape }}{{ path | urlescape }}">
69 a80e4b65 2022-09-19 op gemini://{{ host }}{{ path }}
78 a80e4b65 2022-09-19 op {{ define tp_figure(struct template *tp, const char *url,
79 a80e4b65 2022-09-19 op const char *label) }}
81 54acddc9 2022-09-19 op struct client *clt = tp->tp_arg;
82 54acddc9 2022-09-19 op const char *path = "";
83 54acddc9 2022-09-19 op int relativify;
85 54acddc9 2022-09-19 op relativify = *url == '/' || strstr(url, "//") == NULL;
86 54acddc9 2022-09-19 op if (relativify) {
87 54acddc9 2022-09-19 op path = clt->clt_script_name;
88 54acddc9 2022-09-19 op url++; /* skip leading / */
92 54acddc9 2022-09-19 op <a href="{{ path | urlescape }}{{ url | urlescape }}">
93 07922252 2022-09-19 op <img src="{{ path | urlescape }}{{ url | urlescape }}" />
101 e3c1cbab 2022-09-20 op {{ define tp_error(struct template *tp, const char *reason) }}
102 e3c1cbab 2022-09-20 op {{ render tp_head(tp, "en", "Proxy error") }}
104 e3c1cbab 2022-09-20 op <h1>Proxy error</h1>
105 e3c1cbab 2022-09-20 op <p>Unable to serve the page due to:</p>
106 e3c1cbab 2022-09-20 op <pre>{{ reason }}</pre>
108 e3c1cbab 2022-09-20 op {{ render tp_foot(tp) }}