| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "fmt" |
| 6 | "io" |
| 7 | "net/http" |
| 8 | "os" |
| 9 | "regexp" |
| 10 | "runtime" |
| 11 | "strings" |
| 12 | "time" |
| 13 | ) |
| 14 | |
| 15 | var stableVersion = regexp.MustCompile(`^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$`) |
| 16 | |
| 17 | func main() { |
| 18 | if len(os.Args) < 2 { |
| 19 | fmt.Fprintln(os.Stderr, "usage: inspect-cloudflare-download-access.go VERSION...") |
| 20 | os.Exit(2) |
| 21 | } |
| 22 | client := &http.Client{Timeout: 30 * time.Second} |
| 23 | for _, version := range os.Args[1:] { |
| 24 | if !stableVersion.MatchString(version) { |
| 25 | fmt.Fprintln(os.Stderr, "invalid Stable version") |
| 26 | os.Exit(2) |
| 27 | } |
| 28 | request, err := http.NewRequest(http.MethodGet, "https://dl.reasonix.io/latest/latest.json", nil) |
| 29 | if err != nil { |
| 30 | panic(err) |
| 31 | } |
| 32 | request.Header.Set("User-Agent", fmt.Sprintf("Reasonix-Updater/v%s (%s/%s; build=stable; update=stable)", version, runtime.GOOS, runtime.GOARCH)) |
| 33 | response, err := client.Do(request) |
| 34 | if err != nil { |
| 35 | panic(err) |
| 36 | } |
| 37 | result := map[string]any{ |
| 38 | "kind": "go-updater-manifest", "version": version, |
| 39 | "status": response.StatusCode, "mitigation": response.Header.Get("cf-mitigated"), |
| 40 | "ray": response.Header.Get("cf-ray"), "contentType": response.Header.Get("content-type"), |
| 41 | } |
| 42 | response.Body.Close() |
| 43 | if err := json.NewEncoder(os.Stdout).Encode(result); err != nil { |
| 44 | panic(err) |
| 45 | } |
| 46 | } |
| 47 | for _, target := range []struct{ kind, url string }{ |
| 48 | {"homepage", "https://reasonix.io/?download=desktop&release-postflight=v1.38.12"}, |
| 49 | {"changelog", "https://reasonix.io/changelog/v1.38.12/"}, |
| 50 | } { |
| 51 | for _, profile := range []struct{ kind, userAgent string }{ |
| 52 | {"updater", fmt.Sprintf("Reasonix-Updater/v1.38.12 (%s/%s; build=stable; update=stable)", runtime.GOOS, runtime.GOARCH)}, |
| 53 | {"browser", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"}, |
| 54 | } { |
| 55 | request, err := http.NewRequest(http.MethodGet, target.url, nil) |
| 56 | if err != nil { |
| 57 | panic(err) |
| 58 | } |
| 59 | request.Header.Set("User-Agent", profile.userAgent) |
| 60 | response, err := client.Do(request) |
| 61 | if err != nil { |
| 62 | panic(err) |
| 63 | } |
| 64 | body, err := io.ReadAll(io.LimitReader(response.Body, 2<<20)) |
| 65 | response.Body.Close() |
| 66 | if err != nil { |
| 67 | panic(err) |
| 68 | } |
| 69 | result := map[string]any{ |
| 70 | "kind": "go-site-" + target.kind, "profile": profile.kind, |
| 71 | "status": response.StatusCode, "mitigation": response.Header.Get("cf-mitigated"), |
| 72 | "contentType": response.Header.Get("content-type"), |
| 73 | "hasVersion": strings.Contains(string(body), "v1.38.12"), |
| 74 | "hasDesktopAsset": strings.Contains(string(body), "data-desktop-asset="), |
| 75 | } |
| 76 | if err := json.NewEncoder(os.Stdout).Encode(result); err != nil { |
| 77 | panic(err) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 |