#!/usr/bin/perl
use strict;
use Carp;
use Socket;
use POSIX();
use File::Basename;
use File::Copy;
use MIME::Base64;
use IPC::Open3;
BEGIN {
push(@INC, dirname($0));
}
use RVSInstaller::Config qw(%InstallConf $NEWLINE $BROWSER $WEBROOT %MONS $INS_PHP_FILE_TYPE $INS_CGI_FILE_TYPE);
my ($ioncObj);
if (-x '/usr/bin/php') {
$ioncObj = RVS_Incube->new(phpexec => '/usr/bin/php');
}
elsif (-x '/usr/local/bin/php') {
$ioncObj = RVS_Incube->new(phpexec => '/usr/local/bin/php');
}
else {
print "Please install PHP first.\n";
exit;
}
if ( !-f "/$ioncObj->{ioncube}->{loaderFilename}") {
print "Find not found /$ioncObj->{ioncube}->{loaderFilename}\n";
$ioncObj->installIoncude();
}
$ioncObj->testLoader();
if (-x $InstallConf{'cpModeConfigPath'}{'phpexecPath'}){
my ($cpioncObj) = RVS_Incube->new(phpexec => $InstallConf{'cpModeConfigPath'}{'phpexecPath'});
if ( !-f "/$cpioncObj->{ioncube}->{loaderFilename}") {
print "Find not found /$cpioncObj->{ioncube}->{loaderFilename}\n";
$cpioncObj->installIoncude();
}
$cpioncObj->testLoader();
}
package RVS_Incube;
use strict;
use Carp;
use IPC::Open3;
sub new{
my $pkg = shift;
my $self;
{
my %hash;
$self = bless(\%hash, $pkg);
}
my $options = {};
$options = _load_options([@_], $options);
$self->{phpexec} = ($options->{phpexec}) ? $options->{phpexec}: '/usr/bin/php';
$self->getIoncubeLoader();
$self->getIoncubePackage();
return $self;
}
sub _load_options{
my $argsref = shift;
my $options = shift;
for (my $x = 0; $x < @{$argsref}; $x += 2) {
$options->{lc(${$argsref}[$x])} = ${$argsref}[($x + 1)];
}
return $options;
}
sub saferun{
my ($printOutput) = shift;
my ( @PROGA ) = @_;
open( WNULL, ">/dev/null" );
open( RNULL, "</dev/null" );
my ( $pid ) = IPC::Open3::open3( "<&RNULL", \*PROG, ">&WNULL", @PROGA ) || do {
my ($warnMsg) = sprintf('%s: [%s]:%s','Error while executing', join( ' ', @PROGA ),$!);
warn($warnMsg);
return;
};
my @output;
while(<PROG>) {
if ($printOutput) {
warn($_);
}
push(@output,$_);
}
close(PROG);
close(RNULL);
close(WNULL);
waitpid( $pid, 0 );
return @output;
}
sub testLoader{
my $self = shift;
my $ext = $self->getExtensionPath();
my ($phpCode);
$phpCode = <<PHPCODE;
if (!extension_loaded('ionCube Loader')) {
\$fdl = preg_replace('#/([^/]+)#', '../', "$ext") . "$self->{ioncube}->{loaderFilename}";
dl(\$fdl);
}
PHPCODE
$phpCode = replacePHPCode($phpCode);
open my $FD, '>', '/tmp/rvsitebuilderinstall_testionc';
print $FD "<?php\n $phpCode \n?>";
close($FD);
my $output = join('', saferun(0, $self->{phpexec} . ' -q /tmp/rvsitebuilderinstall_testionc'));
unlink('/tmp/rvsitebuilderinstall_testionc');
printf("Test ioncube loader with %s : ", $self->{phpexec});
if ($output =~/dl/i) {
print "Failed.\n";
} else {
print "Ok.\n";
}
}
sub getIoncubeLoader{
my $self = shift;
my ($phpCode);
$phpCode = <<PHPCODE;
\$__oc = strtolower(substr(php_uname(),0,3));
\$__ln = "ioncube/ioncube_loader_" . \$__oc . "_" . substr(phpversion(),0,3) . ((\$__oc == "win")?".dll":".so");
echo \$__ln ;
PHPCODE
$phpCode = replacePHPCode($phpCode);
open my $FD, '>', '/tmp/rvsitebuilderinstall_testionc';
print $FD "<?php $phpCode ?>";
close($FD);
my $ioncfiles = join('', saferun(0, $self->{phpexec} . ' -q /tmp/rvsitebuilderinstall_testionc'));
unlink('/tmp/rvsitebuilderinstall_testionc');
if ($ioncfiles !~/^ioncube\/ioncube_loader_(.*?)[win|so]$/) {
printf('Cannot get ioncube loader filename'); exit;
}
$self->{ioncube}->{loaderFilename} = $ioncfiles;
}
sub getIoncubePackage{
my $self = shift;
my ($phpCode);
$phpCode = <<PHPCODE;
function getLoaderFile()
{
\$machinetype = php_uname('m');
\$osType = strtolower(substr(php_uname(),0,3));
if (\$osType == 'dar') {
\$machineType = 'ppc';
} elseif (\$osType == 'fre') {
if ( preg_match('/64/i', \$machinetype, \$aMatch)) {
\$machineType = 'AMD64';
} else {
\$machineType = 'x86';
}
} elseif (\$osType == 'lin') {
if ( preg_match('/64/i', \$machinetype, \$aMatch)) {
\$machineType = 'x86-64';
} elseif ( preg_match('/ppc/i', \$machinetype, \$aMatch)) {
\$machineType = 'ppc';
} elseif ( preg_match('/sparc/i', \$machinetype, \$aMatch)) {
\$machineType = 'sparc';
} else {
\$machineType = 'x86';
}
}elseif (\$osType == 'ope') {
\$osVersion = php_uname('v');
if (preg_match('/3\.7/i', \$osVersion, \$aMatch) ) {
\$machineType = '3.7';
} else {
\$machineType = 'x86';
}
} elseif (\$osType == 'sun') {
if ( preg_match('/sparc/i', \$machinetype, \$aMatch)) {
\$machineType = 'sparc';
}else {
\$machineType = 'x86';
}
} elseif (\$osType == 'win') {
\$machineType = 'x86';
}
return 'ioncube_loaders_' . \$osType . '_' . \$machineType . '.tar.bz2';
}
echo getLoaderFile();
PHPCODE
$phpCode = replacePHPCode($phpCode);
open my $FD, '>', '/tmp/rvsitebuilderinstall_testionc';
print $FD "<?php $phpCode ?>";
close($FD);
my $ioncfiles = join('', saferun(0, $self->{phpexec} . ' -q /tmp/rvsitebuilderinstall_testionc'));
unlink('/tmp/rvsitebuilderinstall_testionc');
if ($ioncfiles !~/^ioncube_loaders_/i) {
printf('Cannot get ioncube package name'); exit;
}
$self->{ioncube}->{packageFilename} = $ioncfiles;
}
sub getExtensionPath{
my $self = shift;
my ($path) = join('', saferun(0, $self->{phpexec} . '-config --extension-dir'));
return $path;
}
sub installIoncude{
my $self = shift;
system('wget http://download.rvglobalsoft.com/loader/ioncube/' . $self->{ioncube}->{packageFilename} . ' -O ' . '/' . $self->{ioncube}->{packageFilename});
if ($? != 0 && $? != 1) {
printf('Sorry, download %s have some problem!!', $self->{ioncube}->{packageFilename});
exit;
}
if ( !-f '/' . $self->{ioncube}->{packageFilename} ) {
printf('Sorry, cannot download %s from http://download.rvglobalsoft.com/loader/ioncube/%s!!', $self->{ioncube}->{packageFilename}, $self->{ioncube}->{packageFilename});
exit;
}
system('tar -jxf ' . '/' . $self->{ioncube}->{packageFilename} . ' -C /');
if ($? != 0 && $? != 1) {
printf('Sorry, extract %s have some problem!!', $self->{ioncube}->{packageFilename});
exit;
}
system('chmod 755 -R /ioncube');
system('chown root -R /ioncube');
}
sub replacePHPCode{
my ($code) = shift;
$code =~s/'/"/gi;
$code =~s/\r|\n//gi;
return $code;
}
1;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez