diff --git a/.gitignore b/.gitignore index 580b408..a8dde60 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,10 @@ .history .ionide -# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode + +actor.pem +relay +config.yml +.conf_* +Caddyfile diff --git a/Caddyfile.tmpl b/Caddyfile.tmpl new file mode 100644 index 0000000..616fd6a --- /dev/null +++ b/Caddyfile.tmpl @@ -0,0 +1,16 @@ +__HOSTNAME__ { + root * __WEBROOT__ + file_server + encode gzip + # These paths are taken from api/api.go, and should be updated + # here if ever changed + reverse_proxy /.well-known/nodeinfo localhost:__APIPORT__ + reverse_proxy /.well-known/webfinger localhost:__APIPORT__ + reverse_proxy /nodeinfo/2.1 localhost:__APIPORT__ + reverse_proxy /actor localhost:__APIPORT__ + reverse_proxy /inbox localhost:__APIPORT__ + + php_fastcgi 127.0.0.1:9000 + +} + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..337a697 --- /dev/null +++ b/Makefile @@ -0,0 +1,80 @@ +SHELL=/bin/bash +VERS=$(shell git describe --tags HEAD) + +.PHONY: all +all: actor.pem config.yml relay Caddyfile + @echo Things and stuff + +.PHONY: setup +setup: genconf + +.PHONY: genconf +genconf: config.yml + +config.yml: .conf_redis .conf_domain .conf_desc config.yml.example | /var/lib/relay/actor.pem + @sed \ + -e 's/^REDIS_URL:.*/REDIS_URL: redis:\/\/$(shell cat .conf_redis):6379/' \ + -e 's/^RELAY_DOMAIN:.*/RELAY_DOMAIN: $(shell cat .conf_domain)/' \ + -e "s/^RELAY_SERVICENAME:.*/RELAY_SERVICENAME: $(shell cat .conf_desc)/" < config.yml.example > $@ + +.conf_redis: + @read -e -p "Redis host? [127.0.0.1] " r; \ + R=$$(echo $$r | tr '[:upper:]' '[:lower:]'); \ + if [ ! "$$R" ]; then \ + R="127.0.0.1"; \ + fi; echo "$$R" > $@ + +.conf_domain: + @read -e -p "Relay Domain? [relay.wig.gl] " r; \ + R=$$(echo $$r | tr '[:upper:]' '[:lower:]'); \ + if [ ! "$$R" ]; then \ + R="relay.wig.gl"; \ + fi; echo "$$R" > $@ + +.conf_desc: + @read -e -p "Description? [Honest Rob's Relay] " r; \ + R=$$(echo $$r | tr -d '"'); \ + if [ ! "$$R" ]; then \ + R="'Honest' Rob's Relay"; \ + fi; echo "$$R" > $@ + +WEBROOT = /var/lib/relay/webroot +APIPORT = $(shell awk -F: '/^RELAY_BIND:/ { print $$3 }' config.yml) +HOSTNAME = $(shell cat .conf_domain) + +.PHONY: caddyfile +caddyfile: /etc/caddy/Caddyfile + +/etc/caddy/Caddyfile: Caddyfile + @if [ ! -d /etc/caddy ]; then echo "/etc/caddy not present, can not continue"; exit 1; fi + @cp $< $@ && echo "Restarting caddy service" && systemctl restart caddy + +Caddyfile: Caddyfile.tmpl config.yml $(WEBROOT) + @sed -e 's!__WEBROOT__!$(WEBROOT)!' -e 's/__APIPORT__/$(APIPORT)/' -e 's/__HOSTNAME__/$(HOSTNAME)/' < Caddyfile.tmpl > $@ + +relay: $(wildcard **/*go) + go build -o $@ -ldflags "-X main.version=$(VERS)" . + +$(WEBROOT): + @mkdir -p $(WEBROOT) + @cp webroot/index.html $(WEBROOT)/index.html + @chown -R relay.relay $(WEBROOT) + +actor.pem: | /usr/bin/openssl + /usr/bin/openssl genrsa -traditional > $@ + chmod 600 $@ + +/var/lib/relay/actor.pem: actor.pem | /var/lib/relay + cp $< $@ + chown relay.relay $@ + chmod 600 $@ + +/var/lib/relay: + groupadd --system relay + useradd --system --gid relay --create-home --home-dir /var/lib/relay --shell /usr/sbin/nologin --comment "YUKIMOCHI Activity-Relay" relay + chmod 755 /var/lib/relay + passwd -l relay + +/usr/bin/openssl: + @echo "Can't continue - please install openssl" + @exit 1 diff --git a/api/handle.go b/api/handle.go index 5881f0f..15f3806 100644 --- a/api/handle.go +++ b/api/handle.go @@ -3,10 +3,11 @@ package api import ( "encoding/json" "errors" - uuid "github.com/satori/go.uuid" "net/http" "net/url" + uuid "github.com/satori/go.uuid" + "github.com/sirupsen/logrus" "github.com/yukimochi/Activity-Relay/models" "github.com/yukimochi/machinery-v1/v1/tasks" @@ -308,7 +309,8 @@ func handleInbox(writer http.ResponseWriter, request *http.Request, activityDeco } } default: + writer.Header().Add("Content-Type", "text/plain") writer.WriteHeader(404) - writer.Write(nil) + writer.Write([]byte("This interface is not for humans, please add this URL as a relay")) } } diff --git a/config.yml.example b/config.yml.example index 44b1470..30772a7 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,11 +1,11 @@ ACTOR_PEM: /var/lib/relay/actor.pem REDIS_URL: redis://redis:6379 -RELAY_BIND: 0.0.0.0:8080 +RELAY_BIND: 127.0.0.1:8080 RELAY_DOMAIN: relay.toot.yukimochi.jp RELAY_SERVICENAME: YUKIMOCHI Toot Relay Service JOB_CONCURRENCY: 50 -# RELAY_SUMMARY: | +RELAY_SUMMARY: Taken from https://github.com/yukimochi/Activity-Relay # RELAY_ICON: https:// # RELAY_IMAGE: https:// diff --git a/webroot/index.html b/webroot/index.html new file mode 100644 index 0000000..2ce69a7 --- /dev/null +++ b/webroot/index.html @@ -0,0 +1,25 @@ + + + + + + YUKIMOCHI Activity-Relay + + + +
+
+
+

YUKIMOCHI Activity-Relay

+
+
+
+
+

This is an unconfigured instance. These files are located in /var/lib/relay/webroot

+
+
+
+ + + +