Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/sharedra...
File: autosusprunner.sh
#!/bin/bash
[0] Fix | Delete
# Shared RADS Tools, written by Erik Soroka (eriks@imhadmin.net, ext 834)
[1] Fix | Delete
# Addition by Vanessa V. 5/12/11
[2] Fix | Delete
# this script gets executed by crontab to suspend accounts scheduled from RADS tool
[3] Fix | Delete
[4] Fix | Delete
FAILED=0
[5] Fix | Delete
[6] Fix | Delete
NOW=$(date +%s)
[7] Fix | Delete
[8] Fix | Delete
# Pull a list of users
[9] Fix | Delete
for CURRENTUSER in $(/bin/ls -A /opt/sharedrads/autosuspend)
[10] Fix | Delete
do
[11] Fix | Delete
if [ -z "$CURRENTUSER" ]; then
[12] Fix | Delete
echo
[13] Fix | Delete
echo "* ERROR: Could not find any accounts pending suspension, exiting."
[14] Fix | Delete
echo
[15] Fix | Delete
exit 1
[16] Fix | Delete
else
[17] Fix | Delete
SUSPTIME=$(cat /opt/sharedrads/autosuspend/$CURRENTUSER |awk '{print $1}')
[18] Fix | Delete
[19] Fix | Delete
if [ "$NOW" -ge "$SUSPTIME" ];then
[20] Fix | Delete
SUSPREASON=$(cat /opt/sharedrads/autosuspend/$CURRENTUSER |awk '{print $2}')
[21] Fix | Delete
TOSUSPEND="$TOSUSPEND $CURRENTUSER"
[22] Fix | Delete
fi
[23] Fix | Delete
fi
[24] Fix | Delete
done
[25] Fix | Delete
unset CURRENTUSER
[26] Fix | Delete
if [ ! -z "$TOSUSPEND" ];then
[27] Fix | Delete
for CURRENTUSER in $TOSUSPEND
[28] Fix | Delete
do
[29] Fix | Delete
[30] Fix | Delete
# Check for missing duration or reason
[31] Fix | Delete
if [[ -z "$SUSPTIME" ]] || [[ -z "$SUSPREASON" ]]; then
[32] Fix | Delete
MSG="cannot determine susp time and/or reason"
[33] Fix | Delete
/opt/sharedrads/suspend_user $CURRENTUSER --info --invoked-by "$0" -r '-' -c "$MSG"
[34] Fix | Delete
echo "ERROR: Cannot autosuspend $CURRENTUSER - $MSG" | mail -s "[Autosuspend failure] $CURRENTUSER `hostname -s`" reclamations@imhadmin.net
[35] Fix | Delete
rm -f /opt/sharedrads/autosuspend/$CURRENTUSER
[36] Fix | Delete
exit 1
[37] Fix | Delete
fi
[38] Fix | Delete
[39] Fix | Delete
# Check if the user still exists or is already suspended
[40] Fix | Delete
VALIDUSER=MAYBE
[41] Fix | Delete
/usr/bin/id $CURRENTUSER || VALIDUSER=0
[42] Fix | Delete
[43] Fix | Delete
if [ "$VALIDUSER" = "0" ]; then
[44] Fix | Delete
MSG="Cannot process auto-suspension for $CURRENTUSER because they don't appear to exist"
[45] Fix | Delete
/opt/sharedrads/suspend_user $CURRENTUSER --info --invoked-by "$0" -r '-' -c "$MSG"
[46] Fix | Delete
rm -f /opt/sharedrads/autosuspend/$CURRENTUSER
[47] Fix | Delete
exit 1
[48] Fix | Delete
[49] Fix | Delete
elif [ -f /var/cpanel/suspended/$CURRENTUSER ];then
[50] Fix | Delete
MSG="Cannot process auto-suspension for $CURRENTUSER because they already appear to be suspended"
[51] Fix | Delete
/opt/sharedrads/suspend_user $CURRENTUSER --info --invoked-by "$0" -r '-' -c "$MSG"
[52] Fix | Delete
rm -f /opt/sharedrads/autosuspend/$CURRENTUSER
[53] Fix | Delete
exit 1
[54] Fix | Delete
fi
[55] Fix | Delete
[56] Fix | Delete
# if the reason is a move and the user's domains are pointed here, send an alert
[57] Fix | Delete
if echo "$SUSPREASON" | egrep [mM]ove >/dev/null;then
[58] Fix | Delete
domainlist=$(egrep ": ${CURRENTUSER}$" /etc/userdomains | cut -d: -f1)
[59] Fix | Delete
userFails=()
[60] Fix | Delete
for domain in $domainlist
[61] Fix | Delete
do
[62] Fix | Delete
AREC=$(dig +short $domain |head -1 |awk '{print $1'} )
[63] Fix | Delete
MXREC=$(dig +short $(dig +short $domain MX |awk '{print $2}' | tail -1 |awk '{print $1}') |tail -1 )
[64] Fix | Delete
if [ ! -z $AREC ];then
[65] Fix | Delete
if grep $AREC /etc/ips >/dev/null || [[ "$AREC" == "$(cat /var/cpanel/mainip)" ]]; then
[66] Fix | Delete
userFails+=( "\n$domain: (A) still pointed to the server" )
[67] Fix | Delete
rm -f /opt/sharedrads/autosuspend/$CURRENTUSER
[68] Fix | Delete
ERROR=1
[69] Fix | Delete
fi
[70] Fix | Delete
fi
[71] Fix | Delete
[72] Fix | Delete
if [ ! -z $MXREC ];then
[73] Fix | Delete
if grep $MXREC /etc/ips >/dev/null || [[ "$MXREC" == "$(cat /var/cpanel/mainip |head -1)" ]]; then
[74] Fix | Delete
userFails+=( "\n$domain: (MX) still pointed to the server" )
[75] Fix | Delete
rm -f /opt/sharedrads/autosuspend/$CURRENTUSER
[76] Fix | Delete
ERROR=1
[77] Fix | Delete
fi
[78] Fix | Delete
fi
[79] Fix | Delete
done
[80] Fix | Delete
if [ ${#userFails[@]} -gt 0 ]; then
[81] Fix | Delete
echo -e "${userFails[@]}" > /opt/sharedrads/failsuspend/$CURRENTUSER
[82] Fix | Delete
fi
[83] Fix | Delete
fi
[84] Fix | Delete
[85] Fix | Delete
if [ "$ERROR" != "1" ];then
[86] Fix | Delete
MSG="Scheduled suspension for $CURRENTUSER has been initiated"
[87] Fix | Delete
/opt/sharedrads/suspend_user $CURRENTUSER -r $SUSPREASON -c "$MSG"
[88] Fix | Delete
if [ "$?" -eq 0 ] && [ -f /var/cpanel/suspended/$CURRENTUSER ] ; then
[89] Fix | Delete
rm -f /opt/sharedrads/autosuspend/$CURRENTUSER
[90] Fix | Delete
fi
[91] Fix | Delete
fi
[92] Fix | Delete
done
[93] Fix | Delete
fi
[94] Fix | Delete
## EOF ##
[95] Fix | Delete
[96] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function