#!/bin/rc # webshittery for use with the following plumbing rules: # wdir is /mnt/webshit # data matches \[submit\]|§|□|○|[⁰¹²³⁴⁵⁶⁷⁸⁹]+|hpost.*|←|→|{[0-9]*} # plumb to webshit # data matches (gemini|gopher|https?)://[a-zA-Z0-9\-._~:/?#[\]@!$&''()*+,;=%]+ # plumb to webshit # plumb client window webshit # and rules for image, audio & video ports to handle multimedia: # dst is video # plumb to video # plumb client window tube # dst is audio # plumb to audio # plumb client window playlist # dst is image # plumb to image # plumb client page -iw rfork en width = 70 nl = ' ' fn jumpto{ if(test -f $1){ n = $1 cat $n >/dev/text echo -n  >/dev/kbdin } if not read `{ls -rt} } fn format{ if(test -s incoming){ if(~ $mime text/*){ n = `{ls | wc -l} if(~ $data *' '*) echo ← '{'^$n^'} → {'^$data^'}'^$nl >$n if not echo ← '{'^$n^'} →' $data^$nl >$n switch($mime){ case text/gemini* tr -d [ ]/{ sub(/^=>[ ]+/, "") if(match($1, "^//")) url[n] = "gemini:"$1 else if(match($1, "^/")) url[n] = root $1 else if(match($1, "^[a-z]+://")) url[n] = $1 else url[n] = base $1 sub(/^[^ ]+[ ]+/, "") sub(/$/, fn(n++)) } {print} END{ if(n == 1) exit printf "\nReferences:\n" for(i = 1; i < n; i++) printf "%s%s\n", fn(i), url[i] } ' | fmt -j -l $width >>$n case text/gopher* tr -d 1{ type = substr($1, 1, 1) display = substr($1, 2, length($1) - 1) if(type == "i" || type == "3") print display else if(type == "h"){ sub("^URL:", "", $2) url[n] = $2 print "HTTP: " display fn(n++) }else{ if($3 == "") s = host else s = $3 if($4 != "" && $4 != "70") s = s ":" $4 if($4 == "" && s == host && ENVIRON["port"] != "70") s = s ":" ENVIRON["port"] if(substr($2, 1, 1) == "/") url[n] = "gopher://" s "/" type $2 else url[n] = "gopher://" s "/" type base $2 print t[type] display fn(n++) } } END{ if(n == 1) exit printf "References:\n" for(i = 1; i < n; i++) printf "%s%s\n", fn(i), url[i] } ' >>$n case text/html* if(~ $data hpost*) data = `{echo $data | awk '{print $3}'} htmlfmt -u $data -l $width incoming >>$n case * tr -d >$n } cat $n >/dev/text echo -n  >/dev/kbdin } if not{ if(~ $mime application/^(troff postscript pdf ghostscript)) port = image if not port = `{echo $mime | sed 's,/.*,,'} if(! test -r /mnt/plumb/$port || ! plumb -id $port /dev/kbdin k = '' while(~ $k ''){ echo -n 'write: ' k = `{read /dev/cons} if(! ~ $k /*){ echo 'must be an absolute path! (/dev/null is always there…)' k = '' } if not if(test -d $k){ echo $k is a directory! k = '' } if not if(test -f $k){ echo $k exists! 𝐨verwrite? >[3]/dev/consctl{ echo rawon >[1=3] if(! ~ `''{read -c 1 /dev/cons} o || ! echo -n >$k){ k = '' echo try again! } } } if not{ echo -n >$k if(! test -f $k) k = '' } } cp incoming $k echo written } } } rm -f incoming } fn gemget{ echo $data^ reply = `{read | tr -d } switch($reply(1)){ case 1* echo $reply(2-) echo -n  >/dev/kbdin echo -n input: $data^'?' >[1=3] >/dev/consctl{ echo holdon sed 's/ /%20/g' /dev/cons | urlencode | sed 's/%0A$//' >[1=3] } case 2* cat >incoming >[2]/dev/null echo $reply(2) | tr -d >[1=3] case 3* # REDIRECT echo redirect: $reply(2) | tr -d >[1=3] case * # ERRORS echo error: $reply(2-) >[1=3] } } ramfs -um /mnt/webshit cd /mnt/webshit echo -n /mnt/webshit >/dev/wdir echo -n webshit >/dev/label echo -n scroll >/dev/wctl n = 0 /dev/null{ read; read; read; read; read ndata = `{read} data = `''{read -c $ndata} }) switch($data){ case gemini://?* gopher://?* https://?* http://?* echo unhide >/dev/wctl >[2]/dev/null echo current >/dev/wctl echo fetching $data … proto = `{echo $data | sed 's,([^:]+).*,\1,'} host = `{echo $data | sed 's,[^:]+://([^:/]+).*,\1,'} port = `{echo $data | sed 's,[^:]+://[^:/]+:([0-9]+).*,\1,'} if(! ~ $port [0-9]*) port = $proto switch($proto){ case gemini if(~ $port gemini) port = 1965 mime = `{tlsclient tcp!$host!$port /bin/rc -c gemget >[3=1] >[2]/dev/null} switch($mime(1)){ case input: redirect: plumb $mime(2) case error: echo $mime case * format } case gopher if(~ $port gopher) port = 70 host = `{ndb/dnsgetip $host} item = `{echo $data | sed 's!^gopher://[^/]+/(.)/.*!\1!'} if(! ~ $item ?) item = 1 what = `{echo $data | sed 's!^gopher://[^/]+(/./|/)?(.*)!/\2!'} if(~ $item 7){ echo -n  >/dev/kbdin echo -n 'Enter search string: ' what = $what^' '^`$nl{read /dev/cons} } $con/ctl echo $what^ > $con/data cat $con/data }>incoming if(~ $item 1 7) mime = text/gopher if not mime = `{file -m incoming} format case http* <>/mnt/web/clone { d=/mnt/web/^`{sed 1q} echo -n url $data >[1=0] cp $d/body incoming data = `{cat $d/parsed/url} mime = `{cat $d/contenttype >[2]/dev/null} } if(~ $mime '' application/octet-stream) mime = `{file -m incoming >[2]/dev/null} format } case '[submit]' § □ ○ if(test -f $n){ data = `{read $n} if(~ $data(4) http*) hpost $data(4) if not if(~ $data(6) http*) hpost $data(6) } case hpost* eval $data >incoming mime = `{file -m incoming} echo unhide >/dev/wctl >[2]/dev/null echo current >/dev/wctl format case [⁰¹²³⁴⁵⁶⁷⁸⁹][⁰¹²³⁴⁵⁶⁷⁸⁹][⁰¹²³⁴⁵⁶⁷⁸⁹][⁰¹²³⁴⁵⁶⁷⁸⁹] [⁰¹²³⁴⁵⁶⁷⁸⁹][⁰¹²³⁴⁵⁶⁷⁸⁹][⁰¹²³⁴⁵⁶⁷⁸⁹] [⁰¹²³⁴⁵⁶⁷⁸⁹][⁰¹²³⁴⁵⁶⁷⁸⁹] [⁰¹²³⁴⁵⁶⁷⁸⁹] if(test -f $n) <$n awk ' BEGIN{while($0 != "References:") getline} /^'^$data^' /{ found = 1 if(match($2, "https?://")) system("plumb ''"$2"''") else print "bad footnote reference: "$0 exit } END{if(!found) print "no reference for footnote '^$data^'"} ' case ← jumpto `{echo $n 1-p | dc} case → jumpto `{echo $n 1+p | dc} case '{'*'}' jumpto `{echo $data | tr -dc 0-9} case * echo received bad plumb: $data }