-
Notifications
You must be signed in to change notification settings - Fork 6
/
echarts.go
159 lines (144 loc) · 3.21 KB
/
echarts.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 main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
)
type EData struct {
Name string `json:"name"`
Draggable bool `json:"draggable"`
Category string `json:"category"`
Value string `json:"value"`
SymbolSize float32 `json:"symbolSize"`
}
type ECategory struct {
Name string `json:"name"`
}
type ELink struct {
Source string `json:"source"`
Target string `json:"target"`
Value string `json:"value"`
LineStyle ELineStyle `json:"lineStyle"`
}
type ELineStyle struct {
Normal ELineStyleNormal `json:"normal"`
}
type ELineStyleNormal struct {
Curveness float32 `json:"curveness"`
}
func genjs(name string, mp map[string]*dnsrecord, fname string) {
var datas []EData
var links []ELink
var categories []ECategory
var categoriesname []string
catamap := make(map[string]int)
for _, v := range mp {
upname := "."
if v.name != "." {
// Upper Name
upname = getuplevelname(v.name)
if _, ok := catamap[upname]; !ok {
catamap[upname] = 0
categoriesname = append(categoriesname, upname)
categories = append(categories, ECategory{
Name: upname,
})
}
//CNAME
if v.cname != "" {
catamap[v.cname] = 0
categoriesname = append(categoriesname, v.cname)
categories = append(categories, ECategory{
Name: v.cname,
})
}
//CNAME Link
if v.cname != "" {
links = append(links, ELink{
Source: v.name,
Target: v.cname,
Value: "CNAME",
LineStyle: ELineStyle{
Normal: ELineStyleNormal{
Curveness: 0.2,
},
},
})
}
// //SOA Link
// if v.soa != "" {
// links = append(links, ELink{
// Source: v.name,
// Target: v.soa,
// Value: "SOA",
// LineStyle: ELineStyle{
// Normal: ELineStyleNormal{
// Curveness: 0.2,
// },
// },
// })
// }
}
//Data
dotcount := float32(strings.Count(v.name, "."))
cnss := float32(48.00)
cnss = cnss / dotcount
data := EData{
Name: v.name,
Draggable: true,
Category: upname,
Value: strings.Join(v.ip, "\n"),
SymbolSize: cnss,
}
datas = append(datas, data)
//NS Link
for _, ns := range v.ns {
links = append(links, ELink{
Source: v.name,
Target: ns,
Value: "NS",
LineStyle: ELineStyle{
Normal: ELineStyleNormal{
Curveness: 0.2,
},
},
})
}
}
for _, v := range mp {
ln := v.name
for {
if ln == "." {
break
}
//Upper Name Link
un := getuplevelname(ln)
links = append(links, ELink{
Source: ln,
Target: un,
Value: "Parent",
LineStyle: ELineStyle{
Normal: ELineStyleNormal{
Curveness: 0.2,
},
},
})
ln = un
}
}
// categories = make([]string, len(catamap))
// for i, v := range catamap {
// categories[v] = i
// }
cataarrjsonbin, _ := json.Marshal(categoriesname)
catajsonbin, _ := json.Marshal(categories)
datajsonbin, _ := json.Marshal(datas)
linkjsonbin, _ := json.Marshal(links)
cataarrjson := string(cataarrjsonbin)
catajson := string(catajsonbin)
datajson := string(datajsonbin)
linkjson := string(linkjsonbin)
jsonstr := fmt.Sprintf(tpl, cataarrjson, datajson, linkjson, catajson, name)
ioutil.WriteFile(fname, []byte(jsonstr), 0666)
}