From c80e4036fbac53039b607c4bb8a5489d016a009f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 22 Jan 2016 15:28:56 -0500 Subject: initial commit --- .gitignore | 4 ++++ Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ httpconnectd.sh | 30 ++++++++++++++++++++++++++++++ httpconnectd.socket | 11 +++++++++++ httpconnectd@.service.in | 13 +++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 httpconnectd.sh create mode 100644 httpconnectd.socket create mode 100644 httpconnectd@.service.in 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 -- cgit v1.2.3