#!/usr/bin/perl
# Copyright 2006 Ensim Corporation
# Author - atul
($sec,$min,$hr,$day,$month,$year)=localtime();
$mcfile = "/home/virtual/FILESYSTEMTEMPLATE/siteinfo/etc/mail/sendmail.mc" ;
$mcfile1 = $mcfile ."_$year$month$day$hr$min" ;
system("/bin/cp -f $mcfile $mcfile1") ;
open(MCFILE,$mcfile) ;
@lines = <MCFILE> ;
close(MCFILE);
@newlines ;
$curdir = `pwd` ;
chomp ($curdir) ;
foreach ( @lines ){
	if ( $_ =~ /confDEF_USER_ID/ ){
		push (@newlines,$_) ;
		push (@newlines,"define(`SMART_HOST', `[localhost]')dnl \n") ;
	}elsif($_ =~/SMART_HOST/){
		next;
	}else {
		push (@newlines,$_) ;
	}
}

open (MCFILE,">$mcfile") ;
print MCFILE @newlines ;
close (MCFILE);

@sites = `sitelookup -a site_handle` ;
foreach (sort @sites){
	chomp ($_) ;
	print "Processing $_ : " ;
	chdir ("/home/virtual/$_/fst/etc/mail") ;
	system("/bin/cp sendmail.cf sendmail.cf- ") ;
	system ("/usr/bin/m4 sendmail.mc > sendmail.cf") ;
	print "	Done! \n" ;
}
chdir ($curdir) ;
print "Restaring sendmail service \n" ;
system("/sbin/service sendmail restart") ;

