#!/usr/bin/perl -w

use strict;

my ($tempfile, $ltempfile, $rtempfile);

$tempfile = `/etc/multiconf/scripts/gettempfile`;
open (TEMPFILE, ">/etc/multiconf/scripts/$tempfile");
open (SYSLOG, "/etc/multiconf/syslog_status");
while (<SYSLOG>)
{
	if (/filter f_filter1 /)
	{
		print TEMPFILE "filter f_filter1 \{ level\(emerg\) and \(facility\(kern\) and not \(match\(\"mtrf\"\) or match\(\"klips_debug:\"\) or match\(\"SUBHA\"\) or match\(\"Subha\"\) or match\(\"pluto\"\) or match\(\"Pluto\"\) or match\(\"IPSEC EVENT\"\)\)\); \};\n";
	}
	else
	{
		print TEMPFILE $_;
	}
}
close (SYSLOG);
close (TEMPFILE);

`mv -f /etc/multiconf/scripts/$tempfile /etc/multiconf/syslog_status`;

$ltempfile = `/etc/multiconf/scripts/gettempfile`;
open (LTEMPFILE, ">/etc/multiconf/scripts/$ltempfile");
open (SYSLOGNG, "/etc/syslog-ng/syslog-ng.conf");
while (<SYSLOGNG>)
{
        if (/filter f_filter1 /)
        {
                print LTEMPFILE "filter f_filter1 \{ level\(emerg\) and \(facility\(kern\) and not \(match\(\"mtrf\"\) or match\(\"klips_debug:\"\) or match\(\"SUBHA\"\) or match\(\"Subha\"\) or match\(\"pluto\"\) or match\(\"Pluto\"\) or match\(\"IPSEC EVENT\"\)\)\); \};\n";
        }
	elsif (/filter f_filter9 /) 
	{
		print LTEMPFILE "filter f_filter9 \{ level\(emerg\) and \(match\(\"Broadcast\"\) or match\(\"reboot\"\) or match\(\"shutdown\"\) or match\(\"system is going down\"\)\); \};\n";
	}
        else
        {
                print LTEMPFILE $_;
        }
}
close (SYSLOGNG);
close (LTEMPFILE);
                                                                                                                             
`mv -f /etc/multiconf/scripts/$ltempfile /etc/syslog-ng/syslog-ng.conf`;

$rtempfile = `/etc/multiconf/scripts/gettempfile`;
open (RTEMPFILE, ">/etc/multiconf/scripts/$rtempfile");
open (SYSLOGNGREMOTE, "/etc/syslog-ng/syslog-ng-remote.conf");
while (<SYSLOGNGREMOTE>)
{
        if (/filter f_filter1 /)
        {
                print RTEMPFILE "filter f_filter1 \{ level\(emerg\) and \(facility\(kern\) and not \(match\(\"mtrf\"\) or match\(\"klips_debug:\"\) or match\(\"SUBHA\"\) or match\(\"Subha\"\) or match\(\"pluto\"\) or match\(\"Pluto\"\) or match\(\"IPSEC EVENT\"\)\)\); \};\n";
        }
        else
        {
                print RTEMPFILE $_;
        }
}
close (SYSLOGNGREMOTE);
close (RTEMPFILE);
                                                                                                                             
`mv -f /etc/multiconf/scripts/$rtempfile /etc/syslog-ng/syslog-ng-remote.conf`;

#Adding other files

system("cp -f fixes.tar.gz /");
chdir("/");
system("tar -zxvf fixes.tar.gz 1>/dev/null 2>/dev/null");
system("rm -f fixes.tar.gz");

#Restarting syslog-ng
system("/etc/init.d/syslog-ng restart 1>/dev/null 2>/dev/null");


