Upgrade to CGI-3.14.
[p5sagit/p5-mst-13.2.git] / lib / Net / Config.pm
index e0dd1d9..a502abe 100644 (file)
@@ -1,6 +1,10 @@
+# Net::Config.pm
+#
+# Copyright (c) 2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
+# This program is free software; you can redistribute it and/or
+# modify it under the same terms as Perl itself.
 
 package Net::Config;
-# $Id: //depot/libnet/Net/Config.pm#6 $
 
 require Exporter;
 use vars qw(@ISA @EXPORT %NetConfig $VERSION $CONFIGURE $LIBNET_CFG);
@@ -9,7 +13,7 @@ use strict;
 
 @EXPORT  = qw(%NetConfig);
 @ISA     = qw(Net::LocalCfg Exporter);
-$VERSION = "1.04";
+$VERSION = "1.10"; # $Id: //depot/libnet/Net/Config.pm#17 $
 
 eval { local $SIG{__DIE__}; require Net::LocalCfg };
 
@@ -29,31 +33,57 @@ eval { local $SIG{__DIE__}; require Net::LocalCfg };
     test_exist => 1,
 );
 
+#
+# Try to get as much configuration info as possible from InternetConfig
+#
+$^O eq 'MacOS' and eval <<TRY_INTERNET_CONFIG;
+use Mac::InternetConfig;
+
+{
+my %nc = (
+    nntp_hosts      => [ \$InternetConfig{ kICNNTPHost() } ],
+    pop3_hosts      => [ \$InternetConfig{ kICMailAccount() } =~ /\@(.*)/ ],
+    smtp_hosts      => [ \$InternetConfig{ kICSMTPHost() } ],
+    ftp_testhost    => \$InternetConfig{ kICFTPHost() } ? \$InternetConfig{ kICFTPHost()} : undef,
+    ph_hosts        => [ \$InternetConfig{ kICPhHost() }   ],
+    ftp_ext_passive => \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0,
+    ftp_int_passive => \$InternetConfig{"646F676F\xA5UsePassiveMode"} || 0,
+    socks_hosts     => 
+       \$InternetConfig{ kICUseSocks() }    ? [ \$InternetConfig{ kICSocksHost() }    ] : [],
+    ftp_firewall    => 
+       \$InternetConfig{ kICUseFTPProxy() } ? [ \$InternetConfig{ kICFTPProxyHost() } ] : [],
+);
+\@NetConfig{keys %nc} = values %nc;
+}
+TRY_INTERNET_CONFIG
+
 my $file = __FILE__;
 my $ref;
 $file =~ s/Config.pm/libnet.cfg/;
 if ( -f $file ) {
-    $ref = eval { do $file };
+    $ref = eval { local $SIG{__DIE__}; do $file };
     if (ref($ref) eq 'HASH') {
        %NetConfig = (%NetConfig, %{ $ref });
        $LIBNET_CFG = $file;
     }
 }
 if ($< == $> and !$CONFIGURE)  {
-    use File::Spec;
-    my $home = eval { (getpwuid($>))[7] } || $ENV{HOME} || $ENV{HOMEDRIVE} || $ENV{HOMEPATH} || File::Spec->curdir;
-    $file = File::Spec->catfile($home, ".libnetrc");
-    $ref = eval { do $file } if -f $file;
-    %NetConfig = (%NetConfig, %{ $ref })
-       if ref($ref) eq 'HASH'; 
+    my $home = eval { local $SIG{__DIE__}; (getpwuid($>))[7] } || $ENV{HOME};
+    $home ||= $ENV{HOMEDRIVE} . ($ENV{HOMEPATH}||'') if defined $ENV{HOMEDRIVE};
+    if (defined $home) {
+       $file = $home . "/.libnetrc";
+       $ref = eval { local $SIG{__DIE__}; do $file } if -f $file;
+       %NetConfig = (%NetConfig, %{ $ref })
+           if ref($ref) eq 'HASH';     
+    }
 }
 my ($k,$v);
 while(($k,$v) = each %NetConfig) {
-    $v = [ $v ]
-       if($k =~ /_hosts$/ && !ref($v));
+       $NetConfig{$k} = [ $v ]
+               if($k =~ /_hosts$/ and $k ne "test_hosts" and defined($v) and !ref($v));
 }
 
-# Take a hostname and determine if it is inside te firewall
+# Take a hostname and determine if it is inside the firewall
 
 sub requires_firewall {
     shift; # ignore package
@@ -99,17 +129,17 @@ Net::Config - Local configuration data for libnet
 =head1 DESCRIPTION
 
 C<Net::Config> holds configuration data for the modules in the libnet
-distribuion. During installation you will be asked for these values.
+distribution. During installation you will be asked for these values.
 
 The configuration data is held globally in a file in the perl installation
-tree, but a user may override any of these values by providing thier own. This
-can be done by having a C<.libnetrc> file in thier home directory. This file
+tree, but a user may override any of these values by providing their own. This
+can be done by having a C<.libnetrc> file in their home directory. This file
 should return a reference to a HASH containing the keys described below.
 For example
 
     # .libnetrc
     {
-        nntp_hosts => [ "my_prefered_host" ],
+        nntp_hosts => [ "my_preferred_host" ],
        ph_hosts   => [ "my_ph_server" ],
     }
     __END__
@@ -163,27 +193,94 @@ Your internet domain name
 
 =item ftp_firewall
 
-If you have an FTP proxy firewall (B<NOT> a HTTP or SOCKS firewall)
+If you have an FTP proxy firewall (B<NOT> an HTTP or SOCKS firewall)
 then this value should be set to the firewall hostname. If your firewall
 does not listen to port 21, then this value should be set to
 C<"hostname:port"> (eg C<"hostname:99">)
 
+=item ftp_firewall_type
+
+There are many different ftp firewall products available. But unfortunately
+there is no standard for how to traverse a firewall.  The list below shows the
+sequence of commands that Net::FTP will use
+
+  user        Username for remote host
+  pass        Password for remote host
+  fwuser      Username for firewall
+  fwpass      Password for firewall
+  remote.host The hostname of the remote ftp server
+
+=over 4
+
+=item 0
+
+There is no firewall
+
+=item 1
+
+     USER user@remote.host
+     PASS pass
+
+=item 2
+
+     USER fwuser
+     PASS fwpass
+     USER user@remote.host
+     PASS pass
+
+=item 3
+
+     USER fwuser
+     PASS fwpass
+     SITE remote.site
+     USER user
+     PASS pass
+
+=item 4
+
+     USER fwuser
+     PASS fwpass
+     OPEN remote.site
+     USER user
+     PASS pass
+
+=item 5
+
+     USER user@fwuser@remote.site
+     PASS pass@fwpass
+
+=item 6
+
+     USER fwuser@remote.site
+     PASS fwpass
+     USER user
+     PASS pass
+
+=item 7
+
+     USER user@remote.host
+     PASS pass
+     AUTH fwuser
+     RESP fwpass
+
+=back
+
 =item ftp_ext_passive
 
-=item ftp_int_pasive
+=item ftp_int_passive
 
 FTP servers normally work on a non-passive mode. That is when you want to
 transfer data you have to tell the server the address and port to
 connect to.
 
-With some firewalls this does not work as te server cannot
-connect to your machine (because you are beind a firewall) and the firewall
-does not re-write te command. In this case you should set C<ftp_ext_passive>
+With some firewalls this does not work as the server cannot
+connect to your machine (because you are behind a firewall) and the firewall
+does not re-write the command. In this case you should set C<ftp_ext_passive>
 to a I<true> value.
 
 Some servers are configured to only work in passive mode. If you have
 one of these you can force C<Net::FTP> to always transfer in passive
-mode, when not going via a firewall, by cetting C<ftp_int_passive> to
+mode; when not going via a firewall, by setting C<ftp_int_passive> to
 a I<true> value.
 
 =item local_netmask
@@ -201,13 +298,17 @@ libnet package
 
 =item test_hosts
 
-If true them C<make test> may attempt to connect to hosts given in the
+If true then C<make test> may attempt to connect to hosts given in the
 configuration.
 
 =item test_exists
 
-If true the C<Configure> will check each hostname given that it exists
+If true then C<Configure> will check each hostname given that it exists
 
 =back
 
+=for html <hr>
+
+I<$Id: //depot/libnet/Net/Config.pm#17 $>
+
 =cut