#!/bin/csh -f

if (! $?log) then
        set log=status.log
        set info=info.log
endif
if (-f param_csh.ini) then
        source param_csh.ini
endif
if (-f precheck.ini) then
        source precheck.ini
endif
alias straight 'printf "%-60s %s" \!*'
alias straightln 'printf "%-60s %s\n" \!*'

set path=($path /usr/sbin /sbin)
set S_HOST=`hostname | cut -d"." -f1`
straight "Checking loopback interface configuration: "
(grep '^[^#]*localhost' /etc/hosts >& /dev/null ) && echo "[OK]" || echo "[FAULT]"
straight "Checking host name in hosts file:          " 

grep `eval hostname` /etc/hosts >& /dev/null && echo "[OK]" || echo "[FAULT]" 

straight "Checking hostname in LOCAL DNS:            "
bash -c "nslookup `hostname` 2>>$info" | grep 'Name:' | awk '{print $2}' >>& $info && echo "[OK]" || echo "[WARNING]"
straight "Checking short host name in hosts file:    "
set ipaddr=`grep $S_HOST'[^a-zA-Z0-9-]*' /etc/hosts |  grep -v '^#' | awk '{print $1}' | head -1`
if ("$ipaddr" == "") then
	echo "[FAULT]"
else
	echo "[OK]"
endif

straight "Checking short host name on loopback :     "
if ("$ipaddr" == "127.0.0.1") then
	echo "[FAULT]"
else
	echo "[OK]"
endif

straight "Checking physical ip address match :       "
ifconfig -a | grep "inet " | grep $ipaddr >& /dev/null && echo "[OK]" || echo "[FAULT]"
if (-e /usr/sbin/selinuxenabled) then
    straight "Checking SELINUX disabled :                "
    /usr/sbin/selinuxenabled   && echo "[FAULT]" || echo "[OK]"
endif
if (`uname` == Linux) then
    echo "iptables service must be down or uninstalled to prevent network problems" > $info
    straight "Checkin IPTables down :                    "
    /sbin/service iptables status >& $info  && echo "[WARNING]" || echo "[OK]"
    straight "IPTables does not start at boot :          "
    /sbin/chkconfig iptables --list |& grep "on" >& $info  && echo "[WARNING]" || echo "[OK]"
endif

