Current File : //proc/3/cwd/scripts/postrestoreacct |
#!/bin/bash
# cPanel script hook for account restorations
# Documentation: http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/ScriptHooks
# Vanessa V InMotion Hosting 1/23/12
# order of passed variables:
USER=$1
OLDUSER=$2
DOMAIN=$3
HOMEDIR=$4
# Not like this script would be run by itself, but prevent it from doing so (just in case)
if [ $# -lt 3 ];then
echo "This script can only be executed as a hook to /scripts/restorepkg"
exit 1
fi
##################################################################################################
# Custom PHP version check
# This will check the users for custom PHP handlers that are not supported on the current server
##################################################################################################
echo
echo "Checking for custom PHP handlers"
# Check first to see if the user has a home .htaccess with a PHP handler inside
if egrep "^AddHandler application/x-httpd-php5[0-9]" $HOMEDIR/.htaccess >/dev/null ; then
customphp=1
phpver=$(egrep "^AddHandler application/x-httpd-php[0-9][0-9]" $HOMEDIR/.htaccess | head -1 | awk '{print $2}' | cut -d- -f3)
echo "User has a custom PHP handler: $phpver"
# This handler has to be custom, so check that it's installed...
if [ ! -s /usr/local/apache/conf/$phpver.conf ];then
echo "Used PHP handler is not installed...switching to system default"
# Remove the handler lines in .htaccess
sed '/Use PHP/d' -i $HOMEDIR/.htaccess
sed '/^AddHandler application\/x-httpd-php5[0-9]/d' -i $HOMEDIR/.htaccess
# Is this .htaccess now empty? If so, remove it!
if [ ! -s $HOMEDIR/.htaccess ]; then
rm -f $HOMEDIR/.htaccess
fi
fi
else
customphp=0
fi
##################################################################################################
# PHP.ini check
# This will check the user's custom php.ini for common issues that caused error_log
##################################################################################################
# If the user has a custom php.ini, try to fix it if it's incorrect
if [ -s $HOMEDIR/public_html/php.ini ];then
# Fix the extension directories, if different
realextdir=$($(which php-config) --extension-dir)
oldextdir=$(cat $HOMEDIR/public_html/php.ini |egrep ^extension_dir | head -1 | cut -d= -f2)
if [ "$realextdir" != "$oldextdir" ] && [ ! -d "$oldextdir" ] ;then
echo "PHP extension directory ($oldextdir) is incorrect...fixing"
perl -i -pe "s<$oldextdir><$realextdir>g" $HOMEDIR/public_html/php.ini
fi
# Check if we're loading any unsupported modules
extlist=$(egrep "^extension=" $HOMEDIR/public_html/php.ini | cut -d= -f2 | sed 's/\"//g')
for ext in $extlist
do
if [ ! -f "$realextdir/$ext" ];then
echo "$ext does not exist...disabling"
sed "s/extension=$ext/;extension=$ext/g" -i $HOMEDIR/public_html/php.ini
fi
done
# Remove preceding forward slashes from extension names (PHP 5.3 does not like this)
sed 's/^extension="\//^extension="/g' -i $HOMEDIR/public_html/php.ini
sed 's/^extension=\//^extension=/g' -i $HOMEDIR/public_html/php.ini
# Fix the zend extensions
zendextlist=$(grep zend_extension $HOMEDIR/public_html/php.ini | cut -d= -f2 | sed 's/\"//g')
for zendext in $zendextlist
do
if [ ! -f "$zendext" ];then
echo "$zendext does not exist...disabling"
sed '/zend_extension/d' -i $HOMEDIR/public_html/php.ini
fi
done
if [ "$customphp" == "0" ];then
#sed '/zend_extension/d' -i $HOMEDIR/public_html/php.ini
sed 's/zend_extension/;zend_extension/g' -i $HOMEDIR/public_html/php.ini
grep zend_extension= /usr/local/lib/php.ini >> $HOMEDIR/public_html/php.ini
fi
fi
exit 0;