forked from ordinary-dev/mta-sts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (41 loc) · 973 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"io"
"log"
"net/http"
"os"
"strings"
)
func getVar(key string, fallback string) string {
value := os.Getenv(key)
if value == "" {
value = fallback
}
return value
}
func getMtaSts(w http.ResponseWriter, r *http.Request) {
// Headers
w.Header().Set("Content-Type", "text/plain")
// STS Version
io.WriteString(w, "version: STSv1\n")
// Mode
mode := getVar("MTA_STS_MODE", "enforce")
io.WriteString(w, "mode: "+mode+"\n")
// Max age
maxAge := getVar("MTA_STS_MAX_AGE", "604800")
io.WriteString(w, "max_age: "+maxAge+"\n")
// MX servers
mxServers := strings.Split(getVar("MTA_STS_MX", "mx.change.me"), ",")
for _, server := range mxServers {
io.WriteString(w, "mx: "+server+"\n")
}
}
func main() {
port := getVar("PORT", "8080")
log.Println("Starting server at localhost:" + port)
http.HandleFunc("/.well-known/mta-sts.txt", getMtaSts)
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatal(err)
}
}