File: //proc/self/root/scripts.20110531.215904.25158/oldaddoncgi2cpaddon
#!/usr/bin/perl
# cpanel - oldaddoncgi2cpaddon 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::AccessIds ();
use Cpanel; #issafe
use Cpanel::cPAddons; #issafe
use Cpanel::cPAddons::ConvertData; #issafe
my $user = $ARGV[0] || '';
my $aoname = lc $ARGV[1] || '';
my $aopath = $ARGV[2] || '';
my $quiet = $ARGV[3] || 0;
if ( !$user && -t STDIN ) {
print 'What user do you want to fix up? : ';
$user = <STDIN>;
chomp $user;
}
die 'Please supply a user' if !$user;
die 'I do not know what that addon is' if ( $aoname
&& !exists $Cpanel::cPAddons::ConvertData::aoi{$aoname} ); #issafe
my $cp = Cpanel->new();
$cp->initcp($user);
die "Invalid User" if ( $Cpanel::user ne $user ); #issafe
Cpanel::AccessIds::setuids($user);
chdir $Cpanel::homedir or die "Could not chdir into $Cpanel::homedir: $!"; #issafe
if ( !-d "$Cpanel::homedir/.cpaddons/" ) { #issafe
mkdir "$Cpanel::homedir/.cpaddons/" or die "Could not make $Cpanel::homedir/.cpaddons/: $!"; #issafe
chown( ( getpwnam($Cpanel::user) )[ 2, 3 ], "$Cpanel::homedir/.cpaddons" ) or warn; #issafe
}
my @addons = $aoname ? ($aoname) : sort keys %Cpanel::cPAddons::ConvertData::aoi; #issafe
for (@addons) {
if ( $Cpanel::cPAddons::ConvertData::aoi{$_}->{'noconvert'} ) { #issafe
my $name = $Cpanel::cPAddons::ConvertData::aoi{$_}->{'convert'}{'name'}; #issafe
if ( -e $Cpanel::cPAddons::ConvertData::aoi{$_}->{'convert'}{'dotfile'} ) { #issafe
print "!!!! Note: $name conversion can not be done :\n" . "\t1) install a new $name via the new addon interface\n" . "\t2) import the database from the old $name\n\t3) remove" . " the old installation via the old addon interface\n";
}
else {
print "No $name Installs to fix up.\n" unless $quiet;
}
}
else {
convert( $Cpanel::cPAddons::ConvertData::aoi{$_}->{'convert'} ); #issafe
}
}
###############
## functions ##
###############
sub register {
my ( $hr, $rewrite_ref, $name, $quiet ) = @_;
my $num = 0;
while ( -e "./.cpaddons/$hr->{'addon'}.$num" ) {
$num++;
}
$hr->{'registry'} = "$hr->{'addon'}.$num";
if ( Cpanel::cPAddons::_write_cache( "./.cpaddons/$hr->{'registry'}", $hr ) ) { #issafe
print "$hr->{registry} $hr->{installpath} successfully fixed up!\n"
unless $quiet;
}
else {
warn "Could not store info for new $name system: $!";
${$rewrite_ref} .= "$hr->{'installpath'} $hr->{'mysql_user_post'} $hr->{'version'}\n";
}
}
sub convert {
my $h = shift;
print "Starting $h->{'name'} $aopath...\n" unless $quiet;
if ( -e "./$h->{'dotfile'}" ) {
open AOR, "./$h->{'dotfile'}" or die "Could not open ./$h->{'dotfile'}: $!";
my @installs = <AOR>;
close AOR;
my $rewrite = '';
for (@installs) {
chomp;
next if !$_;
my ( $dir, $dbp, $ver ) = split /\s+/;
$dbp = '' if !defined $dbp;
$ver = '' if !defined $ver;
if ( $aopath && $dir ne $aopath ) {
print "Skipping $dir since its not $aopath\n" unless $quiet;
$rewrite .= "$dir $dbp $ver\n";
next;
}
if ( $ver !~ m/^\Q$h->{'version'}\E\-?/ ) {
$rewrite .= "$dir $dbp $ver\n";
print "Skipping $dir since its not version $h->{'version'}\n" unless $quiet;
next;
}
my $aohr = $h->{'handler'}->( $dir, $dbp, $ver, \$rewrite );
if ( ref $aohr eq 'HASH' ) {
if ( !%{$aohr} ) {
warn "Convert hash is empty!";
$rewrite .= "$dir $dbp $ver\n" if $rewrite !~ m/^$dir $dbp $ver\n/;
}
else {
register( $aohr, \$rewrite, $h->{'name'}, $quiet );
}
}
else {
warn "handler did not return a hashref!";
}
}
open AOW, '>', "./$h->{dotfile}" or die "Could not open ./$h->{dotfile}: $!";
print AOW $rewrite;
close AOW;
if ( -z "./$h->{'dotfile'}" ) {
unlink "./$h->{'dotfile'}" or die "Could not remove ./$h->{dotfile}: $!";
}
else {
warn "./$h->{'dotfile'} not removed since there was some installs" . ' that did not get fixed up right.';
}
}
else {
print "No $h->{'name'} Installs to fix up.\n" unless $quiet;
}
}