Category Archives: cPanel

cPanel AppConfig for Fantastico

A simple script to populate the configuration file and register Fantastico with the cPanel AppConfig system.

#!/bin/sh

cat > /var/cpanel/apps/addon_fantastico.conf <<EOF
name=addon_fantastico
service=whostmgr
url=/cgi/addon_fantastico.cgi
url2=/cgi/fantastico/index.php
url3=/cgi/fantastico/fantastico.php
user=root
acls=any
displayname=addon_fantastico
EOF

/usr/local/cpanel/bin/register_appconfig /var/cpanel/apps/addon_fantastico.conf

WordPress Mass Update Script

I recently came across an excellent bash to mass update WordPress installs, which was written by Liz Quilty. This script works well, but unfortunately it did require manually setting paths if you are not using /var/www for your installs. Due to the large and varying number of servers I needed this for, I decided to make some changes so the script is slightly more automated and eliminate the need for the end user to edit the script.

These changes include:
– Added –path option to allow script to be ran on a specific path only.
e.g wordpress wpupgrade.sh –path /home/user
– Added a function to check for the existence of /var/www and /home, also validates –path option to insure custom path exists.
– Added a function to check the latest WordPress version via wordpress.org api.
– Script is now broke down into into the following functions.
usercheck
path
version
main
help

Here is my modified version.

wget http://dropdeaddick.com/files/wordpress-upgradeDD.sh
bash wordpress-upgradeDD.sh

Here is the original.

wget http://b.ri.mu/files/wordpress-upgrade.sh
bash wordpress-upgrade.sh

Update Timthumb for All cPanel Users

A simple script to check all cPanel user accounts for timthumb.php(WordPress) and update them to the latest version if needed. Also checks for timthumb being used as thumb.php. Uses check to insure thumb.php is not affected for scripts like joomla, which does not use timthumb.

#! /bin/bash
# Detects and updates timthumb.php to latest version for all cPanel users.
# dropdeaddick.com

latest=`lynx -source http://timthumb.googlecode.com/svn/trunk/timthumb.php |grep "define ('VERSION'" $file |cut -f4 -d"'"`
if [ -z "$latest" ]; then
echo "could not get latest timthumb release, aborting!"
exit 1
fi
for user in `awk -F':' '{ if ($3 > 499) print $0 }' /etc/passwd | grep home | cut -d':' -f1`; do
for file in `find /home*/$user/public_html/ -type f \( -name 'thumb.php' -o -name 'timthumb.php' \) 2>/dev/null | tr ' ' '%'`; do
file=`echo $file | tr '%' ' '`
check=`grep -c "code.google.com/p/timthumb" "$file"`
if [ -z "$check" ]; then
break
fi
if [ "$check" -gt "0" ]; then
version=`grep "define ('VERSION'" "$file" |cut -f4 -d"'"`
if [ "$version" != "$latest" ]; then
echo -e "\e[1;31mWARNING version $version\e[0m updating $file!"
# rm -f $file #delete current file before replacing.
wget -nv -t3 -T3 http://timthumb.googlecode.com/svn/trunk/timthumb.php -O "$file"
chown $user: "$file"
else
echo -e "\e[1;32mOK version $version\e[0m skipping $file"
fi
fi
done
done

cPanel – Fix Ownership of /home/user

I recently had an issue with incorrect ownership of all files under /home/user/ due to mismatched UIDs after a cPanel server restore. The following script took care of this in no time.

echo -e "Checking ownership of /home/user \n"
for i in `ls /var/cpanel/users/`
do
if [ "$i" != "root" ]; then
chown -R $i:$i /home/$i
chown $i:nobody /home/$i/public_html /home/$i/.htpasswds
chown $i:mail /home/$i/etc /home/$i/etc/*/shadow /home/$i/etc/*/passwd
echo $i
fi
done

cPanel Webmail Direct Login Script

A simple and configurable script for direct login to the cPanel webmail applications(Horde, SquirrelMail, RoundCube).

<?php
// Modified version of the standard cPanel login page to allow direct login to a specific webmail application.
// Must set $host , $login_path , and $mail_app, defaults to cPanel proxy subdomains and SquirrelMail
$host = 'example.com';
// Uncomment one of the following to set login URL type

View full script

cPanel Email Filter for IP Range

I recently needed to block a large amount of incoming email via IP range in cPanel for a single account versus blocking the IP range on the entire server. This was accomplished using cPanel’s Account Level Filtering for Mail.

Here is the filter setting using 192.168.0.0/24 as an example.

Rules:
Any Header
matches regex
192\.168\.\d{1,3}\.\d{1,3}

Action:
Discard Message

cpanel mail filter