-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathmain.go
506 lines (476 loc) · 14.2 KB
/
main.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
package main
import (
"crypto/md5"
"embed"
"flag"
"fmt"
"github.com/atotto/clipboard"
"github.com/denisbrodbeck/machineid"
"howett.net/plist"
"net"
"os"
"os/exec"
"runtime"
"sort"
"strconv"
"strings"
"time"
"github.com/unknwon/i18n"
)
var version = 229
var hosts = []string{"https://idea.jeter.eu.org", "http://129.154.205.7:7191", "http://jetbra.serv00.net:7191", "http://ba.serv00.net:7191"}
var host = hosts[0]
var githubPath = "https://github.com/kingparks/jetbra-activate/releases/download/latest/"
var err error
var green = "\033[32m%s\033[0m\n"
var yellow = "\033[33m%s\033[0m\n"
var hGreen = "\033[1;32m%s\033[0m"
var dGreen = "\033[4;32m%s\033[0m\n"
var red = "\033[31m%s\033[0m\n"
var defaultColor = "%s"
var lang, _ = getLocale()
var deviceID = getMacMD5_241018()
var machineID = getMacMD5_241019()
var client = Client{Hosts: hosts}
//go:embed all:script
var scriptFS embed.FS
//go:embed all:locales
var localeFS embed.FS
type Tr struct {
i18n.Locale
}
var tr *Tr
func main() {
language := flag.String("l", lang, "set language, eg: zh, en, nl, ru, hu, tr")
flag.Parse()
localeFileEn, _ := localeFS.ReadFile("locales/en.ini")
_ = i18n.SetMessage("en", localeFileEn)
localeFileNl, _ := localeFS.ReadFile("locales/nl.ini")
_ = i18n.SetMessage("nl", localeFileNl)
localeFileRu, _ := localeFS.ReadFile("locales/ru.ini")
_ = i18n.SetMessage("ru", localeFileRu)
localeFileHu, _ := localeFS.ReadFile("locales/hu.ini")
_ = i18n.SetMessage("hu", localeFileHu)
localeFileTr, _ := localeFS.ReadFile("locales/tr.ini")
_ = i18n.SetMessage("tr", localeFileTr)
localeFileEs, _ := localeFS.ReadFile("locales/es.ini")
_ = i18n.SetMessage("es", localeFileEs)
lang = *language
switch lang {
case "zh":
tr = &Tr{Locale: i18n.Locale{Lang: "zh"}}
githubPath = strings.ReplaceAll(githubPath, "https://github.com", "https://gitee.com")
case "nl":
tr = &Tr{Locale: i18n.Locale{Lang: "nl"}}
case "ru":
tr = &Tr{Locale: i18n.Locale{Lang: "ru"}}
case "hu":
tr = &Tr{Locale: i18n.Locale{Lang: "hu"}}
case "tr":
tr = &Tr{Locale: i18n.Locale{Lang: "tr"}}
case "es":
tr = &Tr{Locale: i18n.Locale{Lang: "es"}}
default:
tr = &Tr{Locale: i18n.Locale{Lang: "en"}}
}
fmt.Printf(green, tr.Tr("IntelliJ 授权")+` v`+strings.Join(strings.Split(fmt.Sprint(version), ""), "."))
// 检查是否在容器环境
if content, err := os.ReadFile("/proc/1/cgroup"); err == nil {
if strings.Contains(string(content), "/docker/") {
fmt.Printf(red, tr.Tr("不支持容器环境"))
_, _ = fmt.Scanln()
panic(tr.Tr("不支持容器环境"))
}
}
client.SetProxy(lang)
checkUpdate(version)
sCount, sPayCount, _, _, exp := client.GetMyInfo(deviceID)
fmt.Printf(green, tr.Tr("设备码")+":"+deviceID)
expTime, _ := time.ParseInLocation("2006-01-02 15:04:05", exp, time.Local)
fmt.Printf(green, tr.Tr("付费到期时间")+":"+exp)
fmt.Printf("\033[32m%s\033[0m\u001B[1;32m %s \u001B[0m\033[32m%s\033[0m\u001B[1;32m %s \u001B[0m\u001B[32m%s\u001B[0m\n",
tr.Tr("推广命令:(已推广"), sCount, tr.Tr("人,推广已付费"), sPayCount, tr.Tr("人;每推广10人或推广付费2人可获得一年授权)"))
fmt.Printf(hGreen, "bash <(curl -Lk "+githubPath+"install.sh) "+deviceID+"\n")
fmt.Printf(green, tr.Tr("专属推广链接")+":"+host+"?p="+deviceID)
printAD()
fmt.Println()
fmt.Printf(defaultColor, tr.Tr("选择要授权的产品:"))
jbProduct := []string{"IntelliJ IDEA", "CLion", "PhpStorm", "Goland", "PyCharm", "WebStorm", "Rider", "DataGrip", "DataSpell", "RustRover"}
jbProductChoice := []string{"idea", "clion", "phpstorm", "goland", "pycharm", "webstorm", "rider", "datagrip", "dataspell", "rustrover"}
for i, v := range jbProduct {
fmt.Printf(hGreen, fmt.Sprintf("%d. %s\t", i+1, v))
}
fmt.Println()
fmt.Print(tr.Tr("请输入产品编号(直接回车默认为1):"))
productIndex := 1
_, _ = fmt.Scanln(&productIndex)
if productIndex < 1 || productIndex > len(jbProduct) {
fmt.Println(tr.Tr("输入有误"))
return
}
fmt.Println(tr.Tr("选择的产品为:") + jbProduct[productIndex-1])
fmt.Println()
// 到期了
periodIndex := 1
_ = []time.Duration{367 * 24 * time.Hour, 24 * time.Hour}
if expTime.Before(time.Now()) {
fmt.Printf(defaultColor, tr.Tr("选择有效期:"))
jbPeriod := []string{"1" + tr.Tr("年(购买)"), "24" + tr.Tr("小时(免费)")}
for i, v := range jbPeriod {
fmt.Printf(hGreen, fmt.Sprintf("%d. %s\t", i+1, v))
}
fmt.Println()
fmt.Printf("%s", tr.Tr("请输入有效期编号(直接回车默认为1):"))
_, _ = fmt.Scanln(&periodIndex)
if periodIndex < 1 || periodIndex > len(jbPeriod) {
fmt.Println(tr.Tr("输入有误"))
return
}
fmt.Println(tr.Tr("选择的有效期为:") + jbPeriod[periodIndex-1])
fmt.Println()
}
lic := ""
for i := 0; i < 50; i++ {
if i == 20 {
Clean()
Active(jbProductChoice[productIndex-1])
}
time.Sleep(20 * time.Millisecond)
h := strings.Repeat("=", i) + strings.Repeat(" ", 49-i)
fmt.Printf("\r%.0f%%[%s]", float64(i)/49*100, h)
}
fmt.Println()
fmt.Println()
switch periodIndex {
case 2:
isOk, result := client.GetLic(jbProductChoice[productIndex-1], periodIndex-1)
if !isOk {
fmt.Printf(red, result)
return
}
lic = result
case 1:
// 没到期
if expTime.After(time.Now()) {
isOk, result := client.GetLic(jbProductChoice[productIndex-1], periodIndex-1)
if !isOk {
fmt.Printf(red, result)
return
}
lic = result
fmt.Println()
goto Process
}
// 到期了
payUrl, orderID := client.GetPayUrl()
isCopyText := ""
errClip := clipboard.WriteAll(payUrl)
if errClip == nil {
isCopyText = tr.Tr("(已复制到剪贴板)")
}
fmt.Println(tr.Tr("付费已到期,捐赠以获取一年期授权") + isCopyText)
fmt.Printf(dGreen, payUrl)
fmt.Println(tr.Tr("捐赠完成后请回车"))
//检测控制台回车
checkPay:
_, _ = fmt.Scanln()
isPay := client.PayCheck(orderID, deviceID)
if !isPay {
fmt.Println(tr.Tr("未捐赠,请捐赠完成后回车"))
goto checkPay
}
isOk, result := client.GetLic(jbProductChoice[productIndex-1], periodIndex-1)
if !isOk {
fmt.Printf(red, result)
return
}
fmt.Println()
}
Process:
isCopyText := ""
err = clipboard.WriteAll(lic)
if err == nil {
isCopyText = tr.Tr("(已复制到剪贴板)")
}
fmt.Printf(yellow, tr.Tr("首次执行请重启IDE,然后填入下面授权码;非首次执行直接填入下面授权码即可")+isCopyText)
switch runtime.GOOS {
case "windows":
_ = exec.Command("taskkill", "/IM", jbProductChoice[productIndex-1]+".exe", "/F").Run()
_ = exec.Command("taskkill", "/IM", jbProductChoice[productIndex-1]+"64.exe", "/F").Run()
case "darwin":
_ = exec.Command("killall", "-9", jbProductChoice[productIndex-1]).Run()
case "linux":
_ = exec.Command("killall", "-9", jbProductChoice[productIndex-1]+".sh").Run()
_ = exec.Command("killall", "-9", "java").Run()
}
fmt.Println()
fmt.Printf(hGreen, lic)
fmt.Println()
for i := 0; i < 4; i++ {
_, _ = fmt.Scanln()
}
}
func getMacMD5() string {
// 获取本机的MAC地址
interfaces, err := net.Interfaces()
if err != nil {
fmt.Println("err:", err)
return ""
}
var macAddress []string
var wifiAddress []string
var bluetoothAddress []string
var macErrorStr string
for _, inter := range interfaces {
// 排除虚拟网卡
hardwareAddr := inter.HardwareAddr.String()
if hardwareAddr == "" {
//fmt.Println(fmt.Sprintf("log: have not hardwareAddr :%+v",inter))
continue
}
macErrorStr += inter.Name + ":" + hardwareAddr + "\n"
virtualMacPrefixes := []string{
"00:05:69", "00:0C:29", "00:1C:14", "00:50:56", // VMware
"00:15:5D", // Hyper-V
"08:00:27", "0A:00:27", // VirtualBox
}
isVirtual := false
for _, prefix := range virtualMacPrefixes {
if strings.HasPrefix(hardwareAddr, strings.ToLower(prefix)) {
isVirtual = true
break
}
}
if isVirtual {
//fmt.Println(fmt.Sprintf("log: isVirtual :%+v",inter))
continue
}
// 大于en6的排除
if strings.HasPrefix(inter.Name, "en") {
numStr := inter.Name[2:]
num, _ := strconv.Atoi(numStr)
if num > 6 {
//fmt.Println(fmt.Sprintf("log: is num>6 :%+v",inter))
continue
}
}
if strings.HasPrefix(inter.Name, "en") || strings.HasPrefix(inter.Name, "Ethernet") || strings.HasPrefix(inter.Name, "以太网") || strings.HasPrefix(inter.Name, "WLAN") {
//fmt.Println(fmt.Sprintf("log: add :%+v",inter))
macAddress = append(macAddress, hardwareAddr)
} else if strings.HasPrefix(inter.Name, "Wi-Fi") || strings.HasPrefix(inter.Name, "无线网络") {
wifiAddress = append(wifiAddress, hardwareAddr)
} else if strings.HasPrefix(inter.Name, "Bluetooth") || strings.HasPrefix(inter.Name, "蓝牙网络连接") {
bluetoothAddress = append(bluetoothAddress, hardwareAddr)
} else {
//fmt.Println(fmt.Sprintf("log: not add :%+v",inter))
}
}
if len(macAddress) == 0 {
macAddress = append(macAddress, wifiAddress...)
if len(macAddress) == 0 {
macAddress = append(macAddress, bluetoothAddress...)
}
if len(macAddress) == 0 {
fmt.Printf(red, "no mac address found,Please contact customer service")
_, _ = fmt.Scanln()
return macErrorStr
}
}
sort.Strings(macAddress)
return fmt.Sprintf("%x", md5.Sum([]byte(strings.Join(macAddress, ","))))
}
func getMac_241018() string {
interfaces, err := net.Interfaces()
if err != nil {
fmt.Println("err:", err)
return ""
}
var macError []string
for _, inter := range interfaces {
hardwareAddr := inter.HardwareAddr.String()
if hardwareAddr == "" {
continue
}
macError = append(macError, inter.Name+": "+hardwareAddr)
}
sort.Strings(macError)
return strings.Join(macError, "\n")
}
func getMacMD5_241018() string {
interfaces, err := net.Interfaces()
if err != nil {
fmt.Println("err:", err)
return ""
}
var macAddress, bluetoothAddress []string
virtualMacPrefixes := []string{
"00:05:69", "00:0C:29", "00:1C:14", "00:50:56", // VMware
"00:15:5D", // Hyper-V
"08:00:27", "0A:00:27", // VirtualBox
}
for _, inter := range interfaces {
hardwareAddr := inter.HardwareAddr.String()
if hardwareAddr == "" {
continue
}
isVirtual := false
for _, prefix := range virtualMacPrefixes {
if strings.HasPrefix(hardwareAddr, strings.ToLower(prefix)) {
isVirtual = true
break
}
}
if isVirtual {
continue
}
switch {
case strings.HasPrefix(inter.Name, "en"), strings.HasPrefix(inter.Name, "Ethernet"), strings.HasPrefix(inter.Name, "以太网"):
macAddress = append(macAddress, hardwareAddr)
case strings.HasPrefix(inter.Name, "Bluetooth"), strings.HasSuffix(inter.Name, "Bluetooth"), strings.HasPrefix(inter.Name, "蓝牙网络连接"):
bluetoothAddress = append(bluetoothAddress, hardwareAddr)
}
}
if len(macAddress) == 0 {
macAddress = append(macAddress, bluetoothAddress...)
if len(macAddress) == 0 {
//fmt.Printf(red, "no mac address found,Please contact customer service")
//_, _ = fmt.Scanln()
//return macErrorStr
return getMacMD5_241019()
}
}
sort.Strings(macAddress)
return fmt.Sprintf("%x", md5.Sum([]byte(strings.Join(macAddress, ","))))
}
func getMacMD5_241019() string {
id, err := machineid.ID()
if err != nil {
return err.Error()
}
id = strings.ToLower(id)
id = strings.ReplaceAll(id, "-", "")
return id
}
func printAD() {
ad := client.GetAD()
if len(ad) == 0 {
return
}
fmt.Printf(yellow, ad)
}
func checkUpdate(version int) {
upUrl := client.CheckVersion(fmt.Sprint(version))
if upUrl == "" {
return
}
isCopyText := ""
installCmd := `bash -c "$(curl -fsSLk ` + githubPath + `install.sh)"`
errClip := clipboard.WriteAll(installCmd)
if errClip == nil {
isCopyText = tr.Tr("(已复制到剪贴板)")
}
switch runtime.GOOS {
case "windows":
fmt.Printf(red, tr.Tr("有新版本,请关闭本窗口,将下面命令粘贴到GitBash窗口执行")+isCopyText+`:`)
default:
fmt.Printf(red, tr.Tr("有新版本,请关闭本窗口,将下面命令粘贴到新终端窗口执行")+isCopyText+`:`)
}
fmt.Printf(hGreen, installCmd)
_, _ = fmt.Scanln()
os.Exit(0)
return
}
// 获取推广人
func getPromotion() (promotion string) {
b, _ := os.ReadFile(os.Getenv("HOME") + "/.jetbrarc")
promotion = strings.TrimSpace(string(b))
if len(promotion) == 0 {
if len(os.Args) > 1 {
promotion = os.Args[1]
}
}
return
}
func getLocale() (langRes, locRes string) {
osHost := runtime.GOOS
langRes = "en"
locRes = "US"
switch osHost {
case "windows":
// Exec powershell Get-Culture on Windows.
cmd := exec.Command("powershell", "Get-Culture | select -exp Name")
output, err := cmd.Output()
if err == nil {
langLocRaw := strings.TrimSpace(string(output))
langLoc := strings.Split(langLocRaw, "-")
langRes = langLoc[0]
langRes = strings.Split(langRes, "-")[0]
locRes = langLoc[1]
return
}
case "darwin":
// Exec shell Get-Culture on MacOS.
cmd := exec.Command("sh", "osascript -e 'user locale of (get system info)'")
output, err := cmd.Output()
if err == nil {
langLocRaw := strings.TrimSpace(string(output))
langLoc := strings.Split(langLocRaw, "_")
langRes = langLoc[0]
langRes = strings.Split(langRes, "-")[0]
if len(langLoc) == 1 {
return
}
locRes = langLoc[1]
return
}
plistB, err := os.ReadFile(os.Getenv("HOME") + "/Library/Preferences/.GlobalPreferences.plist")
if err != nil {
fmt.Println(err)
_, _ = fmt.Scanln()
panic(err)
}
var a map[string]interface{}
_, err = plist.Unmarshal(plistB, &a)
if err != nil {
fmt.Println(err)
_, _ = fmt.Scanln()
panic(err)
}
langLocRaw := a["AppleLocale"].(string)
langLoc := strings.Split(langLocRaw, "_")
langRes = langLoc[0]
langRes = strings.Split(langRes, "-")[0]
if len(langLoc) == 1 {
return
}
locRes = langLoc[1]
return
case "linux":
envlang, ok := os.LookupEnv("LANG")
if ok {
langLocRaw := strings.TrimSpace(envlang)
langLocRaw = strings.Split(envlang, ".")[0]
langLoc := strings.Split(langLocRaw, "_")
langRes = langLoc[0]
langRes = strings.Split(langRes, "-")[0]
if len(langLoc) == 1 {
return
}
locRes = langLoc[1]
return
}
}
if langRes == "" {
langLocRaw := os.Getenv("LC_CTYPE")
langLocRaw = strings.Split(langLocRaw, ".")[0]
langLoc := strings.Split(langLocRaw, "_")
langRes = langLoc[0]
langRes = strings.Split(langRes, "-")[0]
if len(langLoc) == 1 {
return
}
locRes = langLoc[1]
return
}
return
}