CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/cwd/usr/local/rvglobalsoft/rvglobalsoft/auto/rvsitebuilderinstaller/
Upload File :
Current File : //proc/2/cwd/usr/local/rvglobalsoft/rvglobalsoft/auto/rvsitebuilderinstaller/real_autoinstaller.cgi

#!/bin/sh
eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
if 0;

#!/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 File::Basename;
use File::Copy;
#use Data::Dumper; error in cpanel 11.38.1.6
use MIME::Base64;
use IPC::Open2;
use DBI;
use IO::Handle;
BEGIN {
	push(@INC, dirname($0));
}

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

use RVSInstaller::Config qw(%FuncConf %InstallConf $NEWLINE $BROWSER $WEBROOT %MONS $UIOBJ $INS_PHP_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 $tarOption $bunzip2Option $SCRIPT_OPT $UICONF $skipBzip2
$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_chflags $cmd_chattr
$cmd_replace $cmd_echo $cmd_lsattr $cmd_cat $cmd_date $cmd_locale $cmd_localedef $cmd_uname $cmd_perl $RVS_IP_CONF
);

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

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

#Register appConfig for cPanel
if ($InstallConf{'cpMode'} eq 'cpanel' && -e $InstallConf{'ThisParh'} . '/appconfig/rvsitebuilder.conf' && -e $InstallConf{'ThisParh'} . '/appconfig/registerapp') {
	my $chmod = whichCmd('chmod');
	system($chmod . ' 755 ' . $InstallConf{'ThisParh'} . '/appconfig/registerapp');
	if ($BROWSER == 1) {
    	system($InstallConf{'ThisParh'} . '/appconfig/registerapp > /dev/null');	
	} else {
		system($InstallConf{'ThisParh'} . '/appconfig/registerapp');
	}
}

if (!-e '.usebzip2mode') {
    $skipBzip2 = 1;
}
if (!findBunzip2()) {
	$tarOption = '-jxvf';
	$skipBzip2 = 1;
} else {
    $tarOption = '-xvf';
}
$bunzip2Option = '-c';
$SkipPro = 0;
$SkipThemeLite = 0;
$SkipThemePro = 0;

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

require $InstallConf{'RVInstaller'} . '/rvsdownload.pl';

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

#=============Get Argument============
#For New Serer
RVSInstaller::CommonLib::getArgumentAll();
if(RVSInstaller::CommonLib::isNewServer()){
	RVSInstaller::CommonLib::validateAgeementLiencse();
	RVSInstaller::CommonLib::getTemplatePathFromArgument();
}

# Get on-demand template configuration
$InstallConf{'on-demandTemplate'} = RVSInstaller::CommonLib::isOnDemnadTemplate();

#RVSInstaller::CommonLib::autoCrateDabase();
#RVSInstaller::CommonLib::testConnectionDb();
#exit;
#===================================





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 {
	#STDIN->blocking(0);
    my ($mainIP);
    $mainIP = RVSInstaller::Process::getMainIP();
	
   	if ($InstallConf{'cpMode'} eq 'cpanel') {
		if(RVSInstaller::CommonLib::isAutoInstall()){
			
		}elsif ( (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE' 
	           &&  !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE.php' ) 
	           &&!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.conf.php'  
	           && !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php' ) {
	
	        print "RVSitebuilder automatical update cannot be completed.\n";
	        print "Please access to WHM/RVGlobalsoft Manager/RVSitebuilder Manager, to setup RVSItebuilder manually.\n"; 
	        exit;   
	    }
	}
    
    if (-e $InstallConf{'ThisParh'} . '/getphpinipath.php' && -e '/root/.accesshash') {
        my ($aKey);
        $aKey = '';
        open(R, '/root/.accesshash');
        while(<R>) {
            chomp;
            s/\r|\n|\ //i;
            $aKey .= $_;
        }
        close(R);
    	my ($phpIniPath) = join(',',whmConnection($aKey,'/cgi/rvsitebuilderinstaller/getphpinipath.php'));

    	if ($phpIniPath =~/\/usr\/local\/lib\/php\.ini/gi || $phpIniPath =~/\/usr\/lib\/php\.ini/gi) {
            print "Your cPanel usage php.ini at $phpIniPath\n";
            my ($selectMakecpphp) = 0; 
            eval {
                local $SIG{ALRM} = sub { die 'Timed Out'; };
                alarm 60;
                my($inputkey, $upconfirm);
                $upconfirm = 0;
                do {
                    print "Do you want to run script '/usr/local/cpanel/scripts/makecpphp' to fix php.ini path. : [y|n]? ";
                    chomp($inputkey = <STDIN>);
                    $inputkey =~ s/\n//g;
                    $inputkey = lc($inputkey);
                    if ($inputkey eq 'yes' || $inputkey eq 'y') {
                        $upconfirm = 1;
                        $selectMakecpphp = 1;
                    } elsif ($inputkey eq 'no' || $inputkey eq 'n' ) {
                    	$upconfirm = 1;
                    	$selectMakecpphp = 0;
                    }
                } while($upconfirm == 0);
                alarm 0; 
                #<-- Cancel the alarm -->
            };
            
            if ($selectMakecpphp) {
            	system('/usr/local/cpanel/scripts/makecpphp');
            }
    	}
    }

    $BROWSER = 0;
    if (defined $UIOBJ->{'OBJ'}) {
        $UICONF->{'OBJ'} = $UIOBJ->{'OBJ'};
    }
    
}

loadvars();
autoFix();

$| = 1;
Validate();

sub loadvars{
	if (-f '.rvsBackticks') {
        system('rm -f .rvsBackticks');
    }
    
	my ($testBackticks) = callBackticks('echo', 'RVSiteBuilder Test Backticks');
	if ($testBackticks !~/RVSiteBuilder Test Backticks/gi) {
		open(my $FW, '>', '.rvsBackticks');
		print $FW, 1;
		close($FW);
	}
	
    $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');
    
    
    my ($osType) = callBackticks("$cmd_uname -s");
    if ($osType =~/freebsd/gi) {
        $cmd_chflags = whichCmd('chflags');
        $cmd_cp_all = $cmd_cp . ' -rf';
    } else {
        $cmd_chattr = whichCmd('chattr');
        $cmd_cp_all = $cmd_cp . ' -a';
    }
 
    my($mainIP) = RVSInstaller::Process::getMainIP();
    
    #my ($rvglobalPath) = '/var/cpanel/rvglobalsoft';
    my ($rvglobalPath) = $InstallConf{'cpModeConfigPath'}{'companyPath'};

    my ($rvsitbuilderProgramPath) = $rvglobalPath . '/rvsitebuilder';
    $RVS_IP_CONF = $rvsitbuilderProgramPath . '/var/' . $mainIP . '.conf.php';
}

sub Validate{
    my (%FORM, $INPUT, $callAction);
    if (  $BROWSER ) {
        %FORM = RVSInstaller::Process::ParseForm();
    } else {
        %FORM = RVSInstaller::Process::ParseOpt();
    }

    if ($FORM{'debug'} eq 'ENV') {
        foreach (keys %ENV) {
            print "\$ENV{'" . $_ . "'} = " . $ENV{$_} . "<br />\n";
        }
        exitScript();
    }elsif ($FORM{'debug'} ) {
        $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;
        }
        $SCRIPT_OPT->{'rollback'} = $hParam{'rollback'};
    }
    
    if (-f $InstallConf{'cpModeConfigPath'}{'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;
        }
        $SCRIPT_OPT->{'getversion'} = $hParam{'getversion'};
    }

    if (defined $FORM{'force'}) {
         my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'force'} = 1;
            $INPUT =  \%hParam;
        }  else {
            $hParam{'force'} = 1;
            $INPUT =  \%hParam;
        }
        $SCRIPT_OPT->{'force'} = $hParam{'force'};
    }
    if (!$BROWSER && !defined $FORM{'system'}) {
        my ($perlPath) = RVSInstaller::Process::getPerlPath();
        system("$perlPath ". $InstallConf{'ThisParh'} . '/autoinstaller.cgi --system');
    } else {
        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{
    if ( $BROWSER ) {
    	RVSInstaller::ScreenControl::LogMsg('===Exit Script===');
        print "</body></html>\n";
    }
    exit;   
}

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

#######################################################################################################################
#   Start Program
#######################################################################################################################
sub Process_begin{
    my ($param) = $_[0];
    my (%output);
    #print $param; debug?
    print keys %{$param};
    if ($param) {
        %output = %{$param};
    }
    else {
        %output = ();
    }
    
    RVSInstaller::ScreenControl::LogMsg('Start real_autoinstaller.cgi' . "\n");
    callNextFunc(\%output);
}

#######################################################################################################################
#   Group License Information
#######################################################################################################################
sub Process_LicenseInfo{
    my ($param) = $_[0];
    my %hParam = %{$param};
    
    RVSInstaller::ScreenControl::DisplayMsg('', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate('License Information') . '.', 1);
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate('License Information'), '');
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    if (defined $hParam{'force'}) {
        RVSInstaller::ScreenControl::DisplayMsg('Use option force update', '1');
        if ( -e $InstallConf{'PackagePath'}) {
            system($cmd_rm, '-rf', $InstallConf{'PackagePath'},'>/dev/null');
            system('mkdir -p ' . $InstallConf{'PackagePath'});
        }
    }
    callNextFunc(\%hParam);
}

#######################################################################################################################
# Get License Information
#######################################################################################################################
sub Process_LicenseInfoGet{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    $hParam{'MainIP'} = RVSInstaller::Process::getMainIP();
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'}, '1', 'subMsg' . $ACTION);
    push(@{$hParam{'boxMessages'}}, $objLANG->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'});
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
    
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Used xxx connection validate xxx for IP', 'SSL' ,'license') . ' ' . $hParam{'MainIP'}, '1', 'subMsg' . $ACTION);
    push(@{$hParam{'boxMessages'}}, $objLANG->TranSlate('Used xxx connection validate xxx for IP', 'SSL' ,'license') . ' ' . $hParam{'MainIP'});
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Used xxx connection validate xxx for IP', 'SSL', 'license') . ' ' . $hParam{'MainIP'} . "\n");
    # <-- Connection to license site by SSL-->
    
    my $rvcode = rvsLicenseEncode();
    $rvcode =~ s/\n|\r|\t//gi;
    #get license2 https

    my $url = $InstallConf{'SiteConf'}{'license'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'license'}{'uri'}{'site1'};
    my %licenseInfo = RVSInstaller::Process::postConnection($url,'POST',"rvcode=$rvcode");
    
    my %licenseInfoPage = RVSInstaller::Process::UnSerializerData($licenseInfo{'Page'});
    if ( $licenseInfo{'Err'} ) {
        # <-- Connection error -->
        $licenseInfo{'Err'} =~s/\r|\n|\"//gi;
        RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot used xxx connection to') . ' ' . 
        		$InstallConf{'SiteConf'}{'license'}{'address'}{'site1'} . ': ' . $licenseInfo{'Err'} , 1, 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
        push(@{$hParam{'boxMessages'}}, ' -- ' . $objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot used xxx connection to') . ' ' . 
            	$InstallConf{'SiteConf'}{'license'}{'address'}{'site1'} . ': ' . $licenseInfo{'Err'}
        );
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
            
        # <-- Used NONE SSL Connection -->
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Used xxx connection validate xxx for IP', 'NONE-SSL' ,'license') . ' ' . $hParam{'MainIP'}, '1', 'subMsg' . $ACTION);
        push(@{$hParam{'boxMessages'}}, 
            $objLANG->TranSlate('Used xxx connection validate xxx for IP', 'NONE-SSL' ,'license') . ' ' . $hParam{'MainIP'}
        );
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Used xxx connection validate xxx for IP', 'NONE-SSL', 'license') . ' ' . $hParam{'MainIP'} . "\n");
        
        #get license2 http
        
        my $url = $InstallConf{'SiteConf'}{'license'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'license'}{'uri'}{'site1'};
        my %licenseInfo = RVSInstaller::Process::postConnection($url,'POST',"rvcode=$rvcode");
        
        %licenseInfoPage = RVSInstaller::Process::UnSerializerData($licenseInfo{'Page'});
        if ( $licenseInfo{'Err'} ) {
            # <-- Connection error -->
            $licenseInfo{'Err'} =~s/\r|\n|\"//gi;
            
            RVSInstaller::ScreenControl::LogMsg('SSL connection has error, ' . $licenseInfo{'Err'} . "\n");
            RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot connection to') . ' ' . $InstallConf{'SiteConf'}{'license'}{'address'}{'site1'} . ': ' . $licenseInfo{'Err'} , 1, 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
           
            RVSInstaller::ScreenControl::LogMsg('Sorry, cannot connection with SSL and NONE-SSL' . ".\n");
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
            # <-- End Process Installer -->
            exitScript();
        }
    }
    
    my $licenseIP = (exists $licenseInfoPage{'rvsitebuilder'}{'license-ip'})
            ? $licenseInfoPage{'rvsitebuilder'}{'license-ip'}
            : $hParam{'MainIP'};
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Validate license for IP') . ' ' . $licenseIP, '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Validate license for IP') . ' ' . $licenseIP . ' has been completed.' . "\n");
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Pass') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    @{$hParam{'boxMessages'}} = ();
    push(@{$hParam{'boxMessages'}}, $objLANG->TranSlate('Validate license for IP') . ' ' . $licenseIP . ': ' . $objLANG->TranSlate('Pass'));
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
    
    $hParam{'LicenseInfo'} = $licenseInfo{'Page'};
    push(@{$hParam{'BoxMessages'}}, @{$hParam{'boxMessages'}});
    callNextFunc(\%hParam);
}

#######################################################################################################################
#   Diaplay License Type
#######################################################################################################################
sub Process_LicenseInfoType{
    my ($param) = $_[0];
    my (%hParam) = %{$param};

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Product information'));
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg('RVSiteBuilder', '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    push(@{$hParam{'BoxMessages'}}, 'Your license type: RVSiteBuilder');
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}});
    RVSInstaller::ScreenControl::LogMsg('Your license type: RVSiteBuilder' . "\n");
    
    callNextFunc(\%hParam);
}

#######################################################################################################################
#   Display License Expired Date
#######################################################################################################################
sub Process_LicenseInfoExp{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
    
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Validate expired date'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, $objLANG->TranSlate('Validate expired date') . '...');

    $hParam{'MainIP'} = RVSInstaller::Process::getMainIP();
    #if ( $hParam{'MainIP'} eq 'on error') {
    if ( exists $hLicenseInfo{'rvsitebuilder'}{'expire-date'} && $hLicenseInfo{'rvsitebuilder'}{'expire-date'} > time ) {
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($hLicenseInfo{'rvsitebuilder'}{'expire-show'} , '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg('Your license expired  on ' . $hLicenseInfo{'rvsitebuilder'}{'expire-show'} . "\n");
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, $objLANG->TranSlate('Validate expired date') . ': ' . $hLicenseInfo{'rvsitebuilder'}{'expire-show'});
    }
    elsif ( exists $hLicenseInfo{'rvsitebuilder'}{'expire-date'} && $hLicenseInfo{'rvsitebuilder'}{'expire-date'} < time 
            || exists $hLicenseInfo{'issue_id'} && $hLicenseInfo{'issue_id'} == '501') 
    {
    	 my $expireShow = (exists $hLicenseInfo{'rvsitebuilder'}{'expire-date'}) 
    	       ? $hLicenseInfo{'rvsitebuilder'}{'expire-date'}
               : $hLicenseInfo{'issue_title'};
         
         my $issueDetail = '';
         my $issueId = ( exists $hLicenseInfo{'issue_id'} ) ? $hLicenseInfo{'issue_id'} : '';
         if ( $issueId == '501' ) {
         	my $issueType = ( exists $hLicenseInfo{'issue_type'} ) ? $hLicenseInfo{'issue_type'} : '';
         	if ($issueType == 0) {
         		$issueDetail = 'To avoid license suspended, please login to your account to renew at https://rvglobalsoft.com/clientarea -> "Account" -> "Invoices" and pay the pending invoice.';
         	} elsif ($issueType == 1) {
         		$issueDetail = 'To avoid license suspended, please login to your account to renew at https://rvglobalsoft.com/clientarea -> "Account" -> "Invoices" and pay the pending invoice.';
         	} elsif ($issueType == 3) {
                $issueDetail = 'Once your Trial license expired. You can make a new order for it https://rvglobalsoft.com/clientarea -> "Order" -> "Licenses" -> Select RVSitebuilder package you want.';
            }
            
            if ( $BROWSER ) {
            	$issueDetail =~ s#((;?http[s]?\:\/\/)?(;?[\da-z\.-]+)\.(;?[a-z\.]{2,6})(;?[\/\w\.\-\&\=]*)*\/?)#<a href="$1" target="_blank">$1</a>#gi;
            	$issueDetail =~ s#([\"][a-zA-Z]+[\"])#<b>$1</b>#gi;
            }
         }
         
         RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
         RVSInstaller::ScreenControl::DisplayMsg("Your license has expired. " . $expireShow . "\n$issueDetail", '', 'subMsg' . $ACTION);
         RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
         RVSInstaller::ScreenControl::LogMsg('Your license has expired. ' . $expireShow . "\n");
         RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, "Your license has expired.\n$issueDetail" . $expireShow);
    } else {
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
        if ( exists $hLicenseInfo{'on error'} && $hLicenseInfo{'on error'} ) {
        	@{$hParam{'BoxMessages'}} = ();
            RVSInstaller::ScreenControl::DisplayMsg($hLicenseInfo{'issue_title'}, '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            push( @{$hParam{'BoxMessages'}}, $hLicenseInfo{'issue_title'} );
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Error' , @{$hParam{'BoxMessages'}});
            RVSInstaller::ScreenControl::LogMsg($hLicenseInfo{'issue_id'} . ': ' . $hLicenseInfo{'issue_title'} . "\n");
            
            $hLicenseInfo{'issue_detail'} = _licenseErrorDetail(\%hLicenseInfo);
            RVSInstaller::ScreenControl::DisplayMsg($hLicenseInfo{'issue_detail'}, 1);
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, $hLicenseInfo{'issue_detail'} );
            RVSInstaller::ScreenControl::LogMsg($hLicenseInfo{'issue_detail'} . "\n");
        }
        else {
            RVSInstaller::ScreenControl::DisplayMsg("Cannot get license information form RVGlobalsoft site.", '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg("Cannot get license information form RVGlobalsoft site." . "\n");
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', "Cannot get license information form RVGlobalsoft site.");
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        }
        exitScript();
    }
    
    RVSInstaller::ScreenControl::CloseBoxMsg();
    callNextFunc(\%hParam);
}

#######################################################################################################################
#   Group Download Packages
#######################################################################################################################
sub Process_DownloadPackage{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( -e $InstallConf{'SourcePath'}) {
        RVSInstaller::Process::unlinkAll($InstallConf{'SourcePath'});
    }
    
    if ( !-e $InstallConf{'SourcePath'}) {
        mkdir($InstallConf{'SourcePath'}, 0755);
        chmod(0755, $InstallConf{'SourcePath'});
    }
    
    if (_isRequireConvUtf8()) {
        RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
        RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
        RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Backup native database before convert database to UTF-8") .'.', 1);
        RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
        RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
        
        if ($BROWSER) {
        	RVSInstaller::ScreenControl::jsSetFontColor('subMsg' . 'DownloadPackageLite', '#FF0000');
            #RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
            RVSInstaller::ScreenControl::DisplayMsg('The RVSiteBuilder require backup native database before convert database to UTF-8, but it cannot process in browser mode. Please run the installer on SSH as root: Run "perl ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/autoinstaller.cgi".' , 1, 'subMsg' . "DownloadPackageLite");
            RVSInstaller::ScreenControl::LogMsg('The RVSiteBuilder require backup native database before convert database to UTF-8, but it cannot process in browser mode. Please run the installer on SSH as root: Run "perl ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/autoinstaller.cgi".' . "\n");
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
            RVSInstaller::ScreenControl::DisplayMsg('The RVSiteBuilder require backup native database before convert database to UTF-8, but it cannot process in browser mode. Please run the installer on SSH as root: Run "perl ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/autoinstaller.cgi".', 1);
        
            # to This convert database proces require shell install', 1);
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', 'The RVSiteBuilder require backup native database before convert database to UTF-8, but it cannot process in browser mode. Please run the installer on SSH as root: Run "perl ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/autoinstaller.cgi".');
            exitScript();
        }
        
        my %rvsConf = {};
        if (-e $RVS_IP_CONF){
        	%rvsConf = getRVSiteBuilderConf($RVS_IP_CONF);
        } elsif (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php') {
        	%rvsConf = readINIfile($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php');
		    $rvsConf{'db'}= {};
		    $rvsConf{'db'}{'host'} = $rvsConf{'host'};
		    $rvsConf{'db'}{'port'} = $rvsConf{'dbPort'}{'port'};
		    $rvsConf{'db'}{'user'} = $rvsConf{'databaseUser'};
		    $rvsConf{'db'}{'pass'} = $rvsConf{'databaseUserPass'};
		    $rvsConf{'db'}{'name'} = $rvsConf{'name'};
        }

        #  my ($rvglobalPath) = '/var/cpanel/rvglobalsoft';
        my ($rvglobalPath) = $InstallConf{'cpModeConfigPath'}{'CompanyName'};
        #Is db native?
        #RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Backup database') . ' ' . $rvsConf{'db'}{'name'} . ' to path ' . $rvglobalPath . '/.rvsitebuilder/' . $rvsConf{'db'}{'name'} . '_v4.tar.bz2', '', 'subMsg' . $ACTION);
        my $backupDatabaseStatus = backupRVSiteBuilderDB($rvsConf{'db'}{'host'},$rvsConf{'db'}{'port'},$rvsConf{'db'}{'user'},$rvsConf{'db'}{'pass'},$rvsConf{'db'}{'name'}, $rvglobalPath . '/.rvsitebuilder');
        if ($backupDatabaseStatus) {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        } else {
            RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Failed') , '', 'subMsg' . "DownloadPackageLite");
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
            exitScript();
        }   
    } else {
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate("Database is already UTF-8 encoding"), 1);
    }
    #End backup native db
    
    #confirm upgrade V5
    _confirmUpgradetoV5();
    
    if ( $InstallConf{'cpMode'} eq 'da') {
        _updateRvslibrary();
    }
    
    RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Download Packages") .'.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Download Packages") . "\n");
    callNextFunc(\%hParam);
}

sub _updateRvslibrary{
    if (!-d '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library/banner_large/wpThumbnails'
        || !-d '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library/banner_medium/wpThumbnails'
        || !-d '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library/banner_small/wpThumbnails') {
        system('rm -rf /usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library');
    }
	if (!-d '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library/') {
	   system('rm -f /usr/local/rvglobalsoft/rvsitebuilder/var/rvsitebuildergraphic.md5');
	   system('rm -f /usr/local/rvglobalsoft/rvsitebuilder/var/rvsitebuildergraphic_pro.md5');
	}
}

#######################################################################################################################
#   Process Download RvSiteBuilder Pro Package ( under development ) for 5.4.xx ++
#######################################################################################################################
sub Process_DownloadPackagePro{
    my ( $param ) = $_[0];
    my ( %hParam ) = %{$param};
    
    if (!-d $InstallConf{'PackagePath'}) {
        system('mkdir -p ' . $InstallConf{'PackagePath'});
    }
        
    if ( !exists $hParam{'DownloadPackagePro'} ) {
        $hParam{'DownloadPackagePro'} = 'InformationPackagePro';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('RVSiteBuilder Core'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('RVSiteBuilder Core')), '', 'subMsg' . $ACTION);
        
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('RVSiteBuilder Core') . ' ');
        # <--  License RVSiteBuilder Core -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipPro ) {
            
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable') . "\n");
            $hParam{'DownloadPackagePro'} = 'Completed';
        } else {
        	
        	RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Download ' . $objLANG->TranSlate('RVSiteBuilder Core'), '');
            my ( $reqPackage, $productCode, $saveFilename, $nextStap );
            $hParam{'DownloadPackagePro'} = 'DownloadPackagePro';
            $reqPackage = 'rvsitebuilder-pro';
            
            my ( %OPT );
            $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/rvsitebuilder.md5';
            $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-core/md5file/rvsitebuilder.md5';
        	
             if ($hParam{'rollback'}) {
                    $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
             } elsif ( $hParam{'getversion'}) {
                    $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
             }
        
             $OPT{'logfile'} = $InstallConf{'SourcePath'} . '/.downloads.log';
             Register('saveas', $OPT{'saveas'});
             Register('URL', $OPT{'URL'});
             Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
             Connection();

            my ( $FD, $md5Conf );
            if (!-f $OPT{'saveas'}) {
                RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('failed' , 1, 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get package list of RVSiteBuilder Core.' . "\n");
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get package list of RVSiteBuilder Core.' . ".\n");
                exitScript();
            } else {
                open $FD, '<', $OPT{'saveas'};
                while ( <$FD> ) {
                    chomp;
                    next if (/^$/gi);
                    my ( $file, $md5file ) = split(/=/, $_, 2);
                    $md5Conf->{$file} = $md5file;
                }
                close( $FD );
            }
            
            my ( $oldPkConf );
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvsitebuilder.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvsitebuilder.md5';
                while ( <$FD> ) {
                chomp;
                    next if (/^$/gi);
                    my ( $file, $md5file ) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $oldPkConf->{$file} = $md5file;
                    }
                }
                close( $FD );
            }
            
            my ( @fileDownloads );
            foreach my $filename (sort keys %{$md5Conf}) {
                if ($filename =~/\.bz2$/i || $filename =~/\.gz$/i) {
                    if (defined $SCRIPT_OPT->{'force'} || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'rvsitebuilder'))) {
                        push(@fileDownloads, $filename);
                    } elsif (-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        my ( $oldpkdMD5 ) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $filename);
                        if ($md5Conf->{$filename} ne $oldpkdMD5) {
                            push(@fileDownloads, $filename);
                        }
                    } elsif (!defined $oldPkConf->{$filename} || $oldPkConf->{$filename} ne $md5Conf->{$filename} || !-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        push(@fileDownloads, $filename);
                    }
                }
            }

            $hParam{'PackageProConfiguration'}{'PackagesConfig'} = $md5Conf;
            $hParam{'PackageProConfiguration'}{'reqPackage'} = $reqPackage;
            
            push(@{$hParam{'PackageProConfiguration'}{'downloadFiles'}}, @fileDownloads);
            $hParam{'PackageProConfiguration'}{'downloadIndex'} = 0;
            $hParam{'PackageProConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
            $hParam{'PackageProConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
            $hParam{'PackageProConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
            $hParam{'PackageProConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
            
            if ( -e $hParam{'PackageProConfiguration'}{'LogFileName'} ) {
                unlink($hParam{'PackageProConfiguration'}{'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");
            
            if (scalar(@{$hParam{'PackageProConfiguration'}{'downloadFiles'}}) <=0 ) {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new package of RVSiteBuilder Core.' , '', 'subMsg' . $ACTION);
                # <-- Next Stap -->
                $hParam{'DownloadPackagePro'} = 'Completed';
            } else {
                my ( $fileIndexNum ) = $hParam{'PackageProConfiguration'}{'downloadIndex'}+1;
                my ( $filename ) = ${$hParam{'PackageProConfiguration'}{'downloadFiles'}}[$hParam{'PackageProConfiguration'}{'downloadIndex'}];
                my ( $msg ) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'PackageProConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                $hParam{'DownloadPackagePro'} = 'DownloadPackagePro';
            }
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadPackagePro'} && $hParam{'DownloadPackagePro'} eq 'DownloadPackagePro' ) {
        # <-- Download Package ->
        my ( $file ) = ${$hParam{'PackageProConfiguration'}{'downloadFiles'}}[$hParam{'PackageProConfiguration'}{'downloadIndex'}];
        my ( %OPT );
        
        $OPT{'saveas'} = $InstallConf{'SourcePath'} . '/' . $file;
        #$OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/rvsdownload/' . $file;
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-core/file/' . $file;
        
        if ($hParam{'rollback'}) {
            $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
        } elsif ( $hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }
        
        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
        Register('evalOutput', 1);
        Register('Showdot', 1);
        Register('format', "RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        Connection();
        RVSInstaller::ScreenControl::DisplayMsg('completed' , '1', 'subMsg' . $ACTION);
        
        chmod(0755, $OPT{'saveas'});
        
        if (!-e $InstallConf{'SourcePath'} . '/' . $file) {
            RVSInstaller::ScreenControl::DisplayMsg('Download '. $file . ' has failed!!!' , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Download '. $file . ' has failed!!!' . "\n");
            exitScript();
        }
        
        my ( $pkdMD5 ) =  RVSInstaller::Process::rvsMD5File($InstallConf{'SourcePath'} . '/' . $file);
        
        if (-e $InstallConf{'PackagePath'} . '/' . $file) {
            unlink($InstallConf{'PackagePath'} . '/' . $file);
        }
        
        move($InstallConf{'SourcePath'} . '/' . $file, $InstallConf{'PackagePath'} . '/' . $file);
        
        if ($pkdMD5 eq $hParam{'PackageProConfiguration'}{'PackagesConfig'}->{$file}) {
            $hParam{'PackageProConfiguration'}{'downloadIndex'} = $hParam{'PackageProConfiguration'}{'downloadIndex'}+1;
            if (scalar(@{$hParam{'PackageProConfiguration'}{'downloadFiles'}}) <= $hParam{'PackageProConfiguration'}{'downloadIndex'}) {
                
                my ($msg) = 'Download package of RVSiteBuilder Core(' . @{$hParam{'PackageProConfiguration'}{'downloadFiles'}} . ' files) completed.';
                RVSInstaller::ScreenControl::DisplayMsg($msg , '', 'subMsg' . $ACTION);
            # <-- Next Stap -->
                $hParam{'DownloadPackagePro'} = 'Completed';
            } else {
                my ( $fileIndexNum ) = $hParam{'PackageProConfiguration'}{'downloadIndex'}+1;
                my ( $filename ) = ${$hParam{'PackageProConfiguration'}{'downloadFiles'}}[$hParam{'PackageProConfiguration'}{'downloadIndex'}];
                my ( $msg ) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'PackageProConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                $hParam{'DownloadPackagePro'} = 'DownloadPackagePro';
            }
        } else {
            RVSInstaller::ScreenControl::DisplayMsg('Sorry, MD5 of '. $file . ' is invalid!!!' , '1', 'subMsg' . $ACTION);
            exitScript();
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadPackagePro'} && $hParam{'DownloadPackagePro'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#######################################################################################################################
#   Process Download Template For RVSiteBuilder Package ( under development )  v5.4.xx ++
#######################################################################################################################
#===================================== Full Template Package ==========================================
sub Process_DownloadTemplateFullPackage{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if($InstallConf{'on-demandTemplate'}){
    	#Skip if on-demand = yes : Download full template
    	RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Full Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Template Full Package')), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Full Package') . ' ');
    	RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip Template Full Package (On-demand Template [Yes]'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Skip Template Full Package (On-demand Template [Yes]'));
        $hParam{'DownloadTemplateFullPackage'} = 'Completed';
        
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
        return 1;
    }
    
    if ( !exists $hParam{'DownloadTemplateFullPackage'} ) {
        $hParam{'DownloadTemplateFullPackage'} = 'InformationTemplateFull';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Full Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Template Full Package')), '', 'subMsg' . $ACTION);
        
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Full Package') . ' ');
        # <-- License RVSiteBuilder -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemePro ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable') . "\n");
            $hParam{'DownloadTemplateFullPackage'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Download ' . $objLANG->TranSlate('Template'), '');
            my ($reqPackage, $productCode, $saveFilename, $nextStap);
            $hParam{'DownloadTemplateFullPackage'} = 'DownloadTemplateFullPackage';
            
            my (%OPT);
            $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/fullpackage.md5';
             if(!-e $InstallConf{'RVInstaller'} . '/skipinstall/.validatepackage') {
                $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-templatefullpackage/md5file/fullpackage.md5';
        
                if ($hParam{'rollback'}) {
                    $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
                } elsif ( $hParam{'getversion'}) {
                    $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
                }
        
                $OPT{'logfile'} = $InstallConf{'SourcePath'} . '/.downloads.log';
        
                Register('saveas', $OPT{'saveas'});
                Register('URL', $OPT{'URL'});
                Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
                Connection();
            }
            
            my ($FD, $md5Conf);
            if (!-f $OPT{'saveas'}) {
                RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('failed' , 1, 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation template full package list' . "\n");
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation template full package list' . ".\n");
                exitScript();
            } else {
                open $FD, '<', $OPT{'saveas'};
                while (<$FD>) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $md5Conf->{$file} = $md5file;
                }
                close($FD);
            }
            my ($oldPkConf);
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5';
                while(<$FD>) {
                chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $oldPkConf->{$file} = $md5file;
                    }
                }
                close($FD);
            }
        
            my (@fileDownloads);
            foreach my $filename (sort keys %{$md5Conf}) {
                if ($filename =~/\.bz2$/i || $filename =~/\.gz$/i) {
                    if (defined $SCRIPT_OPT->{'force'} || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'template'))) {
                        push(@fileDownloads, $filename);
                    } elsif (-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        my ($oldpkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $filename);
                        if ($md5Conf->{$filename} ne $oldpkdMD5) {
                            push(@fileDownloads, $filename);
                        }
                    } elsif (!defined $oldPkConf->{$filename} || $oldPkConf->{$filename} ne $md5Conf->{$filename}) {
                        push(@fileDownloads, $filename);
                    }
                }
            }
            
            $hParam{'TemplateFullConfiguration'}{'PackagesConfig'} = $md5Conf;
            $hParam{'TemplateFullConfiguration'}{'reqPackage'} = $reqPackage;
            
            push(@{$hParam{'TemplateFullConfiguration'}{'downloadFiles'}}, @fileDownloads);
            $hParam{'TemplateFullConfiguration'}{'downloadIndex'} = 0;
            $hParam{'TemplateFullConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
            $hParam{'TemplateFullConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
            $hParam{'TemplateFullConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
            $hParam{'TemplateFullConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
            
            if ( -e $hParam{'TemplateFullConfiguration'}{'LogFileName'} ) {
                unlink($hParam{'TemplateFullConfiguration'}{'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");
            
            if (scalar(@{$hParam{'TemplateFullConfiguration'}{'downloadFiles'}}) <=0 ) {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new template full package.' , '', 'subMsg' . $ACTION);
                # <-- Next Stap -->
                $hParam{'DownloadTemplateFullPackage'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'TemplateFullConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'TemplateFullConfiguration'}{'downloadFiles'}}[$hParam{'TemplateFullConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'TemplateFullConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            }
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadTemplateFullPackage'} && $hParam{'DownloadTemplateFullPackage'} eq 'DownloadTemplateFullPackage' ) {
        # <-- Download Package ->
        my ($file) = ${$hParam{'TemplateFullConfiguration'}{'downloadFiles'}}[$hParam{'TemplateFullConfiguration'}{'downloadIndex'}];
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/' . $file;
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-templatefullpackage/file/' . $file;
        if ($hParam{'rollback'}) {
            $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
        }
        elsif ( $hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }

        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
        Register('evalOutput', 1);
        Register('Showdot', 1);
        Register('format', "RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        Connection();
        RVSInstaller::ScreenControl::DisplayMsg('completed' , '1', 'subMsg' . $ACTION);
        chmod(0755, $OPT{'saveas'});
        if (!-e $InstallConf{'PackagePath'} . '/' . $file) {
            RVSInstaller::ScreenControl::DisplayMsg('Download '. $file . ' has failed!!!' , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Download '. $file . ' has failed!!!' . "\n");
            exitScript();
        }
        my ($pkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $file);
        if (-e $InstallConf{'PackagePath'} . '/' . $file) {
            #unlink($InstallConf{'PackagePath'} . '/' . $file);
        }
        #move($InstallConf{'SourcePath'} . '/' . $file, $InstallConf{'PackagePath'} . '/' . $file);
        
        if ($pkdMD5 eq $hParam{'TemplateFullConfiguration'}{'PackagesConfig'}->{$file}) {
            $hParam{'TemplateFullConfiguration'}{'downloadIndex'} = $hParam{'TemplateFullConfiguration'}{'downloadIndex'}+1;
            if (scalar(@{$hParam{'TemplateFullConfiguration'}{'downloadFiles'}}) <= $hParam{'TemplateFullConfiguration'}{'downloadIndex'}) {
                
                my ($msg) = 'Download full template of RVSiteBuilder (' . @{$hParam{'TemplateFullConfiguration'}{'downloadFiles'}} . ' files) completed.';
                RVSInstaller::ScreenControl::DisplayMsg($msg , '', 'subMsg' . $ACTION);
            # <-- Next Stap -->
                $hParam{'DownloadTemplateFullPackage'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'TemplateFullConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'TemplateFullConfiguration'}{'downloadFiles'}}[$hParam{'TemplateFullConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'TemplateFullConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                $hParam{'DownloadTemplateFullPackage'} = 'DownloadTemplateFullPackage';
            }
        } else {
            RVSInstaller::ScreenControl::DisplayMsg('Sorry, MD5 of '. $file . '(' . $pkdMD5 . '/' . $hParam{'TemplateFullConfiguration'}{'PackagesConfig'}->{$file} . ') is invalid!!!' , '1', 'subMsg' . $ACTION);
            exitScript();
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadTemplateFullPackage'} && $hParam{'DownloadTemplateFullPackage'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#===================================== On-demand template ==========================================
sub Process_DownloadTemplatePro{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if(!$InstallConf{'on-demandTemplate'}){
    	#Skip if on-demand = no
    	RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Preview Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Template Preview Package')), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Preview Package') . ' ');
    	RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip Template Preview Package (On-demand Template [No]'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Skip Template Preview Package (On-demand Template [No]'));
        $hParam{'DownloadTemplatePro'} = 'Completed';
        
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
        return 1;
    }
    
    if ( !exists $hParam{'DownloadTemplatePro'} ) {
        $hParam{'DownloadTemplatePro'} = 'InformationTemplatePro';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Preview Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Template Preview Package')), '', 'subMsg' . $ACTION);
        
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Preview Package') . ' ');
        # <-- License RVSiteBuilder -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemePro ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable') . "\n");
            $hParam{'DownloadTemplatePro'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Download ' . $objLANG->TranSlate('Template'), '');
            my ($reqPackage, $productCode, $saveFilename, $nextStap);
            $hParam{'DownloadTemplatePro'} = 'DownloadTemplatePro';
            
            my (%OPT);
            $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/templatepreview.md5';
             if(!-e $InstallConf{'RVInstaller'} . '/skipinstall/.validatepackage') {
                $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-templatepreview/md5file/templatepreview.md5';
        
                if ($hParam{'rollback'}) {
                    $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
                } elsif ( $hParam{'getversion'}) {
                    $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
                }
        
                $OPT{'logfile'} = $InstallConf{'SourcePath'} . '/.downloads.log';
        
                Register('saveas', $OPT{'saveas'});
                Register('URL', $OPT{'URL'});
                Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
                Connection();
            }
            
            my ($FD, $md5Conf);
            if (!-f $OPT{'saveas'}) {
                RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('failed' , 1, 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation template preview list' . "\n");
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation template preview list' . ".\n");
                exitScript();
            } else {
                open $FD, '<', $OPT{'saveas'};
                while (<$FD>) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $md5Conf->{$file} = $md5file;
                }
                close($FD);
            }
            my ($oldPkConf);
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5';
                while(<$FD>) {
                chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $oldPkConf->{$file} = $md5file;
                    }
                }
                close($FD);
            }
        
            my (@fileDownloads);
            foreach my $filename (sort keys %{$md5Conf}) {
                if ($filename =~/\.bz2$/i || $filename =~/\.gz$/i) {
                    if (defined $SCRIPT_OPT->{'force'} || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'template'))) {
                        push(@fileDownloads, $filename);
                    } elsif (-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        my ($oldpkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $filename);
                        if ($md5Conf->{$filename} ne $oldpkdMD5) {
                            push(@fileDownloads, $filename);
                        }
                    } elsif (!defined $oldPkConf->{$filename} || $oldPkConf->{$filename} ne $md5Conf->{$filename}) {
                        push(@fileDownloads, $filename);
                    }
                }
            }
            
            $hParam{'TemplateProConfiguration'}{'PackagesConfig'} = $md5Conf;
            $hParam{'TemplateProConfiguration'}{'reqPackage'} = $reqPackage;
            
            push(@{$hParam{'TemplateProConfiguration'}{'downloadFiles'}}, @fileDownloads);
            $hParam{'TemplateProConfiguration'}{'downloadIndex'} = 0;
            $hParam{'TemplateProConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
            $hParam{'TemplateProConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
            $hParam{'TemplateProConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
            $hParam{'TemplateProConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
            
            if ( -e $hParam{'TemplateProConfiguration'}{'LogFileName'} ) {
                unlink($hParam{'TemplateProConfiguration'}{'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");
            
            if (scalar(@{$hParam{'TemplateProConfiguration'}{'downloadFiles'}}) <=0 ) {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new template preview package.' , '', 'subMsg' . $ACTION);
                # <-- Next Stap -->
                $hParam{'DownloadTemplatePro'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'TemplateProConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'TemplateProConfiguration'}{'downloadFiles'}}[$hParam{'TemplateProConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'TemplateProConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            }
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadTemplatePro'} && $hParam{'DownloadTemplatePro'} eq 'DownloadTemplatePro' ) {
        # <-- Download Package ->
        my ($file) = ${$hParam{'TemplateProConfiguration'}{'downloadFiles'}}[$hParam{'TemplateProConfiguration'}{'downloadIndex'}];
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/' . $file;
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-templatepreview/file/' . $file;
        if ($hParam{'rollback'}) {
            $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
        }
        elsif ( $hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }

        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
        Register('evalOutput', 1);
        Register('Showdot', 1);
        Register('format', "RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        Connection();
        RVSInstaller::ScreenControl::DisplayMsg('completed' , '1', 'subMsg' . $ACTION);
        chmod(0755, $OPT{'saveas'});
        if (!-e $InstallConf{'PackagePath'} . '/' . $file) {
            RVSInstaller::ScreenControl::DisplayMsg('Download '. $file . ' has failed!!!' , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Download '. $file . ' has failed!!!' . "\n");
            exitScript();
        }
        my ($pkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $file);
        if (-e $InstallConf{'PackagePath'} . '/' . $file) {
            #unlink($InstallConf{'PackagePath'} . '/' . $file);
        }
        #move($InstallConf{'SourcePath'} . '/' . $file, $InstallConf{'PackagePath'} . '/' . $file);
        
        if ($pkdMD5 eq $hParam{'TemplateProConfiguration'}{'PackagesConfig'}->{$file}) {
            $hParam{'TemplateProConfiguration'}{'downloadIndex'} = $hParam{'TemplateProConfiguration'}{'downloadIndex'}+1;
            if (scalar(@{$hParam{'TemplateProConfiguration'}{'downloadFiles'}}) <= $hParam{'TemplateProConfiguration'}{'downloadIndex'}) {
                
                my ($msg) = 'Download template of RVSiteBuilder (' . @{$hParam{'TemplateProConfiguration'}{'downloadFiles'}} . ' files) completed.';
                RVSInstaller::ScreenControl::DisplayMsg($msg , '', 'subMsg' . $ACTION);
            # <-- Next Stap -->
                $hParam{'DownloadTemplatePro'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'TemplateProConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'TemplateProConfiguration'}{'downloadFiles'}}[$hParam{'TemplateProConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'TemplateProConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                $hParam{'DownloadTemplatePro'} = 'DownloadTemplatePro';
            }
        } else {
            RVSInstaller::ScreenControl::DisplayMsg('Sorry, MD5 of '. $file . '(' . $pkdMD5 . '/' . $hParam{'TemplateProConfiguration'}{'PackagesConfig'}->{$file} . ') is invalid!!!' , '1', 'subMsg' . $ACTION);
            exitScript();
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadTemplatePro'} && $hParam{'DownloadTemplatePro'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#######################################################################################################################
#   Process Download Template Library For RVSiteBuilder Package ( under development )  v5.4.xx ++
#######################################################################################################################
sub Process_DownloadTemplateLibrary{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( !exists $hParam{'DownloadTemplateLibrary'} ) {
        $hParam{'DownloadTemplateLibrary'} = 'InformationTemplateLibrary';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Library Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Template Library Package')), '', 'subMsg' . $ACTION);
        
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Library Package') . ' ');
        # <-- License RVSiteBuilder -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemePro ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable') . "\n");
            $hParam{'DownloadTemplateLibrary'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Download ' . $objLANG->TranSlate('Template Library Package'), '');
            my ($reqPackage, $productCode, $saveFilename, $nextStap);
            $hParam{'DownloadTemplateLibrary'} = 'DownloadTemplateLibrary';
            
            my (%OPT);
            $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/library.md5';
             if(!-e $InstallConf{'RVInstaller'} . '/skipinstall/.validatepackage') {
                $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-library/md5file/library.md5';
        
                if ($hParam{'rollback'}) {
                    $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
                } elsif ( $hParam{'getversion'}) {
                    $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
                }
        
                $OPT{'logfile'} = $InstallConf{'SourcePath'} . '/.downloads.log';
        
                Register('saveas', $OPT{'saveas'});
                Register('URL', $OPT{'URL'});
                Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
                Connection();
            }
            
            my ($FD, $md5Conf);
            if (!-f $OPT{'saveas'}) {
                RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('failed' , 1, 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation template library package list' . "\n");
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation template library package list' . ".\n");
                exitScript();
            } else {
                open $FD, '<', $OPT{'saveas'};
                while (<$FD>) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $md5Conf->{$file} = $md5file;
                }
                close($FD);
            }
            my ($oldPkConf);
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/library.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/library.md5';
                while(<$FD>) {
                chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $oldPkConf->{$file} = $md5file;
                    }
                }
                close($FD);
            }
        
            my @fileDownloads = ();
            foreach my $filename (sort keys %{$md5Conf}) {
                if ($filename =~/\.bz2$/i || $filename =~/\.gz$/i) {
                    if (defined $SCRIPT_OPT->{'force'} || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'template'))) {
                        push(@fileDownloads, $filename);
                    } elsif (-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        my ($oldpkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $filename);
                        if ($md5Conf->{$filename} ne $oldpkdMD5) {
                            push(@fileDownloads, $filename);
                        }
                    } elsif (!defined $oldPkConf->{$filename} || $oldPkConf->{$filename} ne $md5Conf->{$filename}) {
                        push(@fileDownloads, $filename);
                    }
                }
            }
            
            $hParam{'TemplateProConfiguration'}{'PackagesConfig'} = $md5Conf;
            $hParam{'TemplateProConfiguration'}{'reqPackage'} = $reqPackage;
            
            push(@{$hParam{'TemplateProConfiguration'}{'downloadFiles'}}, @fileDownloads);
            $hParam{'TemplateProConfiguration'}{'downloadIndex'} = 0;
            $hParam{'TemplateProConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
            $hParam{'TemplateProConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
            $hParam{'TemplateProConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
            $hParam{'TemplateProConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
            
            if ( -e $hParam{'TemplateProConfiguration'}{'LogFileName'} ) {
                unlink($hParam{'TemplateProConfiguration'}{'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");
            
            if (scalar(@{$hParam{'TemplateProConfiguration'}{'downloadFiles'}}) <=0 ) {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new template library of RVSiteBuilder .' , '', 'subMsg' . $ACTION);
                # <-- Next Stap -->
                $hParam{'DownloadTemplateLibrary'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'TemplateProConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'TemplateProConfiguration'}{'downloadFiles'}}[$hParam{'TemplateProConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'TemplateProConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            }
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadTemplateLibrary'} && $hParam{'DownloadTemplateLibrary'} eq 'DownloadTemplateLibrary' ) {
        # <-- Download Package ->
        my ($file) = ${$hParam{'TemplateProConfiguration'}{'downloadFiles'}}[$hParam{'TemplateProConfiguration'}{'downloadIndex'}];
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/' . $file;
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-library/file/' . $file;
        if ($hParam{'rollback'}) {
            $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
        }
        elsif ( $hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }

        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
        Register('evalOutput', 1);
        Register('Showdot', 1);
        Register('format', "RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        Connection();
        RVSInstaller::ScreenControl::DisplayMsg('completed' , '1', 'subMsg' . $ACTION);
        chmod(0755, $OPT{'saveas'});
        if (!-e $InstallConf{'PackagePath'} . '/' . $file) {
            RVSInstaller::ScreenControl::DisplayMsg('Download '. $file . ' has failed!!!' , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Download '. $file . ' has failed!!!' . "\n");
            exitScript();
        }
        my ($pkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $file);
        if (-e $InstallConf{'PackagePath'} . '/' . $file) {
            #unlink($InstallConf{'PackagePath'} . '/' . $file);
        }
        #move($InstallConf{'SourcePath'} . '/' . $file, $InstallConf{'PackagePath'} . '/' . $file);
        
        if ($pkdMD5 eq $hParam{'TemplateProConfiguration'}{'PackagesConfig'}->{$file}) {
            $hParam{'TemplateProConfiguration'}{'downloadIndex'} = $hParam{'TemplateProConfiguration'}{'downloadIndex'}+1;
            if (scalar(@{$hParam{'TemplateProConfiguration'}{'downloadFiles'}}) <= $hParam{'TemplateProConfiguration'}{'downloadIndex'}) {
                
                my ($msg) = 'Download template of RVSiteBuilder (' . @{$hParam{'TemplateProConfiguration'}{'downloadFiles'}} . ' files) completed.';
                RVSInstaller::ScreenControl::DisplayMsg($msg , '', 'subMsg' . $ACTION);
            # <-- Next Stap -->
                $hParam{'DownloadTemplateLibrary'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'TemplateProConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'TemplateProConfiguration'}{'downloadFiles'}}[$hParam{'TemplateProConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'TemplateProConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                $hParam{'DownloadTemplateLibrary'} = 'DownloadTemplateLibrary';
            }
        } else {
            RVSInstaller::ScreenControl::DisplayMsg('Sorry, MD5 of '. $file . '(' . $pkdMD5 . '/' . $hParam{'TemplateProConfiguration'}{'PackagesConfig'}->{$file} . ') is invalid!!!' , '1', 'subMsg' . $ACTION);
            exitScript();
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadTemplateLibrary'} && $hParam{'DownloadTemplateLibrary'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#######################################################################################################################
#   Process Download RVseagullMod Library For RVSiteBuilder Package ( under development )  v5.4.xx ++
#######################################################################################################################
sub Process_DownloadRvlibrary{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( !exists $hParam{'DownloadRvlibrary'} ) {
        $hParam{'DownloadRvlibrary'} = 'InformationRvlibrary';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Rvlibrary'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Rvlibrary')), '', 'subMsg' . $ACTION);
        
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Rvlibrary') . ' ');
        # <-- License RVSiteBuilder -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemePro ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable') . "\n");
            $hParam{'DownloadRvlibrary'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Download ' . $objLANG->TranSlate('Rvlibrary'), '');
            my ($reqPackage, $productCode, $saveFilename, $nextStap);
            $hParam{'DownloadRvlibrary'} = 'DownloadRvlibrary';
            
            my (%OPT);
            $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/rvseagullmod.md5';
            
             if(!-e $InstallConf{'RVInstaller'} . '/skipinstall/.validatepackage') {
                $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-rvseagullmod/md5file/rvseagullmod.md5';
        
                if ($hParam{'rollback'}) {
                    $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
                } elsif ( $hParam{'getversion'}) {
                    $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
                }
        
                $OPT{'logfile'} = $InstallConf{'SourcePath'} . '/.downloads.log';
        
                Register('saveas', $OPT{'saveas'});
                Register('URL', $OPT{'URL'});
                Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
                Connection();
            }
            
            my ($FD, $md5Conf);
            if (!-f $OPT{'saveas'}) {
                RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('failed' , 1, 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation Rvlibrary of RVSiteBuilder list' . "\n");
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation Rvlibrary of RVSiteBuilder list' . ".\n");
                exitScript();
            } else {
                open $FD, '<', $OPT{'saveas'};
                while (<$FD>) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $md5Conf->{$file} = $md5file;
                }
                close($FD);
                #copy($OPT{'saveas'}, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvseagullmod.md5');
            }
            my ($oldPkConf);
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvseagullmod.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvseagullmod.md5';
                while(<$FD>) {
                chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i || $file =~/\.tgz$/i) {
                        $oldPkConf->{$file} = $md5file;
                    }
                }
                close($FD);
            }
        
            my (@fileDownloads);
            foreach my $filename (sort keys %{$md5Conf}) {
                if ($filename =~/\.bz2$/i || $filename =~/\.gz$/i || $filename =~/\.tgz$/i) {
                    if (defined $SCRIPT_OPT->{'force'}  || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'rvseagullmod'))) {
                        push(@fileDownloads, $filename);
                    } elsif (-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        my ($oldpkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $filename);
                        if ($md5Conf->{$filename} ne $oldpkdMD5) {
                            push(@fileDownloads, $filename);
                        }
                    } elsif (!defined $oldPkConf->{$filename} || $oldPkConf->{$filename} ne $md5Conf->{$filename}) {
                        push(@fileDownloads, $filename);
                    }
                }
            }
            
            $hParam{'RvlibraryConfiguration'}{'PackagesConfig'} = $md5Conf;
            $hParam{'RvlibraryConfiguration'}{'reqPackage'} = $reqPackage;
            
            push(@{$hParam{'RvlibraryConfiguration'}{'downloadFiles'}}, @fileDownloads);
            $hParam{'RvlibraryConfiguration'}{'downloadIndex'} = 0;
            $hParam{'RvlibraryConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
            $hParam{'RvlibraryConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
            $hParam{'RvlibraryConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
            $hParam{'RvlibraryConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
            
            if ( -e $hParam{'RvlibraryConfiguration'}{'LogFileName'} ) {
                unlink($hParam{'RvlibraryConfiguration'}{'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");
            
            if (scalar(@{$hParam{'RvlibraryConfiguration'}{'downloadFiles'}}) <=0 ) {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new Rvlibrary of RVSiteBuilder .' , '', 'subMsg' . $ACTION);
                # <-- Next Stap -->
                $hParam{'DownloadRvlibrary'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'RvlibraryConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'RvlibraryConfiguration'}{'downloadFiles'}}[$hParam{'RvlibraryConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'RvlibraryConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            }
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadRvlibrary'} && $hParam{'DownloadRvlibrary'} eq 'DownloadRvlibrary' ) {
        # <-- Download Package ->
        my ($file) = ${$hParam{'RvlibraryConfiguration'}{'downloadFiles'}}[$hParam{'RvlibraryConfiguration'}{'downloadIndex'}];
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/' . $file;
        unlink($OPT{'saveas'}) if(-f $OPT{'saveas'});
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-rvseagullmod/file/' . $file;
        if ($hParam{'rollback'}) {
            $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
        }
        elsif ( $hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }

        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
        Register('evalOutput', 1);
        Register('Showdot', 1);
        Register('format', "RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        Connection();
        RVSInstaller::ScreenControl::DisplayMsg('completed' , '1', 'subMsg' . $ACTION);
        chmod(0755, $OPT{'saveas'});
        if (!-e $InstallConf{'PackagePath'} . '/' . $file) {
            RVSInstaller::ScreenControl::DisplayMsg('Download '. $file . ' has failed!!!' , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Download '. $file . ' has failed!!!' . "\n");
            exitScript();
        }
        my ($pkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $file);
        if (-e $InstallConf{'PackagePath'} . '/' . $file) {
            #unlink($InstallConf{'PackagePath'} . '/' . $file);
        }
        #move($InstallConf{'SourcePath'} . '/' . $file, $InstallConf{'PackagePath'} . '/' . $file);
        
        if ($pkdMD5 eq $hParam{'RvlibraryConfiguration'}{'PackagesConfig'}->{$file}) {
            $hParam{'RvlibraryConfiguration'}{'downloadIndex'} = $hParam{'RvlibraryConfiguration'}{'downloadIndex'}+1;
            if (scalar(@{$hParam{'RvlibraryConfiguration'}{'downloadFiles'}}) <= $hParam{'RvlibraryConfiguration'}{'downloadIndex'}) {
                
                my ($msg) = 'Download Rvlibrary of RVSiteBuilder (' . @{$hParam{'RvlibraryConfiguration'}{'downloadFiles'}} . ' files) completed.';
                RVSInstaller::ScreenControl::DisplayMsg($msg , '', 'subMsg' . $ACTION);
            # <-- Next Stap -->
                $hParam{'DownloadRvlibrary'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'RvlibraryConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'RvlibraryConfiguration'}{'downloadFiles'}}[$hParam{'RvlibraryConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{''}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                $hParam{'DownloadRvlibrary'} = 'DownloadRvlibrary';
            }
        } else {
            RVSInstaller::ScreenControl::DisplayMsg('Sorry, MD5 of '. $file . '(' . $pkdMD5 . '/' . $hParam{'RvlibraryConfiguration'}{'PackagesConfig'}->{$file} . ') is invalid!!!' , '1', 'subMsg' . $ACTION);
            exitScript();
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadRvlibrary'} && $hParam{'DownloadRvlibrary'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#######################################################################################################################
#   Process Download Language For RVSiteBuilder Package ( under development )  v5.4.xx ++
#######################################################################################################################
sub Process_DownloadLanguage{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( !exists $hParam{'DownloadLanguage'} ) {
        $hParam{'DownloadLanguage'} = 'InformationLanguage';
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Language'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx package information', $objLANG->TranSlate('Language')), '', 'subMsg' . $ACTION);
        
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Language') . ' ');
        # <-- License RVSiteBuilder Pro -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemePro ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable') . "\n");
            $hParam{'DownloadLanguage'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, 'Download ' . $objLANG->TranSlate('Language'), '');
            my ($reqPackage, $productCode, $saveFilename, $nextStap);
            $hParam{'DownloadLanguage'} = 'DownloadLanguage';
            
            my (%OPT);
            $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/language.md5';
             if(!-e $InstallConf{'RVInstaller'} . '/skipinstall/.validatepackage') {
                $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-language/md5file/language.md5';
        
                if ($hParam{'rollback'}) {
                    $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
                } elsif ( $hParam{'getversion'}) {
                    $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
                }
        
                $OPT{'logfile'} = $InstallConf{'SourcePath'} . '/.downloads.log';
        
                Register('saveas', $OPT{'saveas'});
                Register('URL', $OPT{'URL'});
                Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
                Connection();
            }
            
            my ($FD, $md5Conf);
            if (!-f $OPT{'saveas'}) {
                RVSInstaller::ScreenControl::DisplayMsg("\t$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('failed' , 1, 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation Language of RVSiteBuilder list' . "\n");
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::LogMsg('Sorry, cannot get configulation Language of RVSiteBuilder list' . ".\n");
                exitScript();
            } else {
                open $FD, '<', $OPT{'saveas'};
                while (<$FD>) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $md5Conf->{$file} = $md5file;
                }
                close($FD);
                #move($OPT{'saveas'}, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5');
            }
            my ($oldPkConf);
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/language.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/language.md5';
                while(<$FD>) {
                chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $oldPkConf->{$file} = $md5file;
                    }
                }
                close($FD);
            }
        
            my (@fileDownloads);
            foreach my $filename (sort keys %{$md5Conf}) {
                if ($filename =~/\.bz2$/i || $filename =~/\.gz$/i) {
                    if (defined $SCRIPT_OPT->{'force'}  || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'language'))) {
                        push(@fileDownloads, $filename);
                    } elsif (-e $InstallConf{'PackagePath'} . '/' . $filename) {
                        my ($oldpkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $filename);
                        if ($md5Conf->{$filename} ne $oldpkdMD5) {
                            push(@fileDownloads, $filename);
                        }
                    } elsif (!defined $oldPkConf->{$filename} || $oldPkConf->{$filename} ne $md5Conf->{$filename}) {
                        push(@fileDownloads, $filename);
                    }
                }
            }
            
            $hParam{'LanguageConfiguration'}{'PackagesConfig'} = $md5Conf;
            $hParam{'LanguageConfiguration'}{'reqPackage'} = $reqPackage;
            
            push(@{$hParam{'LanguageConfiguration'}{'downloadFiles'}}, @fileDownloads);
            $hParam{'LanguageConfiguration'}{'downloadIndex'} = 0;
            $hParam{'LanguageConfiguration'}{'ProductCode'} = $InstallConf{'Packages'}{$reqPackage}{'ProductCode'};
            $hParam{'LanguageConfiguration'}{'ProductName'} = $InstallConf{'Packages'}{$reqPackage}{'ProductName'};
            $hParam{'LanguageConfiguration'}{'SaveFilename'} = $InstallConf{'Packages'}{$reqPackage}{'SaveFilename'};
            $hParam{'LanguageConfiguration'}{'LogFileName'} = $InstallConf{'SourcePath'} . '/.rvsdownloadlog';
            
            if ( -e $hParam{'LanguageConfiguration'}{'LogFileName'} ) {
                unlink($hParam{'LanguageConfiguration'}{'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");
            
            if (scalar(@{$hParam{'LanguageConfiguration'}{'downloadFiles'}}) <=0 ) {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new Language of RVSiteBuilder .' , '', 'subMsg' . $ACTION);
                # <-- Next Stap -->
                $hParam{'DownloadLanguage'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'LanguageConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'LanguageConfiguration'}{'downloadFiles'}}[$hParam{'LanguageConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{'LanguageConfiguration'}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            }
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadLanguage'} && $hParam{'DownloadLanguage'} eq 'DownloadLanguage' ) {
        # <-- Download Package ->
        my ($file) = ${$hParam{'LanguageConfiguration'}{'downloadFiles'}}[$hParam{'LanguageConfiguration'}{'downloadIndex'}];
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'PackagePath'} . '/' . $file;
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'download'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'download'}{'uri'}{'site1'} . '/download/rvsitebuilder-language/file/' . $file;
        if ($hParam{'rollback'}) {
            $OPT{'URL'} .= '/requireversion/' . $hParam{'rollback'};
        }
        elsif ( $hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }

        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('logfile', $InstallConf{'SourcePath'} . '/.downloads.log');
        Register('evalOutput', 1);
        Register('Showdot', 1);
        Register('format', "RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        Connection();
        RVSInstaller::ScreenControl::DisplayMsg('completed' , '1', 'subMsg' . $ACTION);
        chmod(0755, $OPT{'saveas'});
        if (!-e $InstallConf{'PackagePath'} . '/' . $file) {
            RVSInstaller::ScreenControl::DisplayMsg('Download '. $file . ' has failed!!!' , '1', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Download '. $file . ' has failed!!!' . "\n");
            exitScript();
        }
        my ($pkdMD5) =  RVSInstaller::Process::rvsMD5File($InstallConf{'PackagePath'} . '/' . $file);
        if (-e $InstallConf{'PackagePath'} . '/' . $file) {
            #unlink($InstallConf{'PackagePath'} . '/' . $file);
        }
        #move($InstallConf{'SourcePath'} . '/' . $file, $InstallConf{'PackagePath'} . '/' . $file);
        
        if ($pkdMD5 eq $hParam{'LanguageConfiguration'}{'PackagesConfig'}->{$file}) {
            $hParam{'LanguageConfiguration'}{'downloadIndex'} = $hParam{'LanguageConfiguration'}{'downloadIndex'}+1;
            if (scalar(@{$hParam{'LanguageConfiguration'}{'downloadFiles'}}) <= $hParam{'LanguageConfiguration'}{'downloadIndex'}) {
                
                my ($msg) = 'Download Language of RVSiteBuilder (' . @{$hParam{'LanguageConfiguration'}{'downloadFiles'}} . ' files) completed.';
                RVSInstaller::ScreenControl::DisplayMsg($msg , '', 'subMsg' . $ACTION);
            # <-- Next Stap -->
                $hParam{'DownloadLanguage'} = 'Completed';
            } else {
                my ($fileIndexNum) = $hParam{'LanguageConfiguration'}{'downloadIndex'}+1;
                my ($filename) = ${$hParam{'LanguageConfiguration'}{'downloadFiles'}}[$hParam{'LanguageConfiguration'}{'downloadIndex'}];
                my ($msg) = "Downloading $filename (" . $fileIndexNum . '/' .  @{$hParam{''}{'downloadFiles'}} . ')... ';
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
                $hParam{'DownloadLanguage'} = 'DownloadLanguage';
            }
        } else {
            RVSInstaller::ScreenControl::DisplayMsg('Sorry, MD5 of '. $file . '(' . $pkdMD5 . '/' . $hParam{'RvlibraryConfiguration'}{'PackagesConfig'}->{$file} . ') is invalid!!!' , '1', 'subMsg' . $ACTION);
            exitScript();
        }
        StepRedirect(\%hParam);
    } elsif ( exists $hParam{'DownloadLanguage'} && $hParam{'DownloadLanguage'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

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

#######################################################################################################################
#   Process Uncompress RVSiteBuilder Package
#######################################################################################################################
sub Process_UncompressPro{
	my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if (-l $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www') {
         system('unlink ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www');
    }
    if ( !exists $hParam{'UncompressPro'}) {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('RVSiteBuilder Core'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the RVSiteBuilder license'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the RVSiteBuilder license'));
    }
    
    # <-- License RVSiteBuilder -->
    my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
    $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
    
    if ( !exists $hParam{'UncompressPro'} && (!$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
    $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipPro) ) {
    	
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable'));
            
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    } else {
    	if ( !exists $hParam{'UncompressPro'} ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate('Uncompress Package') . ' ' . $objLANG->TranSlate('RVSiteBuilder Core'), '');
            RVSInstaller::ScreenControl::DisplayMsg('', '1');
            #RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('RVSiteBuilder Lite'), '1');
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the xxx package', $objLANG->TranSlate('RVSiteBuilder Core')), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the xxx package', $objLANG->TranSlate('RVSiteBuilder Core')));
    
            my ($saveFilename );
            
            if ( !-e $InstallConf{'PackagePath'} . '/rvsitebuilder.md5') {
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('Find not found the package list of RVSiteBuilder.', '', 'subMsg' . $ACTION, '', '#FF0000');
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg('Find not found the package list of RVSiteBuilder.');
                $hParam{'UncompressPro'} = 'Completed';
            } else {
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Ready') , '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Ready'));
            
                my ( $newPkConf, $oldPkConf );
                open my $FD, '<' , $InstallConf{'PackagePath'} . '/rvsitebuilder.md5';
                while ( <$FD> ) {
                    chomp;
                    next if (/^$/gi);
                    my ( $file, $md5file ) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $newPkConf->{$file} = $md5file;
                    }
                }
                close( $FD );
                
                if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvsitebuilder.md5') {
                    open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvsitebuilder.md5';
                    while( <$FD> ) {
                        chomp;
                        next if (/^$/gi);
                        my ( $file, $md5file ) = split(/=/, $_, 2);
                        if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                            $oldPkConf->{$file} = $md5file;
                        }
                    }
                    close( $FD );
                } 
          
                foreach my $newpkfile (keys %{$newPkConf}) {
                	if (defined $SCRIPT_OPT->{'force'} || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'rvsitebuilder'))) {
                		push(@{$hParam{'UncompressProFileLists'}}, $newpkfile);
                		next;
                	}
                	next if(defined $oldPkConf->{$newpkfile} && $oldPkConf->{$newpkfile} eq $newPkConf->{$newpkfile});
                    push(@{$hParam{'UncompressProFileLists'}}, $newpkfile);
                }
                
	            if (defined $hParam{'UncompressProFileLists'} && scalar(@{$hParam{'UncompressProFileLists'}}) > 0) {
	            	@{$hParam{'UncompressProFileLists'}} = sort(@{$hParam{'UncompressProFileLists'}});
	                $hParam{'UncompressPro'} = 'Uncompress';
	                $hParam{'UncompressProMD5'} = $newPkConf;
	                my ( $filename ) = ${$hParam{'UncompressProFileLists'}}[0];
	                my ( $msg ) = "Extract $filename ... ";
	                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
	                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
	            } else {
	                RVSInstaller::ScreenControl::DisplayMsg('Not have new RVSiteBuilder.', '1', 'subMsg' . $ACTION);
	                $hParam{'UncompressPro'} = 'Completed';
	            }
            }
            StepRedirect(\%hParam);
    	} elsif (exists $hParam{'UncompressPro'} && $hParam{'UncompressPro'} eq 'Uncompress' ) {
    		if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'}) {
                system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} , '>/dev/null');
            }
            if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var') {
                system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var' , '>/dev/null');
            }
    		
    		my ($extractfile) = shift(@{$hParam{'UncompressProFileLists'}});
        
            if (!-e $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template') {
            	system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template' , '>/dev/null');
            }
            
            open PID, $cmd_tar . ' -jxvf ' . $InstallConf{'PackagePath'} . '/' . $extractfile . ' -C ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '|'; 
            while (<PID>) {
            	RVSInstaller::ScreenControl::LogMsg("Extract $extractfile: $_");
                #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $extractfile, $_);    
            }
            close(PID);
            
            open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvsitebuilder.md5';
            my (@piers) = <$FD>;
            close($FD);
        
            open $FD, '>' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvsitebuilder.md5';
            foreach my $inline (@piers) {
                if ($inline=~/^$extractfile=i/) {
                    next;
                } else {
                    print $FD $inline;
                }
            }
            print $FD "$extractfile=$hParam{'UncompressProMD5'}->{$extractfile}\n";
            close($FD);
            
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , 1, 'subMsg' . $ACTION);
            if (scalar(@{$hParam{'UncompressProFileLists'}}) > 0) {
                $hParam{'UncompressPro'} = 'Uncompress';
                my ($filename) = ${$hParam{'UncompressProFileLists'}}[0];
                my ($msg) = "Extract $filename ... ";
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
            } else {
                $hParam{'UncompressPro'} = 'Completed';
            }
            StepRedirect(\%hParam);
    	} elsif (exists $hParam{'UncompressPro'} && $hParam{'UncompressPro'} eq 'Completed' ) {
            my ( %hSendParam );
            $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
            $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
            RVSInstaller::ScreenControl::CloseBoxMsg();
            callNextFunc(filterParam(\%hSendParam, \%hParam));
        }
    }
}

#######################################################################################################################
#   Process Uncompress Template Package for RVSiteBuilder Pro 
#######################################################################################################################
#==================== Uncompress Template Full Package ===============================
sub Process_UncompressTemplateFullPackage{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if($InstallConf{'on-demandTemplate'}){
    	#Skip if on-demand = yes : 
    	RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Full Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Uncompress xxx package', $objLANG->TranSlate('Template Full Package')), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Full Package') . ' ');
    	RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip Template Full Package (On-demand Template [Yes]'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Skip Template Full Package (On-demand Template [Yes]'));
        $hParam{'UncompressTemplateFullPackage'} = 'Completed';
        
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
        return 1;
    }
    
    if ( !exists $hParam{'UncompressTemplateFullPackage'} ) {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Preview'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the RVSiteBuilder license'), '', 'subMsg' . $ACTION);
    
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Preview'));
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the RVSiteBuilder license'));
        $hParam{'UncompressTemplateFullPackage'} = 'CheckLicense';
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateFullPackage'} && $hParam{'UncompressTemplateFullPackage'} eq 'CheckLicense') {
    # <-- License RVSiteBuilder Pro -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemeLite ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable'));
            $hParam{'UncompressTemplateFullPackage'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate('Uncompress Package') . ' ' . $objLANG->TranSlate('Template Preview'), '');
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available'));
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Available'), '');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available'));
            $hParam{'UncompressTemplateFullPackage'} = 'ValidatePkConf';
            RVSInstaller::ScreenControl::DisplayMsg('Checking the templates of RVSiteBuilder package configulation', '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Checking the templates of RVSiteBuilder package configulation.');
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateFullPackage'} && $hParam{'UncompressTemplateFullPackage'} eq 'ValidatePkConf') {
        my ($saveFilename );
        if ( !-e $InstallConf{'PackagePath'} . '/fullpackage.md5') {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg('Find not found the templates of RVSiteBuilder package configulation', '', 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg('Find not found the templates of RVSiteBuilder package configulation');
            $hParam{'UncompressTemplateFullPackage'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Ready') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Ready'));
            
            my ($newPkConf, $oldPkConf);
            open my $FD, '<' , $InstallConf{'PackagePath'} . '/fullpackage.md5';
            while ( <$FD> ) {
                chomp;
                next if (/^$/gi);
                my ($file, $md5file) = split(/=/, $_, 2);
                $newPkConf->{$file} = $md5file
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i);
            }
            close( $FD );
            
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5';
                while ( <$FD> ) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $oldPkConf->{$file} = $md5file
                        if ($file =~/\.bz2$/i || $file =~/\.gz$/i);
                }
                close($FD);
            }
            
            foreach my $newpkfile (keys %{$newPkConf}) {
            	push(@{$hParam{'TemplateFullFileLists'}}, $newpkfile)
                    if ($SCRIPT_OPT->{'force'} || !defined $oldPkConf->{$newpkfile} || $newPkConf->{$newpkfile} ne $oldPkConf->{$newpkfile}
                    	|| (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'template')));
            }

            if (defined $hParam{'TemplateFullFileLists'} && scalar(@{$hParam{'TemplateFullFileLists'}}) > 0) {
            	@{$hParam{'TemplateFullFileLists'}} = sort(@{$hParam{'TemplateFullFileLists'}});
                $hParam{'UncompressTemplateFullPackage'} = 'Uncompress';
                $hParam{'TemplateFullMD5'} = $newPkConf;
                my ($filename) = ${$hParam{'TemplateFullFileLists'}}[0];
                my ($msg) = "Extract $filename ... ";
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
            } else {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new Template Preview of RVSiteBuilder .', '1', 'subMsg' . $ACTION);
                $hParam{'UncompressTemplateFullPackage'} = 'Completed';
            }
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateFullPackage'} && $hParam{'UncompressTemplateFullPackage'} eq 'Uncompress' ) {
        if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'}) {
            system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} , '>/dev/null');
        }
        if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var') {
            system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var' , '>/dev/null');
        }
        my ($extractfile) = shift(@{$hParam{'TemplateFullFileLists'}});
            
        open PID, 'tar -jxvf ' . $InstallConf{'PackagePath'} . '/' . $extractfile . ' -C ' . $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . ' |'; 
        while (<PID>) {
            #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', "Extract $extractfile ... ", $_);
        }
        close(PID);
        
        open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5';
        my (@piers) = <$FD>;
        close($FD);
        open $FD, '>' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5';
        foreach my $inline (@piers) {
            if ($inline=~/^$extractfile=i/) {
                next;
            } else {
                print $FD $inline;
            }
        }
        print $FD "$extractfile=$hParam{'TemplateFullMD5'}->{$extractfile}\n";
        close($FD);
        if (-f $InstallConf{'PackagePath'} . '/' . $extractfile) {
        #    unlink($InstallConf{'PackagePath'} . '/' . $extractfile);  
        }

        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , 1, 'subMsg' . $ACTION);
        if (scalar(@{$hParam{'TemplateFullFileLists'}}) > 0) {
            $hParam{'UncompressTemplateFullPackage'} = 'Uncompress';
            my ($filename) = ${$hParam{'TemplateFullFileLists'}}[0];
            my ($msg) = "Extract $filename ... ";
            RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
        } else {
            $hParam{'UncompressTemplateFullPackage'} = 'Completed';
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateFullPackage'} && $hParam{'UncompressTemplateFullPackage'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#==================== Uncompress Template Preview ===============================
sub Process_UncompressTemplatePro{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if(!$InstallConf{'on-demandTemplate'}){
    	#Skip if on-demand = no
    	RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg('', 1);
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Preview Package'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Uncompress xxx package', $objLANG->TranSlate('Template Preview Package')), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Preview Package') . ' ');
    	RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip Template Preview Package (On-demand Template [No]'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Skip Template Preview Package (On-demand Template [No]'));
        $hParam{'UncompressTemplateFullPackage'} = 'Completed';
        
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
        return 1;
    }
    
    if ( !exists $hParam{'UncompressTemplatePro'} ) {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Preview'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the RVSiteBuilder Pro license'), '', 'subMsg' . $ACTION);
    
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Preview'));
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the RVSiteBuilder license'));
        $hParam{'UncompressTemplatePro'} = 'CheckLicense';
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplatePro'} && $hParam{'UncompressTemplatePro'} eq 'CheckLicense') {
    # <-- License RVSiteBuilder Pro -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemeLite ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable'));
            $hParam{'UncompressTemplatePro'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate('Uncompress Package') . ' ' . $objLANG->TranSlate('Template Pro'), '');
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available'));
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Available'), '');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available'));
            $hParam{'UncompressTemplatePro'} = 'ValidatePkConf';
            RVSInstaller::ScreenControl::DisplayMsg('Checking the templates of RVSiteBuilder package configulation', '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Checking the templates of RVSiteBuilder package configulation.');
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplatePro'} && $hParam{'UncompressTemplatePro'} eq 'ValidatePkConf') {
        my ($saveFilename );
        if ( !-e $InstallConf{'PackagePath'} . '/templatepreview.md5') {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg('Find not found the template preview of RVSiteBuilder package configulation', '', 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg('Find not found the template previre of RVSiteBuilder package configulation');
            $hParam{'UncompressTemplatePro'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Ready') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Ready'));
            
            my ($newPkConf, $oldPkConf);
            open my $FD, '<' , $InstallConf{'PackagePath'} . '/templatepreview.md5';
            while ( <$FD> ) {
                chomp;
                next if (/^$/gi);
                my ($file, $md5file) = split(/=/, $_, 2);
                $newPkConf->{$file} = $md5file
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i);
            }
            close( $FD );
            
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5';
                while ( <$FD> ) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $oldPkConf->{$file} = $md5file
                        if ($file =~/\.bz2$/i || $file =~/\.gz$/i);
                }
                close($FD);
            }
            
            foreach my $newpkfile (keys %{$newPkConf}) {
            	push(@{$hParam{'TemplateProFileLists'}}, $newpkfile)
                    if ($SCRIPT_OPT->{'force'} || !defined $oldPkConf->{$newpkfile} || $newPkConf->{$newpkfile} ne $oldPkConf->{$newpkfile}
                    || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'template')));
            }

            if (defined $hParam{'TemplateProFileLists'} && scalar(@{$hParam{'TemplateProFileLists'}}) > 0) {
            	@{$hParam{'TemplateProFileLists'}} = sort(@{$hParam{'TemplateProFileLists'}});
                $hParam{'UncompressTemplatePro'} = 'Uncompress';
                $hParam{'TemplateProMD5'} = $newPkConf;
                my ($filename) = ${$hParam{'TemplateProFileLists'}}[0];
                my ($msg) = "Extract $filename ... ";
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
            } else {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new template preview of RVSiteBuilder.', '1', 'subMsg' . $ACTION);
                $hParam{'UncompressTemplatePro'} = 'Completed';
            }
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplatePro'} && $hParam{'UncompressTemplatePro'} eq 'Uncompress' ) {
        if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'}) {
            system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} , '>/dev/null');
        }
        if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var') {
            system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var' , '>/dev/null');
        }
        my ($extractfile) = shift(@{$hParam{'TemplateProFileLists'}});
            
        open PID, 'tar -jxvf ' . $InstallConf{'PackagePath'} . '/' . $extractfile . ' -C ' . $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template' . ' |'; 
        while (<PID>) {
            #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', "Extract $extractfile ... ", $_);
        }
        close(PID);
        
        open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5';
        my (@piers) = <$FD>;
        close($FD);
        open $FD, '>' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/templatepreview.md5';
        foreach my $inline (@piers) {
            if ($inline=~/^$extractfile=i/) {
                next;
            } else {
                print $FD $inline;
            }
        }
        print $FD "$extractfile=$hParam{'TemplateProMD5'}->{$extractfile}\n";
        close($FD);
        if (-f $InstallConf{'PackagePath'} . '/' . $extractfile) {
        #    unlink($InstallConf{'PackagePath'} . '/' . $extractfile);  
        }

        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , 1, 'subMsg' . $ACTION);
        if (scalar(@{$hParam{'TemplateProFileLists'}}) > 0) {
            $hParam{'UncompressTemplatePro'} = 'Uncompress';
            my ($filename) = ${$hParam{'TemplateProFileLists'}}[0];
            my ($msg) = "Extract $filename ... ";
            RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
        } else {
            $hParam{'UncompressTemplatePro'} = 'Completed';
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplatePro'} && $hParam{'UncompressTemplatePro'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#######################################################################################################################
#   Process Uncompress Template Package for RVSiteBuilder Pro 
#######################################################################################################################
sub Process_UncompressTemplateLibrary{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( !exists $hParam{'UncompressTemplateLibrary'} ) {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Template Library'), '1');
#MI        #RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the RVSiteBuilder Pro license'), '', 'subMsg' . $ACTION);
    
#MI        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Template Pro'));
#MI        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the RVSiteBuilder Pro license'));
        $hParam{'UncompressTemplateLibrary'} = 'CheckLicense';
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateLibrary'} && $hParam{'UncompressTemplateLibrary'} eq 'CheckLicense') {
    # <-- License RVSiteBuilder Pro -->
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipThemeLite ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable'));
            $hParam{'UncompressTemplateLibrary'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate('Uncompress Package') . ' ' . $objLANG->TranSlate('Template Pro'), '');
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available'));
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Available'), '');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Available'));
            $hParam{'UncompressTemplateLibrary'} = 'ValidatePkConf';
            RVSInstaller::ScreenControl::DisplayMsg('Checking the templates library of RVSiteBuilder package configulation', '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg('Checking the templates library of RVSiteBuilder package configulation.');
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateLibrary'} && $hParam{'UncompressTemplateLibrary'} eq 'ValidatePkConf') {
        my ($saveFilename );
        if ( !-e $InstallConf{'PackagePath'} . '/library.md5') {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg('Find not found the templates library of RVSiteBuilder package configulation', '', 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg('Find not found the templates library of RVSiteBuilder package configulation');
            $hParam{'UncompressTemplateLibrary'} = 'Completed';
        } else {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Ready') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Ready'));
            
            my ($newPkConf, $oldPkConf);
            open my $FD, '<' , $InstallConf{'PackagePath'} . '/library.md5';
            while ( <$FD> ) {
                chomp;
                next if (/^$/gi);
                my ($file, $md5file) = split(/=/, $_, 2);
                $newPkConf->{$file} = $md5file
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i);
            }
            close( $FD );
            
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/library.md5') {
                open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/library.md5';
                while ( <$FD> ) {
                    chomp;
                    next if (/^$/gi);
                    my ($file, $md5file) = split(/=/, $_, 2);
                    $oldPkConf->{$file} = $md5file
                        if ($file =~/\.bz2$/i || $file =~/\.gz$/i);
                }
                close($FD);
            }
            
            foreach my $newpkfile (keys %{$newPkConf}) {
            	if ($SCRIPT_OPT->{'force'} || !defined $oldPkConf->{$newpkfile} 
	                || $newPkConf->{$newpkfile} ne $oldPkConf->{$newpkfile}
	                || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'template'))
	                ){
	                	print "push $newpkfile to download\n" if($DEBUG);
                    	push(@{$hParam{'TemplateProFileLists'}}, $newpkfile);
            	}
            }

            if (defined $hParam{'TemplateProFileLists'} && scalar(@{$hParam{'TemplateProFileLists'}}) > 0) {
            	@{$hParam{'TemplateProFileLists'}} = sort(@{$hParam{'TemplateProFileLists'}});
                $hParam{'UncompressTemplateLibrary'} = 'Uncompress';
                $hParam{'TemplateProMD5'} = $newPkConf;
                my ($filename) = ${$hParam{'TemplateProFileLists'}}[0];
                my ($msg) = "Extract $filename ... ";
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
            } else {
                RVSInstaller::ScreenControl::DisplayMsg('Not have new template library of RVSiteBuilder .', '1', 'subMsg' . $ACTION);
                $hParam{'UncompressTemplateLibrary'} = 'Completed';
            }
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateLibrary'} && $hParam{'UncompressTemplateLibrary'} eq 'Uncompress' ) {
        if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'}) {
            system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} , '>/dev/null');
        }
        if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var') {
            system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var' , '>/dev/null');
        }
        my ($extractfile) = shift(@{$hParam{'TemplateProFileLists'}});
        
        my $pathExtart = $InstallConf{'cpModeConfigPath'}{'TemplatePath'};
        if($extractfile =~ /^database/){
        	$pathExtart = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/data/';
        }
            
        open PID, 'tar -jxvf ' . $InstallConf{'PackagePath'} . '/' . $extractfile . ' -C ' . $pathExtart . ' |'; 
        while (<PID>) {
            #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', "Extract $extractfile ... ", $_);
        }
        close(PID);
        
        if($extractfile =~ /^database/){
        	system('"' . $cmd_cp . '" -f ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/data/database/* ' .
        			$InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/data/'
        	);
        }
        
        open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/library.md5';
        my (@piers) = <$FD>;
        close($FD);
        open $FD, '>' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/library.md5';
        foreach my $inline (@piers) {
            if ($inline=~/^$extractfile=i/) {
                next;
            } else {
                print $FD $inline;
            }
        }
        print $FD "$extractfile=$hParam{'TemplateProMD5'}->{$extractfile}\n";
        close($FD);
        if (-f $InstallConf{'PackagePath'} . '/' . $extractfile) {
        #    unlink($InstallConf{'PackagePath'} . '/' . $extractfile);  
        }

        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , 1, 'subMsg' . $ACTION);
        if (scalar(@{$hParam{'TemplateProFileLists'}}) > 0) {
            $hParam{'UncompressTemplateLibrary'} = 'Uncompress';
            my ($filename) = ${$hParam{'TemplateProFileLists'}}[0];
            my ($msg) = "Extract $filename ... ";
            RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
        } else {
            $hParam{'UncompressTemplateLibrary'} = 'Completed';
        }
        StepRedirect(\%hParam);
    } elsif (exists $hParam{'UncompressTemplateLibrary'} && $hParam{'UncompressTemplateLibrary'} eq 'Completed' ) {
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    }
}

#######################################################################################################################
#   Process Uncompress Language RVSiteBuilder Pro Package
#######################################################################################################################
sub Process_UncompressLanguage{
	my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( !exists $hParam{'UncompressLanguage'}) {
        RVSInstaller::ScreenControl::DisplayMsg('', '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('RVSiteBuilder Language'), '1');
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the RVSiteBuilder Language license'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the RVSiteBuilder Language license'));
    }
    
    # <-- License RVSiteBuilder Pro -->
    my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
    $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
    
    if ( !exists $hParam{'UncompressLanguage'} && (!$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
    $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' || $SkipPro) ) {
    	
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Unavailable'));
            
        my (%hSendParam);
        $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
        $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
        RVSInstaller::ScreenControl::CloseBoxMsg();
        callNextFunc(filterParam(\%hSendParam, \%hParam));
    } else {
    	if ( !exists $hParam{'UncompressLanguage'} ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate('Uncompress Package') . ' ' . $objLANG->TranSlate('RVSiteBuilder Language'), '');
            RVSInstaller::ScreenControl::DisplayMsg('', '1');
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('RVSiteBuilder Language'), '1');
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking the xxx package', $objLANG->TranSlate('RVSiteBuilder Language')), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking the xxx package', $objLANG->TranSlate('RVSiteBuilder Language')));
    
            my ($saveFilename );
            
            if ( !-e $InstallConf{'PackagePath'} . '/language.md5') {
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
                RVSInstaller::ScreenControl::DisplayMsg('Find not found the package list of RVSiteBuilder Language.', '', 'subMsg' . $ACTION, '', '#FF0000');
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg('Find not found the package list of RVSiteBuilder Language.');
                $hParam{'UncompressLanguage'} = 'Completed';
            } else {
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Ready') , '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Ready'));
            
            	my $newPkConf = {};
                my $oldPkConf = {};
                open my $FD, '<' , $InstallConf{'PackagePath'} . '/language.md5';
                while ( <$FD> ) {
                    chomp;
                    next if (/^$/gi);
                    my ( $file, $md5file ) = split(/=/, $_, 2);
                    if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                        $newPkConf->{$file} = $md5file;
                    }
                }
                close( $FD );
                
                if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/language.md5') {
                    open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/language.md5';
                    while( <$FD> ) {
                        chomp;
                        next if (/^$/gi);
                        my ( $file, $md5file ) = split(/=/, $_, 2);
                        if ($file =~/\.bz2$/i || $file =~/\.gz$/i) {
                            $oldPkConf->{$file} = $md5file;
                        }
                    }
                    close( $FD );
                } 
          
                foreach my $newpkfile (keys %{$newPkConf}) {
                    push(@{$hParam{'UncompressLanguageFileLists'}}, $newpkfile) 
                    	if ($SCRIPT_OPT->{'force'} || !defined $oldPkConf->{$newpkfile} || $newPkConf->{$newpkfile} ne $oldPkConf->{$newpkfile}
                    		|| (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'language')));
                }
                
                if (defined $hParam{'UncompressLanguageFileLists'} && scalar(@{$hParam{'UncompressLanguageFileLists'}}) > 0) {
	            	@{$hParam{'UncompressLanguageFileLists'}} = sort(@{$hParam{'UncompressLanguageFileLists'}});
	                $hParam{'UncompressLanguage'} = 'Uncompress';
	                $hParam{'TemplateFullMD5'} = $newPkConf;
	                my ($filename) = ${$hParam{'UncompressLanguageFileLists'}}[0];
	                my ($msg) = "Extract $filename ... ";
	                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
	                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
	            } else {
	                RVSInstaller::ScreenControl::DisplayMsg('Not have new Not have new Language of RVSiteBuilder .', '1', 'subMsg' . $ACTION);
	                $hParam{'UncompressLanguage'} = 'Completed';
	            }
            }
            StepRedirect(\%hParam);
    	} elsif (exists $hParam{'UncompressLanguage'} && $hParam{'UncompressLanguage'} eq 'Uncompress' ) {
    		if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'}) {
                system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} , '>/dev/null');
            }
            if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var') {
                system($cmd_mkdir, '-p', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var' , '>/dev/null');
            }
    		
    		my ($extractfile) = shift(@{$hParam{'UncompressLanguageFileLists'}});
            
            open PID, $cmd_tar . ' -jxvf ' . $InstallConf{'PackagePath'} . '/' . $extractfile . ' -C ' . $InstallConf{'cpModeConfigPath'}{'companyPath'} . '|'; 
            while (<PID>) {
            	RVSInstaller::ScreenControl::LogMsg("Extract $extractfile: $_");
                #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $extractfile, $_);    
            }
            close(PID);
            
            open my $FD, '<' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/language.md5';
            my (@piers) = <$FD>;
            close($FD);
        
            open $FD, '>' , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/language.md5';
            foreach my $inline (@piers) {
                if ($inline=~/^$extractfile=i/) {
                    next;
                } else {
                    print $FD $inline;
                }
            }
            print $FD "$extractfile=$hParam{'UncompressLanguageMD5'}->{$extractfile}\n";
            close($FD);
            
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , 1, 'subMsg' . $ACTION);
            if (scalar(@{$hParam{'UncompressLanguageFileLists'}}) > 0) {
                $hParam{'UncompressLanguage'} = 'Uncompress';
                my ($filename) = ${$hParam{'UncompressLanguageFileLists'}}[0];
                my ($msg) = "Extract $filename ... ";
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
            } else {
                $hParam{'UncompressLanguage'} = 'Completed';
            }
            StepRedirect(\%hParam);
    	} elsif (exists $hParam{'UncompressLanguage'} && $hParam{'UncompressLanguage'} eq 'Completed' ) {
            my ( %hSendParam );
            $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
            $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
            RVSInstaller::ScreenControl::CloseBoxMsg();
            callNextFunc(filterParam(\%hSendParam, \%hParam));
        }
    }
}

#######################################################################################################################
#   Group Installation
#######################################################################################################################
sub Process_Install{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    $tarOption = '-xvf';
    RVSInstaller::ScreenControl::DisplayMsg('', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Installation") .'.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Installation"));
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate("Installation"), '');
    callNextFunc(\%hParam);   
}

#######################################################################################################################
#   Install Program
#######################################################################################################################
sub _makeCompanyPath{
    my ($errorMsg);
    if ( !-e $InstallConf{'cpModeConfigPath'}{'companyPath'}) {
        mkdir($InstallConf{'cpModeConfigPath'}{'companyPath'}) or $errorMsg = $!;
        chmod(0755, $InstallConf{'cpModeConfigPath'}{'companyPath'});    
     }

    if ( $errorMsg || !-d $InstallConf{'cpModeConfigPath'}{'companyPath'}) {
        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') . ', ' . $objLANG->TranSlate('cannot created company path') . ': ' . $errorMsg . '.', 1, 'subMsg' . $ACTION, '', '#FF0000');
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot created company path') . ': ' . $errorMsg . '.');
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot created company path') . ': ' . $errorMsg . '.');
        exitScript();
    }
}

sub _validateDefaultTheme{
	my ( $errorMsg, $frontendPath, @defaultTheme, $foundDefaultTheme );
	$frontendPath = '/usr/local/cpanel/base/frontend';
    @defaultTheme = ( 'x','x2','x3','rvskin');
    $foundDefaultTheme = 0;
    
    foreach my $theme (@defaultTheme) {
        if (-e $frontendPath . '/' . $theme) {
            $InstallConf{'cpModeConfigPath'}{'SkinPath'} = $frontendPath . '/' . $theme;
            $foundDefaultTheme = 1;
            last;
        }
    }
    
    if (!$foundDefaultTheme) {
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot found default theme path') . ': ' . $errorMsg . '.');
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot found default theme path') . ': ' . $errorMsg . '.');
        exitScript();
    }  
}

sub _cleanTmpFiles{
	my ( @tempFileLists ) = @_;
	foreach my $fileList (@tempFileLists) {
		if ( -f $fileList || -l $fileList) {
			unlink($fileList);
		} else {
			system($cmd_rm . ' -rf ' .  $fileList . ' > /dev/null');
		}
	}
}

sub _makeProgramPath{
	my ( $errorMsg );
	if ( !-e $InstallConf{'cpModeConfigPath'}{'programPath'} ) {
        mkdir($InstallConf{'cpModeConfigPath'}{'programPath'}) or $errorMsg = $!;
        chmod(0755, $InstallConf{'cpModeConfigPath'}{'programPath'});  
    }
        
    if ( $errorMsg || !-e $InstallConf{'cpModeConfigPath'}{'programPath'}) {
        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') . ', ' . $objLANG->TranSlate('cannot created program path') . ' ' . $errorMsg . '.', 1, 'subMsg' . $ACTION, '', '#FF0000');
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot created program path') . ' ' . $errorMsg . '.');
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot created program path') . ' ' . $errorMsg . '.');
        exitScript();
    }
}

sub _makeSymlinkForTemplate{
	RVSInstaller::ScreenControl::LogMsg('go to _makeSymlinkForTemplate');
    if ( !readlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/template') ) {
        my ( $err );
        
        chdir($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www');
        if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/template') {
            system($cmd_mv . ' template template.bak >/dev/null 2>&1');
        }
        
        symlink('../template', 'template')  or $err = "Cannot symlink template: $!\n";
        chdir($InstallConf{'ThisParh'});
        
        if ( $err ne '' ) {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($err, '', 'subMsg' . $ACTION,'', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg($err);
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $err);
            exitScript();
        }
    }
}

sub _makeSymlinkForScript{
	RVSInstaller::ScreenControl::LogMsg('go to _makeSymlinkForScript');
    if ( !readlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/scripts') ) {
        my ( $err );
        
        chdir($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www');
        if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/scripts') {
            system($cmd_mv . ' scripts scripts.bak >/dev/null 2>&1');
        }
        
        symlink('../scripts', 'scripts')  or $err = "Cannot symlink scripts: $!\n";
        chdir($InstallConf{'ThisParh'});
        
        if ( $err ne '' ) {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($err, '', 'subMsg' . $ACTION,'', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $err);
            RVSInstaller::ScreenControl::LogMsg($err);
            exitScript();
        }
    }
}

sub _installPear{
	#repairPath();
	my ( $pear_bin );
    $pear_bin = callBackticks("which pear");   
    $pear_bin =~s/\r|\n//gi;
    
    if ($pear_bin eq '') {
        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('Cannot found pear on this server') , 1, 'subMsg' . $ACTION, '', '#FF0000');
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot found pear on this server') . ' ' . $pear_bin);
        exitScript();      
    }

    system($cmd_mkdir . ' /usr/local/bin') if (!-d '/usr/local/bin' && !-l '/usr/local/bin');
    
    if (!-f '/usr/local/bin/pear' && !-l '/usr/local/bin/pear') {
        if (-f '/usr/bin/pear') {
            system($cmd_ln . ' -s /usr/bin/pear /usr/local/bin/pear');
        } else {
            system($cmd_ln . ' -s ' . $pear_bin . ' /usr/local/bin/pear');
        }
    }

    #Validate update file
    my $md5ProviderRvseagullmod = $InstallConf{'PackagePath'} . '/rvseagullmod.md5';
    my $md5LocalRvseagullmod = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvseagullmod.md5';
    if (-e $md5ProviderRvseagullmod && -f $md5LocalRvseagullmod 
    	&& !(defined $SCRIPT_OPT->{'force'}  || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'all' || $ARGUMENT{'force'} eq 'rvseagullmod')))
    ) {
        my %md5ProviderHash = readINIfile($md5ProviderRvseagullmod);
        my %md5LocalHash = readINIfile($md5LocalRvseagullmod);
        my $skipInstall = 0;
        foreach my $eachKey (keys %md5ProviderHash){
        	if(defined $md5LocalHash{$eachKey} && $md5LocalHash{$eachKey} eq $md5ProviderHash{$eachKey}){
        		print "Pear install have skip ,not have new RVSeagullMod\n";
        		$skipInstall = 1;
        	}else{
        		last;
        	}
        }
        return 1 if($skipInstall);
    }
    
    if (!-e $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/.skippear') {
    	
    	# Uninstall Pear in /usr/lib/php for PHP5
        uninstallRVSeagullMod('/usr/bin/pear', 'usr lib') if (!$BROWSER);
    
        # PHP 5
        installRVSeagullMod('/usr/local/bin/pear', 'local lib');
        
        #php_selectable
        if ( -e '/usr/local/apache/conf/php4.htaccess' && -e '/usr/local/apache/conf/php5.htaccess' ) {
            if (-e '/usr/local/php4/bin/pear') {
                # PHP 4 install pear to /usr/local/php4/lib/php
                #installRVSeagullMod('/usr/local/php4/bin/pear', 'local php4 lib');
            }
        }
    } else {
        print "Pear install have skip by DEBUG please delete file " . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . "/rvsitebuilderinstaller/.skippear\n";
    }
	
}

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

    RVSInstaller::ScreenControl::DisplayMsg('', '1');
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Creating RVGlobalsoft and RVSiteBuilder directory'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Creating RVGlobalsoft and RVSiteBuilder directory'));
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '',$objLANG->TranSlate('Creating RVGlobalsoft and RVSiteBuilder directory'));
    
    _makeCompanyPath();
    
   if ($InstallConf{'cpMode'} eq 'cpanel') {
       _validateDefaultTheme();
   }

    _makeProgramPath();

    $hParam{'InstallProgram'} = 'InstallProgram';
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Creating RVGlobalsoft and RVSiteBuilder directory') . ' has been completed.');

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Copy source files to program path') .'. ' . $objLANG->TranSlate("Please wait") . '...', 1, 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Copy source files to program path') .'. ');
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Copy source files to program path'));

    # Fix change license Pro to Lite and delete modules/sitebuilderpro before rsync: Apiruk Boonruksa
    my ( @cleanTempFiles, %hLicenseInfo);
    %hLicenseInfo = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
    $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
    
    if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
    $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' ) {
    	
        push(@cleanTempFiles, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilderpro');
    }
    
    push(@cleanTempFiles, 
        $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilder.tar.bz2'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilder-pro.tar.bz2'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvstemplate.tar.bz2'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvstemplate-pro.tar.bz2'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull_mod/seagull/modules/forums/www'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull_mod/seagull/modules/forums/www2'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/classes/SitebuilderDAO'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/themes/default/sitebuilder/Category.html'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/themes/default/sitebuilder/rvs_ajaxpopup.html'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/themes/default/sitebuilder/rvs_popup.html'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/www/themes/savant'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/default/templates/custom/home.html'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/www/themes/smarty'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/docs'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/tests'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/CHANGELOG.txt'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/CODING_STANDARDS.txt',
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/INSTALL.txt'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/RVMOD.txt'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/blog'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/contactus'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/documentor'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/faq'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/gallery2'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/guestbook'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/newsletter'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/publisher'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/seagull/modules/randommsg'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilderGraphicPro'
        , $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller.tar'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/classes/cComponentAndUserFrameworkUserMgr.php'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/classes/cComponentAndUserFrameworkAdminMgr.php'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/classes/cNewsletterUserMgr.php'
        , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/classes/cNewsletterAdminMgr.php'
    );
    
    _cleanTmpFiles(@cleanTempFiles);
    
    system($cmd_cp_all . ' ' 
        . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/templates/Category.html ' 
        . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/themes/default/sitebuilder/Category.html >/dev/null 2>&1' );
    system($cmd_cp_all . ' '
        . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/templates/rvs_ajaxpopup.html ' 
        . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/themes/default/sitebuilder/rvs_ajaxpopup.html >/dev/null 2>&1' );
    system($cmd_cp_all . ' '
        . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/templates/rvs_popup.html ' 
        . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/themes/default/sitebuilder/rvs_popup.html >/dev/null 2>&1' );


    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Copy source files to program path'));
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Copy source files to program path') . ' has been colpleted.');
        
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Creating other directory and hard links'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Creating other directory and hard links') . '...');
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Creating other directory and hard links'));
    RVSInstaller::ScreenControl::DisplayMsg("", 1);
    
   

     if ($InstallConf{'cpMode'} eq 'cpanel') {
     	 _makeSymlinkForTemplate();
         _makeSymlinkForScript();
         #fixPHPExtensionPath();
     }
     fixPHPExtensionPath();
    
    if ( !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/project' ) {
        mkdir($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/project', 0755);
    }
    if ( !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var' ) {
        mkdir($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var', 0755);    	
    }        
    if ( !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/log' ) {
        mkdir($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/log', 0755)
    }
    system('chmod', '0755', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/log');

    if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/log/php_log.txt') {
    	system('chmod', '0666', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/log/php_log.txt');
    }
    
    if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE.php' 
        && !-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/.fix206') {
        system($cmd_rm . ' -f ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE.php >/dev/null 2>&1');
        open(W, '>', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/.fix206');
        print W 'fix';
        close(W);
    }
    
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate("Install RVSeagullMod Pear Lib") . '...');
    RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Install RVSeagullMod Pear Lib") .'.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
    
    _installPear();

    my $pathLisense = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilder.lic';
    my $pathLisensePro = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilder-pro.lic';
    #clean link
    if (-l $pathLisense) {
    	unlink($pathLisense);
    }
    if (-l $pathLisensePro) {
        unlink($pathLisensePro);
    }
    #make link
    chdir($InstallConf{'cpModeConfigPath'}{'programPath'});
    
    if (-e $pathLisense) {
        system('rm -f ' . $pathLisense);	
    }
    if (-e $pathLisensePro) {
        system('rm -f ' . $pathLisensePro);	
    }
    if (!-l $pathLisense) {
        system($cmd_ln . ' -s var/license/rvsitebuilder.lic');
    }
    if (!-l $pathLisensePro) {
        system($cmd_ln . ' -s var/license/rvsitebuilder-pro.lic');	
    }

    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Creating other directory and hard links') . ' has been completed.');
    
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Changes the permissions of files'), 1, 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files') . '...');
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Changes the permissions of files'));
    
    opendir(DIR, $InstallConf{'cpModeConfigPath'}{'programPath'}); 
    my (@dirs) =	readdir(DIR);
    closedir(DIR);
    my ($file);

    foreach $file ( @dirs ) {
        if ( $file eq '.' || $file eq '..' ) {
            next;
        } elsif ( -f $InstallConf{'cpModeConfigPath'}{'programPath'}. '/' . $file ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file);
            RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file, 0755);
        } elsif ( -d $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file 
            && !-l  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file 
            && $file ne 'www'
        ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file);
            RVSInstaller::ScreenControl::DisplayMsg('Changes the permissions directory ' . $file . ' ', '', 'subMsg' . $ACTION);
            RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file, 0755);
            chmod(0755, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $file);
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        } else {
            next;
        } 
    }
    
    opendir(DIR, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www'); 
    (@dirs) =	readdir(DIR);
    closedir(DIR);
    foreach $file ( @dirs ) {
        if ( $file eq '.' || $file eq '..' ) {
            next;
        }
        elsif ( -f $InstallConf{'cpModeConfigPath'}{'programPath'}. '/www/' . $file ) {
            RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file, 0755);
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file);
        } elsif ( -d $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file 
            && !-l  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file 
            && $file ne 'rvs_library' && $file ne 'project'
        ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file);
            RVSInstaller::ScreenControl::DisplayMsg('Changes the permissions directory www/' . $file . ' ', '', 'subMsg' . $ACTION);
            RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file, 0755);
            chmod(0755, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/' . $file);
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        } else {
            next;
        } 
    }
    
    opendir(DIR, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library'); 
    (@dirs) =	readdir(DIR);
    closedir(DIR);
    foreach $file ( @dirs ) {
        if ( $file eq '.' || $file eq '..' ) {
            next;
        } elsif ( -f $InstallConf{'cpModeConfigPath'}{'programPath'}. '/www/rvs_library/' . $file ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file);
            RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file, 0755);
        } elsif ( -d $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file 
            && !-l  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file 
        ) {
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file);
            RVSInstaller::ScreenControl::DisplayMsg('Changes the permissions directory www/rvs_library/' . $file . ' ', '', 'subMsg' . $ACTION);
            RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file, 0755);
            chmod(0755, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_library/' . $file);
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        } else {
            next;
        } 
    }
    
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'});
    chmod(0755, $InstallConf{'cpModeConfigPath'}{'programPath'});
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var');
    RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var', 0755);

    if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/wysiwyg/config.php') {
        system($cmd_rm . ' -rf '. $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/wysiwyg/config.php')
    }
    if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/tmp') {
        system($cmd_rm . ' -rf '. $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/tmp')
    }

    #TODO 1 ทำ log rotate ก็ต่อเมื่อมีไฟล์ IP Config / Pharadol
    if ( $RVS_IP_CONF ) {
    	RVSInstaller::ScreenControl::LogMsg("\n ===================================>have mainIP " . "\n");
    	my %rvsConf = getRVSiteBuilderConf($RVS_IP_CONF);
    	my $pathVar = $rvsConf{'log'}{'name'};
	    my @a = split('\/', $pathVar);
	    $pathVar =~ s/$a[scalar(@a)-1]//;
		
		RVSInstaller::Process::chmodAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/'. $pathVar , 0755)
            if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/'. $pathVar) ;
            
    	runRotateRvsitebuilderLogPath($InstallConf{'cpModeConfigPath'}{'programPath'}, $rvsConf{'log'}{'name'});
    }else{
    	RVSInstaller::ScreenControl::LogMsg("\n ===================================> no mainIP " . "\n");
    }

    if ( !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvslicense.ini' ) {
        open my $FD, '>', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvslicense.ini';
        print $FD '';
        close($FD);
    }
    
    system($cmd_chmod, '666', $InstallConf{'cpModeConfigPath'}{'programPath'} .'/var/rvslicense.ini');

    if ( !-e $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template/rvsMasterTemplate.php') {
    	open my $FD, '>', $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template/rvsMasterTemplate.php';
        print $FD '';
        close($FD);
    }
    system($cmd_chmod, '666', $InstallConf{'cpModeConfigPath'}{'TemplatePath'} .'/template/rvsMasterTemplate.php');

    if (-e $InstallConf{'SourcePath'}) {
    	system($cmd_chmod, '-R', '644', $InstallConf{'SourcePath'});
    }

    #Start secure user task
    my $user = callBackticks("whoami");
    $user =~s/\r|\n//gi;  
    
    if ($InstallConf{'cpMode'} eq 'cpanel') {
        if ( $user ne "root" ) {
            print  "You must run this script as root, else you may not have privileges ";
            print  "to properly restore all files.\n";
            exit;
        }
   }

    addSecureUser();
    
    RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Add secure user") .'.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
    
    my $pwd = $InstallConf{'cpModeConfigPath'}{'programPath'};
    my $rvbinpath = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvbin';
    
    system('mkdir -p ' . $rvbinpath) 
        if (!-d $rvbinpath);
    system('mkdir -p ' .  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/.tmp')
        if (!-d $InstallConf{'cpModeConfigPath'}{'programPath'} . '/.tmp');
    system('chmod 700 ' . $InstallConf{'cpModeConfigPath'}{'companyPath'} . '/tmp')
        if (-d $InstallConf{'cpModeConfigPath'}{'companyPath'} . '/tmp');
    
    print "Compile rvswrapper ... ";
    
    unlink($rvbinpath . '/rvswrapper')
        if (-e $rvbinpath . '/rvswrapper' && -e $pwd . '/rvbin-src/rvswrapper.c');
    
    system('gcc', '-o', $rvbinpath . '/rvswrapper', $pwd . '/rvbin-src/rvswrapper.c')
        if (-e $pwd . '/rvbin-src/rvswrapper.c');
    
    if ($? != 0 && $? != 1) {
        print "failed.\n";
        system('rm -rf ' . $pwd . '/rvbin-src');
        exit;
    }
 
    unlink("$rvbinpath/secure.pl")
        if (-e "$rvbinpath/rvbin/secure.pl");
    unlink("$rvbinpath/rvlog.pl")
        if (-e "$rvbinpath/rvbin/rvlog.pl");
    system("rm -rf $pwd/www/users")
        if (-d "$pwd/www/users");
    system("rm -rf $pwd/www/downloads")
        if (-d "$pwd/www/downloads");
    mkdir("$pwd/www/userdata")
        if (!-e "$pwd/www/userdata");
    system("mkdir -p $pwd/var/license")
        if (!-e "$pwd/var/license");
    mkdir("$pwd/www/project")
        if (!-e "$pwd/www/project");
    system("cp  $pwd/rvbin-src/secure.pl $rvbinpath/secure.pl")
        if (-e "$pwd/rvbin-src/secure.pl");
    system("cp  $pwd/rvbin-src/rvlog.pl $rvbinpath/rvlog.pl")
        if (-e "$pwd/rvbin-src/rvlog.pl");
    
    system("chown securervsite:securervsite $rvbinpath/");
    system("chown securervsite:securervsite $rvbinpath/*");
    system("chown securervsite:securervsite $rvbinpath/secure.pl");
    system("chown securervsite:securervsite $rvbinpath/rvlog.pl");
    system("chown securervsite:securervsite $rvbinpath/rvswrapper");
    
    system("chown securervsite:securervsite " . $InstallConf{'cpModeConfigPath'}{'programPath'} . "/.tmp");
    
    system("chmod 555 $rvbinpath/");
    system("chmod 550 $rvbinpath/*");
    system("chmod 770 " . $InstallConf{'cpModeConfigPath'}{'programPath'} . "/.tmp");
    
    system("chmod 770 $rvbinpath/secure.pl");
    system("chmod 770 $rvbinpath/rvlog.pl");
    #system("chmod ug+s $rvbinpath/rvswrapper");
    system("chmod 2711 $rvbinpath/rvswrapper");
    
    #For template
	system("mkdir -p $pwd/www/userdata/securervsite") if(!-d "$pwd/www/userdata/securervsite");
	system("chown -R securervsite:securervsite $pwd/www/userdata/securervsite");
	system("chmod -R 575 $pwd/www/userdata/securervsite");
	
	#fix update on-demand template
	if (-e $pwd . '/www/userdata/securervsite/templateinfo.ini') {
		unlink($pwd . '/www/userdata/securervsite/templateinfo.ini');
	}
	if(-e "$pwd/template"){
		my $templateRealPath = "$pwd/template";
		if(-l "$pwd/template"){
			$templateRealPath = readlink $templateRealPath;
		}
		system("chown -R securervsite:securervsite $templateRealPath");
		system("chmod -R 575 $templateRealPath");
	}

    system("rm -rf $pwd/rvbin-src")
        if (-e "$pwd/rvbin-src");
    
    if (-x $rvbinpath . '/rvswrapper') {
        print "succeed.\n";
    } else {
        print "failed.\n";
    }
    
    ## Test rvswrapper
    my $testRvswrapper = callBackticks($rvbinpath . '/rvswrapper');
    
    if ($testRvswrapper =~/Permission denied/gi) {
    	## Move rvbin to /usr/rvsitebuilder and testting again
    	if (!-d '/usr/rvsitebuilder') {
    	   system('mkdir -p /usr/rvsitebuilder');	
    	}
    	
    	if (!-d '/usr/rvsitebuilder/modules' && -d '/usr/rvsitebuilder/rvbin') {
    		system('rm -rf /usr/rvsitebuilder/rvbin');
    		system($cmd_cp_all . ' ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvbin /usr/rvsitebuilder/');
    	}

    	$testRvswrapper = callBackticks('/usr/rvsitebuilder/rvbin/rvswrapper');
    	if ($testRvswrapper =~/Permission denied/gi) {
    		## Move rvbin to /home/rvsitebuilder 
            if (!-d '/home/rvsitebuilder') {
                system('mkdir -p /home/rvsitebuilder >/dev/null');  
            }
            
            if (!-d '/home/rvsitebuilder/modules' && -d '/home/rvsitebuilder/rvbin') {
                system('rm -rf /home/rvsitebuilder/rvbin >/dev/null');
                system('mv ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvbin /home/rvsitebuilder/ >/dev/null');
                system('ln -s /home/rvsitebuilder/rvbin ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvbin >/dev/null');
            }

    	} else {
    		system('rm -rf ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvbin >/dev/null');
    		system('ln -s /usr/rvsitebuilder/rvbin ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvbin >/dev/null');
    	}
    }
    
    ## set path www/project
    RVSInstaller::ScreenControl::DisplayMsg('Changes the permissions directory projects ', '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/project');
    my $projectPath = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/project';
    if (-e $projectPath) {
        system("chown securervsite:securervsite $projectPath");
        chmod(0575, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/project');
    }
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    
    ## set path www/userdata
    RVSInstaller::ScreenControl::DisplayMsg('Changes the permissions directory users ', '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Changes the permissions of files'), $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/users');
    system("chown securervsite:securervsite $InstallConf{'cpModeConfigPath'}{'programPath'}/www/userdata");
    chmod(0575, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/userdata');
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    
    ## Fix Owner in www/userdata
    opendir(DIR, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/userdata');
    my (@users) = grep {!(/^\./) && -f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/userdata/' . $_} readdir(DIR);
    closedir(DIR);
    
    foreach my $user (@users)
    {
    	system("chown $user:securervsite " . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/userdata/' . $user . ' >/dev/null');
    	system("chown $user:$user  -R " . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/userdata/' . $user . '/* >/dev/null');
    }
            
    
    
    # set path var/license
    system("chown securervsite:securervsite $InstallConf{'cpModeConfigPath'}{'programPath'}/var/license");
    chmod(0575, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license');

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Changes the permissions of files'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Changes the permissions of files') . ' has been completed.');

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Remove resources'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Remove resources'));
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Remove resources'));
    RVSInstaller::Process::unlinkAll($InstallConf{'SourcePath'});
        
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Remove resources') . ' has been completed.');
        
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Checking default folders'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Checking default folders'));
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Checking default folders'));
    $hParam{'InstallProgram'} = 'checkFolder';

   #Install plugin rvsitebuilder to Directadmin
   if ($InstallConf{'cpMode'} eq 'da') {
        InstallPluginRvsOnDa();
   }
   
   #V5 delete www/rvs_help
   _deleteRvshelpV5();
   
   #v5 replace owner lang
	my $adminPath = '';
	if ($InstallConf{'cpMode'} eq 'da') {
	        $adminPath = "/home/admin";
	} else {
	        $adminPath = $InstallConf{'cpModeConfigPath'}{'companyPath'};
	}
	my $ownerLangPath = $adminPath . '/.rvsitebuilder/lang/sitebuilder';
	
	if (!-f $ownerLangPath . '/replaceFileLang.complete') {
	replaceKeyLang();
	}
    
    if ( !-e $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/flash' ||
    !-e $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template' ||
    !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc' ||
    !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/lib' ||
    !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts' ||
    !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules' ||
    !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder') {
        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') . ', ' . $objLANG->TranSlate('some folders has broken') . '.', 1, 'subMsg' . $ACTION, '', '#FF0000');
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('some folders has broken') . '.');
        RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('some folders has broken') . '.');
        exitScript();
    }

    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    
    RVSInstaller::ScreenControl::LogMsg('Installation has been completed.');

    my (%hSendParam);
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    RVSInstaller::ScreenControl::CloseBoxMsg();
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

#######################################################################################################################
#   Group Setup RVSiteBuilder
#######################################################################################################################
sub Process_SetupRVS{
    my ($param) = $_[0];
    my (%hParam) = %{$param};

    RVSInstaller::ScreenControl::DisplayMsg('', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Setup RVSiteBuilder") .'.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Setup RVSiteBuilder"));
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, $objLANG->TranSlate("Setup RVSiteBuilder"), '');
    callNextFunc(\%hParam); 
}

#######################################################################################################################
#   Control Panel Type
#######################################################################################################################
sub Process_SetupRVSPanelType{
    my ($param) = $_[0];
    my (%hParam) = %{$param};

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Control Panel Type'), '');
    

    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate(lc($InstallConf{'cpMode'})) , '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Control Panel Type') . $objLANG->TranSlate(lc($InstallConf{'cpMode'})));
    RVSInstaller::ScreenControl::DisplayBoxMsg(0, '', $objLANG->TranSlate('Control Panel Type') . ': ' . $objLANG->TranSlate(lc($InstallConf{'cpMode'})));
    if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/myconf.ini.dist') {
        my (@pears);
        open(R, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/myconf.ini.dist');
        @pears = <R>;
        close(R);
            
        open(W,'> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/myconf.ini.dist');
        foreach (@pears) {
            if ( /^cpmode/i ) {
                RVSInstaller::ScreenControl::LogMsg('Setting value cpmode in ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/myconf.ini.dist to ' . $InstallConf{'cpMode'} );
                print W 'cpmode=' . $InstallConf{'cpMode'} . "\n";
            }
            else {
                print W $_;   
            }
        }
        close(W);
    }
    if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/default.conf.ini.dist') {
        my (@pears);
        open(R, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/default.conf.ini.dist');
        @pears = <R>;
        close(R);
            
        open(W,'>' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/default.conf.ini.dist');
        foreach (@pears) {
            if ( /^cpmode/i ) {
                RVSInstaller::ScreenControl::LogMsg('Setting value cpmode in ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/default.conf.ini.dist to ' . $InstallConf{'cpMode'} );
                print W 'cpmode=' . $InstallConf{'cpMode'} . "\n";
            }
            else {
                print W $_;   
            }
        }
        close(W);
    }
    my (%hSendParam);
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}


#######################################################################################################################
#   Setup RVSiteBuilder Managet
#######################################################################################################################
sub Process_SetupRVSManager{
    my ($param) = $_[0];
    my (%hParam) = %{$param};

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Setting RVSiteBuilder Manager'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Setting RVSiteBuilder Manager') . '...');
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Setting RVSiteBuilder Manager'));
    
    if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/backupuser.pl') {
       unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/backupuser.pl');
    }
    
    if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/rvcountuserdb.pl') {
       unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/rvcountuserdb.pl');
    }
    
    #RVSInstaller::Process::copyAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm', $InstallConf{'cpModeConfigPath'}{'ManagerPath'});
    if ( $InstallConf{'cpMode'} eq 'cpanel' ){
	    if(-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/index.cgi'){
	    	copy($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/index.cgi', $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder');
	    }
	    
	    if(-f $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/index.cgi'){
	    	chmod(0755, $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/index.cgi');
	    }
	    
	    if(-f $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/index.cgi'){
            chmod(0755, $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/index.cgi');
        }
	    
	    if (-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/addon_rvsitebuilder.cgi') {
	    	unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/whm/addon_rvsitebuilder.cgi');
	    }
	    
	    if (-e $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/backupuser.pl') {
	        unlink($InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/backupuser.pl');
	    }
	    
	    if (-e $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvcountuserdb.pl') {
	       unlink($InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvcountuserdb.pl');
	    }
    }
    
    #remove symlink cgi/rvsitebuilder to rvglobalsoft/rvsitebuilder
    #if ( !readlink($InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/' . $InstallConf{'ProgramName'}) ) {
    #    chdir($InstallConf{'cpModeConfigPath'}{'ManagerPath'});
    #    symlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www', $InstallConf{'ProgramName'});
    #    chdir($InstallConf{'ThisParh'});
    #}
    
    ######### Make docroot/cgi/rvsitebuilder symlink to rvsitebuilder/www ###########

    if ( $InstallConf{'cpMode'} eq 'cpanel') {
	    my $target = '/usr/local/cpanel/whostmgr/docroot/cgi/rvsitebuilder';
	    my $dest = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www';
	
	    if (-l '/usr/local/cpanel/whostmgr/docroot/cgi/rvsitebuilder') {
	        chdir("/usr/local/cpanel/whostmgr/docroot/cgi/");
	        system("unlink rvsitebuilder");
	    }
	
	    if (!-d $target) {
	        chdir("/usr/local/cpanel/whostmgr/docroot/cgi/");
	        system("mkdir rvsitebuilder");
	    }
	
	    if (-d $target) {
	        #make folder
	        if (!-d $target . '/project') {
	            system('mkdir ' . $target . '/project');
	            system('chmod 755 ' . $target . '/project');
	        }
	        #make link
	        if (-e $dest . '/project/pj_preview_root' && !-l $target . '/project/pj_preview_root') {
	            symlink($dest . '/project/pj_preview_root', $target . '/project/pj_preview_root');
	        }
	        #make folder
	        if (!-d $target . '/userdata') {
	            system('mkdir ' . $target . '/userdata');
	            system('chmod 755 ' . $target . '/userdata');
	        }
	        #make link
	        if (-e $dest . '/userdata/root' && !-l $target . '/userdata/root') {
	            symlink($dest . '/userdata/root', $target . '/userdata/root');
	        }
	    }
	
	    #project , userdata
	    if ( -d $dest ) {
	        opendir( DIR, $dest );
	        my (@dirs) = readdir(DIR);
	        closedir(DIR);
	        my ($file);
	        foreach $file (@dirs) {
	            $file =~ s/\/$//gi;
	            if ( $file eq '.' || $file eq '..' 
	                || $file eq 'project'
	                || $file eq 'userdata') {
	                next;
	            }
	            elsif ( -e $dest . '/' . $file && !-l $target . '/' . $file) {
	                if (-f $target . '/' . $file && $target != '' && $file != '') {
	                    unlink($target . '/' . $file);  
	                }
	                if (-d $target . '/' . $file && $target != '' && $file != '') {
	                    system('rm -rf ' . $target . '/' . $file);  
	                }
	                print "Make symlink " . $dest . '/' . $file . " " . $target . '/' . $file . "\n";
	                symlink( $dest . '/' . $file, $target . '/' . $file);
	            }
	        }
	    }
	    
	 ####################### Make root and make link userdata ###################################### 
	 if ( !-d $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/userdata/root' ) {
	 	 system('mkdir ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/userdata/root');
	 }
	 
	 if ( -d $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/userdata/root/upload') {
         system('rm -rf ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/userdata/root/upload'); 
     }
     
	 if ( !-l $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilder/userdata/root/upload') {
	 	  system("ln -s /var/cpanel/rvglobalsoft/.rvsitebuilder/upload " . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . "/rvsitebuilder/userdata/root/upload");
	 }
	 if ( !-d '/var/cpanel/rvglobalsoft/.rvsitebuilder/upload/template') {
	 	system('mkdir -p /var/cpanel/rvglobalsoft/.rvsitebuilder/upload/template');
	 }
	 ####################### End Make root and make link userdata ##################################
	 
	 ####################### Make link userdata/root/downloads ######################################
	 if ( !-d $dest . '/userdata/root/downloads' ) {
         system('mkdir -p ' . $dest . '/userdata/root/downloads');
     }
     if (-e $dest . '/userdata/root/downloads' && !-l $target . '/userdata/root/downloads') {
         symlink($dest . '/userdata/root/downloads', $target . '/userdata/root/downloads');
     }
     ####################### End Make link userdata/root/downloads ##################################
	    
    }
    ############## End Make docroot/cgi/rvsitebuilder symlink to rvsitebuilder/www #########

    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Setting RVSiteBuilder Manager') . ' has been completed.');
    $hParam{'SetupRVSManager'} = 'Completed';

    my (%hSendParam);
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

#######################################################################################################################
#   Setup RVSiteBuilder User Interface
#######################################################################################################################
sub Process_SetupRVSPanel{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Setting RVSiteBuilder User Interface') . '...');
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Setting RVSiteBuilder User Interface'), '');
    
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Setting RVSiteBuilder User Interface'));
   if ( $InstallConf{'cpMode'} eq 'cpanel') {
    #Directadmin not do it
    RVSInstaller::Process::copyAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/skin', $InstallConf{'cpModeConfigPath'}{'SkinPath'});
    
    #Directadmin do not make symlink
    if ( !readlink($InstallConf{'cpModeConfigPath'}{'UserInterface'} . '/' . $InstallConf{'ProgramName'}) ) {
        chdir($InstallConf{'cpModeConfigPath'}{'UserInterface'});
        symlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/www', $InstallConf{'ProgramName'});
        chdir($InstallConf{'ThisParh'});
    }
    
    #copy xml-api to /usr/local/cpanel/base/xml-api
    my $xmlApiPath = '/usr/local/cpanel/base/xml-api';    
    if (! -d $xmlApiPath) {
        system($cmd_mkdir . ' ' . $xmlApiPath);
    }
    if (-d $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/xml-api') {
    	system($cmd_cp . ' ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/xml-api/rvscompliercptag.cpphp ' . $xmlApiPath . ' >/dev/null 2>&1');
    }
    
    #Directadmin do not it
    if ( -e $InstallConf{'cpModeConfigPath'}{'ModulePath'} ) {
        RVSInstaller::Process::copyAll($InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/modules', $InstallConf{'cpModeConfigPath'}{'ModulePath'});
        my (@modulesFile);
        opendir(DIR, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/modules');
        @modulesFile = readdir(DIR);
        close(DIR);
        foreach ( @modulesFile) {
            if ( $_ ne '.' && $_ ne '..' && -e $InstallConf{'cpModeConfigPath'}{'ModulePath'} . '/' . $_) {
                #Example chmod(0644,'/usr/local/cpanel/Cpanel/Rvsitebuilder.pm');
                chmod($InstallConf{'cpModeConfigPath'}{'ModulePrem'}, $InstallConf{'cpModeConfigPath'}{'ModulePath'} . '/' . $_);
            }   
        }
    }
    
    my ($cpVersion);
    $cpVersion = getcPanelVersion();
    if ( int $cpVersion->{'version'}{'int'}{'1'} >= 11) {
    	#register paper_lantern
    	registerThemePaperLantern();
    	
        if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/cpanelplugin/rvsitebuilder.cpanelplugin' ) {
            system('/usr/local/cpanel/bin/register_cpanelplugin ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/' . $InstallConf{'cpMode'} . '/cpanelplugin/rvsitebuilder.cpanelplugin >/dev/null 2>&1');
        }
        
        if (-f '/usr/local/cpanel/base/frontend/rvskin/rvskin/rvsitebuilder_upsale.html') {
            system($cmd_replace . " 'index.php/sitebuilder' 'index.php?/sitebuilder' -- /usr/local/cpanel/base/frontend/rvskin/rvskin/rvsitebuilder_upsale.html >/dev/null 2>&1");
        }
        
        if (-f '/usr/local/cpanel/Cpanel/Rvskin.pm') {
            system($cmd_replace . " 'index.php/sitebuilder'  'index.php?/sitebuilder' -- /usr/local/cpanel/Cpanel/Rvskin.pm >/dev/null 2>&1");
        }
        
        if ( -e '/usr/local/cpanel/base/frontend/x/cells/cpanelplugin_rvsitebuilder.html') {
            system($cmd_rm . ' -f /usr/local/cpanel/base/frontend/x/cells/cpanelplugin_rvsitebuilder.html >/dev/null 2>&1');
        }
        if ( -e '/usr/local/cpanel/bin/rebuild_sprites') {
            system('/usr/local/cpanel/bin/rebuild_sprites >/dev/null 2>&1');  
        }
    }

    my(@users) = user_array();
    foreach (@users) {
        my $userHomeDir = (getpwnam($_))[7];    
        if (-e "$userHomeDir/.rvskin/cache") {
            system($cmd_rm . " -f $userHomeDir/.rvskin/cache/mysql/* > /dev/null 2>&1");
            system($cmd_rm . " -f $userHomeDir/.rvskin/cache/data/* > /dev/null 2>&1");
        }    
    }
    
    # Debug Log File #
    system($cmd_echo . ' "Server Information:" > '. $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_uname . ' -a >> '. $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_echo . ' "" >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_echo . ' "File attributes:" >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    my ($os) = callBackticks("$cmd_uname -s");
    my ($opt);
    if ( !$os =~/freebsd/i) {
        system($cmd_lsattr . ' /usr/local/cpanel/3rdparty/etc/php.ini >> '. $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
        system($cmd_lsattr . ' /usr/local/cpanel/base/frontend/x3/dynamicui/dynamicui_rvsitebuilder.conf &> ' .  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug2.log');
        system($cmd_cat . ' ' .  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug2.log >> ' .  $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
        if (-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug2.log') {
            unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug2.log');
        }
    }
    system($cmd_echo . ' "" >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_echo . ' "Report file system disk space usage" >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_df . ' -h >>  '. $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_echo . ' "" >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_echo . ' "Last Debug" >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    system($cmd_date . ' >> ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/debug.log');
    # Debug Log File #
    
    # Locale check and fix
    system($cmd_locale . ' -a |grep -i ru_RU.cp1251 > ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/.rvlocale.fix');
    open(my $FD, '<', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/.rvlocale.fix');
    my ($localeLog) = join('', <$FD>);
    close ($FD);
    $localeLog =~s/\r|\n//gi;
    if ($localeLog eq '') {
        #/usr/share/i18n/charmaps/CP1251.gz
    	system($cmd_localedef . ' -c -i ru_RU -f cp1251 ru_RU.CP1251 > /dev/null 2>&1');
    }
    if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/.rvlocale.fix') {
    	unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/.rvlocale.fix');
    }
   }
   
    # Locale check and fix
    
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Setting RVSiteBuilder User Interface') . ' has been colpleted.');
    
    my (%hSendParam);
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

sub user_array{
        my(@users);
        if(-e $InstallConf{'cpModeConfigPath'}{'root'} . "/users") {
            opendir(DIR, $InstallConf{'cpModeConfigPath'}{'root'} . '/users');
            @users = grep {!(/^\./) && -f $InstallConf{'cpModeConfigPath'}{'root'} . '/users/' . $_} readdir(DIR);
            closedir(DIR);

        }
        return @users;
}

sub registerThemePaperLantern {
	my $paperLantern = '/usr/local/cpanel/base/frontend/paper_lantern';
	my $programPath = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/panelmenus/cpanel/cpanelplugin';
	my $folderName = 'register_paper_lantern.tar.bz2';
	if (-d $paperLantern && -f $programPath . '/' . $folderName) {
		system('cp',$programPath . '/' . $folderName, '/root/');
		if (-f '/root/' . $folderName) {
            my $cmd_register = '/usr/local/cpanel/scripts/install_plugin ' . '/root/' . $folderName . ' >/dev/null 2>&1';
            RVSInstaller::ScreenControl::DisplayBoxMsg(' register paper_lantern ');
            RVSInstaller::ScreenControl::LogMsg(' register paper_lantern ==== ' . $cmd_register);
            system($cmd_register);
		}
	}
}

#######################################################################################################################
#
#######################################################################################################################
sub InstallPluginRvsOnDa {
    RVSInstaller::ScreenControl::LogMsg('Install plugin rvsitebuilder on directadmin');
    ##################
    # Update Plugin
    ##################
    system("cp -rf /usr/local/rvglobalsoft/rvsitebuilder/panelmenus/directadmin/plugin/rvsitebuilder /usr/local/directadmin/plugins/");
    system("cp -rf /usr/local/rvglobalsoft/rvsitebuilder/www/* /usr/local/directadmin/plugins/rvsitebuilder/images/");
    
    # Update extension ioncube in php.ini
    if (-f '/usr/local/directadmin/plugins/rvsitebuilderinstaller/admin/updatephpini.php') {
        my $cmdIoncube = 'php -d disable_functions="" -d safe_mode="Off" -d open_basedir="" /usr/local/directadmin/plugins/rvsitebuilderinstaller/admin/updatephpini.php';
        system($cmdIoncube);
    }
    
    if (-e '/usr/local/directadmin/plugins/rvsitebuilder/images/www') {
    	if (-d '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_help') {
    		system("rm -rf /usr/local/directadmin/plugins/rvsitebuilder/images/rvs_help");
    	}

        if (-d '/usr/local/directadmin/plugins/rvsitebuilder/images/www/rvs_library') {
            system("cp -rf /usr/local/directadmin/plugins/rvsitebuilder/images/www/rvs_library /usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library");
        }
    	
	   
	    #system("cp -rf /usr/local/directadmin/plugins/rvsitebuilder/images/www/* /usr/local/directadmin/plugins/rvsitebuilder/images/");
        system("rm -rf /usr/local/directadmin/plugins/rvsitebuilder/images/www");
    }
    
    if (-e '/usr/local/rvglobalsoft/rvsitebuilder/www') {
        system("rm -rf /usr/local/rvglobalsoft/rvsitebuilder/www");
    }
    
    if (!-l '/usr/local/rvglobalsoft/rvsitebuilder/www') {
       system("ln -s /usr/local/directadmin/plugins/rvsitebuilder/images /usr/local/rvglobalsoft/rvsitebuilder/www");
    }

    ####################
    # Make Upload Folder
    ####################
    if (!-e '/home/admin/.rvsitebuilder/upload') {
        system("mkdir -p /home/admin/.rvsitebuilder/upload");
    }
    if (!-e '/home/admin/.rvsitebuilder/upload/template') {
        system("mkdir -p /home/admin/.rvsitebuilder/upload/template");
    }
    
    if (-l '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library') {
        system('unlink /usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library');
    }
    
    if (-d '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library/rvs_library') {
        system("rm -rf /usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library/rvs_library");
    }

    # is link unlink rvs_library to copy
    DaRvslibrarycopy();


    #change permission file adn folder to admin:admin
    system("chown admin:admin /home/admin/.rvsitebuilder -R");
    
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/user -R");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/admin -R");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/hooks -R");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/scripts -R");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/reseller -R");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/plugin.conf -R");
    system("chown diradmin:diradmin /usr/local/directadmin/plugins/rvsitebuilder/images");
    
    if (!-d '/usr/local/directadmin/plugins/rvsitebuilder/images/userdata') {
        system("mkdir /usr/local/directadmin/plugins/rvsitebuilder/images/userdata");
    }
    
    if (!-d '/usr/local/directadmin/plugins/rvsitebuilder/images/project') {
        system("mkdir /usr/local/directadmin/plugins/rvsitebuilder/images/project");
    }
    
    system("chown securervsite:securervsite /usr/local/directadmin/plugins/rvsitebuilder/images/userdata");
    system("chown securervsite:securervsite /usr/local/directadmin/plugins/rvsitebuilder/images/project");
     
    system("chmod 777 /usr/local/rvglobalsoft/rvsitebuilder/var");
    system("chmod -R 755 /usr/local/directadmin/plugins/rvsitebuilder");
    if (-d '/usr/local/directadmin/plugins/rvsitebuilder/images/template'){
    	system("chmod -R 575 /usr/local/directadmin/plugins/rvsitebuilder/images/template");
    }
    if (-d '/usr/local/rvglobalsoft/rvsitebuilder/license') {
        system("chmod 575 /usr/local/rvglobalsoft/rvsitebuilder/license");
    }
    system("chmod 575 /usr/local/directadmin/plugins/rvsitebuilder/images/userdata");
    if (!-d '/usr/local/directadmin/plugins/rvsitebuilder/images/userdata/securervsite') {
        system("mkdir -p /usr/local/directadmin/plugins/rvsitebuilder/images/userdata/securervsite");
    }
    system("chown securervsite:securervsite /usr/local/directadmin/plugins/rvsitebuilder/images/userdata/securervsite");
    system("chmod 575 -R /usr/local/directadmin/plugins/rvsitebuilder/images/userdata/securervsite");
    
    system("chmod 575 /usr/local/directadmin/plugins/rvsitebuilder/images/project");
    
    if (!-l '/usr/local/rvglobalsoft/rvsitebuilder/template') {
        system("ln -s /usr/local/directadmin/plugins/rvsitebuilder/images/template /usr/local/rvglobalsoft/rvsitebuilder/template");
    }
    if (!-l '/usr/local/rvglobalsoft/rvsitebuilder/flash') {
        system("ln -s /usr/local/directadmin/plugins/rvsitebuilder/images/flash /usr/local/rvglobalsoft/rvsitebuilder/flash");
    }
    
    if (!-d '/usr/local/rvglobalsoft/rvsitebuilder/var/log') {
        system("mkdir /usr/local/rvglobalsoft/rvsitebuilder/var/log");
    }
    if (!-f '/usr/local/rvglobalsoft/rvsitebuilder/var/log/php_log.txt') {
        system("touch /usr/local/rvglobalsoft/rvsitebuilder/var/log/php_log.txt");
    }
    
    system("chmod 555 /usr/local/directadmin/plugins/rvsitebuilder/user/php.ini");
    system("chmod 555 /usr/local/directadmin/plugins/rvsitebuilderinstaller/admin/php.ini");
    system("chmod -R 777 /usr/local/rvglobalsoft/rvsitebuilder/var/log");
    
    ########################################
    # delete file INSTALL_COMPLETE.php
    ########################################
    if (-f '/usr/local/rvglobalsoft/rvsitebuilder/var/INSTALL_COMPLETE.php') {
    	system("rm -f /usr/local/rvglobalsoft/rvsitebuilder/var/INSTALL_COMPLETE.php");
    }
}

 #############################################################
    # is link unlink rvs_library to copy
 #############################################################
sub DaRvslibrarycopy()
{
	 my $dir = '/usr/local/directadmin/plugins/rvsitebuilder/images/rvs_library';
	if (-d $dir) {
	    opendir (DIR, $dir ) || die "Error in opening dir $dir\n";
	    while( (my $dirname = readdir(DIR))){
		my $path = $dir.'/'.$dirname;
			if (-d $path && $dirname ne "." && $dirname ne "..") {
		        opendir ( DIRLevel, $path) || die "Error in opening dir $path\n";
			        while( (my $filename = readdir(DIRLevel))){
				        if (-l $path . '/' . $filename) {
				        my $realpath = readlink $path . '/' . $filename;
				        unlink $path . '/' . $filename;
				        system("cp -rf $path/$realpath $path/$filename");
				        }
			        }
		       		 closedir(DIRLevel);
			}
		}
		closedir(DIR);
	 }
}


#######################################################################################################################
#   Setup RVSiteBuilder Specially Script for Control Panel
#######################################################################################################################
sub Process_SetupRVSScript{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $objLANG->TranSlate('Running specially script for') . ' ' . $objLANG->TranSlate(lc($InstallConf{'cpMode'})) . '...');
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Running specially script for') . ' ' . $objLANG->TranSlate(lc($InstallConf{'cpMode'})), '', 'subMsg' . $ACTION);
    
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Running specially script for') . ' ' . $objLANG->TranSlate(lc($InstallConf{'cpMode'})));
    
    if ( -e $InstallConf{'RVInstaller'} . '/' . lc($InstallConf{'cpMode'}) . '.pl' ) {
        open(R, $InstallConf{'RVInstaller'} . '/' . lc($InstallConf{'cpMode'}) . '.pl');
        my (@scripts) = <R>;
        close(R);
        my ($scritp) = join('', @scripts);
        eval($scritp);
    }
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Running specially script for') . ' ' . $objLANG->TranSlate(lc($InstallConf{'cpMode'})) . ' has been completed.');
    
    my (%hSendParam);
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    RVSInstaller::ScreenControl::CloseBoxMsg();
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

#######################################################################################################################
#   Group Get License Key
#######################################################################################################################
sub Process_GetLicense{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    RVSInstaller::ScreenControl::DisplayMsg('', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Updated License Key") . '.', 1);
    RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Updated License Key"));
    RVSInstaller::ScreenControl::DisplayBoxMsg(1, $objLANG->TranSlate("Updated License Key"), 'Please wait...');
    callNextFunc(\%hParam); 
}

#######################################################################################################################
#   Process Get Encryption Type
#######################################################################################################################
sub Process_GetLicenseType{
    my ($param) = $_[0];
    my (%hParam) = %{$param};

    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Encryption Type') . ' ');
    

    my ($encryptType);
    if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/encrypt-type.txt') {
        open(R, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/encrypt-type.txt');
        my (@enc) = <R>;
        close(R);
        $encryptType = join('', @enc);
        $encryptType =~s/\r|\n//gi;
    }
    else {
        $encryptType = 'sg';
    }
    
    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate($encryptType), '', 'subMsg' . $ACTION);
    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Encryption Type') . ' ' . $objLANG->TranSlate($encryptType));

    $hParam{'EncryptType'} = $encryptType;
    my (%hSendParam);
    $hSendParam{'EncryptType'} = $hParam{'EncryptType'};
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

#######################################################################################################################
#   Process Download License Key
#######################################################################################################################
sub Process_GetLicenseDow{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if ( !-d $InstallConf{'TmpLicensePath'} ) {
    	mkdir( $InstallConf{'TmpLicensePath'}, 0755 );
    }
    
    $hParam{'SaveReqFile'} = $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseReqFile'};
       
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Setting xxx request license key', $objLANG->TranSlate($hParam{'EncryptType'})), '', 'subMsg' . $ACTION);
    
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Setting xxx request license key', $objLANG->TranSlate($hParam{'EncryptType'})));
        
    if ( -e '/root/.accesshash' || $InstallConf{'cpMode'} eq 'da') {
        my ($aKey);
        $aKey = '';
        open(R, '/root/.accesshash');
        while(<R>) {
            chomp;
            s/\r|\n|\ //i;
            $aKey .= $_;
        }
        close(R);
    
        RVSInstaller::ScreenControl::LogMsg('WHM Connection');
        my $callUrl =  '/cgi/rvsitebuilderinstaller/' . $hParam{'EncryptType'} . '.php';
        
        my @page = '';
        if ( $InstallConf{'cpMode'} eq 'da') {
        	my $saveFile = ' > ' . $hParam{'SaveReqFile'};
        	my $cmdIoncube = 'php -c /usr/local/directadmin/plugins/rvsitebuilderinstaller/admin/php.ini /usr/local/rvglobalsoft/rvsitebuilderinstaller/ioncube.php' . $saveFile;
        	@page = system($cmdIoncube);
        	$tarOption = '-xvf';
        } else {
            @page = whmConnection($aKey, $callUrl);
            open(W , '>' . $hParam{'SaveReqFile'});
            foreach (@page) {
                RVSInstaller::ScreenControl::LogMsg($_);
                print W $_;
            }
            close(W);
            copy($hParam{'SaveReqFile'}, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $InstallConf{'LicenseReqFile'});
        }
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate($hParam{'EncryptType'}) . ' request key');

        chmod(0777, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $InstallConf{'LicenseReqFile'});
        
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'));
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
    
        $hParam{'SaveToFilename'} = 'mylicense.tar';
        $hParam{'LogFile'} = $InstallConf{'TmpLicensePath'} . '/.rvlicense.log';
            
        if ( -e $hParam{'LogFile'} ) {
            unlink($hParam{'LogFile'});
        }
       
        my (%licReq, $dataReq, @allIPList);
        @allIPList = RVSInstaller::Process::getAllIP();
        
        #WRITE ALL IP IN FILE :: Puttipong
        my $licensePath = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license';
        if (-w $licensePath) {
            my $fileIpAll = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/allip.ini';
            open(W, "> $fileIpAll");
            foreach my $value (@allIPList) {
                if ($value != '') {
                    print W $value . "=" . $value . "\n";
                }
            }
            close(W);
            chmod(0644,$fileIpAll);
        }
        #END WRITE ALL IP
        
        my (%OPT);
        $OPT{'saveas'} = $InstallConf{'TmpLicensePath'} . '/' . $hParam{'SaveToFilename'};
        $OPT{'URL'} = $InstallConf{'SiteConf'}{'licensekey'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'licensekey'}{'uri'}{'site1'};
        $dataReq = 'rvcode=' . rvsLicenseEncode(join('', @page));
        RVSInstaller::ScreenControl::LogMsg('License Key: ' . $dataReq . "\n");
        
        Register('saveas', $OPT{'saveas'});
        Register('URL', $OPT{'URL'});
        Register('postdata', $dataReq);
        Register('evalOutput', 1);
        Register('format', "RVSInstaller::ScreenControl::LogMsg('\$1' \. \"\\n\");RVSInstaller::ScreenControl::DisplayMsg('\$1', '1', 'subMsg' . \$ACTION);");
        
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sendding the license request to xxx', $InstallConf{'SiteConf'}{'licensekey'}{'address'}{'site1'}) , '1');
        
        Connection();
        
        my (%licVal, $Data, %hValidate);
        $hValidate{'Page'} = 1;
        if ($hValidate{'Err'} ) {
            # <-- NONE SSL Connection -->
            RVSInstaller::ScreenControl::LogMsg('Connection to ' . $InstallConf{'SiteConf'}{'licensekey'}{'address'}{'site1'} . ' prot 80  NONE SSL page ' .$InstallConf{'SiteConf'}{'licensekey'}{'uri'}{'site1'});
            #download license2 http
            
            my $url = $InstallConf{'SiteConf'}{'licensekey'}{'address'}{'site1'} . $InstallConf{'SiteConf'}{'licensekey'}{'uri'}{'site1'};
            my %hValidate = RVSInstaller::Process::postConnection($url,'POST',"rvcode=$Data");
        }
        
        if ( $hValidate{'Err'} ) {
            RVSInstaller::ScreenControl::DisplayMsg($hValidate{'Err'} , 1, 'subMsg' . $ACTION);
            $hParam{'LicenseSkip'} = 1;
        } else {
            if ( $hValidate{'Page'} ne '1') {
                $hParam{'LicenseSkip'} = 1;
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Invalid'), '', 'subMsg' . $ACTION);
            }
            else {
                  
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Running uncompressed the licenses key package'), '1', 'subMsg' . $ACTION);
                chdir($InstallConf{'TmpLicensePath'});
                my (@logTarData); 
                $SIG{'PIPE'} = 'IGNORE';
                $SIG{'HUP'}  = 'IGNORE';
                $SIG{'ALRM'} = 'IGNORE';
                ############### download file  mylicense.tar and change permission and extract file ###########
                chmod(0755, $InstallConf{'TmpLicensePath'} . '/' . $hParam{'SaveToFilename'});
                my $cmdTar = $cmd_tar . ' ' . $tarOption . ' ' . $hParam{'SaveToFilename'} . ' >/dev/null 2>&1';
                RVSInstaller::ScreenControl::LogMsg('extract cmd=' . $cmdTar . "]\n");
                system($cmdTar);
                
                #open PID, $cmd_tar . ' ' . $tarOption . ' ' . $hParam{'SaveToFilename'} . '|'; 
                #while (<PID>) {
                #    ~s/\r|\n//gi;
                #    push(@logTarData, $_); 
                #}
                #close(PID);
                 if (!-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license') {
                 	system('mkdir -p ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license');
                 }
                 system('chown securervsite:securervsite ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license');
                 
                 if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} ) {
                    unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
                 }
                 
                 if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} ) {
                    unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
                 }
                 
                 if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} ) {
                    unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
                 }
                 
                 if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} ) {
                    unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
                 }
                 
                $hParam{'GetLicenseDow'} = 'Completed';
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            }
        }
    } else {
        # <-- Not Read Root accesshash -->
        $hParam{'LicenseSkip'} = 1;
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Cannot read remote access key'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot read remote access key'));
    }
    my (%hSendParam);
    $hSendParam{'LicenseSkip'} = $hParam{'LicenseSkip'};
    $hSendParam{'EncryptType'} = $hParam{'EncryptType'};
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

#######################################################################################################################
#   Process Download License Key
#######################################################################################################################
sub Process_GetLicenseLite{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder Lite')), '', 'subMsg' . $ACTION);
    
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder Lite')));
   
    if ( $hParam{'LicenseSkip'} ) {
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder Lite')) . ' has been skip.');
    } else {
    	if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'}) {
    		unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
    	}
    	
        if ( -e $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} ) {
            RVSInstaller::ScreenControl::LogMsg('Copy license RVSiteBuilder Lite file to program path');
            
            if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} ) {
                my ($os) = callBackticks("$cmd_uname -s");
                my ($opt);
                if ( $os =~/freebsd/gi) {
                    system($cmd_chflags . ' noschg ' . $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} . ' >/dev/null 2>&1')
                } else {
                    system($cmd_chattr . ' -i ' . $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} . ' >/dev/null 2>&1')
                }
            }
            
            copy($InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'}, 
                $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
                
            chmod(0464, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
            system('chown securervsite:securervsite ' . $InstallConf{'cpModeConfigPath'}{'programPath'} 
                . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
            
            unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
            
            if ( !readlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'}) ) {
                chdir($InstallConf{'cpModeConfigPath'}{'programPath'});
                symlink('var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'} 
                    , $InstallConf{'LicenseKey'}{'rvsitebuilder-lite'});
                chdir($InstallConf{'ThisParh'});
            }
            
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg('Copy license RVSiteBuilder Lite file to program path has been completed');
        } else {
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Failed'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('RVSiteBuilder Lite license key')), '', 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('RVSiteBuilder Lite license key')));
        }
    }
    my (%hSendParam);
    $hSendParam{'LicenseSkip'} = $hParam{'LicenseSkip'};
    $hSendParam{'EncryptType'} = $hParam{'EncryptType'};
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

#######################################################################################################################
#   Process Download License Key
#######################################################################################################################
sub Process_GetLicensePro{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder')), '', 'subMsg' . $ACTION);
    
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder')));
    if ( $hParam{'LicenseSkip'} ) {
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Skip'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder Lite')) . ' has been skip.');
    } else {
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} = 1;
        
        if ( !$hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} || 
        $hLicenseInfo{'rvsitebuilder'}{'products'}{'pro'} eq '' ) {
        	
            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Unavailable'), '', 'subMsg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
            RVSInstaller::ScreenControl::LogMsg(
                $objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder Lite')) . ' has been unavailable.');
        } else {
        	if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} ) {
        	   unlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
        	}
        	
            if (-e $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} ) {
                
                if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} ) {
                    my ($os) = callBackticks("$cmd_uname -s");
                    if ( $os =~/freebsd/gi) {
                        system($cmd_chflags . ' noschg ' . $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} . ' >/dev/null 2>&1');
                    } else {
                        system($cmd_chattr . ' -i ' . $InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} . ' >/dev/null 2>&1');
                    }
                }
                
                copy($InstallConf{'TmpLicensePath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'}
                    , $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
                    
                chmod(0464, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
                system('chown securervsite:securervsite ' . $InstallConf{'cpModeConfigPath'}{'programPath'} 
                    . '/var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
                
                if ( !readlink($InstallConf{'cpModeConfigPath'}{'programPath'} . '/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'}) ) {
                    chdir($InstallConf{'cpModeConfigPath'}{'programPath'});
                    symlink('var/license/' . $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'} , $InstallConf{'LicenseKey'}{'rvsitebuilder-pro'});
                    chdir($InstallConf{'ThisParh'});
                }
                
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Updatting xxx license key', $objLANG->TranSlate('RVSiteBuilder')) . 'has been completed.');
            } else {
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('RVSiteBuilder license key')), '', 'subMsg' . $ACTION, '', '#FF0000');
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('RVSiteBuilder license key')));
            }
        }
    }
    
    my (%hSendParam);
    $hSendParam{'LicenseSkip'} = $hParam{'LicenseSkip'};
    $hSendParam{'EncryptType'} = $hParam{'EncryptType'};
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    RVSInstaller::Process::unlinkAll($InstallConf{'TmpLicensePath'});
    callNextFunc(filterParam(\%hSendParam, \%hParam));
}

sub Process_end{
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    if(RVSInstaller::CommonLib::isNewServer()){
		RVSInstaller::CommonLib::autoCrateDabase();
		RVSInstaller::CommonLib::testConnectionDb();
    }
    
    #case force=database
    if (defined $SCRIPT_OPT->{'force'} || (defined $ARGUMENT{'force'} && ($ARGUMENT{'force'} eq 'database'))) {
        my $installComplete = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE';
        my $installCompletePhp = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE.php';
        if (-e $installComplete) {
            unlink $installComplete;	
        }
        if (-e $installCompletePhp) {
            unlink $installCompletePhp;    
        }
    }
    
    #Move md5 download path to program path #fix md5 file
    my $md5File = {
		'rvsitebuilder'	=> 'rvsitebuilder.md5',
		'templatepreview'	=> 'templatepreview.md5',
		'templatefullpackage'	=> 'fullpackage.md5',
		'database'	=> 'library.md5',
		'rvseagullmod'	=> 'rvseagullmod.md5',
        'language'	=> 'language.md5',
    };
    
    if($InstallConf{'on-demandTemplate'}){
    	unlink $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $md5File->{'templatefull'} if(-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $md5File->{'templatefullpackage'});
    	delete $md5File->{'templatefullpackage'};
    }else{
    	unlink $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $md5File->{'templatepreview'} if(-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $md5File->{'templatepreview'});
    	delete $md5File->{'templatepreview'};
    }
    
    foreach my $eachPackage (keys %{$md5File}){
    	my $md5Provider = $InstallConf{'PackagePath'} . '/' . $md5File->{$eachPackage};
    	my $md5Local = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $md5File->{$eachPackage};
    	if(-f $md5Provider){
    		unlink $md5Local if(-f $md5Local);
    		copy($md5Provider,$md5Local);
    	}
    }
    
    if (-f ('/scripts/rvspredatabasesetup') && -x ('/scripts/rvspredatabasesetup')) {
        my ($installLog) = $InstallConf{'cpModeConfigPath'}{'companyPath'} . '/.rvsitebuilder/rvspredatabasesetup.log';
        system('/scripts/rvspredatabasesetup >' . $installLog);
                        
        my $msgErrorLog;
        my $msgErrorBrowser;
        open (FILE, '<', $installLog);
        while (<FILE>) {
            $msgErrorLog .= $_;
            $msgErrorBrowser .= $_ . '<br/>';
        }
        close(FILE);
        
        if ( $BROWSER) {
            RVSInstaller::ScreenControl::DisplayMsg($msgErrorBrowser, 1, 'msg' . $ACTION);
            RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msgErrorBrowser);
        } else {
            RVSInstaller::ScreenControl::DisplayMsg($msgErrorBrowser, 1);
            RVSInstaller::ScreenControl::LogMsg($msgErrorLog);
        }
        
        unlink($installLog);
        
    }
    
    #Build version
    my $versionFile = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilderversion.txt';
    my $rvsitebuilderversion = '';
    if ($hParam{'rollback'}) {
    	$rvsitebuilderversion = $hParam{'rollback'};
    } elsif (defined $hParam{'getversion'} && ($hParam{'getversion'} ne 'latest')) {
        $rvsitebuilderversion = $hParam{'getversion'};
    }else{
        $rvsitebuilderversion = RVSInstaller::CommonLib::getLatestVersion();
    }
    if($rvsitebuilderversion ne ''){
		open my $FW, '>', $versionFile;
	    print $FW "$rvsitebuilderversion";
	    close($FW);
    }
    

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

        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate("Install RVSiteBuilder has completed") .'.', 1, 'msg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Install RVSiteBuilder has completed") . '.');
        
        my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
        my ($script, $redirect);
        
        my $expireTime = (exists $hLicenseInfo{'rvsitebuilder'}{'expire-date'}) 
                ? $hLicenseInfo{'rvsitebuilder'}{'expire-date'}
                : time + 3600;
        $redirect = 'index.php?action=DBsetup&exp=' .  $expireTime;
        if ( -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE' 
            || -e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE.php') {
            $redirect .= '&updatedb=1';
        }
        
        $script = $WEBROOT . '/index.php?action=Download&redirect=' .  RVSInstaller::Process::URLEncode($redirect);
        RVSInstaller::ScreenControl::jsMetaRedirect(lc($InstallConf{'cpMode'}), $script);
    } else {
	    if ( $InstallConf{'cpMode'} eq 'cpanel') {
	        RVSInstaller::ScreenControl::DisplayMsg('', 1);
	        RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
	        RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . $objLANG->TranSlate("Updated Database and Configuration") .'.', 1);
	        RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
	        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Updated Database and Configuration"));
	        my ($mainIP);
	        RVSInstaller::ScreenControl::DisplayMsg('Main IP');
	        
	        $mainIP = RVSInstaller::Process::getMainIP();
	        RVSInstaller::ScreenControl::DisplayMsg('<TAB>' . $mainIP , 1);
	        if ( -f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.default.conf.ini.php' ) {
	            
	            open(R, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.default.conf.ini.php');
	            my (@pears) = <R>;
	            close(R);
	            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Setting bootstrap'));
	            open(W, '>' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.default.conf.ini.php');
	            foreach (@pears) {
	                if (/^bootstrap/i) {
	                    print W 'bootstrap=1' . "\n";
	                }
	                else {
	                    print W $_;   
	                }
	            }
	            close(W);
	            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
	            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
	            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
	            
	            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Loading xxx', $objLANG->TranSlate('default configuration')) . ' has ready.');
	            my (%RVSCong, $module);
	            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx', $objLANG->TranSlate('default configuration')));
	            
	            open(R, $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.default.conf.ini.php');
	            while (<R>) {
	                ~s/\r|\n//gi;    
	                if ( /^;/i || $_ eq '') {
	                    next;
	                }
	                elsif ( /^\[(.*?)\]/i ) {
	                    ~s/^\ //gi;
	                    ~s/\ $//gi;
	                    $module = $1;
	                }
	                else {
	                    my ($rvsKey, $rvsValue) = split(/=/, $_, 2);
	                    $rvsKey =~s/^\ //gi;
	                    $rvsKey =~s/\ $//gi;
	                    $rvsValue =~s/^\ //gi;
	                    $rvsValue =~s/\ $//gi;
	                    $rvsValue =~s/"//gi;
	                    if ( $module eq '' ) {
	                        $RVSCong{$rvsKey} = $rvsValue;
	                    }
	                    else {
	                        $RVSCong{$module}{$rvsKey} = $rvsValue;
	                    }
	                }
	            }
	            close(R);
	            
	            
	            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
	            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
	            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
	            
	            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate("Updated Database and Configuration"), '1');
	            if ( lc($InstallConf{'cpMode'}) eq 'cpanel') {
	                whmUpdateDB(\%RVSCong);
	            }
	        } elsif ( -f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.conf.php' 
	                   || -f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php'  ) {
	            
	             my (%RVSCong);           
	            whmUpdateDB(\%RVSCong);
	            RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
	            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
	            RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
	        } else {
	            my %RVSCong = ();
	            my $hostname = callBackticks("hostname");
	    		chomp($hostname);
	            $ARGUMENT{'protocol'} = ($ARGUMENT{'dbname'} eq 'localhost' || $ARGUMENT{'dbname'} eq $mainIP || $ARGUMENT{'dbname'} eq $hostname)?'unix':'tcp';
				$RVSCong{'db'} = {
					'name' => $ARGUMENT{'dbname'},
					'host' => $ARGUMENT{'dbhost'},
					'protocol' => $ARGUMENT{'protocol'},
					'port' => $ARGUMENT{'dbport'},
					'user' => $ARGUMENT{'dbuser'},
					'pass' => $ARGUMENT{'dbpassword'}
				};
	            whmUpdateDB(\%RVSCong);
	            if ( !-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/' . $mainIP . '.conf.php' 
	                   || !-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php'  ) {
	                RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
	                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('default configuration')) . '.', 1, 'subMsg' . $ACTION, '', '#FF0000');
	                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
	                RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('default configuration')) . '.');
	            }
	        }
	    }
	    if($InstallConf{'cpMode'} eq 'da'){
            RVSInstaller::ScreenControl::DisplayMsg("", 1);
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Update RVSiteBuilder has has been successfully'), 1);
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('And go to Directadmin admin'), 1);
	    }
   }
}

sub whmUpdateDB{
    my (%RVSConf) = %{$_[0]};
    my ($hashKey);
    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Loading xxx', $objLANG->TranSlate('remote access key')));
    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** run whmUpdateDB'));
    
    if ( -e '/root/.accesshash' ) {
        my ($aKey);
        $aKey = '';
        open(R, '/root/.accesshash');
        while(<R>) {
			chomp;
			s/\r|\n|\ //i;
			$aKey .= $_;
		}
		close(R);
		my ($dbUpdate);
		my $skipautocreatedb = 1;
		
		if (!$skipautocreatedb && !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE' 
		     && !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/INSTALL_COMPLETE.php' 
		     && !-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php'
		) {
			RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** 1 New Install'));
		    # <-- New Install -->
		    my ($createDBCompleted);
		    if (-e '/root/.my.cnf') {
		        ## Auto create DB
		        if (autoCreateRVSDB()) {
		            ## Auto Create DB
                    $dbUpdate = $InstallConf{'cpModeConfigPath'}{'SetupWizardURL'};
                    $createDBCompleted = 1;
		        }
		    } 
		    
		    if (!$createDBCompleted) {
                ## Auto Create DB Failed
                RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('cannot new installer database configuration') . '.', 1);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Please use WHM to update') . '.', 1);
            }
		}
		elsif (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/setup.php' ) {
			RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** 2 Run setup.php'));
		    $dbUpdate = $InstallConf{'cpModeConfigPath'}{'SetupWizardURL'};
		}
		else {
			RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** 3 Run SetupWizardURL'));
     	    $dbUpdate = $InstallConf{'cpModeConfigPath'}{'SetupWizardURL'};
		    $dbUpdate .= '?name=' . $RVSConf{'db'}{'name'};
            $dbUpdate .= '&type=1';
            $dbUpdate .= '&host=' . $RVSConf{'db'}{'host'};
            $dbUpdate .= '&protocol=' . $RVSConf{'db'}{'protocol'};
            $dbUpdate .= '&port=' . $RVSConf{'db'}{'port'};
            $dbUpdate .= '&user=' . $RVSConf{'db'}{'user'};
            $dbUpdate .= '&pass=' . $RVSConf{'db'}{'pass'};
            $dbUpdate .= '&exp=' . $RVSConf{'SiteBuilder'}{'exp'};
            $dbUpdate .= '&setupType%5BsetConnectionDetails%5D=1';
            $dbUpdate .= '&setupType%5BupDataSitebuilder%5D=1';
            $dbUpdate .= '&btnSubmit=Execute+%28pls+be+patient+if+schema+creation+selected%29';
		}
		
		RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
		
		RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Update RVSiteBuilder Database', 1));
		
		RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** 4 update URL ' . $dbUpdate));

		my @page = whmConnection($aKey, $dbUpdate);
		RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
        
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Clear RVSiteBuilder Cache files', 1));
		@page = whmConnection($aKey, $InstallConf{'cpModeConfigPath'}{'clearCacheURL'});
		RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** 6 clear cache URL ' . $InstallConf{'cpModeConfigPath'}{'clearCacheURL'}));
        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
	    RVSInstaller::ScreenControl::DisplayMsg("", 1);
		RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Update RVSiteBuilder has has been successfully'), 1);
    }
    else {
        RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Sorry') . ', ' . $objLANG->TranSlate('Find not found xxx', $objLANG->TranSlate('remote access key')) . '.', 1, 'subMsg' . $ACTION, '', '#FF0000');
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('****** Find not found access hash'));
    }
}

sub autoCreateRVSDB{
    my (%rvSettingDist);
    if (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/rvautosetting.conf.dist.ini') {
        %rvSettingDist = readINIfile($InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/rvautosetting.conf.dist.ini');
    }
    
    my ($dbuser, $dbpass, $dbserver, $dbport, $dbdb);
    open(DBS,"/root/.my.cnf");   # in some server there is not /root/.my.cnf
    while ( <DBS>) {
        if (/^pass=(\S+)/) {
            $dbpass = $1;
            $dbpass =~ s/^\"|\"$//g;
        }
        if (/^host=(\S+)/) {
            $dbserver = $1;
            $dbserver =~ s/^\"|\"$//g;
        }
        if (/^port=(\S+)/) {
            $dbport = $1;
            $dbport =~ s/^\"|\"$//g;
        }
        if (/^user=(\S+)/) {
            $dbuser = $1;
            $dbuser =~ s/^\"|\"$//g;
        }
    }
    close(DBS);
    if (!$dbserver) {
        $dbserver = "localhost"; 
    }
    
    if (!$dbport) {
        $dbport = 3306;
    }
    if (!$dbuser) {
        $dbuser = 'root';   
    }
    my ($rvsDBUser, $rvsDBPasswd, $rvsDBName);
    
    $rvsDBPasswd = _genPasswd();
    $rvsDBUser = 'sitebuilder' . _genPasswd(3);
    
    
    if(RVSInstaller::CommonLib::validateArgumentType('database')){
		$rvsDBName = $ARGUMENT{'dbname'},
		$dbserver =  $ARGUMENT{'dbhost'},
		$dbport = $ARGUMENT{'dbport'},
		$rvsDBUser = $ARGUMENT{'dbuser'},
		$rvsDBPasswd =  $ARGUMENT{'dbpassword'}
    }
    
    $dbdb = 'mysql';
    my ($dbh) = DBI->connect("DBI:mysql:$dbdb:$dbserver:$dbport", "$dbuser", "$dbpass");
    unless ( $dbh ) {
        return 0;
    }
    
    if($rvsDBName eq ''){
	    my ($dbcheck);
	    my ($q) = $dbh->prepare("show databases;");
	    $q->execute;
	    do {
	        $dbcheck = "";
	        $rvsDBName = 'sitebuilder' . _genPasswd(3);
	        while( my $data = $q->fetchrow_arrayref) {
	            if ($data->[0] =~ /\b$rvsDBName\b/) {
	                $dbcheck = "1";
	            }
	        }
	    } while ($dbcheck eq "1");
	    
	    $q->finish();
    }

   $dbh->do("CREATE DATABASE IF NOT EXISTS `$rvsDBName`;");
   $dbh->do("FLUSH PRIVILEGES;");
   
    my ($mainip,$hostname);
    $hostname = callBackticks("hostname");
    chomp($hostname);
    $mainip = RVSInstaller::Process::getMainIP();
    
    $dbh->do("GRANT ALL PRIVILEGES ON `$rvsDBName`.* TO '$rvsDBUser'\@'localhost' IDENTIFIED BY '$rvsDBPasswd';");
    $dbh->do("GRANT ALL PRIVILEGES ON `$rvsDBName`.* TO '$rvsDBUser'\@'$mainip' IDENTIFIED BY '$rvsDBPasswd';");
    $dbh->do("GRANT ALL PRIVILEGES ON `$rvsDBName`.* TO '$rvsDBUser'\@'$hostname' IDENTIFIED BY '$rvsDBPasswd';");
    $dbh->do("FLUSH PRIVILEGES;");
    $dbh->disconnect();
    
    $dbh = DBI->connect("DBI:mysql:$rvsDBName:$dbserver:$dbport", "$rvsDBUser", "$rvsDBPasswd");
    unless ($dbh) {
        return 0;
    }
    $dbh->disconnect();
    open(my $FD, '<', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/rvautosetting.conf.dist.ini');
    my (@rvDists) = <$FD>;
    close($FD);
    open(my $FW, '<', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/etc/rvautosetting.conf.ini.php');
    foreach (@rvDists) {
        my ($key, $value) = split(/=/, $_, 2);
        chomp($key);
        if (lc($key) eq 'host') {
            print $FW, "host=\"$dbserver\"\n";
        } elsif (lc($key) eq 'name') {
            print $FW, "name=\"$rvsDBName\"\n";
        } elsif (lc($key) eq 'databaseUser') {
            print $FW, "databaseUser=\"$rvsDBUser\"\n";
        } elsif (lc($key) eq 'databaseUserPass') {
            print $FW, "databaseUserPass=\"$rvsDBPasswd\"\n";
        } elsif (lc($key) eq 'port') {
            print $FW, "port=\"$rvsDBPasswd\"\n";
        } elsif (lc($key) eq 'protocol') {
            if ($dbserver eq 'localhost' || $dbserver eq $mainip || $dbserver eq $hostname) {
                print $FW, "protocol=\"unix\"\n";
            } else {
                print $FW, "protocol=\"tcp\"\n";
            }
        } else {
            print $FW, $_;   
        }
    }
    close($FW);
    return 1;
}

sub _genPasswd{
    my ($max) = shift;
    if (int $max <= 0) {
        $max = 16
    }
    my (@aChar) = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
    my ($passwd) = '';
    my ($num) = scalar(@aChar) -1;
    for (my $loop =0; $loop < $max; $loop++) {
        my ($randnum) = rand($num);
        my ($text) = $aChar[$randnum];
        $passwd .= $text;
    }
    return $passwd;
}

##loopbackip มีปัญหา loopbackip มากกว่า 1 จะทำให้ socket ไม่ได้จะต้องเปลี่ยนเป็น mainip แทน
sub _getLoopbackIp {
    my $mainIP = '127.0.0.1';
    if (is2loopback() == 1) {
        $mainIP = RVSInstaller::Process::getMainIP();;
    }
    RVSInstaller::ScreenControl::LogMsg(' == mainIP == ' . $mainIP);
	return $mainIP;
}

sub is2loopback {
    my $cmd_uname = RVSInstaller::Process::rvsWhich('uname');
    my $system = callBackticks("$cmd_uname -s");
    my @allIPList = ();
    $system =~s/\n|\r//gi;
    my $ips = '';
    my @ListIPS = ();
    if ( $system =~/freebsd/i) {
        $ips = callBackticks('/sbin/ifconfig -a');
    } else {
        $ips = callBackticks("/sbin/ifconfig");
    }
    @ListIPS = split('\n', $ips);
    my  $count = 0 ;
    foreach (@ListIPS) {
        if ( /(\d*)\.(\d*)\.(\d*).(\d*)/) {
            if ( $1 eq '127' ) {
                $count++;
            }
        }
    }
    return ($count > 1) ? 1:0;
}


sub whmConnection {
	my ($accesskey, $request) = @_;
	my (@PAGE, $error, @pairs, $pair, $name,$value,$system);
	$accesskey =~s/[\r|\n]*//g;
	RVSInstaller::ScreenControl::LogMsg(' == request == ' . $request);
	if ($accesskey) {
		my $authstr = "root:$accesskey";
		my $proto = getprotobyname('tcp');
		socket(WHM, AF_INET, SOCK_STREAM, $proto) || print "socket error: $!\n";
		# my $iaddr = gethostbyname("localhost") || print "Unable to resolve localhost\n";
		# my $iaddr =  pack("C4",127,0,0,1); ยกเลิกบรรทัดนี้
		# Boom: เปลี่ยนมาใช้แบบนี้แทน เหมือนจะมีปัญหาคับ 127.0.0.1
	    
	    my $mainIP = _getLoopbackIp();
	    my $iaddr =  inet_aton($mainIP);
	    
		my $port = 2086;
		my $referer = 'http://' . RVSInstaller::Process::getMainIP() . ':2086';    
		my $sin = sockaddr_in($port, $iaddr);
		connect("WHM", $sin) || print "Unable to connect to WHM\n";
		send WHM, "GET $request HTTP/1.0\n", 0;
        send WHM, "Referer: $referer\n", 0;
		send WHM, "Connection: close\n", 0;
		send WHM, "Authorization: WHM $authstr\n\n", 0;
		my $inheaders = 1;
		print "\nRequest: $request\n";
		while(<WHM>) {
			s/\n|\r\n//g;
			if (!$inheaders) {
			    push(@PAGE,$_);
			}
			$inheaders = 0 if (/^$/ && $inheaders);
			if (/^Location/i) {
			    my ($loc);
			    ($loc, $request) = split(/:/, $_, 2);
			    $request =~s/^\ //gi;
			   $request =~s/\ $//gi;
			   $request =~s/http\:\/\/.?\:2086//gi;
			   $request =~s/https\:\/\/.?\:2087//gi;
			   
			   #if ($request =~/\/cp/gi) {
			     goto REDIRECT;
			   #}
			}
		}
		close(WHM);
	}
	else {
		push(@PAGE, "Missing WHM Remote Access Key.");
		print "<h1 align=center>Error!! Missing WHM Remote Access Key.</h1>";
	}
	return(@PAGE);
REDIRECT:
    close(WHM);
    @PAGE = whmConnection($accesskey, $request);
    return(@PAGE);
}

sub filterParam{
    my (%params) = %{$_[0]};
    my (%masterParams) = %{$_[1]};
    if ( exists $masterParams{'rollback'}) {
        $params{'rollback'} = $masterParams{'rollback'};
    }
    if ( exists $masterParams{'getversion'}) {
        $params{'getversion'} = $masterParams{'getversion'};
    }
    if ( exists $masterParams{'debug'}) {
        $params{'debug'} = $masterParams{'debug'};
    }
    return \%params;
}

# $perlv =~ /PHP (\d+\.\d+\.\d+)/ 3 digit
# $perlv =~ /PHP (\d+\.\d+)/ 2 digit
sub getPhpVersion{
    my $perlv = callBackticks("php -v");
    if ( $perlv =~ /PHP (\d+\.\d+)/ ) {
        return $1;
    } else {
        return 'unknown';
    }
}

sub getcPanelVersion{
    my ( $cpVer );
    open(VERSION,'<',"/usr/local/cpanel/version");
    $cpVer=join('', <VERSION>);
    close(VERSION);
    chomp($cpVer);
    
    my ( $ver, $temp_max, $rel, $r_ver, $ver_1, $ver_2, $ver_3, $version);
    ( $ver, $temp_max) = split(/-/, $cpVer, 2);
    ( $rel, $r_ver ) = split( /_/, $temp_max, 2);
    ( $ver_1, $ver_2, $ver_3 ) = split(/\./,$ver, 3);
    my ($verstion);
    $verstion ={
        'realVersion' =>  $cpVer,
        'version' => {
            'string' => $ver,
            'int' => {
               '1' => $ver_1 ? $ver_1 : 0,
               '2' => $ver_2 ? $ver_2 : 0,
               '3' => $ver_3 ? $ver_3 : 0,
            },
        },
        'release' => {
            'string' => $temp_max,
            'int' => {
                '1' => $rel,
                '2' => $r_ver,
            }
        },
    };
    return $verstion;
}

sub fixPHPExtensionPath{
	RVSInstaller::ScreenControl::LogMsg('go to fixPHPExtensionPath');
    if ( $InstallConf{'cpMode'} eq 'cpanel' ) {
    	my ($extensionPath) = callBackticks("/usr/local/cpanel/3rdparty/bin/php-config --extension-dir");
        chomp($extensionPath);
        if ($extensionPath =~/^\/usr\/local\/cpanel\/3rdparty\//i && !-d $extensionPath) {
            system('mkdir', '-p', $extensionPath);
        }
    }
    
    if ( $InstallConf{'cpMode'} eq 'da') {
    	my ($extensionPath) = callBackticks("/usr/local/bin/php-config --extension-dir");
        chomp($extensionPath);
        if ($extensionPath =~/^\/usr\/local\/lib\/php\//i && !-d $extensionPath) {
            system('mkdir', '-p', $extensionPath);
        }
    }

    if (-f $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/fixionc.pl') {
        system($cmd_perl . ' ' . $InstallConf{'cpModeConfigPath'}{'ManagerPath'} . '/rvsitebuilderinstaller/fixionc.pl > /dev/null');
    }
}

sub findBunzip2{
	if ($skipBzip2) {
		return 0;
	}
	if (-x '/usr/bin/bunzip2') {
		return '/usr/bin/bunzip2';
	} elsif (-x '/usr/local/bin/bunzip2') {
		return '/usr/local/bin/bunzip2';
	} else {
		my ($bzip2Path) = callBackticks("which bunzip2");
		chomp($bzip2Path);
		if ($bzip2Path ne '' && -x $bzip2Path) {
			return $bzip2Path;
		} else {
			return 0;
		}
	}
}

sub getPearBin{
    my ($pear_bin) = $_[0];

    my $rvpear_bin = $pear_bin;
    $rvpear_bin =~s/pear$/rvpear/;
    my $phpBin = '$PHP';
    if ($BROWSER && ($pear_bin eq '/usr/local/bin/pear')) {
        $phpBin = '/usr/local/bin/php';
    }

    #clear disable_functions=ini_set,ini_get,popen,
    #memory_limit=64M
    #clear extension_dir  example suhosin
    #Case /usr/local/bin/php Must use suhosin.executor.func.blacklist=''
    my $phpDefineConfig = '-d disable_functions="" -d register_globals="Off" -d suhosin.executor.func.blacklist="" -d memory_limit=128M -d max_execution_time=3600';
    
    #my $exeCommand = sprintf(
    #    'exec $PHP -C -q %s $INCARG -d output_buffering=1 -d variables_order=EGPCS -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" $INCDIR/pearcmd.php "$@"'
    #    , $phpDefineConfig);
        
    my $exeCommand = sprintf(
        'exec %s -C -q %s $INCARG -d output_buffering=1 -d variables_order=EGPCS -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" $INCDIR/pearcmd.php "$@"'
        , $phpBin, $phpDefineConfig);
    
    open my $FR, '<', $pear_bin;
    my @aFile = <$FR>;
    close($FR);
    
    open my $FW, '>', $rvpear_bin;
    foreach my $line(@aFile){
        $line =~s/\r|\n//gi;
        if ($line =~/^exec \$PHP/) {
            print $FW $exeCommand . "\n";
        } else {
            print $FW "$line\n";
        }
    }
    close($FW);

    if (-e $rvpear_bin) {
        chmod(0700, $rvpear_bin);
    }    
    
    return $rvpear_bin;      
}

sub removeRvPearBin{
    my ($rvpear_bin) = $_[0];
    
    if (-e $rvpear_bin) {
        if ($rvpear_bin =~ /rvpear$/) {
            unlink($rvpear_bin);
        }        
    }
}

sub uninstallRVSeagullMod {
    my ($pear_bin, $install_type) = @_;

    $pear_bin = getPearBin($pear_bin);
    
    my $php_dir = callBackticks("$pear_bin config-get php_dir");
    $php_dir =~s/\r|\n//gi;

        
    if (-e "$php_dir/RVSeagullMod") {
        system($pear_bin . ' uninstall -n RVSeagullMod');
        RVSInstaller::ScreenControl::LogMsg($pear_bin . ' uninstall -n RVSeagullMod');
        
        if (-e "$php_dir/RVSeagullMod") {
            system($cmd_rm . " -rf $php_dir/RVSeagullMod")
        }
        
        my $msg = 'Uninstall RVSeagullMod for ' . $install_type . '. ' . $objLANG->TranSlate("Please wait") . '...';
        RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg);
        RVSInstaller::ScreenControl::DisplayMsg($msg, '1', 'subMsg' . $ACTION);
        RVSInstaller::ScreenControl::LogMsg($msg . "\n");
    }
    removeRvPearBin($pear_bin);
}

sub installRVSeagullMod {
    my ($pear_bin, $install_type) = @_;
    my ($temp_dir, $cache_dir, $download_dir, $current_temp_dir, $current_cache_dir, $current_download_dir);
    my ($install_log) = $InstallConf{'cpModeConfigPath'}{'companyPath'} . '/.rvsitebuilder/pearInstallation.log';
        
    my $rvTmpPath = $InstallConf{'cpModeConfigPath'}{'companyPath'} . '/.rvsitebuilder/pear/tmp';
    my $rvpearFile = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/RVSeagullMod-1.0.1.tgz';
    
    my $sourceRVSeagullMod = $InstallConf{'PackagePath'} . '/RVSeagullMod-1.0.1.tgz';
    if(-f $sourceRVSeagullMod){
    	unlink $rvpearFile if(-f $rvpearFile);
    	copy($sourceRVSeagullMod,$rvpearFile);
    }
    
    my $installPearResult;
        
    if (! -d $rvTmpPath) {
        system($cmd_mkdir . ' -p ' . $rvTmpPath);
    }
    
    chdir('/');
        
    if (!-x $pear_bin) {
        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('Cannot execute pear on path') . ' ' . $pear_bin, 1, 'subMsg' . $ACTION, '', '#FF0000');
        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);

        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot execute pear on path') . ' ' . $pear_bin);
        RVSInstaller::ScreenControl::LogMsg('Exit 1');
        exitScript();            
    } else {    
        
        if ($InstallConf{'cpMode'} eq 'cpanel') {
            $pear_bin = getPearBin($pear_bin);
        } 
        
        my $php_bin = callBackticks("$pear_bin config-get php_bin");
        RVSInstaller::ScreenControl::LogMsg('1 output ?=' . $?);
        if($? != 0 && $? != 1){
            RVSInstaller::ScreenControl::LogMsg('Output php_bin:' . $php_bin);
            
            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('Cannot execute pear command because') . ' ' . $php_bin, 1, 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
            
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot execute pear command because') . ' ' . $php_bin);
            removeRvPearBin($pear_bin);
            RVSInstaller::ScreenControl::LogMsg('skip Exit 2');
            #exitScript();
         }                    
        
        $php_bin =~s/\r|\n//gi;  

        my $php_dir = callBackticks("$pear_bin config-get php_dir");   
        $php_dir =~s/\r|\n//gi;
        if (!-e $php_bin) {
        	$php_bin = '/usr/local/bin/php';
        }
        if (!-x $php_bin) {
            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('Cannot execute php on path') . ' ' . $php_bin, 1, 'subMsg' . $ACTION, '', '#FF0000');
            RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
            
            RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot execute php on path') . ' ' . $php_bin);
            removeRvPearBin($pear_bin);
            RVSInstaller::ScreenControl::LogMsg('Exit 3');
            exitScript();
               
        } else {
                
           #backup config path เก็บ default ของเครื่องไว้ก่อน
            $temp_dir = callBackticks("$pear_bin config-get temp_dir");
            $cache_dir = callBackticks("$pear_bin config-get cache_dir");
            $download_dir = callBackticks("$pear_bin config-get download_dir");
            $temp_dir =~s/\r|\n//gi;
            $cache_dir =~s/\r|\n//gi;
            $download_dir =~s/\r|\n//gi;
                
            #reset config path
            system($pear_bin . ' config-set temp_dir ' . $rvTmpPath . ' >/dev/null');
            system($pear_bin . ' config-set cache_dir ' . $rvTmpPath . ' >/dev/null');
            system($pear_bin . ' config-set download_dir ' . $rvTmpPath . ' >/dev/null');
                
            $current_temp_dir = callBackticks("$pear_bin config-get temp_dir");
            $current_cache_dir = callBackticks("$pear_bin config-get cache_dir");
            $current_download_dir = callBackticks("$pear_bin config-get download_dir");
            $current_temp_dir =~s/\r|\n//gi;
            $current_cache_dir =~s/\r|\n//gi;
            $current_download_dir =~s/\r|\n//gi;                            
                
            
            RVSInstaller::ScreenControl::LogMsg('0:temp_dir: ' . $temp_dir);
            RVSInstaller::ScreenControl::LogMsg('0:cache_dir: ' . $cache_dir);
            RVSInstaller::ScreenControl::LogMsg('0:download_dir: ' . $download_dir);
            
            RVSInstaller::ScreenControl::LogMsg('=============================');
             
            RVSInstaller::ScreenControl::LogMsg('1:temp_dir: ' . $current_temp_dir);
            RVSInstaller::ScreenControl::LogMsg('1:cache_dir: ' . $current_cache_dir);
            RVSInstaller::ScreenControl::LogMsg('1:download_dir: ' . $current_download_dir);
                
            if ( $current_temp_dir eq  $rvTmpPath && 
                $current_cache_dir eq $rvTmpPath &&
                $current_download_dir eq $rvTmpPath) {
                
                my $msg = '';

                $msg = $objLANG->TranSlate('Upgrade pear with xxx', 'Archive_Tar') ;
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...');
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
               
                my @softUpgradeList = ('PEAR','Archive_Tar'); 
                
                foreach my $packageName(@softUpgradeList) {
                	## install pear            
                    $installPearResult = callBackticks("$pear_bin upgrade -l $packageName");
                }

                my @forceUpgradeList = ('File','File_Util','File_CSV'); 
                
                #กรณ๊มีแพคเกจ File ใน /usr/lib/php แต่ไม่มีใน /usr/local/lib/php ต้องฟอซอัพเกรด
                foreach my $packageName(@forceUpgradeList) {
                    $installPearResult = callBackticks("$pear_bin upgrade -f $packageName");
                }
                
                #install MDB2
                my ($runperlPath) = RVSInstaller::Process::getPerlPath();           
                my $installpearpackage =  $InstallConf{'ThisParh'} . '/fixpearpackage.pl';
                if (-f $installpearpackage) {
                	callBackticks("$runperlPath $installpearpackage");
                }
                
                $msg = $objLANG->TranSlate('Install pear with xxx', 'RVSeagullMod-1.0.1.tgz') ;
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...');
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
               
                ## install pear            
                $installPearResult = callBackticks("$pear_bin install -f $rvpearFile");
                
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg($msg . " , completed\n");
                
                $msg = $objLANG->TranSlate('Upgrade pear with xxx', 'RVSeagullMod-1.0.1.tgz');
                RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...');
                #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...' . '<br><br>' . $objLANG->TranSlate("This process will take 5-10 minutes by normal") . '<br> ' . $objLANG->TranSlate("If your server is running this process longer"));
                RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
             
             
                ## upgrade pear       
                $installPearResult = callBackticks("$pear_bin upgrade -f $rvpearFile");
                
                RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
                RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                RVSInstaller::ScreenControl::LogMsg($msg . " , completed\n");
                
                RVSInstaller::ScreenControl::LogMsg('2 output ?=' . $?);
                if ($? != 0 && $? != 1) {
                    # try to install after extract .tgz            
                    
                    RVSInstaller::ScreenControl::DisplayMsg("$failedColor");
                    RVSInstaller::ScreenControl::DisplayMsg("Pear Install/upgrade have problem, trying install with extract package.");
                    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                    RVSInstaller::ScreenControl::DisplayMsg('', 1);
                    RVSInstaller::ScreenControl::LogMsg("Pear Install/upgrade have problem, trying install with extract package.\n");
                    
                    RVSInstaller::ScreenControl::LogMsg("change dir=" . $rvTmpPath . "\n");
                    
                    chdir($rvTmpPath);      
                    my ($forceInstallPearError) = 0;
                    
                    $msg = "Extract file RVSeagullMod-1.0.1.tgz";
                    RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...');
                    RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                    RVSInstaller::ScreenControl::LogMsg($msg . "\n");
                    
                    system($cmd_tar . ' -xzf ' . $InstallConf{'cpModeConfigPath'}{'programPath'} . '/scripts/RVSeagullMod-1.0.1.tgz >/dev/null');
                    
                    RVSInstaller::ScreenControl::LogMsg('3 output ?=' . $?);
                    if ($? != 0 && $? != 1) {
                         $forceInstallPearError = 1;
                         system($cmd_echo . ' "Can not extract RVSeagullMod-1.0.1.tgz " >>' . $install_log);
                         RVSInstaller::ScreenControl::LogMsg("Can not extract RVSeagullMod-1.0.1.tgz\n");
                     }

                    if ($forceInstallPearError) {
                        my $msgErrorLog;
                        my $msgErrorBrowser;
                        open (FILE, '<', $install_log);
                        while (<FILE>) {
                                $msgErrorLog .= $_;
                                $msgErrorBrowser .= $_ . '<br/>';
                        }
                        close(FILE);
                        
                        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('Cannot install pear for ') . $install_type . ' ' . $msgErrorBrowser, 1, 'subMsg' . $ACTION, '', '#FF0000');
                        RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                        
                        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot install pear for ') . $install_type . ' ' . $msgErrorLog);
                        
                        #restore config path
                        system($pear_bin . ' config-set temp_dir ' . $temp_dir . ' >/dev/null');
                        system($pear_bin . ' config-set cache_dir ' . $cache_dir . ' >/dev/null');
                        system($pear_bin . ' config-set download_dir ' . $download_dir . ' >/dev/null');

                        removeRvPearBin($pear_bin);
                        RVSInstaller::ScreenControl::LogMsg('Exit 4');
                        exitScript();
                    } else {
                    	system($cmd_cp . ' -f ' . $rvTmpPath . '/package.xml ' . $rvTmpPath .'/RVSeagullMod-1.0.1');        
                        chdir('/');
                     
                        $msg = $objLANG->TranSlate('Install pear with xxx', 'package.xml');
                        #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . '. Please wait...');
                        RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...' . '<br><br>' . $objLANG->TranSlate("This process will take 5-10 minutes by normal") . '<br> ' . $objLANG->TranSlate("If your server is running this process longer"));
                        RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                        RVSInstaller::ScreenControl::LogMsg($msg . "\n");
                        
                        system($pear_bin . ' install -f ' . $rvTmpPath .'/RVSeagullMod-1.0.1/package.xml >' . $install_log);
                        
                        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
                        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                        RVSInstaller::ScreenControl::LogMsg($msg . " , completed\n");
                        
                        $msg = $objLANG->TranSlate('Upgrade pear with xxx', 'package.xml');;
                        #RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . '. Please wait...');
                        RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $msg . ' ' . $objLANG->TranSlate("Please wait") . ' ...' . '<br><br>' . $objLANG->TranSlate("This process will take 5-10 minutes by normal") . '<br> ' . $objLANG->TranSlate("If your server is running this process longer"));
                        RVSInstaller::ScreenControl::DisplayMsg($msg, '', 'subMsg' . $ACTION);
                        RVSInstaller::ScreenControl::LogMsg($msg . "\n");
                        
                        system($pear_bin . ' upgrade -f ' . $rvTmpPath .'/RVSeagullMod-1.0.1/package.xml >>' . $install_log);
                        
                        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");
                        RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed'), '', 'subMsg' . $ACTION);
                        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                        RVSInstaller::ScreenControl::LogMsg($msg . " , completed\n");
                    }  
                }
                    
                #restore config path
                system($pear_bin . ' config-set temp_dir ' . $temp_dir . ' >/dev/null');
                system($pear_bin . ' config-set cache_dir ' . $cache_dir . ' >/dev/null');
                system($pear_bin . ' config-set download_dir ' . $download_dir . ' >/dev/null');
                
                $current_temp_dir = callBackticks("$pear_bin config-get temp_dir");
                $current_cache_dir = callBackticks("$pear_bin config-get cache_dir");
                $current_download_dir = callBackticks("$pear_bin config-get download_dir");
                $current_temp_dir =~s/\r|\n//gi;
                $current_cache_dir =~s/\r|\n//gi;
                $current_download_dir =~s/\r|\n//gi;
                if ( $current_temp_dir ne  $temp_dir || 
                    $current_cache_dir ne $cache_dir ||
                    $current_download_dir ne $download_dir) {
                    
                    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('Cannot change pear config'), 1, 'subMsg' . $ACTION, '', '#FF0000');
                    RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                        
                    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot change pear config'));
                    
               }
               
               RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Install pear for ' . $install_type));
               if (-e $php_dir . '/RVSeagullMod/modules/user/classes/UserDAO.php') {
                    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Install pear for ' . $install_type) . ' has been completed.');
                    RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $completedColor");            
                    RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate('Completed') , '', 'subMsg' . $ACTION);
                    RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
               } else {
                   #restore config path
                    system($pear_bin . ' config-set temp_dir ' . $temp_dir . ' >/dev/null');
                    system($pear_bin . ' config-set cache_dir ' . $cache_dir . ' >/dev/null');
                    system($pear_bin . ' config-set download_dir ' . $download_dir . ' >/dev/null');
                    
                    #install with default config path
                    system("$pear_bin install -f $rvpearFile 2>&1");
                    system("$pear_bin upgrade -f $rvpearFile 2>&1");
                    if (-e $php_dir . '/RVSeagullMod/modules/user/classes/UserDAO.php') { 
                        RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Install pear for ' . $install_type) . ' not completed.');
                        RVSInstaller::ScreenControl::DisplayMsg("<TAB>[ $failedColor");            
                        RVSInstaller::ScreenControl::DisplayMsg('File ' . $php_dir . '/RVSeagullMod/modules/user/classes/UserDAO.php does not exist or zero byte.' , '', 'subMsg' . $ACTION);
                        RVSInstaller::ScreenControl::DisplayMsg("\e[0m ]", 1);
                    }
                    
                    removeRvPearBin($pear_bin);
                    RVSInstaller::ScreenControl::LogMsg('Exit 5');
                    exitScript();                    
                }
               
            } else {
                    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('Cannot change pear config back'), 1, 'subMsg' . $ACTION, '', '#FF0000');
                    RVSInstaller::ScreenControl::DisplayMsg("\e[0m", 1);
                        
                    RVSInstaller::ScreenControl::LogMsg($objLANG->TranSlate('Cannot change pear config back'));
                    
            }
        }
        
        if (-e $php_dir . '/RVSeagullMod') {
            system($cmd_chmod, '-R', '755', $php_dir . '/RVSeagullMod');
        }            
               
    }
        
    #delele tmp
    if (-e $install_log) {
        unlink($install_log);
    }
    if (-d $rvTmpPath) {
        system($cmd_rm . ' -rf ' . $rvTmpPath  . '>/dev/null 2>&1');
    }
    
    removeRvPearBin($pear_bin);
}

#return $phpIniData{'PHP'}{'memory_limit'}

sub readINIfile{
    my ($filename) = $_[0];
    my (%result);
    if (!-e $filename) {
        return %result;
    }
    my ($section) = '';
    my ($commentchar) = ';';
    open my $FD, '<', $filename;
    my (@pears) = <$FD>;
    close($FD);
    
    foreach my $filedata (@pears) {
        my ($dataline) = rvtrim($filedata);
        my ($firstchar) = substr($dataline, 0, 1);
        if ( $firstchar ne $commentchar && $dataline ne'') {
            if ($firstchar eq '[' && substr($dataline, -1, 1) eq ']') {
                $section = substr($dataline, 1, -1);
            } else {
                my ($key, $value) = split(/=/, $dataline, 2);
                $key = rvtrim($key);
                $value = rvtrim($value);
                if ( $value=~/"(.*)"/i) {
                    $value = $1; 
                }
                if ($section ne '') {
                    $result{"$section"}{"$key"} = $value;
                } else {
                    $result{"$key"} = $value;
                }
            } 
        }
    }
    return %result;
}

#setINIfile('php.ini','memory_limit','64M');

sub setINIfile{
  my ($iniFile,$setKey,$setVal) = @_;

    open my $FR, '<', $iniFile;
    my @aFile = <$FR>;
    close($FR);

    open my $FW, '>', $iniFile;
    foreach(@aFile){
        my ($key, $value) = split(/=/, $_, 2);
        $key = rvtrim($key);
        if ($key eq $setKey){
            print $FW "$setKey=$setVal\n";
        } else {
            print $FW $_;
        }
    }
    close($FW);
    return 1;
}

sub rvtrim{
    my ($msg) = $_[0];
    $msg =~s/\r|\n//gi;
    $msg =~s/^ //gi;
    $msg =~s/ $//gi;
    return $msg;
}

#INPUT:    rsync
#OUTPUT: /usr/local/bin/rsync

sub rvsystem {
    my @cmd = @_;
    my $res = system(@cmd);
    return $res;
}

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::DisplayBoxMsg(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::DisplayBoxMsg(1, '', $cmd . ' is not support.');
        RVSInstaller::ScreenControl::LogMsg($cmd . ' is not support.');
        
    } elsif (!-x $binpath) {
        RVSInstaller::ScreenControl::DisplayBoxMsg(1, '', $cmd . ' is not executeable.');
        RVSInstaller::ScreenControl::LogMsg($cmd . ' is not executeable.');
    }    
        
    return $binpath;
}

sub addSecureUser{
    my ($system);
    chomp($system = callBackticks("uname -s"));

    my ($username) = 'securervsite'; 
    my ($securervsiteUID) =(getpwnam($username))[2]; 
    my ($gid) = (getgrnam($username))[2];
    
    print "Checking user \"securervsite\" ... ";
    if ( !$securervsiteUID ) {
        print "not found.\n";
        print "Create user \"securervsite\" ... ";
        my ($userAddCmd); 
        if ($system =~ /freebsd/i) { 
        	#cannot get group id by securervsite go to add group
        	if (!$gid) {
        		$userAddCmd = 'pw groupadd securervsite; ';
        	}
            $userAddCmd .= "pw useradd $username -s /sbin/nologin"; 
        } else {
        	#cannot get group id by securervsite go to add group
        	if (!$gid) {
                $userAddCmd = 'groupadd securervsite; ';
            }
            #some server add option -g group name
            $userAddCmd .= "useradd $username -s /sbin/nologin -g securervsite"; 
            #$userAddCmd .= "useradd $username -s /sbin/nologin"; 
        } 
        
        my ( $pid ) = open2( *R, *W,"$userAddCmd"); 
     
        close(W); 
        my ( $found ); 
        while(<R>) { 
            if (/user $username exists/) { 
                $found = 1; 
            } 
        } 
        close(R); 
        waitpid($pid, 0); 
        print "succeed.\n";
    } else {
        print "found.\n";
    }

    return $username; 
}

sub getRVSiteBuilderConf {
    my $rvsIPConfPath = $_[0];
    my %conf = {};
    
    open(R, '<', $rvsIPConfPath);
    while (<R>) {
        ~s/\r|\n//gi;    
        if ($_=~/^$/ ||$_=~/^\/\// || $_=~/^#/|| $_=~/^\/\*/) {
            next;
        }
        my @tmp = split ('=',$_);
        my $value = $tmp[1];
        $value =~s/^\s*'?//;
        $value =~s/'?\s*;$//;
         
        my @confKey = ($_ =~ /\['(\w+)'\]/g);
        if (@confKey > 2) {
            $conf{$confKey[0]}{$confKey[1]}{$confKey[2]} = $value;
        } else {
            $conf{$confKey[0]}{$confKey[1]} = $value;
        }
    }
    return %conf;
}

sub getrealipbyhostname
{
    my ($host) = shift;
    if ($host =~ /^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/) {
           return $host;
    } else {
        my ($packed_ip, $ip_address);
        $packed_ip = gethostbyname($host);
        if (defined $packed_ip) {
            $ip_address = inet_ntoa($packed_ip);
            return $ip_address;
        } else {
          return $host;
        }
    }
}

sub getmainip{
   my($system, $ethdev,$ips, @IPS);
   $ethdev = '';
   chomp($system = callBackticks("uname -s"));
   if ( -f "/etc/wwwacct.conf") {
        open(CONF,"/etc/wwwacct.conf");
        while(<CONF>) {
            s/\n//g;
            if ($_ !~ /^;/) {
                if ($_ =~ /ETHDEV/) {
                    (undef,$ethdev) = split(/ /, $_);
                }
            }    
        }
    close(CONF);
   }
   if ($system =~ /freebsd/i || $ethdev eq "") {
      $ips = callBackticks("/sbin/ifconfig -a 2>/dev/null");
   } 
   else {
      $ips = callBackticks("/sbin/ifconfig $ethdev 2>/dev/null");
   }
   @IPS = split(/\n/, $ips);
   foreach my $ip (@IPS) {
      if ($ip =~ /(\d*)\.(\d*)\.(\d*).(\d*)/) {
         if ($1 ne "127") {
            return "$1.$2.$3.$4";
         }
      }
   }
   # No Reached
   return "0.0.0.0";
}

sub _getIpListOnSource {
   my $ips = callBackticks("/sbin/ifconfig");
   my @IPS = split(/\n/, $ips);
   my (@returnIps);
   foreach my $ip (@IPS) {
       if ($ip =~ /(\d*)\.(\d*)\.(\d*).(\d*)/) {
           if ($1 ne "127") {
               push(@returnIps,"$1.$2.$3.$4");
           }
       }
   }
   return @returnIps; 
}

sub isLocalhost{
    my ($hostorip) = shift;
    if ($hostorip =~/^localhost/) {
        return 1;     
    }
    
    my ($rip) = getrealipbyhostname($hostorip);
    if ($rip eq '127.0.0.1') {
        return 1;
    }
    my ($mainip) = getmainip();
    if ($mainip eq $rip) {
        return 1;   
    }
    my (@allIp) = _getIpListOnSource();
    foreach my $listIp (@allIp) {
        if ($listIp eq $rip) {
            return 1;    
        }
    }
    return 0;
}

#backup fail exit 'Backup fail'
#remote db? how? mysql root
#$rvsConf{'db'}{'host'},$rvsConf{'db'}{'port'},$rvsConf{'db'}{'user'},$rvsConf{'db'}{'pass'},$rvsConf{'db'}{'name'},$rvsConf{'db'}{'name'}, $rvglobalPath . '/.rvsitebuilder'
sub backupRVSiteBuilderDB {
    my ($db_host,$db_port,$db_user,$db_pass,$db_name,$targetpath) = @_;
    
    my $backupName = $db_name . '_v4';
    
    if (-e $targetpath . '/' . $backupName . '.tar.bz2' || -e $targetpath . '/' . $backupName . '.sql') {
        #print "\n$db_name is already backup\n";
        #return 1;
    }
    
    $db_pass = _cleanDbPassword($db_pass);
    
    my ($dbuser, $dbpass, $dbserver, $dbport, $dbdb);
    
    my $hostname = callBackticks("hostname");
    chomp($hostname);
    
    open(DBS,"/root/.my.cnf");   # in some server there is not /root/.my.cnf
    while ( <DBS>) {
        if (/^pass=(\S+)/) {
            $dbpass = $1;
            $dbpass =~ s/^\"|\"$//g;
        }
        if (/^host=(\S+)/) {
            $dbserver = $1;
            $dbserver =~ s/^\"|\"$//g;
        }
        if (/^port=(\S+)/) {
            $dbport = $1;
            $dbport =~ s/^\"|\"$//g;
        }
        if (/^user=(\S+)/) {
            $dbuser = $1;
            $dbuser =~ s/^\"|\"$//g;
        }
    }
    close(DBS);
    if (!$dbserver) {
        $dbserver = "localhost"; 
    }
    
    if (!$dbport) {
        $dbport = 3306;
    }
    if (!$dbuser) {
        $dbuser = 'root';   
    }
    
    #Begin confirm backup native

    eval {
        local $SIG{ALRM} = sub { die 'Timed Out'; };
        alarm 60;
        my($inputkey, $upconfirm);
        $upconfirm = 0;
        do {
        	RVSInstaller::ScreenControl::DisplayMsg("Do you want to backup native database (yes/no)? no to exit. : ", 0);
            chomp($inputkey = <STDIN>);
            $inputkey =~ s/\n//g;
            $inputkey = lc($inputkey);
            if ($inputkey eq 'yes' || $inputkey eq 'y') {
                $upconfirm = 1;
            }
            if ($inputkey eq 'no' || $inputkey eq 'n' ) {
                exitScript();
            }
        } while($upconfirm == 0);
        #<-- Cancel the alarm -->
        alarm 0; 
    };
            
    #<-- race condition protection -->
    alarm 0; 
    $SIG{'ALRM'} = 'IGNORE';
    if ( $@ ) {
        if ( $@ =~/Timed Out/ ) {
            RVSInstaller::ScreenControl::DisplayMsg($objLANG->TranSlate("Confirm backup time out please run installer again"), 1);
        } else {
            print "\nError: Eval corrupted: $@\n";
        }
        exitScript();
    }
    #End confirm backup native
    
    if ( (isLocalhost($db_host) &&  isLocalhost($dbserver)) || (getrealipbyhostname($db_host) eq getrealipbyhostname($dbserver)) || ($db_host =~/^$hostname/ && $dbserver=~/^$hostname/) ) {
        print "Backup local database $db_name\n";
        if (!-e $targetpath) {
            system("mkdir -p $targetpath");
            if (!-e $targetpath) {
                print "Can not create dir $targetpath\n";
                return 0;
            }
        }
        
        my $targetBackupBzipFile = $targetpath . '/' . $backupName . '.tar.bz2'; 
        
        my $cmd;
        
        if (-e $targetBackupBzipFile) {
            print $backupName . "tar.bz2 already backup.\n";
            return 1;
        } 
        
        if (-e '/var/lib/mysql/' . $db_name) {
            $cmd = sprintf('cp -rf /var/lib/mysql/%s %s/%s',
                $db_name,
                $targetpath,
                $backupName
            );
            system($cmd);
            
            if (!-e $targetpath . '/' . $backupName) {
                print "Can not copy dir to  $targetpath \n";
                return 0;
            }
    
            chdir($targetpath);
    
            $cmd = sprintf('tar cjf %s.tar.bz2 %s',
                $backupName,
                $backupName
            );
            system($cmd);
            
            if (-s $targetBackupBzipFile == 0) {
                print "Can not create bzip file $targetBackupBzipFile \n";
                system("rm -f $targetBackupBzipFile");
                return 0;
            }                
    
            $cmd = sprintf('rm -rf %s/%s',
                $targetpath,
                $backupName
            );
            system($cmd);
        }
    } else {
        #Case remote db
        print "Backup remote database $db_name\n";
        #already convert?
        my ($dbh,$q,$data);
        $dbh = DBI->connect("DBI:mysql:$db_name:$db_host:$db_port", "$db_user", "$db_pass");
        unless ( $dbh ) {
            return 0;
        }            
        $q = $dbh->prepare("SHOW TABLES;");
        $q->execute;
        my $isAlreadyConvert = 0;            
        while($data=$q->fetchrow_arrayref) {
            if ($data->[0] eq 'rvs_convert_utf8') {
               $isAlreadyConvert = 1;
            }
        }
        $q->finish();
        $dbh->disconnect();
        if ($isAlreadyConvert) {
            return 1;
        }
        my $rvsdumpfile = $targetpath . '/' . $backupName . '.sql';
        if (-e $rvsdumpfile) {
            print "$db_name is already backup\n";
        }
        my ( $pid ) = open2( *R, *W,"mysqldump --user=$db_user --password=$db_pass  --host=$db_host --databases $db_name --result-file=$rvsdumpfile"); 
        close(W); 
        while(<R>) { 
        } 
        close(R); 
        waitpid($pid, 0);
        #can Dump?
        if (!-e $rvsdumpfile) {
            print "Can not dump $db_name on remote database\n";
            return 0;
        }
        if (-s $rvsdumpfile == 0) {
            print "Can not dump $db_name on remote database please check disk quota\n";
            return 0;
        }
    }        
    return 1;
}

sub _isRequireConvUtf8{
	my $isRequireConvert = 0;
    if (-e $RVS_IP_CONF) {
        my %rvsConf = getRVSiteBuilderConf($RVS_IP_CONF);
        if ($rvsConf{'db'}{'postConnect'} !~/SET NAMES utf8$/gi && $rvsConf{'db'}{'name'} ne '') {
            $isRequireConvert = 1;
        }
    } elsif (-e $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php') {
    	$isRequireConvert = 1;
    	open(R, '<', $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/rvautosetting.conf.ini.php');
        while (<R>) {
        	if ($_ =~/postConnect=SET NAMES utf8/gi) {
        		$isRequireConvert = 0;
        		last;
        	}
        }
        close(R);
    }
    return $isRequireConvert;
}

sub _cleanDbPassword{
    
    my $dbPass = $_[0];
    
    #print "DatabasePassword = $dbPass <br>";
    
    # Repleac Character Speacial  \()|"<>;&
    $dbPass =~ s/\\/\\\\/gi;   #  \
    $dbPass =~ s/\(/\\(/gi;    #  (
    $dbPass =~ s/\)/\\)/gi;    #  )
    $dbPass =~ s/\|/\\|/gi;    #  |
    $dbPass =~ s/"/\\"/gi;     #  "
    $dbPass =~ s/</\\</gi;     #  <
    $dbPass =~ s/>/\\>/gi;     #  >
    $dbPass =~ s/;/\\;/gi;     #  ;
    $dbPass =~ s/&/\\&/gi;     #  &
    ###########################
        
    #print "DatabasePassword(Repleac) = $dbPass";

    return $dbPass;
}

sub symlinkOnce {
    my ($target, $link) = @_;
    
    if (!-e $target) {
        return 0;
    }
    if (!readlink($link)) {
        symlink($target, $link);
        print "Create link $link -> $target \n";
    }
    return 1;
}

sub runRotateRvsitebuilderLogPath {
	my ( $programPath,$logname) = @_;
	
	my @aFile = split('\.', $logname);
	my @pa = split('/', $logname);
	my $pathVar = $pa[0] . '/'. $pa[1].'/';
    my $file = $aFile['0'];
	my $fileLog2 = $file . ".2.tar.gz";
	my $fileLog1 = $file . ".1.tar.gz";

	#print "\n" . "*****:".  $programPath . '/' . $fileLog1 . "\n" . $programPath . '/' . $fileLog2."\n";
	RVSInstaller::ScreenControl::LogMsg("\n" . $programPath . '/' . $fileLog1 . "\n" . $programPath . '/' . $fileLog2 ."\n");
    unlink($programPath . '/' . $fileLog2)
        if (-f $programPath . '/' . $fileLog2);
    
    copy($programPath . '/' . $fileLog1, $programPath . '/' . $fileLog2)
        if (-f $programPath . '/' . $fileLog1);

    RVSInstaller::ScreenControl::LogMsg("\n" . $programPath . '/' . $logname . "\n");

    if (-f $programPath . '/' . $logname) {
    	my $cmd = $cmd_tar . ' cvzf ' . $programPath . '/' . $fileLog1 . ' ' .$programPath . '/' . $logname . ' >/dev/null 2>&1';
        RVSInstaller::ScreenControl::LogMsg($cmd);
        system($cmd);
        chdir('/');
    }
    
    #clean file log to empty
    unlink($programPath . '/' . $logname)
        if (-f $programPath . '/' . $logname);
    
    
    open my $FD, '>', $programPath . '/' . $logname;
    print $FD '';
    close($FD);

    system($cmd_chmod, '666', $programPath . '/' . $logname)
        if (-f $programPath . '/' . $logname);
}

sub callBackticks{
    my $cmd = join(' ', @_);

    RVSInstaller::ScreenControl::LogMsg('cmd=' .$cmd);
    
    if (-f '.rvsBackticks') {
        system('rm -f .rvsBackticks');
    }
    
    my ($TestBackticks) = `echo 'RV Test Backticks'`;
    my ($skipBackticks) = 0;
    if ($TestBackticks !~/RV Test Backticks/) {
        $skipBackticks = 1;
    }
    if (-f '.skipBackticks' || $skipBackticks eq 1) {
        system("$cmd > .rvsBackticks 2>&1");
    }
    my ($resuft);
    if (-f '.rvsBackticks') {
        my ($fd);
        open($fd, '<', '.rvsBackticks');
        $resuft = join('',<$fd>);
        close($fd);
        system('rm -f .rvsBackticks');
    } else {
        $resuft = `$cmd 2>&1`;
    }
 
    return $resuft;
}

sub _deleteRvshelpV5{
	RVSInstaller::ScreenControl::LogMsg('Validate Upgrade >= V5 delete www/rvs_help' . "\n");
	my $pathVersion = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilderversion.txt';
	my $pathRvsHelp = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/www/rvs_help';
    if (-f $pathVersion) {
        open(my $fh, "<", $pathVersion);
        my @versiondata =  <$fh>;
        my ($version,$b) = split(/\./, $versiondata[0] ,2);
        if (-d $pathRvsHelp && $version >= 5) {
            system('rm -rf ' . $pathRvsHelp);
        }
     }
}

sub _confirmUpgradetoV5{
	RVSInstaller::ScreenControl::LogMsg('Validate Confirm Upgrade V4 to V5 (yes/no)?' . "\n");
	my $pathVersion = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/rvsitebuilderversion.txt';
    #get latest version
    my %licenseInfo = %{RVSInstaller::Connection::UrlConnection($InstallConf{'SiteConf'}{'download'}{'address'}{'site1'}, 80, '', 0, '/latestversion.php?program=rvsitebuilder&getlatestversion=1', 60)};              
    #print Dumper(%licenseInfo);

    my ($latestversion, $b) = split(/\./,  $licenseInfo{'Page'} ,2);
    if (-f $pathVersion) {
        open(my $fh, "<", $pathVersion);
        my @z =  <$fh>;
        my ($oldversion, $b) = split(/\./,  $z[0] ,2);
        $oldversion = trim($oldversion);
        $latestversion = trim($latestversion);
        #print "\n current:" . $oldversion;
        #print "\n latest:" . $latestversion;
        if ($oldversion == 4 && $latestversion >= 5) {
        
        RVSInstaller::ScreenControl::DisplayMsg("\n", 1);
        RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
        RVSInstaller::ScreenControl::DisplayMsg("#\t\t" . "Upgrade RVSiteBuilder To V5", 1);
        RVSInstaller::ScreenControl::DisplayMsg('########################################################################', 1);
    
    #Begin confirm upgrade
    eval {
        local $SIG{ALRM} = sub { print "\nTimed Out "; exitScript();  exit; };
        alarm 60;
        my($inputkey, $upconfirm);
        $upconfirm = 0;
        
        do {
            RVSInstaller::ScreenControl::DisplayMsg("After upgrade to RVSiteBuilder V.5, you will not be able to rollback to V.4\n", 0);
            RVSInstaller::ScreenControl::DisplayMsg("Are you sure you want to continue upgrade RVSiteBuilder V.5? [yes|no]", 0);
            chomp($inputkey = <STDIN>);
            $inputkey =~ s/\n//g;
            $inputkey = lc($inputkey);
            if ($inputkey eq 'yes' || $inputkey eq 'y') {
                $upconfirm = 1;
            }
            if ($inputkey eq 'no' || $inputkey eq 'n' ) {
                exitScript();
            }
            
        } while($upconfirm == 0);
        #<-- Cancel the alarm -->
        alarm 0;
    };
   }
 }
}

sub replaceKeyLang{
	my $sourceDir = "";
	my $destFile = "";
	my $adminPath = "";
	if ($InstallConf{'cpMode'} eq 'da') {
		$adminPath = "/home/admin";
	} else {
		$adminPath = $InstallConf{'cpModeConfigPath'}{'companyPath'};
	}
	my $ownerLangPath = $adminPath . '/.rvsitebuilder/lang/sitebuilder';
	my $ownerLangBackup = $adminPath . '/.rvsitebuilder/lang/sitebuilder/backuplang';
	my $oldwordsFile = $InstallConf{'cpModeConfigPath'}{'programPath'} . '/modules/sitebuilder/lang/english-utf-8.oldwords.php';
	
	$sourceDir = $ownerLangPath;
	$destFile = $oldwordsFile;
	
	if (!-d $sourceDir && !-f $destFile) {
	    exitScript(); 
	}
	
	#make backup folder
	if (!-d $ownerLangBackup) {
		system('mkdir -p ' . $ownerLangBackup);
	}
	
	my $replaceComplete = 0;
	my @aSourceFiles = listFiles($sourceDir, "-utf-8.php\$");
	my %aLine;
	my @aAllKeys = ();
	#my @aAllValue = ();
 	for (my $i=0;$i<scalar(@aSourceFiles);$i++) {
                my $filename = $sourceDir . "/" . $aSourceFiles[$i];

                if (-f $filename) {
                #defind value
                my $langFile = $sourceDir . "/" . $aSourceFiles[$i];
                my $langFileNew = $sourceDir . "/backuplang/" . $aSourceFiles[$i];
                my $msgOut = "";
                
                #backup file lang
                if (!-f $langFileNew) { 
                    my $cmd = 'cp -R ' . $langFile . ' ' . $langFileNew;
                    system($cmd);
                }
                
                open (R,'<', $destFile) or die "can't open data";
                        my @data= <R>;
                        close (R);
                          foreach my $keyLong(@data) {
                               $keyLong =~s/\$oldwords\[(.*)\]/$1/g;
                               $keyLong =~s/\;$|\?>$|^<\?php//;

                               #print $keyLong ."\n";
                               my @aData = split('=', $keyLong);
                               if ($aData[0] && $aData[1]) {
                                   my $key1 = trim($aData[0]);
                                   my $key2 = trim($aData[1]);

                                   #replace key " to \"
                                   $key1 =~s/"/\\"/g;
                                   $key2 =~s/"/\\"/g;
                                   my $codReplace = "";
                                   my $cmdReplace = "";
                                   my $sed = "sed -i '' -e ";
                                   ############ free BSD ##########
                                   my $os = $^O;
                                   if ($os eq 'freebsd') {
                                    if ($key1 =~/\"/gi) {
                                            #case "
                                            $key1 =~s/\\/\\/g;
                                            $key2 =~s/\\/\\/g;
                                            $key1 =~s/\//\//g;
                                            $key2 =~s/\//\//g;
                                            $key1 =~s/^\'//g;
                                            $key2 =~s/\'$//g;
                                            $codReplace = $sed . "'s/" . $key1 . "/" . $key2 . "/g' -- " . $langFile;
                                        } else {
                                            #case '
                                            $key1 =~s/\\/\\/g;
                                            $key2 =~s/\\/\\/g;
                                            $key1 =~s/\//\//g;
                                            $key2 =~s/\//\//g;
                                            $key1 = 'words\[' . $key1 .'\]';
                                            $key2 = 'words[' . $key2 .']';
                                            $codReplace = $sed . '"s/'. $key1 . '/' . $key2 . '/g" -- ' . $langFile;                                        
                                        }
                                    system($codReplace);
                                    ################################
                                    } else {
                                    ############ cpanel ##########
                                        $key1 = '"[' . $key1 . ']"';
                                        $key2 = '"[' . $key2 . ']"';
                                        $cmdReplace = "replace " . $key1 . " " . $key2 . " -- " . $langFile;
                                        system($cmdReplace);
                                    }

                                    #if out put have error print command
                                    if ($? != 0 && $? != 1) {
                                        print $cmdReplace . "\n";
                                    } else {
                                        $replaceComplete = 1;
                                    }
                               }
                          }
                }

                       if ($replaceComplete == 1) {
                        print $filename;
                        print "\n replace to new keylang complete. \n";
                       }

        } #End foreach

        if ($replaceComplete == 1) {
        my $cmd = "touch " . $sourceDir .'/replaceFileLang.complete';
           system($cmd);
        }

} #End function replaceKeyLang


sub listFiles {
    my ($dirname) = (defined($_[0])) ? $_[0] : "";  
    my ($patterns) = (defined($_[1])) ? $_[1] : "*";

    my @aListFile = ();
    if (-d $dirname) {
        opendir(DIR, $dirname);
        @aListFile = grep(/$patterns/, readdir(DIR));
        closedir(DIR);
    }
    return @aListFile;
}

sub trim {
    my ($value) = shift;
    #$value =~s/^[\s| |\r\n]*|[\s| ]*$//simx;  
    $value =~ s/^\s+//;
    $value =~ s/\s+$//;
    return $value;  
}

sub autoFix {
	#========== Auto Fix =============
	
	#Case rvsitebuilder/template/template
	my $pathFixRemove = $InstallConf{'cpModeConfigPath'}{'TemplatePath'} . '/template/template';
	if(-d $pathFixRemove && !-l $pathFixRemove){
		system('rm -rf ' . $pathFixRemove);
		unlink $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5' if(-f $InstallConf{'cpModeConfigPath'}{'programPath'} . '/var/fullpackage.md5');
	}
}

sub rvsLicenseEncode {
	my @aAllIP = RVSInstaller::Process::getAllIP();
	my $licCode = (exists $_[0]) ? $_[0] : '';
	my $aRVCode = {
            'ips' => RVSInstaller::Serialize::serialize(\@aAllIP),
            'virtualization' => 0,
            'encrypt-type' => 'ioncube',
            'license-code' => $licCode,
    };
	
	return RVSInstaller::Process::SerializerData($aRVCode);
}

sub _licenseErrorDetail {
    my %hParam = %{$_[0]};
    
    my $issueId = $hParam{'issue_id'};
    my $issueTitle = $hParam{'issue_title'};
    my $licenseType = $hParam{'license_type'};
    my $issueDetail = 'No details of the error.';
    
    if ($licenseType == 0 || $issueId == '001' || $issueId == '002' || $issueId == '401' || $issueId == '402') { #0 = Leased License
        	if($issueId == '001') {
        		$issueDetail = 'Please contact RVStaff immediately at https://rvglobalsoft.com/tickets/new&deptId=2.';
        	} elsif ($issueId == '002') {
        		$issueDetail = 'Please check IP setting in your server and fix it before trying to connect rvglobalsoft again';
        	} elsif ($issueId == '101') {
                $issueDetail = 'Please check your payment in https://rvglobalsoft.com/clientarea/invoices/ or check license status at https://rvglobalsoft.com/verifyrvlicense.';
            } elsif ($issueId == '301') {
                $issueDetail = 'Please login to your account to renew the pending invoice at https://rvglobalsoft.com/clientarea -> "Account" -> "Invoices" and pay the pending invoice.';
            } elsif ($issueId == '302') {
                $issueDetail = 'Please contact RVGlobalsoft staff at https://rvglobalsoft.com/tickets/new&deptId=2.';
            } elsif ($issueId == '401') {
                $issueDetail = 'Please validate license with RVGlobalsoft https://rvglobalsoft.com/verifyrvlicense, or check the ethernet device setting at https://rvglobalsoft.com/knowledgebase/article/209/validating-license-for-my-ip-failed-in-the-installation-process/ ,or contact rvstaff at https://rvglobalsoft.com/tickets/new&deptId=2.';
            } elsif ($issueId == '402') {
                $issueDetail = 'Please contact RVGlobalsoft staff at https://rvglobalsoft.com/tickets/new&deptId=2.';
            } elsif ($issueId == '501') {
                $issueDetail = 'To avoid license suspended, please login to your account to renew at https://rvglobalsoft.com/clientarea -> "Account" -> "Invoices" and pay the pending invoice.';
            }
    } elsif ($licenseType == 1) { #1 = NOC/Distributor License
	        if($issueId == '001') {
	            $issueDetail = 'Please contact RVStaff immediately at https://rvglobalsoft.com/tickets/new&deptId=2.';
	        } elsif ($issueId == '002') {
	            $issueDetail = 'Please check IP setting in your server and fix it before trying to connect rvglobalsoft again';
	        } elsif ($issueId == '101') {
	        	$issueDetail = 'Please make sure you’ve added the license IP already in https://rvglobalsoft.com/clientarea/services/noc-licenses/.';
	        } elsif ($issueId == '301') {
	            $issueDetail = 'Please login to your account to renew the pending invoice at https://rvglobalsoft.com/clientarea -> "Account" -> "Invoices" and pay the pending invoice.';
	        } elsif ($issueId == '302') {
                $issueDetail = 'Please contact RVGlobalsoft staff at https://rvglobalsoft.com/tickets/new&deptId=2.';
            } elsif ($issueId == '501') {
                $issueDetail = 'To avoid license suspended, please login to your account to renew at https://rvglobalsoft.com/clientarea -> "Account" -> "Invoices" and pay the pending invoice.';
            }
    } elsif ($licenseType == 3) { #3 = Trial License
	        if ($issueId == '301') {
	            $issueDetail = 'Once your Trial license expired and suspended. You can make a new order for it https://rvglobalsoft.com/clientarea -> "Order" -> "Licenses" -> Select RVSitebuilder package you want.';
	        } elsif ($issueId == '501') {
                $issueDetail = 'Once your Trial license expired. You can make a new order for it https://rvglobalsoft.com/clientarea -> "Order" -> "Licenses" -> Select RVSitebuilder package you want.';
            }
    } else {
    	$issueDetail = 'License type ' . $licenseType .' : unknown license type';
    }
    
    if ( $BROWSER ) {
        $issueDetail =~ s#((;?http[s]?\:\/\/)?(;?[\da-z\.-]+)\.(;?[a-z\.]{2,6})(;?[\/\w\.\-\&\=]*)*\/?)#<a href="$1" target="_blank">$1</a>#gi;
        $issueDetail =~ s#([\"][a-zA-Z]+[\"])#<b>$1</b>#gi;
    }
    
    return $issueDetail;
}

1;
__END__

Copyright 2K16 - 2K18 Indonesian Hacker Rulez