3 # Copyright (c) 2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
10 use vars qw(@ISA @EXPORT %NetConfig $VERSION $CONFIGURE $LIBNET_CFG);
11 use Socket qw(inet_aton inet_ntoa);
14 @EXPORT = qw(%NetConfig);
15 @ISA = qw(Net::LocalCfg Exporter);
16 $VERSION = "1.05"; # $Id: //depot/libnet/Net/Config.pm#9 $
18 eval { local $SIG{__DIE__}; require Net::LocalCfg };
29 ftp_firewall => undef,
38 $file =~ s/Config.pm/libnet.cfg/;
40 $ref = eval { do $file };
41 if (ref($ref) eq 'HASH') {
42 %NetConfig = (%NetConfig, %{ $ref });
46 if ($< == $> and !$CONFIGURE) {
47 my $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
49 $file = $home . "/.libnetrc";
50 $ref = eval { do $file } if -f $file;
51 %NetConfig = (%NetConfig, %{ $ref })
52 if ref($ref) eq 'HASH';
56 while(($k,$v) = each %NetConfig) {
58 if($k =~ /_hosts$/ && !ref($v));
61 # Take a hostname and determine if it is inside te firewall
63 sub requires_firewall {
64 shift; # ignore package
67 return 0 unless defined $NetConfig{'ftp_firewall'};
69 $host = inet_aton($host) or return -1;
70 $host = inet_ntoa($host);
72 if(exists $NetConfig{'local_netmask'}) {
73 my $quad = unpack("N",pack("C*",split(/\./,$host)));
74 my $list = $NetConfig{'local_netmask'};
75 $list = [$list] unless ref($list);
77 my($net,$bits) = (m#^(\d+\.\d+\.\d+\.\d+)/(\d+)$#) or next;
78 my $mask = ~0 << (32 - $bits);
79 my $addr = unpack("N",pack("C*",split(/\./,$net)));
81 return 0 if (($addr & $mask) == ($quad & $mask));
89 use vars qw(*is_external);
90 *is_external = \&requires_firewall;
98 Net::Config - Local configuration data for libnet
102 use Net::Config qw(%NetConfig);
106 C<Net::Config> holds configuration data for the modules in the libnet
107 distribuion. During installation you will be asked for these values.
109 The configuration data is held globally in a file in the perl installation
110 tree, but a user may override any of these values by providing their own. This
111 can be done by having a C<.libnetrc> file in their home directory. This file
112 should return a reference to a HASH containing the keys described below.
117 nntp_hosts => [ "my_prefered_host" ],
118 ph_hosts => [ "my_ph_server" ],
124 C<Net::Config> defines the following methods. They are methods as they are
125 invoked as class methods. This is because C<Net::Config> inherits from
126 C<Net::LocalCfg> so you can override these methods if you want.
130 =item requires_firewall HOST
132 Attempts to determine if a given host is outside your firewall. Possible
135 -1 Cannot lookup hostname
136 0 Host is inside firewall (or there is no ftp_firewall entry)
137 1 Host is outside the firewall
139 This is done by using hostname lookup and the C<local_netmask> entry in
140 the configuration data.
144 =head1 NetConfig VALUES
162 Each is a reference to an array of hostnames (in order of preference),
163 which should be used for the given protocol
167 Your internet domain name
171 If you have an FTP proxy firewall (B<NOT> a HTTP or SOCKS firewall)
172 then this value should be set to the firewall hostname. If your firewall
173 does not listen to port 21, then this value should be set to
174 C<"hostname:port"> (eg C<"hostname:99">)
176 =item ftp_firewall_type
178 There are many different ftp firewall products available. But unfortunately
179 there is no standard for how to traverse a firewall. The list below shows the
180 sequence of commands that Net::FTP will use
182 user Username for remote host
183 pass Password for remote host
184 fwuser Username for firewall
185 fwpass Password for firewall
186 remote.host The hostname of the remote ftp server
196 USER user@remote.host
203 USER user@remote.host
224 USER user@fwuser@remote.site
229 USER fwuser@remote.site
236 USER user@remote.host
243 =item ftp_ext_passive
247 FTP servers normally work on a non-passive mode. That is when you want to
248 transfer data you have to tell the server the address and port to
251 With some firewalls this does not work as the server cannot
252 connect to your machine (because you are behind a firewall) and the firewall
253 does not re-write the command. In this case you should set C<ftp_ext_passive>
256 Some servers are configured to only work in passive mode. If you have
257 one of these you can force C<Net::FTP> to always transfer in passive
258 mode; when not going via a firewall, by setting C<ftp_int_passive> to
263 A reference to a list of netmask strings in the form C<"134.99.4.0/24">.
264 These are used by the C<requires_firewall> function to determine if a given
265 host is inside or outside your firewall.
269 The following entries are used during installation & testing on the
276 If true then C<make test> may attempt to connect to hosts given in the
281 If true then C<Configure> will check each hostname given that it exists
287 I<$Id: //depot/libnet/Net/Config.pm#9 $>