File: //scripts.20110531.215904.25158/restorepkg
#!/usr/bin/perl
# cpanel - restorepkg Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use strict;
use Cpanel::AcctUtils ();
use Cpanel::Usage ();
use Cpanel::Validate::Username ();
my $version = 2.0;
my $skipres = 0;
my $force = 0;
my $override = 0;
my $path = '';
my $ip = 'n';
my %opts = (
'force' => \$force,
'skipres' => \$skipres,
'override' => \$override,
'ip' => \$ip,
);
Cpanel::Usage::wrap_options( \@ARGV, \&usage, \%opts );
my $user = $ARGV[-1];
if ( -e $user ) {
( $user, $path ) = get_user($user);
}
if ( !$force && Cpanel::AcctUtils::accountexists($user) ) {
print "Sorry, the user $user already exists on this system. If you really want to do this run $0 --force $user\n";
exit();
}
if ( !$force && Cpanel::Validate::Username::group_exists( $user ) ) {
print "Sorry, the group $user already exists on this system. If you really want to do this run $0 --force $user\n";
exit;
}
if ( !$user || $user eq '' || !@ARGV ) {
usage();
exit;
}
$ENV{'LONGUSERS'} = 1;
$ENV{'REMOTE_USER'} = 'root';
$ENV{'PKGRESTORE'} = 1;
print qq{cPanel restorepkg $version\n};
print qq{cPanel user: $user\n} if $path;
print qq{Force Mode: } . ( $force ? 'yes' : 'no' ) . "\n";
print qq{Reseller Privs Restore: } . ( $skipres ? 'no' : 'yes' ) . "\n";
print "\n";
my $manual = 1;
my $whm_bin_dir = '/usr/local/cpanel/whostmgr/bin';
my $whm5_bin = -e $whm_bin_dir . '/whostmgr5.pl' ? $whm_bin_dir . '/whostmgr5.pl' : $whm_bin_dir . '/whostmgr5';
system $whm5_bin, 'quickrestore', $user, $skipres, $override, $path, $force, $ip, $manual;
sub usage {
my $prog = $0;
$prog =~ s{^.+/(.+)$}{$1};
print <<EOF;
$prog [--force] [--skipres] [--override] [--ip=(y|n|Custom IP)] -- [cpuser|/path/to/cpuser-file]
To specify a dedicated IP for a restored account, the "--ip" option requires an argument of "y" for yes,
or "n" for no. Additionally, an IP argument may be specified to set the desired dedicated IP.
Security Note: It is recommended that you do not restore a package from an untrusted source.
If you choose to ignore this warning, you should use --skipres to minimize the risk.
EOF
exit;
}
sub get_user {
my ($file) = @_;
my $user = '';
my @parts = split /\//, $file;
$file = pop @parts;
my $path = join '/', @parts;
if ( $file =~ m/^cpmove-(\S+)\.tar(?:\.gz$|$)/ ) {
print "Using cpmove archive\n";
$user = $1;
}
elsif ( $file =~ /^backup-\d+\.\d+\.\d+_\d+\-\d+\-\d+_(\S+)\.tar(?:\.gz$|$)/ ) {
print "Using backup archive\n";
$user = $1;
}
elsif ( $file =~ m/^(\S+)\.tar(?:\.gz$|$)/ ) {
print "Using username archive\n";
$user = $1;
}
elsif ( $file =~ /cpmove-(\S+)\/?$/ ) {
print "Using pre-extracted cpmove file\n";
$user = $1;
}
return ( $user, $path );
}