git ssb

0+

cel / dillo-gemini



Commit 3eaae0075f7e0bd94595e6486528262ad962274c

Init

cel committed on 10/31/2019, 7:59:33 PM

Files changed

README.mdadded
gemini.filter.dpiadded
README.mdView
@@ -1,0 +1,31 @@
1 +# dillo-gemini
2 +
3 +[Gemini][] protocol plugin for [Dillo][].
4 +
5 +## Screenshot
6 +
7 +![Dillo loading gemini://gemini.conman.org/](&Mi6TnZIOeSmIVeI0VbtY3tqvIEcoCrUas2EwwS09sl0=.sha256)
8 +
9 +## Install
10 +
11 +```sh
12 +git clone ssb://%V0D7DtSnZyyAp1NbgOJF2ZAFMeUy9eXwyClCEKYUYAI=.sha256 dillo-gemini
13 +cd dillo-gemini
14 +mkdir -p ~/.dillo/dpi/gemini
15 +ln -rs gemini.dpi ~/.dillo/dpi/gemini
16 +test -f ~/.dillo/dpidrc || cp /etc/dillo/dpidrc ~/.dillo/dpidrc
17 +echo 'proto.gemini=gemini/gemini.dpi' >> ~/.dillo/dpidrc
18 +dpidc stop
19 +```
20 +
21 +## Sites to try
22 +
23 +- <gemini://gemini.circumlunar.space/>
24 +- <gemini://gemini.conman.org/>
25 +
26 +[Gemini]: https://gopher.tildeverse.org/zaibatsu.circumlunar.space/1/~solderpunk/gemini
27 +[Dillo]: https://dillo.org/
28 +
29 +## License
30 +
31 +FSFAP
gemini.filter.dpiView
@@ -1,0 +1,143 @@
1 +#!/bin/bash
2 +# dillo-gemini
3 +# © 2019 cel @f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519
4 +# Copying and distribution of this file, with or without modification,
5 +# are permitted in any medium without royalty provided the copyright
6 +# notice and this notice are preserved. This file is offered as-is,
7 +# without any warranty.
8 +
9 +read -d '>' auth
10 +read -d '>' cmd
11 +case "$cmd" in
12 + "<cmd='open_url' url='"*);;
13 + *) echo $cmd; exit;;
14 +esac
15 +url=${cmd#"<cmd='open_url' url='"}
16 +url=${url%"' '"}
17 +
18 +serve_404() {
19 + printf "<cmd='start_send_page' url='' '>\n"
20 + printf "Content-type: text/plain\r\n\r\n"
21 + echo Not found
22 +}
23 +
24 +render_gemini() {
25 + printf "Content-type: text/html\r\n\r\n<!doctype html><pre>"
26 + sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1<a href="\2">\2<\/a>\3/'
27 + printf "%s" "</pre>"
28 +}
29 +
30 +send_status_msg() {
31 + printf "<cmd='send_status_message' msg='%s' '>" "$*"
32 +}
33 +
34 +serve_status_not_supported() {
35 + printf "<cmd='start_send_page' url='' '>\n"
36 + printf "Content-type: text/plain\r\n\r\n"
37 + echo Status not implemented: $1
38 + echo $2
39 +}
40 +
41 +serve_missing_status() {
42 + printf "<cmd='start_send_page' url='' '>\n"
43 + printf "Content-type: text/plain\r\n\r\n"
44 + echo Empty status response. $2
45 +}
46 +
47 +serve_success() {
48 + printf "<cmd='start_send_page' url='' '>\n"
49 + type=$1
50 + case "$type" in
51 + text/gemini*) render_gemini;;
52 + *) printf "Content-type: $type\r\n\r\n"; cat;;
53 + esac
54 +}
55 +
56 +serve_redirect() {
57 + url=$1
58 + send_status_msg "Redirected"
59 + printf "<cmd='start_send_page' url='' '>\n"
60 + printf "Content-type: text/html\r\n\r\n"
61 + # TODO: html-escape url
62 + cat <<-EOF
63 + <!doctype html>
64 + <html>
65 + <head>
66 + <title>Redirect to $url</title>
67 + </head>
68 + <body>
69 + <h3>Redirect to <a href="$url">$url</a></3>
70 + </body>
71 + </html>
72 + EOF
73 +}
74 +
75 +serve_error() {
76 + status=$1
77 + meta=$2
78 + send_status_msg "Request failed"
79 + printf "<cmd='start_send_page' url='' '>\n"
80 + printf "Content-type: text/html\r\n\r\n"
81 + cat <<-EOF
82 + <!doctype html>
83 + <html>
84 + <head>
85 + <title>Request failed</title>
86 + </head>
87 + <body>
88 + <h3>Request failed: $status</h3>
89 + <code>$meta</code>
90 + </body>
91 + </html>
92 + EOF
93 +}
94 +
95 +serve_fail() {
96 + meta="$1"
97 + send_status_msg "Client certificate required"
98 + printf "<cmd='start_send_page' url='' '>\n"
99 + printf "Content-type: text/html\r\n\r\n"
100 + cat <<-EOF
101 + <!doctype html>
102 + <html>
103 + <head>
104 + <title>Client certificate required</title>
105 + </head>
106 + <body>
107 + <h3>Client certificate required</h3>
108 + <p>Not implemented!</p>
109 + <code>$meta</code>
110 + </body>
111 + </html>
112 + EOF
113 +}
114 +
115 +serve_gemini() {
116 + url=$1
117 + url1=${url#gemini://}
118 + hostname=${url1%%/*}
119 + host=${hostname%%:*}
120 + port=${hostname##*:}
121 + if [ "$host" = "$port" ]; then port=1965; fi
122 + send_status_msg "Sending request..."
123 + printf "%s\r\n" "$url" | ncat --ssl "$host" "$port" | {
124 + read status meta
125 + send_status_msg "Status: $status"
126 + meta=$(echo "$meta" | sed 's/\s*$//')
127 + case "$status" in
128 + 1*) serve_input "$meta";;
129 + 2*) serve_success "$meta";;
130 + 3*) serve_redirect "$meta";;
131 + 4*) serve_error "$status" "$meta";;
132 + 5*) serve_error "$meta";;
133 + 6*) serve_client_cert_required "$meta";;
134 + '') serve_missing_status "$meta";;
135 + *) serve_status_not_supported "$status" "$meta";;
136 + esac
137 + }
138 +}
139 +
140 +case "$url" in
141 + gemini:*) serve_gemini "$url";;
142 + *) serve_404;;
143 +esac

Built with git-ssb-web