home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.6.1.638-MSWin32-x86.msi / _1c160f5f70c2c91b03b51e59590f526c < prev    next >
Encoding:
Text File  |  2004-04-13  |  12.6 KB  |  605 lines

  1. #!perl
  2.  
  3. #
  4. # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
  5.  
  6. use strict;
  7. use IO::File;
  8. use Getopt::Std;
  9. use ExtUtils::MakeMaker qw(prompt);
  10.  
  11. use vars qw($opt_d $opt_o);
  12. use Config;
  13.  
  14. ##
  15. ##
  16. ##
  17.  
  18. my %cfg = ();
  19. my @cfg = ();
  20.  
  21. my($libnet_cfg,$msg,$ans,$def,$have_old);
  22.  
  23. ##
  24. ##
  25. ##
  26.  
  27. sub valid_host
  28. {
  29.  my $h = shift;
  30.  
  31.  defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
  32. }
  33.  
  34. ##
  35. ##
  36. ##
  37.  
  38. sub test_hostnames (\@)
  39. {
  40.  my $hlist = shift;
  41.  my @h = ();
  42.  my $host;
  43.  my $err = 0;
  44.  
  45.  foreach $host (@$hlist)
  46.   {
  47.    if(valid_host($host))
  48.     {
  49.      push(@h, $host);
  50.      next;
  51.     }
  52.    warn "Bad hostname: '$host'\n";
  53.    $err++;
  54.   }
  55.  @$hlist = @h;
  56.  $err ? join(" ",@h) : undef;
  57. }
  58.  
  59. ##
  60. ##
  61. ##
  62.  
  63. sub Prompt
  64. {
  65.  my($prompt,$def) = @_;
  66.  
  67.  $def = "" unless defined $def;
  68.  
  69.  chomp($prompt);
  70.  
  71.  if($opt_d)
  72.   {
  73.    print $prompt,," [",$def,"]\n";
  74.    return $def;
  75.   }
  76.  prompt($prompt,$def);
  77. }
  78.  
  79. ##
  80. ##
  81. ##
  82.  
  83. sub get_host_list
  84. {
  85.  my($prompt,$def) = @_;
  86.  
  87.  $def = join(" ",@$def) if ref($def);
  88.  
  89.  my @hosts;
  90.  
  91.  do
  92.   {
  93.    my $ans = Prompt($prompt,$def);
  94.  
  95.    $ans =~ s/(\A\s+|\s+\Z)//g;
  96.  
  97.    @hosts = split(/\s+/, $ans);
  98.   }
  99.  while(@hosts && defined($def = test_hostnames(@hosts)));
  100.  
  101.  \@hosts;
  102. }
  103.  
  104. ##
  105. ##
  106. ##
  107.  
  108. sub get_hostname
  109. {
  110.  my($prompt,$def) = @_;
  111.  
  112.  my $host;
  113.  
  114.  while(1)
  115.   {
  116.    my $ans = Prompt($prompt,$def);
  117.    $host = ($ans =~ /(\S*)/)[0];
  118.    last
  119.     if(!length($host) || valid_host($host));
  120.  
  121.    $def =""
  122.     if $def eq $host;
  123.  
  124.    print <<"EDQ";
  125.  
  126. *** ERROR:
  127.     Hostname `$host' does not seem to exist, please enter again
  128.     or a single space to clear any default
  129.  
  130. EDQ
  131.   }
  132.  
  133.  length $host
  134.     ? $host
  135.     : undef;
  136. }
  137.  
  138. ##
  139. ##
  140. ##
  141.  
  142. sub get_bool ($$)
  143. {
  144.  my($prompt,$def) = @_;
  145.  
  146.  chomp($prompt);
  147.  
  148.  my $val = Prompt($prompt,$def ? "yes" : "no");
  149.  
  150.  $val =~ /^y/i ? 1 : 0;
  151. }
  152.  
  153. ##
  154. ##
  155. ##
  156.  
  157. sub get_netmask ($$)
  158. {
  159.  my($prompt,$def) = @_;
  160.  
  161.  chomp($prompt);
  162.  
  163.  my %list;
  164.  @list{@$def} = ();
  165.  
  166. MASK:
  167.  while(1) {
  168.    my $bad = 0;
  169.    my $ans = Prompt($prompt) or last;
  170.  
  171.    if($ans eq '*') {
  172.      %list = ();
  173.      next;
  174.    }
  175.  
  176.    if($ans eq '=') {
  177.      print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
  178.      next;
  179.    }
  180.  
  181.    unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
  182.      warn "Bad netmask '$ans'\n";
  183.      next;
  184.    }
  185.  
  186.    my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
  187.    if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
  188.      warn "Bad netmask '$ans'\n";
  189.      next MASK;
  190.    }
  191.    foreach my $byte (@ip) {
  192.      if ( $byte > 255 ) {
  193.        warn "Bad netmask '$ans'\n";
  194.        next MASK;
  195.      }
  196.    } 
  197.  
  198.    my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits); 
  199.  
  200.    if ($remove) {
  201.      delete $list{$mask};
  202.    }
  203.    else {
  204.      $list{$mask} = 1;
  205.    }
  206.  
  207.   }
  208.  
  209.  [ keys %list ];
  210. }
  211.  
  212. ##
  213. ##
  214. ##
  215.  
  216. sub default_hostname
  217. {
  218.  my $host;
  219.  my @host;
  220.  
  221.  foreach $host (@_)
  222.   {
  223.    if(defined($host) && valid_host($host))
  224.     {
  225.      return $host
  226.     unless wantarray;
  227.      push(@host,$host);
  228.     }
  229.   }
  230.  
  231.  return wantarray ? @host : undef;
  232. }
  233.  
  234. ##
  235. ##
  236. ##
  237.  
  238. getopts('do:');
  239.  
  240. $libnet_cfg = "$Config{installsitelib}/Net/libnet.cfg"
  241.     unless(defined($libnet_cfg = $opt_o));
  242.  
  243. my %oldcfg = ();
  244.  
  245. $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
  246. if( -f $libnet_cfg )
  247.  {
  248.   %oldcfg = ( %{ do $libnet_cfg } );
  249.  }
  250. elsif (eval { require Net::Config }) 
  251.  {
  252.   $have_old = 1;
  253.   %oldcfg = %Net::Config::NetConfig;
  254.  }
  255.  
  256. map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
  257.  
  258. $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
  259. $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
  260.  
  261. #---------------------------------------------------------------------------
  262.  
  263. if($have_old && !$opt_d)
  264.  {
  265.   $msg = <<EDQ;
  266.  
  267. Ah, I see you already have installed libnet before.
  268.  
  269. Do you want to modify/update your configuration (y|n) ?
  270. EDQ
  271.  
  272.  $opt_d = 1
  273.     unless get_bool($msg,0);
  274.  }
  275.  
  276. #---------------------------------------------------------------------------
  277.  
  278. $msg = <<EDQ;
  279.  
  280. This script will prompt you to enter hostnames that can be used as
  281. defaults for some of the modules in the libnet distribution.
  282.  
  283. To ensure that you do not enter an invalid hostname, I can perform a
  284. lookup on each hostname you enter. If your internet connection is via
  285. a dialup line then you may not want me to perform these lookups, as
  286. it will require you to be on-line.
  287.  
  288. Do you want me to perform hostname lookups (y|n) ?
  289. EDQ
  290.  
  291. $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
  292.  
  293. print <<EDQ unless $cfg{'test_exist'};
  294.  
  295. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  296.  
  297. OK I will not check if the hostnames you give are valid
  298. so be very cafeful
  299.  
  300. *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
  301. EDQ
  302.  
  303.  
  304. #---------------------------------------------------------------------------
  305.  
  306. print <<EDQ;
  307.  
  308. The following questions all require a list of host names, separated
  309. with spaces. If you do not have a host available for any of the
  310. services, then enter a single space, followed by <CR>. To accept the
  311. default, hit <CR>
  312.  
  313. EDQ
  314.  
  315. $msg = 'Enter a list of available NNTP hosts :';
  316.  
  317. $def = $oldcfg{'nntp_hosts'} ||
  318.     [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
  319.  
  320. $cfg{'nntp_hosts'} = get_host_list($msg,$def);
  321.  
  322. #---------------------------------------------------------------------------
  323.  
  324. $msg = 'Enter a list of available SMTP hosts :';
  325.  
  326. $def = $oldcfg{'smtp_hosts'} ||
  327.     [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
  328.  
  329. $cfg{'smtp_hosts'} = get_host_list($msg,$def);
  330.  
  331. #---------------------------------------------------------------------------
  332.  
  333. $msg = 'Enter a list of available POP3 hosts :';
  334.  
  335. $def = $oldcfg{'pop3_hosts'} || [];
  336.  
  337. $cfg{'pop3_hosts'} = get_host_list($msg,$def);
  338.  
  339. #---------------------------------------------------------------------------
  340.  
  341. $msg = 'Enter a list of available SNPP hosts :';
  342.  
  343. $def = $oldcfg{'snpp_hosts'} || [];
  344.  
  345. $cfg{'snpp_hosts'} = get_host_list($msg,$def);
  346.  
  347. #---------------------------------------------------------------------------
  348.  
  349. $msg = 'Enter a list of available PH Hosts   :'  ;
  350.  
  351. $def = $oldcfg{'ph_hosts'} ||
  352.     [ default_hostname('dirserv') ];
  353.  
  354. $cfg{'ph_hosts'}   =  get_host_list($msg,$def);
  355.  
  356. #---------------------------------------------------------------------------
  357.  
  358. $msg = 'Enter a list of available TIME Hosts   :'  ;
  359.  
  360. $def = $oldcfg{'time_hosts'} || [];
  361.  
  362. $cfg{'time_hosts'} = get_host_list($msg,$def);
  363.  
  364. #---------------------------------------------------------------------------
  365.  
  366. $msg = 'Enter a list of available DAYTIME Hosts   :'  ;
  367.  
  368. $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
  369.  
  370. $cfg{'daytime_hosts'} = get_host_list($msg,$def);
  371.  
  372. #---------------------------------------------------------------------------
  373.  
  374. $msg = <<EDQ;
  375.  
  376. Do you have a firewall/ftp proxy  between your machine and the internet 
  377.  
  378. If you use a SOCKS firewall answer no
  379.  
  380. (y|n) ?
  381. EDQ
  382.  
  383. if(get_bool($msg,0)) {
  384.  
  385.   $msg = <<'EDQ';
  386. What series of FTP commands do you need to send to your
  387. firewall to connect to an external host.
  388.  
  389. user/pass     => external user & password
  390. fwuser/fwpass => firewall user & password
  391.  
  392. 0) None
  393. 1) -----------------------
  394.      USER user@remote.host
  395.      PASS pass
  396. 2) -----------------------
  397.      USER fwuser
  398.      PASS fwpass
  399.      USER user@remote.host
  400.      PASS pass
  401. 3) -----------------------
  402.      USER fwuser
  403.      PASS fwpass
  404.      SITE remote.site
  405.      USER user
  406.      PASS pass
  407. 4) -----------------------
  408.      USER fwuser
  409.      PASS fwpass
  410.      OPEN remote.site
  411.      USER user
  412.      PASS pass
  413. 5) -----------------------
  414.      USER user@fwuser@remote.site
  415.      PASS pass@fwpass
  416. 6) -----------------------
  417.      USER fwuser@remote.site
  418.      PASS fwpass
  419.      USER user
  420.      PASS pass
  421. 7) -----------------------
  422.      USER user@remote.host
  423.      PASS pass
  424.      AUTH fwuser
  425.      RESP fwpass
  426.  
  427. Choice:
  428. EDQ
  429.  $def = exists $oldcfg{'ftp_firewall_type'}  ? $oldcfg{'ftp_firewall_type'} : 1;
  430.  $ans = Prompt($msg,$def);
  431.  $cfg{'ftp_firewall_type'} = 0+$ans;
  432.  $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
  433.  
  434.  $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
  435. }
  436. else {
  437.  delete $cfg{'ftp_firewall'};
  438. }
  439.  
  440.  
  441. #---------------------------------------------------------------------------
  442.  
  443. if (defined $cfg{'ftp_firewall'})
  444.  {
  445.   print <<EDQ;
  446.  
  447. By default Net::FTP assumes that it only needs to use a firewall if it
  448. cannot resolve the name of the host given. This only works if your DNS
  449. system is setup to only resolve internal hostnames. If this is not the
  450. case and your DNS will resolve external hostnames, then another method
  451. is needed. Net::Config can do this if you provide the netmasks that
  452. describe your internal network. Each netmask should be entered in the
  453. form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
  454.  
  455. EDQ
  456. $def = [];
  457. if(ref($oldcfg{'local_netmask'}))
  458.  {
  459.   $def = $oldcfg{'local_netmask'};
  460.    print "Your current netmasks are :\n\n\t",
  461.     join("\n\t",@{$def}),"\n\n";
  462.  }
  463.  
  464. print "
  465. Enter one netmask at each prompt, prefix with a - to remove a netmask
  466. from the list, enter a '*' to clear the whole list, an '=' to show the
  467. current list and an empty line to continue with Configure.
  468.  
  469. ";
  470.  
  471.   my $mask = get_netmask("netmask :",$def);
  472.   $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
  473.  }
  474.  
  475. #---------------------------------------------------------------------------
  476.  
  477. ###$msg =<<EDQ;
  478. ###
  479. ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
  480. ###then enter a list of hostames
  481. ###
  482. ###Enter a list of available SOCKS hosts :
  483. ###EDQ
  484. ###
  485. ###$def = $cfg{'socks_hosts'} ||
  486. ###    [ default_hostname($ENV{SOCKS5_SERVER},
  487. ###               $ENV{SOCKS_SERVER},
  488. ###               $ENV{SOCKS4_SERVER}) ];
  489. ###
  490. ###$cfg{'socks_hosts'}   =  get_host_list($msg,$def);
  491.  
  492. #---------------------------------------------------------------------------
  493.  
  494. print <<EDQ;
  495.  
  496. Normally when FTP needs a data connection the client tells the server
  497. a port to connect to, and the server initiates a connection to the client.
  498.  
  499. Some setups, in particular firewall setups, can/do not work using this
  500. protocol. In these situations the client must make the connection to the
  501. server, this is called a passive transfer.
  502. EDQ
  503.  
  504. if (defined $cfg{'ftp_firewall'}) {
  505.   $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
  506.  
  507.   $def = $oldcfg{'ftp_ext_passive'} || 0;
  508.  
  509.   $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
  510.  
  511.   $msg = "\nShould all other FTP connections be passive (y|n) ?";
  512.  
  513. }
  514. else {
  515.   $msg = "\nShould all FTP connections be passive (y|n) ?";
  516. }
  517.  
  518. $def = $oldcfg{'ftp_int_passive'} || 0;
  519.  
  520. $cfg{'ftp_int_passive'} = get_bool($msg,$def);
  521.  
  522.  
  523. #---------------------------------------------------------------------------
  524.  
  525. $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
  526.  
  527. $ans = Prompt("\nWhat is your local internet domain name :",$def);
  528.  
  529. $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
  530.  
  531. #---------------------------------------------------------------------------
  532.  
  533. $msg = <<EDQ;
  534.  
  535. If you specified some default hosts above, it is possible for me to
  536. do some basic tests when you run `make test'
  537.  
  538. This will cause `make test' to be quite a bit slower and, if your
  539. internet connection is via dialup, will require you to be on-line
  540. unless the hosts are local.
  541.  
  542. Do you want me to run these tests (y|n) ?
  543. EDQ
  544.  
  545. $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
  546.  
  547. #---------------------------------------------------------------------------
  548.  
  549. $msg = <<EDQ;
  550.  
  551. To allow Net::FTP to be tested I will need a hostname. This host
  552. should allow anonymous access and have a /pub directory
  553.  
  554. What host can I use :
  555. EDQ
  556.  
  557. $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
  558.     if $cfg{'test_hosts'};
  559.  
  560.  
  561. print "\n";
  562.  
  563. #---------------------------------------------------------------------------
  564.  
  565. chmod(0644, $libnet_cfg);
  566. my $fh = IO::File->new($libnet_cfg, "w") or
  567.     die "Cannot create `$libnet_cfg': $!";
  568.  
  569. print "Writing $libnet_cfg\n";
  570.  
  571. print $fh "{\n";
  572.  
  573. my $key;
  574. foreach $key (keys %cfg) {
  575.     my $val = $cfg{$key};
  576.     if(!defined($val)) {
  577.     $val = "undef";
  578.     }
  579.     elsif(ref($val)) {
  580.     $val = '[' . join(",",
  581.         map {
  582.         my $v = "undef";
  583.         if(defined $_) {
  584.             ($v = $_) =~ s/'/\'/sog;
  585.             $v = "'" . $v . "'";
  586.         }
  587.         $v;
  588.         } @$val ) . ']';
  589.     }
  590.     else {
  591.     $val =~ s/'/\'/sog;
  592.     $val = "'" . $val . "'" if $val =~ /\D/;
  593.     }
  594.     print $fh "\t'",$key,"' => ",$val,",\n";
  595. }
  596.  
  597. print $fh "}\n";
  598.  
  599. $fh->close;
  600.  
  601. ############################################################################
  602. ############################################################################
  603.  
  604. exit 0;
  605.