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!';
38 # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
43 use ExtUtils::MakeMaker qw(prompt);
45 use vars qw($opt_d $opt_o);
54 my($libnet_cfg,$msg,$ans,$def,$have_old);
64 defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
71 sub test_hostnames (\@)
78 foreach $host (@$hlist)
85 warn "Bad hostname: '$host'\n";
89 $err ? join(" ",@h) : undef;
98 my($prompt,$def) = @_;
100 $def = "" unless defined $def;
106 print $prompt,," [",$def,"]\n";
109 prompt($prompt,$def);
118 my($prompt,$def) = @_;
120 $def = join(" ",@$def) if ref($def);
126 my $ans = Prompt($prompt,$def);
128 $ans =~ s/(\A\s+|\s+\Z)//g;
130 @hosts = split(/\s+/, $ans);
132 while(@hosts && defined($def = test_hostnames(@hosts)));
143 my($prompt,$def) = @_;
149 my $ans = Prompt($prompt,$def);
150 $host = ($ans =~ /(\S*)/)[0];
152 if(!length($host) || valid_host($host));
160 Hostname `$host' does not seem to exist, please enter again
161 or a single space to clear any default
177 my($prompt,$def) = @_;
181 my $val = Prompt($prompt,$def ? "yes" : "no");
183 $val =~ /^y/i ? 1 : 0;
192 my($prompt,$def) = @_;
202 my $ans = Prompt($prompt) or last;
210 print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
214 unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
215 warn "Bad netmask '$ans'\n";
219 my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
220 if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
221 warn "Bad netmask '$ans'\n";
224 foreach my $byte (@ip) {
226 warn "Bad netmask '$ans'\n";
231 my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
256 if(defined($host) && valid_host($host))
264 return wantarray ? @host : undef;
273 $libnet_cfg = "libnet.cfg"
274 unless(defined($libnet_cfg = $opt_o));
278 $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
281 %oldcfg = ( %{ do $libnet_cfg } );
283 elsif (eval { require Net::Config })
286 %oldcfg = %Net::Config::NetConfig;
289 map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
291 $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
292 $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
294 #---------------------------------------------------------------------------
296 if($have_old && !$opt_d)
300 Ah, I see you already have installed libnet before.
302 Do you want to modify/update your configuration (y|n) ?
306 unless get_bool($msg,0);
309 #---------------------------------------------------------------------------
313 This script will prompt you to enter hostnames that can be used as
314 defaults for some of the modules in the libnet distribution.
316 To ensure that you do not enter an invalid hostname, I can perform a
317 lookup on each hostname you enter. If your internet connection is via
318 a dialup line then you may not want me to perform these lookups, as
319 it will require you to be on-line.
321 Do you want me to perform hostname lookups (y|n) ?
324 $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
326 print <<EDQ unless $cfg{'test_exist'};
328 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
330 OK I will not check if the hostnames you give are valid
333 *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
337 #---------------------------------------------------------------------------
341 The following questions all require a list of host names, separated
342 with spaces. If you do not have a host available for any of the
343 services, then enter a single space, followed by <CR>. To accept the
348 $msg = 'Enter a list of available NNTP hosts :';
350 $def = $oldcfg{'nntp_hosts'} ||
351 [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
353 $cfg{'nntp_hosts'} = get_host_list($msg,$def);
355 #---------------------------------------------------------------------------
357 $msg = 'Enter a list of available SMTP hosts :';
359 $def = $oldcfg{'smtp_hosts'} ||
360 [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
362 $cfg{'smtp_hosts'} = get_host_list($msg,$def);
364 #---------------------------------------------------------------------------
366 $msg = 'Enter a list of available POP3 hosts :';
368 $def = $oldcfg{'pop3_hosts'} || [];
370 $cfg{'pop3_hosts'} = get_host_list($msg,$def);
372 #---------------------------------------------------------------------------
374 $msg = 'Enter a list of available SNPP hosts :';
376 $def = $oldcfg{'snpp_hosts'} || [];
378 $cfg{'snpp_hosts'} = get_host_list($msg,$def);
380 #---------------------------------------------------------------------------
382 $msg = 'Enter a list of available PH Hosts :' ;
384 $def = $oldcfg{'ph_hosts'} ||
385 [ default_hostname('dirserv') ];
387 $cfg{'ph_hosts'} = get_host_list($msg,$def);
389 #---------------------------------------------------------------------------
391 $msg = 'Enter a list of available TIME Hosts :' ;
393 $def = $oldcfg{'time_hosts'} || [];
395 $cfg{'time_hosts'} = get_host_list($msg,$def);
397 #---------------------------------------------------------------------------
399 $msg = 'Enter a list of available DAYTIME Hosts :' ;
401 $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
403 $cfg{'daytime_hosts'} = get_host_list($msg,$def);
405 #---------------------------------------------------------------------------
409 Do you have a firewall/ftp proxy between your machine and the internet
411 If you use a SOCKS firewall answer no
416 if(get_bool($msg,0)) {
419 What series of FTP commands do you need to send to your
420 firewall to connect to an external host.
422 user/pass => external user & password
423 fwuser/fwpass => firewall user & password
426 1) -----------------------
427 USER user@remote.host
429 2) -----------------------
432 USER user@remote.host
434 3) -----------------------
440 4) -----------------------
446 5) -----------------------
447 USER user@fwuser@remote.site
449 6) -----------------------
450 USER fwuser@remote.site
454 7) -----------------------
455 USER user@remote.host
462 $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
463 $ans = Prompt($msg,$def);
464 $cfg{'ftp_firewall_type'} = 0+$ans;
465 $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
467 $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
470 delete $cfg{'ftp_firewall'};
474 #---------------------------------------------------------------------------
476 if (defined $cfg{'ftp_firewall'})
480 By default Net::FTP assumes that it only needs to use a firewall if it
481 cannot resolve the name of the host given. This only works if your DNS
482 system is setup to only resolve internal hostnames. If this is not the
483 case and your DNS will resolve external hostnames, then another method
484 is needed. Net::Config can do this if you provide the netmasks that
485 describe your internal network. Each netmask should be entered in the
486 form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
490 if(ref($oldcfg{'local_netmask'}))
492 $def = $oldcfg{'local_netmask'};
493 print "Your current netmasks are :\n\n\t",
494 join("\n\t",@{$def}),"\n\n";
498 Enter one netmask at each prompt, prefix with a - to remove a netmask
499 from the list, enter a '*' to clear the whole list, an '=' to show the
500 current list and an empty line to continue with Configure.
504 my $mask = get_netmask("netmask :",$def);
505 $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
508 #---------------------------------------------------------------------------
512 ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
513 ###then enter a list of hostames
515 ###Enter a list of available SOCKS hosts :
518 ###$def = $cfg{'socks_hosts'} ||
519 ### [ default_hostname($ENV{SOCKS5_SERVER},
520 ### $ENV{SOCKS_SERVER},
521 ### $ENV{SOCKS4_SERVER}) ];
523 ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
525 #---------------------------------------------------------------------------
529 Normally when FTP needs a data connection the client tells the server
530 a port to connect to, and the server initiates a connection to the client.
532 Some setups, in particular firewall setups, can/do not work using this
533 protocol. In these situations the client must make the connection to the
534 server, this is called a passive transfer.
537 if (defined $cfg{'ftp_firewall'}) {
538 $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
540 $def = $oldcfg{'ftp_ext_passive'} || 0;
542 $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
544 $msg = "\nShould all other FTP connections be passive (y|n) ?";
548 $msg = "\nShould all FTP connections be passive (y|n) ?";
551 $def = $oldcfg{'ftp_int_passive'} || 0;
553 $cfg{'ftp_int_passive'} = get_bool($msg,$def);
556 #---------------------------------------------------------------------------
558 $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
560 $ans = Prompt("\nWhat is your local internet domain name :",$def);
562 $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
564 #---------------------------------------------------------------------------
568 If you specified some default hosts above, it is possible for me to
569 do some basic tests when you run `make test'
571 This will cause `make test' to be quite a bit slower and, if your
572 internet connection is via dialup, will require you to be on-line
573 unless the hosts are local.
575 Do you want me to run these tests (y|n) ?
578 $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
580 #---------------------------------------------------------------------------
584 To allow Net::FTP to be tested I will need a hostname. This host
585 should allow anonymous access and have a /pub directory
587 What host can I use :
590 $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
591 if $cfg{'test_hosts'};
596 #---------------------------------------------------------------------------
598 my $fh = IO::File->new($libnet_cfg, "w") or
599 die "Cannot create `$libnet_cfg': $!";
601 print "Writing $libnet_cfg\n";
606 foreach $key (keys %cfg) {
607 my $val = $cfg{$key};
612 $val = '[' . join(",",
616 ($v = $_) =~ s/'/\'/sog;
624 $val = "'" . $val . "'" if $val =~ /\D/;
626 print $fh "\t'",$key,"' => ",$val,",\n";
633 ############################################################################
634 ############################################################################
639 close OUT or die "Can't close $file: $!";
640 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
641 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';