#!/bin/bash
>/root/details.txt
log_file=/root/details.txt
echo -e "=== General  ===\n\n==== Server Information  ====\n\nHostname : `hostname`<br>Main IP : `hostname -i`<br>Purpose: Web Hosting<br>" >> $log_file;
echo `hostname ` | grep -E "(elinuxservers.com|dns-nac-zone.com|livingdot.com)"
if [ $? -eq 0 ]
then 
	echo "Type : Shared<br>" >> $log_file;
else 
	echo "Type : Dedicated<br>" >> $log_file;
fi
echo `arch` | grep "x86_64"
if [ $? -eq 0 ]
then 
	echo "Architecture : 64 bits<br>" >> $log_file;
else
	echo "Architecture : 32 bits<br>" >> $log_file;
fi
echo -e "OS : `cat /etc/redhat-release` <br>Control Panel: Cpanel<br>Data Center:LosAngeles,CA <br>Service Tag: If any<br> \n" >> $log_file;
echo -e "=== Hardware Details  ===\n\n==== Processor  ====\n\nProcessor Model: `cat /proc/cpuinfo  | grep "model name" | cut -d: -f2 | head -1`<br>\n<pre>flags : ` cat /proc/cpuinfo  | grep flags | cut -d: -f2 | head -1`</pre>\n" >> $log_file;
echo -e "==== Memory  ====\n" >> $log_file
mem=`free -m |grep Mem|awk '{print $2}'`;
swap=`free -m | awk '{print $2}' | tail -1`
echo -e "RAM : ${mem} M<br>Swap : ${swap} M\n" >> $log_file
df -h | grep -q "/vz";
out=`echo $?`;
echo -e "==== Disks  ====\n\n<pre>`fdisk -l `</pre>\n<pre>\n`cat /etc/fstab`</pre>\n<pre>\n`df -h`</pre>\n\n==== lspci  ====\n\n<pre>`lspci`</pre>\n" >>$log_file;
echo -e "==== Kernel  ====\n\nKernel:`uname -r`<br>\nModules<pre>`lsmod`</pre>\n" >>$log_file;
echo -e "==== Dmidecode ====\n\n<pre>`dmidecode --type 1`</pre>\n" >> $log_file;
echo -e "=== Network Details  ===\n\n==== Ethernet Controllers  ====\n\n<pre>`lspci | grep Ethernet`</pre>\n" >> $log_file;
if [ $out -ne 0 ]; then 
echo -e "==== Name Servers  ====\n\n<pre>`cat /etc/wwwacct.conf | grep NS  | grep -v TTL`</pre>\n" >> $log_file;
fi
echo -e "==== Resolvers  ====\n\n<pre>`cat /etc/resolv.conf | grep nameserver`</pre>\n " >> $log_file;
if [ $out -ne 0 ]; then
echo -e "==== Secondary IPs  ====\n\n<pre>`cat /etc/ips|cut -d: -f1 | perl -lpe'$\=$.%5?$":"\n"'`</pre>\n" >> $log_file;
fi
echo -e "=== RAID Details  ===\n" >> $log_file
raid=`lspci | grep -i raid | awk '{print $5}'`
if [ $raid = "3ware" ]
then
	tw=`which tw_cli`;
        ver=`$tw info | awk '{print $2}' | tail -2 | grep -v "^$"`
        ctrl=`$tw info | awk '{print $1}' | tail -2 | grep -v "^$"`
        echo "RAID Controller&nbsp;: $raid $ver" >> $log_file;
        echo -e "<pre>`$tw info $ctrl`\n</pre>" >> $log_file;
elif [ $raid = "Adaptec" ]
then
        echo "RAID Controller&nbsp;: $raid" >> $log_file
        echo -e "<pre>`/usr/StorMan/arcconf GETCONFIG 1 AL`\n</pre>">> $log_file;
else
	raid=`lspci | grep -i raid | awk '{print $10}'`
	if [ $raid = "MegaRAID" ]; then
		MegaCli64 -AdpAllInfo -aAll
	fi
fi
if [ $out -ne 0 ]; then
echo -e "\n=== Software Details  ===\n\n==== Cpanel  ====\n\nversion : `cat /usr/local/cpanel/version`\n\n==== Http  ====\n\n<pre>`/usr/local/apache/bin/apachectl -V`\n\n">> $log_file;
grep modsec /usr/local/apache/conf/httpd.conf >> /dev/null
if [ $? -eq 0 ]
then
        echo -e "Mod_sec module :Enabled" >> $log_file;
	grep modsec /usr/local/apache/conf/httpd.conf >> $log_file;
else
	echo "Mod_sec module :Not enabled<br>" >> $log_file;
fi
grep LoadModule  /usr/local/apache/conf/modsec2.conf >> /dev/null
if [ $? -eq 0 ]
then 
	echo -e "Mod_sec module version: 2" >> $log_file;
	grep LoadModule  /usr/local/apache/conf/modsec2.conf >> $log_file;
        echo -e "</pre>\n\n" >> $log_file;
else
	echo "Mod_sec module versio :1</pre>\n\n" >> $log_file;
fi
echo -e "==== PHP  ====\n\nVersion : `php -v | grep built`<br> ` /usr/local/cpanel/bin/rebuild_phpconf --current | grep handlers `<br>`/usr/local/cpanel/bin/rebuild_phpconf --current | grep DEFAULT`<br> `/usr/local/cpanel/bin/rebuild_phpconf --current | grep PHP4` <br> ` /usr/local/cpanel/bin/rebuild_phpconf --current | grep PHP5`<br> `/usr/local/cpanel/bin/rebuild_phpconf --current | grep SUEXEC` <br> " >> $log_file;
grep "suPHP_Engine on" /usr/local/apache/conf/php.conf >> /dev/null
if [ $? -eq 0 ]
then 
	echo -e "PHP Compiled as CGI_SUPHP : Yes<br>" >> $log_file;
	grep "suPHP_Engine on" /usr/local/apache/conf/php.conf >> $log_file;
else
	echo -e"PHP Compiled as CGI_SUPHP : No<br>" >> $log_file;
fi
#A=`php --ini | grep Loaded | awk '{print $4}'`
A=`php -i | grep php.ini | grep "/php.ini" | awk '{print $NF}'`;
echo -e "<pre>Php variables:\n `grep "^safe_mode " $A ` \n `grep "^max_execution_time" $A | awk '{print $1, $2, $3}'` \n `grep "^extension_dir" $A ` \n `grep "^register_globals" $A` \n `grep upload_max_filesize $A` \n ` grep allow_url_fopen $A`\n\n" >> $log_file;
echo -e "`php -v`\n" >> $log_file;
echo -e "`php -i | grep configure`</pre>\n" >> $log_file;
echo -e "==== Exim  ====\n\nExim Version: ` rpm -qa | grep exim | cut -d_ -f1`\n" >> $log_file;
echo -e "==== MySQL  ====\n\nMysql version: `mysql -V | cut -d, -f1`\n" >> $log_file;
echo -e "=== Backup Details  ===\n" >>$log_file;
ps -aux | grep cdp | grep -v warning  >> /dev/null
	if [ $? -eq 0 ]
then
	echo  "CDP enabled : Yes" >> $log_file;
else
 	echo "CDP enabled : No" >> $log_file;
fi
B=/etc/cpbackup.conf
var=`grep BACKUPENABLE $B | awk '{print $2}'`;
if [ $var = "yes" ]; then
	echo -e "Backup Enabled : Yes<br>" >> $log_file
	echo -e "Backup Directory : `grep BACKUPDIR $B | awk '{print $2}'`<br>" >> $log_file
	echo -e "Backup Accounts : `grep BACKUPACCTS $B | awk '{print $2}'`<br>" >> $log_file
	echo -e "Backup Files : `grep BACKUPFILES $B | awk '{print $2}'`<br>" >> $log_file
	echo -e "Backup Type : `grep BACKUPTYPE $B | awk '{print $2}'`<br>" >> $log_file
	echo -e "Backup Interval : `grep BACKUPINT $B | awk '{print $2}'`<br>" >> $log_file
	echo -e "Backup Days : `grep BACKUPDAYS $B | awk '{print $2}'`<br>" >> $log_file
	grep BACKUPRETDAILY $B | awk '{print $2}' >> /dev/null
	if [ $? -eq 0 ]
	then
	         echo "Backup Retention Daily : Yes<br>" >> $log_file;
	else
        	echo "Backup Retention Daily : No<br>" >> $log_file;
	fi
	grep BACKUPRETWEEKLY $B | awk '{print $2}' >> /dev/null
	if [ $? -eq 0 ]
	then
        	 echo "Backup Retention Weekly : Yes<br>" >> $log_file;
	else
        	echo "Backup Retention Weekly : No<br>" >> $log_file;
	fi
	grep BACKUPRETMONTHLY $B | awk '{print $2}' >> /dev/null
	if [ $? -eq 0 ]
	then
        	 echo "Backup Retention Monthly : Yes<br>" >> $log_file;
	else
        	echo "Backup Retention Monthly : No<br>" >> $log_file;
	fi
	echo -e "Backup Logs : `grep BACKUPLOGS $B | awk '{print $2}'`<br>">> $log_file
else
	echo -e "Backup Enabled : NO<br>" >> $log_file
fi
fi
echo -e "\n=== Login ===\n">> $log_file;
echo -e "==== SSH ====\nSSH Port: 22<br>SU User:<br>SU Pass:<br>Root Pass:\n">> $log_file;
echo -e "==== DRAC ====\nIP : <br>User : <br>Password : <br>Web interface : https://ipaddress/<br>\n" >> $log_file;
echo -e "=== Bash users ===\n\n<pre>`cat /etc/passwd | grep /bin/bash` </pre>\n" >>$log_file;
echo -e "=== Rebooter ip ===\n<pre></pre>\n">> $log_file;
echo -e "==== Maldet ====\n<pre>1) Full server scan using Maldet (all public_html) -- 
2) Daily cron or Real time monitoring via inotify -- 
3) Configured for email or similar alerts -- 
</pre>\n" >> $log_file;
echo -e "=== Changelog ===\n" >>$log_file;
echo -e "==== Hardware Notes ====\n\n<pre></pre>\n" >> $log_file;
echo -e "==== OS ====\n\n<pre></pre>\n" >>$log_file;
echo -e "==== Services  ====\n\n<pre></pre>\n" >>$log_file; 
echo -e "==== Reboot History ====\n\n<pre>Date & Time : 
Reason : </pre>\n" >> $log_file;
echo "****************************************************************************"
echo "****** Check $log_file for Server details *******"
echo "****************************************************************************"
echo -e "\n ******Please include the IPMI and reboot information in the wiki****** \n\n ************** Check All entries are correctly added in wiki and add it manually if there is any missing entries ****************"
cat /root/details.txt |mail -s "SERVER DETAILS OF `hostname`" l3@ihnetworks.com
