-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (66 loc) · 1.54 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"golang.org/x/crypto/acme/autocert"
)
func main() {
http.HandleFunc("/upload", uploadUDID)
http.HandleFunc("/", rootHandler)
m_ := &autocert.Manager{
Cache: autocert.DirCache("./certificates"),
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(
"subdomain.domain.tld",
),
}
go http.ListenAndServe(":http", m_.HTTPHandler(nil))
s_ := &http.Server{
Addr: ":https",
TLSConfig: &tls.Config{
GetCertificate: m_.GetCertificate,
},
}
s_.ListenAndServeTLS("", "")
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
downloadUDID(w, r)
return
}
w.Write([]byte(r.URL.Path[1:]))
}
func downloadUDID(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/x-apple-aspen-config")
w.Header().Set("Content-Disposition", "attachment; filename=\"udid.mobileconfig\"")
file_, err := os.Open("./udid.mobileconfig")
if err != nil {
log.Printf("failed to send .mobileconfig: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
io.Copy(w, file_)
}
func uploadUDID(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("failed to read uploaded UDID: %v", err)
w.WriteHeader(http.StatusBadRequest)
return
}
http.Redirect(
w,
r,
fmt.Sprintf(
"/%s",
string(data)[strings.Index(string(data), "<string>")+8:strings.Index(string(data), "</string>")],
),
http.StatusMovedPermanently,
)
}