-
Notifications
You must be signed in to change notification settings - Fork 10
/
plus.go
125 lines (118 loc) · 2.73 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package utils
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
// UGLY CODE , Pull Request is welcome
func Plus(filePath string, test bool) error {
var times sync.WaitGroup
var err error
var id string
var currentStep int = 1
ctx, cancel := context.WithCancel(context.Background())
if fileType, err := GetFileType(filePath); fileType == "json" && err == nil {
if _, id, err = GetTokenID(filePath); err != nil {
panic(err)
}
} else {
if _, id, err = IniGetTokenID(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.Printf("Total added %d GB\n", currentStep)
fmt.Println("Updating config file...")
if fileType, err := GetFileType(filePath); fileType == "json" && err == nil {
UpdateConfigFile(filePath)
} else {
UpdateIniConfig(filePath)
}
fmt.Println("Updated config file successfully")
os.Exit(0)
}()
go func() {
for {
time.Sleep(100 * time.Millisecond)
if i := currentStep % 10; i == 0 {
if fileType, err := GetFileType(filePath); fileType == "json" && err == nil {
UpdateConfigFile(filePath)
} else {
UpdateIniConfig(filePath)
}
}
}
}()
for {
time.Sleep(500 * time.Millisecond)
times.Add(1)
if test {
select {
case <-ctx.Done():
times.Done()
return nil
default:
}
}
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 {
times.Done()
fmt.Println(err)
fmt.Println("Waiting for 30 seconds...")
select {
case <-ctx.Done():
return
default:
}
cancel()
time.Sleep(30 * time.Second)
currentStep--
ctx, cancel = context.WithCancel(context.Background())
} else {
times.Done()
fmt.Println(" Added", index, "GB")
}
}(currentStep)
}
}
}