HEX
Server: Apache
System: Linux server.y-p01.co.uk 3.10.0-1160.144.1.el7.tuxcare.els3.x86_64 #1 SMP Fri Mar 6 13:52:53 UTC 2026 x86_64
User: calderca (1008)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //bin/srvhsmon
#!/bin/bash
# Description: CPU Load, Free Memory, Free swap, disk partitions,RAID,IP Address RBL listing check ,rDNS,FDNS check monitoring script
# Copyright (c) 2013, Alex Parker
#Maintainer :: Alex Parker
CURRENTVERSION=0103201802
kernelversion()
{
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mKernel \t\t\t: \E[35;48m `uname -s -r -v`"
else
echo "Kernel#`uname -s -r -v`" >>  $REPORT
fi
}

controlpanel()
{
if [ -e "/usr/local/cpanel/version" ]; then
cp="cPanel"

if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mControlPanel \t\t: \E[35;48m cPanel/WHM `cat /usr/local/cpanel/version`"
else
echo "ControlPanel#cPanel/WHM `cat /usr/local/cpanel/version`" >> $REPORT
fi
elif [ -e "/usr/local/directadmin/directadmin" ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mControlPanel \t\t: \E[35;48m `cat /etc/redhat-release`"
else
echo "ControlPanel#`cat /etc/redhat-release`" >> $REPORT
fi
elif [ -e "/usr/local/psa/version" ]; then
cp="Plesk"
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mControlPanel \t\t: \E[35;48m Plesk `cat /usr/local/psa/version`"
else
echo "ControlPanel#Plesk `cat /usr/local/psa/version`" >> $REPORT
fi
fi
}


oscheck()
{
if [ -f /etc/redhat-release ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mOS \t\t\t: \E[35;48m `cat /etc/redhat-release`"
else
echo "OS#`cat /etc/redhat-release`" >> $REPORT
fi
elif [ -f /etc/debian_version ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mOS \t\t\t: \E[35;48m `cat /etc/debian_version`"
else
echo "OS#`cat /etc/debian_version`" >> $REPORT
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\t\t\032\E[33;48m\E[33;48mOS \t\t\t: \E[31;48m  OS NOT Detected."
else
echo "OS#OS NOT Detected." >> $REPORT
fi
fi

## virttype
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mhypervisor \t\t: \E[35;48m $virtype"
else
echo ""
#echo "OS#`cat /etc/redhat-release`" >> $REPORT
fi

}

mailqueue()
{
if [ -z "$maxmailq" ]; then
maxmailq=500
fi
if [ "$cp" = cPanel ]; then
mailq=`/usr/sbin/exim -bpc`
elif [ "$cp" = Plesk ]; then
mailq=`/usr/bin/mailq |tail -n 1 |awk {'print $5'}`
else
mailq=""
fi
if [ ! -z "$mailq" ];then
if [ $mailq -ge $maxmailq ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mMail Queue \t\t: \E[31;48m [CRITICAL]  [$mailq] "
else
echo "Mail Queue#[CRITICAL]   $mailq#RED" >> $REPORT
fi
dorun="NO";
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mMail Queue \t\t: \E[32;48m [NORMAL]  [$mailq]"
else
echo "Mail Queue#[NORMAL]   $mailq#GREEN" >> $REPORT
fi
fi
fi
}
# Load Check
cpucheck()
{
if [ `uname` = Linux ]; then
cpu_load=`/usr/bin/uptime | awk -F'load average:' '{ print $2}' | sed 's/\./ /g' | awk '{print $1}'`
else
echo "OS version is different! Exit"
fi
if [ $cpu_load -ge $maxload ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mServer Load \t\t: \E[31;48m [CRITICAL]   `uptime | awk '{ print $10 $11 $12 }'` "
else
echo "Server Load#[CRITICAL]   `uptime | awk '{ print $10 $11 $12 }'`#RED" >> $REPORT
fi
dorun="NO";
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mServer Load \t\t: \E[32;48m [NORMAL]   `uptime | awk '{ print $10 $11 $12 }'`"
else
echo "Server Load#[NORMAL]   `uptime | awk '{ print $10 $11 $12 }'`#GREEN" >> $REPORT
fi
fi
}

# Memory Check
memorycheck()
{
if [ `uname` = Linux ]; then
#memory=`/usr/bin/free -m | grep Mem | awk '{print $3/$2 * 100.0}' | cut -d\. -f1`
memory=`/usr/bin/free | awk 'FNR == 3 {print $3/($3+$4)*100}' | cut -d\. -f1`
else
echo "OS version is different! Exit"
exit
fi

if [ $memory -ge $maxmemory ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mMemory \t\t\t: \E[31;48m [CRITICAL] Memory usage of $memory% detected."
else
echo "Memory#[CRITICAL] Memory usage of $memory% detected.#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mMemory \t\t\t: \E[32;48m [NORMAL]   Memory usage of $memory% detected."
else
echo "Memory#[NORMAL]   Memory usage of $memory% detected.#GREEN" >> $REPORT
fi
fi
}

# Swap Check
swapcheck()
{
if [ `uname` = Linux ]; then
swap=`/usr/bin/free -m | grep Swap | awk '{print $3/$2 * 100.0}' | cut -d\. -f1`
else
echo "OS version is different! Exit"
exit
fi

if [ $swap -ge $maxswap ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48m SWAP \t\t\t: \E[31;48m [CRITICAL] Swap usage of $swap% detected."
else
echo "SWAP#[CRITICAL] Swap usage of $swap% detected.#RED" >> $REPORT
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mSWAP \t\t\t: \E[32;48m [NORMAL]   Swap usage of $swap% detected."
else
echo "SWAP#[NORMAL]   Swap usage of $swap% detected.#GREEN" >> $REPORT
fi
fi
}

# Current loggin users
loginuser()
{
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mCurrent Loggin Users \t: \E[35;48m `/usr/bin/users`  "
else
echo "Current Loggin Users#`/usr/bin/users`" >> $REPORT
fi
}
# Partitions check


# HDD/Storage Check
storagecheck()
{
df -P -H -l -P | grep -vE '^Filesystem|tmpfs|cdrom|cgroup' | awk '{ print $5 " " $1 " " $6 }' > $TEMDIR/dfoutput;
while read output ; do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
partition=$(echo $output | awk '{ print $2 }' )
label=$(echo $output | awk '{ print $3 }' )

if [ $usep  -ge $maxstorage ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mPartition Size \t\t: \E[31;48m [CRITICAL] Running out of space \"$partition [$label] ($usep%)\"."
else
echo "Partition Size#[CRITICAL] Running out of space \"$partition [$label] ($usep%)\".#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
else
psize=$(($psize +1 ))
fi
counter=$(( $counter+1 ))
done < $TEMDIR/dfoutput
if [ $psize -eq $counter ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mPartition Size \t\t: \E[32;48m [NORMAL]  "
else
echo "Partition Size#[NORMAL]#GREEN" >> $REPORT
fi
fi
if [ `egrep " ro,|,ro " /proc/mounts|grep -Ev 'virtfs|cagefs-skeleton|cgroup'|wc -l` -gt 0 ];then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mPartition Mount \t\t: \E[31;48m [CRITICAL] `egrep " ro,|,ro " /proc/mounts |grep -Ev 'virtfs|cagefs-skeleton|cgroup' |awk {'print $1 " "  $ 2'}` is mounted READ-ONLY."
else
echo "Partition Mount#[CRITICAL] `egrep " ro,|,ro " /proc/mounts |grep -Ev 'virtfs|cagefs-skeleton|cgroup' |awk {'print $1 " "  $ 2'}` is mounted READ-ONLY.#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
fi
}

# HDD iNODE usages
inodecheck()
{
df -P -H -l -i | grep -vE '^Filesystem|tmpfs|cdrom|cgroup|efi' | awk '{ print $5 " " $1 " " $6 }' > $TEMDIR/dfinodeoutput;
while read output ; do
usei=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
ipartition=$(echo $output | awk '{ print $2 }' )
ilabel=$(echo $output | awk '{ print $3 }' )

if [ $usei  -ge $maxstorage ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mInode Limit \t\t: \E[31;48m [CRITICAL] Running out of inodes \"$ipartition [$ilabel] ($usei%)\"."
else
echo "Inode Limit#[CRITICAL] Running out of inodes \"$partition [$ilabel] ($usei%)\".#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
else
psize=$(($psize +1 ))
fi
counter=$(( $counter+1 ))
done < $TEMDIR/dfinodeoutput
#if [ $psize -eq $counter ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mInode Limit \t\t: \E[32;48m [NORMAL]  "
else
echo "Inode Limit#[NORMAL]#GREEN" >> $REPORT
#fi
fi
}

hdd_heath_check()
{
TEMPRAIDSTATUS="/root/raidstatus"
TMPLOG="$TEMDIR/raidstatus"

## check RAID Controller
if [ `lspci |grep  'RAID\|SCSI' |wc -l` -gt 0 ] && [ $RAIDMON == YES ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRAID Controller \t: \E[32;48m YES  "
else
echo "RAID Controller#YES#GREEN" >> $REPORT
fi
raidstatus=YES;
else
raidstatus=NO;
dtype=ata

disk_drives=$(cat /proc/partitions|grep "[[:digit:]]"|grep -o "[[:lower:]]\{3,4\}\$")
for drive in $disk_drives
do
smardcheck $drive $dtype
done
fi
if [ $RAIDMON == YES ] ; then
if [ $raidstatus = YES ] ; then
if [ -f $TMPLOG ] && [ ! -z `find "$TMPLOG" -mmin -$file_life` ]  ;then
row=0;
while read i; do
[ -z "$i" ] && continue
rstatus[$row,0]="`echo $i  | sed '/^$/d'|cut -d# -f1`"
rstatus[$row,1]="`echo $i  | sed '/^$/d'|cut -d# -f2`"
rstatus[$row,2]="`echo $i  | sed '/^$/d'|cut -d# -f3`"
dtype=`echo $i  | sed '/^$/d'|cut -d# -f4`
row=$(( $row + 1 ))
done < $TMPLOG
else
if [[ `/sbin/lspci |grep -E 'MegaSAS|MegaRAID'` =~ "Mega" ]] ; then
if [ `command -v megacli` ];then
rstatus=`megacli -ldinfo -L0 -aall |grep State |awk '{print $2}'`
megacli -ldinfo -L0 -aall  > $TEMDIR/raidheath
row=0;
rstatus[$row,0]="`cat  $TEMDIR/raidheath |grep 'Virtual Disk' | awk '{print $3}'`"
rstatus[$row,1]="`cat $TEMDIR/raidheath |grep 'RAID Level' |cut -d : -f2`"
rstatus[$row,2]="`cat $TEMDIR/raidheath |grep State |awk '{print $3}'`"
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
rm -f  $TEMDIR/raidheath
#smartdchek
for hdid in `megacli -pdlist -a0| grep 'Device Id' |cut -d: -f2 |tr -d " "`; do
dtype="sat+megaraid,$hdid"
smardcheck sda $dtype
done
#
elif [ `command -v megasasctl` ];then
megasasctl | awk '/ RAID / {print $1 " "  $3$4 " "  $6}' > $TEMDIR/raidheath
row=0;
while read i; do
[ -z "$i" ] && continue
rstatus[$row,0]="`echo $i |awk {'print $1'}`"
rstatus[$row,1]="`echo $i |awk {'print $2'}`"
rstatus[$row,2]="`echo $i |awk {'print $3'}`"
if [ $row -eq 0 ] ; then
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
else
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" >> $TMPLOG
fi
row=$(( $row + 1 ))
done < $TEMDIR/raidheath
rm -f  $TEMDIR/raidheath
#smartdchek
for hdid in `megacli -pdlist -a0| grep 'Device Id' |cut -d: -f2 |tr -d " "`; do
dtype="megaraid,$hdid"
smardcheck sda $dtype
done
#
else
RAIDMON=NO
fi
elif  [[ `/sbin/lspci |grep -E 'SAS1068E|SAS1064ET'` =~ "SAS106" ]] ;
then
dtype="";
if [ `command -v mpt-status` ];then
id=`mpt-status -p |grep "vol_id\|id=" |cut -d, -f 1|awk {'print $3'}|cut -d= -f 2`;
rstatus=`mpt-status -i $id -s |grep vol_id| awk '{print $3}'`
mpt-status -i $id  |grep vol_id > $TEMDIR/raidheath
row=0;
while read i; do
[ -z "$i" ] && continue
rstatus[$row,0]="`echo $i  |awk {'print $2  $3'}`"
rstatus[$row,1]="`echo $i |awk {'print $4 ":"$5'}| tr -d ','`"
rstatus[$row,2]="`echo $i | awk {'print $11'} | tr -d ','`"
if [ $row -eq 0 ] ; then
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype#2" > $TMPLOG
else
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype#2" >> $TMPLOG
fi
row=$(( $row + 1 ))
done < $TEMDIR/raidheath
rm -f  $TEMDIR/raidheath
#smartd check
modprobe sg
smardcheck sg0
smardcheck sg1
else
RAIDMON=NO
fi
elif  [[ `/sbin/lspci |grep -E '3ware'` =~ "3ware" ]] ;
then
dtype="";
if [ `command -v tw_cli` ];then
# Find the controller ID
 CONTROLLER_ID=`tw_cli info | awk 'NR==4' | awk '{print $1}'`
# # Find the RAID unit ID
 UNIT_ID=`tw_cli info $CONTROLLER_ID | awk 'NR==4' | awk '{print $1}'`
#
rstatus=`tw_cli info $CONTROLLER_ID $UNIT_ID status | awk '{print $4}'|tr -d '\n'`
tw_cli /$CONTROLLER_ID/$UNIT_ID show |grep RAID  > $TEMDIR/raidheath
row=0;
while read i; do
[ -z "$i" ] && continue
rstatus[$row,0]="`echo $i  |awk {'print $2'}`"
rstatus[$row,1]="`echo $i |awk {'print $8'}`"
rstatus[$row,2]="`echo $i |awk {'print $3'}`"
if [ $row -eq 0 ] ; then
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
else
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" >> $TMPLOG
fi
row=$(( $row + 1 ))
done < $TEMDIR/raidheath
rm -f  $TEMDIR/raidheath
smardcheck twa0 "3ware,0"
smardcheck twa0 "3ware,1"
else
RAIDMON=NO
fi
elif [[ `/sbin/lspci |grep -E 'SAS2008|SAS2308|SAS3008' |wc -l` -gt 0  ]] ;
then
dtype="megaraid,0";
if [ `command -v sas2ircu` ];then
/usr/sbin/sas2ircu 0 DISPLAY > $TEMDIR/raidheath
row=0;
acount=0
for i in `cat $TEMDIR/raidheath|grep -E 'IR volume'|awk {'print $3'}` ; do
if [ -z $i ]; then
rstatus[$row,0]="NO"
else
rstatus[$row,0]="$i"
fi
row=$(( $row + 1 ))
acount=$(( $row + 1 ))
done
row=0;
for i in `cat $TEMDIR/raidheath|grep RAID1 |awk {'print $4'}` ; do
if [ -z $i ]; then
rstatus[$row,1]="NO"
else
rstatus[$row,1]="$i"
fi
row=$(( $row + 1 ))
done
row=0;
for i in `cat $TEMDIR/raidheath|grep 'Status of volume'  |awk {'print $5'}` ; do
if [ $i=="Okay" ] ; then
i="Optimal"
fi
if [ -z $i ]; then
rstatus[$row,2]="NO"
else
rstatus[$row,2]="$i"
fi
row=$(( $row + 1 ))
done
for (( row=0; row < ($acount -1 ); row++ )) ; do
if [ $row -eq 0 ] ; then
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
else
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" >> $TMPLOG
fi
done
rm -f  $TEMDIR/raidheath
#smartcheck
modprobe sg
smardcheck sg1
smardcheck sg2
#
else
RAIDMON=NO
fi
elif [[ `/sbin/lspci | grep RAID |grep -E 'Hewlett-Packard Company Smart Array|Series/C200|Series/C220'|wc -l` -gt 0 ]] ;
then
if [ `command -v hpacucli` ];then
slotid=`hpacucli controller all  show config detail |grep Slot: |cut -d: -f2|tr -d ' '|head -1`
hpacucli controller slot=$slotid  logicaldrive all show status  > $TEMDIR/raidheath
row=0;
while read i; do
[ -z "$i" ] && continue
rstatus[$row,0]="`echo $i |awk {'print $1 $2'}`"
rstatus[$row,1]="`echo $i |awk {'print $5'} |cut -d')' -f1`"
rstatus[$row,2]="`echo $i |cut -d':' -f2`"
if [ $row -eq 0 ] ; then
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
else
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" >> $TMPLOG
fi
row=$(( $row + 1 ))
done < $TEMDIR/raidheath
rm -f  $TEMDIR/raidheath
#Smart health check
slotid=`hpacucli controller all  show config detail |grep Slot: |cut -d: -f2|tr -d ' '|head -1`
phydrive=`hpacucli ctrl slot=$slotid pd all show status  |grep physicaldrive |wc -l`
for (( row=0; row < ($phydrive); row++ )) ; do
dtype="cciss,$row"
smardcheck sda $dtype
done


else
RAIDMON=NO
fi
elif  [[ `/sbin/lspci |grep -E 'AAC-RAID|AAC-RAID|Adaptec Series 6'` =~ "Adaptec" ]] ;
then
dtype="sat -s on";
if [ -f '/usr/StorMan/arcconf' ];then
/usr/StorMan/arcconf GETCONFIG 1 > $TEMDIR/raidheath
row=0;
acount=0
for i in `cat $TEMDIR/raidheath|grep -E 'Logical device name' |awk '{print $5}'` ; do
rstatus[$row,0]="$i"
row=$(( $row + 1 ))
acount=$(( $row + 1 ))
done
row=0;
for i in `cat $TEMDIR/raidheath|grep -E 'RAID level' |awk '{print $4}'` ; do
rstatus[$row,1]="RAID$i"
row=$(( $row + 1 ))
done
row=0;
for i in `cat $TEMDIR/raidheath|grep -E 'Status of logical device' |awk '{print $6}'` ; do
rstatus[$row,2]="$i"
row=$(( $row + 1 ))
done
for (( row=0; row < ($acount -1 ); row++ )) ; do
if [ $row -eq 0 ] ; then
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
else
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" >> $TMPLOG
fi
done
rm -f  $TEMDIR/raidheath
#SMARTD status
smardcheck sg1 $dtype
smardcheck sg2 $dtype
else
RAIDMON=NO
fi

### software RAID
elif  [ `/bin/grep ^md -c /proc/mdstat` -gt 0 ] ;
then
dtype="areca,0";
if [ -f '/proc/mdstat' ];then
row=0;
acount=0
rstatus[$row,0]="MD"
rstatus[$row,1]=`cat  /proc/mdstat|grep -w "active" | awk '{print $4}'`
if [ `egrep "\[.*(=|>|\.).*\]" /proc/mdstat -c` -eq 0  ]; then
rstatus[$row,2]="Optimal"
else
rstatus[$row,2]="Degraded"
fi
echo "${rstatus[$row,0]}#${rstatus[$row,1]}#${rstatus[$row,2]}#$dtype" > $TMPLOG
fi

else
echo "RAID Controller on `hostname` server is not match"
RAIDMON=NO
fi
fi #end
fi

if [ $raidstatus = YES ] ; then
if [[ ! -z ${#rstatus[@]} ]]  ;then
Rows=`cat $TEMDIR/raidstatus | sed '/^$/d'|wc -l`
Columns=3
row=0
while [ "$row" -lt "$Rows" ]
do
if [ ${rstatus[$row,2]} = Optimal ]  || [ ${rstatus[$row,2]} = OPTIMAL ] || [ ${rstatus[$row,2]} = OK ] || [ ${rstatus[$row,2]} = optimal ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRAID Status  \t\t: \E[32;48m VG$row ${rstatus[$row,0]}  ${rstatus[$row,1]}  ${rstatus[$row,2]}    "
else
echo "RAID Status#VG$row ${rstatus[$row,0]}  ${rstatus[$row,1]}  ${rstatus[$row,2]}#GREEN" >> $REPORT
fi
elif  [ ${rstatus[$row,0]} = NO ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRAID Status  \t\t: \E[36;48m NO RAID Configured    "
else
echo "RAID Status#NO RAID Configured#ORANGE" >> $REPORT
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRAID Status \t\t: \E[31;48m [CRITICAL]  RAIDMON NOT INSTALLED"
else
echo "RAID Status#[CRITICAL]  RAIDMON NOT INSTALLED#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRAID Status \t\t: \E[31;48m [CRITICAL]  Degraded More details check $TEMPRAIDSTATUS "
else
echo "RAID Status#[CRITICAL]  Degraded More details check $TEMPRAIDSTATUS#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
fi
let "row += 1"
done
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRAID Status \t\t: \E[31;48m [CRITICAL] RAIDMON NOT INSTALLED "
else
echo "RAID Status#[CRITICAL] RAIDMON NOT INSTALLED#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
fi
fi
fi
}

# Write Speed
hddwrite()
{
if [ $HDPARMMON == YES ] ; then
dev="/dev/"
GetInfo()
{
  wspeed=`dd if=/dev/zero of=/root/dd_test bs=1MB count=64 conv=fdatasync  2>&1 |grep bytes |  awk '{print $8}' |cut -d. -f1`
  rm -f /root/tstfile
  if [ ! -z $wspeed ] ;then

  echo "$wspeed  $1$2" >> $TEMDIR/hddwrite
  if [ $wspeed -lt $maxhdparm ] ;then
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[31;48m [CRITICAL]  $1$2 Timing buffered disk reads is LOW $wspeed  MB/sec."
  else
  echo "HDD Write Speed#[CRITICAL]  $1$2 Timing buffered disk reads is LOW $wspeed  MB/sec.#RED" >> $REPORT
  herror=$(( $herror + 1 ))
  fi
  elif [ $wspeed -lt $warn_hdparm ]  &&  [ $wspeed -gt $warn_hdparm ] ;then
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[31;48m [WARNING]  $1$2 Timing buffered disk reads is LOW $wspeed  MB/sec."

  else
  echo "HDD Write Speed#[WARNING]  $1$2 Timing buffered disk reads is LOW $wspeed  MB/sec.#ORANGE" >> $REPORT
  herror=$(( $herror + 1 ))
  fi
  else
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[32;48m [NORMAL]   $1$2 ($wspeed) MB/sec  "
  else
  echo "HDD Write Speed#[NORMAL]   $1$2 ($wspeed) MB/sec#GREEN" >> $REPORT
  fi
  fi
  fi
}
if [ ! -f '/bin/dd' ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[31;48m [CRITICAL]  dd command not Found.."
else
echo "HDD Write Speed#[CRITICAL]  dd command not Found.#RED" >> $REPORT
fi
else
if [ -f  "$TEMDIR/hddwrite" ]  ;then
if test `find "$TEMDIR/hddwrite" -mmin -$file_life` ;then
while read output ; do
[ -z "$output" ] && continue
wspeed=$(echo $output | awk '{ print $1}' | cut -d. -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ ! -z $wspeed ] ;then
if [ $wspeed -lt $maxhdparm ] ;then
if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[31;48m [CRITICAL]  $partition Timing buffered disk reads is LOW $wspeed  MB/sec."
  else
  echo "HDD Write Speed#[CRITICAL]  $partition Timing buffered disk reads is LOW $wspeed  MB/sec.#RED" >> $REPORT
  herror=$(( $herror + 1 ))
  fi
  elif [ $wspeed -lt $warn_hdparm ]  &&  [ $wspeed -gt $warn_hdparm ] ;then
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[31;48m [WARNING]  $partition Timing buffered disk reads is LOW $wspeed  MB/sec."
  else
  echo "HDD Write Speed#[WARNING]  $partition Timing buffered disk reads is LOW $wspeed  MB/sec.#ORANGE" >> $REPORT
  fi
  else
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Write Speed \t: \E[32;48m [NORMAL]   $partition ($wspeed) MB/sec  "
  else
echo "HDD Write Speed#[NORMAL]   $partition ($wspeed) MB/sec#GREEN" >> $REPORT
fi
  fi
fi
done < "$TEMDIR/hddwrite"
else
echo > $TEMDIR/hddwrite
disk_drives=$(cat /proc/partitions|grep "[[:digit:]]"|grep -o "[[:lower:]]\{3,4\}\$")
for drive in $disk_drives
do
  GetInfo $dev $drive
 done
fi
else
echo > $TEMDIR/hddwrite
disk_drives=$(cat /proc/partitions|grep "[[:digit:]]"|grep -o "[[:lower:]]\{3,4\}\$")
for drive in $disk_drives
do
  GetInfo $dev $drive
 done
fi
fi
fi
}


hdparm()
{
if [ $HDPARMMON == YES ]; then
dev="/dev/"
GetInfo()
{
  speed=`/sbin/hdparm -t "$1$2" | grep Timing | awk {'print $11'} |cut -d. -f1 | cut -d. -f1`
  if [ ! -z $speed ] ;then

  echo "$speed  $1$2" >> $TEMDIR/hdparmout
  if [ $speed -lt $maxhdparm ] ;then
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Read Speed \t\t: \E[31;48m [CRITICAL]  $1$2 Timing buffered disk reads is LOW $speed  MB/sec."
  else
  echo "HDD Read Speed#[CRITICAL]  $1$2 Timing buffered disk reads is LOW $speed  MB/sec.#RED" >> $REPORT
  herror=$(( $herror + 1 ))
  fi
  elif [ $speed -lt $warn_hdparm ]  &&  [ $speed -gt $warn_hdparm ] ;then
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Read Speed \t\t: \E[31;48m [WARNING]  $1$2 Timing buffered disk reads is LOW $speed  MB/sec."
  else
  echo "HDD Read Speed#[WARNING]  $1$2 Timing buffered disk reads is LOW $speed  MB/sec.#ORANGE" >> $REPORT
  herror=$(( $herror + 1 ))
  fi
  else
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Read Speed \t\t: \E[32;48m [NORMAL]   $1$2 ($speed) MB/sec  "
  else
  echo "HDD Read Speed#[NORMAL]   $1$2 ($speed) MB/sec#GREEN" >> $REPORT
  fi
  fi
  fi
}
if [ ! -f '/sbin/hdparm' ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDPARM \t\t\t: \E[31;48m [CRITICAL]  hdparm command not Found.."
yum install hdparm -y -q
else
echo "HDD Read Speed#[CRITICAL]  hdparm command not Found.#RED" >> $REPORT
fi
else
if [ -f  "$TEMDIR/hdparmout" ]  ;then
if test `find "$TEMDIR/hdparmout" -mmin -$file_life` ;then
while read output ; do
speed=$(echo $output | awk '{ print $1}' | cut -d. -f1 )

partition=$(echo $output | awk '{ print $2 }' )
if [ ! -z $speed ] ;then
if [ $speed -lt $maxhdparm ] ;then
if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Read Speed \t\t: \E[31;48m [CRITICAL]  $partition Timing buffered disk reads is LOW $speed  MB/sec."
  else
  echo "HDD Read Speed#[CRITICAL]  $partition Timing buffered disk reads is LOW $speed  MB/sec.#RED" >> $REPORT
  herror=$(( $herror + 1 ))
  fi
  elif [ $speed -lt $warn_hdparm ]  &&  [ $speed -gt $warn_hdparm ] ;then
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Read Speed \t\t: \E[31;48m [WARNING]  $partition Timing buffered disk reads is LOW $speed  MB/sec."
  else
  echo "HDD Read Speed#[WARNING]  $partition Timing buffered disk reads is LOW $speed  MB/sec.#ORANGE" >> $REPORT
  fi
  else
  if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Read Speed \t\t: \E[32;48m [NORMAL]   $partition ($speed) MB/sec  "
  else
echo "HDD Read Speed#[NORMAL]   $partition ($speed) MB/sec#GREEN" >> $REPORT
fi
  fi
fi
done < "$TEMDIR/hdparmout"
else
echo > $TEMDIR/hdparmout
disk_drives=$(cat /proc/partitions|grep "[[:digit:]]"|grep -o "[[:lower:]]\{3,4\}\$")
for drive in $disk_drives
do
  GetInfo $dev $drive
 done
fi
else
echo > $TEMDIR/hdparmout
disk_drives=$(cat /proc/partitions|grep "[[:digit:]]"|grep -o "[[:lower:]]\{3,4\}\$")
for drive in $disk_drives
do
  GetInfo $dev $drive
 done
fi
fi
fi
}

## check hardware firewall status
hwfwstatus()
{
ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
if [ `echo  $ip | grep -E "(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)"` ]; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48;41m\E[1;33;48mHardware Firewall\t: \E[1;35;48m YES  \033[0m"
else
echo "Hardware Firewall#YES" >> $REPORT
fi
fi
}


csfstatus()
{
if  [ -f '/usr/sbin/csf' ] ; then
if [ -e '/etc/csf/csf.disable' ]; then
fstatus="Disabled"   ;
colid="31"
colname="RED";
else
fstatus="Enabled";
colid="32"
colname="GREEN";
fi
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mFirewall [CSF] \t\t: \E[$colid;48m [$fstatus]"
else
echo "Firewall [CSF]#[$fstatus#$colname]" >> $REPORT
fi
else
IPTABLES=iptables
VAR_SUBSYS_IPTABLES=/var/lock/subsys/$IPTABLES
IPV=${IPTABLES%tables} # ip for ipv4 | ip6 for ipv6
[ "$IPV" = "ip" ] && _IPV="ipv4" || _IPV="ipv6"
PROC_IPTABLES_NAMES=/proc/net/${IPV}_tables_names
NF_TABLES=$(cat "$PROC_IPTABLES_NAMES" 2>/dev/null)
if [ ! -f "$VAR_SUBSYS_IPTABLES" -a -z "$NF_TABLES" ]; then
fstatus="Disabled"   ;
colid="31"
colname="RED";

else
fstatus="Enabled";
colid="32"
colname="GREEN";

fi
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48m Firewall [IPTABLES] \t: \E[$colid;48m [$fstatus]"
else
echo "Firewall [IPTABLES]#[$fstatus]#$colname" >> $REPORT
fi

fi
}

 smardcheck()
{

if [ ! -f '/usr/bin/bc' ] ;then
yum -q install bc -y;
fi

dev="/dev/"
drive=$1
dtype=$2
GetInfo()
{
if [ ! -z $dtype ] ; then
smartcmd="smartctl  -d $dtype"
diskid=`echo $dtype|cut -d"," -f2`
diskname=$drive-$diskid
else
smartcmd="smartctl"
diskname=$drive
fi

if [ "`$smartcmd  -i $1$2 |grep 'Device does not support SMART'`" ] ;then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mSMARTD HDD Status \t: \E[36;48m [INFO]   $diskname Device does not support SMART ."
else
echo "SMARTD HDD Status#[INFO]   $diskname Device does not support SMART#black" >> $REPORT
fi
else
SMARTMESSAGE1="$TEMDIR/smartmessage-$diskname"
MAILMESSAGE="$TEMDIR/mailmessage-$diskname"

$smartcmd -a $1$2 > $SMARTMESSAGE1
cat $SMARTMESSAGE1 > $MAILMESSAGE

## HDD AGE check
if [ `cat $SMARTMESSAGE1 | grep Power_On_Hours |wc -l` -gt 0 ]; then
hddage=`cat $SMARTMESSAGE1 | grep Power_On_Hours | /bin/awk '{print $10}'`
else
hddage=`cat $SMARTMESSAGE1 | grep "number of hours powered up" | /bin/awk '{print $7}'`
fi
if [ ! -z $hddage ] ; then
#let hddage=($hddage)/24
hddage=$(echo "$hddage"/24 | bc)
if (( $hddage > 365 )); then
hddage=$(echo "scale=2; $hddage"/365 | bc)
hddage="$hddage Year"
else
hddage="$hddage Days"
fi
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD AGE [$diskname]  \t: \E[32;48m [ $hddage ] "
else
echo "HDD AGE [$diskname]#[$hddage]#GREEN" >> $REPORT
fi
fi
## disk load

hddload=`cat $SMARTMESSAGE1 | grep "Load_Cycle_Count" | /bin/awk '{print $10}'`
if [ ! -z $hddload ] ; then
lcc=$hddload
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD LOAD [$diskname]  \t: \E[32;48m [ $hddload ] "
else
echo "HDD LOAD [$diskname]#[$hddload]#GREEN" >> $REPORT
fi
fi
smardarry=("Reallocated_Sector_Ct"  'Spin_Retry_Count' 'Calibration_Retry_Count' 'Reallocated_Event_Count' 'Current_Pending_Sector' 'Offline_Uncorrectable');
for err in "${smardarry[@]}"
do
errormesg="";
hcheck=`cat $SMARTMESSAGE1 | grep $err | /bin/awk '{print $10}'`
if [ "$hcheck" ]; then
if [ "$err" == "Reallocated_Sector_Ct" ] && [ "$hcheck" -gt 500 ] ; then
errormesg="[$err : $hcheck]";
elif [ "$err" != "Reallocated_Sector_Ct" ] && [ "$hcheck" -gt 0 ] ;then
errormesg="[$err : $hcheck]";
else
nomg=1;
fi
fi
done
if [ "$errormesg" ] ; then
if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Health [$diskname] \t: \E[31;48m [CRITICAL] $diskname HDD is FAILED errocode:$errormesg more details check $SMARTMESSAGE1 ."
  else
echo "Health HDD [$1$2]#[CRITICAL] $diskname HDD is FAILED more details check $SMARTMESSAGE1 .#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mHDD Health [$diskname] \t: \E[32;48m [NORMAL] "
else
echo "HDD Health [$diskname]#NORMAL]#GREEN" >> $REPORT
fi
fi
fi

}

if [ ! -f '/usr/sbin/smartctl' ]; then
echo -e "\t\t\t\t\t\032\E[33;48mSMART Status \t\t: \E[31;48m [CRITICAL]          smartd not installed."
yum install smartd smartmontools -q -y
elif [  `pidof -c -o 2347 -o 26531 -o %PPID -x smartd` ] ; then
GetInfo $dev $drive
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48mSMART Status \t\t: \E[31;48m [CRITICAL]   smartd service not running."
/etc/init.d/smartd restart > /dev/null 2>&1
else
echo "SMART Status#[CRITICAL]   smartd service not running.#RED" >> $REPORT
/etc/init.d/smartd restart > /dev/null 2>&1
fi
fi

}

## File system error check
filesystemcheck()
{
errcount=0
messagelog=/var/log/messages
tempmsglog=$TEMDIR/filesystemerror
if [ -f  "$TEMDIR/filesystemerror" ]  ;then
if test `find "$TEMDIR/filesystemerror" -mmin -$file_life` ;then
errcount=`cat $tempmsglog|wc -l`;
fi
else
cat $messagelog |grep -i 'Currently unreadable (pending) sectors\|Buffer I/O error on device\|error: ext3_journal_start_sb' > $tempmsglog
errcount=`cat $tempmsglog|wc -l`;
fi
if [ $errcount -gt 0 ];then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mFileSystem Status \t: \E[31;48m [CRITICAL] FileSystem Error Found more details check $tempmsglog ."
else
echo "FileSystem Status#[CRITICAL] FileSystem Error Found more details check $tempmsglog .#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
else
if [ $ALERT == NO ] ; then
  echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mFileSystem Status \t: \E[32;48m [NORMAL] "
  else
  echo "FileSystem Status#[NORMAL]#GREEN" >> $REPORT
  fi
fi
}

## RBL checking

multi_rbl_check()
{
if [ -f "$TEMDIR/rblblacklist" ]  && [ $firstcheck == "NO" ] && [ ! -z `find "$TEMDIR/rblblacklist" -mmin -3600` ]  ;then
while read output ; do
[ -z "$output" ] && continue
status=$(echo $output | cut -d# -f1 )
ip=$(echo $output | cut -d# -f2 )
rbl=$(echo $output | cut -d# -f3 )
if [ "$1" == "$ip" ] ; then
if [ $status == "CRITICAL" ] ;then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRBL Blacklist \t\t: \E[31;48m [$status] $ip blacklisted $rbl"
else
echo "RBL Blacklist#[$status] $ip blacklisted $rbl#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRBL Blacklist \t\t: \E[32;48m [NORMAL] $ip"
else
echo "RBL Blacklist#[NORMAL] $ip#GREEN" >> $REPORT
fi
fi
fi
done < "$TEMDIR/rblblacklist"
else
DEBUG="$2"
firstcheck="YES"
# RBL list from http://www.anti-abuse.org/multi-rbl-check/
RBL="bl.spamcop.net cbl.abuseat.org b.barracudacentral.org dnsbl.sorbs.net http.dnsbl.sorbs.net dul.dnsbl.sorbs.net misc.dnsbl.sorbs.net smtp.dnsbl.sorbs.net socks.dnsbl.sorbs.net spam.dnsbl.sorbs.net web.dnsbl.sorbs.net zombie.dnsbl.sorbs.net pbl.spamhaus.org sbl.spamhaus.org xbl.spamhaus.org zen.spamhaus.org psbl.surriel.com dnsbl.njabl.org combined.njabl.org rbl.spamlab.com dyna.spamrats.com noptr.spamrats.com spam.spamrats.com cbl.anti-spam.org.cn cdl.anti-spam.org.cn  drone.abuse.ch httpbl.abuse.ch korea.services.net short.rbl.jp virus.rbl.jp spamrbl.imp.ch wormrbl.imp.ch virbl.bit.nl rbl.suresupport.com dsn.rfc-ignorant.org  spamguard.leadmon.net netblock.pedantic.org multi.surbl.org ix.dnsbl.manitu.net tor.dan.me.uk rbl.efnetrbl.org relays.mail-abuse.org blackholes.mail-abuse.org rbl-plus.mail-abuse.org dnsbl.dronebl.org access.redhawk.org db.wpbl.info rbl.interserver.net query.senderbase.org bogons.cymru.com"
ip=$1
ipb="NO"
r_ip=$(echo $ip|awk -F"." '{for(i=NF;i>0;i--) printf i!=1?$i".":"%s",$i}')
for rbl in $RBL
do
echo -n "RBL Blacklist :Checking  $ip blacklisting $rbl ... please wait while.............................."
sleep 0
echo -ne "\x0d\E[2k"

if [ ! -z "$DEBUG" ]
then
echo "testing `hostname` ($ip) against $rbl"
fi
result=$(dig +short $r_ip.$rbl)
if [ ! -z "$result" ]
then
#echo "`hostname` ($ip) is in $rbl with code $result"

echo "CRITICAL#$1#$rbl" >> $TEMDIR/rblblacklist
if [ $ALERT == NO ] ; then
echo -e "\r$var\033[K"
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRBL Blacklist \t\t: \E[31;48m [CRITICAL] $ip blacklisted $rbl"
else
echo "RBL Blacklist#[CRITICAL] $ip blacklisted $rbl#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi

ipb="YES";
fi
if [[ ! -z "$DEBUG" && -z "$result" ]]
then
echo "\`->negative"
fi
done
if [ $ipb == "NO" ]; then
echo "NORMAL#$1" >> $TEMDIR/rblblacklist
if [ $ALERT == NO ] ; then
echo -e "\r$var\033[K"
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mRBL Blacklist \t\t: \E[32;48m [NORMAL] $ip"
else
echo "RBL Blacklist#[NORMAL] $ip#GREEN" >> $REPORT
fi

fi
fi
}

### rbl, rdns,fdns check
rbl_rdns_fdns_check()
{
firstcheck="NO";
function system_primary_ip()
{
# returns the primary IP assigned to eth0
#echo $(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')
echo $(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
}



function get_rdns()
{
# calls host on an IP address and returns its reverse dns

if [ ! -e /usr/bin/host ]; then
yum -y install dnsutils > /dev/null
fi
echo $(host $1 | awk '/pointer/ {print $5}' | sed 's/\.$//')
}
function get_fdns()
{
# calls host on an IP address and returns its reverse dns

if [ ! -e /usr/bin/host ]; then
yum -y install dnsutils > /dev/null
fi
echo $(host $1 | awk '/address/ {print $4}' | sed 's/\.$//')
}

dnscheck()
{
if [ $RDNS == YES ] ; then
rdnsip=$(get_rdns $1) ;
if [ "$2"  == "*" ] ; then
domain=`hostname`
else
domain=$2
fi

## rDNS check script
if [ ! -z "$rdnsip" ]; then
if [ "$rdnsip" == "$domain" ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mReverse DNS \t\t: \E[32;48m [NORMAL] $1"
else
echo "Reverse DNS#[NORMAL] $1#GREEN" >> $REPORT
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mReverse DNS \t\t: \E[31;48m [CRITICAL] $1 rDNS MISMATCH"
else
echo "Reverse DNS#[CRITICAL] $1 rDNS MISMATCH#RED" >> $REPORT
fi
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mReverse DNS \t\t: \E[31;48m [CRITICAL] $1 rDNS MISSING"
else
echo "Reverse DNS#[CRITICAL] $1 rDNS MISSING#RED" >> $REPORT
fi
fi
fi

## forward dns check
if [ $FDNS == YES ] ; then
fdnsip=$(get_fdns $domain) ;
if [ ! -z "$fdnsip" ]; then
if [ "$fdnsip" ==  "$1" ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mForward DNS \t\t: \E[32;48m [NORMAL] $1"
else
echo "Forward DNS#[NORMAL] $1#GREEN" >> $REPORT
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mForward DNS \t\t: \E[31;48m [CRITICAL] $1 FDNS MISMATCH"
else
echo "Forward DNS#[CRITICAL] $1 FDNS MISMATCH#RED" >> $REPORT
fi
fi
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mForward DNS \t\t: \E[31;48m [CRITICAL] $1 FDNS MISSING"
else
echo "Forward DNS#[CRITICAL]  $1 FDNS MISSING#RED" >> $REPORT
fi
fi
fi

}


if [ -f '/etc/mailips' ] ; then
if [ `/bin/cat /etc/mailips |wc -l ` -ne 0 ] ;then
mailips=`/bin/cat /etc/mailips |grep -v "#" |sed 's/ //g'`
if [ `echo  $ip | grep -vE "(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])"` ]; then
for mailip in $mailips
do
ip=`echo $mailip |cut -d: -f2 `
#if [ `echo  $ip | grep -vE "10.10.|192.168|172.16"` ]; then
if [ `echo  $ip | grep -vE "(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])"` ]; then
domain=`echo $mailip |cut -d: -f1`
dnscheck $ip "$domain"
if [ $RBLCHECK == YES ] ; then
multi_rbl_check $ip
fi
fi
done
fi
else
ip=$(system_primary_ip)
#if [ `echo  $ip | grep -vE "10.10.|192.168|172.16"` ]; then
if [ `echo  $ip | grep -vE "(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])"` ]; then
domain=`hostname`
dnscheck $ip "$domain"
if [ $RBLCHECK == YES ] ; then
multi_rbl_check $ip
fi
fi
fi
else
ip=$(system_primary_ip)
#if [ `echo  $ip | grep -vE "10.10.|192.168|172.16"` ]; then
if [ `echo  $ip | grep -vE "(127\.)|(192\.168\.)|(10\.)|(172\.1[6-9]\.)|(172\.2[0-9]\.)|(172\.3[0-1]\.)|(::1$)|([fF][cCdD])"` ]; then
domain=`hostname`
dnscheck $ip "$domain"
if [ $RBLCHECK == YES ] ; then
multi_rbl_check $ip
fi
fi
fi

}
###
poodle_vul_check()
{
if [ ! -f '/usr/bin/nmap' ] ;then
yum -q install nmap -y;
fi
httpstatus=$(/usr/bin/nmap -PN -p 443  localhost | /bin/grep 443/ | /bin/awk '{ print$2 }')
if [ $httpstatus == "open" ]; then
port=${2:-443}
timeout_bin=`which timeout 2>/dev/null`
ips=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
for host in $ips
do
out="`echo 'Q' | ${timeout_bin:+$timeout_bin 5} openssl s_client -ssl3 -connect "${host}:${port}" 2>/dev/null`"

if [ $? -eq 124 ]; then
        echo "error: Timeout connecting to host!"
        exit 1
fi

proto=`echo "$out" | grep '^ *Protocol *:' | awk '{ print $3 }'`
cipher=`echo "$out" | grep '^ *Cipher *:' | awk '{ print $3 }'`
if [ "$cipher" = '0000'  -o  "$cipher" = '(NONE)' ]; then
continue;
else
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mPOODLE Vulnerability \t: \E[31;48m [CRITICAL] $host:$port SSLv3 [$proto/$cipher] enabled "
else
echo "POODLE Vulnerability#[CRITICAL] [CRITICAL] $host:$port SSLv3 [$proto/$cipher] enabled#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi

fi
done
fi
}
## Memcache valuranble
function memcache_vul_check()
{
if [ ! -f '/usr/bin/nmap' ] ;then
yum -q install nmap -y;
fi
memstatus=$(netstat -nau |grep 11211 |wc -l)
if [ $memstatus -gt 0 ]; then
/sbin/service memcached stop
replace 'OPTIONS=""' 'OPTIONS="-l 127.0.0.1 -U 0"' -- /etc/sysconfig/memcached
if [ $(cat /etc/sysconfig/memcached |grep "l 127.0.0.1 -U 0") -gt 0 ]; then
/sbin/service memcached start
fi
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mMemcache Vulne \t: \E[31;48m [CRITICAL] Memcache Patched  "
fi
fi
}

## one tmeupdate
onetime()
{
echo 1
}
##  glibc CVE-2015-7547 check
glibc_vul_check()
{
glibcversion=`rpm -q glibc | awk -F- {'print $2'} |  uniq`
if [ $glibcversion > "2.9" ] ; then
if [ $ALERT == NO ] ; then
echo -e "\t\t\t\t\t\032\E[33;48m\E[33;48mGLIBC Vulnerability \t: \E[31;48m [CRITICAL] glibc vulnerabile version $glibcversion found."
else
echo "GLIBC Vulnerability#[CRITICAL] [CRITICAL] glibc vulnerabile version $glibcversion found#RED" >> $REPORT
herror=$(( $herror + 1 ))
fi
fi
}
## Shared RBL mon
shared_rbl()
{
firstcheck="NO";
if [ -f '/etc/mailips' ] ; then
if [ `/bin/cat /etc/mailips |wc -l ` -ne 0 ] ;then
ip=`/bin/cat /etc/mailips |grep "*" |grep -v "#" |cut -d: -f2 |sed 's/ //g'`
if [ `echo  $ip | grep -vE "10.10.|192.168|172.16"` ]; then
multi_rbl_check $ip
fi
fi
else
ip=$(system_primary_ip)
if [ `echo  $ip | grep -vE "10.10.|192.168|172.16"` ]; then
multi_rbl_check $ip
fi
fi
}
update()
{
if [ `grep 'srvhsmon' /etc/profile |wc -l` -eq 0 ]; then
cat >> /etc/profile << NEOF
## Server Heathcheck Script
if [ "\$LOGNAME" == "root" ]; then
if [ -f /usr/bin/srvhsmon ];then
/usr/bin/srvhsmon --check 2> /dev/null
fi
fi
NEOF
fi
}

## Techsupport help
techhelp()
{
if [ ! -f "/root/techsupport.help" ] ; then
cat >> /root/techsupport.help<< NEOF
### File is created by TechSupport Team so please don't delete it
###########################################################################
A) Running Service
-------------------------------
Service Name  |  Service port |
--------------|---------------|
HTTP/HTTPS    |   80/443      |
--------------|---------------|
MySQL         |   3306        |
--------------|---------------|
SMTP/POP/IMAP |   25/110/143  |
--------------|---------------|
cPanel/WHM    |   default     |
--------------|---------------|
              |               |
--------------|---------------|
              |               |
--------------|---------------|

###########################################################################
B) Service Configuration Path and Details

###########################################################################
Service         : HTTP
Home Path       : /usr/local/apache/
Conf Path       : /usr/local/apache/conf
VirtualHost     : /usr/local/apache/conf/
Logs Path       : /usr/local/apache/logs/
Service Port    : 80,443
Dependency Service and Port : MySQL

Service start/stop command :
T stop : service httpd stop
To start : service httpd startssl
To reload : service httpd  restart
###############################################################################

C) Customized installation


###############################################################################


D) Important Note

1)
2)
3)
4)
5)
==
NEOF
fi

}
## help
showhelp()
{
   echo "Server Health/Security Check "
   echo "  --check    : Check server health/security and display output on screen"
   echo "  --chkspam    : Check spammer/malicious spamming account on server"
   echo "  --alert    : Check server health/security and send a notification "
   echo "  --recheck  : Re check server health/security and display output on screen"
   echo "  --conf     : Restore default server health/security configuration file"
   echo "  --update   : Update server health/security script"
   echo "  --siteinfo domain : Display Basic domain info"
   echo "  --help     : echo this help screen"
}
alert()
{
email=$1
cat > $TEMDIR/heathcheckreport.html << NEOF
<div align="center" style="width: 100%;">
<h2 style="font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif;"> Server Health and Security Check Report </h2></font>
<table  style="border: 1px solid #181818; border-collapse: collapse; border-spacing: 0; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10pt; width: 600; " align="center">
NEOF

cat $REPORT | while read line; do
echo -e "<tr style=\"border: 1px solid #181818; border-collapse: collapse; border-spacing: 0; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10pt; background-color: #789090; color: #181800;\" >

                                <th style=\"border: 1px solid #181818; border-collapse: collapse; border-spacing: 0; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10pt; background-color: #E4E4C8; color: #000; text-align: center; background-color: #789090; color: #181800\">
                                        `echo $line | cut -d# -f1`
                                </th>

                                <td style=\"border: 1px solid #181818; border-collapse: collapse; border-spacing: 0; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: 10pt; background-color: #E4E4C8; color:`echo $line | cut -d# -f3`; text-align: center; \">
                                         `echo $line | cut -d# -f2`
                                </td>

                        </tr>" >> $TEMDIR/heathcheckreport.html
done
echo "</table>" >> $TEMDIR/heathcheckreport.html
if [ -e "/usr/local/cpanel/version" ]; then
if [ ! -f "/usr/bin/mutt" ]; then
yum install mutt -y -q
fi
mutt -e "set content_type=text/html" -e "set realname=\"Server Admin\"  " $email -s "$2" < $TEMDIR/heathcheckreport.html
else
(cat <<EOCAT
Subject: $2
From: Server Admin <root@`hostname`>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=NextPart_0123456789
Content-Transfer-Encoding: 7bit
--NextPart_0123456789
Content-Type: text/html
Content-Disposition: inline
EOCAT
cat $TEMDIR/heathcheckreport.html) | /usr/sbin/sendmail $email
fi

}
## Read variable
readvarible()
{
if [ ! -f "/usr/sbin/virt-what" ] ; then
yum -q install  virt-what -y
fi
virtype="";
if [ `dmidecode | egrep -i Microsoft |wc -l` -gt 0 ] ; then
virtype="Microsoft Virtual Machine"
elif [ `dmidecode | egrep -i VMware |wc -l` -gt 0 ] ; then
virtype="Vmware Virtual Machine"
elif [ `dmidecode | egrep -i QEMU |wc -l` -gt 0 ] ; then
virtype="KVM Virtual Machine"
elif [ `virt-what |grep -i xen|wc -l` -gt 0 ] ; then
virtype="XEN Virtual Machine"
else
virtype="Dedicated"
fi

if [ -e $CONFILE ]; then
ADMINEMAIL=`cat $CONFILE |grep -w "ADMINEMAIL" |gawk -F= '{ print $2 }'|tr -d '"'`;
RAIDMON=`cat $CONFILE |grep -w "RAIDMON" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxmemory=`cat $CONFILE |grep -w "MAXMEMORY" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxswap=`cat $CONFILE |grep -w "MAXSWAP" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxload=`cat $CONFILE |grep -w "MAXLOAD" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxstorage=`cat $CONFILE |grep -w "MAXSTORAGE" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxhdparm=`cat $CONFILE |grep -w "MAXHDPARM" |gawk -F= '{ print $2 }'|tr -d '"'`;
warn_hdparm=`cat $CONFILE |grep -w "WARN_HDPARM" |gawk -F= '{ print $2 }'|tr -d '"'`;
RDNS=`cat $CONFILE |grep -w "RDNS" |gawk -F= '{ print $2 }'|tr -d '"'`;
FDNS=`cat $CONFILE |grep -w "FDNS" |gawk -F= '{ print $2 }'|tr -d '"'`;
RBLCHECK=`cat $CONFILE |grep -w "RBLCHECK" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxmailq=`cat $CONFILE |grep -w "MAXMAILQ" |gawk -F= '{ print $2 }'|tr -d '"'`;
else

ADMINEMAIL=`cat $CONFILE |grep -w "ADMINEMAIL" |gawk -F= '{ print $2 }'|tr -d '"'`;
RAIDMON=`cat $CONFILE |grep -w "RAIDMON" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxmemory=`cat $CONFILE |grep -w "MAXMEMORY" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxswap=`cat $CONFILE |grep -w "MAXSWAP" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxload=`cat $CONFILE |grep -w "MAXLOAD" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxstorage=`cat $CONFILE |grep -w "MAXSTORAGE" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxhdparm=`cat $CONFILE |grep -w "MAXHDPARM" |gawk -F= '{ print $2 }'|tr -d '"'`;
warn_hdparm=`cat $CONFILE |grep -w "WARN_HDPARM" |gawk -F= '{ print $2 }'|tr -d '"'`;
RDNS=`cat $CONFILE |grep -w "RDNS" |gawk -F= '{ print $2 }'|tr -d '"'`;
FDNS=`cat $CONFILE |grep -w "FDNS" |gawk -F= '{ print $2 }'|tr -d '"'`;
RBLCHECK=`cat $CONFILE |grep -w "RBLCHECK" |gawk -F= '{ print $2 }'|tr -d '"'`;
maxmailq=`cat $CONFILE |grep -w "MAXMAILQ" |gawk -F= '{ print $2 }'|tr -d '"'`;

fi
#check blank variable and set default value
if [ -z "ADMINEMAIL" ]; then
ADMINEMAIL="root@`hostname`"
fi
if [ -z "RAIDMON" ]; then
RAIDMON=YES
fi
if [ -z "maxmemory" ]; then
maxmemory=98
fi
if [ -z "maxswap" ]; then
maxswap=80
fi
if [ -z "maxload" ]; then
maxload=10
fi
if [ -z "maxstorage" ]; then
maxstorage=90
fi
if [ -z "maxhdparm" ]; then
maxhdparm=25
fi
if [ -z "warn_hdparm" ]; then
warn_hdparm=50
fi
if [ -z "RDNS" ]; then
RDNS=YES
fi
if [ -z "FDNS" ]; then
FDNS=YES
fi
if [ -z "RBLCHECK" ]; then
RBLCHECK=YES
fi

##
if [ "$virtype" != "Dedicated" ] ; then
RAIDMON=NO
HDPARMMON=NO
fi
}



cpcheckspam()
{
if [ -e "/usr/local/cpanel/version" ]; then
month=`date +%b`
date=`date +%Y-%m-%d`
EXIMLOGS="/root/exim_mainlog-tmp";
if [ -e "/home/logs/exim/$month/exim_mainlog-$date.gz" ] ; then
zcat /home/logs/exim/$month/exim_mainlog-$date.gz > $EXIMLOGS;
cat  /var/log/exim_mainlog >>  $EXIMLOGS;
elif [ -e "/var/log/exim_mainlog.1.gz" ]; then
zcat /var/log/exim_mainlog.1.gz  > $EXIMLOGS;
else
EXIMLOGS='/var/log/exim_mainlog'
fi
if [ -e "/usr/local/cpanel/version" ]; then
echo "======="
echo -e "\033[40;32m \e[1m 1) Email Queue :"`tput sgr0;``exim -bpc`
exim -bpr | exiqsumm -c | head -3
echo "======="
echo -e "\033[40;32m \e[1m 2) No of forwarders to hotmail gmail aol : "`tput sgr0;` `grep  -E 'hotmail|gmail|aol|yahoo|outlook' /etc/valiases/*  |wc -l`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " Medium "
grep  -E 'hotmail|gmail|aol|yahoo|outlook' /etc/valiases/* |awk -F"/" '{print $4}' |cut -d: -f1 |sort  | uniq -c | sort -nr -k1 | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) check top account and forwarder and notify to clients "`tput sgr0;`
echo "======="
echo "======="
echo -e "\033[40;32m \e[1m 3) Catch All enabled domains : "`tput sgr0;` `grep "*:" /etc/valiases/* | grep -E 'hotmail|gmail|aol|yahoo|outlook' |wc -l`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
grep "*:" /etc/valiases/* | grep -E 'hotmail|gmail|aol|yahoo|outlook' |cut -d"/" -f4
echo -e "\033[40;32m \e[91m Suggestion: 1) Disble all catch all emails(/etc/valiases/domain) file and set to '*: :fail: No Such User Here' "`tput sgr0;`
echo "======="

echo -e "\033[40;32m \e[1m 4) Top Account which send mails from localhost :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
grep "=> .*@.*@.*" $EXIMLOGS | awk '{print $6,$5}' | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) check top account, it's cron's email send to cpanel default account and set blank value in cont MAILTO "`tput sgr0;`
echo "======="
echo -e "\033[40;32m \e[1m 5) Top Authenticated Dovecot Login :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
cat $EXIMLOGS |egrep -o 'dovecot_login[^ ]+' | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) Reset the password and inform a client about same as account is being compromised and sending spam email"`tput sgr0;`
echo "======="

echo "======="
echo -e "\033[40;32m \e[1m 5) Exceeded the max emails per hour :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
cat $EXIMLOGS |grep "exceeded the max emails" |awk -F": Domain" '{print $2}'|awk {'print $1'}| grep -v '^$' |sort |uniq
echo -e "\033[40;32m \e[91m Suggestion: 1) Reset the password and inform a client about same as account is being compromised and sending spam email"`tput sgr0;`
echo "======="

echo -e "\033[40;32m \e[1m 6) Top cpanel user/account sender (authenticated_local_user) :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
cat $EXIMLOGS |grep 'B=authenticated_local_user' | awk -F"S=" '{print $2}' |awk '{print $1}' | sort | uniq -c | sort -nr -k1 | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) Might changes to comrpormised cpanel ccount and being used to sent spam email from non exist emial addresss"
echo -e  "\033[40;32m \e[91m 2) immediately change cpanel password and informa a client about it with logs "`tput sgr0;`
echo "======="
echo -e "\033[40;32m \e[1m 7) Top 5 Email account sender :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
cat $EXIMLOGS |awk -F"=>" '{print $2}'  |awk '{print $1,$2}' | grep '@'| sort | uniq -c | sort -nr -k1 | head -3
echo "======="
echo -e "\033[40;32m \e[1m 8) Top mails send through scripts :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " High "
#grep cwd $EXIMLOGS | grep -v /var/spool | awk -F"cwd=" '{print $2}'  | awk '{print $1}' |grep "home" | uniq -c | sort -nr | head -5
awk '{ if ($0 ~ "cwd" && $0 ~ "home") {print $3} }' $EXIMLOGS | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) Identify a spamming script , disble it and inform a client."`tput sgr0;`
echo "======="
echo -e "\033[40;32m \e[1m 9) Top mails send through Cron :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " Low "
grep cwd $EXIMLOGS | grep -v /var/spool | awk -F"cwd=" '{print $2}'   | grep CronDaemon | awk '{print $1}' |grep "home" |  sort| uniq -c | sort -nr | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) Check crons email and disble them if it send to external domain very frequently ."`tput sgr0;`
echo "======="
echo -e "\033[40;32m \e[1m 10) Top 5 Recipient domains :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " Medium "
echo -e "\033[40;33m \e[1m Count To GMAIL :" `grep "=>" $EXIMLOGS | awk '{print $5}' | grep "gmail.com" | wc -l ;``tput sgr0;`
grep "=>" $EXIMLOGS | awk '{print $6,$5}' | grep "gmail.com" | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;33m \e[1m Count To AOL :" `grep "=>" $EXIMLOGS | awk '{print $5}' | grep "aol.com" | wc -l ;``tput sgr0;`
grep "=>" $EXIMLOGS | awk '{print $6,$5}' | grep "aol.com" | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;33m \e[1m Count To HOTMAIL :" `grep "=>" $EXIMLOGS | awk '{print $5}' | grep "hotmail.com" | wc -l ;``tput sgr0;`
grep "=>" $EXIMLOGS | awk '{print $6,$5}' | grep "hotmail.com" | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;33m \e[1m Count To LIVEMAIL :" `grep "=>" $EXIMLOGS | awk '{print $5}' | grep "live.com" | wc -l ;``tput sgr0;`
grep "=>" $EXIMLOGS | awk '{print $6,$5}' | grep "live.com" | sort | uniq -c | sort -nr | head -3
echo -e "\033[40;33m \e[1m Count To YAHOO :" `grep "=>" $EXIMLOGS | awk '{print $5}' | grep "yahoo.com" | wc -l ;``tput sgr0;`
grep "=>" $EXIMLOGS | awk '{print $6,$5}' | grep "yahoo.com" | sort | uniq -c | sort -nr | head -3

echo "======="
echo -e "\033[40;32m \e[1m 11) Root Forwarder : "`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " Low "
if [ -e '/root/.forward' ] ; then
cat /root/.forward

fi
echo "======="
echo -e "\033[40;32m \e[1m 12) Top Autoresponder :"`tput sgr0;`
echo -e "\033[40;31m \e[1m Priority: "`tput sgr0;` " Medium "
cat  $EXIMLOGS |  grep .autorespond | awk '{print $7}' | sort -nr | uniq -c | sort -nr | head -3
echo -e "\033[40;32m \e[91m Suggestion: 1) disable external domain autoresponder specially hotmail, outlook, gmail etc.."`tput sgr0;`
echo "======="
exim -bpr | grep frozen | awk {'print $3'} | xargs exim -Mrm >/dev/null 2>&1
exim -bpr | grep "<>" | awk {'print $3'} | xargs exim -Mrm >/dev/null 2>&1
fi
if [ -e '/root/exim_mainlog-tmp' ]; then
rm -f /root/exim_mainlog-tmp
fi
fi
}

siteinfo()
{
RED='\033[01;31m'
GREEN='\033[01;32m'
MOUVE='\033[01;35m'
WHITE='\033[01;1;37m'
DYELLOW='\033[01;33m'
YELLOW='\033[01;1;33m'
DGREEN='\033[01;32m'
CYAN='\033[01;36m'
BOLD=$(tput bold)
UNDERLINE=$(tput sgr 0 1)
RESET='\033[0m'

DOMAIN=$1
if [ `echo $DOMAIN | grep "www." | wc -l` -gt 0 ] || [ `echo $DOMAIN |wc -c` -le 1 ]; then
echo -e "$RED Enter domain without www $RESET"
        exit
fi
service_check()
{
APCHECK=$(netstat -alnp | grep httpd | wc -l)
APCHECKU=$(netstat -alnp | grep apache2 | wc -l)
if [ "$APCHECK" -gt 0 ] || [ "$APCHECKU" -gt 0 ] ; then
echo -e "$BOLD $CYAN WEBSERVER:APACHE(80)\t\t\t:-\t\t\t$GREEN [RUNNING]$WHITE `netstat -alnp | grep httpd | grep LISTEN | grep -v ":443" | head -1 | cut -d":" -f2 | awk '{print $1}'` `netstat -alnp | grep httpd | grep LISTEN | head -1 | cut -d":" -f4` $RESET"
fi
NGCHECK=$(netstat -alnp | grep nginx | wc -l)
if [ "$NGCHECK" -gt 0 ]; then
echo -e "$BOLD $CYAN WEBSERVER:NGINX\t\t\t:- \t\t\t$GREEN [RUNNING] $RESET$WHITE `netstat -alnp | grep nginx | grep LISTEN | head -3 | grep -v 443| cut -d":" -f2 | awk '{print $1}'`  $RESET"
fi
echo -e "$BOLD $CYAN WEBSERVER:APACHE(443)\t\t\t:-\t\t\t$GREEN [RUNNING]$WHITE`netstat -alnp | grep :443 | grep LISTEN | head -1 | cut -d"/" -f2`  $RESET"

if [ `netstat -alnp | grep :53 | head -n 1 | cut -d"/" -f2|wc -l` -gt 0 ]; then
echo -e "$BOLD $CYAN DNS SERVICE \t\t\t\t:-\t\t\t$GREEN [RUNNING]$WHITE`netstat -alnp | grep :53 | head -n 1 | cut -d"/" -f2`  $RESET"
else
echo -e "$BOLD $CYAN DNS SERVICE \t\t\t\t:-\t\t\t$RED [DOWN]  $RESET"
fi
mysql=$(netstat -alnp  | grep mysql.sock | head -n 1 | wc -l)

if [ "$mysql" -gt 0 ]; then
echo -e "$BOLD $CYAN MYSQL SERVICE Status \t\t\t:-\t\t\t$RESET $GREEN[RUNNING] $RESET "
else
echo -e "$BOLD $CYAN MYSQL SERVICE Status \t\t\t:-\t\t\t$RESET $RED[DOWN] $RESET "
fi
}
DNSCHECK()
{
which dig &>/dev/null

if [ $? -eq 0 ]; then
echo ""
else
echo " "
echo " If you want to install it use : yum install bind-utils for Ubantu/Debian : apt-get install dnsutils"
fi
echo -e "$DYELLOW ===============================$DGREEN Domains DNS  Information $DYELLOW============================================== $RESET"

NS=$(dig $DOMAIN @8.8.8.8 ns +noall +answer +nocomments +short  |  tr "\n" " ")
#if [ -z "$NS" ]; then
#echo -e "$BOLD $CYAN A Record\t\t:- \t\t\t$RESET $RED  DNS ISSUE DETECTED  $RESET"
#exit
#fi

ARECORD=$(dig $DOMAIN @8.8.8.8 A +noall +answer +nocomments +short |  tr "\n" " ")
MXRECORD=$(dig $DOMAIN @8.8.8.8 MX +noall +answer +nocomments +short |  tr "\n" " ")
TXTRECORD=$(dig $DOMAIN @8.8.8.8 txt +noall +answer +nocomments +short)
echo -e "$BOLD $CYAN Name servers\t\t:-\t\t\t$RESET $WHITE  $NS   $RESET "
echo -e "$BOLD $CYAN A Record\t\t:- \t\t\t$RESET $WHITE  $ARECORD $RESET "

if [ `ifconfig  | grep "$ARECORD"| wc -l` -eq 0 ];then
if [ -e  /var/cpanel/cpnat ];then
if [ `cat /var/cpanel/cpnat|grep $ARECORD|awk '(print $1)'| wc -l` -eq 0  ];then

echo -e "$BOLD $RED $DOMAIN IS POINTING TO EXTERNAL SERVER OR USING CDN SERVICE $RESET "
exit
fi
fi
echo -e "$BOLD $RED $DOMAIN IS POINTING TO EXTERNAL SERVER OR USING CDN SERVICE $RESET "
exit
fi
if [ -z "$ARECORD" ];then
echo -e "$BOLD $CYAN A Record\t\t:- \t\t\t$RESET $RED  A RECORD MISSING  $RESET"
exit
fi

if [ -z "$MXRECORD" ];then
echo -e "$BOLD $CYAN MX Record\t\t:- \t\t\t$RESET $RED  MX RECORD MISSING  $RESET"
else
echo -e "$BOLD $CYAN MX Record\t\t:- \t\t\t$RESET $WHITE  $MXRECORD  $RESET "
MXIP=$(echo $MXRECORD | awk '{print $2}')
IP=$(host $MXIP | head -n 1 | awk '{print $4}')
if [ `ifconfig  | grep "$IP" | wc -l` -gt 0 ]; then

echo -e "$BOLD $CYAN MAIL SERVER \t\t:- \t\t\t$RESET $WHITE  LOCAL  $RESET "
if [ -e  /var/cpanel/cpnat ]; then
if [ `cat /var/cpanel/cpnat|grep $IP| wc -l` -gt 0  ];then
echo -e "$BOLD $CYAN MAIL SERVER \t\t:- \t\t\t$RESET $WHITE  LOCAL  $RESET "
fi
fi
else
echo -e "$BOLD $CYAN MAIL SERVER \t\t:- \t\t\t$RESET $WHITE  REMOTE  $RESET "
fi
fi
if [ -z "$TXTRECORD" ];then
echo -e "$BOLD $CYAN TXT Record\t\t:- \t\t\t$RESET $RED  TXT RECORD MISSING $RESET "
else
echo -e "$BOLD $CYAN TXT Record\t\t:- \t\t\t$RESET $WHITE  $TXTRECORD  $RESET "
fi


#echo -e "$DYELLOW===================================================================================================================$RESET "

}

siteresponse()
{
RES=$(curl -Is http://$DOMAIN | head -n 1 | awk '{print $2}')
if [ "$RES" -eq "502" ]|| [ "$RES" -eq "504" ]; then
echo "$GREEN A 502 error means that a web server that is serving as a reverse proxy (say, Apache) for the website origin server (such as NginX), did not receive a valid response from the original web server. $RESET"
echo -e "$GREEN Please check if you have Nginx and apache running on server both the  services are online and working fine $RESET"
fi
if [ "$RES" -eq "500" ]; then
echo -e  "$GREEN If it is Cpanel server 1. Check apache error log. 2. .htaccess file for invalid  value $RESET"
fi

if [ "$RES" -eq "301" ]; then
echo -e "$GREEN Site is redirected $RESET"
fi
}
sitecheck()
{
echo -e "$DYELLOW============================================$GREEN Site Information $RESET  $DYELLOW  =====================================$RESET "
USER=$(/scripts/whoowns $DOMAIN)
if [ `cat /etc/userdomains| grep "$DOMAIN" | wc -l` -eq 0 ] || [ `/scripts/whoowns $DOMAIN | wc -l` -eq 0 ]; then
echo -e "$BOLD $RED $DOMAIN DOES NOT BELONG TO ANY CUSTOMER $RESET "
exit
fi
echo -e "$BOLD $CYAN Domain Name\t\t:-\t\t\t $WHITE$DOMAIN $RESET "
echo -e "$BOLD $CYAN Owner of Domain\t:-\t\t\t $WHITE`/scripts/whoowns $DOMAIN` $RESET"
                        if [ -e /var/cpanel/userdata/$USER/$DOMAIN\_SSL ]; then
                                SSLFILE=$(cat /var/cpanel/userdata/$USER/$DOMAIN\_SSL | grep sslcertificatefile | awk '{print $2}')
                                openssl x509 -noout -in $SSLFILE -text >> /tmp/SSLINFO_$DOMAIN
echo -e "$BOLD $CYAN SSL INSTALLED \t:-\t\t\t $GREEN YES $RESET"
echo -e "$BOLD $CYAN SSL EXPIRY \t\t:-\t\t $WHITE`cat /tmp/SSLINFO_$DOMAIN | awk -F"Not After :" '{print $2}' |tr "\n" " "` $RESET"
echo -e "$BOLD $CYAN SSL ISSUER \t\t:-\t\t\t $WHITE`cat /tmp/SSLINFO_$DOMAIN | grep Issuer | awk -F"O=" '{print $2}'|tr "\n" " "` $RESET"
rm -f /tmp/SSLINFO_$DOMAIN
                                fi
if [ `cat /etc/redhat-release  | grep CloudLinux | wc -l` -eq 1 ];then
LVEINFO=$(lveinfo -o cpu_max --display-username | grep $USER | wc -l)
if [ "$LVEINFO" -gt 0 ]; then
echo -e "$BOLD $CYAN php-fpm Conf file \t:-\t\t\t$RED CPU Usage of $USER is High $RESET"
fi
fi
if [ -e /opt/cpanel/ea-php*/root/etc/php-fpm.d/$DOMAIN.conf ]; then
echo -e "$BOLD $CYAN php-fpm \t\t:-\t\t\t$WHITE ON $RESET "
echo -e "$BOLD $CYAN php-fpm Conf file \t:-\t\t\t$WHITE `ls -al /opt/cpanel/ea-php*/root/etc/php-fpm.d/$DOMAIN.conf| awk '{print $9}'|  tr "\n" " "` $RESET"
echo -e "$BOLD $CYAN php-fpm Log file \t:-\t\t\t$WHITE `cat /opt/cpanel/ea-php*/root/etc/php-fpm.d/$DOMAIN.conf| grep error_log | awk '{print $3}'|  tr "\n" " "` $RESET"
FPM=$(ls -al /opt/cpanel/ea-php*/root/etc/php-fpm.d/$DOMAIN.conf| cut -d"/" -f4)
SYSTEMFPMLOG=$(ls -al /opt/cpanel/$FPM/root/usr/var/log/php-fpm/error.log |awk '{print $9}')
DOMAINFPMLOG=$(cat /opt/cpanel/ea-php*/root/etc/php-fpm.d/$DOMAIN.conf| grep error_log | awk '{print $3}')
echo -e "$BOLD $CYAN php-fpm Log file \t:-\t\t\t $MOUVE[SYSTEM] $WHITE `ls -al /opt/cpanel/$FPM/root/usr/var/log/php-fpm/error.log |awk '{print $9}'|  tr "\n" " "` $RESET"

echo -e "\t\t\t\t\t $MOUVE If you want to make changes in php-fpm Configuration make changes in file $GREEN /var/cpanel/userdata/$USER/$DOMAIN.php-fpm.yaml $RESET"
echo -e "\t\t\t\t\t $MOUVE After making changes run the command $GREEN /scripts/php_fpm_config --rebuild --domain=$DOMAIN $RESET"
        else
echo -e "$BOLD $CYAN php-fpm \t\t:-\t\t\t$RESET $WHITE OFF $RESET "
        fi
DOCROOT=$(httpd -V | grep HTTPD_ROOT | cut -d"=" -f2 | cut -d'"' -f2)
echo -e "$BOLD $CYAN Document Root \t:-\t\t\t$RESET $WHITE `grep -C 3 www.$DOMAIN  $DOCROOT/conf/httpd.conf | grep DocumentRoot | sort -n | uniq | awk {'print $2'}|  tr "\n" " "`  $RESET"

if [ -L "/var/cpanel/overquota/blocks_$USER" ]; then
echo -e "$BOLD $CYAN Account Quota Status \t:-\t\t\t$RESET $RED Exceeded $RESET "
        else
echo -e "$BOLD $CYAN Account Quota Status \t:-\t\t\t$RESET $WHITE Normal $RESET "

        fi
CDOCROOT=$(grep -C 3 www.$DOMAIN  $DOCROOT/conf/httpd.conf | grep DocumentRoot | sort -n | uniq | awk {'print $2'})
cd $CDOCROOT ; echo "<?php phpinfo(); ?>"  > phpinfo.php
chown $USER.$USER phpinfo.php
echo -e "$BOLD $CYAN PHP Version \t\t:-\t\t\t$RESET   $WHITE `php phpinfo.php | grep "PHP Version"|sort -n | uniq | awk '{print $4}'|  tr "\n" " "` $RESET"
        if [ -e "$CDOCROOT/wp-config.php" ]; then
echo -e "$BOLD $CYAN Application Hosted \t:-\t\t\t$RESET   $WHITE Wordpress `grep wp_version $CDOCROOT/wp-includes/version.php | cut -d"'" -f2 | grep [0-9]|  tr "\n" " "` $RESET"
        fi
                if [ -e "$CDOCROOT/libraries/joomla/version.php" ]; then
echo -e "$BOLD $CYAN Application Hosted \t\t:-\t\t\t$RESET   $WHITE Joomla  `fgrep '$RELEASE'  $CDOCROOT/libraries/joomla/version.php | cut -d"'" -f2|  tr "\n" " "` $RESET"

                fi
                        if [ -e "$CDOCROOT/modules/system/system.info" ];then
echo -e "$BOLD $CYAN Application Hosted \t\t:-\t\t\t$RESET   $WHITE Drupal `cat $CDOCROOT/modules/system/system.info  | grep version | cut -d'"' -f2 | grep [0-9]|  tr "\n" " "` $RESET"
                        fi
MXRECORD=$(dig $DOMAIN @8.8.8.8 MX +noall +answer +nocomments +short)
if [  `echo $MXRECORD |wc -l` -gt 1 ];then

MXIP=$(echo $MXRECORD | awk '{print $2}')

IP=$(host $MXIP | head -n 1 | awk '{print $4}')
if [ `ifconfig  | grep $IP| wc -l` -gt 0 ];then
if [ -e  /var/cpanel/cpnat ];then
if [`cat /var/cpanel/cpnat|grep $IP| wc -l` -gt 0  ];then
echo ""
if [ `cat /etc/localdomains|grep $DOMAIN|wc -l` == 0 ]; then
echo -e "$BOLD $RED DOMAIN entry missing from localdomains file. $RESET "
fi
fi
fi
fi
fi
FILECOUNT=$(find $CDOCROOT -type f \( -name "*.sql" -o -name "*.zip" -o -name "*.tar" -o -name "*.tar.gz" -o -name "*.tar.bz2" -o -name "*.gz" \)| wc -l)
if [ "$FILECOUNT" -gt 0 ]; then
echo -e "$DYELLOW===================================================================================================================$RESET "
echo -e "$BOLD $RED DO NOT KEEP ANY BACKUP ZIP TAR DATABASE DUMP IN DOCUMENTROOT MOVE THEM OUT OF DOCUMENTROOT $RESET"
find $CDOCROOT -type f \( -name "*.sql" -o -name "*.zip" -o -name "*.tar" -o -name "*.tar.gz" -o -name "*.tar.bz2" -o -name "*.gz" \)
fi
DNSCHECK
read -n 1 -s -r -p  "Press Enter for Site Summary"
echo -e " \n "

echo -e "$DYELLOW============================================$GREEN RUNNING SERVICES $RESET  $DYELLOW================================================$RESET "
service_check
echo -e "$DYELLOW============================================$DGREEN PHP Environment Settings$RESET  $DYELLOW================================================$RESET "
echo -e "$BOLD $CYAN Main php.ini Configuration File \t:-\t\t\t$WHITE `php phpinfo.php | grep "Configuration File (php.ini) Path" | awk '{print $6}'|  tr "\n" " "` $RESET"
echo -e "$BOLD $CYAN Loaded Configuration File\t\t:-\t\t\t$WHITE `curl -s http://$DOMAIN/phpinfo.php | grep "Loaded Configuration File" | awk '{print $6}' | cut -d">" -f2|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN Additional .ini files parsed\t\t:-\t\t\t$WHITE `php phpinfo.php | grep "Additional .ini files parsed" | awk '{print $6}'|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN Display Error\t\t\t\t:-\t\t\t$WHITE `php phpinfo.php | grep display_errors | awk '{print $5}'|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN PHP Memory Limit\t\t\t:-\t\t\t$WHITE `php phpinfo.php | grep memory_limit | awk '{print $5}'|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN allow_url_fopen\t\t\t:-\t\t\t$WHITE `php phpinfo.php | grep "allow_url_fopen" | awk '{print $5}'|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN allow_url_include\t\t\t:-\t\t\t$WHITE `php phpinfo.php | grep "allow_url_include" | awk '{print $5}'|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN open_basedir\t\t\t\t:-\t\t\t$WHITE `php phpinfo.php | grep "open_basedir" | awk '{print $6 " " $7}'|  tr "\n" " "` $RESET "

echo -e "$BOLD $CYAN Disabled PHP Functions\t\t:-\t\t\t$WHITE `php phpinfo.php | grep disable_functions | awk '{print $3}'|tr "\n" " "` $RESET "
rm -f $CDOCROOT/phpinfo.php
read -n 1 -s -r -p  " Press Any Key  for Error Recorded For The Domain"
echo -e " \n "
echo -e "$DYELLOW============================================$GREEN Latest Apache error $RESET  $DYELLOW================================================$RESET "
echo -e "$MOUVE##############################################################################################################################################$RESET "
tail -n 20 /usr/local/apache/logs/error_log | grep $DOMAIN

if [ -e /opt/cpanel/ea-php*/root/etc/php-fpm.d/$DOMAIN.conf ]; then
echo -e "$MOUVE#############################################$GREEN Latest SYSTEM PHP-FPM error $RESET  $MOUVE##################################################$RESET"
tail -n 20 $SYSTEMFPMLOG | grep $DOMAIN
fi
if [ -e "$DOMAINFPMLOG" ]; then
echo -e "$MOUVE#############################################$GREEN Latest DOMAIN PHP-FPM error $RESET  $MOUVE##############################################$RESET"
tail -n 20 $DOMAINFPMLOG
fi
echo -e "$MOUVE##############################################################################################################################################$RESET"

if [ `cat /etc/redhat-release  | grep CloudLinux | wc -l` -eq 1 ];then
echo -e "$DYELLOW============================================$GREEN Top 10 users, by max CPU usage $RESET  $DYELLOW================================================$RESET"
lveinfo -o cpu_max --display-username
fi

siteresponse
}
SSLCHECKER()
{
echo |openssl s_client -connect $DOMAIN:443 2>/dev/null | openssl x509 -noout -text | grep DNS: >> /tmp/SSLINFO_$DOMAIN
if [ `cat /tmp/SSLINFO_$DOMAIN|grep $DOMAIN|wc -l` -gt 0 ]; then
echo -e "$BOLD $CYAN SSL INSTALLED \t\t:-\t\t\t$GREEN YES $RESET"
echo -e "$BOLD $CYAN SSL EXPIRY \t\t:-\t\t\t$WHITE`echo | openssl s_client -connect $DOMAIN:443 2>/dev/null | openssl x509 -noout -dates | awk -F"notAfter=" '{print $2}'|tr "\n" " "` $RESET"
echo -e "$BOLD $CYAN ALTERNATIVE NAME \t\t:-\t\t\t$WHITE`cat /tmp/SSLINFO_$DOMAIN| grep -C 1 "Subject Alternative Name"|awk -F"DNS:" '{print $2 $3 $4 $5 $6 $7 $8 $9 $10 $11}'|  tr "\n" " " ` $RESET"
else
echo -e "$BOLD $CYAN SSL INSTALLED \t\t:-\t\t\t$RED NO $RESET"
fi

rm -f /tmp/SSLINFO_$DOMAIN
}
sitecheck_plesk()
{
if [ `cat /usr/local/psa/version  | cut -d"." -f1` -le 12 ]; then
echo -e "$BOLD $RED $DOMAIN SCRIPT DOES NOT SUPPORT THIS VERSION OF PLESK $RESET "
exit
fi
echo -e "$DYELLOW============================================$GREEN Site Information $RESET  $DYELLOW  ===================================$RESET "
echo -e "$BOLD $CYAN Domain Name \t\t\t:-\t\t\t$WHITE $DOMAIN $RESET "
plesk bin domain -i $DOMAIN >> /tmp/pleskdomaininfo_$DOMAIN.txt
if [ `echo $?` -eq 1 ]; then
echo -e "$BOLD $RED $DOMAIN DOES NOT BELONG TO ANY CUSTOMER $RESET "
rm -f /tmp/pleskdomaininfo_$DOMAIN.txt
exit
fi
echo -e "$BOLD $CYAN Domain status \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Domain status"| awk '{print $3}'` $RESET "
echo -e "$BOLD $CYAN Hosting type \t\t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Hosting type" | awk '{print $3 " " $4}'` $RESET "
echo -e "$BOLD $CYAN Domain User \t\t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "FTP Login:" | awk '{print $3'}` $RESET "
echo -e "$BOLD $CYAN Expiration date \t\t:-\t\t\t$WHITE  `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Expiration date"| awk '{print $3}'` $RESET "
echo -e "$BOLD $CYAN Disk space limit \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Disk space limit" | awk '{print $4 " " $5}'` $RESET "
echo -e "$BOLD $CYAN Disk space usage \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Size" | awk '{print $2 " " $3}'` $RESET "
echo -e "$BOLD $CYAN Bandwidth limit \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Traffic limit" | awk '{print $3}'` $RESET "
echo -e "$BOLD $CYAN Bandwidth usage \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Traffic:" | awk '{print $2 " " $3}'` $RESET "
echo -e "$BOLD $CYAN Mail service status \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "Mail service:" | awk '{print $3}'` $RESET "
echo -e "$BOLD $CYAN Document Root \t\t:-\t\t\t$WHITE `cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "WWW-Root"| awk '{print $2}'` $RESET "
echo -e "$BOLD $CYAN PHP Handler Used \t\t:-\t\t\t$WHITE `/usr/local/psa/admin/bin/php /root/php_management_tool list | grep $DOMAIN | awk {'print $3'}` $RESET "
PDOCROOT=$(cat /tmp/pleskdomaininfo_$DOMAIN.txt | grep "WWW-Root"| awk '{print $2}')
if [ -e "$PDOCROOT/wp-config.php" ]; then
echo -e "$BOLD $CYAN Application Hosted \t\t:-\t\t\t$WHITE Wordpress `grep wp_version $PDOCROOT/wp-includes/version.php | cut -d"'" -f2 | grep [0-9]|  tr "\n" " "` $RESET"
fi
if [ -e "$PDOCROOT/libraries/joomla/version.php" ]; then
echo -e "$BOLD $CYAN Application Hosted \t\t:-\t\t\t$WHITE Joomla `fgrep '$RELEASE' $PDOCROOT/libraries/joomla/version.php | cut -d"'" -f2|  tr "\n" " "` $RESET"
fi
SSLCHECKER
rm -f /tmp/pleskdomaininfo_$DOMAIN.txt
echo -e "$BOLD $CYAN Nginx Configuration File \t:-\t\t\t$WHITE  `ls -ld /etc/nginx/plesk.conf.d/*/$DOMAIN.conf | head -1 | cut -d ">" -f 2|  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN Apache Configuration File \t:-\t\t\t$WHITE `ls -ld /etc/httpd/conf/plesk.conf.d/*/$DOMAIN.conf | head -1 | cut -d ">" -f 2` $RESET "
echo -e "$BOLD $CYAN Nginx ErrorLog \t\t:-\t\t\t$WHITE  `grep error_log /etc/nginx/plesk.conf.d/*/$DOMAIN.conf | head -1 | cut -d ";" -f 1 | sed -n 's/.* //p'` $RESET "
echo -e "$BOLD $CYAN Apache ErrorLog \t\t:-\t\t\t$WHITE ` grep ErrorLog /etc/httpd/conf/plesk.conf.d/*/$DOMAIN.conf | head -1 | cut -d ":" -f 2 | sed -n 's/.* //p'` $RESET "
FILECOUNTP=$(find $PDOCROOT -type f \( -name "*.sql" -o -name "*.zip" -o -name "*.tar" -o -name "*.tar.gz" -o -name "*.tar.bz2" -o -name "*.gz" \)| wc -l)
if [ "$FILECOUNTP" -gt 0 ]; then
echo -e "$BOLD $RED DO NOT KEEP ANY BACKUP ZIP TAR DATABASE DUMP IN DOCUMENTROOT MOVE THEM OUT OF DOCUMENTROOT $RESET"
echo -e "$BOLD $MOUVE `find $PDOCROOT -type f \( -name "*.sql" -o -name "*.zip" -o -name "*.tar" -o -name "*.tar.gz" -o -name "*.tar.bz2" -o -name "*.gz" \)` $RESET "
fi
DNSCHECK
read -n 1 -s -r -p  "Press Any Key  for Site Summary"
echo -e " \n "
echo -e "$DYELLOW============================================$GREEN RUNNING SERVICES $RESET  $DYELLOW================================================$RESET "
service_check
echo -e "$DYELLOW============================================$DGREEN PHP Environment Settings $RESET  $DYELLOW================================================$RESET "
plesk bin domain --show-php-settings $DOMAIN >> /tmp/$DOMAIN-php.txt
echo -e "$BOLD $CYAN open_basedir\t\t\t\t\t:-\t\t\t$WHITE `cat /tmp/$DOMAIN-php.txt | grep open_basedir | awk '{print $3}' |  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN error_reporting\t\t\t\t:-\t\t\t$WHITE `cat /tmp/$DOMAIN-php.txt | grep error_reporting | awk -F"=" '{print $2}' |  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN max_execution_time\t\t\t\t:-\t\t\t$WHITE `cat /tmp/$DOMAIN-php.txt | grep max_execution_time | awk '{print $3}' |  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN max_input_time\t\t\t\t:-\t\t\t$WHITE `cat /tmp/$DOMAIN-php.txt | grep max_input_time | awk -F"=" '{print $2}' |  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN upload_max_filesize\t\t\t\t:-\t\t\t$WHITE `cat /tmp/$DOMAIN-php.txt | grep upload_max_filesize | awk -F"=" '{print $2}' |  tr "\n" " "` $RESET "
echo -e "$BOLD $CYAN Additional directivies\t\t\t:-\t\t\t$WHITE `cat /tmp/$DOMAIN-php.txt | grep "Additional directivies" | awk -F":" '{print $2}' |  tr "\n" " "` $RESET "
#echo -e "$WHITE `plesk bin domain --show-php-settings $DOMAIN` $RESET"
rm -f /tmp/$DOMAIN-php.txt
read -n 1 -s -r -p  " Press Any Key  for Error Recorded For The Domain"
echo -e " \n "
echo -e "$DYELLOW============================================$GREEN Latest Apache error $RESET  $DYELLOW================================================$RESET"
ApacheErrorLog=$(grep ErrorLog /etc/httpd/conf/plesk.conf.d/*/$DOMAIN.conf | awk '{print $2}' | cut -d '"' -f 2 | uniq)
NginxErrorLog1=$(grep error_log /etc/nginx/plesk.conf.d/*/$DOMAIN.conf | awk '{print $2}' | sort -n | uniq  | cut -d'"' -f2 )
#echo -e "$MOUVE#########################################################################################################################################$RESET "
echo -e "$WHITE `cat $ApacheErrorLog |tail -n 10` $RESET "
echo -e "$MOUVE##########################################################################################################################################$RESET "
echo -e "$BOLD $CYAN Latest Nginx of domain $DOMAIN $RESET "
echo -e "$MOUVE##########################################################################################################################################$RESET "
echo -e "$WHITE `cat $NginxErrorLog1 |tail -n 10`$RESET "
#echo -e "$MOUVE################################################################################################################$RESET "
siteresponse
echo -e "$DYELLOW=================================================================================================================$RESET "
}
controlpanel_check()
{
if [ -e "/usr/local/cpanel/version" ]; then
sitecheck
fi
if [ -e "/usr/local/psa/version" ]; then
sitecheck_plesk

fi
}
controlpanel_check
}

# Main Server Heath Check script
main()
{

if [ $ALERT == NO ] ; then
echo -e "                                                                                                  "
echo "                       ======================= Server (`hostname`) Details  ======================="
echo -e "\t\t\t\t\t\E[33;48m\E[33;48mHOSTNAME \t\t: \E[35;48m `hostname`"
else
echo "HOSTNAME#`hostname`" > $REPORT
fi
oscheck
kernelversion
controlpanel
loginuser
hwfwstatus

if [ $ALERT == NO ] ; then
echo -e "                                                                                                  "
echo -e "                             \t\t\t\t\t \E[37;60m Server Health and Security Check Report "
echo -e "                                                                                                  "
fi
cpucheck
if [ $dorun == YES ] || [ $1 == RECHECK ];then
memorycheck
swapcheck
csfstatus
mailqueue
storagecheck
inodecheck
if [ "$virtype" = "Dedicated" ] ; then
hdd_heath_check
hdparm
hddwrite
fi
#smardcheck
filesystemcheck
rbl_rdns_fdns_check
#poodle_vul_check
#glibc_vul_check
memcache_vul_check
# The END
fi
tput sgr0
if [ $ALERT == NO ] ; then
echo "                       ======================================================================================================"
fi
}


##################################################################
## Execute the program
##################################################################


## Gloabl variabkes
doall=0;
counter=0;
psize=0;
error=0;
dorun=YES;
herror=0
dtype="";
file_life=360
ALERT="NO";
HDPARMMON="YES"
CP="";
maxmailq="";
TEMDIR=/tmp/srvhsmon
REPORT=$TEMDIR/heathcheckreport
CONFILE="/etc/srvhsmon.conf"
readvarible
techhelp
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
OS=`rpm -qa \*-release | grep -Ei "oracle|redhat-|centos-|cloudlinux" | cut -d"-" -f3| cut -d"." -f1|head -1`
if [ ! -d "/tmp/srvhsmon" ]; then
mkdir -p /tmp/srvhsmon
fi
if [ $OS == "5" ] ;then
declare -a rstatus
else
declare -A rstatus
fi

case "$1" in
   --check)
    main CHECK
;;
   --siteinfo)
     siteinfo $2
;;
   --chkspam)
    cpcheckspam
;;
   --alert)
   ALERT=YES
   if [ -z $2 ] ; then
   echo "Enter ther email address "
   else
   rm -f $TEMDIR/*
   main CHECK
   if [ $herror -gt 0 ] ; then
   asubject="`hostname` Server Report : HealthCheck : Critical ($herror)"
   else
   asubject="`hostname` Server Report : HealthCheck : OK "
   fi
   if [ "$3" == "CRITICAL" ] && [ $herror -gt 0 ] ; then
   alert "$2" "$asubject"
   else
   alert "$2" "$asubject"
   fi
   fi
;;
   --recheck)
   rm -f $TEMDIR/*
    main RECHECK
;;

 --update)
    update

;;


--sharbl)
rm -f $TEMDIR/rblblacklist
shared_rbl
;;
   *)
      showhelp
      exit 0;
   ;;
esac
exit 0;