CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/root/usr/local/rvglobalsoft/rvglobalsoft/auto/rvsitebuilderinstaller/
Upload File :
Current File : //proc/2/root/usr/local/rvglobalsoft/rvglobalsoft/auto/rvsitebuilderinstaller/autoinstaller.cgi

#!/usr/bin/perl
# WebSite:  http://www.rvglobalsoft.com
# Unauthorized copying is strictly forbidden and may result in severe legal action.
# Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
# 
# =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
# Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
# This Agreement is a legal contract, which specifies the terms of the license
# and warranty limitation between you and RV Global Soft Co.,Ltd. and RV Site Builder.
# You should carefully read the following terms and conditions before
# installing or using this software.  Unless you have a different license
# agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
# indicates your acceptance of the license and warranty limitation terms
# contained in this Agreement. If you do not agree to the terms of this
# Agreement, promptly delete and destroy all copies of the Software.
#
# =====  Grant of License =======
# The Software may only be installed and used on a single host machine.
#
# =====  Disclaimer of Warranty =======
# THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
# WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
# WARRANTIES WHETHER EXPRESSED OR IMPLIED.   BECAUSE OF THE VARIOUS HARDWARE
# AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
# FITNESS FOR A PARTICULAR PURPOSE IS OFFERED.  THE USER MUST ASSUME THE
# ENTIRE RISK OF USING THIS PROGRAM.  ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
# LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
# IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
# CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
# OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
# BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
# NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
# RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
# RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
# BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
# =====================================================================
use strict;
use Carp;
use Socket;
use POSIX                  ();
use File::Basename;
use File::Copy;
#use Data::Dumper; error in cpanel 11.38.1.6
use MIME::Base64;
use IPC::Open2;

BEGIN {
	push(@INC, dirname($0));
}

use RVSInstaller::Config qw(%InstallConf $NEWLINE $BROWSER $WEBROOT %MONS $INS_PHP_FILE_TYPE $INS_CGI_FILE_TYPE);
use RVSInstaller::Process;
use RVSInstaller::Serializer;
use RVSInstaller::ScreenControl;
use RVSInstaller::Langauge;
use RVSInstaller::Connection;
use RVSInstaller::CommonLib qw(%ARGUMENT);
use vars qw($BROWSER $ACTION $objLANG $completedColor $failedColor 
$SkipPro $SkipThemeLite $SkipThemePro $DEBUG %FuncConf $nextScriptParam
$cmd_cp $cmd_cp_all $cmd_mv $cmd_rm $cmd_mkdir $cmd_ln $cmd_rsync $cmd_tar
$cmd_replace $cmd_uname $cmd_df $cmd_chmod 
$cmd_replace $cmd_echo $cmd_lsattr $cmd_cat $cmd_date $cmd_locale $cmd_localedef $cmd_uname $cmd_perl
$callBySysCmd
);

$SIG{'PIPE'} = 'IGNORE';
$SIG{'HUP'}  = 'IGNORE';
$SIG{'ALRM'} = 'IGNORE';

$DEBUG = 0;
if(-f '/usr/local/rvglobalsoft/rvsitebuilderintaller.debug'){
	$DEBUG = 1;
}

$| = 1;

if ( $BROWSER == 0 && $> != 0 ) {
    die __FILE__ . " must be ran as root";
}


%FuncConf = (
    'begin' => {
        'next' => 'UpdateInstaller',
        'group' => 'init',
    },
    'UpdateInstaller' => {
        'next' => 'DowInstaller',
        'group' => 'UpdateInstaller',
    },
    'DowInstaller' => {
        'next' => 'SetupInstaller',
        'group' => 'UpdateInstaller',
    },
    'SetupInstaller' => {
        'next' => 'end',
        'group' => 'UpdateInstaller',
    },
    'end' => {
        'next' => '',
        'group' => 'init',
    },
);

$completedColor = "\e[1m\e[36m";
$failedColor = "\e[1m\e[31m";

$objLANG = RVSInstaller::Langauge->new(
    'Path' => $InstallConf{'ThisParh'} . '/lang',
    'Langauge' => 'en',
    'GlobalFile' => 'global',
    'GlobalFileType' => 'ini.php',
    'LangFile' => 'autoinstaller',
    'LangFileType' => 'ini',
);

if ( $BROWSER ) {
	print "HTTP/1.1 200 OK\n";
    print "Content-type: text/html\n\n";
    print "<html><head><title>RVSiteBuilder Installer</title>\n";
    print "</head>\n";
    print '<script src="' . $WEBROOT . '/include/install.js.' . $INS_PHP_FILE_TYPE . '" language="javascript" type="text/javascript"></script>';
    print "<body>\n";
    $BROWSER = 1;
}
else {
    $BROWSER = 0;
}

#=============Get Argument============
RVSInstaller::CommonLib::getArgumentAll();
RVSInstaller::CommonLib::validateAgeementLiencse();
#=====================================

if ( !-f $InstallConf{'ThisParh'} . "/.skipcheckroot") {
	my ($user) = callBackticks("whoami");
	 if ( $user ne "root\n" ) {
	    exitScript($InstallConf{'ThisParh'} . "/.skipcheckroot" . $objLANG->TranSlate("You must run this script as root else you may not have privileges to properly restore all files"));
	}
}

$| = 1;   
chackPid();     
loadvars();
Validate();

sub chackPid()
{
	
}


sub loadvars{
    $cmd_cp = whichCmd('cp');
    $cmd_mv = whichCmd('mv');
    $cmd_rm = whichCmd('rm');
    $cmd_mkdir = whichCmd('mkdir');
    
    $cmd_ln = whichCmd('ln');
    $cmd_rsync = whichCmd('rsync');
    $cmd_tar = whichCmd('tar');
    
    $cmd_replace = whichCmd('replace');
    $cmd_uname = whichCmd('uname');
    $cmd_df = whichCmd('df');
    $cmd_chmod = whichCmd('chmod');
    
    $cmd_replace = whichCmd('replace');
    $cmd_echo = whichCmd('echo');
    $cmd_lsattr = whichCmd('lsattr');
    $cmd_cat = whichCmd('cat');
    $cmd_date = whichCmd('date');
    $cmd_locale = whichCmd('locale');
    $cmd_localedef = whichCmd('localedef');
    $cmd_uname  = whichCmd('uname');
    $cmd_perl = whichCmd('perl');
}

sub Validate{
    my (%FORM, $INPUT, $callAction);
    if ( $BROWSER ) {
        %FORM = RVSInstaller::Process::ParseForm();
        if (%FORM) {
            $nextScriptParam = '?';
            my ($insertAnd);
            foreach (keys %FORM) {
                next if ($FORM{$_} =~/^$/gi);
                $nextScriptParam .=  $insertAnd . $_ . "=" . $FORM{$_};
                $insertAnd = '&';
            }
        }
    } else {
        %FORM = RVSInstaller::Process::ParseOpt();
        if (%FORM) {
            $nextScriptParam = ' ';
            my ($insertAnd);
            foreach (keys %FORM) {
                
                next if ($FORM{$_} =~/^$/gi && ($_ ne 'force' ||$_ ne 'help'));
                if ($_ ne 'force') {
                    $nextScriptParam .=  $insertAnd . "-" . $_ . "=" . $FORM{$_};
                } else {
                    $nextScriptParam .=  $insertAnd . "--force";
                }
                $insertAnd = ' ';
            }
            
            if (defined $FORM{'system'}) {
            	$callBySysCmd = '1';
            }
        }
    }

    if ($FORM{'debug'} eq 'ENV') {
        foreach (keys %ENV) {
            print "\$ENV{'" . $_ . "'} = " . $ENV{$_} . "<br />\n";
        }
        exitScript();
    }
    elsif ($FORM{'debug'} eq '1') {
        $DEBUG = 1;
    }
    
    if ( !$FORM{'action'} || $FORM{'action'} eq '' ) {
        $ACTION = 'begin';
    }
    else {
        $ACTION = $FORM{'action'};
    }
    if ( $FORM{'param'} && $FORM{'param'} ne '' ) {
         $INPUT = $FORM{'param'};
    }
    
    if ( $FORM{'call'} && $FORM{'call'} ne '' ) {
        $callAction = $FORM{'call'} . '_';
    }
    else {
        $callAction = 'Process_';
    }
    
    if ( $FORM{'rollback'}) {
         my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'rollBack'} = $FORM{'rollback'};
            $INPUT =  \%hParam;
        } 
        else {
            $hParam{'rollBack'} = $FORM{'rollback'};
            $INPUT =  \%hParam;
        }
    }
    #'/var/cpanel/rvglobalsoft/.rvsitebuilder/.getlatestversion'
    if (-f $InstallConf{'Installation'}{$InstallConf{'cpMode'}}{'companyPath'} . '/.rvsitebuilder/.getlatestversion') {
        my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'getversion'} = 'latest';
            $INPUT =  \%hParam;
        } 
        else {
            $hParam{'getversion'} = 'latest';
            $INPUT =  \%hParam;
        }
    }
    
    if ( $FORM{'getversion'}) {
        my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'getversion'} = $FORM{'getversion'};
            $INPUT =  \%hParam;
        } 
        else {
            $hParam{'getversion'} = $FORM{'getversion'};
            $INPUT =  \%hParam;
        }
    }
      
    if ( $FORM{'force'}) {
         my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'force'} = 1;
            $INPUT =  \%hParam;
        } 
        else {
            $hParam{'force'} = 1;
            $INPUT =  \%hParam;
        }
    }
    
    my ($callFunc) = $callAction . $ACTION . '($INPUT)';
    
    print "Call Function : " . $callFunc ."\n" if ( $DEBUG );
    
    eval($callFunc);
}

sub callNextFunc{
    my ($param) = $_[0];
    my ($nextFunc) = $FuncConf{$ACTION}->{'next'};
    print "Param Call Next Function :  " . $nextFunc ."\n" if ( $DEBUG );
    my ($nextGroup) = $FuncConf{$nextFunc}->{'group'} ;
    if ( $BROWSER ) {
        if ( "$nextFunc" ne "$ACTION" && "$ACTION" ne 'begin') {
            RVSInstaller::ScreenControl::jsChangeImg($ACTION, '2');
            RVSInstaller::ScreenControl::jsChangeArrow($ACTION, '1');
            RVSInstaller::ScreenControl::jsSetFontColor('msg' . $ACTION, '#7CABC1');
            RVSInstaller::ScreenControl::jsSetFontColor('subMsg' . $ACTION, '#7CABC1');
            RVSInstaller::ScreenControl::jsSetFontWeight('msg' . $ACTION, 'normal');
            RVSInstaller::ScreenControl::jsSetFontWeight('subMsg' . $ACTION, 'normal');
        }
        
        if ( "$nextGroup" ne "$nextFunc" ) {
            RVSInstaller::ScreenControl::jsChangeImg($nextFunc, '1');
            RVSInstaller::ScreenControl::jsChangeArrow($nextFunc, '2');
            RVSInstaller::ScreenControl::jsSetFontWeight('msg' . $nextFunc, 'bold');
            RVSInstaller::ScreenControl::jsSetFontColor('msg' . $nextFunc, '#FF740E');
            RVSInstaller::ScreenControl::jsSetFontColor('group' . $nextGroup, '#7CABC1');
        }
        if ( $nextGroup eq $nextFunc ) {
            RVSInstaller::ScreenControl::jsSetFontColor('group' . $nextFunc, '#FF740E');
        }
        else {
            if ( "$nextFunc" ne 'end' ) {
            RVSInstaller::ScreenControl::jsSetFontColor('msg' . $nextFunc, '#FF740E');
            RVSInstaller::ScreenControl::jsSetFontColor('subMsg' . $nextFunc, '#FFB20E');
            RVSInstaller::ScreenControl::jsSetFontWeight('msg' . $nextFunc, 'bold');
            RVSInstaller::ScreenControl::jsSetFontWeight('subMsg' . $nextFunc, 'normal');
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate("Please wait") . ' ...', '', 'subMsg' . $nextFunc);
            }
        }
          
        if ( $FuncConf{$nextFunc}->{'group'} ne $FuncConf{$ACTION}->{'group'}) {
            if ( $FuncConf{$ACTION}->{'group'} ne 'init') {
                RVSInstaller::ScreenControl::jsChangeSta($FuncConf{$ACTION}->{'group'}, '1');
            }
        }
    }
    my ($callNext) = 'Process_' . $nextFunc . '($param)';
    $ACTION = $nextFunc;
    eval($callNext);
    exitScript();
}

sub StepRedirect{
    my ($param) = $_[0];
    eval('Process_' . $ACTION . '($param)');
    exitScript();
}

sub exitScript{
    my ($exitMsg) = $_[0];
    RVSInstaller::ScreenControl::DisplayMsg($exitMsg, 1, 'ErrorDisplay');
    if ( $BROWSER ) {
        print "</body></html>\n";
    }
    exit;   
}

#######################################################################################################################
#
#   Process Functions
#
#######################################################################################################################

#######################################################################################################################
#   Start Program
#######################################################################################################################
sub Process_begin{
    my ($param) = $_[0];
    my (%output);
    
    if ($param) {
        %output = %{$param};
    }
    
    if ( !-d $InstallConf{'ThisParh'} . '/logs' ) {
        mkdir($InstallConf{'ThisParh'} . '/logs', 0666);
    }
    open(W ,">" . $InstallConf{'ThisParh'} . '/logs/rvsmain_log');
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
    $year += 1900;
    print W "Start running updated RVSiteBuilder : $mday " . $MONS{$mon} . " $year - $hour:$min:$sec\n";
    close(W);
    chmod(0666, $InstallConf{'ThisParh'} . '/logs/rvsmain_log');
    
    RVSInstaller::ScreenControl::DisplayMsg('', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate('Tester Connection') . '.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Tester Connection') . "\n");

    my %testConn = (
        'RVG80' => {
            'domain' => 'rvglobalsoft.com',
            'port' => '80',
        },
        'Down80' => {
            'domain' => 'download.rvglobalsoft.com',
            'port' => '80',
        },
        'Down443' => {
            'domain' => 'download.rvglobalsoft.com',
            'port' => '443',
        },
        'Lic80' => {
            'domain' => 'license2.rvglobalsoft.com',
            'port' => '80',
        },
        'Lic443' => {
            'domain' => 'license2.rvglobalsoft.com',
            'port' => '443',
        },
    );
    
    my @testStep = ('RVG80', 'Down80', 'Down443', 'Lic80', 'Lic443');
    my ($connKey);
    RVSInstaller::ScreenControl::jsSetFontColor('groupTestConnect', '#FF740E');
    foreach $connKey ( @testStep ) {
        RVSInstaller::ScreenControl::jsChangeImg($connKey, '1');
        RVSInstaller::ScreenControl::jsChangeArrow($connKey, '2');
        RVSInstaller::ScreenControl::jsSetFontColor('msg' . $connKey, '#FF740E');
        RVSInstaller::ScreenControl::jsSetFontColor('subMsg' . $connKey, '#FFB20E');
        
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}) . ' : ');
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}));
        my ($testConnection) = TestConnection($testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'});
        if ( $testConnection ) {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Failed'));
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}) . ' has failed.');
            if ( $testConn{$connKey}{'port'} eq '80') {
                RVSInstaller::ScreenControl::DisplayMsg($testConnection, '1', 'subMsg' . $connKey, '', '#FF0000');
                exitScript();
            }
            else {
                RVSInstaller::ScreenControl::DisplayMsg('Package verification fall back from SSL mode to non-SSL mode', '1', 'subMsg' . $connKey, '', '#FF0000');
            }
        }
        else {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Ready') , '', 'subMsg' . $connKey);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}) . ' has ready.');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        }
        RVSInstaller::ScreenControl::jsChangeImg($connKey, '2');
        RVSInstaller::ScreenControl::jsChangeArrow($connKey, '1');
        RVSInstaller::ScreenControl::jsSetFontColor('msg' . $connKey, '#7CABC1');
        RVSInstaller::ScreenControl::jsSetFontColor('subMsg' . $connKey, '#7CABC1');
    }
    RVSInstaller::ScreenControl::jsSetFontColor('groupTestConnect', '#7CABC1');
    RVSInstaller::ScreenControl::jsChangeSta('TestConnect', '1');
    callNextFunc(\%output);
}

#######################################################################################################################
#   Group Auto Update RVSiteBuilder Installer
#######################################################################################################################
sub Process_UpdateInstaller{
    my ($param) = $_[0];
    my %hParam = %{$param};
    RVSInstaller::ScreenControl::DisplayMsg('', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate('Update RVSiteBuilder Installer') . '.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Update RVSiteBuilder Installer') . "\n");
    callNextFunc(\%hParam);
    
}

sub Process_DowInstaller{
    my ($param) = $_[0];
    my %hParam = %{$param};

    if ( -d $InstallConf{'SourcePath'}) {
        RVSInstaller::Process::unlinkAll($InstallConf{'SourcePath'});
    }

    if ( -d $InstallConf{'PackagePath'}) {
        chmod(0755, $InstallConf{'SourcePath'});
    #    RVSInstaller::Process::unlinkAll($InstallConf{'PackagePath'});
    }
        
    if (!-d $InstallConf{'SourcePath'} ) {
        mkdir($InstallConf{'SourcePath'}, 0755);
        chmod(0755, $InstallConf{'SourcePath'});
    }
    
    if ( -e $InstallConf{'SourcePath'} . '/.rvsdownloadlog') {
        unlink($InstallConf{'SourcePath'} . '/.rvsdownloadlog');
    }

    if ( !-e $InstallConf{'ThisParh'} . '/.skipupdateauto') {
        $hParam{'DownloadInstaller'} = 'InformationPackageInstall';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading RVSiteBuilder Installer package information'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg(':');
       
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Loading RVSiteBuilder Installer package information') . " : ");
        
        my ($reqPackage, $productCode, $saveFilename, $nextStap);
        $reqPackage = 'rvsitebuilder-upgrade';

        $hParam{'DownloadInstallerConfiguration'}{'reqPackage'} = $reqPackage;
        $hParam{'DownloadInstallerConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
        $hParam{'DownloadInstallerConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
        $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
        $hParam{'DownloadInstallerConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
        
        if ( -e $hParam{'DownloadInstallerConfiguration'}{'LogFileName'} ) {
            unlink($hParam{'DownloadInstallerConfiguration'}{'LogFileName'});
        }
        
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Available') , '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available') . "\n");

        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Downloading new xxx package', $hParam{'DownloadInstallerConfiguration'}{'ProductName'}) , '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg(':', '1');
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Downloading new xxx package', $hParam{'DownloadInstallerConfiguration'}{'ProductName'}) . "\n");

        # <-- Download -->
 
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'SourcePath'} . '/' . $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'};
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/' . $hParam{'DownloadInstallerConfiguration'}{'ProductCode'};
        if ($hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }

        require $InstallConf{'RVInstaller'} . '/rvsdownload.pl';
        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('evalOutput', 1);
        Register('format', "RVSInstaller::ScreenControl::LogMsg('\$1' \. \"\\n\");RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
    
        Connection();

        RVSInstaller::ScreenControl::DisplayMsg('', 1);
    
        RVSInstaller::ScreenControl::DisplayMsg(':');
        RVSInstaller::ScreenControl::LogMsg("Download the RVSiteBuilder Installer package has been completed.\n");

        my ($resourceMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'SourcePath'} . '/' . $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'});
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Validating RVSiteBuilder Installer package') . ' ' . $resourceMD5, '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Validating RVSiteBuilder Installer package') . ' ' . $resourceMD5 . "\n");
        my (%hData, $Data, %hValidate);
        %hData = (
            'product-name' => $hParam{'DownloadInstallerConfiguration'}{'ProductCode'},
            'MD5-Value' => $resourceMD5,
        );
        if ($hParam{'getversion'}) {
            $hData{'getversion'} = $hParam{'getversion'};
        }
    
        RVSInstaller::ScreenControl::LogMsg('RVS Product Name : ' . $hParam{'DownloadInstallerConfiguration'}{'ProductCode'} . "\n");
        RVSInstaller::ScreenControl::LogMsg('MD5 of package : ' . $resourceMD5 . "\n");
      
        $Data = RVSInstaller::Process::URLEncode(RVSInstaller::Process::SerializerData(\%hData));
        RVSInstaller::ScreenControl::LogMsg('Send RVS Code : ' . $Data . "\n");
        
        RVSInstaller::ScreenControl::LogMsg('Use SSL connection.' . "\n");
        #license2 download
        %hValidate = %{RVSInstaller::Connection::UrlConnection($InstallConf{'SiteConf'}{'download'}{'address'}{'site1'}, 443, '', 1, $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/rvcode/' . $Data)};
        if ( $hValidate{'Err'} ) {
            RVSInstaller::ScreenControl::LogMsg('SSL connection has error ' . $hValidate{'Err'} . ".\n");
            RVSInstaller::ScreenControl::LogMsg('Use NONE-SSL connection.' . "\n");
            %hValidate = %{RVSInstaller::Connection::UrlConnection($InstallConf{'SiteConf'}{'download'}{'address'}{'site1'}, 80, '', 0, $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/rvcode/' . $Data)};
        }

        if ( $hValidate{'Err'} && !-e $InstallConf{'RVInstaller'} . '/skipinstall/.validateinstaller') {
            $hValidate{'Err'} =~s/\r|\n|\"//gi;
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::LogMsg('NONE-SSL connection has error ' . $hValidate{'Err'} . ".\n");
            RVSInstaller::ScreenControl::DisplayMsg($hValidate{'Err'} , 1, 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg(" ]\e[0m", 1);
            RVSInstaller::ScreenControl::LogMsg('Sorry, cannot connection with SSL and NONE-SSL' . ".\n");
            exitScript();
        }
        my (%MasterCheck);
        RVSInstaller::ScreenControl::LogMsg('Receive Data : ' . $hValidate{'Page'} . "\n");
        %MasterCheck = RVSInstaller::Process::UnSerializerData($hValidate{'Page'});

        if ( $MasterCheck{'RVS-Validate'} eq '1') {
            if ( !-d $InstallConf{'PackagePath'}) {
                mkdir($InstallConf{'PackagePath'},  0755);
                chmod(0755, $InstallConf{'PackagePath'});
            }
            
            if ( -e $InstallConf{'PackagePath'} . '/' . $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'} ) {
                unlink($InstallConf{'PackagePath'} . '/' . $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'});
            }
        
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Latest Version') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg('Now the RVSiteBuilder Installer package has been latest version' . "\n");
        } else {
            RVSInstaller::ScreenControl::LogMsg('Your the RVSiteBuilder Installer package has old version' . "\n");
            RVSInstaller::ScreenControl::DisplayMsg($MasterCheck{'RVS-Validate'});
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Download RVSiteBuilder Installer package has invalid') . ', ' . $objLANG->TranSlate('please contact RVSiteBuilder Support') , '1', 'subMsg' . $ACTION);
            exitScript();
        }
    } else {
    	RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    }
    # <-- NEXT STEAP -->
    my (%hSendParam);
    $hSendParam{'reqPackage'} = $hParam{'DownloadInstallerConfiguration'}{'reqPackage'};
    callNextFunc(RVSInstaller::Process::SerializerData(\%hSendParam));
}

sub Process_SetupInstaller{
    my ($param) = $_[0];
    my %hParam = RVSInstaller::Process::UnSerializerData($param);

    RVSInstaller::ScreenControl::DisplayMsg('', '1');
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Setup RVSiteBuilder Installer'),1, 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Setup RVSiteBuilder Installer') . ".\n");
        
    if ( -e $InstallConf{'ThisParh'} . '/.skipupdateauto') {
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip') , '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg('Skip setup RVSiteBuilder Installer' . ".\n");

    }
    elsif ( -e $InstallConf{'SourcePath'} . '/' . $InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'} ) {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Running tar uncompressed the xxx package', $objLANG->TranSlate('RVSiteBuilder Installer')),'', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Running tar uncompressed the xxx package', $objLANG->TranSlate('RVSiteBuilder Installer')) . ".\n");
        my ($self_mtime)     = ( stat($InstallConf{'ThisParh'} . '/autoinstaller.cgi') )[9];
        $InstallConf{'AutoInstallStat'} = $self_mtime;
        # <-- Tar Package -->
        chdir($InstallConf{'SourcePath'});
        my (@logTarData); 
        open PID, $cmd_tar . ' -xopf ' . $InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'} . '|'; 
        while (<PID>) {
            ~s/\r|\n//gi;
            RVSInstaller::ScreenControl::DisplayMsg($_ , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg($_ . "\n");
            push(@logTarData, $_); 
        }
        close(PID);
        
        my ($chData) = 1;
        my ($errorMsg);
        foreach ( @logTarData ) {
            if ( /\/$/) {
                if ( !-d $_) {
                    $errorMsg = $objLANG->TranSlate('the folder') . ' ' . $_ . ' ' . $objLANG->TranSlate('cannot uncompressed');
                    $chData = 0;
                    last;
                }
            }
            else {
                if ( !-e $_) {
                    $errorMsg = $objLANG->TranSlate('the file') . ' ' . $_ . ' ' . $objLANG->TranSlate('cannot uncompressed');
                    $chData = 0;
                    last;
                }    
            }
        }
        
        chdir($InstallConf{'ThisParh'});
        if ( !$chData ) {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Failed'));
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::DisplayMsg('', 1);
            RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $errorMsg . '.', 1, 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
            RVSInstaller::ScreenControl::LogMsg('Uncompress the package has been uncompleted, ' . $errorMsg . ".\n");
            exitScript();
        }
        else {
            if ( -e $InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'}) {
                unlink($InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'});
            }
            if ( -e $InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'}) {
                unlink($InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'});
            }
            
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg('Uncompress the package has been completed' . "\n");
        }
        
        # <-- Copy source files to installer path -->
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Copy source files to installer path') , '1', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Copy source files to program path') . ".\n");
        open PID, $cmd_rsync . ' -avz --timeout=60 ' . $InstallConf{'SourcePath'} . '/rvsitebuilderinstaller/ ' . $InstallConf{'ThisParh'} . '|'; 
        my (@logTarData);
        while (<PID>) {
            ~s/\r|\n//gi;
            push(@logTarData, $_);
            RVSInstaller::ScreenControl::DisplayMsg($_, 1, 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg($_ . "\n");
        }
        close(PID);

        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Changes the permissions of files') , '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg('Changeing the permission of files and folders' . ".\n");
        
        my ($login,$pass,$uid,$gid) = getpwnam('root');
        RVSInstaller::ScreenControl::LogMsg('Changes the owner to ' . $uid . ' and group to ' . $gid . "\n");
        RVSInstaller::Process::chownAll($InstallConf{'ThisParh'}, $uid, $gid);
        
        if ( -e $InstallConf{'ThisParh'} . '/autoinstaller.cgi') {
            RVSInstaller::ScreenControl::LogMsg('Changes ' . $InstallConf{'ThisParh'} . '/autoinstaller.cgi to mode 755' . "\n");
            chmod(0755, $InstallConf{'ThisParh'} . '/autoinstaller.cgi');
        }
        if ( -e $InstallConf{'ThisParh'} . '/real_autoinstaller.cgi') {
            RVSInstaller::ScreenControl::LogMsg('Changes ' . $InstallConf{'ThisParh'} . '/real_autoinstaller.cgi to mode 755' . "\n");
            chmod(0755, $InstallConf{'ThisParh'} . '/real_autoinstaller.cgi');
        }
        
        if (!-e $InstallConf{'Installation'}{$InstallConf{'cpMode'}}{'companyPath'} . '/rvsitebuilder/panelmenus/' . $InstallConf{'cpMode'} . '/scripts') {
            system('mkdir -p ' . $InstallConf{'Installation'}{$InstallConf{'cpMode'}}{'companyPath'} . '/rvsitebuilder/panelmenus/' . $InstallConf{'cpMode'} . '/scripts >/dev/null');	
        }
        
        if (-f $InstallConf{'Installation'}{$InstallConf{'cpMode'}}{'companyPath'} . '/rvsitebuilder/panelmenus/' . $InstallConf{'cpMode'} . '/scripts/autofixphpini.pl') {
        	system('rm -f ' . $InstallConf{'Installation'}{$InstallConf{'cpMode'}}{'companyPath'} . '/rvsitebuilder/panelmenus/' . $InstallConf{'cpMode'} . '/scripts/autofixphpini.pl >/dev/null');
        }
        
        system('cp ' . $InstallConf{'ThisParh'} . '/autofixphpini.pl ' . $InstallConf{'Installation'}{$InstallConf{'cpMode'}}{'companyPath'} . '/rvsitebuilder/panelmenus/' . $InstallConf{'cpMode'} . '/scripts >/dev/null');
        
        my ($newself_mtime)     = ( stat($InstallConf{'ThisParh'} . '/autoinstaller.cgi') )[9];
        $InstallConf{'NewAutoInstallStat'} = $newself_mtime;
        
        RVSInstaller::Process::chmodAll($InstallConf{'RVInstaller'}, 0755);
        RVSInstaller::Process::chmodAll($InstallConf{'InclidePath'}, 0755);
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    }
    else {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('Find not found the xxx', $InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'}),'', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('Find not found the xxx', $InstallConf{'Packages'}{$hParam{'reqPackage'}}{'SaveFilename'}) . ".\n");
        exitScript();

    }
 
    # <-- NEXT STEAP -->
    my (%hSendParam);
    $hSendParam{'reqPackage'} = {'reqPackage'};
    callNextFunc(RVSInstaller::Process::SerializerData(\%hSendParam));

}

sub Process_end{
    if ( $BROWSER ) {
        if ($InstallConf{'AutoInstallStat'} eq $InstallConf{'NewAutoInstallStat'}) {
            RVSInstaller::ScreenControl::LogMsg('Running page ' . $WEBROOT . '/real_autoinstaller.' . $INS_CGI_FILE_TYPE . "\n");
            print '<script>window.location="' . $WEBROOT . '/real_autoinstaller.' . $INS_CGI_FILE_TYPE . $nextScriptParam . '";</script>' . "\n";
        } else {
            RVSInstaller::ScreenControl::LogMsg('Running page ' . $WEBROOT . '/autoinstaller.' . $INS_CGI_FILE_TYPE . "\n");
            print '<script>window.location="' . $WEBROOT . '/autoinstaller.' . $INS_CGI_FILE_TYPE . $nextScriptParam . '";</script>' . "\n";
        }
    } else {
        if ($InstallConf{'AutoInstallStat'} eq $InstallConf{'NewAutoInstallStat'}) {
            RVSInstaller::ScreenControl::LogMsg('Running real_autoinstaller.cgi' . "\n");
            my ($perlPath) = RVSInstaller::Process::getPerlPath();
            system("$perlPath ". $InstallConf{'ThisParh'} . '/real_autoinstaller.cgi' . $nextScriptParam . ' --system ' . RVSInstaller::CommonLib::buildArgumentForCli());
        } else {
            RVSInstaller::ScreenControl::LogMsg('Running autoinstaller.cgi' . "\n");
            my ($perlPath) = RVSInstaller::Process::getPerlPath();
            system("$perlPath ". $InstallConf{'ThisParh'} . '/autoinstaller.cgi ' . RVSInstaller::CommonLib::buildArgumentForCli());
        }
        if ( -d $InstallConf{'SourcePath'}) {
            RVSInstaller::Process::unlinkAll($InstallConf{'SourcePath'});
        }
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
        $year += 1900;
        print "Run on: $mday " . $MONS{$mon} . " $year - $hour:$min:$sec\n";
    }
    exitScript();
}

sub TestConnection{
    my ($domain, $port) = @_;
    my ($request) = '/testconnection.php';
    
    $domain =~s/^http:\/\///gi;
    $domain =~s/^https:\/\///gi;
    my ($testmsg) = '$1 connection has ready.';
    $testmsg =~s/\$1/$domain/gi;
    
    my ($status, $page);
    $page = '';
    if ( $port eq '443' || $port eq 443 ) {
    	if ( -f $InstallConf{'ThisParh'} . '/.skipsslconnection') {
    		return 'skip ssl connection';
    	}
        eval { require Net::SSLeay; };
        if ($@) {
            return 'Net::SSLeay' . ' ' . $objLANG->TranSlate("is not compiled");
        }
        
        my ($SSLresult, %headers);
        eval {
            local $SIG{ALRM} = sub { return $objLANG->TranSlate("Connection Timeout"); };
            alarm 15; 
            ($page, $SSLresult, %headers) = Net::SSLeay::get_https($domain , $port, $request) or return 'Error : ' . $!;
            alarm 0;
		};
    }
    else {
        
        $SIG{'PIPE'} = $SIG{'ALRM'} = sub {
            print "Unable to retrieve file\n";
            die;
        };
        # <-- Port 80 -->
        my $poto = getprotobyname('tcp');
        
        my $ipaddr = inet_aton($domain);
		if (!defined ($ipaddr)) {
            return $objLANG->TranSlate("Get protocal by hostname failed") . '.';
		}
		
		socket(SOCKET, AF_INET, SOCK_STREAM, $poto) or sub { return "socket error" . ": $!"; };
		
		$port = getservbyname( 'http', 'tcp' );
		my $sin = sockaddr_in($port, $ipaddr);
		
		connect (SOCKET, $sin) or sub { return $objLANG->TranSlate("Cannot create socket connection to") . ' ' . $domain . '.'; };
        #send SOCKET, "GET " . $request . " HTTP/1.0\n\n", 0;
        send SOCKET, "GET $request HTTP/1.0\r\nHost: $domain\r\n\r\n", 0;
        my $inheaders = 1;
		my $httpStatus;
		my ($pages) = '';
		while (<SOCKET>) {
        alarm(20);    
            if ($inheaders) {
                ~s/\n//g;
                ~s/\s$//g;
                
                if ( /^HTTP\/([\d\.]+)\s(.*)/ ) {
                    $httpStatus  = $2;
                    $httpStatus  =~s/^\s//gi;
                    $httpStatus  =~s/\s$//gi;
                    if ( $httpStatus !~/200/gi) {
                        return 'Connection ' . $httpStatus;
                    }
                }
				if ( /^$/ && $inheaders) {
				    $inheaders = 0;
			    }
			}
			else {
			     $page .= $_;
			}
 alarm(0);
		}
		close (SOCKET);
    }

    if ( $page =~/$testmsg/gi ) {
        return 0;
    }
    else {
        return $objLANG->TranSlate('Sorry cannot connection to xxx please following it', $domain, $port);
    }
}

#test1
sub whichCmd{
    my ($cmd) = $_[0];
    return if ($cmd eq '');
    return if ($cmd =~/\//);
    
    my $whichCmd = '';
    my $binpath = '';
    my @binpathList = (
        '/bin',
        '/usr/bin',
        '/usr/local/bin',
        '/sbin',
        '/usr/sbin',
        '/usr/local/sbin'
    );
    
    foreach my $path(@binpathList) {
        if ( -x $path . '/' . 'which') {
            $whichCmd = $path . '/' . 'which';
            last;
        }  
    }
    if ($whichCmd eq '') {
        RVSInstaller::ScreenControl::DisplayMsg(1, '', 'which command is not support.');
        RVSInstaller::ScreenControl::LogMsg('which command is not support.');    
        return $binpath;
    }
    
    $binpath = callBackticks("$whichCmd $cmd");
    chomp ($binpath);
    $binpath =~s/\n|\r//gi;
    
    if ($binpath eq '' || $binpath=~/null/) {
        foreach my $path(@binpathList) {
            if ( -x $path . '/' . $cmd) {
                $binpath = $path . '/' . $cmd;
                last;
            }
        }                
    }
    
    if ($binpath eq '') {
        RVSInstaller::ScreenControl::DisplayMsg(1, '', $cmd . ' is not support.');
        RVSInstaller::ScreenControl::LogMsg($cmd . ' is not support.');
        
    } elsif (!-x $binpath) {
        RVSInstaller::ScreenControl::DisplayMsg(1, '', $cmd . ' is not executeable.');
        RVSInstaller::ScreenControl::LogMsg($cmd . ' is not executeable.');
    }    
        
    return $binpath;
}

sub callBackticks{
    my $cmd = $_[0];
    if (-f '.rvsBackticks') {
        system('rm -f .rvsBackticks');
    }
    
    system("$cmd > .rvsBackticks");
    my ($resuft);
    if (-f '.rvsBackticks') {
        my ($fd);
        open($fd, '<', '.rvsBackticks');
        $resuft = join('',<$fd>);
        close($fd);
        system('rm -f .rvsBackticks');
    } else {
        $resuft = `$cmd`;
    }
    return $resuft;
}

1;
__END__

Copyright 2K16 - 2K18 Indonesian Hacker Rulez