diff --git a/Makefile b/Makefile index fb6bd33..8a3ce5a 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ DIST_DIR ?= dist/ GOOS ?= linux ARCH ?= $(shell uname -m) BUILDINFOSDET ?= +GOARCH = $(shell echo $(ARCH) | sed 's/x86_64/amd64/g') SOFT_NAME := epee_service SOFT_VERSION := $(shell git describe --tags $(git rev-list --tags --max-count=1)) @@ -13,7 +14,7 @@ URL := https://git.gnous.eu/enpls/epee-service DESCRIPTION := EnPLS Epee (Enpls Proxy EnginE) Utility Service BUILDINFOS := ($(shell date +%FT%T%z)$(BUILDINFOSDET)) LDFLAGS := '-X main.version=$(SOFT_VERSION) -X main.buildinfos=$(BUILDINFOS)' - +GOARCH := amd64 OUTPUT_SOFT := $(DIST_DIR)epee-$(SOFT_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION) .PHONY: vet @@ -34,7 +35,8 @@ clean: .PHONY: build build: prepare - go build -ldflags $(LDFLAGS) -o $(OUTPUT_SOFT) + @echo Building binary for $(GOOS)/$(GOARCH) + env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags $(LDFLAGS) -o $(OUTPUT_SOFT) .PHONY: package-deb package-deb: prepare @@ -44,10 +46,8 @@ package-deb: prepare --architecture $(ARCH) \ --license "$(LICENSE)" \ --package $(DIST_DIR) \ - $(OUTPUT_SOFT)=/usr/bin/frite-web \ - extra/links.txt.example=/etc/frite/links.txt \ - extra/frite-web.service=/usr/lib/systemd/system/frite-web.service - + $(OUTPUT_SOFT)=/usr/bin/epee-service \ + extra/epee.service=/usr/lib/systemd/system/epee.service .PHONY: package-rpm package-rpm: prepare fpm -s dir -t rpm -n $(SOFT_NAME) -v $(VERSION_PKG) \ @@ -56,6 +56,5 @@ package-rpm: prepare --architecture $(ARCH) \ --license "$(LICENSE) "\ --package $(DIST_DIR) \ - $(OUTPUT_SOFT)=/usr/bin/frite-web \ - extra/links.txt.example=/etc/frite/links.txt \ - extra/frite-web.service=/usr/lib/systemd/system/frite-web.service \ No newline at end of file + $(OUTPUT_SOFT)=/usr/bin/epee-service \ + extra/epee.service=/usr/lib/systemd/system/epee.service \ No newline at end of file diff --git a/extra/epee.service b/extra/epee.service new file mode 100644 index 0000000..d9ea020 --- /dev/null +++ b/extra/epee.service @@ -0,0 +1,32 @@ +[Unit] +Description=Enpls Proxy EnginE Utility Service +After=network.target + +[Service] +Type=simple +; User=epee +; Group=epee +WorkingDirectory=/etc/epee/ +ExecStart=/usr/bin/epee-service + +NoNewPrivileges=yes +ProtectSystem=strict +ProtectHome=true +RestrictNamespaces=true +PrivateTmp=true +PrivateDevices=true +ProtectClock=true +ProtectControlGroups=true +ProtectKernelTunables=true +ProtectKernelLogs=true +ProtectKernelModules=true +LockPersonality=true +RestrictSUIDSGID=true +RemoveIPC=true +RestrictRealtime=true +SystemCallFilter=@system-service +SystemCallArchitectures=native +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/go.mod b/go.mod index 6cdbb29..b814594 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module git.gnous.eu/enpls/epee-service go 1.19 + +require ( + github.com/sirupsen/logrus v1.9.0 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..64cb7ad --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/logging.go b/logging.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/logging.go @@ -0,0 +1 @@ +package main diff --git a/main.go b/main.go index d7b9a0c..b957656 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,9 @@ import ( "encoding/json" "fmt" "html/template" - "log" "net/http" + + log "github.com/sirupsen/logrus" ) //go:embed static @@ -24,10 +25,14 @@ type Error struct { func main() { port := "5900" - http.Handle("/static/", http.FileServer(http.FS(staticFS))) + http.Handle("/cdn-cgi/static/", http.StripPrefix("/cdn-cgi/", http.FileServer(http.FS(staticFS)))) + http.HandleFunc("/cdn-cgi/trace", headersHandler) http.HandleFunc("/", errorHandler) - log.Printf("Listening on :%s...", port) + log.WithFields(log.Fields{ + "port": port, + }).Info("Started webserver listening") + err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil) if err != nil { log.Fatal(err) @@ -51,8 +56,8 @@ func errorHandler(w http.ResponseWriter, r *http.Request) { } errorData := errors[errorCode] if errorData.Title == "" { - errorData.Title = "Error" - errorData.Message = "An error occurred." + errorData.Title = "Oops 🤓" + errorData.Message = "It seems like something went wrong. Please try again later." } // Render error page @@ -75,3 +80,11 @@ func generateInternalServerError(w http.ResponseWriter, err error) { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(`{"error": "Internal Server Error"}`)) } + +func headersHandler(w http.ResponseWriter, r *http.Request) { + for name, headers := range r.Header { + for _, h := range headers { + fmt.Fprintf(w, "%v: %v\n", name, h) + } + } +} diff --git a/templates/error.html b/templates/error.html index d6c0390..d00be50 100644 --- a/templates/error.html +++ b/templates/error.html @@ -6,7 +6,7 @@ {{.Title}} - + @@ -21,9 +21,12 @@ href="mailto:mael@enpls.org">contact us. + \ No newline at end of file