#!/usr/bin/perl
##############################################################################
# By BumbleBeeWare.com 2006
# backup files from a webpage
# targz.cgi
##############################################################################
print "Content-Type: text/html\n\n";
# Parse incomming data
&form_parse;
# print the form to get paths
if($ENV{"REQUEST_METHOD"} ne "POST") {&print_form;}
# make sure the directory is valid or tar.gz file will be empty
if (-d $FORM{'backupdir'}){}
else { print "$FORM{'backupdir'} is not a valid directory.";
exit;}
# see if the backup dir is available and writeable
open (BACKUP, ">$FORM{'backupfile'}")||&cantopen;
close (BACKUP);
# use open because most servers wont allow `system` from a webpage
open (TAR, "/bin/tar -cpzf $FORM{'backupfile'} $FORM{'backupdir'}/* |");
close(TAR);
# print response
print "Backup Completed of $FORM{'backupdir'}
\n";
print "The backup file is $FORM{'backupfile'}
\n";
sub form_parse {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}}
sub print_form {
print "
This program will allow you to backup files or directories in a tar.gz format. |