Fix footer date year & error path

This commit is contained in:
Mael G. 2023-03-21 16:22:45 +01:00
parent 859e144797
commit 502a87a551
7 changed files with 80 additions and 16 deletions

View file

@ -3,6 +3,7 @@ DIST_DIR ?= dist/
GOOS ?= linux GOOS ?= linux
ARCH ?= $(shell uname -m) ARCH ?= $(shell uname -m)
BUILDINFOSDET ?= BUILDINFOSDET ?=
GOARCH = $(shell echo $(ARCH) | sed 's/x86_64/amd64/g')
SOFT_NAME := epee_service SOFT_NAME := epee_service
SOFT_VERSION := $(shell git describe --tags $(git rev-list --tags --max-count=1)) 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 DESCRIPTION := EnPLS Epee (Enpls Proxy EnginE) Utility Service
BUILDINFOS := ($(shell date +%FT%T%z)$(BUILDINFOSDET)) BUILDINFOS := ($(shell date +%FT%T%z)$(BUILDINFOSDET))
LDFLAGS := '-X main.version=$(SOFT_VERSION) -X main.buildinfos=$(BUILDINFOS)' LDFLAGS := '-X main.version=$(SOFT_VERSION) -X main.buildinfos=$(BUILDINFOS)'
GOARCH := amd64
OUTPUT_SOFT := $(DIST_DIR)epee-$(SOFT_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION) OUTPUT_SOFT := $(DIST_DIR)epee-$(SOFT_VERSION)-$(GOOS)-$(ARCH)$(EXTENSION)
.PHONY: vet .PHONY: vet
@ -34,7 +35,8 @@ clean:
.PHONY: build .PHONY: build
build: prepare 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 .PHONY: package-deb
package-deb: prepare package-deb: prepare
@ -44,10 +46,8 @@ package-deb: prepare
--architecture $(ARCH) \ --architecture $(ARCH) \
--license "$(LICENSE)" \ --license "$(LICENSE)" \
--package $(DIST_DIR) \ --package $(DIST_DIR) \
$(OUTPUT_SOFT)=/usr/bin/frite-web \ $(OUTPUT_SOFT)=/usr/bin/epee-service \
extra/links.txt.example=/etc/frite/links.txt \ extra/epee.service=/usr/lib/systemd/system/epee.service
extra/frite-web.service=/usr/lib/systemd/system/frite-web.service
.PHONY: package-rpm .PHONY: package-rpm
package-rpm: prepare package-rpm: prepare
fpm -s dir -t rpm -n $(SOFT_NAME) -v $(VERSION_PKG) \ fpm -s dir -t rpm -n $(SOFT_NAME) -v $(VERSION_PKG) \
@ -56,6 +56,5 @@ package-rpm: prepare
--architecture $(ARCH) \ --architecture $(ARCH) \
--license "$(LICENSE) "\ --license "$(LICENSE) "\
--package $(DIST_DIR) \ --package $(DIST_DIR) \
$(OUTPUT_SOFT)=/usr/bin/frite-web \ $(OUTPUT_SOFT)=/usr/bin/epee-service \
extra/links.txt.example=/etc/frite/links.txt \ extra/epee.service=/usr/lib/systemd/system/epee.service
extra/frite-web.service=/usr/lib/systemd/system/frite-web.service

32
extra/epee.service Normal file
View file

@ -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

5
go.mod
View file

@ -1,3 +1,8 @@
module git.gnous.eu/enpls/epee-service module git.gnous.eu/enpls/epee-service
go 1.19 go 1.19
require (
github.com/sirupsen/logrus v1.9.0 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)

11
go.sum Normal file
View file

@ -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=

1
logging.go Normal file
View file

@ -0,0 +1 @@
package main

23
main.go
View file

@ -5,8 +5,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"log"
"net/http" "net/http"
log "github.com/sirupsen/logrus"
) )
//go:embed static //go:embed static
@ -24,10 +25,14 @@ type Error struct {
func main() { func main() {
port := "5900" 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) 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) err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -51,8 +56,8 @@ func errorHandler(w http.ResponseWriter, r *http.Request) {
} }
errorData := errors[errorCode] errorData := errors[errorCode]
if errorData.Title == "" { if errorData.Title == "" {
errorData.Title = "Error" errorData.Title = "Oops 🤓"
errorData.Message = "An error occurred." errorData.Message = "It seems like something went wrong. Please try again later."
} }
// Render error page // Render error page
@ -75,3 +80,11 @@ func generateInternalServerError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(`{"error": "Internal Server Error"}`)) 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)
}
}
}

View file

@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Title}}</title> <title>{{.Title}}</title>
<link rel="stylesheet" href="/static/main.css"> <link rel="stylesheet" href="/cdn-cgi/static/main.css">
</head> </head>
<body> <body>
@ -21,9 +21,12 @@
href="mailto:mael@enpls.org">contact us</a>. href="mailto:mael@enpls.org">contact us</a>.
</div> </div>
<div class="footer"> <div class="footer">
<p>&copy; Copyright {{.Year}} EnPLS Network - <a href="https://enpls.org">enpls.org</a> </p> <p>&copy; Copyright <span id="year"></span> EnPLS Network - <a href="https://enpls.org">enpls.org</a> </p>
</div> </div>
</div> </div>
<script type="text/javascript">
document.getElementById("year").innerHTML = new Date().getFullYear();
</script>
</body> </body>
</html> </html>