4 use File::Basename qw(&basename &dirname);
7 # List explicitly here the variables you want Configure to
8 # generate. Metaconfig only looks for shell variables, so you
9 # have to mention them as if they were shell variables, not
10 # %Config entries. Thus you write
12 # to ensure Configure will look for $Config{startperl}.
14 # This forces PL files to create target in same directory as PL file.
15 # This is so that make depend always knows where to find PL derivatives.
18 my $file = basename($0, '.PL');
19 $file .= '.com' if $^O eq 'VMS';
21 open OUT, ">", $file or die "Can't create $file: $!";
23 print "Extracting $file (with variable substitutions)\n";
25 # In this section, perl variables will be expanded during extraction.
26 # You can use $Config{...} to use Configure variables.
28 print OUT <<"!GROK!THIS!";
30 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
31 if 0; # ^ Run only under a shell
34 # In the following, perl variables are not expanded during extraction.
36 print OUT <<'!NO!SUBS!';
40 libnetcfg - configure libnet
44 The libnetcfg utility can be used to configure the libnet.
45 Starting from perl 5.8 libnet is part of the standard Perl
46 distribution, but the libnetcfg can be used for any libnet
51 Without arguments libnetcfg displays the current configuration.
54 # old config ./libnet.cfg
55 daytime_hosts ntp1.none.such
57 ftp_testhost ftp.funet.fi
59 nntp_hosts nntp.none.such
61 pop3_hosts pop.none.such
62 smtp_hosts smtp.none.such
66 time_hosts ntp.none.such
67 # libnetcfg -h for help
70 It tells where the old configuration file was found (if found).
72 The C<-h> option will show a usage message.
74 To change the configuration you will need to use either the C<-c> or
77 The default name of the old configuration file is by default
78 "libnet.cfg", unless otherwise specified using the -i option,
79 C<-i oldfile>, and it is searched first from the current directory,
80 and then from your module path.
82 The default name of the new configuration file is "libnet.cfg", and by
83 default it is written to the current directory, unless otherwise
84 specified using the -o option, C<-o newfile>.
88 L<Net::Config>, L<libnetFAQ>
92 Graham Barr, the original Configure script of libnet.
94 Jarkko Hietaniemi, conversion into libnetcfg for inclusion into Perl 5.8.
98 # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
100 BEGIN { pop @INC if $INC[-1] eq '.' }
104 use ExtUtils::MakeMaker qw(prompt);
107 use vars qw($opt_d $opt_c $opt_h $opt_o $opt_i);
116 my($libnet_cfg_in,$libnet_cfg_out,$msg,$ans,$def,$have_old);
126 defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
133 sub test_hostnames (\@)
140 foreach $host (@$hlist)
142 if(valid_host($host))
147 warn "Bad hostname: '$host'\n";
151 $err ? join(" ",@h) : undef;
160 my($prompt,$def) = @_;
162 $def = "" unless defined $def;
168 print $prompt,," [",$def,"]\n";
171 prompt($prompt,$def);
180 my($prompt,$def) = @_;
182 $def = join(" ",@$def) if ref($def);
188 my $ans = Prompt($prompt,$def);
190 $ans =~ s/(\A\s+|\s+\Z)//g;
192 @hosts = split(/\s+/, $ans);
194 while(@hosts && defined($def = test_hostnames(@hosts)));
205 my($prompt,$def) = @_;
211 my $ans = Prompt($prompt,$def);
212 $host = ($ans =~ /(\S*)/)[0];
214 if(!length($host) || valid_host($host));
222 Hostname '$host' does not seem to exist, please enter again
223 or a single space to clear any default
239 my($prompt,$def) = @_;
243 my $val = Prompt($prompt,$def ? "yes" : "no");
245 $val =~ /^y/i ? 1 : 0;
254 my($prompt,$def) = @_;
264 my $ans = Prompt($prompt) or last;
272 print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
276 unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
277 warn "Bad netmask '$ans'\n";
281 my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
282 if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
283 warn "Bad netmask '$ans'\n";
286 foreach my $byte (@ip) {
288 warn "Bad netmask '$ans'\n";
293 my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
318 if(defined($host) && valid_host($host))
326 return wantarray ? @host : undef;
335 $libnet_cfg_in = "libnet.cfg"
336 unless(defined($libnet_cfg_in = $opt_i));
338 $libnet_cfg_out = "libnet.cfg"
339 unless(defined($libnet_cfg_out = $opt_o));
343 $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
344 if( -f $libnet_cfg_in )
346 %oldcfg = ( %{ local @INC = '.'; do $libnet_cfg_in } );
348 elsif (eval { require Net::Config })
351 %oldcfg = %Net::Config::NetConfig;
354 map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
356 #---------------------------------------------------------------------------
360 $0: Usage: $0 [-c] [-d] [-i oldconfigile] [-o newconfigfile] [-h]
361 Without options, the old configuration is shown.
363 -c change the configuration
364 -d use defaults from the old config (implies -c, non-interactive)
365 -i use a specific file as the old config file
366 -o use a specific file as the new config file
369 The default name of the old configuration file is by default
370 "libnet.cfg", unless otherwise specified using the -i option,
371 C<-i oldfile>, and it is searched first from the current directory,
372 and then from your module path.
374 The default name of the new configuration file is "libnet.cfg", and by
375 default it is written to the current directory, unless otherwise
376 specified using the -o option.
382 #---------------------------------------------------------------------------
387 push @inc, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
388 push @inc, $ENV{PERLLIB} if exists $ENV{PERLLIB};
391 my $trycfgfile = File::Spec->catfile($_, $libnet_cfg_in);
392 if (-f $trycfgfile && -r $trycfgfile) {
393 $oldcfgfile = $trycfgfile;
397 print "# old config $oldcfgfile\n" if defined $oldcfgfile;
398 for (sort keys %oldcfg) {
399 printf "%-20s %s\n", $_,
400 ref $oldcfg{$_} ? @{$oldcfg{$_}} : $oldcfg{$_};
402 unless ($opt_c || $opt_d) {
403 print "# $0 -h for help\n";
408 #---------------------------------------------------------------------------
410 $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
411 $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
413 #---------------------------------------------------------------------------
415 if($have_old && !$opt_d)
419 Ah, I see you already have installed libnet before.
421 Do you want to modify/update your configuration (y|n) ?
425 unless get_bool($msg,0);
428 #---------------------------------------------------------------------------
432 This script will prompt you to enter hostnames that can be used as
433 defaults for some of the modules in the libnet distribution.
435 To ensure that you do not enter an invalid hostname, I can perform a
436 lookup on each hostname you enter. If your internet connection is via
437 a dialup line then you may not want me to perform these lookups, as
438 it will require you to be on-line.
440 Do you want me to perform hostname lookups (y|n) ?
443 $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
445 print <<EDQ unless $cfg{'test_exist'};
447 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
449 OK I will not check if the hostnames you give are valid
452 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
456 #---------------------------------------------------------------------------
460 The following questions all require a list of host names, separated
461 with spaces. If you do not have a host available for any of the
462 services, then enter a single space, followed by <CR>. To accept the
467 $msg = 'Enter a list of available NNTP hosts :';
469 $def = $oldcfg{'nntp_hosts'} ||
470 [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
472 $cfg{'nntp_hosts'} = get_host_list($msg,$def);
474 #---------------------------------------------------------------------------
476 $msg = 'Enter a list of available SMTP hosts :';
478 $def = $oldcfg{'smtp_hosts'} ||
479 [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
481 $cfg{'smtp_hosts'} = get_host_list($msg,$def);
483 #---------------------------------------------------------------------------
485 $msg = 'Enter a list of available POP3 hosts :';
487 $def = $oldcfg{'pop3_hosts'} || [];
489 $cfg{'pop3_hosts'} = get_host_list($msg,$def);
491 #---------------------------------------------------------------------------
493 $msg = 'Enter a list of available SNPP hosts :';
495 $def = $oldcfg{'snpp_hosts'} || [];
497 $cfg{'snpp_hosts'} = get_host_list($msg,$def);
499 #---------------------------------------------------------------------------
501 $msg = 'Enter a list of available PH Hosts :' ;
503 $def = $oldcfg{'ph_hosts'} ||
504 [ default_hostname('dirserv') ];
506 $cfg{'ph_hosts'} = get_host_list($msg,$def);
508 #---------------------------------------------------------------------------
510 $msg = 'Enter a list of available TIME Hosts :' ;
512 $def = $oldcfg{'time_hosts'} || [];
514 $cfg{'time_hosts'} = get_host_list($msg,$def);
516 #---------------------------------------------------------------------------
518 $msg = 'Enter a list of available DAYTIME Hosts :' ;
520 $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
522 $cfg{'daytime_hosts'} = get_host_list($msg,$def);
524 #---------------------------------------------------------------------------
528 Do you have a firewall/ftp proxy between your machine and the internet
530 If you use a SOCKS firewall answer no
535 if(get_bool($msg,0)) {
538 What series of FTP commands do you need to send to your
539 firewall to connect to an external host.
541 user/pass => external user & password
542 fwuser/fwpass => firewall user & password
545 1) -----------------------
546 USER user@remote.host
548 2) -----------------------
551 USER user@remote.host
553 3) -----------------------
559 4) -----------------------
565 5) -----------------------
566 USER user@fwuser@remote.site
568 6) -----------------------
569 USER fwuser@remote.site
573 7) -----------------------
574 USER user@remote.host
581 $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
582 $ans = Prompt($msg,$def);
583 $cfg{'ftp_firewall_type'} = 0+$ans;
584 $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
586 $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
589 delete $cfg{'ftp_firewall'};
593 #---------------------------------------------------------------------------
595 if (defined $cfg{'ftp_firewall'})
599 By default Net::FTP assumes that it only needs to use a firewall if it
600 cannot resolve the name of the host given. This only works if your DNS
601 system is setup to only resolve internal hostnames. If this is not the
602 case and your DNS will resolve external hostnames, then another method
603 is needed. Net::Config can do this if you provide the netmasks that
604 describe your internal network. Each netmask should be entered in the
605 form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
609 if(ref($oldcfg{'local_netmask'}))
611 $def = $oldcfg{'local_netmask'};
612 print "Your current netmasks are :\n\n\t",
613 join("\n\t",@{$def}),"\n\n";
617 Enter one netmask at each prompt, prefix with a - to remove a netmask
618 from the list, enter a '*' to clear the whole list, an '=' to show the
619 current list and an empty line to continue with Configure.
623 my $mask = get_netmask("netmask :",$def);
624 $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
627 #---------------------------------------------------------------------------
631 ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
632 ###then enter a list of hostames
634 ###Enter a list of available SOCKS hosts :
637 ###$def = $cfg{'socks_hosts'} ||
638 ### [ default_hostname($ENV{SOCKS5_SERVER},
639 ### $ENV{SOCKS_SERVER},
640 ### $ENV{SOCKS4_SERVER}) ];
642 ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
644 #---------------------------------------------------------------------------
648 Normally when FTP needs a data connection the client tells the server
649 a port to connect to, and the server initiates a connection to the client.
651 Some setups, in particular firewall setups, can/do not work using this
652 protocol. In these situations the client must make the connection to the
653 server, this is called a passive transfer.
656 if (defined $cfg{'ftp_firewall'}) {
657 $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
659 $def = $oldcfg{'ftp_ext_passive'} || 0;
661 $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
663 $msg = "\nShould all other FTP connections be passive (y|n) ?";
667 $msg = "\nShould all FTP connections be passive (y|n) ?";
670 $def = $oldcfg{'ftp_int_passive'} || 0;
672 $cfg{'ftp_int_passive'} = get_bool($msg,$def);
675 #---------------------------------------------------------------------------
677 $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
679 $ans = Prompt("\nWhat is your local internet domain name :",$def);
681 $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
683 #---------------------------------------------------------------------------
687 If you specified some default hosts above, it is possible for me to
688 do some basic tests when you run 'make test'
690 This will cause 'make test' to be quite a bit slower and, if your
691 internet connection is via dialup, will require you to be on-line
692 unless the hosts are local.
694 Do you want me to run these tests (y|n) ?
697 $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
699 #---------------------------------------------------------------------------
703 To allow Net::FTP to be tested I will need a hostname. This host
704 should allow anonymous access and have a /pub directory
706 What host can I use :
709 $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
710 if $cfg{'test_hosts'};
715 #---------------------------------------------------------------------------
717 my $fh = IO::File->new($libnet_cfg_out, "w") or
718 die "Cannot create '$libnet_cfg_out': $!";
720 print "Writing $libnet_cfg_out\n";
725 foreach $key (keys %cfg) {
726 my $val = $cfg{$key};
731 $val = '[' . join(",",
735 ($v = $_) =~ s/'/\'/sog;
743 $val = "'" . $val . "'" if $val =~ /\D/;
745 print $fh "\t'",$key,"' => ",$val,",\n";
752 ############################################################################
753 ############################################################################
758 close OUT or die "Can't close $file: $!";
759 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
760 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';