-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocap.go
159 lines (148 loc) · 3.35 KB
/
procap.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package procapgo
import (
"bytes"
"encoding/json"
"errors"
"io"
"net/http"
"strings"
"time"
)
type Task struct {
Id string `json:"ID"`
Time int `json:"Time"`
Message string `json:"Message"`
Success bool `json:"Success"`
Results struct {
Pass string `json:"Pass"`
ChallengeKey string `json:"ChallengeKey"`
} `json:"Results"`
}
type Options struct {
RawUrl string
Sitekey string
Proxy string
UserAgent string
Rqdata string
Apikey string
}
type User struct {
DailyLimit int `json:"daily_limit"`
DailyReset int64 `json:"next_reset"`
DailyUsed int `json:"daily_used"`
DailyRemaining int `json:"daily_remaining"`
Funds float64 `json:"balance"`
PlanExpire int64 `json:"plan_expire"`
}
func CreateTask(o Options) (Task, error) {
if o.Apikey == "" && o.Sitekey == "" && o.RawUrl == "" {
return Task{}, errors.New("missing required parameters (apikey, sitekey, raw url)")
}
if !strings.Contains(o.RawUrl, "://") {
o.RawUrl = "https://" + o.RawUrl
}
if !strings.Contains(o.Proxy, "://") && o.Proxy != "" {
o.Proxy = "http://" + o.Proxy
}
payload := map[string]string{
"url": o.RawUrl,
"sitekey": o.Sitekey,
"proxy": o.Proxy,
"userAgent": o.UserAgent,
"rqdata": o.Rqdata,
}
p, err := json.Marshal(payload)
if err != nil {
return Task{}, err
}
req, err := http.NewRequest(http.MethodPost, "https://api.procap.wtf/createTask", bytes.NewReader(p))
if err != nil {
return Task{}, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("apikey", o.Apikey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return Task{}, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return Task{}, err
}
var t Task
err = json.Unmarshal(b, &t)
if err != nil {
return Task{}, err
}
if !t.Success {
return Task{}, errors.New(t.Message)
}
return t, nil
}
func CheckTask(t Task) (Task, error) {
req, err := http.NewRequest(http.MethodGet, "https://api.procap.wtf/checkTask/"+t.Id, nil)
if err != nil {
return Task{}, err
}
req.Header.Set("apikey", t.Results.ChallengeKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return Task{}, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return Task{}, err
}
err = json.Unmarshal(b, &t)
if err != nil {
return Task{}, err
}
return t, nil
}
func Solve(o Options) (string, string, error) {
t, err := CreateTask(o)
if err != nil {
return "", "", err
}
start := time.Now()
for {
t, err = CheckTask(t)
if t.Results.Pass != "" {
return t.Results.Pass, t.Results.ChallengeKey, nil
}
if err != nil {
return "", "", err
}
if !t.Success {
return "", "", errors.New(t.Message)
}
if time.Since(start) > time.Minute*2 {
return "", "", errors.New("solving timed out")
}
time.Sleep(time.Second)
}
}
func GetUser(apikey string) (User, error) {
req, err := http.NewRequest(http.MethodGet, "https://api.procap.wtf/user", nil)
if err != nil {
return User{}, err
}
req.Header.Set("apikey", apikey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return User{}, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return User{}, err
}
var user User
err = json.Unmarshal(b, &user)
if err != nil {
return User{}, err
}
return user, nil
}