forked from cj123/canijailbreak.com
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jailbreak.go
61 lines (44 loc) · 1.1 KB
/
jailbreak.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/cj123/canijailbreak.com/model"
)
func validate(j *model.JailbreakJSON) error {
for _, jailbreak := range j.Jailbreaks {
if jailbreak.URL == "" {
continue
}
log.Printf("Testing url: %s for jailbreak %s %s\n", jailbreak.URL, jailbreak.Name, jailbreak.Version)
res, err := http.Get(jailbreak.URL)
if err != nil {
return err
}
if res.StatusCode >= 400 {
return fmt.Errorf("URL: %s for jailbreak %s (iOS %s) is not valid (status code: %d)", jailbreak.URL, jailbreak.Name, jailbreak.Firmwares.Start, res.StatusCode)
}
res.Body.Close()
}
return nil
}
func marshalToFile(j *model.JailbreakJSON, filename string) error {
out, err := json.Marshal(j)
if err != nil {
return err
}
return ioutil.WriteFile(filename, out, 0644)
}
func getJailbreaks(filename string) (jb *model.JailbreakJSON, err error) {
jailbreakFile, err := os.Open(filename)
d := json.NewDecoder(jailbreakFile)
jb = &model.JailbreakJSON{}
err = d.Decode(&jb)
if err != nil {
return nil, err
}
return jb, err
}