#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl
$mailprog = "/usr/sbin/sendmail";
#**************************************************************
#
# Script to monitor cpbackup script customizations: watchcpbackup V1.1
#
# Written by:
# Premier Website Solutions -
http://www.premierwebsitesolutions.com
# Created - in 2003 (V1.0)
# Modified - September 12, 2004 (V1.1)
# - minor modifications to make usable by others
#
#
# Set a few variables below and upload this script to anywhere on your server,
# then set a cron job to run the script every hour. I put mine in a subfolder
# of the servers scripts folder. (/scripts/custom)
#
# To set the cronjob, in shell, type crontab -e, then enter what's between the quotes
# on the following line as a new line in your cron listings:
# "0 * * * * /scripts/custom/watchcpbackup.cgi"
#
# Ownership and permissions of the script should be root:root, and 0700.
#
# This script only needs to run after a cpanel upgrade, so you could set
# the cron job to run it 1 hour after upcp runs, but then if you change
# when upcp runs, you will need to change this also. This script is fast,
# so it's easier to just run it every hour.
#
# **** Using this script ****
# --------------------------------------------------------------------------------------
# |To use this script, you need to make a copy of the real cpbackup script and call it |
# |cpbackupunedited, then after your customizations, make a copy of your custom one and |
# |call it cpbackupedited. These copies need to be in the same directory as cpbackup. |
# | |
# |What this script does is compare your custom cpbackup script to a copy of it. |
# |If a cpanel update changes the cpbackup script, this script will notice the change. |
# | |
# |Now the fun part. Many upgrades only change the cpbackup script back to what it was |
# |originally. If it's changed, this script compares the new cpbackup to a copy of the |
# |original one. If the update merely wrote the original one back, it would match the |
# |copy. This script would then take the copy of your custom one and reuse it. Now, if |
# |the update altered the script, you would be emailed and told that your customizations |
# |are lost and that you will need to redo them. The script does tell you where changes |
# |were made to help with reapplying your customizations. |
# | |
# |I customized my cpbackup script over a year ago and have only had to redo the changes |
# |maybe half a dozen times. |
# --------------------------------------------------------------------------------------
#
#
# Registered users of this script will be notified of any future updates.
# If you registered this copy with me, put your email here for future reference.
# This copy is registered to:
#
#**************************************************************
# This is where the email will be sent when a change is detected.
# If you use spamassassin, you should include a name, like this:
# $sendto_email = 'YourName <you@youremail.com>';
$sendto_email = 'YourName <you@youremail.com>';
# This is the sender for the email message.
# Change it if you wish.
$sender_email = 'YourName <you@youremail.com>';
# This is where your cpbackup file is located.
# It shouldn't need to be changed.
$path = "/scripts";
$diff1 = system("cmp $path/cpbackup $path/cpbackupedited");
if ($diff1 eq "0") {
exit;
}
else {
$diff2 = system("cmp $path/cpbackup $path/cpbackupunedited");
}
if ($diff2 eq "0") {
system("cp -f $path/cpbackupedited $path/cpbackup");
# Open The Mail Program
open(MAIL,"|$mailprog -t");
print MAIL "Content-Type: text/html; charset=iso-8859-1\n";
print MAIL "To: $sendto_email\n";
print MAIL "From: $sender_email\n";
print MAIL "Subject: cpbackup file changed and restored\n";
print MAIL "<b>The cpbackup file was changed back to the original and has been automatically replaced with the edited version.</b><br><br>\n\n";
close (MAIL);
}
if ($diff2 ne "0") {
# Open The Mail Program
open(MAIL,"|$mailprog -t");
print MAIL "Content-Type: text/html; charset=iso-8859-1\n";
print MAIL "To: $sendto_email\n";
print MAIL "From: $sender_email\n";
print MAIL "Subject: cpbackup file changed\n";
print MAIL "<b>The cpbackup file has been changed and no longer matches the original file. You will need to redo your custom work.</b><br><br>\n\n";
close (MAIL);
}