access control with header for checknodes

This commit is contained in:
Joerg Lehmann 2022-07-14 20:20:34 +02:00
parent 736fc6b058
commit 02cc375133
2 changed files with 13 additions and 4 deletions

View File

@ -40,11 +40,11 @@ func sendEmailAbo(username string, alias string, deveui string, days_left int, l
} }
mail_message := "To: " + username + ` mail_message := "To: " + username + `
From: info@wo-bisch.ch From: info@wo-bisch.ch
Subject: ` + level + ` - wo-bisch.ch: Abo laeuft ab (` + alias + `) Subject: ` + level + ` - wo-bisch.ch: Abo verlaengern (` + alias + `)
Lieber Benutzer von wo-bisch.ch Lieber Benutzer von wo-bisch.ch
` + ablauftext + `Das Abo von "` + alias + `" (DevEUI: ` + deveui + `) laeuft in ` + strconv.Itoa(days_left) + ` Tagen ab. ` + ablauftext + `
Bitte Abo verlaengern auf https://wo-bisch.ch Bitte Abo verlaengern auf https://wo-bisch.ch
@ -117,6 +117,14 @@ func checkNodes() {
} }
func checkNodesHandler(w http.ResponseWriter, req *http.Request) { func checkNodesHandler(w http.ResponseWriter, req *http.Request) {
headers := req.Header
val, ok := headers["X-Checknodes"]
if ok {
fmt.Printf("X-Checknodes header is present with value %s\n", val)
checkNodes() checkNodes()
} else {
fmt.Println("X-Checknodes header is not present")
}
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }

View File

@ -7,6 +7,7 @@ import (
"html/template" "html/template"
"io/ioutil" "io/ioutil"
"log" "log"
"math"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@ -402,7 +403,7 @@ func CalcDaysUntil(mydate string) int {
if err != nil { if err != nil {
days = 0 days = 0
} }
days = int(t.Sub(time.Now()).Hours() / 24) days = int(math.Round((t.Sub(time.Now()).Hours() / 24) + 0.5))
return days return days
} }