xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/utils/libnetcfg.PL (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/local/bin/perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateuse Config;
4*0Sstevel@tonic-gateuse File::Basename qw(&basename &dirname);
5*0Sstevel@tonic-gateuse Cwd;
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gate# List explicitly here the variables you want Configure to
8*0Sstevel@tonic-gate# generate.  Metaconfig only looks for shell variables, so you
9*0Sstevel@tonic-gate# have to mention them as if they were shell variables, not
10*0Sstevel@tonic-gate# %Config entries.  Thus you write
11*0Sstevel@tonic-gate#  $startperl
12*0Sstevel@tonic-gate# to ensure Configure will look for $Config{startperl}.
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate# This forces PL files to create target in same directory as PL file.
15*0Sstevel@tonic-gate# This is so that make depend always knows where to find PL derivatives.
16*0Sstevel@tonic-gatemy $origdir = cwd;
17*0Sstevel@tonic-gatechdir dirname($0);
18*0Sstevel@tonic-gatemy $file = basename($0, '.PL');
19*0Sstevel@tonic-gate$file .= '.com' if $^O eq 'VMS';
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gateopen OUT,">$file" or die "Can't create $file: $!";
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gateprint "Extracting $file (with variable substitutions)\n";
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate# In this section, perl variables will be expanded during extraction.
26*0Sstevel@tonic-gate# You can use $Config{...} to use Configure variables.
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gateprint OUT <<"!GROK!THIS!";
29*0Sstevel@tonic-gate$Config{startperl}
30*0Sstevel@tonic-gate    eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
31*0Sstevel@tonic-gate	if \$running_under_some_shell;
32*0Sstevel@tonic-gate!GROK!THIS!
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate# In the following, perl variables are not expanded during extraction.
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gateprint OUT <<'!NO!SUBS!';
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate=head1 NAME
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gatelibnetcfg - configure libnet
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate=head1 DESCRIPTION
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gateThe libnetcfg utility can be used to configure the libnet.
45*0Sstevel@tonic-gateStarting from perl 5.8 libnet is part of the standard Perl
46*0Sstevel@tonic-gatedistribution, but the libnetcfg can be used for any libnet
47*0Sstevel@tonic-gateinstallation.
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate=head1 USAGE
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gateWithout arguments libnetcfg displays the current configuration.
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate    $ libnetcfg
54*0Sstevel@tonic-gate    # old config ./libnet.cfg
55*0Sstevel@tonic-gate    daytime_hosts        ntp1.none.such
56*0Sstevel@tonic-gate    ftp_int_passive      0
57*0Sstevel@tonic-gate    ftp_testhost         ftp.funet.fi
58*0Sstevel@tonic-gate    inet_domain          none.such
59*0Sstevel@tonic-gate    nntp_hosts           nntp.none.such
60*0Sstevel@tonic-gate    ph_hosts
61*0Sstevel@tonic-gate    pop3_hosts           pop.none.such
62*0Sstevel@tonic-gate    smtp_hosts           smtp.none.such
63*0Sstevel@tonic-gate    snpp_hosts
64*0Sstevel@tonic-gate    test_exist           1
65*0Sstevel@tonic-gate    test_hosts           1
66*0Sstevel@tonic-gate    time_hosts           ntp.none.such
67*0Sstevel@tonic-gate    # libnetcfg -h for help
68*0Sstevel@tonic-gate    $
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gateIt tells where the old configuration file was found (if found).
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gateThe C<-h> option will show a usage message.
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gateTo change the configuration you will need to use either the C<-c> or
75*0Sstevel@tonic-gatethe C<-d> options.
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gateThe default name of the old configuration file is by default
78*0Sstevel@tonic-gate"libnet.cfg", unless otherwise specified using the -i option,
79*0Sstevel@tonic-gateC<-i oldfile>, and it is searched first from the current directory,
80*0Sstevel@tonic-gateand then from your module path.
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gateThe default name of the new configuration file is "libnet.cfg", and by
83*0Sstevel@tonic-gatedefault it is written to the current directory, unless otherwise
84*0Sstevel@tonic-gatespecified using the -o option, C<-o newfile>.
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate=head1 SEE ALSO
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gateL<Net::Config>, L<Net::libnetFAQ>
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate=head1 AUTHORS
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gateGraham Barr, the original Configure script of libnet.
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gateJarkko Hietaniemi, conversion into libnetcfg for inclusion into Perl 5.8.
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate=cut
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate# $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gateuse strict;
101*0Sstevel@tonic-gateuse IO::File;
102*0Sstevel@tonic-gateuse Getopt::Std;
103*0Sstevel@tonic-gateuse ExtUtils::MakeMaker qw(prompt);
104*0Sstevel@tonic-gateuse File::Spec;
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gateuse vars qw($opt_d $opt_c $opt_h $opt_o $opt_i);
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate##
109*0Sstevel@tonic-gate##
110*0Sstevel@tonic-gate##
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gatemy %cfg = ();
113*0Sstevel@tonic-gatemy @cfg = ();
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gatemy($libnet_cfg_in,$libnet_cfg_out,$msg,$ans,$def,$have_old);
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate##
118*0Sstevel@tonic-gate##
119*0Sstevel@tonic-gate##
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gatesub valid_host
122*0Sstevel@tonic-gate{
123*0Sstevel@tonic-gate my $h = shift;
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
126*0Sstevel@tonic-gate}
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate##
129*0Sstevel@tonic-gate##
130*0Sstevel@tonic-gate##
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gatesub test_hostnames (\@)
133*0Sstevel@tonic-gate{
134*0Sstevel@tonic-gate my $hlist = shift;
135*0Sstevel@tonic-gate my @h = ();
136*0Sstevel@tonic-gate my $host;
137*0Sstevel@tonic-gate my $err = 0;
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate foreach $host (@$hlist)
140*0Sstevel@tonic-gate  {
141*0Sstevel@tonic-gate   if(valid_host($host))
142*0Sstevel@tonic-gate    {
143*0Sstevel@tonic-gate     push(@h, $host);
144*0Sstevel@tonic-gate     next;
145*0Sstevel@tonic-gate    }
146*0Sstevel@tonic-gate   warn "Bad hostname: '$host'\n";
147*0Sstevel@tonic-gate   $err++;
148*0Sstevel@tonic-gate  }
149*0Sstevel@tonic-gate @$hlist = @h;
150*0Sstevel@tonic-gate $err ? join(" ",@h) : undef;
151*0Sstevel@tonic-gate}
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate##
154*0Sstevel@tonic-gate##
155*0Sstevel@tonic-gate##
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gatesub Prompt
158*0Sstevel@tonic-gate{
159*0Sstevel@tonic-gate my($prompt,$def) = @_;
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate $def = "" unless defined $def;
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate chomp($prompt);
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate if($opt_d)
166*0Sstevel@tonic-gate  {
167*0Sstevel@tonic-gate   print $prompt,," [",$def,"]\n";
168*0Sstevel@tonic-gate   return $def;
169*0Sstevel@tonic-gate  }
170*0Sstevel@tonic-gate prompt($prompt,$def);
171*0Sstevel@tonic-gate}
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gate##
174*0Sstevel@tonic-gate##
175*0Sstevel@tonic-gate##
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gatesub get_host_list
178*0Sstevel@tonic-gate{
179*0Sstevel@tonic-gate my($prompt,$def) = @_;
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate $def = join(" ",@$def) if ref($def);
182*0Sstevel@tonic-gate
183*0Sstevel@tonic-gate my @hosts;
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate do
186*0Sstevel@tonic-gate  {
187*0Sstevel@tonic-gate   my $ans = Prompt($prompt,$def);
188*0Sstevel@tonic-gate
189*0Sstevel@tonic-gate   $ans =~ s/(\A\s+|\s+\Z)//g;
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gate   @hosts = split(/\s+/, $ans);
192*0Sstevel@tonic-gate  }
193*0Sstevel@tonic-gate while(@hosts && defined($def = test_hostnames(@hosts)));
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate \@hosts;
196*0Sstevel@tonic-gate}
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate##
199*0Sstevel@tonic-gate##
200*0Sstevel@tonic-gate##
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gatesub get_hostname
203*0Sstevel@tonic-gate{
204*0Sstevel@tonic-gate my($prompt,$def) = @_;
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate my $host;
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate while(1)
209*0Sstevel@tonic-gate  {
210*0Sstevel@tonic-gate   my $ans = Prompt($prompt,$def);
211*0Sstevel@tonic-gate   $host = ($ans =~ /(\S*)/)[0];
212*0Sstevel@tonic-gate   last
213*0Sstevel@tonic-gate	if(!length($host) || valid_host($host));
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate   $def =""
216*0Sstevel@tonic-gate	if $def eq $host;
217*0Sstevel@tonic-gate
218*0Sstevel@tonic-gate   print <<"EDQ";
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate*** ERROR:
221*0Sstevel@tonic-gate    Hostname `$host' does not seem to exist, please enter again
222*0Sstevel@tonic-gate    or a single space to clear any default
223*0Sstevel@tonic-gate
224*0Sstevel@tonic-gateEDQ
225*0Sstevel@tonic-gate  }
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate length $host
228*0Sstevel@tonic-gate	? $host
229*0Sstevel@tonic-gate	: undef;
230*0Sstevel@tonic-gate}
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate##
233*0Sstevel@tonic-gate##
234*0Sstevel@tonic-gate##
235*0Sstevel@tonic-gate
236*0Sstevel@tonic-gatesub get_bool ($$)
237*0Sstevel@tonic-gate{
238*0Sstevel@tonic-gate my($prompt,$def) = @_;
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate chomp($prompt);
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gate my $val = Prompt($prompt,$def ? "yes" : "no");
243*0Sstevel@tonic-gate
244*0Sstevel@tonic-gate $val =~ /^y/i ? 1 : 0;
245*0Sstevel@tonic-gate}
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gate##
248*0Sstevel@tonic-gate##
249*0Sstevel@tonic-gate##
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gatesub get_netmask ($$)
252*0Sstevel@tonic-gate{
253*0Sstevel@tonic-gate my($prompt,$def) = @_;
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate chomp($prompt);
256*0Sstevel@tonic-gate
257*0Sstevel@tonic-gate my %list;
258*0Sstevel@tonic-gate @list{@$def} = ();
259*0Sstevel@tonic-gate
260*0Sstevel@tonic-gateMASK:
261*0Sstevel@tonic-gate while(1) {
262*0Sstevel@tonic-gate   my $bad = 0;
263*0Sstevel@tonic-gate   my $ans = Prompt($prompt) or last;
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate   if($ans eq '*') {
266*0Sstevel@tonic-gate     %list = ();
267*0Sstevel@tonic-gate     next;
268*0Sstevel@tonic-gate   }
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gate   if($ans eq '=') {
271*0Sstevel@tonic-gate     print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
272*0Sstevel@tonic-gate     next;
273*0Sstevel@tonic-gate   }
274*0Sstevel@tonic-gate
275*0Sstevel@tonic-gate   unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
276*0Sstevel@tonic-gate     warn "Bad netmask '$ans'\n";
277*0Sstevel@tonic-gate     next;
278*0Sstevel@tonic-gate   }
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate   my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
281*0Sstevel@tonic-gate   if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
282*0Sstevel@tonic-gate     warn "Bad netmask '$ans'\n";
283*0Sstevel@tonic-gate     next MASK;
284*0Sstevel@tonic-gate   }
285*0Sstevel@tonic-gate   foreach my $byte (@ip) {
286*0Sstevel@tonic-gate     if ( $byte > 255 ) {
287*0Sstevel@tonic-gate       warn "Bad netmask '$ans'\n";
288*0Sstevel@tonic-gate       next MASK;
289*0Sstevel@tonic-gate     }
290*0Sstevel@tonic-gate   }
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate   my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
293*0Sstevel@tonic-gate
294*0Sstevel@tonic-gate   if ($remove) {
295*0Sstevel@tonic-gate     delete $list{$mask};
296*0Sstevel@tonic-gate   }
297*0Sstevel@tonic-gate   else {
298*0Sstevel@tonic-gate     $list{$mask} = 1;
299*0Sstevel@tonic-gate   }
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate  }
302*0Sstevel@tonic-gate
303*0Sstevel@tonic-gate [ keys %list ];
304*0Sstevel@tonic-gate}
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate##
307*0Sstevel@tonic-gate##
308*0Sstevel@tonic-gate##
309*0Sstevel@tonic-gate
310*0Sstevel@tonic-gatesub default_hostname
311*0Sstevel@tonic-gate{
312*0Sstevel@tonic-gate my $host;
313*0Sstevel@tonic-gate my @host;
314*0Sstevel@tonic-gate
315*0Sstevel@tonic-gate foreach $host (@_)
316*0Sstevel@tonic-gate  {
317*0Sstevel@tonic-gate   if(defined($host) && valid_host($host))
318*0Sstevel@tonic-gate    {
319*0Sstevel@tonic-gate     return $host
320*0Sstevel@tonic-gate	unless wantarray;
321*0Sstevel@tonic-gate     push(@host,$host);
322*0Sstevel@tonic-gate    }
323*0Sstevel@tonic-gate  }
324*0Sstevel@tonic-gate
325*0Sstevel@tonic-gate return wantarray ? @host : undef;
326*0Sstevel@tonic-gate}
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate##
329*0Sstevel@tonic-gate##
330*0Sstevel@tonic-gate##
331*0Sstevel@tonic-gate
332*0Sstevel@tonic-gategetopts('dcho:i:');
333*0Sstevel@tonic-gate
334*0Sstevel@tonic-gate$libnet_cfg_in = "libnet.cfg"
335*0Sstevel@tonic-gate	unless(defined($libnet_cfg_in  = $opt_i));
336*0Sstevel@tonic-gate
337*0Sstevel@tonic-gate$libnet_cfg_out = "libnet.cfg"
338*0Sstevel@tonic-gate	unless(defined($libnet_cfg_out = $opt_o));
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gatemy %oldcfg = ();
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate$Net::Config::CONFIGURE = 1; # Suppress load of user overrides
343*0Sstevel@tonic-gateif( -f $libnet_cfg_in )
344*0Sstevel@tonic-gate {
345*0Sstevel@tonic-gate  %oldcfg = ( %{ do $libnet_cfg_in } );
346*0Sstevel@tonic-gate }
347*0Sstevel@tonic-gateelsif (eval { require Net::Config })
348*0Sstevel@tonic-gate {
349*0Sstevel@tonic-gate  $have_old = 1;
350*0Sstevel@tonic-gate  %oldcfg = %Net::Config::NetConfig;
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate
353*0Sstevel@tonic-gatemap { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
354*0Sstevel@tonic-gate
355*0Sstevel@tonic-gate#---------------------------------------------------------------------------
356*0Sstevel@tonic-gate
357*0Sstevel@tonic-gateif ($opt_h) {
358*0Sstevel@tonic-gate print <<EOU;
359*0Sstevel@tonic-gate$0: Usage: $0 [-c] [-d] [-i oldconfigile] [-o newconfigfile] [-h]
360*0Sstevel@tonic-gateWithout options, the old configuration is shown.
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate   -c change the configuration
363*0Sstevel@tonic-gate   -d use defaults from the old config (implies -c, non-interactive)
364*0Sstevel@tonic-gate   -i use a specific file as the old config file
365*0Sstevel@tonic-gate   -o use a specific file as the new config file
366*0Sstevel@tonic-gate   -h show this help
367*0Sstevel@tonic-gate
368*0Sstevel@tonic-gateThe default name of the old configuration file is by default
369*0Sstevel@tonic-gate"libnet.cfg", unless otherwise specified using the -i option,
370*0Sstevel@tonic-gateC<-i oldfile>, and it is searched first from the current directory,
371*0Sstevel@tonic-gateand then from your module path.
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gateThe default name of the new configuration file is "libnet.cfg", and by
374*0Sstevel@tonic-gatedefault it is written to the current directory, unless otherwise
375*0Sstevel@tonic-gatespecified using the -o option.
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gateEOU
378*0Sstevel@tonic-gate exit(0);
379*0Sstevel@tonic-gate}
380*0Sstevel@tonic-gate
381*0Sstevel@tonic-gate#---------------------------------------------------------------------------
382*0Sstevel@tonic-gate
383*0Sstevel@tonic-gate{
384*0Sstevel@tonic-gate   my $oldcfgfile;
385*0Sstevel@tonic-gate   my @inc;
386*0Sstevel@tonic-gate   push @inc, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
387*0Sstevel@tonic-gate   push @inc, $ENV{PERLLIB}  if exists $ENV{PERLLIB};
388*0Sstevel@tonic-gate   push @inc, @INC;
389*0Sstevel@tonic-gate   for (@inc) {
390*0Sstevel@tonic-gate    my $trycfgfile = File::Spec->catfile($_, $libnet_cfg_in);
391*0Sstevel@tonic-gate    if (-f $trycfgfile && -r $trycfgfile) {
392*0Sstevel@tonic-gate     $oldcfgfile = $trycfgfile;
393*0Sstevel@tonic-gate     last;
394*0Sstevel@tonic-gate    }
395*0Sstevel@tonic-gate   }
396*0Sstevel@tonic-gate   print "# old config $oldcfgfile\n" if defined $oldcfgfile;
397*0Sstevel@tonic-gate   for (sort keys %oldcfg) {
398*0Sstevel@tonic-gate	printf "%-20s %s\n", $_,
399*0Sstevel@tonic-gate               ref $oldcfg{$_} ? @{$oldcfg{$_}} : $oldcfg{$_};
400*0Sstevel@tonic-gate   }
401*0Sstevel@tonic-gate   unless ($opt_c || $opt_d) {
402*0Sstevel@tonic-gate    print "# $0 -h for help\n";
403*0Sstevel@tonic-gate    exit(0);
404*0Sstevel@tonic-gate   }
405*0Sstevel@tonic-gate}
406*0Sstevel@tonic-gate
407*0Sstevel@tonic-gate#---------------------------------------------------------------------------
408*0Sstevel@tonic-gate
409*0Sstevel@tonic-gate$oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
410*0Sstevel@tonic-gate$oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
411*0Sstevel@tonic-gate
412*0Sstevel@tonic-gate#---------------------------------------------------------------------------
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gateif($have_old && !$opt_d)
415*0Sstevel@tonic-gate {
416*0Sstevel@tonic-gate  $msg = <<EDQ;
417*0Sstevel@tonic-gate
418*0Sstevel@tonic-gateAh, I see you already have installed libnet before.
419*0Sstevel@tonic-gate
420*0Sstevel@tonic-gateDo you want to modify/update your configuration (y|n) ?
421*0Sstevel@tonic-gateEDQ
422*0Sstevel@tonic-gate
423*0Sstevel@tonic-gate $opt_d = 1
424*0Sstevel@tonic-gate	unless get_bool($msg,0);
425*0Sstevel@tonic-gate }
426*0Sstevel@tonic-gate
427*0Sstevel@tonic-gate#---------------------------------------------------------------------------
428*0Sstevel@tonic-gate
429*0Sstevel@tonic-gate$msg = <<EDQ;
430*0Sstevel@tonic-gate
431*0Sstevel@tonic-gateThis script will prompt you to enter hostnames that can be used as
432*0Sstevel@tonic-gatedefaults for some of the modules in the libnet distribution.
433*0Sstevel@tonic-gate
434*0Sstevel@tonic-gateTo ensure that you do not enter an invalid hostname, I can perform a
435*0Sstevel@tonic-gatelookup on each hostname you enter. If your internet connection is via
436*0Sstevel@tonic-gatea dialup line then you may not want me to perform these lookups, as
437*0Sstevel@tonic-gateit will require you to be on-line.
438*0Sstevel@tonic-gate
439*0Sstevel@tonic-gateDo you want me to perform hostname lookups (y|n) ?
440*0Sstevel@tonic-gateEDQ
441*0Sstevel@tonic-gate
442*0Sstevel@tonic-gate$cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gateprint <<EDQ unless $cfg{'test_exist'};
445*0Sstevel@tonic-gate
446*0Sstevel@tonic-gate*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
447*0Sstevel@tonic-gate
448*0Sstevel@tonic-gateOK I will not check if the hostnames you give are valid
449*0Sstevel@tonic-gateso be very cafeful
450*0Sstevel@tonic-gate
451*0Sstevel@tonic-gate*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
452*0Sstevel@tonic-gateEDQ
453*0Sstevel@tonic-gate
454*0Sstevel@tonic-gate
455*0Sstevel@tonic-gate#---------------------------------------------------------------------------
456*0Sstevel@tonic-gate
457*0Sstevel@tonic-gateprint <<EDQ;
458*0Sstevel@tonic-gate
459*0Sstevel@tonic-gateThe following questions all require a list of host names, separated
460*0Sstevel@tonic-gatewith spaces. If you do not have a host available for any of the
461*0Sstevel@tonic-gateservices, then enter a single space, followed by <CR>. To accept the
462*0Sstevel@tonic-gatedefault, hit <CR>
463*0Sstevel@tonic-gate
464*0Sstevel@tonic-gateEDQ
465*0Sstevel@tonic-gate
466*0Sstevel@tonic-gate$msg = 'Enter a list of available NNTP hosts :';
467*0Sstevel@tonic-gate
468*0Sstevel@tonic-gate$def = $oldcfg{'nntp_hosts'} ||
469*0Sstevel@tonic-gate	[ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
470*0Sstevel@tonic-gate
471*0Sstevel@tonic-gate$cfg{'nntp_hosts'} = get_host_list($msg,$def);
472*0Sstevel@tonic-gate
473*0Sstevel@tonic-gate#---------------------------------------------------------------------------
474*0Sstevel@tonic-gate
475*0Sstevel@tonic-gate$msg = 'Enter a list of available SMTP hosts :';
476*0Sstevel@tonic-gate
477*0Sstevel@tonic-gate$def = $oldcfg{'smtp_hosts'} ||
478*0Sstevel@tonic-gate	[ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
479*0Sstevel@tonic-gate
480*0Sstevel@tonic-gate$cfg{'smtp_hosts'} = get_host_list($msg,$def);
481*0Sstevel@tonic-gate
482*0Sstevel@tonic-gate#---------------------------------------------------------------------------
483*0Sstevel@tonic-gate
484*0Sstevel@tonic-gate$msg = 'Enter a list of available POP3 hosts :';
485*0Sstevel@tonic-gate
486*0Sstevel@tonic-gate$def = $oldcfg{'pop3_hosts'} || [];
487*0Sstevel@tonic-gate
488*0Sstevel@tonic-gate$cfg{'pop3_hosts'} = get_host_list($msg,$def);
489*0Sstevel@tonic-gate
490*0Sstevel@tonic-gate#---------------------------------------------------------------------------
491*0Sstevel@tonic-gate
492*0Sstevel@tonic-gate$msg = 'Enter a list of available SNPP hosts :';
493*0Sstevel@tonic-gate
494*0Sstevel@tonic-gate$def = $oldcfg{'snpp_hosts'} || [];
495*0Sstevel@tonic-gate
496*0Sstevel@tonic-gate$cfg{'snpp_hosts'} = get_host_list($msg,$def);
497*0Sstevel@tonic-gate
498*0Sstevel@tonic-gate#---------------------------------------------------------------------------
499*0Sstevel@tonic-gate
500*0Sstevel@tonic-gate$msg = 'Enter a list of available PH Hosts   :'  ;
501*0Sstevel@tonic-gate
502*0Sstevel@tonic-gate$def = $oldcfg{'ph_hosts'} ||
503*0Sstevel@tonic-gate	[ default_hostname('dirserv') ];
504*0Sstevel@tonic-gate
505*0Sstevel@tonic-gate$cfg{'ph_hosts'}   =  get_host_list($msg,$def);
506*0Sstevel@tonic-gate
507*0Sstevel@tonic-gate#---------------------------------------------------------------------------
508*0Sstevel@tonic-gate
509*0Sstevel@tonic-gate$msg = 'Enter a list of available TIME Hosts   :'  ;
510*0Sstevel@tonic-gate
511*0Sstevel@tonic-gate$def = $oldcfg{'time_hosts'} || [];
512*0Sstevel@tonic-gate
513*0Sstevel@tonic-gate$cfg{'time_hosts'} = get_host_list($msg,$def);
514*0Sstevel@tonic-gate
515*0Sstevel@tonic-gate#---------------------------------------------------------------------------
516*0Sstevel@tonic-gate
517*0Sstevel@tonic-gate$msg = 'Enter a list of available DAYTIME Hosts   :'  ;
518*0Sstevel@tonic-gate
519*0Sstevel@tonic-gate$def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
520*0Sstevel@tonic-gate
521*0Sstevel@tonic-gate$cfg{'daytime_hosts'} = get_host_list($msg,$def);
522*0Sstevel@tonic-gate
523*0Sstevel@tonic-gate#---------------------------------------------------------------------------
524*0Sstevel@tonic-gate
525*0Sstevel@tonic-gate$msg = <<EDQ;
526*0Sstevel@tonic-gate
527*0Sstevel@tonic-gateDo you have a firewall/ftp proxy  between your machine and the internet
528*0Sstevel@tonic-gate
529*0Sstevel@tonic-gateIf you use a SOCKS firewall answer no
530*0Sstevel@tonic-gate
531*0Sstevel@tonic-gate(y|n) ?
532*0Sstevel@tonic-gateEDQ
533*0Sstevel@tonic-gate
534*0Sstevel@tonic-gateif(get_bool($msg,0)) {
535*0Sstevel@tonic-gate
536*0Sstevel@tonic-gate  $msg = <<'EDQ';
537*0Sstevel@tonic-gateWhat series of FTP commands do you need to send to your
538*0Sstevel@tonic-gatefirewall to connect to an external host.
539*0Sstevel@tonic-gate
540*0Sstevel@tonic-gateuser/pass     => external user & password
541*0Sstevel@tonic-gatefwuser/fwpass => firewall user & password
542*0Sstevel@tonic-gate
543*0Sstevel@tonic-gate0) None
544*0Sstevel@tonic-gate1) -----------------------
545*0Sstevel@tonic-gate     USER user@remote.host
546*0Sstevel@tonic-gate     PASS pass
547*0Sstevel@tonic-gate2) -----------------------
548*0Sstevel@tonic-gate     USER fwuser
549*0Sstevel@tonic-gate     PASS fwpass
550*0Sstevel@tonic-gate     USER user@remote.host
551*0Sstevel@tonic-gate     PASS pass
552*0Sstevel@tonic-gate3) -----------------------
553*0Sstevel@tonic-gate     USER fwuser
554*0Sstevel@tonic-gate     PASS fwpass
555*0Sstevel@tonic-gate     SITE remote.site
556*0Sstevel@tonic-gate     USER user
557*0Sstevel@tonic-gate     PASS pass
558*0Sstevel@tonic-gate4) -----------------------
559*0Sstevel@tonic-gate     USER fwuser
560*0Sstevel@tonic-gate     PASS fwpass
561*0Sstevel@tonic-gate     OPEN remote.site
562*0Sstevel@tonic-gate     USER user
563*0Sstevel@tonic-gate     PASS pass
564*0Sstevel@tonic-gate5) -----------------------
565*0Sstevel@tonic-gate     USER user@fwuser@remote.site
566*0Sstevel@tonic-gate     PASS pass@fwpass
567*0Sstevel@tonic-gate6) -----------------------
568*0Sstevel@tonic-gate     USER fwuser@remote.site
569*0Sstevel@tonic-gate     PASS fwpass
570*0Sstevel@tonic-gate     USER user
571*0Sstevel@tonic-gate     PASS pass
572*0Sstevel@tonic-gate7) -----------------------
573*0Sstevel@tonic-gate     USER user@remote.host
574*0Sstevel@tonic-gate     PASS pass
575*0Sstevel@tonic-gate     AUTH fwuser
576*0Sstevel@tonic-gate     RESP fwpass
577*0Sstevel@tonic-gate
578*0Sstevel@tonic-gateChoice:
579*0Sstevel@tonic-gateEDQ
580*0Sstevel@tonic-gate $def = exists $oldcfg{'ftp_firewall_type'}  ? $oldcfg{'ftp_firewall_type'} : 1;
581*0Sstevel@tonic-gate $ans = Prompt($msg,$def);
582*0Sstevel@tonic-gate $cfg{'ftp_firewall_type'} = 0+$ans;
583*0Sstevel@tonic-gate $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
584*0Sstevel@tonic-gate
585*0Sstevel@tonic-gate $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
586*0Sstevel@tonic-gate}
587*0Sstevel@tonic-gateelse {
588*0Sstevel@tonic-gate delete $cfg{'ftp_firewall'};
589*0Sstevel@tonic-gate}
590*0Sstevel@tonic-gate
591*0Sstevel@tonic-gate
592*0Sstevel@tonic-gate#---------------------------------------------------------------------------
593*0Sstevel@tonic-gate
594*0Sstevel@tonic-gateif (defined $cfg{'ftp_firewall'})
595*0Sstevel@tonic-gate {
596*0Sstevel@tonic-gate  print <<EDQ;
597*0Sstevel@tonic-gate
598*0Sstevel@tonic-gateBy default Net::FTP assumes that it only needs to use a firewall if it
599*0Sstevel@tonic-gatecannot resolve the name of the host given. This only works if your DNS
600*0Sstevel@tonic-gatesystem is setup to only resolve internal hostnames. If this is not the
601*0Sstevel@tonic-gatecase and your DNS will resolve external hostnames, then another method
602*0Sstevel@tonic-gateis needed. Net::Config can do this if you provide the netmasks that
603*0Sstevel@tonic-gatedescribe your internal network. Each netmask should be entered in the
604*0Sstevel@tonic-gateform x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
605*0Sstevel@tonic-gate
606*0Sstevel@tonic-gateEDQ
607*0Sstevel@tonic-gate$def = [];
608*0Sstevel@tonic-gateif(ref($oldcfg{'local_netmask'}))
609*0Sstevel@tonic-gate {
610*0Sstevel@tonic-gate  $def = $oldcfg{'local_netmask'};
611*0Sstevel@tonic-gate   print "Your current netmasks are :\n\n\t",
612*0Sstevel@tonic-gate	join("\n\t",@{$def}),"\n\n";
613*0Sstevel@tonic-gate }
614*0Sstevel@tonic-gate
615*0Sstevel@tonic-gateprint "
616*0Sstevel@tonic-gateEnter one netmask at each prompt, prefix with a - to remove a netmask
617*0Sstevel@tonic-gatefrom the list, enter a '*' to clear the whole list, an '=' to show the
618*0Sstevel@tonic-gatecurrent list and an empty line to continue with Configure.
619*0Sstevel@tonic-gate
620*0Sstevel@tonic-gate";
621*0Sstevel@tonic-gate
622*0Sstevel@tonic-gate  my $mask = get_netmask("netmask :",$def);
623*0Sstevel@tonic-gate  $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
624*0Sstevel@tonic-gate }
625*0Sstevel@tonic-gate
626*0Sstevel@tonic-gate#---------------------------------------------------------------------------
627*0Sstevel@tonic-gate
628*0Sstevel@tonic-gate###$msg =<<EDQ;
629*0Sstevel@tonic-gate###
630*0Sstevel@tonic-gate###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
631*0Sstevel@tonic-gate###then enter a list of hostames
632*0Sstevel@tonic-gate###
633*0Sstevel@tonic-gate###Enter a list of available SOCKS hosts :
634*0Sstevel@tonic-gate###EDQ
635*0Sstevel@tonic-gate###
636*0Sstevel@tonic-gate###$def = $cfg{'socks_hosts'} ||
637*0Sstevel@tonic-gate###	[ default_hostname($ENV{SOCKS5_SERVER},
638*0Sstevel@tonic-gate###			   $ENV{SOCKS_SERVER},
639*0Sstevel@tonic-gate###			   $ENV{SOCKS4_SERVER}) ];
640*0Sstevel@tonic-gate###
641*0Sstevel@tonic-gate###$cfg{'socks_hosts'}   =  get_host_list($msg,$def);
642*0Sstevel@tonic-gate
643*0Sstevel@tonic-gate#---------------------------------------------------------------------------
644*0Sstevel@tonic-gate
645*0Sstevel@tonic-gateprint <<EDQ;
646*0Sstevel@tonic-gate
647*0Sstevel@tonic-gateNormally when FTP needs a data connection the client tells the server
648*0Sstevel@tonic-gatea port to connect to, and the server initiates a connection to the client.
649*0Sstevel@tonic-gate
650*0Sstevel@tonic-gateSome setups, in particular firewall setups, can/do not work using this
651*0Sstevel@tonic-gateprotocol. In these situations the client must make the connection to the
652*0Sstevel@tonic-gateserver, this is called a passive transfer.
653*0Sstevel@tonic-gateEDQ
654*0Sstevel@tonic-gate
655*0Sstevel@tonic-gateif (defined $cfg{'ftp_firewall'}) {
656*0Sstevel@tonic-gate  $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
657*0Sstevel@tonic-gate
658*0Sstevel@tonic-gate  $def = $oldcfg{'ftp_ext_passive'} || 0;
659*0Sstevel@tonic-gate
660*0Sstevel@tonic-gate  $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
661*0Sstevel@tonic-gate
662*0Sstevel@tonic-gate  $msg = "\nShould all other FTP connections be passive (y|n) ?";
663*0Sstevel@tonic-gate
664*0Sstevel@tonic-gate}
665*0Sstevel@tonic-gateelse {
666*0Sstevel@tonic-gate  $msg = "\nShould all FTP connections be passive (y|n) ?";
667*0Sstevel@tonic-gate}
668*0Sstevel@tonic-gate
669*0Sstevel@tonic-gate$def = $oldcfg{'ftp_int_passive'} || 0;
670*0Sstevel@tonic-gate
671*0Sstevel@tonic-gate$cfg{'ftp_int_passive'} = get_bool($msg,$def);
672*0Sstevel@tonic-gate
673*0Sstevel@tonic-gate
674*0Sstevel@tonic-gate#---------------------------------------------------------------------------
675*0Sstevel@tonic-gate
676*0Sstevel@tonic-gate$def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
677*0Sstevel@tonic-gate
678*0Sstevel@tonic-gate$ans = Prompt("\nWhat is your local internet domain name :",$def);
679*0Sstevel@tonic-gate
680*0Sstevel@tonic-gate$cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
681*0Sstevel@tonic-gate
682*0Sstevel@tonic-gate#---------------------------------------------------------------------------
683*0Sstevel@tonic-gate
684*0Sstevel@tonic-gate$msg = <<EDQ;
685*0Sstevel@tonic-gate
686*0Sstevel@tonic-gateIf you specified some default hosts above, it is possible for me to
687*0Sstevel@tonic-gatedo some basic tests when you run `make test'
688*0Sstevel@tonic-gate
689*0Sstevel@tonic-gateThis will cause `make test' to be quite a bit slower and, if your
690*0Sstevel@tonic-gateinternet connection is via dialup, will require you to be on-line
691*0Sstevel@tonic-gateunless the hosts are local.
692*0Sstevel@tonic-gate
693*0Sstevel@tonic-gateDo you want me to run these tests (y|n) ?
694*0Sstevel@tonic-gateEDQ
695*0Sstevel@tonic-gate
696*0Sstevel@tonic-gate$cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
697*0Sstevel@tonic-gate
698*0Sstevel@tonic-gate#---------------------------------------------------------------------------
699*0Sstevel@tonic-gate
700*0Sstevel@tonic-gate$msg = <<EDQ;
701*0Sstevel@tonic-gate
702*0Sstevel@tonic-gateTo allow Net::FTP to be tested I will need a hostname. This host
703*0Sstevel@tonic-gateshould allow anonymous access and have a /pub directory
704*0Sstevel@tonic-gate
705*0Sstevel@tonic-gateWhat host can I use :
706*0Sstevel@tonic-gateEDQ
707*0Sstevel@tonic-gate
708*0Sstevel@tonic-gate$cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
709*0Sstevel@tonic-gate	if $cfg{'test_hosts'};
710*0Sstevel@tonic-gate
711*0Sstevel@tonic-gate
712*0Sstevel@tonic-gateprint "\n";
713*0Sstevel@tonic-gate
714*0Sstevel@tonic-gate#---------------------------------------------------------------------------
715*0Sstevel@tonic-gate
716*0Sstevel@tonic-gatemy $fh = IO::File->new($libnet_cfg_out, "w") or
717*0Sstevel@tonic-gate	die "Cannot create `$libnet_cfg_out': $!";
718*0Sstevel@tonic-gate
719*0Sstevel@tonic-gateprint "Writing $libnet_cfg_out\n";
720*0Sstevel@tonic-gate
721*0Sstevel@tonic-gateprint $fh "{\n";
722*0Sstevel@tonic-gate
723*0Sstevel@tonic-gatemy $key;
724*0Sstevel@tonic-gateforeach $key (keys %cfg) {
725*0Sstevel@tonic-gate    my $val = $cfg{$key};
726*0Sstevel@tonic-gate    if(!defined($val)) {
727*0Sstevel@tonic-gate	$val = "undef";
728*0Sstevel@tonic-gate    }
729*0Sstevel@tonic-gate    elsif(ref($val)) {
730*0Sstevel@tonic-gate	$val = '[' . join(",",
731*0Sstevel@tonic-gate	    map {
732*0Sstevel@tonic-gate		my $v = "undef";
733*0Sstevel@tonic-gate		if(defined $_) {
734*0Sstevel@tonic-gate		    ($v = $_) =~ s/'/\'/sog;
735*0Sstevel@tonic-gate		    $v = "'" . $v . "'";
736*0Sstevel@tonic-gate		}
737*0Sstevel@tonic-gate		$v;
738*0Sstevel@tonic-gate	    } @$val ) . ']';
739*0Sstevel@tonic-gate    }
740*0Sstevel@tonic-gate    else {
741*0Sstevel@tonic-gate	$val =~ s/'/\'/sog;
742*0Sstevel@tonic-gate	$val = "'" . $val . "'" if $val =~ /\D/;
743*0Sstevel@tonic-gate    }
744*0Sstevel@tonic-gate    print $fh "\t'",$key,"' => ",$val,",\n";
745*0Sstevel@tonic-gate}
746*0Sstevel@tonic-gate
747*0Sstevel@tonic-gateprint $fh "}\n";
748*0Sstevel@tonic-gate
749*0Sstevel@tonic-gate$fh->close;
750*0Sstevel@tonic-gate
751*0Sstevel@tonic-gate############################################################################
752*0Sstevel@tonic-gate############################################################################
753*0Sstevel@tonic-gate
754*0Sstevel@tonic-gateexit 0;
755*0Sstevel@tonic-gate!NO!SUBS!
756*0Sstevel@tonic-gate
757*0Sstevel@tonic-gateclose OUT or die "Can't close $file: $!";
758*0Sstevel@tonic-gatechmod 0755, $file or die "Can't reset permissions for $file: $!\n";
759*0Sstevel@tonic-gateexec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
760*0Sstevel@tonic-gatechdir $origdir;
761