access control with header for checknodes
This commit is contained in:
parent
736fc6b058
commit
02cc375133
|
|
@ -40,11 +40,11 @@ func sendEmailAbo(username string, alias string, deveui string, days_left int, l
|
|||
}
|
||||
mail_message := "To: " + username + `
|
||||
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
|
||||
|
||||
` + ablauftext + `Das Abo von "` + alias + `" (DevEUI: ` + deveui + `) laeuft in ` + strconv.Itoa(days_left) + ` Tagen ab.
|
||||
` + ablauftext + `
|
||||
|
||||
Bitte Abo verlaengern auf https://wo-bisch.ch
|
||||
|
||||
|
|
@ -117,6 +117,14 @@ func checkNodes() {
|
|||
}
|
||||
|
||||
func checkNodesHandler(w http.ResponseWriter, req *http.Request) {
|
||||
checkNodes()
|
||||
headers := req.Header
|
||||
|
||||
val, ok := headers["X-Checknodes"]
|
||||
if ok {
|
||||
fmt.Printf("X-Checknodes header is present with value %s\n", val)
|
||||
checkNodes()
|
||||
} else {
|
||||
fmt.Println("X-Checknodes header is not present")
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
|
@ -402,7 +403,7 @@ func CalcDaysUntil(mydate string) int {
|
|||
if err != nil {
|
||||
days = 0
|
||||
}
|
||||
days = int(t.Sub(time.Now()).Hours() / 24)
|
||||
days = int(math.Round((t.Sub(time.Now()).Hours() / 24) + 0.5))
|
||||
|
||||
return days
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue