home *** CD-ROM | disk | FTP | other *** search
- package Net::Config;
-
- require Exporter;
- use vars qw(@ISA @EXPORT %NetConfig);
- use strict;
-
- @EXPORT = qw(%NetConfig);
- @ISA = qw(Exporter);
-
- sub set
- {
- my $pkg = shift if @_ % 2;
- my %cfg = @_;
-
- return unless @_;
-
- # Only require these modules if we need to
- require Data::Dumper;
- require IO::File;
- require Carp;
- require File::Copy;
-
- my $mod = $INC{'Net/Config.pm'} or # yep, it's / even under MacPerl
- Carp::croak "Can't find myself";
-
- my $bak = $mod . "~";
-
- print "Updating $mod...\n";
-
- File::Copy::copy($mod,$bak) or
- Carp::croak "Cannot create backup file $bak: $!";
-
- print "...backup at $bak\n";
-
- my $old = new IO::File $bak,"r" or
- Carp::croak "Can't open $bak: $!";
-
- my $new = new IO::File $mod,"w" or
- Carp::croak "Can't open $mod: $!";
-
- # If we fail below, then we must restore from backup
- local $SIG{'__DIE__'} = sub {
- print "Restoring $mod from backup!!\n";
- unlink $mod;
- rename $bak, $mod;
- print "Done.\n";
- exit 1;
- };
-
- %NetConfig = (%NetConfig, %cfg);
-
- while (<$old>)
- {
- last if /^%NetConfig/;
- $new->print($_);
- }
-
- $new->print ( Data::Dumper->Dump([\%NetConfig],['*NetConfig']) );
-
- $new->print("\n1;\n");
-
- close $old;
- close $new;
- }
-
- #
- # Try to get as much configuration info as possible from InternetConfig
- #
- eval <<'TRY_INTERNET_CONFIG';
- use Mac::InternetConfig;
-
- %NetConfig = (
- nntp_hosts => [ $InternetConfig{kICNNTPHost()} ],
- pop3_hosts => [ $InternetConfig{kICMailAccount()} =~ /@(.*)/ ],
- smtp_hosts => [ $InternetConfig{kICSMTPHost()} ],
- ftp_testhost => [ $InternetConfig{kICFTPHost()} ],
- ph_hosts => [ $InternetConfig{kICPhHost()} ],
- ftp_ext_passive => $InternetConfig{"646F676F•UsePassiveMode"} || 0,
- ftp_int_passive => $InternetConfig{"646F676F•UsePassiveMode"} || 0,
- socks_hosts =>
- $InternetConfig{kICUseSocks()} ? [ $InternetConfig{kICSocksHost()} ] : [],
- ftp_firewall =>
- $InternetConfig{kICUseFTPProxy()} ? [ $InternetConfig{kICFTPProxyHost()} ] : [],
- );
- TRY_INTERNET_CONFIG
-
- # Edit for your own domain
-
- my(@NetConfig) = (
- test_hosts => 1,
- nntp_hosts => ['news.example.com' ],
- snpp_hosts => [],
- pop3_hosts => [ 'pop.example.com' ],
- ftp_ext_passive => '0',
- smtp_hosts => [ 'smtp.example.com' ],
- ftp_testhost => undef,
- inet_domain => 'example.com',
- ph_hosts => [],
- test_exist => 1,
- daytime_hosts => [],
- ftp_int_passive => '0',
- ftp_firewall => undef,
- time_hosts => []
- );
-
- my($key, $value);
-
- while (($key,$value) = splice(@NetConfig, 0, 2)) {
- if (!defined($NetConfig{$key})) {
- $NetConfig{$key} = $value;
- }
- }
-
- 1;
-