Tag Archives: WHM Cpanel

Quick Quota Calculator for Cpanel Users

To get an instant view of the diskspace being used by each Cpanel user account home directory, I created this little script. Thanks to Spiral for some pointers on getting the cleaned account list.

#!/bin/bash
#
CPUSERS=`/bin/ls -- /var/cpanel/users | /bin/grep -v "\.\|cpanel\|root\|mysql\|nobody"`
TOT=1
for CPUSER in $CPUSERS; do
   CPHOME="$(/bin/grep "${CPUSER}:" /etc/passwd | cut -d':' -f6)"
   NEWACC="`/usr/bin/du -m --summarize $CPHOME`"
   S="`printf \"%03d\" $(echo $NEWACC | awk '{print $1}')`"
   let "TOT=$TOT+$(echo $NEWACC | awk '{print $1}')/1"
   ACCSUM=$ACCSUM"\n"$S" "$CPHOME
done
echo -e $ACCSUM | sort
echo $TOT

As always, do not test in a production environment!

Simple change detector for cpanel template files

OK, in answer to requests, here is a simple bash script to check any file for changes. It could have been done with MD5 hashes, but it’s probably not necessary (overkill).

Just copy the file you want to check and rename it with a different extension (e.g. .check)

Then just run the following script under a crontab entry – probably best a short while after upcp is run.

#!/bin/bash
COMPARE="`diff --brief /usr/local/cpanel/etc/httptemplates/apache2_2/default /usr/local/cpanel/etc/httptemplates/apache2_2/default.check`"
if [ ${#COMPARE} -gt 0 ]; then
   echo "There was a change found in /usr/local/cpanel/etc/httptemplates/apache2_2/default" | /bin/mail -s "Changes in Cpanel Templates Detected `date`" santfiles@mac.com
fi

If the files are the same then diff should return nothing, so we just check for a return value that is greater than 0.

Of course, if you happen to have CSF and LFD installed, then there is no need for any of this – just set up a File watch. (making sure you set LF_DIRWATCH_FILE to a value other than zero to make sure your watched files and directories are actually being watched!)

As always – test test, and test again before using anything here in a production environment!

Applying RewriteCond to Multiple RewriteRule in .htaccess

Just a quick hints and tips update for today. On a number of my sites I have been using mod_rewrite to produce SEO friendly URLs. e.g. :

mysite.com/widgets/my-big-widget

instead of something like:

mysite.com/index.php?cat=4&function=show&prod=456

This is done using RewriteCond and RewriteRule statements in .htaccess. However, normally RewriteCond only applies to the RewriteRule immediately following it. This means we end up with horrible repetitive blocks of code in our .htaccess files. In this article I’ll show you how to rationalise this problem and shorten your code! Read More…

WHM/Cpanel Copy Packages and Features

WHM tips are coming thick and fast this week! This time I came across the problem of quickly creating a copy of an existing WHM Package or Feature List. These are normally managed in the area:

 Main >> Packages

Which is fine if you are starting from scratch, but what if you want to create a new Package, or Feature List based on a pre-existing one? Going through all those check boxes is a royal pain! Well, it turns out it’s pretty simples! Read On… Read More…

WHM/Cpanel per-user php.ini under Apache 2.x and suPHP

OK, time for another delve into the underbelly of WHM, and a short lesson in how to achieve something which seems so poorly covered (although Cpanel, to their credit have started to explain things a little more clearly) elsewhere, especially for folks who may not be uber-geeks (I make no such claim!).

Very often we want to tighten php.ini up to make our servers as secure as possible – but then there is always going to be a few accounts where for various reasons, you want to bend the rules. Well, now you can set up your WHM/Cpanel server with a central php.ni and yet allow selected users the ability to use a customised php.ini, managed and controlled by YOU! Read More…

Adding multiple forwarders quickly in Cpanel/WHM

I often have to add several forwarders at a time to various accounts, and I thought I would just share this little tip for anyone who is doing things the hard way via the control panel.

The forwarders and default routing instructions are usually stored in a directory /etc/valiases

Each domain has a file, which contains it’s routing information, the format of the file is generally:

sourceaddress@thisdomain.co.uk: destination@otherdomain.co.uk
*: :fail: No such user here

The last line sorts out the default routing. The asterisk representing a wildcard address, the destination being :fail: and the failure message returned at SMTP time is “No such user here”.

You can add as many lines as you wish using the editor of your choice. Enjoy!