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.
- checksums.yaml +7 -0
- data/bin/nicinfo +22 -0
- data/lib/autnum.rb +90 -0
- data/lib/bootstrap.rb +198 -0
- data/lib/bsfiles/asn.json +2326 -0
- data/lib/bsfiles/dns.json +25 -0
- data/lib/bsfiles/entity.json +52 -0
- data/lib/bsfiles/ipv4.json +244 -0
- data/lib/bsfiles/ipv6.json +97 -0
- data/lib/cache.rb +141 -0
- data/lib/common_json.rb +263 -0
- data/lib/common_names.rb +49 -0
- data/lib/config.rb +260 -0
- data/lib/constants.rb +113 -0
- data/lib/data_tree.rb +205 -0
- data/lib/demo/autnum.json +228 -0
- data/lib/demo/domain-dnr.json +695 -0
- data/lib/demo/domain-rir.json +569 -0
- data/lib/demo/domains.json +625 -0
- data/lib/demo/entities.json +545 -0
- data/lib/demo/entity-dnr.json +143 -0
- data/lib/demo/entity-rir.json +394 -0
- data/lib/demo/error-code.json +31 -0
- data/lib/demo/help.json +58 -0
- data/lib/demo/ip.json +306 -0
- data/lib/demo/nameservers.json +434 -0
- data/lib/demo/ns-simple.json +210 -0
- data/lib/demo/ns-very-simple.json +41 -0
- data/lib/demo/ns.json +63 -0
- data/lib/demo/simple-ip.json +41 -0
- data/lib/demo/simple.json +13 -0
- data/lib/domain.rb +203 -0
- data/lib/ds_data.rb +70 -0
- data/lib/entity.rb +372 -0
- data/lib/enum.rb +47 -0
- data/lib/error_code.rb +56 -0
- data/lib/female-first-names.txt +4275 -0
- data/lib/ip.rb +86 -0
- data/lib/key_data.rb +70 -0
- data/lib/last-names.txt +88799 -0
- data/lib/male-first-names.txt +1219 -0
- data/lib/nicinfo_logger.rb +370 -0
- data/lib/nicinfo_main.rb +1013 -0
- data/lib/notices.rb +110 -0
- data/lib/ns.rb +108 -0
- data/lib/utils.rb +189 -0
- metadata +90 -0
data/lib/common_json.rb
ADDED
@@ -0,0 +1,263 @@
|
|
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 'time'
|
19
|
+
require 'entity'
|
20
|
+
|
21
|
+
module NicInfo
|
22
|
+
|
23
|
+
def NicInfo.display_object_with_entities object, config, data_node
|
24
|
+
obj_array = object
|
25
|
+
unless object.instance_of? Array
|
26
|
+
obj_array = Array.new
|
27
|
+
obj_array << object
|
28
|
+
end
|
29
|
+
respobjs = ResponseObjSet.new config
|
30
|
+
obj_array.each do |array_object|
|
31
|
+
root = array_object.to_node
|
32
|
+
data_node.add_root( root )
|
33
|
+
if !array_object.entities.empty?
|
34
|
+
NicInfo::add_entity_nodes( array_object.entities, root )
|
35
|
+
end
|
36
|
+
respobjs.add array_object
|
37
|
+
NicInfo::add_entity_respobjs( array_object.entities, respobjs )
|
38
|
+
respobjs.associateEntities array_object.entities
|
39
|
+
end
|
40
|
+
data_node.to_normal_log( config.logger, true )
|
41
|
+
respobjs.display
|
42
|
+
end
|
43
|
+
|
44
|
+
def NicInfo.add_entity_nodes entities, node
|
45
|
+
entities.each do |entity|
|
46
|
+
entity_node = entity.to_node
|
47
|
+
node.add_child( entity_node )
|
48
|
+
NicInfo::add_entity_nodes( entity.entities, entity_node )
|
49
|
+
end if entities
|
50
|
+
end
|
51
|
+
|
52
|
+
def NicInfo.add_entity_respobjs entities, respobjs
|
53
|
+
entities.each do |entity|
|
54
|
+
respobjs.add( entity )
|
55
|
+
NicInfo::add_entity_respobjs( entity.entities, respobjs )
|
56
|
+
end if entities
|
57
|
+
end
|
58
|
+
|
59
|
+
# deals with common JSON RDAP structures
|
60
|
+
class CommonJson
|
61
|
+
|
62
|
+
def initialize config
|
63
|
+
@config = config
|
64
|
+
end
|
65
|
+
|
66
|
+
def process_entities objectclass
|
67
|
+
entities = Array.new
|
68
|
+
json_entities = NicInfo::get_entitites( objectclass )
|
69
|
+
json_entities.each do |json_entity|
|
70
|
+
entity = Entity.new( @config )
|
71
|
+
entity.process( json_entity )
|
72
|
+
entities << entity
|
73
|
+
end if json_entities
|
74
|
+
return entities
|
75
|
+
end
|
76
|
+
|
77
|
+
def display_remarks objectclass
|
78
|
+
remarks = objectclass[ "remarks" ]
|
79
|
+
if (Notices::is_excessive_notice(remarks, @config)) && (@config.logger.data_amount != NicInfo::DataAmount::EXTRA_DATA)
|
80
|
+
@config.logger.datum "Excessive Remarks", "Use \"-V\" or \"--data extra\" to see them."
|
81
|
+
else
|
82
|
+
if remarks
|
83
|
+
if remarks.instance_of?( Array )
|
84
|
+
remarks.each do |remark|
|
85
|
+
if remark.instance_of?( Hash )
|
86
|
+
title = remark[ "title" ]
|
87
|
+
@config.logger.datum "Remarks", "-- #{title} --" if title
|
88
|
+
descriptions = NicInfo::get_descriptions remark, @config
|
89
|
+
i = 1
|
90
|
+
descriptions.each do |line|
|
91
|
+
if !title && i == 1
|
92
|
+
@config.logger.datum "Remarks", line
|
93
|
+
elsif i != 1 || title
|
94
|
+
@config.logger.datum i.to_s, line
|
95
|
+
end
|
96
|
+
i = i + 1
|
97
|
+
end if descriptions
|
98
|
+
links = NicInfo::get_links remark, @config
|
99
|
+
if links
|
100
|
+
@config.logger.datum "More", NicInfo::get_alternate_link( links )
|
101
|
+
@config.logger.datum "About", NicInfo::get_about_link( links )
|
102
|
+
@config.logger.datum "TOS", NicInfo::get_tos_link( links )
|
103
|
+
@config.logger.datum "(C)", NicInfo::get_copyright_link( links )
|
104
|
+
@config.logger.datum "License", NicInfo::get_license_link( links )
|
105
|
+
end
|
106
|
+
else
|
107
|
+
@config.conf_msgs << "remark is not an object."
|
108
|
+
end
|
109
|
+
end
|
110
|
+
else
|
111
|
+
@config.conf_msgs << "'remarks' is not an array."
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def display_string_array json_name, display_name, json_data, data_amount
|
118
|
+
arr = json_data[ json_name ]
|
119
|
+
if arr
|
120
|
+
if arr.instance_of?( Array )
|
121
|
+
new_arr = Array.new
|
122
|
+
arr.each do |str|
|
123
|
+
if str.instance_of?( String )
|
124
|
+
new_arr << NicInfo::capitalize( str )
|
125
|
+
else
|
126
|
+
@config.conf_msgs << "value in string array is not a string."
|
127
|
+
end
|
128
|
+
end
|
129
|
+
@config.logger.info data_amount, display_name, new_arr.join( ", " )
|
130
|
+
else
|
131
|
+
@config.conf_msgs << "'#{json_name}' is not an array."
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def display_status objectclass
|
137
|
+
display_string_array "status", "Status", objectclass, DataAmount::NORMAL_DATA
|
138
|
+
end
|
139
|
+
|
140
|
+
def display_port43 objectclass
|
141
|
+
@config.logger.extra "Port 43 Whois", objectclass[ "port43" ]
|
142
|
+
end
|
143
|
+
|
144
|
+
def display_links cn, objectclass
|
145
|
+
links = NicInfo::get_links objectclass, @config
|
146
|
+
if links
|
147
|
+
@config.logger.extra "Links", "-- for #{cn} --"
|
148
|
+
@config.logger.extra "Reference", NicInfo::get_self_link( links )
|
149
|
+
@config.logger.extra "More", NicInfo::get_alternate_link( links )
|
150
|
+
@config.logger.extra "About", NicInfo::get_about_link( links )
|
151
|
+
@config.logger.extra "TOS", NicInfo::get_tos_link( links )
|
152
|
+
@config.logger.extra "(C)", NicInfo::get_copyright_link( links )
|
153
|
+
@config.logger.extra "License", NicInfo::get_license_link( links )
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def display_events objectclass
|
158
|
+
events = objectclass[ "events" ]
|
159
|
+
if events
|
160
|
+
if events.instance_of?( Array )
|
161
|
+
events.each do |event|
|
162
|
+
item_name = NicInfo::capitalize( event[ "eventAction" ] )
|
163
|
+
item_value = Time.parse( event[ "eventDate" ] ).rfc2822
|
164
|
+
actor = event[ "eventActor" ]
|
165
|
+
if actor
|
166
|
+
item_value << " by #{actor}"
|
167
|
+
end
|
168
|
+
@config.logger.datum item_name, item_value
|
169
|
+
end
|
170
|
+
else
|
171
|
+
@config.conf_msgs << "'events' is not an array."
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def display_as_events_actors asEventActors
|
177
|
+
asEventActors.each do |asEventActor|
|
178
|
+
item_name = NicInfo::capitalize( asEventActor.eventAction )
|
179
|
+
item_value = Time.parse( asEventActor.eventDate ).rfc2822
|
180
|
+
item_value << " by #{asEventActor.entity_cn}"
|
181
|
+
@config.logger.datum item_name, item_value
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def display_public_ids objectclass
|
186
|
+
public_ids = objectclass[ "publicIds" ]
|
187
|
+
if public_ids
|
188
|
+
if public_ids.instance_of?( Array )
|
189
|
+
public_ids.each do |public_id|
|
190
|
+
if public_id.instance_of?( Hash )
|
191
|
+
item_name = "Public ID"
|
192
|
+
item_value = public_id[ "identifier" ]
|
193
|
+
authority = public_id[ "type" ]
|
194
|
+
item_value << " (#{authority})" if authority
|
195
|
+
@config.logger.datum item_name, item_value
|
196
|
+
else
|
197
|
+
@config.conf_msgs << "public id in array 'publicIds' is not an object."
|
198
|
+
end
|
199
|
+
end
|
200
|
+
else
|
201
|
+
@config.conf_msgs << "'publicIds' is not an array."
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
class EventActor
|
209
|
+
attr_accessor :eventAction, :eventDate, :related, :entity_cn
|
210
|
+
end
|
211
|
+
|
212
|
+
# for keeping track of objects to display
|
213
|
+
class ResponseObjSet
|
214
|
+
|
215
|
+
def initialize config
|
216
|
+
@config = config
|
217
|
+
@arr = Array.new #for keeping track of insertion order
|
218
|
+
@set = Hash.new
|
219
|
+
@self_links = Hash.new
|
220
|
+
end
|
221
|
+
|
222
|
+
def add respObj
|
223
|
+
if respObj.instance_of? Array
|
224
|
+
respObj.each do |obj|
|
225
|
+
add obj
|
226
|
+
end
|
227
|
+
else
|
228
|
+
if !@set[ respObj.get_cn ]
|
229
|
+
@set[ respObj.get_cn ] = respObj
|
230
|
+
@arr << respObj
|
231
|
+
self_link = NicInfo.get_self_link( NicInfo.get_links( respObj.objectclass, @config ) )
|
232
|
+
@self_links[ self_link ] = respObj if self_link
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def display
|
238
|
+
@arr.each do |object|
|
239
|
+
object.display
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def associateEventActor eventActor
|
244
|
+
return if !eventActor or !eventActor.related
|
245
|
+
associate = @self_links[ eventActor.related ]
|
246
|
+
if associate
|
247
|
+
associate.asEventActors << eventActor
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def associateEntities entities
|
252
|
+
entities.each do |entity|
|
253
|
+
associateEntities entity.entities if !entity.entities.empty?
|
254
|
+
entity.asEvents.each do |asEvent|
|
255
|
+
asEvent.entity_cn = entity.get_cn
|
256
|
+
associateEventActor asEvent
|
257
|
+
end
|
258
|
+
end if entities
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
data/lib/common_names.rb
ADDED
@@ -0,0 +1,49 @@
|
|
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
|
+
module NicInfo
|
17
|
+
|
18
|
+
def NicInfo::is_last_name name
|
19
|
+
is_name "last-names.txt", name
|
20
|
+
end
|
21
|
+
|
22
|
+
def NicInfo::is_male_name name
|
23
|
+
is_name "male-first-names.txt", name
|
24
|
+
end
|
25
|
+
|
26
|
+
def NicInfo::is_female_name name
|
27
|
+
is_name "female-first-names.txt", name
|
28
|
+
end
|
29
|
+
|
30
|
+
def NicInfo::is_name file_name, name
|
31
|
+
retval = false
|
32
|
+
name.gsub! '*',''
|
33
|
+
names = name.split( ' ' )
|
34
|
+
|
35
|
+
file = File.new( File.join( File.dirname( __FILE__ ) , file_name ), "r" )
|
36
|
+
file.each_line do |line|
|
37
|
+
names.each do |n|
|
38
|
+
if line.start_with?( n )
|
39
|
+
retval = true
|
40
|
+
break
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
file.close
|
45
|
+
|
46
|
+
return retval
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,260 @@
|
|
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
|
+
require 'fileutils'
|
17
|
+
require 'nicinfo_logger'
|
18
|
+
require 'yaml'
|
19
|
+
require 'ostruct'
|
20
|
+
require 'constants'
|
21
|
+
|
22
|
+
module NicInfo
|
23
|
+
|
24
|
+
# Handles configuration of the application
|
25
|
+
class Config
|
26
|
+
|
27
|
+
attr_accessor :logger, :config, :rdap_cache_dir, :options, :conf_msgs, :rdap_bootstrap_dir
|
28
|
+
|
29
|
+
# Intializes the configuration with a place to look for the config file
|
30
|
+
# If the file doesn't exist, a default is used.
|
31
|
+
# Main routines will do something like NicInfo::Config.new( NicInfo::Config.formulate_app_data_dir() )
|
32
|
+
def initialize app_data
|
33
|
+
|
34
|
+
@options = OpenStruct.new
|
35
|
+
@app_data = app_data
|
36
|
+
@logger = NicInfo::Logger.new
|
37
|
+
@conf_msgs = Array.new
|
38
|
+
|
39
|
+
config_file_name = Config.formulate_config_file_name( @app_data )
|
40
|
+
if File.exist?( config_file_name )
|
41
|
+
@config = YAML.load( File.open( config_file_name ) )
|
42
|
+
else
|
43
|
+
@config = YAML.load( @@yaml_config )
|
44
|
+
end
|
45
|
+
|
46
|
+
configure_logger()
|
47
|
+
end
|
48
|
+
|
49
|
+
# Setups work space for the application and lays down default config
|
50
|
+
# If directory is nil, then it uses its own value
|
51
|
+
def setup_workspace
|
52
|
+
|
53
|
+
@rdap_bootstrap_dir = File.join( @app_data, NicInfo::BOOTSTRAP_FILE_DIR )
|
54
|
+
if ! File.exist?( @app_data )
|
55
|
+
|
56
|
+
@logger.trace "Creating configuration in " + @app_data
|
57
|
+
Dir.mkdir( @app_data )
|
58
|
+
f = File.open( Config.formulate_config_file_name( @app_data ), "w" )
|
59
|
+
f.puts @@yaml_config
|
60
|
+
f.close
|
61
|
+
|
62
|
+
@rdap_cache_dir = File.join( @app_data, "rdap_cache" )
|
63
|
+
Dir.mkdir( @rdap_cache_dir )
|
64
|
+
|
65
|
+
copy_bsfiles
|
66
|
+
|
67
|
+
else
|
68
|
+
|
69
|
+
if @options.reset_config
|
70
|
+
config_file_name = Config.formulate_config_file_name( @app_data )
|
71
|
+
@logger.trace "Resetting configuration in " + config_file_name
|
72
|
+
f = File.open( config_file_name, "w" )
|
73
|
+
f.puts @@yaml_config
|
74
|
+
f.close
|
75
|
+
@config = YAML.load( File.open( config_file_name ) )
|
76
|
+
@logger.trace "Resetting bootstrap files in " + @rdap_bootstrap_dir
|
77
|
+
begin
|
78
|
+
FileUtils::rm_r( @rdap_bootstrap_dir )
|
79
|
+
rescue Errno::ENOENT
|
80
|
+
# do nothing
|
81
|
+
end
|
82
|
+
copy_bsfiles
|
83
|
+
end
|
84
|
+
@logger.trace "Using configuration found in " + @app_data
|
85
|
+
@rdap_cache_dir = File.join( @app_data, "rdap_cache" )
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def copy_bsfiles
|
92
|
+
src_dir = File.join( File.dirname( __FILE__ ), NicInfo::BOOTSTRAP_FILE_DIR )
|
93
|
+
FileUtils::cp_r( src_dir, @rdap_bootstrap_dir )
|
94
|
+
end
|
95
|
+
|
96
|
+
def save name, data
|
97
|
+
data_file = File.open( File.join( @app_data, name ), "w" )
|
98
|
+
data_file.write data
|
99
|
+
data_file.close
|
100
|
+
end
|
101
|
+
|
102
|
+
def save_as_yaml name, obj
|
103
|
+
data_file = File.open( File.join( @app_data, name ), "w" )
|
104
|
+
data_file.puts YAML::dump(obj)
|
105
|
+
data_file.close
|
106
|
+
end
|
107
|
+
|
108
|
+
def load name
|
109
|
+
data_file = File.open( File.join( @app_data, name ), "r" )
|
110
|
+
retval = data_file.read
|
111
|
+
data_file.close
|
112
|
+
return retval
|
113
|
+
end
|
114
|
+
|
115
|
+
def load_as_yaml name, default = nil
|
116
|
+
file_name = make_file_name( name )
|
117
|
+
retval = default
|
118
|
+
if File.exists?( file_name )
|
119
|
+
data_file = File.open( File.join( @app_data, name ), "r" )
|
120
|
+
retval = YAML::load( data_file )
|
121
|
+
data_file.close
|
122
|
+
elsif default == nil
|
123
|
+
raise "#{file_name} does not exist"
|
124
|
+
end
|
125
|
+
return retval
|
126
|
+
end
|
127
|
+
|
128
|
+
def make_file_name name
|
129
|
+
File.join( @app_data, name )
|
130
|
+
end
|
131
|
+
|
132
|
+
# Configures the logger
|
133
|
+
def configure_logger
|
134
|
+
output = @config[ NicInfo::OUTPUT ]
|
135
|
+
return if output == nil
|
136
|
+
|
137
|
+
@logger.message_level = output[ NicInfo::MESSAGES ]
|
138
|
+
@logger.validate_message_level
|
139
|
+
|
140
|
+
messages_file = output[ NicInfo::MESSAGES_FILE ]
|
141
|
+
if messages_file != nil
|
142
|
+
@logger.message_out = File.open( messages_file, "w+" )
|
143
|
+
end
|
144
|
+
|
145
|
+
@logger.data_amount = output[ NicInfo::DATA ]
|
146
|
+
@logger.validate_data_amount
|
147
|
+
|
148
|
+
data_file = output[ NicInfo::DATA_FILE ]
|
149
|
+
if data_file != nil
|
150
|
+
@logger.data_out= File.open( data_file, "w+" )
|
151
|
+
end
|
152
|
+
|
153
|
+
@logger.pager=output[ NicInfo::PAGER ]
|
154
|
+
@logger.auto_wrap=output[ NicInfo::AUTO_WRAP ]
|
155
|
+
@logger.default_width=output[ NicInfo::DEFAULT_WIDTH ]
|
156
|
+
@logger.detect_width=output[ NicInfo::DETECT_WIDTH ]
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.clean
|
160
|
+
|
161
|
+
FileUtils::rm_r( formulate_app_data_dir() )
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.formulate_app_data_dir
|
166
|
+
if RUBY_PLATFORM =~ /win32/
|
167
|
+
data_dir = File.join(ENV['APPDATA'], "NicInfo")
|
168
|
+
elsif RUBY_PLATFORM =~ /linux/
|
169
|
+
data_dir = File.join(ENV['HOME'], ".NicInfo")
|
170
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
171
|
+
data_dir = File.join(ENV['HOME'], ".NicInfo")
|
172
|
+
elsif RUBY_PLATFORM =~ /freebsd/
|
173
|
+
data_dir = File.join(ENV['HOME'], ".NicInfo")
|
174
|
+
else
|
175
|
+
raise ScriptError, "system platform is not recognized."
|
176
|
+
end
|
177
|
+
return data_dir
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.formulate_config_file_name data_dir
|
181
|
+
File.join( data_dir, "config.yaml" )
|
182
|
+
end
|
183
|
+
|
184
|
+
@@yaml_config = <<YAML_CONFIG
|
185
|
+
output:
|
186
|
+
|
187
|
+
# possible values are NONE, SOME, ALL
|
188
|
+
messages: SOME
|
189
|
+
|
190
|
+
# If specified, messages goes to this file
|
191
|
+
# otherwise, leave it commented out to go to stderr
|
192
|
+
#messages_file: /tmp/NicInfo.messages
|
193
|
+
|
194
|
+
# possible values are TERSE, NORMAL, EXTRA
|
195
|
+
data: NORMAL
|
196
|
+
|
197
|
+
# If specified, data goest to this file
|
198
|
+
# otherwise, leave it commented out to go to stdout
|
199
|
+
#data_file: /tmp/NicInfo.data
|
200
|
+
|
201
|
+
# Page output with system pager when appropriate.
|
202
|
+
pager: true
|
203
|
+
|
204
|
+
# Automatically wrap text when possible.
|
205
|
+
auto_wrap: true
|
206
|
+
|
207
|
+
# When auto wrapping, automatically determine the terminal
|
208
|
+
# width if possible
|
209
|
+
detect_width: true
|
210
|
+
|
211
|
+
# The default terminal width if it is not to be detected
|
212
|
+
# or cannot be detected
|
213
|
+
default_width: 80
|
214
|
+
|
215
|
+
cache:
|
216
|
+
|
217
|
+
# The maximum age an item from the cache will be used.
|
218
|
+
# This value is in seconds
|
219
|
+
cache_expiry: 3600
|
220
|
+
|
221
|
+
# The maximum age an item will be in the cache before it is evicted
|
222
|
+
# when the cache is cleaned.
|
223
|
+
# This value is in seconds
|
224
|
+
cache_eviction: 604800
|
225
|
+
|
226
|
+
# Use the cache.
|
227
|
+
# Values are true or false
|
228
|
+
use_cache: true
|
229
|
+
|
230
|
+
# Automatically clean the cache.
|
231
|
+
clean_cache: true
|
232
|
+
|
233
|
+
bootstrap:
|
234
|
+
|
235
|
+
# The base or bootstrap URL. Specifying this will bypass all built-in bootstrapping.
|
236
|
+
#base_url: http://rdappilot.arin.net/rdapbootstrap
|
237
|
+
|
238
|
+
help_root_url: http://rdappilot.arin.net/rdapbootstrap
|
239
|
+
|
240
|
+
entity_root_url: http://rdappilot.arin.net/restfulwhois/rdap
|
241
|
+
|
242
|
+
ip_root_url: http://rdappilot.arin.net/restfulwhois/rdap
|
243
|
+
|
244
|
+
as_root_url: http://rdappilot.arin.net/restfulwhois/rdap
|
245
|
+
|
246
|
+
domain_root_url: http://rdappilot.arin.net/restfulwhois/rdap
|
247
|
+
|
248
|
+
ns_root_url: http://rdappilot.arin.net/restfulwhois/rdap
|
249
|
+
|
250
|
+
search:
|
251
|
+
|
252
|
+
# Substring matching
|
253
|
+
# NOT YET USED
|
254
|
+
substring: true
|
255
|
+
|
256
|
+
YAML_CONFIG
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
data/lib/constants.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (C) 2011,2012,2013,2014,2015 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
|
+
# IPv4 and IPv6 regular expressions are credited to Mike Poulson and are found here:
|
17
|
+
# http://blogs.msdn.com/b/mpoulson/archive/2005/01/10/350037.aspx
|
18
|
+
|
19
|
+
module NicInfo
|
20
|
+
|
21
|
+
VERSION = "0.2.0"
|
22
|
+
VERSION_LABEL = "NicInfo v." + VERSION
|
23
|
+
COPYRIGHT = "Copyright (c) 2011,2012,2013,2014,2015 American Registry for Internet Numbers (ARIN)"
|
24
|
+
|
25
|
+
# regular expressions
|
26
|
+
NET_HANDLE_REGEX = /^NET-.*/i
|
27
|
+
NET6_HANDLE_REGEX = /^NET6-.*/i
|
28
|
+
AS_REGEX = /^[0-9]{1,10}$/
|
29
|
+
ASN_REGEX = /^AS[0-9]{1,20}$/i
|
30
|
+
IP4_ARPA = /\.in-addr\.arpa[\.]?/i
|
31
|
+
IP6_ARPA = /\.ip6\.arpa[\.]?/i
|
32
|
+
DATA_TREE_ADDR_REGEX = /\d=$/
|
33
|
+
DOMAIN_REGEX = /^([\S\-]+\.?)+\.([a-z][a-z0\-]+)\.?$/i
|
34
|
+
DOMAIN_SRCH_REGEX = /^([\S\-]+\.?)+\.([a-z][a-z0\-\*]+)\.?$/i
|
35
|
+
NS_REGEX = /^ns[0-9]\.([\S\-]+\.?)+\.([a-z][a-z0\-]+)\.?$/i
|
36
|
+
URL_REGEX = /^(http|https):\/\/.*/
|
37
|
+
ENTITY_REGEX = /^.*\-.*/
|
38
|
+
|
39
|
+
# IPv4 and IPv6 regular expressions are credited to Mike Poulson and are found here:
|
40
|
+
# http://blogs.msdn.com/b/mpoulson/archive/2005/01/10/350037.aspx
|
41
|
+
IPV4_REGEX = /\A(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\z/
|
42
|
+
IPV6_REGEX = /\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\z/
|
43
|
+
IPV6_HEXCOMPRESS_REGEX = /\A((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)\z/
|
44
|
+
|
45
|
+
#File Name Constants
|
46
|
+
LASTTREE_YAML = "lasttree.yaml"
|
47
|
+
DEMO_DIR = "demo"
|
48
|
+
BOOTSTRAP_FILE_DIR = "bsfiles"
|
49
|
+
ASN_BOOTSTRAP = "asn.json"
|
50
|
+
DNS_BOOTSTRAP = "dns.json"
|
51
|
+
ENTITY_BOOTSTRAP = "entity.json"
|
52
|
+
IPV4_BOOTSTRAP = "ipv4.json"
|
53
|
+
IPV6_BOOTSTRAP = "ipv6.json"
|
54
|
+
|
55
|
+
# Config constants
|
56
|
+
OUTPUT = "output"
|
57
|
+
MESSAGES = "messages"
|
58
|
+
MESSAGES_FILE = "messages_file"
|
59
|
+
DATA = "data"
|
60
|
+
DATA_FILE = "data_file"
|
61
|
+
PAGER = "pager"
|
62
|
+
AUTO_WRAP = "auto_wrap"
|
63
|
+
DETECT_WIDTH = "detect_width"
|
64
|
+
DEFAULT_WIDTH = "default_width"
|
65
|
+
CACHE = "cache"
|
66
|
+
CACHE_EXPIRY = "cache_expiry"
|
67
|
+
CACHE_EVICTION = "cache_eviction"
|
68
|
+
USE_CACHE = "use_cache"
|
69
|
+
CLEAN_CACHE = "clean_cache"
|
70
|
+
BOOTSTRAP = "bootstrap"
|
71
|
+
BOOTSTRAP_URL = "bootstrap_url"
|
72
|
+
HELP_ROOT_URL = "help_root_url"
|
73
|
+
ENTITY_ROOT_URL = "entity_root_url"
|
74
|
+
IP_ROOT_URL = "ip_root_url"
|
75
|
+
AS_ROOT_URL = "as_root_url"
|
76
|
+
DOMAIN_ROOT_URL = "domain_root_url"
|
77
|
+
NS_ROOT_URL = "ns_root_url"
|
78
|
+
ARIN_URL = "arin_url"
|
79
|
+
RIPE_URL = "ripe_url"
|
80
|
+
LACNIC_URL = "lacnic_url"
|
81
|
+
APNIC_URL = "apnic_url"
|
82
|
+
AFRINIC_URL = "afrinic_url"
|
83
|
+
COM_URL = "com_url"
|
84
|
+
NET_URL = "net_url"
|
85
|
+
ORG_URL = "org_url"
|
86
|
+
INFO_URL = "info_url"
|
87
|
+
BIZ_URL = "biz_url"
|
88
|
+
SEARCH = "search"
|
89
|
+
SUBSTRING = "substring"
|
90
|
+
|
91
|
+
# NicInfo values
|
92
|
+
NICINFO_DEMO_URL = "nicInfo_demoUrl"
|
93
|
+
NICINFO_DEMO_HINT = "nicInfo_demoHint"
|
94
|
+
NICINFO_DEMO_ERROR = "nicInfo_demoError"
|
95
|
+
|
96
|
+
# Other constants
|
97
|
+
RDAP_CONTENT_TYPE = "application/rdap+json"
|
98
|
+
JSON_CONTENT_TYPE = "application/json"
|
99
|
+
|
100
|
+
DNSSEC_ALGORITHMS = {
|
101
|
+
0 => "reserved",
|
102
|
+
1 => "RSA/MD5",
|
103
|
+
2 => "Diffie-Hellman",
|
104
|
+
3 => "DSA/SHA-1",
|
105
|
+
4 => "Elliptic Curve",
|
106
|
+
5 => "RSA/SHA-1",
|
107
|
+
252 => "Indirect",
|
108
|
+
253 => "Private DNS",
|
109
|
+
254 => "Private OID",
|
110
|
+
255 => "reserved"
|
111
|
+
}
|
112
|
+
|
113
|
+
end
|