dot

packages and services management
Log | Files | Refs | README

commit 8bc78b76ba08fb452192611d975b6fef0ff0f684
parent 6a2b1015260544455a6c09bf0ccc7ab869318502
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 16 Feb 2018 11:23:11 +0100

gproxy: convert to ghttpd-style formatting

Diffstat:
Mbin/gproxy | 68++++++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 36 insertions(+), 32 deletions(-)

diff --git a/bin/gproxy b/bin/gproxy @@ -2,10 +2,10 @@ # proxy from gopher to http and html for use with inetd # # /etc/inetd.conf: -# gproxy stream tcp nowait root /.../gproxy gproxy host +# gproxy stream tcp nowait nobody /.../gproxy gproxy host BEGIN { - LOCALHOST = ARGV[1]; + HOST = ARGV[1]; ARGC = 0; } @@ -44,7 +44,7 @@ BEGIN { path = $0; - printf("%s\t%s\t%s\t%s", host, port, flag, path); + exit; } function esc(str) @@ -63,42 +63,46 @@ function url(f) return sprintf("http://%s/%s:%s/%s%s", HOST, f[3], f[4], f[0], f[2]); } -function link(type, f) +function link(f) { - return sprintf("<a href=\"%s\">%s</a> %s", url(f), type, esc(f[1])); + return sprintf("<a href=\"%s\">%s</a>", url(f), esc(f[1])); } END { + gsub("'", "", path); gsub("'", "", host); - gsub("'", "", port); - - cmd = "nc -w 2 -- '" host "' '" port "'" + cmd = "printf '%s\r\n' '" path "' | nc -w 5 '" host "' 70" 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; } + if (flag == "1" || flag == "") { + print("Content-Type: text/html; charset=UTF-8\r"); + print("\r"); + print("<!doctype html><title>" HOST "</title>"); + print("<style>a { text-decoration:none; color:#077; }</style>"); + print("<pre style=\"width: 80ch; margin: auto;\">"); + + while (cmd | getline) { + 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(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); } - - print("</pre>"); }