#!/usr/bin/perl # sync_active.pl -- downloads authoritative active file from ISC and brings # local active file into sync with it $active = "/var/typhoon/etc/active.text"; $control = "/var/typhoon/tools/sync_active/active.control"; $url = "http://open-systems.ufl.edu/mirrors/ftp.isc.org/pub/usenet/CONFIG/active.gz"; $work_dir = "/var/typhoon/tools/sync_active"; $reload_cmd = "/var/typhoon/bin/reload"; $log = "$work_dir/log"; my $current_hash, $add_hash; my $num_removals = 0; chdir $work_dir or die "couldn't change to working dir $work_dir!\n"; die "couldn't download $url!\n" if system "wget $url >/dev/null 2>&1"; die "couldn't gunzip active.gz!" if system "gunzip active.gz >/dev/null 2>&1"; open FILE, "<$active" or die "couldn't open $active!\n"; while () { @parts = split /\s/, $_; lc $parts[0]; $current_hash{$parts[0]} = 1; } close FILE or die "couldn't close $active!\n"; open FILE, "active" or die "couldn't open active!\n"; while () { @parts = split /\s/, $_; lc $parts[0]; if (exists $current_hash{$parts[0]}) { delete $current_hash{$parts[0]}; } else { $add_hash{$parts[0]} = 1; } } close FILE or die "couldn't close active!\n"; open FILE, ">>$control" or die "couldn't open $control!\n"; open LOG, ">>$log"; $date = `date`; print LOG $date; foreach (keys %current_hash) { print FILE "-$_\n"; print LOG "-$_\n"; $num_removals++; } foreach (keys %add_hash) { print FILE "+$_\n"; print LOG "+$_\n"; } close FILE or die "couldn't close $control!\n"; if ($num_removals >= 100) { print LOG "number of removals exceeds 100 -- assuming something ". "is broken\n\n"; close LOG; unlink $control; rename "$work_dir/active", "$work_dir/active.broken"; exit 1; } print LOG "\n\n"; close LOG; `$reload_cmd`; unlink "$work_dir/active" or die "couldn't unlink $work_dir/active!\n";