1
# $Id: inetd.rb,v 1.13 2003/12/16 16:40:39 sdalu Exp $
4
# CONTACT : zonecheck@nic.fr
5
# AUTHOR : Stephane D'Alu <sdalu@nic.fr>
7
# CREATED : 2003/08/27 12:02:17
8
# REVISION : $Revision: 1.13 $
9
# DATE : $Date: 2003/12/16 16:40:39 $
11
# CONTRIBUTORS: (see also CREDITS file)
14
# LICENSE : GPL v2 (or MIT/X11-like after agreement)
15
# COPYRIGHT : AFNIC (c) 2003
17
# This file is part of ZoneCheck.
19
# ZoneCheck is free software; you can redistribute it and/or modify it
20
# under the terms of the GNU General Public License as published by
21
# the Free Software Foundation; either version 2 of the License, or
22
# (at your option) any later version.
24
# ZoneCheck is distributed in the hope that it will be useful, but
25
# WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
# General Public License for more details.
29
# You should have received a copy of the GNU General Public License
30
# along with ZoneCheck; if not, write to the Free Software Foundation,
31
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38
## Processing parameters from INETD
40
## WARN: don't forget to update locale/inetd.*
42
## ----------------------------------------------------------------------
45
## usage: PROGNAME: [-hV] [-46] [-c conf]
46
## --lang Select another language (en, fr, ...)
47
## -h, --help Show this message
48
## -V, --version Display version and exit
49
## -c, --config Specify location of the configuration file
50
## --testdir Location of the directory holding tests
51
## -r, --resolver Resolver to use for guessing 'ns' information
52
## -4, --ipv4 Only allow to check the zone with IPv4 connectivity
53
## -6, --ipv6 Only allow to check the zone with IPv6 connectivity
57
## ?|help 0 This message
58
## q|quit|exit 0 Leave ZoneCheck
59
## check 0 Launch the zone checking process
60
## zone|domain 1 Zone to test
61
## nslist 0+ Set the list of the zone nameservers
62
## set 1-2 Option to set (see options)
63
## unset 1 Option to unset (see options)
64
## preset 1 Preset configuration (supported: classic, fatal)
65
## show 1 Show possibles values (supported: profiles)
68
## lang 1 Select another language (en, fr, ...)
69
## one 0 Only display the most relevant message
70
## quiet 0 Don't display extra titles
71
## tagonly 0 Display only tag (suitable for scripting)
72
## category 1+ Only perform test for the specified category
73
## profile 1 Force a profile to use
74
## verbose 1+ Display extra information (see verbose)
75
## output 1+ Output (see output)
76
## error 1+ Behaviour in case of error (see error)
77
## transp 1+ Transport/routing layer (see transp)
78
## option 1+ Set extra options (-,-opt,opt,opt=foo)
80
## Arguments for Options
81
## verbose: [intro/testname/explain/details]
82
## [reportok|fatalonly] [testdesc|counter]
83
## intro [i] Print summary for domain and associated nameservers
84
## testname [n] Print the test name
85
## explain [x] Print an explanation for failed tests
86
## details [d] Print a detailed description of the failure
87
## reportok [o] Still report passed test
88
## fatalonly [f] Print fatal errors only
89
## testdesc [t] Print the test description before running it
90
## counter [c] Print a test counter
92
## output: [byseverity|byhost] [text|html]
93
## byseverity *[bs] Output is sorted/merged by severity
94
## byhost [bh] Output is sorted/merged by host
95
## text *[t] Output plain text
96
## html [h] Output HTML
98
## error: [allfatal|allwarning|dfltseverity] [stop|nostop]
99
## allfatal [af] All error are considered fatal
100
## allwarning [aw] All error are considered warning
101
## dfltseverity *[ds] Use the severity associated with the test
102
## stop *[s] Stop on the first fatal error
103
## nostop [ns] Never stop (even on fatal error)
105
## transp: [ipv4/ipv6] [udp|tcp|std]
106
## ipv4 *[4] Use IPv4 routing protocol
107
## ipv6 *[6] Use IPv6 routing protocol
108
## udp [u] Use UDP transport layer
109
## tcp [t] Use TCP transport layer
110
## std *[s] Use UDP with fallback to TCP for truncated messages
119
with_msgcat "inetd.%s"
121
def allow_preset ; false ; end
124
@prompt = "zonecheck> "
132
ipv6, ipv4 = false, false
134
opts = GetoptLong::new(
135
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
136
[ '--version', '-V', GetoptLong::NO_ARGUMENT ],
137
[ '--lang', GetoptLong::REQUIRED_ARGUMENT ],
138
[ '--debug', '-d', GetoptLong::REQUIRED_ARGUMENT ],
139
[ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT ],
140
[ '--testdir', GetoptLong::REQUIRED_ARGUMENT ],
141
[ '--resolver', '-r', GetoptLong::REQUIRED_ARGUMENT ],
142
[ '--ipv4', '-4', GetoptLong::NO_ARGUMENT ],
143
[ '--ipv6', '-6', GetoptLong::NO_ARGUMENT ] )
145
opts.each { |opt, arg|
147
when '--help' then usage(EXIT_USAGE, $console.stdout)
149
l10n_version = $mc.get('input:version') % $zc_version
150
l10n_version.gsub!(/PROGNAME/, PROGNAME)
151
$console.stdout.puts l10n_version
153
when '--quiet' then p.rflag.quiet = true
154
when '--debug' then $dbg.level = arg
155
when '--lang' then $locale.lang = arg
156
when '--config' then p.preconf.cfgfile = arg.untaint
157
when '--testdir' then p.preconf.testdir = arg.untaint
158
when '--resolver' then p.resolver.local = arg
159
when '--ipv6' then ipv6 = true
160
when '--ipv4' then ipv4 = true
163
rescue GetoptLong::Error
167
ipv6 = ipv4 = true if !ipv6 && !ipv4
174
def interact(p, c, tm, io=$console.stdout)
175
io.puts $mc.get('input:inetd:welcome').gsub('VERSION', ZC_VERSION)
181
# Check if ^D otherwise read a full line
183
break if char.nil? || char == 4
193
when /^preset\s+(\w+)$/
196
p.verbose = 'i,x,d,c'
197
io.puts '+ set verbose i,x,d,c'
201
io.puts '+ set verbose x,d,f'
202
io.puts '+ set quiet'
204
error($mc.get('input:inetd:unknown_preset') % $1)
206
when /^set\s+(\w+)\s+(.*?)\s*$/
208
when 'verbose' then p.verbose = $2
209
when 'output' then p.output = $2
210
when 'error' then p.error = $2
211
when 'transp' then p.transp = $2
212
when 'option' then p.option = $2
213
when 'category' then p.category = $2
214
when 'quiet' then p.rflag.quiet = true
215
when 'one' then p.rflag.one = true
216
when 'tagonly' then p.rflag.tagonly = true
217
when 'lang' then $locale.lang = $2
218
when 'profile' then p.preconf.profile = c.profilename = $2
220
when /^nslist\s+(.*)/ then p.domain.ns = $1
221
when /^(?:zone|domain)\s+(.*)/ then p.domain.name = $1
223
when /^unset\s+(\w+)$/
225
when 'quiet' then p.rflag.quiet = false
226
when 'one' then p.rflag.one = false
227
when 'profile' then p.preconf.profile = c.profilename = nil
233
c.profiles.each { |profile| io.puts profile.name }
237
io.puts $mc.get('input:inetd:help')
238
# Leave interaction loop
239
when 'check' then return true
240
when 'quit', 'q', 'exit' then return false
244
error($mc.get('input:inetd:what'))
246
rescue Param::ParamError, Config::ConfigError => e
254
io.puts # Skip a line
258
def usage(errcode, io=$console.stdout)
259
io.puts $mc.get('input:inetd:usage').gsub('PROGNAME', PROGNAME)
261
exit errcode unless errcode.nil?
264
def error(str, errcode=nil, io=$console.stdout)
265
l10n_error = $mc.get('word:error').upcase
266
io.puts "#{l10n_error}: #{str}"
268
exit errcode unless errcode.nil?