nicinfo 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/bin/nicinfo +22 -0
  3. data/lib/autnum.rb +90 -0
  4. data/lib/bootstrap.rb +198 -0
  5. data/lib/bsfiles/asn.json +2326 -0
  6. data/lib/bsfiles/dns.json +25 -0
  7. data/lib/bsfiles/entity.json +52 -0
  8. data/lib/bsfiles/ipv4.json +244 -0
  9. data/lib/bsfiles/ipv6.json +97 -0
  10. data/lib/cache.rb +141 -0
  11. data/lib/common_json.rb +263 -0
  12. data/lib/common_names.rb +49 -0
  13. data/lib/config.rb +260 -0
  14. data/lib/constants.rb +113 -0
  15. data/lib/data_tree.rb +205 -0
  16. data/lib/demo/autnum.json +228 -0
  17. data/lib/demo/domain-dnr.json +695 -0
  18. data/lib/demo/domain-rir.json +569 -0
  19. data/lib/demo/domains.json +625 -0
  20. data/lib/demo/entities.json +545 -0
  21. data/lib/demo/entity-dnr.json +143 -0
  22. data/lib/demo/entity-rir.json +394 -0
  23. data/lib/demo/error-code.json +31 -0
  24. data/lib/demo/help.json +58 -0
  25. data/lib/demo/ip.json +306 -0
  26. data/lib/demo/nameservers.json +434 -0
  27. data/lib/demo/ns-simple.json +210 -0
  28. data/lib/demo/ns-very-simple.json +41 -0
  29. data/lib/demo/ns.json +63 -0
  30. data/lib/demo/simple-ip.json +41 -0
  31. data/lib/demo/simple.json +13 -0
  32. data/lib/domain.rb +203 -0
  33. data/lib/ds_data.rb +70 -0
  34. data/lib/entity.rb +372 -0
  35. data/lib/enum.rb +47 -0
  36. data/lib/error_code.rb +56 -0
  37. data/lib/female-first-names.txt +4275 -0
  38. data/lib/ip.rb +86 -0
  39. data/lib/key_data.rb +70 -0
  40. data/lib/last-names.txt +88799 -0
  41. data/lib/male-first-names.txt +1219 -0
  42. data/lib/nicinfo_logger.rb +370 -0
  43. data/lib/nicinfo_main.rb +1013 -0
  44. data/lib/notices.rb +110 -0
  45. data/lib/ns.rb +108 -0
  46. data/lib/utils.rb +189 -0
  47. metadata +90 -0
data/lib/entity.rb ADDED
@@ -0,0 +1,372 @@
1
+ # Copyright (C) 2011,2012,2013,2014 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ require 'config'
16
+ require 'nicinfo_logger'
17
+ require 'utils'
18
+ require 'common_json'
19
+ require 'data_tree'
20
+
21
+ module NicInfo
22
+
23
+ def NicInfo.display_entity json_data, config, data_tree
24
+ entity = Entity.new( config ).process( json_data )
25
+
26
+ respobjs = ResponseObjSet.new config
27
+ root = entity.to_node
28
+ data_tree.add_root( root )
29
+ if !entity.entities.empty?
30
+ NicInfo::add_entity_nodes( entity.entities, root )
31
+ end
32
+ entity.networks.each do |network|
33
+ net_node = network.to_node
34
+ root.add_child( net_node )
35
+ NicInfo::add_entity_nodes( network.entities, net_node )
36
+ end
37
+ entity.autnums.each do |autnum|
38
+ as_node = autnum.to_node
39
+ root.add_child( as_node )
40
+ NicInfo::add_entity_nodes( autnum.entities, as_node )
41
+ end
42
+
43
+ respobjs.add entity
44
+ NicInfo::add_entity_respobjs( entity.entities, respobjs )
45
+ respobjs.associateEntities entity.entities
46
+ entity.networks.each do |network|
47
+ respobjs.add network
48
+ NicInfo::add_entity_respobjs( network.entities, respobjs )
49
+ respobjs.associateEntities network.entities
50
+ end
51
+ entity.autnums.each do |autnum|
52
+ respobjs.add autnum
53
+ NicInfo::add_entity_respobjs( autnum.entities, respobjs )
54
+ respobjs.associateEntities autnum.entities
55
+ end
56
+
57
+ data_tree.to_normal_log( config.logger, true )
58
+ respobjs.display
59
+ end
60
+
61
+ def NicInfo.display_entities json_data, config, data_tree
62
+ entity_array = json_data[ "entitySearchResults" ]
63
+ if entity_array != nil
64
+ if entity_array.instance_of? Array
65
+ display_array = Array.new
66
+ entity_array.each do |ea|
67
+ entity = Entity.new( config ).process( ea )
68
+ display_array << entity
69
+ end
70
+ NicInfo.display_object_with_entities( display_array, config, data_tree )
71
+ else
72
+ config.conf_msgs << "'entitySearchResults' is not an array"
73
+ end
74
+ else
75
+ config.conf_msgs << "'entitySearchResults' is not present"
76
+ end
77
+ end
78
+
79
+ class Org
80
+ attr_accessor :type, :names
81
+ def initialize
82
+ @type = Array.new
83
+ @names = Array.new
84
+ end
85
+ end
86
+
87
+ class Adr
88
+ attr_accessor :structured, :label, :type
89
+ attr_accessor :pobox, :extended, :street, :locality, :region, :postal, :country
90
+ def initialize
91
+ @structured = false
92
+ @label = Array.new
93
+ @type = Array.new
94
+ end
95
+ end
96
+
97
+ class Email
98
+ attr_accessor :type, :addr
99
+ def initialize
100
+ @type = Array.new
101
+ end
102
+ end
103
+
104
+ class Tel
105
+ attr_accessor :type, :number, :ext
106
+ def initialize
107
+ @type = Array.new
108
+ end
109
+ end
110
+
111
+ class JCard
112
+
113
+ attr_accessor :fns, :names, :phones, :emails, :adrs, :kind, :titles, :roles, :orgs
114
+
115
+ def initialize
116
+ @fns = Array.new
117
+ @names = Array.new
118
+ @phones = Array.new
119
+ @emails = Array.new
120
+ @adrs = Array.new
121
+ @titles = Array.new
122
+ @roles = Array.new
123
+ @orgs = Array.new
124
+ end
125
+
126
+ def get_vcard entity
127
+ return entity[ "vcardArray" ]
128
+ end
129
+
130
+ def process entity
131
+ if ( vcard = get_vcard( entity ) ) != nil
132
+ vcardElements = vcard[ 1 ]
133
+ vcardElements.each do |element|
134
+ if element[ 0 ] == "fn"
135
+ @fns << element[ 3 ]
136
+ end
137
+ if element[ 0 ] == "n"
138
+ name = ""
139
+ if element[ 3 ][ -1 ].instance_of? Array
140
+ name << element[ 3 ][ -1 ].join( ' ' )
141
+ end
142
+ name << ' ' if name[-1] != ' '
143
+ name << element[ 3 ][ 1 ]
144
+ if element[ 3 ][ 2 ] && !element[ 3 ][ 2 ].empty?
145
+ name << " " << element[ 3 ][ 2 ]
146
+ end
147
+ if element[ 3 ][ 3 ] && !element[ 3 ][ 3 ].empty?
148
+ name << " " << element[ 3 ][ 3 ]
149
+ end
150
+ name << " " << element[ 3 ][ 0 ]
151
+ if element[ 3 ][ -2 ].instance_of? Array
152
+ name << " " << element[ 3 ][ -2 ].join( ' ' )
153
+ end
154
+ @names << name
155
+ end
156
+ if element[ 0 ] == "tel"
157
+ tel = Tel.new
158
+ if (type = element[ 1 ][ "type" ]) != nil
159
+ tel.type << type if type.instance_of? String
160
+ tel.type = type if type.instance_of? Array
161
+ end
162
+ if (str = element[ 3 ] ).start_with?( "tel:" )
163
+ tel.number=str[ /^tel\:([^;]*)/,1 ]
164
+ tel.ext=str[ /[^;]*ext=(.*)/,1 ]
165
+ else
166
+ tel.number=str
167
+ end
168
+ @phones << tel
169
+ end
170
+ if element[ 0 ] == "email"
171
+ email = Email.new
172
+ if (type = element[ 1 ][ "type" ]) != nil
173
+ email.type << type if type.instance_of? String
174
+ email.type = type if type.instance_of? Array
175
+ end
176
+ email.addr=element[ 3 ]
177
+ @emails << email
178
+ end
179
+ if element[ 0 ] == "adr"
180
+ adr = Adr.new
181
+ if (type = element[ 1 ][ "type" ]) != nil
182
+ adr.type << type if type.instance_of? String
183
+ adr.type = type if type.instance_of? Array
184
+ end
185
+ if (label = element[ 1 ][ "label" ]) != nil
186
+ adr.label = label.split( "\n" )
187
+ else
188
+ adr.pobox=element[ 3 ][ 0 ]
189
+ adr.extended=element[ 3 ][ 1 ]
190
+ adr.street=element[ 3 ][ 2 ]
191
+ adr.locality=element[ 3 ][ 3 ]
192
+ adr.region=element[ 3 ][ 4 ]
193
+ adr.postal=element[ 3 ][ 5 ]
194
+ adr.country=element[ 3 ][ 6 ]
195
+ adr.structured=true
196
+ end
197
+ @adrs << adr
198
+ end
199
+ if element[ 0 ] == "kind"
200
+ @kind = element[ 3 ]
201
+ end
202
+ if element[ 0 ] == "title"
203
+ @titles << element[ 3 ]
204
+ end
205
+ if element[ 0 ] == "role"
206
+ @roles << element[ 3 ]
207
+ end
208
+ if element[ 0 ] == "org"
209
+ org = Org.new
210
+ if (type = element[ 1 ][ "type" ]) != nil
211
+ org.type << type if type.instance_of? String
212
+ org.type = type if type.instance_of? Array
213
+ end
214
+ names = element[ 3 ]
215
+ org.names << names if names.instance_of? String
216
+ org.names = org.names + names if names.instance_of? Array
217
+ @orgs << org
218
+ end
219
+ end
220
+ end
221
+ return self
222
+ end
223
+
224
+ end
225
+
226
+ # deals with RDAP entity structures
227
+ class Entity
228
+
229
+ attr_accessor :asEvents, :selfhref
230
+ attr_accessor :entities, :objectclass, :asEventActors
231
+ attr_accessor :networks, :autnums
232
+
233
+ def initialize config
234
+ @config = config
235
+ @jcard = JCard.new
236
+ @common = CommonJson.new config
237
+ @entity = nil
238
+ @asEvents = Array.new
239
+ @asEventActors = Array.new
240
+ @selfhref = nil
241
+ @entities = Array.new
242
+ end
243
+
244
+ def process json_data
245
+ @objectclass = json_data
246
+ @jcard.process json_data
247
+ events = @objectclass[ "asEventActor" ]
248
+ events.each do |event|
249
+ eventActor = EventActor.new
250
+ eventActor.eventAction=event[ "eventAction" ]
251
+ eventActor.eventDate=event[ "eventDate" ]
252
+ eventActor.related=NicInfo.get_related_link( NicInfo.get_links( event, @config ) )
253
+ @asEvents << eventActor
254
+ end if events
255
+ @selfhref = NicInfo::get_self_link( NicInfo::get_links( @objectclass, @config ) )
256
+ @entities = @common.process_entities @objectclass
257
+ @networks = Array.new
258
+ json_networks = NicInfo::get_networks( @objectclass )
259
+ json_networks.each do |json_network|
260
+ if json_network.is_a?( Hash )
261
+ network = Ip.new( @config )
262
+ network.process( json_network )
263
+ @networks << network
264
+ else
265
+ @config.conf_msgs << "'networks' contains a string and not an object"
266
+ end
267
+ end if json_networks
268
+ @autnums = Array.new
269
+ json_autnums = NicInfo::get_autnums( @objectclass )
270
+ json_autnums.each do |json_autnum|
271
+ if json_autnum.is_a?( Hash )
272
+ autnum = Autnum.new( @config )
273
+ autnum.process( json_autnum )
274
+ @autnums << autnum
275
+ else
276
+ @config.conf_msgs << "'autnums' contains a string and not an object"
277
+ end
278
+ end if json_autnums
279
+ return self
280
+ end
281
+
282
+ def display
283
+ @config.logger.start_data_item
284
+ @config.logger.data_title "[ ENTITY ]"
285
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
286
+ @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
287
+ @jcard.fns.each do |fn|
288
+ @config.logger.terse "Name", fn
289
+ end
290
+ @jcard.names.each do |n|
291
+ @config.logger.extra "Name", n
292
+ end
293
+ @jcard.orgs.each do |org|
294
+ item_value = org.names.join( ", " )
295
+ if !org.type.empty?
296
+ item_value << " ( #{org.type.join( ", " )} )"
297
+ end
298
+ @config.logger.terse "Organization", item_value
299
+ end
300
+ @jcard.titles.each do |title|
301
+ @config.logger.extra "Title", title
302
+ end
303
+ @jcard.roles.each do |role|
304
+ @config.logger.extra "Organizational Role", role
305
+ end
306
+ @jcard.emails.each do |email|
307
+ item_value = email.addr
308
+ if !email.type.empty?
309
+ item_value << " ( #{email.type.join( ", " )} )"
310
+ end
311
+ @config.logger.terse "Email", item_value
312
+ end
313
+ @jcard.phones.each do |phone|
314
+ item_value = phone.number
315
+ if phone.ext
316
+ item_value << " Ext. #{phone.ext}"
317
+ end
318
+ if !phone.type.empty?
319
+ item_value << " ( #{phone.type.join( ", " )} )"
320
+ end
321
+ @config.logger.terse "Phone", item_value
322
+ end
323
+ @common.display_string_array "roles", "Roles", @objectclass, DataAmount::TERSE_DATA
324
+ @common.display_public_ids @objectclass
325
+ @common.display_status @objectclass
326
+ @common.display_port43 @objectclass
327
+ @common.display_events @objectclass
328
+ @jcard.adrs.each do |adr|
329
+ if adr.type.empty?
330
+ @config.logger.extra "Address", "-- for #{get_cn} --"
331
+ else
332
+ @config.logger.extra "Address", "( #{adr.type.join( ", " )} )"
333
+ end
334
+ if adr.structured
335
+ @config.logger.extra "P.O. Box", adr.pobox
336
+ @config.logger.extra "Apt/Suite", adr.extended
337
+ @config.logger.extra "Street", adr.street
338
+ @config.logger.extra "City", adr.locality
339
+ @config.logger.extra "Region", adr.region
340
+ @config.logger.extra "Postal Code", adr.postal
341
+ @config.logger.extra "Country", adr.country
342
+ else
343
+ i = 1
344
+ adr.label.each do |line|
345
+ @config.logger.extra i.to_s, line
346
+ i = i + 1
347
+ end
348
+ end
349
+ end
350
+ @config.logger.extra "Kind", @jcard.kind
351
+ @common.display_as_events_actors @asEventActors
352
+ @common.display_remarks @objectclass
353
+ @common.display_links( get_cn, @objectclass )
354
+ @config.logger.end_data_item
355
+ end
356
+
357
+ def get_cn
358
+ handle = NicInfo::get_handle @objectclass
359
+ handle = "(unidentifiable entity #{object_id})" if !handle
360
+ if !@jcard.fns.empty?
361
+ return "#{@jcard.fns[ 0 ] } ( #{handle} )"
362
+ end
363
+ return handle
364
+ end
365
+
366
+ def to_node
367
+ DataNode.new( get_cn, nil, @selfhref )
368
+ end
369
+
370
+ end
371
+
372
+ end
data/lib/enum.rb ADDED
@@ -0,0 +1,47 @@
1
+ # Copyright (C) 2011,2012,2013,2014 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+
16
+ # Code based on "Enumerations and Ruby"
17
+ # http://www.rubyfleebie.com/enumerations-and-ruby/
18
+
19
+ module NicInfo
20
+
21
+ # A base class for enumerations
22
+ class Enum
23
+
24
+ def Enum.add_item( key, value )
25
+ @hash ||= {}
26
+ @hash[ key ] = value
27
+ end
28
+
29
+ def Enum.const_missing( key )
30
+ @hash[ key ]
31
+ end
32
+
33
+ def Enum.each
34
+ @hash.each { |key,value| yield( key, value ) }
35
+ end
36
+
37
+ def Enum.has_value? value
38
+ @hash.value?( value )
39
+ end
40
+
41
+ def Enum.values
42
+ @hash.values
43
+ end
44
+
45
+ end
46
+
47
+ end
data/lib/error_code.rb ADDED
@@ -0,0 +1,56 @@
1
+ # Copyright (C) 2011,2012,2013,2014 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ require 'config'
16
+ require 'nicinfo_logger'
17
+ require 'utils'
18
+
19
+ module NicInfo
20
+
21
+ # deals with RDAP error code structures
22
+ class ErrorCode
23
+
24
+ def display_error_code ec, config
25
+ config.logger.start_data_item
26
+ title = ec[ "title" ]
27
+ if title == nil
28
+ title = ""
29
+ end
30
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ ERROR ]", title
31
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "Code", ec[ "errorCode" ]
32
+ description = ec[ "description" ]
33
+ i = 1
34
+ description.each do |line|
35
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, i.to_s, line
36
+ i = i + 1
37
+ end
38
+ links = ec[ "links" ]
39
+ if links
40
+ alternate = NicInfo.get_alternate_link links
41
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "More", alternate if alternate
42
+ about = NicInfo.get_about_link links
43
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "About", about if about
44
+ tos = NicInfo.get_tos_link links
45
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "TOS", tos if tos
46
+ copyright = NicInfo.get_copyright_link links
47
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "(C)", copyright if copyright
48
+ license = NicInfo.get_license_link links
49
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "License", license if license
50
+ end
51
+ config.logger.end_data_item
52
+ end
53
+
54
+ end
55
+
56
+ end