dot

packages and services management
Log | Files | Refs | README

commit add8eb824d3f9370d8391c018e2ede1f69b3e29f
parent 730712bde7a45951bd88b3040ee8d05973e57888
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 13 Feb 2018 23:23:47 +0100

[add] gopher-local-proxy to serve http/html

Diffstat:
Abin/ghttpd | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dbin/gopher-proxy | 104-------------------------------------------------------------------------------
Abin/gproxy | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mskel/inetd.conf | 9+++++----
4 files changed, 201 insertions(+), 108 deletions(-)

diff --git a/bin/ghttpd b/bin/ghttpd @@ -0,0 +1,92 @@ +#!/usr/bin/awk -f +# converting gopher://localhost:70 to http://localhost:80/*.html +# +# /etc/inetd.conf: +# ghttpd stream tcp nowait root /.../ghttpd ghttpd host + +BEGIN { + HOST = ARGV[1]; + ARGC = 0; +} + +{ + sub("^GET /", ""); + sub(" HTTP/[0-9].*$", ""); + gsub(" ", "%20"); + gsub("\t", "%0b"); + gsub("\\\\", "%5c"); + + path = substr($0, 2); + flag = substr($0, 1, 1); + + printf("%s: %s / %s\n", $0, flag, path) > "/home/out"; + + exit; +} + +function esc(str) +{ + gsub("&", "\\&amp;", str); + gsub("<", "\\&lt;", str); + gsub(">", "\\&gt;", str); + gsub("\"", "\\&quot;", str); + return str; +} + +function url(f) +{ + if (sub("^URL:", "", f[2])) + return f[2]; + if (f[3] == HOST) + return sprintf("/%s%s", f[0], f[2]); + return sprintf("gopher://%s:%s/%s%s", f[3], f[4], f[0], f[2]); +} + +function link(type, f) +{ + return sprintf("<a href=\"%s\">%s</a> %s", url(f), type, esc(f[1])); +} + +END { + gsub("'", "", path); + + cmd = "printf '%s\r\n' '" path "' | nc -w 2 localhost 70" + + print("HTTP/1.1 200 OK\r"); + + if (flag == "1") { + print("Content-Type: text/html; charset=UTF-8\r"); + print("\r"); + print("<!doctype html><title>" HOST "</title><pre>"); + + t["0"] = "txt"; t["8"] = "net"; t["g"] = "img"; + t["1"] = "dir"; t["h"] = "url"; t["I"] = "img"; + while (cmd | getline) { + if (flag == "0") { + print(esc($0)); + continue; + } else if (flag == "1") { + sub("\r$", ""); + split($0, f, "\t"); + f[0] = substr(f[1], 1, 1); + sub(".", "", f[1]); + } + + if (f[0] == "i") + printf(" %s\n", esc(f[1])); + else + print(link(t[f[0]], f)); + } + print("</pre>"); + + } else if (flag == "0") { + print("Content-Type: text/plain; charset=UTF-8\r"); + print("\r"); + system(cmd); + + } else if (flag == "I" || flag = "g") { + print("Content-Type: image"); + print("\r"); + system(cmd); + } +} diff --git a/bin/gopher-proxy b/bin/gopher-proxy @@ -1,104 +0,0 @@ -#!/usr/bin/awk -f -# proxy from gopher to http and html for use with inetd -# -# /etc/inetd.conf: -# gopher-proxy stream tcp nowait root /.../gopher-proxy gopher-proxy host - -BEGIN { - LOCALHOST = ARGV[1]; - ARGC = 0; -} - -{ - sub("^GET /(gopher://)?", ""); sub(" HTTP/[0-9].*$", ""); - gsub(" ", "%20"); - gsub("\t", "%0b"); - gsub("\\\\", "%5c"); - - host = $0 - if (sub("^[^:]*:", ":")) { - sub(":.*", "", host); - } else if (sub("[^/]*/", "/")) { - sub("/.*", "", host); - } else { - $0 = ""; - } - - port = $0 - if (sub("^:[0-9]+:", "") || sub("^:[0-9]+/", "/")) { - sub(":", "", port); - sub("[:/].*", "", port); - } else if (sub("^:[0-9]+$", "")) { - sub(":", "", port); - } else { - port = "70"; - } - - flag = $0; - if (sub("^/.", "")) { - sub("^/", "", flag); - sub("/.*", "", flag); - } else { - flag = "."; - } - - path = $0; - - printf("%s\t%s\t%s\t%s", host, port, flag, path); -} - -function esc(str) -{ - gsub("&", "\\&amp;", str); - gsub("<", "\\&lt;", str); - gsub(">", "\\&gt;", str); - gsub("\"", "\\&quot;", str); - return str; -} - -function url(f) -{ - if (sub("^URL:", "", f[2])) - return f[2]; - return sprintf("http://%s/%s:%s/%s%s", HOST, f[3], f[4], f[0], f[2]); -} - -function link(type, f) -{ - return sprintf("<a href=\"%s\">%s</a> %s", url(f), type, esc(f[1])); -} - -END { - gsub("'", "", host); - gsub("'", "", port); - - cmd = "nc -w 2 -- '" host "' '" port "'" - - print("HTTP/1.1 200 OK\r"); - print("Content-Encoding: UTF-8\r"); - print("Content-Type: text/html; charset=UTF-8\r"); - print("\r"); - print("<!doctype html><title>gopher proxy</title><pre>"); - - if (FLAG == "0") { - print(esc($0)); - next; - } else if (flag == "1" || flag == ".") { - sub("\r$", ""); - split($0, f, "\t"); - f[0] = substr(f[1], 1, 1); - sub(".", "", f[1]); - } - - while (cmd | getline) { - if (f[0] == "i") { printf(" %s\n", esc(f[1])); next; } - else if (f[0] == "0") { print(link("txt", f)); next; } - else if (f[0] == "1") { print(link("dir", f)); next; } - else if (f[0] == "8") { print(link("net", f)); next; } - else if (f[0] == "h") { print(link("url", f)); next; } - else if (f[0] == "g") { print(link("img", f)); next; } - else if (f[0] == "I") { print(link("img", f)); next; } - } - - print("</pre>"); -} diff --git a/bin/gproxy b/bin/gproxy @@ -0,0 +1,104 @@ +#!/usr/bin/awk -f +# proxy from gopher to http and html for use with inetd +# +# /etc/inetd.conf: +# gproxy stream tcp nowait root /.../gproxy gproxy host + +BEGIN { + LOCALHOST = ARGV[1]; + ARGC = 0; +} + +{ + sub("^GET /(gopher://)?", ""); sub(" HTTP/[0-9].*$", ""); + gsub(" ", "%20"); + gsub("\t", "%0b"); + gsub("\\\\", "%5c"); + + host = $0 + if (sub("^[^:]*:", ":")) { + sub(":.*", "", host); + } else if (sub("[^/]*/", "/")) { + sub("/.*", "", host); + } else { + $0 = ""; + } + + port = $0 + if (sub("^:[0-9]+:", "") || sub("^:[0-9]+/", "/")) { + sub(":", "", port); + sub("[:/].*", "", port); + } else if (sub("^:[0-9]+$", "")) { + sub(":", "", port); + } else { + port = "70"; + } + + flag = $0; + if (sub("^/.", "")) { + sub("^/", "", flag); + sub("/.*", "", flag); + } else { + flag = "."; + } + + path = $0; + + printf("%s\t%s\t%s\t%s", host, port, flag, path); +} + +function esc(str) +{ + gsub("&", "\\&amp;", str); + gsub("<", "\\&lt;", str); + gsub(">", "\\&gt;", str); + gsub("\"", "\\&quot;", str); + return str; +} + +function url(f) +{ + if (sub("^URL:", "", f[2])) + return f[2]; + return sprintf("http://%s/%s:%s/%s%s", HOST, f[3], f[4], f[0], f[2]); +} + +function link(type, f) +{ + return sprintf("<a href=\"%s\">%s</a> %s", url(f), type, esc(f[1])); +} + +END { + gsub("'", "", host); + gsub("'", "", port); + + cmd = "nc -w 2 -- '" host "' '" port "'" + + print("HTTP/1.1 200 OK\r"); + print("Content-Encoding: UTF-8\r"); + print("Content-Type: text/html; charset=UTF-8\r"); + print("\r"); + print("<!doctype html><title>gopher proxy</title><pre>"); + + if (FLAG == "0") { + print(esc($0)); + next; + } else if (flag == "1" || flag == ".") { + sub("\r$", ""); + split($0, f, "\t"); + f[0] = substr(f[1], 1, 1); + sub(".", "", f[1]); + } + + while (cmd | getline) { + if (f[0] == "i") { printf(" %s\n", esc(f[1])); next; } + else if (f[0] == "0") { print(link("txt", f)); next; } + else if (f[0] == "1") { print(link("dir", f)); next; } + else if (f[0] == "8") { print(link("net", f)); next; } + else if (f[0] == "h") { print(link("url", f)); next; } + else if (f[0] == "g") { print(link("img", f)); next; } + else if (f[0] == "I") { print(link("img", f)); next; } + } + + print("</pre>"); +} diff --git a/skel/inetd.conf b/skel/inetd.conf @@ -1,9 +1,10 @@ #service type conn wait user path argv -#pop3 stream tcp nowait root /XXX/bin/popa3d popa3d -#9fs stream tcp nowait root /XXX/bin/u9fs u9fs -#http stream tcp nowait root /XXX/bin/gopher-proxy gopher-proxy nas.josuah.net -#rsync stream tcp nowait root /XXX/bin/rsyncd rsyncd --daemon +#pop3 stream tcp nowait nobody /XXX/bin/popa3d popa3d +#9fs stream tcp nowait nobody /XXX/bin/u9fs u9fs +#http stream tcp nowait nobody /XXX/bin/gproxy gproxy nas.josuah.net +#http stream tcp nowait nobody /XXX/bin/ghttp ghttp josuah.net +#rsync stream tcp nowait nobody /XXX/bin/rsyncd rsyncd --daemon #/tmp/irc.cyberia.is stream unix nowait nobody /XXX/bin/openssl openssl s_client -quiet -connect irc.cyberia.is:6697 #/tmp/unix.chat stream unix nowait nobody /XXX/bin/openssl openssl s_client -quiet -connect unix.chat:6697