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 \$running_under_some_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 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 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 # ./libnetcfg5.7.1 -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, and it
79 is searched from your module path, C<-i oldfile>.
81 The default name of new configuration file is "libnet.cfg", and by
82 default it is written to the current directory, unless otherwise
83 specified using the -o option, C<-o newfile>.
87 L<Net::Config>, L<Net::libnetFAQ>
91 Graham Barr, the original Configure script of libnet.
93 Jarkko Hietaniemi, conversion into libnet cfg for inclusion into Perl 5.8.
97 # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
102 use ExtUtils::MakeMaker qw(prompt);
105 use vars qw($opt_d $opt_c $opt_h $opt_o $opt_i);
114 my($libnet_cfg_in,$libnet_cfg_out,$msg,$ans,$def,$have_old);
124 defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
131 sub test_hostnames (\@)
138 foreach $host (@$hlist)
140 if(valid_host($host))
145 warn "Bad hostname: '$host'\n";
149 $err ? join(" ",@h) : undef;
158 my($prompt,$def) = @_;
160 $def = "" unless defined $def;
166 print $prompt,," [",$def,"]\n";
169 prompt($prompt,$def);
178 my($prompt,$def) = @_;
180 $def = join(" ",@$def) if ref($def);
186 my $ans = Prompt($prompt,$def);
188 $ans =~ s/(\A\s+|\s+\Z)//g;
190 @hosts = split(/\s+/, $ans);
192 while(@hosts && defined($def = test_hostnames(@hosts)));
203 my($prompt,$def) = @_;
209 my $ans = Prompt($prompt,$def);
210 $host = ($ans =~ /(\S*)/)[0];
212 if(!length($host) || valid_host($host));
220 Hostname `$host' does not seem to exist, please enter again
221 or a single space to clear any default
237 my($prompt,$def) = @_;
241 my $val = Prompt($prompt,$def ? "yes" : "no");
243 $val =~ /^y/i ? 1 : 0;
252 my($prompt,$def) = @_;
262 my $ans = Prompt($prompt) or last;
270 print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
274 unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
275 warn "Bad netmask '$ans'\n";
279 my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
280 if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
281 warn "Bad netmask '$ans'\n";
284 foreach my $byte (@ip) {
286 warn "Bad netmask '$ans'\n";
291 my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
316 if(defined($host) && valid_host($host))
324 return wantarray ? @host : undef;
333 $libnet_cfg_in = "libnet.cfg"
334 unless(defined($libnet_cfg_in = $opt_i));
336 $libnet_cfg_out = "libnet.cfg"
337 unless(defined($libnet_cfg_out = $opt_o));
341 $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
342 if( -f $libnet_cfg_in )
344 %oldcfg = ( %{ do $libnet_cfg_in } );
346 elsif (eval { require Net::Config })
349 %oldcfg = %Net::Config::NetConfig;
352 map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
354 #---------------------------------------------------------------------------
358 $0: Usage: $0 [-c] [-d] [-i oldconfigile] [-o newconfigfile] [-h]
359 Without options, the old configuration is shown.
361 -c change the configuration
362 -d use defaults from the old config (implies -c, non-interactive)
363 -i use a specific file as the old config file
364 -o use a specific file as the new config file
367 The default name of the old configuration file is by default
368 "libnet.cfg", unless otherwise specified using the -i option, and it
369 is searched from your module path.
371 The default name of new configuration file is "libnet.cfg", and by
372 default it is written to the current directory, unless otherwise
373 specified using the -o option.
379 #---------------------------------------------------------------------------
384 push @inc, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
385 push @inc, $ENV{PERLLIB} if exists $ENV{PERLLIB};
388 my $trycfgfile = File::Spec->catfile($_, $libnet_cfg_in);
389 if (-f $trycfgfile && -r $trycfgfile) {
390 $oldcfgfile = $trycfgfile;
394 print "# old config $oldcfgfile\n" if defined $oldcfgfile;
395 for (sort keys %oldcfg) {
396 printf "%-20s %s\n", $_,
397 ref $oldcfg{$_} ? @{$oldcfg{$_}} : $oldcfg{$_};
399 unless ($opt_c || $opt_d) {
400 print "# $0 -h for help\n";
405 #---------------------------------------------------------------------------
407 $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
408 $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
410 #---------------------------------------------------------------------------
412 if($have_old && !$opt_d)
416 Ah, I see you already have installed libnet before.
418 Do you want to modify/update your configuration (y|n) ?
422 unless get_bool($msg,0);
425 #---------------------------------------------------------------------------
429 This script will prompt you to enter hostnames that can be used as
430 defaults for some of the modules in the libnet distribution.
432 To ensure that you do not enter an invalid hostname, I can perform a
433 lookup on each hostname you enter. If your internet connection is via
434 a dialup line then you may not want me to perform these lookups, as
435 it will require you to be on-line.
437 Do you want me to perform hostname lookups (y|n) ?
440 $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
442 print <<EDQ unless $cfg{'test_exist'};
444 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
446 OK I will not check if the hostnames you give are valid
449 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
453 #---------------------------------------------------------------------------
457 The following questions all require a list of host names, separated
458 with spaces. If you do not have a host available for any of the
459 services, then enter a single space, followed by <CR>. To accept the
464 $msg = 'Enter a list of available NNTP hosts :';
466 $def = $oldcfg{'nntp_hosts'} ||
467 [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
469 $cfg{'nntp_hosts'} = get_host_list($msg,$def);
471 #---------------------------------------------------------------------------
473 $msg = 'Enter a list of available SMTP hosts :';
475 $def = $oldcfg{'smtp_hosts'} ||
476 [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
478 $cfg{'smtp_hosts'} = get_host_list($msg,$def);
480 #---------------------------------------------------------------------------
482 $msg = 'Enter a list of available POP3 hosts :';
484 $def = $oldcfg{'pop3_hosts'} || [];
486 $cfg{'pop3_hosts'} = get_host_list($msg,$def);
488 #---------------------------------------------------------------------------
490 $msg = 'Enter a list of available SNPP hosts :';
492 $def = $oldcfg{'snpp_hosts'} || [];
494 $cfg{'snpp_hosts'} = get_host_list($msg,$def);
496 #---------------------------------------------------------------------------
498 $msg = 'Enter a list of available PH Hosts :' ;
500 $def = $oldcfg{'ph_hosts'} ||
501 [ default_hostname('dirserv') ];
503 $cfg{'ph_hosts'} = get_host_list($msg,$def);
505 #---------------------------------------------------------------------------
507 $msg = 'Enter a list of available TIME Hosts :' ;
509 $def = $oldcfg{'time_hosts'} || [];
511 $cfg{'time_hosts'} = get_host_list($msg,$def);
513 #---------------------------------------------------------------------------
515 $msg = 'Enter a list of available DAYTIME Hosts :' ;
517 $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
519 $cfg{'daytime_hosts'} = get_host_list($msg,$def);
521 #---------------------------------------------------------------------------
525 Do you have a firewall/ftp proxy between your machine and the internet
527 If you use a SOCKS firewall answer no
532 if(get_bool($msg,0)) {
535 What series of FTP commands do you need to send to your
536 firewall to connect to an external host.
538 user/pass => external user & password
539 fwuser/fwpass => firewall user & password
542 1) -----------------------
543 USER user@remote.host
545 2) -----------------------
548 USER user@remote.host
550 3) -----------------------
556 4) -----------------------
562 5) -----------------------
563 USER user@fwuser@remote.site
565 6) -----------------------
566 USER fwuser@remote.site
570 7) -----------------------
571 USER user@remote.host
578 $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
579 $ans = Prompt($msg,$def);
580 $cfg{'ftp_firewall_type'} = 0+$ans;
581 $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
583 $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
586 delete $cfg{'ftp_firewall'};
590 #---------------------------------------------------------------------------
592 if (defined $cfg{'ftp_firewall'})
596 By default Net::FTP assumes that it only needs to use a firewall if it
597 cannot resolve the name of the host given. This only works if your DNS
598 system is setup to only resolve internal hostnames. If this is not the
599 case and your DNS will resolve external hostnames, then another method
600 is needed. Net::Config can do this if you provide the netmasks that
601 describe your internal network. Each netmask should be entered in the
602 form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
606 if(ref($oldcfg{'local_netmask'}))
608 $def = $oldcfg{'local_netmask'};
609 print "Your current netmasks are :\n\n\t",
610 join("\n\t",@{$def}),"\n\n";
614 Enter one netmask at each prompt, prefix with a - to remove a netmask
615 from the list, enter a '*' to clear the whole list, an '=' to show the
616 current list and an empty line to continue with Configure.
620 my $mask = get_netmask("netmask :",$def);
621 $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
624 #---------------------------------------------------------------------------
628 ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
629 ###then enter a list of hostames
631 ###Enter a list of available SOCKS hosts :
634 ###$def = $cfg{'socks_hosts'} ||
635 ### [ default_hostname($ENV{SOCKS5_SERVER},
636 ### $ENV{SOCKS_SERVER},
637 ### $ENV{SOCKS4_SERVER}) ];
639 ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
641 #---------------------------------------------------------------------------
645 Normally when FTP needs a data connection the client tells the server
646 a port to connect to, and the server initiates a connection to the client.
648 Some setups, in particular firewall setups, can/do not work using this
649 protocol. In these situations the client must make the connection to the
650 server, this is called a passive transfer.
653 if (defined $cfg{'ftp_firewall'}) {
654 $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
656 $def = $oldcfg{'ftp_ext_passive'} || 0;
658 $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
660 $msg = "\nShould all other FTP connections be passive (y|n) ?";
664 $msg = "\nShould all FTP connections be passive (y|n) ?";
667 $def = $oldcfg{'ftp_int_passive'} || 0;
669 $cfg{'ftp_int_passive'} = get_bool($msg,$def);
672 #---------------------------------------------------------------------------
674 $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
676 $ans = Prompt("\nWhat is your local internet domain name :",$def);
678 $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
680 #---------------------------------------------------------------------------
684 If you specified some default hosts above, it is possible for me to
685 do some basic tests when you run `make test'
687 This will cause `make test' to be quite a bit slower and, if your
688 internet connection is via dialup, will require you to be on-line
689 unless the hosts are local.
691 Do you want me to run these tests (y|n) ?
694 $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
696 #---------------------------------------------------------------------------
700 To allow Net::FTP to be tested I will need a hostname. This host
701 should allow anonymous access and have a /pub directory
703 What host can I use :
706 $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
707 if $cfg{'test_hosts'};
712 #---------------------------------------------------------------------------
714 my $fh = IO::File->new($libnet_cfg_out, "w") or
715 die "Cannot create `$libnet_cfg_out': $!";
717 print "Writing $libnet_cfg_out\n";
722 foreach $key (keys %cfg) {
723 my $val = $cfg{$key};
728 $val = '[' . join(",",
732 ($v = $_) =~ s/'/\'/sog;
740 $val = "'" . $val . "'" if $val =~ /\D/;
742 print $fh "\t'",$key,"' => ",$val,",\n";
749 ############################################################################
750 ############################################################################
755 close OUT or die "Can't close $file: $!";
756 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
757 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';