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 # 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 the from your module path.
82 The default name of 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<Net::libnetFAQ>
92 Graham Barr, the original Configure script of libnet.
94 Jarkko Hietaniemi, conversion into libnet cfg for inclusion into Perl 5.8.
98 # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
103 use ExtUtils::MakeMaker qw(prompt);
106 use vars qw($opt_d $opt_c $opt_h $opt_o $opt_i);
115 my($libnet_cfg_in,$libnet_cfg_out,$msg,$ans,$def,$have_old);
125 defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
132 sub test_hostnames (\@)
139 foreach $host (@$hlist)
141 if(valid_host($host))
146 warn "Bad hostname: '$host'\n";
150 $err ? join(" ",@h) : undef;
159 my($prompt,$def) = @_;
161 $def = "" unless defined $def;
167 print $prompt,," [",$def,"]\n";
170 prompt($prompt,$def);
179 my($prompt,$def) = @_;
181 $def = join(" ",@$def) if ref($def);
187 my $ans = Prompt($prompt,$def);
189 $ans =~ s/(\A\s+|\s+\Z)//g;
191 @hosts = split(/\s+/, $ans);
193 while(@hosts && defined($def = test_hostnames(@hosts)));
204 my($prompt,$def) = @_;
210 my $ans = Prompt($prompt,$def);
211 $host = ($ans =~ /(\S*)/)[0];
213 if(!length($host) || valid_host($host));
221 Hostname `$host' does not seem to exist, please enter again
222 or a single space to clear any default
238 my($prompt,$def) = @_;
242 my $val = Prompt($prompt,$def ? "yes" : "no");
244 $val =~ /^y/i ? 1 : 0;
253 my($prompt,$def) = @_;
263 my $ans = Prompt($prompt) or last;
271 print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
275 unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
276 warn "Bad netmask '$ans'\n";
280 my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
281 if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
282 warn "Bad netmask '$ans'\n";
285 foreach my $byte (@ip) {
287 warn "Bad netmask '$ans'\n";
292 my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
317 if(defined($host) && valid_host($host))
325 return wantarray ? @host : undef;
334 $libnet_cfg_in = "libnet.cfg"
335 unless(defined($libnet_cfg_in = $opt_i));
337 $libnet_cfg_out = "libnet.cfg"
338 unless(defined($libnet_cfg_out = $opt_o));
342 $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
343 if( -f $libnet_cfg_in )
345 %oldcfg = ( %{ do $libnet_cfg_in } );
347 elsif (eval { require Net::Config })
350 %oldcfg = %Net::Config::NetConfig;
353 map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
355 #---------------------------------------------------------------------------
359 $0: Usage: $0 [-c] [-d] [-i oldconfigile] [-o newconfigfile] [-h]
360 Without options, the old configuration is shown.
362 -c change the configuration
363 -d use defaults from the old config (implies -c, non-interactive)
364 -i use a specific file as the old config file
365 -o use a specific file as the new config file
368 The default name of the old configuration file is by default
369 "libnet.cfg", unless otherwise specified using the -i option,
370 C<-i oldfile>, and it is searched first from the current directory,
371 and the from your module path.
373 The default name of new configuration file is "libnet.cfg", and by
374 default it is written to the current directory, unless otherwise
375 specified using the -o option.
381 #---------------------------------------------------------------------------
386 push @inc, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
387 push @inc, $ENV{PERLLIB} if exists $ENV{PERLLIB};
390 my $trycfgfile = File::Spec->catfile($_, $libnet_cfg_in);
391 if (-f $trycfgfile && -r $trycfgfile) {
392 $oldcfgfile = $trycfgfile;
396 print "# old config $oldcfgfile\n" if defined $oldcfgfile;
397 for (sort keys %oldcfg) {
398 printf "%-20s %s\n", $_,
399 ref $oldcfg{$_} ? @{$oldcfg{$_}} : $oldcfg{$_};
401 unless ($opt_c || $opt_d) {
402 print "# $0 -h for help\n";
407 #---------------------------------------------------------------------------
409 $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
410 $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
412 #---------------------------------------------------------------------------
414 if($have_old && !$opt_d)
418 Ah, I see you already have installed libnet before.
420 Do you want to modify/update your configuration (y|n) ?
424 unless get_bool($msg,0);
427 #---------------------------------------------------------------------------
431 This script will prompt you to enter hostnames that can be used as
432 defaults for some of the modules in the libnet distribution.
434 To ensure that you do not enter an invalid hostname, I can perform a
435 lookup on each hostname you enter. If your internet connection is via
436 a dialup line then you may not want me to perform these lookups, as
437 it will require you to be on-line.
439 Do you want me to perform hostname lookups (y|n) ?
442 $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
444 print <<EDQ unless $cfg{'test_exist'};
446 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
448 OK I will not check if the hostnames you give are valid
451 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
455 #---------------------------------------------------------------------------
459 The following questions all require a list of host names, separated
460 with spaces. If you do not have a host available for any of the
461 services, then enter a single space, followed by <CR>. To accept the
466 $msg = 'Enter a list of available NNTP hosts :';
468 $def = $oldcfg{'nntp_hosts'} ||
469 [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
471 $cfg{'nntp_hosts'} = get_host_list($msg,$def);
473 #---------------------------------------------------------------------------
475 $msg = 'Enter a list of available SMTP hosts :';
477 $def = $oldcfg{'smtp_hosts'} ||
478 [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
480 $cfg{'smtp_hosts'} = get_host_list($msg,$def);
482 #---------------------------------------------------------------------------
484 $msg = 'Enter a list of available POP3 hosts :';
486 $def = $oldcfg{'pop3_hosts'} || [];
488 $cfg{'pop3_hosts'} = get_host_list($msg,$def);
490 #---------------------------------------------------------------------------
492 $msg = 'Enter a list of available SNPP hosts :';
494 $def = $oldcfg{'snpp_hosts'} || [];
496 $cfg{'snpp_hosts'} = get_host_list($msg,$def);
498 #---------------------------------------------------------------------------
500 $msg = 'Enter a list of available PH Hosts :' ;
502 $def = $oldcfg{'ph_hosts'} ||
503 [ default_hostname('dirserv') ];
505 $cfg{'ph_hosts'} = get_host_list($msg,$def);
507 #---------------------------------------------------------------------------
509 $msg = 'Enter a list of available TIME Hosts :' ;
511 $def = $oldcfg{'time_hosts'} || [];
513 $cfg{'time_hosts'} = get_host_list($msg,$def);
515 #---------------------------------------------------------------------------
517 $msg = 'Enter a list of available DAYTIME Hosts :' ;
519 $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
521 $cfg{'daytime_hosts'} = get_host_list($msg,$def);
523 #---------------------------------------------------------------------------
527 Do you have a firewall/ftp proxy between your machine and the internet
529 If you use a SOCKS firewall answer no
534 if(get_bool($msg,0)) {
537 What series of FTP commands do you need to send to your
538 firewall to connect to an external host.
540 user/pass => external user & password
541 fwuser/fwpass => firewall user & password
544 1) -----------------------
545 USER user@remote.host
547 2) -----------------------
550 USER user@remote.host
552 3) -----------------------
558 4) -----------------------
564 5) -----------------------
565 USER user@fwuser@remote.site
567 6) -----------------------
568 USER fwuser@remote.site
572 7) -----------------------
573 USER user@remote.host
580 $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
581 $ans = Prompt($msg,$def);
582 $cfg{'ftp_firewall_type'} = 0+$ans;
583 $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
585 $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
588 delete $cfg{'ftp_firewall'};
592 #---------------------------------------------------------------------------
594 if (defined $cfg{'ftp_firewall'})
598 By default Net::FTP assumes that it only needs to use a firewall if it
599 cannot resolve the name of the host given. This only works if your DNS
600 system is setup to only resolve internal hostnames. If this is not the
601 case and your DNS will resolve external hostnames, then another method
602 is needed. Net::Config can do this if you provide the netmasks that
603 describe your internal network. Each netmask should be entered in the
604 form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
608 if(ref($oldcfg{'local_netmask'}))
610 $def = $oldcfg{'local_netmask'};
611 print "Your current netmasks are :\n\n\t",
612 join("\n\t",@{$def}),"\n\n";
616 Enter one netmask at each prompt, prefix with a - to remove a netmask
617 from the list, enter a '*' to clear the whole list, an '=' to show the
618 current list and an empty line to continue with Configure.
622 my $mask = get_netmask("netmask :",$def);
623 $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
626 #---------------------------------------------------------------------------
630 ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
631 ###then enter a list of hostames
633 ###Enter a list of available SOCKS hosts :
636 ###$def = $cfg{'socks_hosts'} ||
637 ### [ default_hostname($ENV{SOCKS5_SERVER},
638 ### $ENV{SOCKS_SERVER},
639 ### $ENV{SOCKS4_SERVER}) ];
641 ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
643 #---------------------------------------------------------------------------
647 Normally when FTP needs a data connection the client tells the server
648 a port to connect to, and the server initiates a connection to the client.
650 Some setups, in particular firewall setups, can/do not work using this
651 protocol. In these situations the client must make the connection to the
652 server, this is called a passive transfer.
655 if (defined $cfg{'ftp_firewall'}) {
656 $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
658 $def = $oldcfg{'ftp_ext_passive'} || 0;
660 $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
662 $msg = "\nShould all other FTP connections be passive (y|n) ?";
666 $msg = "\nShould all FTP connections be passive (y|n) ?";
669 $def = $oldcfg{'ftp_int_passive'} || 0;
671 $cfg{'ftp_int_passive'} = get_bool($msg,$def);
674 #---------------------------------------------------------------------------
676 $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
678 $ans = Prompt("\nWhat is your local internet domain name :",$def);
680 $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
682 #---------------------------------------------------------------------------
686 If you specified some default hosts above, it is possible for me to
687 do some basic tests when you run `make test'
689 This will cause `make test' to be quite a bit slower and, if your
690 internet connection is via dialup, will require you to be on-line
691 unless the hosts are local.
693 Do you want me to run these tests (y|n) ?
696 $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
698 #---------------------------------------------------------------------------
702 To allow Net::FTP to be tested I will need a hostname. This host
703 should allow anonymous access and have a /pub directory
705 What host can I use :
708 $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
709 if $cfg{'test_hosts'};
714 #---------------------------------------------------------------------------
716 my $fh = IO::File->new($libnet_cfg_out, "w") or
717 die "Cannot create `$libnet_cfg_out': $!";
719 print "Writing $libnet_cfg_out\n";
724 foreach $key (keys %cfg) {
725 my $val = $cfg{$key};
730 $val = '[' . join(",",
734 ($v = $_) =~ s/'/\'/sog;
742 $val = "'" . $val . "'" if $val =~ /\D/;
744 print $fh "\t'",$key,"' => ",$val,",\n";
751 ############################################################################
752 ############################################################################
757 close OUT or die "Can't close $file: $!";
758 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
759 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';