-
Notifications
You must be signed in to change notification settings - Fork 8
/
plus.go
93 lines (87 loc) · 2.02 KB
/
plus.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package utils
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
// UGLY CODE , Pull Request is welcome
func Plus(filePath string) error {
var times sync.WaitGroup
var err error
var id string
var currentStep int = 1
ctx, cancel := context.WithCancel(context.Background())
if _, id, err = GetTokenID(filePath); err != nil {
panic(err)
}
go func() {
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
<-signalCh
cancel()
fmt.Println("\nWaiting for Response...")
go func() {
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
<-signalCh
fmt.Println()
os.Exit(1)
}()
times.Wait()
fmt.Println("Updating config file...")
UpdateConfigFile(filePath)
fmt.Println("Updated config file successfully")
os.Exit(0)
}()
for {
time.Sleep(500 * time.Millisecond)
times.Add(1)
select {
case <-ctx.Done():
times.Done()
default:
go func(index int) {
var publicKey string
currentStep++
if _, publicKey, err = GenerateKey(); err != nil {
panic(err)
}
installID := RandStringRunes(22, nil)
fcmtoken := RandStringRunes(134, nil)
payload := []byte(
`{
"key":"` + publicKey + `",
"install_id":"` + installID + `",
"fcm_token":"` + installID + `:APA91b` + fcmtoken + `",
"tos":"` + time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + `",
"model":"Android",
"referrer": "` + id + `",
"serial_number":"` + installID + `"
}`,
)
fmt.Println("Registering...", index, "times")
if _, err = request(payload, "", "", "register"); err != nil {
fmt.Println(err)
fmt.Println("Waiting for 30 seconds...")
select {
case <-ctx.Done():
return
default:
}
times.Done()
cancel()
time.Sleep(30 * time.Second)
currentStep--
ctx, cancel = context.WithCancel(context.Background())
} else {
times.Done()
fmt.Println(" Added", index, "GB")
}
}(currentStep)
}
}
}