-
Notifications
You must be signed in to change notification settings - Fork 88
/
prepare.go
1481 lines (1323 loc) · 31.7 KB
/
prepare.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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2014-2024 Li Kexian
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Go module for domain whois information parsing
* https://www.likexian.com/
*/
package whoisparser
import (
"fmt"
"regexp"
"strings"
"github.com/likexian/gokit/assert"
"github.com/likexian/gokit/xslice"
)
// Prepare do prepare the whois info for parsing
func Prepare(text, ext string) (string, bool) { //nolint:cyclop
text = strings.Replace(text, "\r", "", -1)
text = strings.Replace(text, "\t", " ", -1)
text = strings.TrimSpace(text)
switch ext {
case "":
return prepareTLD(text), true
case "edu":
return prepareEDU(text), true
case "int":
return prepareINT(text), true
case "mo":
return prepareMO(text), true
case "hk":
return prepareHK(text), true
case "tw":
return prepareTW(text), true
case "ch":
return prepareCH(text), true
case "it":
return prepareIT(text), true
case "fr", "re", "tf", "yt", "pm", "wf":
return prepareFR(text), true
case "ru", "su", "xn--p1ai":
return prepareRU(text), true
case "fi":
return prepareFI(text), true
case "jp":
return prepareJP(text), true
case "uk":
return prepareUK(text), true
case "kr":
return prepareKR(text), true
case "nz":
return prepareNZ(text), true
case "tk":
return prepareTK(text), true
case "nl":
return prepareNL(text), true
case "eu":
return prepareEU(text), true
case "br":
return prepareBR(text), true
case "ir", "xn--mgba3a4f16a":
return prepareIR(text), true
case "rs":
return prepareRS(text), true
case "kz":
return prepareKZ(text), true
case "ee":
return prepareEE(text), true
case "cn", "xn--fiqs8s", "xn--fiqz9s":
return prepareCN(text), true
case "pl":
return preparePL(text), true
case "dk":
return prepareDK(text), true
case "by":
return prepareBY(text), true
case "ua":
return prepareUA(text), true
case "at":
return prepareAT(text), true
case "sk":
return prepareSK(text), true
default:
return text, false
}
}
// prepareTLD do prepare the tld domain
func prepareTLD(text string) string {
token := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
if strings.Contains(v, ":") {
vs := strings.Split(v, ":")
if strings.TrimSpace(vs[0]) == "organisation" {
if token == "" {
token = "registrant"
}
}
if strings.TrimSpace(vs[0]) == "contact" {
token = strings.TrimSpace(vs[1])
} else {
if token != "" {
v = fmt.Sprintf("%s %s", token, v)
}
}
}
result += "\n" + v
}
return result
}
// prepareEDU do prepare the .edu domain
func prepareEDU(text string) string {
tokens := map[string][]string{
"Registrant:": {
"Organization",
"Address",
"Phone",
"Email",
},
"Administrative Contact:": {
"Name",
"Organization",
"Address",
"Phone",
"Email",
},
"Technical Contact:": {
"Name",
"Organization",
"Address",
"Phone",
"Email",
},
}
token := ""
index := 0
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if strings.HasSuffix(v, ":") {
token = ""
index = 0
}
if _, ok := tokens[v]; ok {
token = v
} else {
if token == "" {
result += "\n" + v
} else {
// address ending now jump to phone
if tokens[token][index] == "Address" && strings.HasPrefix(v, "+") {
found := xslice.Index(tokens[token], "Phone")
if found != -1 {
index = found
}
}
result += fmt.Sprintf("\n%s %s: %s", token[:len(token)-1], tokens[token][index], v)
if tokens[token][index] != "Address" {
index++
}
}
}
}
return result
}
// prepareINT do prepare the .int domain
func prepareINT(text string) string {
token := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
if strings.Contains(v, ":") {
vs := strings.Split(v, ":")
if strings.TrimSpace(vs[0]) == "organisation" {
if token == "" {
token = "registrant"
}
}
if strings.TrimSpace(vs[0]) == "contact" {
token = strings.TrimSpace(vs[1])
} else {
if token != "" {
v = fmt.Sprintf("%s %s", token, v)
}
}
}
result += "\n" + v
}
return result
}
// prepareKZ do prepare the .kz domain
func prepareKZ(text string) string {
groupTokens := map[string]string{
"Organization Using Domain Name": "Registrant ",
"Administrative Contact/Agent": "Administrative ",
}
topTokens := map[string]string{
"Domain status": "Domain status : ",
}
tokens := map[string]string{
"Primary server": "name server",
"Secondary server": "name server",
"Current Registar": "Registrar Name",
}
groupToken := ""
topToken := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
groupToken = ""
continue
}
if token, ok := groupTokens[v]; ok {
groupToken = token
continue
}
if !strings.Contains(v, ":") {
if topToken != "" {
v = fmt.Sprintf("%s%s", topToken, v)
} else {
continue
}
}
vs := strings.SplitN(v, ":", 2)
key := strings.TrimSpace(strings.Replace(vs[0], ".", "", -1))
key = fmt.Sprintf("%s%s", groupToken, key)
if token, ok := tokens[key]; ok {
key = token
}
value := vs[1]
if token, ok := topTokens[key]; ok {
topToken = token
} else {
topToken = ""
}
v = fmt.Sprintf("%s: %s", key, value)
result += "\n" + v
}
return result
}
// prepareMO do prepare the .mo domain
func prepareMO(text string) string {
tokens := map[string]string{
"Registrant:": "Registrant",
"Admin Contact(s):": "Admin",
"Billing Contact(s):": "Billing",
"Technical Contact(s):": "Technical",
}
token := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
if v[0] == '-' {
continue
}
for _, s := range []string{"Record created on", "Record expires on"} {
if strings.HasPrefix(v, s) {
v = strings.Replace(v, s, s+":", 1)
}
}
if _, ok := tokens[v]; ok {
token = tokens[v]
} else {
if token != "" {
v = fmt.Sprintf("%s %s", token, v)
}
}
result += "\n" + v
}
return result
}
var prepareHKEmailRx = regexp.MustCompile(`Email\:\s+([^\s]+)(\s+Hotline\:(.*))?`)
// prepareHK do prepare the .hk domain
func prepareHK(text string) string {
tokens := map[string]string{
"Registrant Contact Information:": "Registrant",
"Administrative Contact Information:": "Admin",
"Technical Contact Information:": "Technical",
"Name Servers Information:": "Name Servers:",
}
dateTokens := []string{
"Domain Name Commencement Date",
"Expiry Date",
}
token := ""
addressToken := false
text = strings.Replace(text, "\n\n", "\n", -1)
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
field := ""
if strings.Contains(v, ":") {
vs := strings.SplitN(v, ":", 2)
field = strings.TrimSpace(vs[0])
if strings.Contains(field, "(") {
field = strings.Split(field, "(")[0]
v = fmt.Sprintf("%s: %s", field, vs[1])
}
addressToken = field == "Address"
if field == "Registrar Contact Information" {
m := prepareHKEmailRx.FindStringSubmatch(vs[1])
if len(m) == 4 {
v = ""
if m[1] != "" {
v += "Registrar Contact Email: " + m[1] + "\n"
}
if m[3] != "" {
v += "Registrar Contact Phone: " + m[3] + "\n"
}
v = strings.TrimSpace(v)
}
}
if field == "Family name" {
vv := strings.TrimSpace(vs[1])
if vv != "" && vv != "." {
result += " " + vv
}
continue
}
} else {
if addressToken {
result += ", " + v
continue
}
}
if _, ok := tokens[v]; ok {
token = tokens[v]
} else {
if token != "" && !assert.IsContains(dateTokens, field) {
v = fmt.Sprintf("%s %s", token, v)
}
}
result += "\n" + v
}
return result
}
var prepareTWEmailRx = regexp.MustCompile(`(.*)\s+([^\s]+@[^\s]+)`)
// prepareTW do prepare the .tw domain
func prepareTW(text string) string { //nolint:cyclop
tokens := map[string][]string{
"Registrant:": {
"Organization",
"Organization",
"Name,Email",
"Phone",
"Fax",
"Address",
"Address",
"Address",
},
"Administrative Contact:": {
"Name,Email",
"Phone",
"Fax",
},
"Technical Contact:": {
"Name,Email",
"Phone",
"Fax",
},
"Contact:": {
"Name",
"Email",
},
}
token := ""
index := -1
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if token == "" && v == "" {
continue
}
for _, s := range []string{"Record created on", "Record expires on"} {
if strings.HasPrefix(v, s) {
v = strings.Replace(v, s, s+":", 1)
}
}
if strings.Contains(v, ":") {
token = ""
index = -1
}
if _, ok := tokens[v]; ok {
token = v
} else {
if token == "" {
result += "\n" + v
} else {
index++
if index > len(tokens[token])-1 {
continue
}
tokenName := token[:len(token)-1]
// Organization may be one line or two lines
if tokenName == "Registrant" && tokens[token][index] == "Organization" {
if strings.Contains(v, "@") {
// Organization one line, jump to next
index++
} else if index == 1 {
// Organization two line, join it
result = strings.TrimSpace(result)
if !strings.HasSuffix(result, ":") {
result += ", " + v
} else {
result += " " + v
}
continue
}
}
// See testdata/noterror/tw_git.tw
if tokenName == "Registrant" && tokens[token][index] != "Address" {
if len(v) == 2 && strings.ToLower(v) != v {
index = xslice.Index(tokens[token], "Address")
}
}
indexName := tokens[token][index]
if tokenName == "Contact" {
tokenName = "Registrant Contact"
}
if strings.Contains(indexName, ",") {
ins := strings.Split(indexName, ",")
m := prepareTWEmailRx.FindStringSubmatch(v)
if len(m) == 3 {
result += fmt.Sprintf("\n%s %s: %s", tokenName, ins[0], strings.TrimSpace(m[1]))
result += fmt.Sprintf("\n%s %s: %s", tokenName, ins[1], strings.TrimSpace(m[2]))
} else {
result += fmt.Sprintf("\n%s %s: %s", tokenName, ins[0], strings.TrimSpace(v))
}
continue
}
result += fmt.Sprintf("\n%s %s: %s", tokenName, indexName, v)
}
}
}
return result
}
// prepareCH do prepare the .ch domain
func prepareCH(text string) string {
phoneMark := "Phone +"
tokens := map[string][]string{
"Domain name": {},
"Registrar": {"Registrar name", "Registrar street", "Registrar Phone", "Registrar Email"},
"DNSSEC": {},
"Name servers": {},
"First registration date": {},
}
var result string
var lastToken string
var lastTokenIndex int
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
for t := range tokens {
if strings.HasPrefix(strings.ToLower(v)+" ", strings.ToLower(t+" ")) {
lastToken = t
lastTokenIndex = 0
v = strings.TrimSpace(v[len(t):])
break
}
}
if v == "" {
continue
}
if len(tokens[lastToken]) > 0 {
if strings.HasPrefix(v, phoneMark) {
lastTokenIndex++
v = strings.TrimSpace(v[len(phoneMark)-1:])
}
result += fmt.Sprintf("\n%s: %s", tokens[lastToken][lastTokenIndex], v)
if tokens[lastToken][lastTokenIndex] != "Registrar street" {
lastTokenIndex++
}
} else {
result += fmt.Sprintf("\n%s: %s", lastToken, v)
}
}
return result
}
// prepareIT do prepare the .it domain
func prepareIT(text string) string {
topTokens := []string{
"Registrant",
"Admin Contact",
"Technical Contacts",
"Registrar",
"Nameservers",
}
topToken := ""
subToken := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if assert.IsContains(topTokens, v) {
topToken = v + " "
subToken = ""
} else {
if v[0] != '*' && strings.Contains(v, ":") {
vs := strings.Split(v, ":")
subToken = vs[0]
} else {
if subToken != "" {
result += ", " + v
continue
}
}
if topToken != "" && !strings.Contains(v, ":") {
result += fmt.Sprintf("\n%s: %s", topToken, v)
} else {
result += fmt.Sprintf("\n%s%s", topToken, v)
}
}
}
return result
}
// prepareFR do prepare the .fr domain
func prepareFR(text string) string {
dsToken := "dsl-id"
hdlToken := "nic-hdl"
regToken := "registrar"
tokens := map[string]string{
"holder-c": "holder",
"admin-c": "admin",
"tech-c": "tech",
}
token := ""
newBlock := false
hdls := map[string]string{}
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
newBlock = true
continue
}
vs := strings.Split(v, ":")
if newBlock && strings.TrimSpace(vs[0]) == regToken {
token = regToken + " "
v = fmt.Sprintf("name: %s", strings.TrimSpace(vs[1]))
}
newBlock = false
if t, ok := tokens[strings.TrimSpace(vs[0])]; ok {
hdls[t] = strings.TrimSpace(vs[1])
}
if strings.TrimSpace(vs[0]) == dsToken && strings.TrimSpace(vs[1]) != "" {
v += "\nDNSSEC: signed"
}
if strings.TrimSpace(vs[0]) == hdlToken {
for _, kk := range keys(hdls) {
if strings.TrimSpace(vs[1]) == hdls[kk] {
token = kk + " "
delete(hdls, kk)
break
}
}
}
result += fmt.Sprintf("\n%s%s", token, v)
}
return result
}
// prepareRU do prepare the .ru domain
func prepareRU(text string) string {
tokens := map[string]string{
"person": "Registrant Name",
"e-mail": "Registrant Email",
"org": "Registrant Organization",
}
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if !strings.Contains(v, ":") {
continue
}
vs := strings.Split(v, ":")
if vv, ok := tokens[strings.TrimSpace(vs[0])]; ok {
v = fmt.Sprintf("%s: %s", vv, vs[1])
} else if vs[0] == "nserver" {
v = strings.Replace(v, ",", " ", -1)
}
result += v + "\n"
}
return result
}
var prepareJPreplacerRx = regexp.MustCompile(`\n(?:\w+\.\s)?\[(.+?)\][\ ]*(.+?)?`)
// prepareJP do prepare the .jp domain
func prepareJP(text string) string {
text = prepareJPreplacerRx.ReplaceAllString(text, "\n$1: $2")
adminToken := "Contact Information"
addressToken := "Postal Address"
token := ""
prefixToken := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if strings.Contains(v, ":") {
vs := strings.SplitN(v, ":", 2)
token = strings.TrimSpace(vs[0])
if token == adminToken {
prefixToken = "admin "
}
if strings.ToLower(token) == "registrant" {
v = fmt.Sprintf("registrant name: %s", vs[1])
}
v = prepareSecondLevelJP(v, token, vs[1])
} else {
if token == addressToken {
result += ", " + v
continue
}
}
result += "\n" + prefixToken + v
}
return result
}
// prepareJP prepares specific mappings for second level .jp domains
// examples include:
// - co.jp
// - ac.jp
// - go.jp
// - or.jp
// - ad.jp
// - ne.jp
// - gr.jp
// - ed.jp
func prepareSecondLevelJP(original string, token string, value string) string {
if strings.ToLower(token) == "administrative contact" {
return fmt.Sprintf("Administrative Contact ID: %s", strings.TrimSpace(value))
}
if strings.ToLower(token) == "technical contact" {
return fmt.Sprintf("Technical Contact ID: %s", strings.TrimSpace(value))
}
if strings.ToLower(token) == "organization" || strings.ToLower(token) == "network service name" {
return fmt.Sprintf("Registrant Organization: %s", strings.TrimSpace(value))
}
return original
}
// prepareUK do prepare the .uk domain
func prepareUK(text string) string {
tokens := map[string]string{
"URL": "Registrar URL",
}
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if strings.Contains(v, ":") {
vs := strings.SplitN(v, ":", 2)
if vv, ok := tokens[strings.TrimSpace(vs[0])]; ok {
v = fmt.Sprintf("%s: %s", vv, vs[1])
}
}
result += "\n" + v
}
return result
}
// prepareKR do prepare the .kr domain
func prepareKR(text string) string {
english := "# ENGLISH"
tokens := map[string]string{
"Administrative Contact(AC)": "Administrative Contact Name",
"AC E-Mail": "Administrative Contact E-Mail",
"AC Phone Number": "Administrative Contact Phone Number",
"Authorized Agency": "Registrar Name",
"Registrant": "Registrant Name",
}
pos := strings.Index(text, english)
if pos != -1 {
text = text[pos+len(english):]
}
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if v[0] == '\'' || v[0] == '-' {
continue
}
if strings.Contains(v, ":") {
vs := strings.SplitN(v, ":", 2)
if vv, ok := tokens[strings.TrimSpace(vs[0])]; ok {
v = fmt.Sprintf("%s: %s", vv, vs[1])
}
}
result += "\n" + v
}
return result
}
// prepareNZ do prepare the .nz domain
func prepareNZ(text string) string {
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if strings.Contains(v, ":") {
vs := strings.SplitN(v, ":", 2)
if strings.HasPrefix(strings.TrimSpace(vs[0]), "ns_name_") {
v = fmt.Sprintf("name server: %s", vs[1])
}
}
result += "\n" + v
}
return result
}
// prepareTK do prepare the .tk domain
func prepareTK(text string) string {
tokens := map[string]string{
"Domain name:": "Domain",
"Domain Nameservers:": "Nameservers",
"Owner contact:": "Registrant",
"Admin contact:": "Admin",
"Billing contact:": "Billing",
"Tech contact:": "Technical",
"Organisation:": "Registrant",
}
fields := map[string][]string{
"Registrant": {
"Organization",
"Name",
"Address",
"Address",
"Address",
"Country",
},
}
token := ""
result := ""
index := 0
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
if _, ok := tokens[v]; ok {
token = tokens[v]
continue
}
if token == "Domain" && strings.Contains(v, " is ") {
vv := strings.Split(v, " is ")
v = fmt.Sprintf("Name: %s\nStatus: %s", vv[0], vv[1])
} else if token == "Registrant" && !strings.Contains(v, ":") {
v = fmt.Sprintf("%s: %s", fields[token][index], v)
index++
}
if token != "" {
if !strings.Contains(v, ":") {
v = fmt.Sprintf("%s: %s", token, v)
} else {
v = fmt.Sprintf("%s %s", token, v)
}
}
result += "\n" + strings.TrimSpace(v)
}
return result
}
// prepareNL do prepare the .nl domain
func prepareNL(text string) string {
tokens := map[string][]string{
"Reseller:": {
"Name",
"Address",
"Address",
"Address",
"Address",
},
"Registrar:": {
"Name",
"Address",
"Address",
"Address",
"Address",
},
}
token := ""
index := 0
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
continue
}
if strings.HasSuffix(v, ":") {
token = ""
index = 0
}
if _, ok := tokens[v]; ok {
token = v
} else {
if token == "" {
result += "\n" + v
} else {
result += fmt.Sprintf("\n%s %s: %s", token[:len(token)-1], tokens[token][index], v)
index++
}
}
}
return result
}
// prepareEU do prepare the .eu domain
func prepareEU(text string) string {
tokens := map[string]string{
"Registrant:": "Registrant",
"Technical:": "Technical",
"Registrar:": "Registrar",
"Onsite(s):": "Onsite",
"Name servers:": "Name servers",
}
token := ""
result := ""
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
if _, ok := tokens[v]; ok {
token = tokens[v]
continue
}
if token != "" {
if strings.Contains(v, ":") {
v = fmt.Sprintf("%s %s", token, v)
} else {
if strings.HasPrefix(v, "Visit www.eurid.eu") {
continue
}
v = fmt.Sprintf("%s: %s", token, v)
}
}
result += "\n" + v
}
return result
}
// prepareBR do prepare the .br domain
func prepareBR(text string) string {
hdlToken := "nic-hdl-br"
tokens := map[string]string{
"owner-c": "registrant",
"admin-c": "admin",
"tech-c": "tech",
"billing-c": "billing",
}
token := ""
hdlMap := map[string]string{}
for _, v := range strings.Split(text, "\n") {
v = strings.TrimSpace(v)
if v == "" {
token = ""
continue
}
if strings.Contains(v, ":") {
vs := strings.SplitN(v, ":", 2)
if strings.TrimSpace(vs[0]) == hdlToken {
token = strings.TrimSpace(vs[1])
hdlMap[token] = ""