#! /usr/bin/perl
###########
# cPXfer
# Allows admin to download a remote account's homedir
# http://git.toolbox.hostgator.com/cpxfer/pages/Home/
# http://git.toolbox.hostgator.com/cpxfer/
# Please submit all bug reports at bugs.hostgator.com
#
# (C) 2011 - HostGator.com, LLC
###########
# By Rish

use strict;

my $tmp = "/root/tmp/cpxfer";
my $altered = 0;

if (not exists $ENV{PAR_GLOBAL_TEMP} or $ENV{PAR_GLOBAL_TEMP} =~ m/^\s*$/) {
	if (not -d "$tmp") {
		system("mkdir -p '$tmp'");
		if (not -d "$tmp") {
			print "[!] Failed to create tmp folder: '$tmp'. Aborting!\n";
			exit 1;
		}
		chmod 0755, $tmp;
	}
	$ENV{PAR_GLOBAL_TEMP} = $tmp;
	$altered = 1;
}

if (not (-w $ENV{PAR_GLOBAL_TEMP} and -x $ENV{PAR_GLOBAL_TEMP})) {
	print "[!] '$ENV{PAR_GLOBAL_TEMP}' does not have the proper privileges to run this utility!\n";
	exit 1;
}

my $ret = system("/root/bin/cpxfer.exe", @ARGV);
if ($altered) { delete $ENV{PAR_GLOBAL_TEMP}; }
exit $ret;
