#!/usr/bin/perl # You may need to change this path to /usr/local/bin/perl #WHMADDON:addonupdates:Backup Drive mount/unmount $mailprog = "/usr/sbin/sendmail"; #************************************************************** # # Script to mount / unmount backup drive from WHM: addon_PWSbackupdrive V3.5 # # Written by: # Premier Website Solutions - http://www.premierwebsitesolutions.com # Created - in 2003 (V1.0) # Modified - February 28, 2004 (V2.0) # - combined seperate mount and unmount scripts into one # - edited to be easily modified for use by others # Modified - March 2, 2004 (V2.01) # - added warning at start of actual code # Modified - April 4, 2005 (V3.0) # - modified to be a WHM addon script # (no customization is needed to the WHM skin) # - modified to automatically detect and show mount condition and let you reverse it # Modified - April 5, 2005 (V3.1) # - added option whether or not to allow resellers to use the script # Last Modified - November 4, 2006 (V3.5) # - changed method of limiting user access # - now allows resellers with root privileges to use script # # # Provide the path to the mtab and fstab files below, and the sender and sendto email # addresses for the email that will be sent when an action is done, then upload # this script to your servers WHM cgi folder. (/usr/local/cpanel/whostmgr/docroot/cgi) # A "Backup Drive mount/unmount" link will automatically appear under "Add-ons" in your WHM options. # Ownership and permissions should be root:root, and 0700, unless you want # to enable wheel users to use it, then it would be root:wheel 0770. # # To work as an add-on script, the file name MUST begin with addon_ # You can change the rest if you want, but DO NOT remove that. # # # BE VERY CAREFUL NOT TO MOUNT YOUR BACKUP DRIVE JUST BEFORE, OR DURING THE # AUTOMATIC BACKUP PROCESS AND WHEN YOU DO MOUNT YOUR BACKUP DRIVE TO LOOK AT # IT, BE SURE TO UNMOUNT IT AFTERWARDS # # # 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: # #************************************************************** # Do you want all resellers to have access to this script, or only those with root access? # If you put $allusers = "y", the script will function for root and all resellers. # Any other value, and only root, or resellers with root privileges, will be able to use it. $allusers = "y"; # Message to display to those who do not have permission to use this script. # If $allusers is set to anything except y, this is what resellers will see if they # click on the link to this script. # Put anything you want between the ~ characters except for the ~ character. $permission_denied_message = qq~Sorry, this function is only available to users with root access.~; # If you want to be emailed when the drive's mount is changed, put your email address here. # If you use spamassassin, you should include a name, like this: # $sendto_email = 'me '; $sendto_email = ''; # This is the sender for the email if you do include a sendto_email. # Change it if you wish. $sender_email = 'Mike '; # Backup drive/partition name $backupname = "backup"; # Path to your mtab file # Used to find if drive/partition is mounted or unmounted $mtabfile = "/etc/mtab"; #------------------------------------------------------------------- #------------------------------------------------------------------- # UNLESS YOU KNOW CGI, DO NOT EDIT ANYTHING BELOW HERE # Feel free to study the code, but alterations are at your own risk #------------------------------------------------------------------- #------------------------------------------------------------------- print "Content-type: text/html\r\n\r\n"; BEGIN { push(@INC,"/usr/local/cpanel"); push(@INC,"/usr/local/cpanel/whostmgr/docroot/cgi"); } use whmlib; if (!$ACL{all} && $allusers ne "y") { defheader("Addon Scripts"); print "$permission_denied_message\n"; exit(); } $input = $ENV{QUERY_STRING}; if ($input eq "mount") {&mount;} elsif ($input eq "unmount") {&unmount;} else {&readmount;} sub readmount { $mountcase = "unmounted"; open (datafile,"$mtabfile") || &error("Unable to open the $mtabfile file"); @mlines = ; close (datafile); foreach $_ (@mlines) { if ($_ =~ /$backupname/) { $mountcase = "mounted"; last; } } if ($mountcase eq "mounted") { print qq~Backup drive is currently $mountcase. unmount (umount) backup drive~; } elsif ($mountcase eq "unmounted") { print qq~Backup drive is currently $mountcase. mount backup drive~; } else { print qq~There appears to be some kind of error. We can't determine the mount case. Please make sure the variables at the start of the script are correct. If they are, please contact the script writer or the person who provided this script.~; } } sub mount { system("mount /$backupname"); print "\nBackup mounted\n\n"; &email; } sub unmount { system("umount /$backupname"); print "\nBackup unmounted\n\n"; &email; } sub email { $operation = $input . "ed"; if ($sendto_email) { # Open The Mail Program open(SENDMAIL,"|$mailprog -t"); print SENDMAIL "Content-Type: text/html; charset=iso-8859-1\n"; print SENDMAIL "To: $sendto_email\n"; print SENDMAIL "From: $sender_email\n"; print SENDMAIL "Subject: backup was $operation\n\n"; print SENDMAIL "The backup drive was $operation.\n"; close (SENDMAIL); } exit; }