added pledge and unveil
This commit is contained in:
parent
21c0d33b5c
commit
4bb7dd054e
330 changed files with 195092 additions and 3 deletions
30
main.go
30
main.go
|
|
@ -15,6 +15,8 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -22,6 +24,15 @@ var (
|
|||
listen string
|
||||
)
|
||||
|
||||
const bfsURL = "https://uvi.bfs.de/Tagesgrafiken"
|
||||
|
||||
var allowedFiles = []string{
|
||||
"/etc/resolv.conf",
|
||||
"/etc/localtime",
|
||||
"/etc/hosts",
|
||||
"/etc/ssl/cert.pem",
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.StringVar(&listen, "l", ":7878", "listen addr")
|
||||
flag.Parse()
|
||||
|
|
@ -29,9 +40,20 @@ func main() {
|
|||
if len(cityList) != len(fileList) {
|
||||
fatal(errors.New("city and file list length differ"))
|
||||
}
|
||||
if err := godrop.PledgePromises("stdio inet rpath unveil"); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
for _, file := range allowedFiles {
|
||||
if err := godrop.Unveil(file, "r"); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
}
|
||||
if err := godrop.UnveilBlock(); err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
ic := &ImageCrawler{
|
||||
url: "https://uvi.bfs.de/Tagesgrafiken",
|
||||
url: bfsURL,
|
||||
c: &http.Client{},
|
||||
m: make(map[int]*Image),
|
||||
}
|
||||
|
|
@ -76,12 +98,14 @@ func main() {
|
|||
return
|
||||
}
|
||||
last := vals[len(vals)-1]
|
||||
imgURL := bfsURL + "/" + fileList[num]
|
||||
fmt.Fprintf(w, indexPage,
|
||||
getColor(last),
|
||||
fmt.Sprintf("%.2f", last),
|
||||
mod.Format(time.RFC1123),
|
||||
time.Now().Format(time.RFC1123),
|
||||
location,
|
||||
imgURL,
|
||||
version,
|
||||
)
|
||||
})
|
||||
|
|
@ -497,7 +521,6 @@ func generateLocPage() string {
|
|||
}
|
||||
|
||||
var locPage = generateLocPage()
|
||||
|
||||
var indexPage = `<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -515,7 +538,8 @@ a, a:link, a:visited {
|
|||
<h1 style="font-size:15em;color:#%s;">%s</h1>
|
||||
<h5 style="font-size:2em;">Updated: %s</h5>
|
||||
<h5 style="font-size:2em;">Server: %s</h5>
|
||||
<h5 style="font-size:2em;"><a href="/set">Location</a>: %s</h5>
|
||||
<h5 style="font-size:2em;"><a href="/set">Change Location</a>: %s</h5>
|
||||
<h5 style="font-size:2em;"><a href="%s" rel="nofollow noreferrer noopener" target="_blank">View Image</a></h5>
|
||||
<footer>UV data copyright belongs to <a href="https://www.bfs.de/DE/themen/opt/uv/uv-index/aktuelle-tagesverlaeufe/aktuell_node.html" rel="nofollow noreferrer noopener" target="_blank">Bundesamt für Strahlenschutz</a><br>
|
||||
Use this service at your own risk.<br>
|
||||
I take no responsibility for missing or incorrect data.<br>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue