# .bashrc

# User specific aliases and functions

#alias rm='rm -i'
#alias cp='cp -i'
#alias mv='mv -i'

# Source global definitions
#if [ -f /etc/bashrc ]; then
#       . /etc/bashrc
#fi


######CUSTOM NATIVE BASHRC 

# .bashrc
if [ $(expr index "$-" i) -eq 0 ]; then
        return
fi
# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

#SYSINFO
sysinfo() {
    echo '[===SYSTEM BUILD===]' 
    uname -a 

    echo '[===LANGUAGE HANDLERS===]' 
    /usr/local/cpanel/bin/rebuild_phpconf --current 
    
    echo '[===PHP CONFIG===]' 
    egrep -i "(disable_fun)"  /usr/local/lib/php.ini | sed 's/;//' 
    
    echo '[===FIREWALL STATUS===]' 
    egrep "(SMTP_BLOCK|SMTP_ALLOWLOCAL|SMTP_PORTS)[[:space:]]?=" /etc/csf/csf.conf 
    csf -v 
    
    echo '[===EMAIL STATUS===]' 
    echo Emails per Hour: $(cat /var/cpanel/maxemailsperhour) 
    echo Emails in Queue: $(exim -bpc) 
    echo '[===RESOURCE ALLOCATION===]' 
    OUT=$(/usr/local/cpanel/bin/dcpumonview | grep -v Top | sed -e 's#<[^>]*># #g' | while read i ; do NF=`echo $i | awk {'print NF'}` ; if [[ "$NF" == "5" ]] ; then USER=`echo $i | awk '{print $1}'`; OWNER=`grep -e "^OWNER=" /var/cpanel/users/$USER | cut -d= -f2` ; echo "$OWNER $i"; fi ; done) ; (echo "USER CPU" ; echo "$OUT" | sort -nrk4 | awk '{print $2,$4}' | head -5) | column -t ; echo; (echo -e "USER MEMORY" ; echo "$OUT" | sort -nrk5 | awk '{print $2,$5}' | head -5) | column -t 
    
    echo '[===ESTABLISHED CONNECTIONS===]' 
    PORTS=([80]=Apache [110]=POP3 [143]=IMAP [25]=SMTP [26]=SMTP [21]=FTP) 
    netstat -plan > "$INSTALLDIR"/stats.txt 
    for port in ${!PORTS[*]} 
    do 
        echo "$(tput bold)${PORTS[$port]}($port):$(tput sgr0)" 
        grep $port "$INSTALLDIR"/stats.txt | awk {'print $5'} | grep -Po "\d{1,3}(?:\.\d{1,3}){3}" | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -c | sort -nk 1 | grep -v "0.0.0.0" | tail -5 | awk '{ if ( $1 > 35 ) { printf "\033[1;31m" } else if ( $1 > 25 ) { printf "\033[1;33m" } else { printf "\033[1;32m" } ; print " ", $1, "\033[0;39m", $2 }'
    done; 
    rm -f "$INSTALLDIR"/stats.txt 
    
    echo '[===CONNECTIONS BY DOMAIN===]'
    lynx -dump -width=200 localhost/whm-server-status | grep 'POST\|GET' | awk '{print $12}' | sort | uniq -c 
    
    echo '[===DISK ALLOCATION===]' 
    df -h 

    echo '[===INODE AUDIT===]' 
    cat /etc/domainusers | cut -f1 -d: | sort -nk1 | while read USER; do quota -s $USER; done | grep '[0-9]k' -B 2 | grep -v "-" | grep '[0-9]k' -B 2 
    
    echo '[===EXCLUDED USERS===]' 
    cat /etc/cpbackup-userskip.conf 
    screen -ls 
    cat /etc/cpspamd.conf
}

pwnmail() {
    if [ -z "$1" ]; then
        echo "Usage: pwnmail STRING|frozen|bounces"
        return
    fi

    if [ "$1" == "frozen" ];then
        exiqgrep -z -i | xargs exim -Mrm
        return
    fi

    if [ "$1" == "bounces" ];then
        exim -bp | grep '<>' | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash
        return
    fi

    exim -bp | grep -B1 "$1" | grep '<.*>' | awk '{print $3}' | while read line; do exim -Mrm $line; done
}

rdnslist() {
    IPs=($(ifconfig | grep 'inet addr' | awk '{print $2}'| sed 's#addr:##g' | grep -v 127.0.0.1 | sed 's/^/ /' | tr '\n' ' '))
    index=1

    for ip in ${IPs[@]};do
        echo "$index.) $ip ----> $(host $ip | cut -d' ' -f5 | sed 's/.$//')"
        index=$[ $index + 1 ]
    done
}
