shithub: webbox

Download patch

ref: 00f4565d29766400b04fe6322c912c8fc58d8796
author: sirjofri <sirjofri@sirjofri.de>
date: Sat Jun 15 15:34:36 EDT 2024

adds files

--- /dev/null
+++ b/README
@@ -1,0 +1,19 @@
+DEPENDENCIES
+
+- tcp80 with lots of support (tested with https://shithub.us/grobe0ba/tcp80/HEAD/info.html )
+
+
+SETUP
+
+- mk install
+
+
+RUN
+
+On your local machine:
+
+- webbox 8080 /
+- webbox 8081 /usr/$user
+
+- $1 = port number
+- $2 = folder to expose
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,13 @@
+</$objtype/mkfile
+
+BIN=/$objtype/bin
+TARG=urldecode
+OFILES=urldecode.$O
+RCFILES=webbox
+
+</sys/src/cmd/mkone
+
+install: ${RCFILES:%=/rc/bin/%}
+
+/rc/bin/%: %
+	cp $stem $target
--- /dev/null
+++ b/urldecode.c
@@ -1,0 +1,81 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+char
+lookup(char c)
+{
+	if (c >= '0' && c <= '9')
+		return c - '0';
+	
+	switch (c) {
+		case 'a':
+		case 'A':
+			return 0x0a;
+		case 'b':
+		case 'B':
+			return 0x0b;
+		case 'c':
+		case 'C':
+			return 0x0c;
+		case 'd':
+		case 'D':
+			return 0x0d;
+		case 'e':
+		case 'E':
+			return 0x0e;
+		case 'f':
+		case 'F':
+			return 0x0f;
+	}
+	fprint(2, "error\n");
+	return 0;
+}
+
+char
+interpret(char a, char b)
+{
+	return (lookup(a) << 4) | lookup(b);
+}
+
+void
+printdec(char *s)
+{
+	char *o, *i, *j;
+	int n = strlen(s);
+	
+	o = mallocz(n+1, 1);
+	if (!o)
+		sysfatal("%r");
+	
+	for (i = s, j = o; *i; i++, j++) {
+		if (*i == '+') {
+			*j = ' ';
+			continue;
+		}
+		if (*i != '%') {
+			*j = *i;
+			continue;
+		}
+		*j = interpret(*(++i), *(++i));
+	}
+	
+	print("%s", o);
+	free(o);
+}
+
+void
+main(int argc, char **argv)
+{
+	Biobuf *b;
+	char *s;
+	USED(argc, argv);
+	
+	b = Bfdopen(0, OREAD);
+	if (!b)
+		sysfatal("%r");
+	
+	while (s = Brdstr(b, '\n', 1)) {
+		printdec(s);
+	}
+}
--- /dev/null
+++ b/webbox
@@ -1,0 +1,90 @@
+#!/bin/rc
+
+rfork en
+
+test -x /bin/urldecode || {
+	echo missing urldecode >[1=2]
+	exit 'missing urldecode'
+}
+
+test -x /bin/tcp80 || {
+	echo missing tcp80 >[1=2]
+	exit 'missing tcp80'
+}
+
+port=8080
+~ $1 '' || port=$1
+folder=/
+~ $2 '' || test -d $2 && folder=$2
+
+webbox=/n/webbox
+
+fn bootstrap{
+header='
+<html><head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<style type="text/css">
+body {
+	font-family: sans-serif;
+	max-width: 960px;
+	margin: auto;
+	padding: 10px;
+}
+</style>
+<title>Webbox</title>
+</head>
+<body>
+<h1><a href="/">Webbox</a></h1>
+'
+cat <<! >$webbox/namespace.httpd
+# empty
+!
+bind $webbox/namespace.httpd /lib/namespace.httpd
+
+cat <<! >$webbox/rules
+/dosnarf.html\?d=(.*)	$webbox/bin/snarf	'\1'
+!
+
+cat <<! >$webbox/bin/snarf
+#!/bin/rc
+echo -n $$1 | urldecode >/dev/snarf
+echo '$header'
+echo '<a href="/snarf.html">Back to snarf</a></body></html>'
+!
+
+cat <<! >$webbox/web/snarf.html
+$header
+<h2>Snarf</h2>
+<form action="/dosnarf.html" method="GET">
+<input type="text" name="d" id="d"><br>
+<input type="submit" value="snarf">
+</form></body></html>
+!
+
+cat <<! >$webbox/web/index.html
+$header
+<h2>Home</h2>
+<ul>
+<li><a href="/files/">files</a></li>
+<li><a href="/snarf.html">snarf</a></li>
+</ul>
+</body>
+</html>
+!
+
+chmod +x $webbox/bin/*
+}
+
+ramfs -m $webbox
+mkdir -p $webbox/bin
+mkdir -p $webbox/web/files
+mkdir -p $webbox/in
+
+bind $folder $webbox/web/files
+bind $webbox/web /usr/web
+
+bootstrap
+
+echo starting listener on 'tcp!*!'$port
+aux/listen1 -t 'tcp!*!'$port /bin/tcp80 -r $webbox/rules