~ubuntu-branches/ubuntu/trusty/zonecheck/trusty

« back to all changes in this revision

Viewing changes to .pc/80_no-rubygems.dpatch/zc/zc.rb

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Delafond
  • Date: 2010-07-08 12:55:39 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100708125539-gazuzu1eb58l3tot
Tags: 3.0.2-1
* New upstream release (Closes: #587419).
* Updated watch file.
* Bumped up Standards revision.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/local/bin/ruby
2
 
# $Id: zc.rb,v 1.125 2010/06/07 08:51:25 chabannf Exp $
3
 
 
4
 
5
 
# CONTACT     : zonecheck@nic.fr
6
 
# AUTHOR      : Stephane D'Alu <sdalu@nic.fr>
7
 
#
8
 
# CREATED     : 2002/07/18 10:29:53
9
 
# REVISION    : $Revision: 1.125 $ 
10
 
# DATE        : $Date: 2010/06/07 08:51:25 $
11
 
#
12
 
# CONTRIBUTORS: (see also CREDITS file)
13
 
#
14
 
#
15
 
# LICENSE     : GPL v3
16
 
# COPYRIGHT   : AFNIC (c) 2003
17
 
#
18
 
# This file is part of ZoneCheck.
19
 
#
20
 
# ZoneCheck is free software; you can redistribute it and/or modify it
21
 
# under the terms of the GNU General Public License as published by
22
 
# the Free Software Foundation; either version 3 of the License, or
23
 
# (at your option) any later version.
24
 
25
 
# ZoneCheck is distributed in the hope that it will be useful, but
26
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
27
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28
 
# General Public License for more details.
29
 
#
30
 
# You should have received a copy of the GNU General Public License
31
 
# along with ZoneCheck; if not, write to the Free Software Foundation,
32
 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33
 
#
34
 
 
35
 
 
36
 
## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
 
##
38
 
## WARN: when editing this file on installed ZoneCheck, you should
39
 
##       keep in mind that some ZoneCheck variant (cgi, ...) are 
40
 
##       more or less strongly connected with this file by:
41
 
##       - a copy     : only THIS file will be modified
42
 
##       - a hardlink : depending of your editor behaviour when
43
 
##                      saving the file, all the files will hold
44
 
##                      the modification OR only this file will.
45
 
##       - a symlink  : no problem should occured (except if on Windows)
46
 
##
47
 
## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48
 
 
49
 
 
50
 
## --> CUSTOMIZATION <-- #############################################
51
 
52
 
# You shouldn't really need to change these values:
53
 
#  - This is normally automatically done when performing a: make install
54
 
#  - Setting the environment variable ZC_INSTALL_PATH should be enough
55
 
#     for testing the code
56
 
#
57
 
 
58
 
## Installation path
59
 
ZC_INSTALL_PATH         = (ENV['ZC_INSTALL_PATH'] || (ENV['HOME'] || '/homes/sdalu') + '/Repository/zonecheck').dup.untaint
60
 
 
61
 
## Directories
62
 
ZC_DIR                  = "#{ZC_INSTALL_PATH}/zc"
63
 
ZC_LIB                  = "#{ZC_INSTALL_PATH}/lib"
64
 
 
65
 
ZC_CONFIG_DIR           = ENV['ZC_CONFIG_DIR']       || "#{ZC_INSTALL_PATH}/etc/zonecheck"
66
 
ZC_LOCALIZATION_DIR     = ENV['ZC_LOCALIZATION_DIR'] || "#{ZC_INSTALL_PATH}/locale"
67
 
ZC_TEST_DIR             = ENV['ZC_TEST_DIR']         || "#{ZC_INSTALL_PATH}/test"
68
 
 
69
 
## Configuration
70
 
ZC_CONFIG_FILE          = ENV['ZC_CONFIG_FILE'] || 'zc.conf'
71
 
 
72
 
## Lang
73
 
ZC_LANG_FILE            = 'zc.%s'
74
 
ZC_LANG_DEFAULT         = 'en'          # can have an enconding: en.ascii
75
 
 
76
 
## Message catalog fallback
77
 
ZC_MSGCAT_FALLBACK      = 'en'          # don't specifie an encoding here
78
 
 
79
 
## Input methods
80
 
ZC_DEFAULT_INPUT        = 'cli'
81
 
 
82
 
ZC_CGI_ENV_KEYS         = [ 'GATEWAY_INTERFACE', 'SERVER_ADDR' ]
83
 
ZC_CGI_EXT              = 'cgi'
84
 
 
85
 
## Publisher
86
 
ZC_HTML_PATH            = ENV['ZC_HTML_PATH'] || "#{ZC_INSTALL_PATH}/www"
87
 
 
88
 
 
89
 
## Contact / Details
90
 
ZC_COPYRIGHT            = 'AFNIC (c) 2003'
91
 
ZC_CONTACT              = 'ZoneCheck <zonecheck@nic.fr>'
92
 
ZC_MAINTAINER           = 'Stephane D\'Alu <sdalu@nic.fr>'
93
 
 
94
 
## Internal
95
 
ZC_XML_PARSER           = ENV['ZC_XML_PARSER'] 
96
 
ZC_IP_STACK             = ENV['ZC_IP_STACK'] || '46'
97
 
 
98
 
## --> END OF CUSTOMIZATION <-- ######################################
99
 
 
100
 
 
101
 
#
102
 
# Identification
103
 
#
104
 
ZC_CVS_NAME     = %q$Name: ZC-3_0_0 $
105
 
ZC_NAME         = 'ZoneCheck'
106
 
ZC_VERSION      = (Proc::new { 
107
 
                       n = ZC_CVS_NAME.split[1]
108
 
                       n = /^ZC-(.*)/.match(n) unless n.nil?
109
 
                       n = n[1]                unless n.nil?
110
 
                       n = n.gsub(/_/, '.')    unless n.nil?
111
 
                       
112
 
                       n || '<unreleased>'
113
 
                   }).call
114
 
PROGNAME        = File.basename($0)
115
 
 
116
 
 
117
 
#
118
 
# Constants
119
 
#
120
 
EXIT_OK         =  0    # Everything went fine, no fatal error, domain ok
121
 
EXIT_FAILED     =  1    # The program completed but the result is negative
122
 
EXIT_TIMEOUT    =  2    # The program completed but the result is negative
123
 
                        #  due to timeout.
124
 
EXIT_ABORTED    =  3    # The user aborted the program before completion
125
 
EXIT_ERROR      =  4    # An error unrelated to the result occured
126
 
EXIT_USAGE      =  9    # The user didn't bother reading the man page
127
 
 
128
 
 
129
 
#
130
 
# Sanity check
131
 
#
132
 
m = /^(\d+)\.(\d+)\./.match(RUBY_VERSION)
133
 
if (m[1].to_i <= 1) && (m[2].to_i < 8)
134
 
    $stderr.puts "#{PROGNAME}: ruby version 1.8.0 at least is required."
135
 
    exit EXIT_ERROR
136
 
end
137
 
 
138
 
 
139
 
#
140
 
# Run at safe level 1
141
 
#  A greater safe level is unfortunately not possible due to some 
142
 
#  low level operations in the Dnsruby library
143
 
#
144
 
$SAFE = 0       # REXML BUG
145
 
 
146
 
 
147
 
#
148
 
# Ensure '.' is not one of the possible path (too much trouble)
149
 
# Add zonecheck directories to ruby path
150
 
#
151
 
$LOAD_PATH.delete_if { |path| path == '.' }
152
 
$LOAD_PATH << ZC_DIR << ZC_LIB
153
 
 
154
 
 
155
 
#
156
 
# Version / Name / Contact
157
 
#
158
 
$zc_version     ||= ZC_VERSION
159
 
$zc_name        ||= ZC_NAME
160
 
$zc_contact     ||= ZC_CONTACT
161
 
 
162
 
#
163
 
# Config directory
164
 
165
 
$zc_config_dir  ||= ZC_CONFIG_DIR
166
 
$zc_config_file ||= ZC_CONFIG_FILE
167
 
 
168
 
#
169
 
# Custom
170
 
#
171
 
$zc_custom      ||= 'zc-custom'
172
 
 
173
 
#
174
 
# Internal
175
 
#
176
 
$zc_xml_parser  ||= ZC_XML_PARSER
177
 
 
178
 
# Resolver configuration
179
 
$rootserver_hintfile    = "#{$zc_config_dir}/rootservers"
180
 
 
181
 
 
182
 
#
183
 
# Requierement
184
 
#
185
 
# Standard Ruby libraries
186
 
require 'socket'
187
 
 
188
 
# Modification to standard/core ruby classes
189
 
require 'ext/array'
190
 
require 'ext/file'
191
 
require 'ext/myxml'
192
 
 
193
 
 
194
 
# ZoneCheck component
195
 
require 'zc-locale'
196
 
require 'msgcat'
197
 
require 'console'
198
 
require 'zonecheck'
199
 
require 'dbg'
200
 
 
201
 
 
202
 
#
203
 
# Debugger object
204
 
#  (earlier initialization, can also be set via input interface)
205
 
#
206
 
$dbg       = ZoneCheck::DBG::new
207
 
$dbg.level = ENV['ZC_DEBUG'] if ENV['ZC_DEBUG']
208
 
 
209
 
 
210
 
begin 
211
 
  require 'rubygems'
212
 
rescue LoadError => e
213
 
  $dbg.msg(ZoneCheck::DBG::INIT, "Unable to require rubygems (#{e})")
214
 
  $stderr.puts "ERROR: You have to install rubygems and Dnsruby in order to execute ZoneCheck"
215
 
  exit EXIT_ERROR
216
 
end
217
 
 
218
 
# External libraries
219
 
begin 
220
 
  require 'dnsruby'
221
 
rescue LoadError => e
222
 
  $dbg.msg(ZoneCheck::DBG::INIT, "Unable to require dnsruby (#{e})")
223
 
  $stderr.puts "ERROR: You have to install Dnsruby in order to execute ZoneCheck"
224
 
  exit EXIT_ERROR
225
 
end
226
 
 
227
 
if Dnsruby.version < 1.47
228
 
  $dbg.msg(ZoneCheck::DBG::INIT, "Unable to require dnsruby (#{e})")
229
 
  $stderr.puts "ERROR: You have to install at least Dnsruby 1.47 in order to execute ZoneCheck"
230
 
  exit EXIT_ERROR
231
 
end
232
 
 
233
 
include ZoneCheck
234
 
 
235
 
#
236
 
# XML parser
237
 
#
238
 
ENV['XML_CATALOG_FILES'] = "#{ZC_DIR}/data/catalog.xml"
239
 
 
240
 
$dbg.msg(DBG::INIT) {
241
 
    shrinked_path = File.shrink_path(ENV['XML_CATALOG_FILES'], ':')
242
 
    "Using XML_CATALOG_FILES=#{shrinked_path}"
243
 
}
244
 
$dbg.msg(DBG::INIT) { "Using XML parser: #{MyXML::Implementation}" }
245
 
 
246
 
 
247
 
 
248
 
#
249
 
# IPv4/IPv6 stack detection
250
 
#  WARN: doesn't implies that we have also the connectivity
251
 
#
252
 
$ipv4_stack = !(ZC_IP_STACK =~ /4/).nil?
253
 
$ipv6_stack = !(ZC_IP_STACK =~ /6/).nil?
254
 
$ipv4_stack = $ipv6_stack = true if !$ipv4_stack && !$ipv6_stack
255
 
 
256
 
$ipv4_stack &&= begin
257
 
                    UDPSocket::new(Socket::AF_INET).close
258
 
                    true
259
 
                rescue NameError,      # if Socket::AF_INET doesn't exist
260
 
                        SystemCallError # for the Errno::EAFNOSUPPORT error
261
 
                    false
262
 
                end
263
 
$ipv6_stack &&= begin
264
 
                    UDPSocket::new(Socket::AF_INET6).close
265
 
                    true
266
 
                rescue NameError,      # if Socket::AF_INET6 doesn't exist
267
 
                        SystemCallError # for the Errno::EAFNOSUPPORT error
268
 
                    false
269
 
                end
270
 
 
271
 
 
272
 
#
273
 
# Internationalisation
274
 
#  WARN: default locale is mandatory as no human messages are
275
 
#        present in the code (except for debugging purpose)
276
 
#
277
 
begin
278
 
    $supported_languages = ["en","fr"]
279
 
  
280
 
    # Initialize locale
281
 
    $locale = Locale::new
282
 
    $locale.lang = ZC_LANG_DEFAULT if $locale.lang.nil?
283
 
    
284
 
    # Initialize the console
285
 
    $console = Console::new
286
 
    
287
 
    # Initialize the message catalog
288
 
    $mc = MsgCat::new(ZC_LOCALIZATION_DIR, ZC_MSGCAT_FALLBACK)
289
 
 
290
 
    # Add watcher for notification of locale changes
291
 
    #  ... and force update
292
 
    $locale.watch('lang', proc { 
293
 
                      $mc.language = $locale.language
294
 
                      $mc.country  = $locale.country
295
 
                      $mc.reload } )
296
 
    $locale.watch('encoding', proc { 
297
 
                      $console.encoding = $locale.encoding } )
298
 
    $locale.notify('lang', 'encoding')
299
 
 
300
 
    # Read msgcat
301
 
    $mc.read(ZC_LANG_FILE)
302
 
 
303
 
rescue => e
304
 
    raise if $dbg.enabled?(DBG::DONT_RESCUE)
305
 
    $stderr.puts "ERROR: #{e.to_s}"
306
 
    exit EXIT_ERROR
307
 
end
308
 
 
309
 
 
310
 
#
311
 
# Load eventual custom version
312
 
#
313
 
begin 
314
 
    require $zc_custom
315
 
rescue LoadError => e
316
 
    $dbg.msg(DBG::INIT, "Unable to require '#{$zc_custom}' (#{e})")
317
 
end
318
 
 
319
 
 
320
 
# XXX
321
 
## Adjustement due to zc-custom
322
 
##
323
 
#begin
324
 
#    hintfile = "#{$zc_config_dir}/rootservers"
325
 
#    if $rootserver_hintfile != hintfile
326
 
#       NResolv::DNS::RootServer.current = NResolv::DNS::RootServer.from_hintfile(hintfile)
327
 
#    end
328
 
#rescue YAML::ParseError, SystemCallError => e
329
 
#    $dbg.msg(DBG::INIT, 
330
 
#           "Unable to read/parse rootserver hint file (#{e})")
331
 
#end
332
 
 
333
 
 
334
 
#
335
 
# Check it now!
336
 
#
337
 
exit ZoneCheck::ZoneCheck::new::start ? EXIT_OK : EXIT_FAILED