#!/usr/bin/perl # # MailScanner - SMTP E-Mail Virus Scanner # Copyright (C) 2002 Julian Field # # $Id: upgrade_MailScanner_conf,v 1.1.2.3 2003/02/15 13:44:04 jkf Exp $ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # The author, Julian Field, can be contacted by email at # Jules@JulianField.net # or by paper mail at # Julian Field # Dept of Electronics & Computer Science # University of Southampton # Southampton # SO17 1BJ # United Kingdom # # # This script will output the contents of a new MailScanner.conf file based # on an old MailScanner.conf file and a default copy of the new file. # It is designed for upgrading MailScanner.conf files from one release of # version 4 to another release of version 4. It will not help with the upgrade # from version 3 or earlier to version 4, you still have to do that by hand. # use FileHandle; use strict; sub Usage { print STDERR "Usage:\n"; print STDERR "upgrade_MailScanner_conf MailScanner.conf MailScanner.conf.rpmnew > MailScanner.conf.new\n"; Afterwards(); exit 1; } sub Afterwards { print STDERR "\nOnce you have checked that MailScanner.conf.new contains\n"; print STDERR "you want, you can then save your old one and move the new\n"; print STDERR "one into place, using commands like these:\n"; print STDERR " mv -f MailScanner.conf MailScanner.conf.old\n"; print STDERR " mv -f MailScanner.conf.new MailScanner.conf\n"; } my $oldfname = shift; my $newfname = shift; Usage() unless $oldfname && $newfname && -f $oldfname && -f $newfname; # Read in the old file to get all their current settings my $oldfh = new FileHandle; $oldfh->open($oldfname) or die "Cannot read old MailScanner.conf file $oldfname, $!"; my($key, $value, $origkey, $origline, %oldsettings, $ReadOldValue, %oldkeys); my(%oldcomments, $comments); $ReadOldValue = 0; $comments = ""; while(<$oldfh>) { chomp; $origline = $_; s/#.*$//; s/^\s+//; s/\s+$//; ($comments .= "$origline\n"),next if /^$/; undef $origkey; undef $key; undef $value; /^(.*?)\s*=/; # \s*(.*)$/; $origkey = $1; $origline =~ /=\s*(.*)$/; $value = $1; $key = lc($origkey); $key =~ s/[^a-z0-9]//g; # Leave numbers and letters only $oldsettings{$key} = $value; $oldkeys{$key} = $origkey; $oldcomments{$key} = $comments; $comments = ""; $ReadOldValue++; } $oldfh->close(); # Read in the new file to get all the default settings and new key names my $newfh = new FileHandle; $newfh->open($newfname) or die "Cannot read new default MailScanner.conf file $newfname, $!"; my($defaultvalue, $UsedOldValue, $UsedDefaultValue); $UsedOldValue = 0; $UsedDefaultValue = 0; $comments = ""; while(<$newfh>) { chomp; $origline = $_; s/#.*$//; s/^\s+//; s/\s+$//; ($comments .= "$origline\n"),next if /^$/; undef $origkey; undef $key; undef $defaultvalue; /^(.*?)\s*=/; # \s*(.*)$/; $origkey = $1; /=\s*(.*)$/; $defaultvalue = $1; $key = lc($origkey); $key =~ s/[^a-z0-9]//g; # Leave numbers and letters only if (exists $oldsettings{$key}) { # They previously had a setting for this parameter print $oldcomments{$key}; print "$origkey = $oldsettings{$key}\n"; delete $oldsettings{$key}; $comments = ""; $UsedOldValue++; } else { # they are using the new default value for this parameter print $comments; print "$origline\n"; print STDERR "Added new: $origline\n"; $comments = ""; $UsedDefaultValue++; } } $newfh->close(); while (($key, $value) = each %oldsettings) { print STDERR "Removed old: $oldkeys{$key} = $value\n"; } print STDERR < MailScanner.conf.new then you should do diff MailScanner.conf.rpmnew MailScanner.conf.new and check for any differences in values you have not changed yourself. EOL Afterwards(); exit 0;