summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-01-22 15:28:56 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-01-22 15:28:56 -0500
commitc80e4036fbac53039b607c4bb8a5489d016a009f (patch)
tree71890b78ecfa239b2f3e272b501f63c87ab3ec32
initial commit
-rw-r--r--.gitignore4
-rw-r--r--Makefile43
-rw-r--r--httpconnectd.sh30
-rw-r--r--httpconnectd.socket11
-rw-r--r--httpconnectd@.service.in13
5 files changed, 101 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e00d49d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+httpconnectd@.service
+httpconnectd
+.var.*
+.tmp.*
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5f50812
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# Copyright 2016 Luke Shumaker
+# License: WTFPLv2
+
+prefix = /usr/local
+bindir = $(prefix)/bin
+systemddir = $(prefix)/lib/systemd/system
+DESTDIR =
+Q = @
+
+########################################################################
+
+MAKEFLAGS += -r
+vars = $(patsubst .var.%,%,$(filter .var.%,$^))
+build_targets = httpconnectd httpconnectd@.service httpconnectd.socket
+install_targets = $(DESTDIR)$(bindir)/httpconnectd $(DESTDIR)$(systemddir)/httpconnectd@.service $(DESTDIR)$(systemddir)/httpconnectd.socket
+
+all: $(build_targets)
+install: $(install_targets)
+clean:
+ rm -f -- httpconnectd httpconnectd@.service
+uninstall:
+ rm -f -- $(install_targets)
+ rmdir -p -- $(dir $(install_targets))
+.PHONY: all install clean uninstall
+
+%: %.sh
+ install -m755 $< $@
+
+%: %.in
+ $(if $(Q),$(Q)echo 'EDIT < $< > $@';)$(if $(vars),sed $(foreach v,$(vars), -e 's|$(v)|$($(v))|g' ),cat) < $< > $@
+
+$(DESTDIR)$(bindir)/%: %
+ install -Dm755 $< $@
+$(DESTDIR)$(systemddir)/%: %
+ install -Dm644 $< $@
+
+.var.%: FORCE
+ $(Q)printf '%s' '$($*)' > .tmp$@ && { cmp -s .tmp$@ $@ && rm -f -- .tmp$@ || mv -Tf .tmp$@ $@; } || { rm -f -- .tmp$@; false; }
+
+.DELETE_ON_ERROR:
+.SECONDARY:
+.PHONY: FORCE
diff --git a/httpconnectd.sh b/httpconnectd.sh
new file mode 100644
index 0000000..ff22d13
--- /dev/null
+++ b/httpconnectd.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+# Copyright 2016 Luke Shumaker
+# License: WTFPLv2
+
+# Dependencies:
+# - bash
+# - socat
+# - date -R
+
+server='httpconnectd'
+
+MethodNotAllowed() {
+ printf '%\r\n' \
+ 'HTTP/1.1 405 Method Not Allowed' \
+ "Server: $server" \
+ "Date: $(date -R)" \
+ 'Allow: CONNECT' \
+ ''
+ exit 0
+}
+
+worker() {
+ read -r method dest version
+ if [[ "$method" != CONNECT ]]; then
+ MethodNotAllowed
+ fi
+ exec socat STDIO TCP-CONNECT:"$dest"
+}
+
+worker "$@"
diff --git a/httpconnectd.socket b/httpconnectd.socket
new file mode 100644
index 0000000..c270b12
--- /dev/null
+++ b/httpconnectd.socket
@@ -0,0 +1,11 @@
+# Copyright 2016 Luke Shumaker
+# License: WTFPLv2
+[Unit]
+Description=A simple HTTP server that only implements the CONNECT method
+
+[Socket]
+ListenStream=8080
+Accept=true
+
+[Install]
+WantedBy=sockets.target
diff --git a/httpconnectd@.service.in b/httpconnectd@.service.in
new file mode 100644
index 0000000..8934abf
--- /dev/null
+++ b/httpconnectd@.service.in
@@ -0,0 +1,13 @@
+# Copyright 2016 Luke Shumaker
+# License: WTFPLv2
+[Unit]
+Description=An HTTP CONNECT connection
+After=network.target
+
+[Service]
+ExecStart=-@bindir@/httpconnectserver
+StandardInput=socket
+StandardOutput=inherit
+StandardError=journal
+User=nobody
+Group=nobody