This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
79 lines (71 loc) · 1.73 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
package main
import (
"fmt"
"net"
"os"
"time"
uerr "github.com/ucloud/ucloud-sdk-go/ucloud/error"
)
func main() {
config.getConf()
initUcloud()
for {
process()
time.Sleep(time.Hour * 24)
}
}
func process() {
fmt.Println("Start to process...")
fmt.Println("Delete old GlobalSSH...")
for _, id := range config.Instances {
deleteGlobalSSH(id)
}
fmt.Println("Checking Github ip...")
ips, _ := fetchIPs()
fmt.Println("Creating ucloud GlobalSSH...")
DomainsNew := make([]string, 0)
instances := make([]string, 0)
for _, ip := range ips {
ip = parseIP(ip)
if ip != "" {
domain, instance, err := newGlobalSSH(ip, area(ip))
if err != nil {
e := err.(uerr.Error)
switch e.Code() {
case 33902:
fmt.Println("UCloud未实名认证,无法创建GlobalSSH")
os.Exit(33902)
case 33981:
fmt.Println("Ucloud GlobalSSH with ip", ip, "already exists")
DomainsNew = append(DomainsNew, fmt.Sprintf("%s.ipssh.net", ip))
instances = append(instances, instance)
default:
fmt.Println("Ucloud error:", err.Error())
}
continue
} else {
fmt.Println("Ucloud new GlobalSSH:", domain)
DomainsNew = append(DomainsNew, domain)
instances = append(instances, instance)
}
}
}
config.Instances = instances
config.save()
fmt.Println("\nSleeping 2min for dns ...")
time.Sleep(time.Minute * 2)
fmt.Println("\nNow Lookup Domain...")
newDnsRecordIps := make([]string, 0)
for _, domain := range DomainsNew {
ips, err := net.LookupIP(domain)
if err != nil {
fmt.Println("DNS lookup error:", err.Error())
} else {
for _, newip := range ips {
newDnsRecordIps = append(newDnsRecordIps, newip.String())
}
}
}
setDnsRecords(newDnsRecordIps)
fmt.Println("End...")
}