File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/iContact.pm
#!/usr/bin/perl
# iContact.pm Copyright(c) 1999-2004 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
package iContact;
BEGIN {
unshift @INC,'/usr/local/cpanel';
}
use Carp;
use Cpanel::OSSys () ;
use Cpanel::Hostname ();
use vars qw(@ISA @EXPORT $VERSION);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(icontact);
$VERSION = '1.0';
sub icontact {
my ( $ctype, $deflevel, $subject, $msg, $ftype ) = @_;
my (%SENDC);
my (%CONTACTS);
my (%CONTACTLVL);
my (%TLEVELS);
my $hostname = Cpanel::Hostname::gethostname();
$TLEVELS{$ctype} = $deflevel;
#CONTACTAIM XXX
#CONTACTEMAIL XXX@XXX.XXX
#CONTACTPAGER XXX@XXX.XXX
#CONTACTUIN XXX
open( WWWACCT, "/etc/wwwacct.conf" );
while (<WWWACCT>) {
chomp();
if (/^(CONTACT[E|P|U|A]+\S+)[\s\t]+(.*)/o) {
my ($contacttype) = $1;
my ($contact) = $2;
$contact =~ s/\n//g;
next if ( $contact eq "" );
$CONTACTS{$contacttype} = $contact;
$CONTACTLVL{$contacttype} = 1;
}
}
close(WWWACCT);
open( WWWACCT, "/etc/wwwacct.conf.shadow" );
while (<WWWACCT>) {
chomp();
if (/^(CONTACT[E|P|U|A]+\S+)[\s\t]+(.*)/o) {
my ($contacttype) = $1;
my ($contact) = $2;
$contact =~ s/\n//g;
next if ( $contact eq "" );
$CONTACTS{$contacttype} = $contact;
$CONTACTLVL{$contacttype} = 1;
}
}
close(WWWACCT);
$CONTACTLVL{'CONTACTEMAIL'} = 3;
$CONTACTLVL{'CONTACTPAGER'} = 1;
$CONTACTLVL{'CONTACTAIM'} = 2;
$CONTACTLVL{'CONTACTUIN'} = 2;
open( CLEVELS, "/var/cpanel/clevels.conf" );
while (<CLEVELS>) {
s/\n//g;
if (/^(CONTACT[E|P|U|A]+\S+) (.*)/) {
my ($contacttype) = $1;
my ($contact) = $2;
$contact =~ s/\n//g;
next if ( $contact eq "" );
$CONTACTLVL{$contacttype} = $contact;
}
}
close(CLEVELS);
open( CLEVELS, "/var/cpanel/iclevels.conf" );
while (<CLEVELS>) {
s/\n//g;
if (/^(\S+) (.*)/) {
my ($contacttype) = $1;
my ($contact) = $2;
$contact =~ s/\n//g;
next if ( $contact eq "" );
$TLEVELS{$contacttype} = $contact;
}
}
close(CLEVELS);
my $level = $TLEVELS{$ctype};
if ( $level eq "" ) { $level = 3; }
foreach my $contact ( sort keys %CONTACTS ) {
my $contactType = $contact;
$contactType =~ s/^CONTACT//g;
if ( int( $CONTACTLVL{$contact} ) >= int($level) ) {
print "Notification => $CONTACTS{$contact} via $contactType [level => $level]\n";
$SENDC{$contact} = 1;
# } else {
# print "skip $contact ($CONTACTLVL{$contact}) [$level]\n";
}
}
my $mail;
foreach my $contact ( sort keys %SENDC ) {
if ( $SENDC{$contact} == 1 && $CONTACTS{$contact} =~ /\@/ ) {
$mail .= "To: $CONTACTS{$contact}\n";
}
}
if ( $mail ne "" ) {
open( SENDMAIL, "|/usr/sbin/sendmail -t" );
print SENDMAIL $mail;
print SENDMAIL "From: cpanel\@${hostname}\n";
print SENDMAIL "Subject: ${subject}\n\n";
if ( $ftype eq "fd" ) {
while (<$msg>) {
print SENDMAIL;
}
}
else {
print SENDMAIL $msg;
}
close(SENDMAIL);
}
my $pid;
if ( $SENDC{'CONTACTAIM'} == 1 ) {
if ( !( $pid = fork() ) ) {
alarm(120);
cleanupfds();
open( STDIN, "<", "/dev/null" );
open( STDOUT, ">", "/dev/null" );
open( STDERR, ">", "/dev/null" );
Cpanel::OSSys::setsid();
system( "/scripts/sendaim", $msg );
exit;
}
}
if ( $SENDC{'CONTACTUIN'} == 1 && $ftype ne "fd" ) {
if ( !( $pid = fork() ) ) {
alarm(120);
cleanupfds();
open( STDIN, "<", "/dev/null" );
open( STDOUT, ">", "/dev/null" );
open( STDERR, ">", "/dev/null" );
Cpanel::OSSys::setsid();
system( "/scripts/sendicq", "$msg" );
exit;
}
}
waitpid( -1, 1 );
}
sub cleanupfds {
#we might want to close(S);
for ( my $n = 3; $n < 10; $n++ ) {
Cpanel::OSSys::close($n);
}
}