CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/root/usr/local/rvglobalsoft/rvmanager/auto/
Upload File :
Current File : //proc/2/root/usr/local/rvglobalsoft/rvmanager/auto/RVSInstaller.pm

#!/usr/bin/perl
##LICENSE##
package RVSInstaller;
use strict;
#use warnings;
use Carp;
use Socket;
use POSIX;
use File::Basename;
use Data::Dumper;
use MIME::Base64;
use IPC::Open2;
use IPC::Open3;
use File::Copy;
use DBI;

use RVSInstaller::Process;
use RVSInstaller::RVSDownload;
use RVSInstaller::ScreenControl;
use RVSInstaller::Serializer;
use RVSInstaller::Template;
use base qw(
        RVSInstaller::Config
        RVSInstaller::Connection
    );
use vars qw($DEBUG);

sub new {
    my $class = shift;
    
    my $self = $class->SUPER::new( @_ );
    
    bless $self, $class;
    
    $self->{ScreenControl}  = RVSInstaller::ScreenControl->new(programName => $self->{'programName'});
    $self->{Language}       = RVSInstaller::Language->new(
        'Path' => dirname(__FILE__) . '/lang',
        'Language' => 'en',
        'GlobalFile' => 'global',
        'GlobalFileType' => 'ini.php',
        'LangFile' => 'autoinstaller',
        'LangFileType' => 'ini',
    );
    
    $self->{RVSDownload}    = RVSInstaller::RVSDownload->new(programName => $self->{'programName'});
    $self->{Template}       = RVSInstaller::Template->new();
    $self->loadvars();
    
    return $self;
}

sub loadvars {
    my $self = shift;
    $self->{'cmd'}->{'cp'} = $self->whichCmd('cp');
    $self->{'cmd'}->{'mv'} = $self->whichCmd('mv');
    $self->{'cmd'}->{'rm'} = $self->whichCmd('rm');
    $self->{'cmd'}->{'mkdir'} = $self->whichCmd('mkdir');
    
    $self->{'cmd'}->{'ln'} = $self->whichCmd('ln');
    $self->{'cmd'}->{'rsync'} = $self->whichCmd('rsync');
    $self->{'cmd'}->{'tar'} = $self->whichCmd('tar');
    
    $self->{'cmd'}->{'replace'} = $self->whichCmd('replace');
    $self->{'cmd'}->{'uname'} = $self->whichCmd('uname');
    $self->{'cmd'}->{'df'} = $self->whichCmd('df');
    $self->{'cmd'}->{'chmod'} = $self->whichCmd('chmod');
    
    $self->{'cmd'}->{'echo'} = $self->whichCmd('echo');
    $self->{'cmd'}->{'lsattr'} = $self->whichCmd('lsattr');
    $self->{'cmd'}->{'cat'} = $self->whichCmd('cat');
    $self->{'cmd'}->{'date'} = $self->whichCmd('date');
    $self->{'cmd'}->{'locale'} = $self->whichCmd('locale');
    $self->{'cmd'}->{'localedef'} = $self->whichCmd('localedef');
    $self->{'cmd'}->{'perl'} = $self->whichCmd('perl');
    
    my ($osType) = RVSInstaller::Process::callBackticks("$self->{'cmd'}->{'uname'} -s");
    if ($osType =~/freebsd/gi) {
        $self->{'cmd'}->{'chflags'} = $self->whichCmd('chflags');
        $self->{'cmd'}->{'cp_all'}  = $self->{'cmd'}->{'cp'} . ' -rf';
    } else {
        $self->{'cmd'}->{'chattr'} = $self->whichCmd('chattr');
        $self->{'cmd'}->{'cp_all'} = $self->{'cmd'}->{'cp'} . ' -a';
    }
}

sub registerAppConfig {
	my $self = shift;
	my $appConfigPath = $self->getInstallConfig('thisPath') . '/auto/appconfig';
	my $appConfigFile = $appConfigPath . '/' . $self->{'programName'} . '.conf';
	my $appConfigRegisFile = $appConfigPath . '/registerapp';
	if(-e $appConfigFile && -e $appConfigFile){
		my $chmod = $self->whichCmd('chmod');
		system($chmod . ' 755 ' .$appConfigRegisFile);
		my ($perlPath) = RVSInstaller::Process::getPerlPath();
		system('cd','/');
        my $pid = open(HANDLE, "|$perlPath ". $appConfigRegisFile . '|');
        close(HANDLE);
        waitpid($pid, 0);
        return 1;
	}
	return 0;
}

sub startInstaller {
    my $self = shift;
    
    #$self->initTemplate();
    $self->initData();
    $self->Validate();
}

sub initData {
    my $self = shift;
    
    $SIG{'PIPE'} = 'IGNORE';
    $SIG{'HUP'}  = 'IGNORE';
    $SIG{'ALRM'} = 'IGNORE';
    
    $| = 1;
    
    if ( $self->{'BROWSER'} == 0 && $> != 0 ) {
        print STDERR $0 . " must be ran as root".$self->{'NEWLINE'}.$self->{'NEWLINE'};
        exit(-1);
    }
    
    $self->{completedColor} = "\e[1m\e[36m";
    $self->{failedColor} = "\e[1m\e[31m";
    
    if ( $self->{'BROWSER'} ) {
        #print "HTTP/1.1 200 OK\n";
        print "Content-type: text/html\n\n";
        print "Connection: keep-alive\n\n";
        print "<html><head><title>".$self->{INSTALLTITLE}."</title>\n";
        print "</head>\n";
        print '<script src="' . $self->{'WEBROOT'} . '/include/install.js.' . $self->{'INS_PHP_FILE_TYPE'} . '?installtitle='.$self->{INSTALLTITLE}.'" language="javascript" type="text/javascript"></script>';
        print "<body>\n";
        $self->{'BROWSER'} = 1;
    }
    else {
        $self->{'BROWSER'} = 0;
    }
    
    if ( !-f $self->getInstallConfig('thisPath') . "/.skipcheckroot") {
        my ($user) = RVSInstaller::Process::callBackticks("whoami");
        if ( $user ne "root\n" ) {
            $self->exitScript($self->getInstallConfig('thisPath') . "/.skipcheckroot" . $self->{Language}->TranSlate("You must run this script as root else you may not have privileges to properly restore all files"));
        }
    }
    
    $| = 1;
}

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

    if ($FORM{'debug'} eq 'ENV') {
        foreach my $key (keys %ENV) {
            print "\$ENV{'" . $key . "'} = " . $ENV{$key} . "<br />\n";
        }
        $self->exitScript();
    }
    elsif ($FORM{'debug'} eq '1') {
        $DEBUG = 1;
    }
    
    if ( !$FORM{'action'} || $FORM{'action'} eq '' ) {
        $self->{ACTION} = 'begin';
    }
    else {
        $self->{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;
        }
    }
    if (-f $self->getInstallConfig('companyPath') . '/.'.$self->{'programName'}.'/.getlatestversion') {
        my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'getversion'} = 'latest';
            $INPUT =  \%hParam;
        }
        else {
            $hParam{'getversion'} = 'latest';
            $INPUT =  \%hParam;
        }
    }
    
    if ( $FORM{'getversion'}) {
        my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'getversion'} = $FORM{'getversion'};
            $INPUT =  \%hParam;
        }
        else {
            $hParam{'getversion'} = $FORM{'getversion'};
            $INPUT =  \%hParam;
        }
    }
      
    if ( $FORM{'force'}) {
         my (%hParam);
        if ($INPUT) {
            %hParam = %{$INPUT};
            $hParam{'force'} = 1;
            $INPUT =  \%hParam;
        }
        else {
            $hParam{'force'} = 1;
            $INPUT =  \%hParam;
        }
    }
    
    print "Create directory for $self->{INSTALLTITLE}\n" if ( $DEBUG );
    RVSInstaller::Process::mkdirp($self->getInstallConfig('thisPath'), "0755");
    
    my ($callFunc) = $callAction . $self->{ACTION};
    
    print "Call Function : " . $callFunc ."\n" if ( $DEBUG );
    eval($self->$callFunc($INPUT));
    if ($@) {
        print $@;
    }
}

sub callNextFunc{
    my $self = shift;
    my ($param) = $_[0];
    
    print "Param Call Next Function :  " . $param ."\n" if ( $DEBUG );

    my ($nextFunc) = $self->getFunctionConfig("$self->{ACTION}.next");
    my ($nextGroup) = $self->getFunctionConfig("$nextFunc.group");
    if ( $self->{'BROWSER'} ) {
        if ( "$nextFunc" ne "$self->{ACTION}" && "$self->{ACTION}" ne 'begin') {
            $self->{ScreenControl}->jsChangeImg($self->{ACTION}, '2');
            $self->{ScreenControl}->jsChangeArrow($self->{ACTION}, '1');
            $self->{ScreenControl}->jsSetFontColor('msg' . $self->{ACTION}, '#7CABC1');
            $self->{ScreenControl}->jsSetFontColor('subMsg' . $self->{ACTION}, '#7CABC1');
            $self->{ScreenControl}->jsSetFontWeight('msg' . $self->{ACTION}, 'normal');
            $self->{ScreenControl}->jsSetFontWeight('subMsg' . $self->{ACTION}, 'normal');
        }
        
        if ( "$nextGroup" ne "$nextFunc" ) {
            $self->{ScreenControl}->jsChangeImg($nextFunc, '1');
            $self->{ScreenControl}->jsChangeArrow($nextFunc, '2');
            $self->{ScreenControl}->jsSetFontWeight('msg' . $nextFunc, 'bold');
            $self->{ScreenControl}->jsSetFontColor('msg' . $nextFunc, '#FF740E');
            $self->{ScreenControl}->jsSetFontColor('group' . $nextGroup, '#7CABC1');
        }
        if ( $nextGroup eq $nextFunc ) {
            $self->{ScreenControl}->jsSetFontColor('group' . $nextFunc, '#FF740E');
        }
        else {
            if ( "$nextFunc" ne 'end' ) {
            $self->{ScreenControl}->jsSetFontColor('msg' . $nextFunc, '#FF740E');
            $self->{ScreenControl}->jsSetFontColor('subMsg' . $nextFunc, '#FFB20E');
            $self->{ScreenControl}->jsSetFontWeight('msg' . $nextFunc, 'bold');
            $self->{ScreenControl}->jsSetFontWeight('subMsg' . $nextFunc, 'normal');
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate("Please wait") . ' ...', '', 'subMsg' . $nextFunc);
            }
        }
          
        if ( $self->getFunctionConfig("$nextFunc.group") ne $self->getFunctionConfig("$self->{ACTION}.group")) {
            if ( $self->getFunctionConfig("$self->{ACTION}.group") ne 'init') {
                $self->{ScreenControl}->jsChangeSta($self->getFunctionConfig("$self->{ACTION}.group"), '1');
            }
        }
    }
    my ($callNext) = 'Process_' . $nextFunc;
    $self->{ACTION} = $nextFunc;
    print "Call Next Function: $callNext\n" if ( $DEBUG );
    if ($self->can($callNext)) {
        eval($self->$callNext($param));
        if ($@) {
            print $@;
        }
    } else {
        print "Not Found method $callNext\n" if ( $DEBUG );
    }
    $self->exitScript();
}

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

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

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

sub whichCmd {
    my $self = shift;
    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 '') {
        $self->{ScreenControl}->DisplayMsg(1, '', 'which command is not support.');
        $self->{ScreenControl}->LogMsg('which command is not support.');
        return $binpath;
    }
    
    $binpath = RVSInstaller::Process::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 '') {
        $self->{ScreenControl}->DisplayMsg(1, '', $cmd . ' is not support.');
        $self->{ScreenControl}->LogMsg($cmd . ' is not support.');
        
    } elsif (!-x $binpath) {
        $self->{ScreenControl}->DisplayMsg(1, '', $cmd . ' is not executeable.');
        $self->{ScreenControl}->LogMsg($cmd . ' is not executeable.');
    }
        
    return $binpath;
}

sub autoCreateRVFrameworkDB {
    my $self = shift;
    my $dbUserPrefix = shift;
    my $requireDB = shift;
    my $createStatus = 0;
    
    if (!defined $requireDB) {
        $requireDB = 1;
    } else {
        $requireDB = ($requireDB) ? 1 : 0;
    }
    
    my ($dbserver, $dbport, $rvsDBUser, $rvsDBPasswd, $rvsDBName);
    
    my ($mainip,$hostname);
    $hostname = RVSInstaller::Process::callBackticks("hostname");
    chomp($hostname);
    $mainip = RVSInstaller::Process::getMainIP();
    
    if ($requireDB eq '1') {
        my ($dbuser, $dbpass);
        ($dbuser, $dbpass, $dbserver, $dbport) = RVSInstaller::Process::getmycnfdata();
        my $dbdb = 'mysql';
        
        if (!$dbserver) {
            $dbserver = "localhost"; 
        }
        
        if (!$dbport) {
            $dbport = 3306;
        }
        if (!$dbuser) {
            $dbuser = 'root';   
        }
        
        $rvsDBPasswd = RVSInstaller::Process::genPasswd();
        $rvsDBUser = (defined($dbUserPrefix) && $dbUserPrefix ne '') ? $dbUserPrefix : 'rvsdb';
        $rvsDBUser .= RVSInstaller::Process::genPasswd(3);
        
        my ($dbh) = DBI->connect("DBI:mysql:$dbdb:$dbserver:$dbport", "$dbuser", "$dbpass");
        unless ( $dbh ) {
            return 0;
        }
        my ($dbcheck);
        my ($q) = $dbh->prepare("show databases;");
        $q->execute;
        do {
            $dbcheck = "";
            $rvsDBName = (defined($dbUserPrefix) && $dbUserPrefix ne '') ? $dbUserPrefix : 'rvsdb';
            $rvsDBName .= RVSInstaller::Process::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;");
        
        $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();
    }
    
    #write out config
    my $defaultConfigPath = sprintf('%s/etc/default.conf.dist.yaml', $self->getInstallConfig('thisPath'));
    my $installConfigPath = sprintf('%s/var/%s.yaml', $self->getInstallConfig('thisPath'), $hostname);
    
    if (open(my $rh, '<', $defaultConfigPath)) {
        my @data = <$rh>;
        close($rh);
        my $strData = join('', @data);
        
        # enabled: 1
        # host: localhost
        # port: 3306
        # user: root
        # pass: ''
        # name: rvframework
        $strData =~ s/enabled\: 1/enabled\: $requireDB/;
        if ($requireDB eq '1') {
            $strData =~ s/host\: localhost/host\: $dbserver/;
            $strData =~ s/port\: 3306/port: $dbport/;
            $strData =~ s/user\: root/user\: $rvsDBUser/;
            $strData =~ s/pass\: \'\'/pass: \'$rvsDBPasswd\'/;
            $strData =~ s/name\: rvframework/name: $rvsDBName/;
        }
        if (open(my $wh, '>', $installConfigPath)) {
            print $wh $strData;
            close($wh);
            $createStatus = 1;
        }
    }
    
    return $createStatus;
}

sub Process_begin {
    my $self = shift;
    my ($param) = $_[0];
    my (%output);
    
    if ($param) {
        %output = %{$param};
    }

    if ( !-d $self->getInstallConfig('thisPath') . '/logs' ) {
        RVSInstaller::Process::mkdirp($self->getInstallConfig('thisPath') . '/logs');
        chmod(0755, $self->getInstallConfig('thisPath') . '/logs');
    }
    
    if (open(my $wh ,">", $self->getInstallConfig('thisPath') . '/logs/rvsmain_log')) {
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
        $year += 1900;
        print $wh "Start running updated RVSiteBuilder : $mday " . $self->{MONS}->{$mon} . " $year - $hour:$min:$sec\n";
        close($wh);
        chmod(0666, $self->getInstallConfig('thisPath') . '/logs/rvsmain_log');
    }
    
    $self->{ScreenControl}->DisplayMsg('', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->DisplayMsg("#\t\t" . $self->{Language}->TranSlate('Tester Connection') . '.', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Tester Connection') . "\n");
    
    my (%testConn, @testStep);
    
    %testConn = (
#rvglobalsoft.com ปิด http ใช้ https แทน การทดสอบ rvglobalsoft.com:80 จึงยกเลิกใช้
#        'RVG80' => {
#            'domain' => 'rvglobalsoft.com',
#            'port' => '80',
#        },
        'Down80' => {
            'domain' => 'download.rvglobalsoft.com',
            'port' => '80',
        },
        'Down443' => {
            'domain' => 'download.rvglobalsoft.com',
            'port' => '443',
        },
        'Lic80' => {
            'domain' => 'license.rvglobalsoft.com',
            'port' => '80',
        },
        'Lic443' => {
            'domain' => 'license.rvglobalsoft.com',
            'port' => '443',
        },
        'Lic280' => {
            'domain' => 'license2.rvglobalsoft.com',
            'port' => '80',
        },
        'Lic2443' => {
            'domain' => 'license2.rvglobalsoft.com',
            'port' => '443',
        },
    );
    
    #@testStep = ('RVG80', 'Down80', 'Down443', 'Lic80', 'Lic443', 'Lic280', 'Lic2443');
    #@testStep = ('RVG80', 'Down80', 'Down443', 'Lic280', 'Lic2443');
    @testStep = ('Down80', 'Down443', 'Lic280', 'Lic2443');
    $self->{ScreenControl}->jsSetFontColor('groupTestConnect', '#FF740E');
    foreach my $connKey ( @testStep ) {
        $self->{ScreenControl}->jsChangeImg($connKey, '1');
        $self->{ScreenControl}->jsChangeArrow($connKey, '2');
        $self->{ScreenControl}->jsSetFontColor('msg' . $connKey, '#FF740E');
        $self->{ScreenControl}->jsSetFontColor('subMsg' . $connKey, '#FFB20E');
        
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}) . ' : ');
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}));
        my ($testConnection) = $self->TestConnection($testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'});
        if ( $testConnection ) {
            $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Failed'));
            $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
            $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}) . ' has failed.');
            if ( $testConn{$connKey}{'port'} eq '80') {
                $self->{ScreenControl}->DisplayMsg($testConnection, '1', 'subMsg' . $connKey, '', '#FF0000');
                $self->exitScript();
            }
            else {
                $self->{ScreenControl}->DisplayMsg('Package verification fall back from SSL mode to non-SSL mode', '1', 'subMsg' . $connKey, '', '#FF0000');
            }
        }
        else {
            $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Ready') , '', 'subMsg' . $connKey);
            $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Connection xxx port xxx', $testConn{$connKey}{'domain'}, $testConn{$connKey}{'port'}) . ' has ready.');
            $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        }
        $self->{ScreenControl}->jsChangeImg($connKey, '2');
        $self->{ScreenControl}->jsChangeArrow($connKey, '1');
        $self->{ScreenControl}->jsSetFontColor('msg' . $connKey, '#7CABC1');
        $self->{ScreenControl}->jsSetFontColor('subMsg' . $connKey, '#7CABC1');
    }
    $self->{ScreenControl}->jsSetFontColor('groupTestConnect', '#7CABC1');
    $self->{ScreenControl}->jsChangeSta('TestConnect', '1');
    $self->callNextFunc(\%output);
}

sub Process_UpdateInstaller{
    my $self = shift;
    my ($param) = $_[0];
    my %hParam = %{$param};
    $self->{ScreenControl}->DisplayMsg('', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->DisplayMsg("#\t\t" . $self->{Language}->TranSlate("Update xxx", $self->{INSTALLTITLE}) . '.', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate("Update xxx", $self->{INSTALLTITLE}) . "\n");
    $self->callNextFunc(\%hParam);
}

sub Process_DownloadInstaller {
    my $self = shift;
    my ($param) = $_[0];
    my %hParam = %{$param};
    
    if ( -d $self->getInstallConfig('sourcePath')) {
        RVSInstaller::Process::unlinkAll($self->getInstallConfig('sourcePath'));
    }
    
    if ( -d $self->getInstallConfig('packagePath')) {
        chmod(0755, $self->getInstallConfig('sourcePath'));
    }
        
    if (!-d $self->getInstallConfig('sourcePath') ) {
        RVSInstaller::Process::mkdirp($self->getInstallConfig('sourcePath'), "0755");
        chmod(0755, $self->getInstallConfig('sourcePath'));
    }
    
    if ( -e $self->getInstallConfig('sourcePath') . '/.rvsdownloadlog') {
        unlink($self->getInstallConfig('sourcePath') . '/.rvsdownloadlog');
    }
    
    if ( !-e $self->getInstallConfig('thisPath') . '/.skipupdateauto') {
        $hParam{'DownloadInstaller'} = 'InformationPackageInstall';
        $self->{ScreenControl}->DisplayMsg('', '1');
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate("Loading xxx package information", $self->{INSTALLTITLE}), '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg(':');
       
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate("Loading xxx package information", $self->{INSTALLTITLE}) . " : ");
        
        $hParam{'DownloadInstallerConfiguration'}{'reqPackage'} = $self->{'reqPackage'};
        $hParam{'DownloadInstallerConfiguration'}{'ProductCode'} = $self->getInstallPackage("$self->{'reqPackage'}.ProductCode");
        $hParam{'DownloadInstallerConfiguration'}{'ProductName'} = $self->getInstallPackage("$self->{'reqPackage'}.ProductName");
        $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'} = $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename");
        $hParam{'DownloadInstallerConfiguration'}{'LogFileName'} = $self->getInstallConfig('sourcePath') . '/.rvsdownloadlog';
        
        if ( -e $hParam{'DownloadInstallerConfiguration'}{'LogFileName'} ) {
            unlink($hParam{'DownloadInstallerConfiguration'}{'LogFileName'});
        }
        
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Available') , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Available') . "\n");
    
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Downloading new xxx package', $hParam{'DownloadInstallerConfiguration'}{'ProductName'}) , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg(':', '1');
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Downloading new xxx package', $hParam{'DownloadInstallerConfiguration'}{'ProductName'}) . "\n");

        # <-- Download -->
     
        my (%OPT);
        $OPT{'saveas'} = $self->getInstallConfig('sourcePath') . '/' . $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'};
        $OPT{'URL'} = $self->getInstallConfig('SiteConf.download.address.site1') . $self->getInstallConfig('SiteConf.download.uri.site1') . '/download/' . $hParam{'DownloadInstallerConfiguration'}{'ProductCode'};
        if ($hParam{'getversion'}) {
            $OPT{'URL'} .= '/getversion/' . $hParam{'getversion'};
        }
    
        $self->{RVSDownload}->Register('saveas', $OPT{'saveas'});
        $self->{RVSDownload}->Register('URL', $OPT{'URL'});
        $self->{RVSDownload}->Register('evalOutput', 1);
        $self->{RVSDownload}->Register('format', "\$self->{ScreenControl}->LogMsg('\$1' \. \"\\n\");\$self->{ScreenControl}->DisplayMsg('\$1', '1', 'subMsg' . \$self->{ACTION});");
    
        $self->{RVSDownload}->Connection();
    
        $self->{ScreenControl}->DisplayMsg('', 1);
    
        $self->{ScreenControl}->DisplayMsg(':');
        $self->{ScreenControl}->LogMsg("Download the $self->{INSTALLTITLE} package has been completed.\n");
        
        my ($resourceMD5) =  RVSInstaller::Process::rvsMD5File($self->getInstallConfig('sourcePath') . '/' . $hParam{'DownloadInstallerConfiguration'}{'SaveFilename'});
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate("Validating xxx package", $self->{INSTALLTITLE}) . ' ' . $resourceMD5, '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate("Validating xxx package", $self->{INSTALLTITLE}) . ' ' . $resourceMD5 . "\n");
        my (%hData, $Data, %hValidate);
        %hData = (
            'product-name' => $hParam{'DownloadInstallerConfiguration'}{'ProductCode'},
            'MD5-Value' => $resourceMD5,
        );
        if ($hParam{'getversion'}) {
            $hData{'getversion'} = $hParam{'getversion'};
        }
    
        $self->{ScreenControl}->LogMsg('RVS Product Name : ' . $hParam{'DownloadInstallerConfiguration'}{'ProductCode'} . "\n");
        $self->{ScreenControl}->LogMsg('MD5 of package : ' . $resourceMD5 . "\n");
      
        $Data = RVSInstaller::Process::URLEncode(RVSInstaller::Process::SerializerData(\%hData));
        $self->{ScreenControl}->LogMsg('Send RVS Code : ' . $Data . "\n");
        
        $self->{ScreenControl}->LogMsg('Use SSL connection.' . "\n");
        %hValidate = %{$self->UrlConnection($self->getInstallConfig('SiteConf.download.address.site1'), 443, '', 1, $self->getInstallConfig('SiteConf.download.uri.site1') . '?rvcode=' . $Data)};
        if ( $hValidate{'Err'} ) {
            $self->{ScreenControl}->LogMsg('SSL connection has error ' . $hValidate{'Err'} . ".\n");
            $self->{ScreenControl}->LogMsg('Use NONE-SSL connection.' . "\n");
            %hValidate = %{$self->UrlConnection($self->getInstallConfig('SiteConf.download.address.site1'), 80, '', 0, $self->getInstallConfig('SiteConf.download.uri.site1') . '?rvcode=' . $Data)};
        }
    
        if ( $hValidate{'Err'} && !-e $self->getInstallConfig('RVSInstaller') . '/skipinstall/.validateinstaller') {
            $hValidate{'Err'} =~s/\r|\n|\"//gi;
            $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
            $self->{ScreenControl}->LogMsg('NONE-SSL connection has error ' . $hValidate{'Err'} . ".\n");
            $self->{ScreenControl}->DisplayMsg($hValidate{'Err'} , 1, 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->DisplayMsg(" ]\e[0m", 1);
            $self->{ScreenControl}->LogMsg('Sorry, cannot connection with SSL and NONE-SSL' . ".\n");
            $self->exitScript();
        }
        my (%MasterCheck);
        $self->{ScreenControl}->LogMsg('Receive Data : ' . $hValidate{'Page'} . "\n");
        %MasterCheck = RVSInstaller::Process::UnSerializerData($hValidate{'Page'});

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

sub Process_SetupInstaller{
    my $self = shift;
    my ($param) = $_[0];
    my %hParam = RVSInstaller::Process::UnSerializerData($param);
    
    #Register AppConfig for cPanel 11.38++
    if(-e '/usr/local/cpanel/cpkeyclt'){
        $self->registerAppConfig();
    }

    $self->{ScreenControl}->DisplayMsg('', '1');
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate("Setup xxx",$self->{INSTALLTITLE}),1, 'subMsg' . $self->{ACTION});
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate("Setup xxx",$self->{INSTALLTITLE}) . ".\n");

    if ( -e $self->getInstallConfig('thisPath') . '/.skipupdateauto') {
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Skip') , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->LogMsg("Skip setup xxx.\n", $self->{INSTALLTITLE});

    }
    elsif ( -e $self->getInstallConfig('sourcePath') . '/' . $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename") ) {
        $self->{ScreenControl}->DisplayMsg('', '1');
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Running tar uncompressed the xxx package', $self->{INSTALLTITLE}),'', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Running tar uncompressed the xxx package', $self->{INSTALLTITLE}) . ".\n");
        my ($self_mtime)     = ( stat($self->getInstallConfig('thisPath') . '/'.$self->getInstallPackage("$self->{'reqPackage'}.auto.installer").'.cgi') )[9];
        $self->setInstallConfig('AutoInstallStat', $self_mtime);
        # <-- Tar Package -->
        chdir($self->getInstallConfig('sourcePath'));
        if ($self->{'programName'} eq 'rvmanager') {
            $self->Process_SetupInstaller_uncompressFileRVManager();
        } else {
            $self->Process_SetupInstaller_uncompressFile();
        }
        chdir($self->getInstallConfig('thisPath'));
        
        ###### TODO make a new subroutine this section is package dependency
        # <-- Copy source files to installer path -->
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Copy source files to installer path') , '1', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Copy source files to program path') . ".\n");
        
        ##rsync
        if ($self->{'programName'} eq 'rvmanager') {
            $self->Process_SetupInstaller_rsyncFileRVManagerAfterUncompress();
        } else {
            $self->Process_SetupInstaller_rsyncFileAfterUncompress();
        }
        
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Changes the permissions of files') , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Changes the permissions of files') . ".\n");
        
        my ($login,$pass,$uid,$gid) = getpwnam('root');
        $self->{ScreenControl}->LogMsg('Changes the owner to ' . $uid . ' and group to ' . $gid . "\n");
        RVSInstaller::Process::chownAll($self->getInstallConfig('thisPath'), $uid, $gid);
        
        my ($newself_mtime) = ( stat($self->getInstallConfig('thisPath') . '/'.$self->getInstallPackage("$self->{'reqPackage'}.auto.installer").'.cgi') )[9];
        $self->setInstallConfig('NewAutoInstallStat', $newself_mtime);
        
        RVSInstaller::Process::chmodAll($self->getInstallConfig('RVSInstaller'), 0755);
        RVSInstaller::Process::chmodAll($self->getInstallConfig('includePath'), 0755);
        #### END make a new subroutine
        
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Completed') , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
    }
    else {
        $self->{ScreenControl}->DisplayMsg('', '1');
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sorry') . ', ' . $self->{Language}->TranSlate('Find not found the xxx', $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename")),'', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Sorry') . ', ' . $self->{Language}->TranSlate('Find not found the xxx', $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename")) . ".\n");
        $self->exitScript();

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

}

sub Process_end{
    my $self = shift;
    if ( $self->{'BROWSER'} ) {
        if ($self->getInstallConfig('AutoInstallStat') eq $self->getInstallConfig('NewAutoInstallStat')) {
            #running real installer
            my $scriptName = sprintf("%s/auto/%s.%s", $self->{'WEBROOT'}, $self->getInstallPackage("$self->{'reqPackage'}.auto.real"), $self->{'INS_CGI_FILE_TYPE'});
            $self->{ScreenControl}->LogMsg("Running page ".$scriptName."\n");
            print '<script>window.location="' . $scriptName . $self->{'nextScriptParam'} . '";</script>' . "\n";
        } else {
            my $scriptName = sprintf("%s/auto/%s.%s", $self->{'WEBROOT'}, $self->getInstallPackage("$self->{'reqPackage'}.auto.installer"), $self->{'INS_CGI_FILE_TYPE'});
            $self->{ScreenControl}->LogMsg("Running page ".$scriptName."\n");
            print '<script>window.location="' . $scriptName . $self->{'nextScriptParam'} . '";</script>' . "\n";
        }
    } else {
        if ($self->getInstallConfig('AutoInstallStat') eq $self->getInstallConfig('NewAutoInstallStat')) {
            #running real installer
            $self->{ScreenControl}->LogMsg("Running ".$self->getInstallPackage("$self->{'reqPackage'}.auto.real").".cgi\n");
            my ($perlPath) = RVSInstaller::Process::getPerlPath();
            my $scriptName = sprintf("%s/auto/%s.cgi", $self->getInstallConfig('thisPath'), $self->getInstallPackage("$self->{'reqPackage'}.auto.real"));
            system("$perlPath ". $scriptName . $self->{'nextScriptParam'} . ' --system');
        } else {
            $self->{ScreenControl}->LogMsg('Running autoinstaller.cgi' . "\n");
            my ($perlPath) = RVSInstaller::Process::getPerlPath();
            my $scriptName = sprintf("%s/auto/%s.cgi", $self->getInstallConfig('thisPath'), $self->getInstallPackage("$self->{'reqPackage'}.auto.installer"));
            system('cd','/');
            my $pid = open(HANDLE, "|$perlPath ". $scriptName . $self->{'nextScriptParam'} . '|');
            close(HANDLE);
            waitpid($pid, 0);
        }
        if ( -d $self->getInstallConfig('sourcePath')) {
            RVSInstaller::Process::unlinkAll($self->getInstallConfig('sourcePath'));
        }
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
        $year += 1900;
        print sprintf("Run on: %s %s %s - %s:%02d:%02d\n", $mday, $self->{MONS}->{$mon}, $year, $hour, $min, $sec);
    }
    if (!defined($self->{'skipExitScript'}) || $self->{'skipExitScript'} != 1) {
        $self->exitScript();
    }
}

#### License Group ####
sub Process_LicenseInfo{
    my $self = shift;
    my ($param) = $_[0];
    my %hParam = %{$param};
    
    $self->{ScreenControl}->DisplayMsg('', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->DisplayMsg("#\t\t" . $self->{Language}->TranSlate('License Information') . '.', 1);
    $self->{ScreenControl}->DisplayBoxMsg(0, $self->{Language}->TranSlate('License Information'), '');
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    if (defined $hParam{'force'}) {
        $self->{ScreenControl}->DisplayMsg('Use option force update', '1');
        if ( -e $self->getInstallConfig('packagePath')) {
            system($self->{'cmd'}->{'rm'}, '-rf', $self->getInstallConfig('packagePath'),'>/dev/null');
            system($self->{'cmd'}->{'mkdir'}.' -p ' . $self->getInstallConfig('packagePath'));
        }
    }

    $self->callNextFunc(\%hParam);
}

sub Process_LicenseRVSkin {
    my $self = shift;
    
    my ($param) = $_[0];
    my %hParam = %{$param};
    
    # Validate RVskin license for cPanel;
    my $mainip = RVSInstaller::Process::getMainIP();

    my($updatelicense) = "";

#   if($version eq "latest") {
#       $updatelicense = 1;
#   }
#   else {
#       my($rvversion1, $rvversion2);
#       $version=~/(\d*)\.(\d*)/;
#       $rvversion1 =$1;
#       $rvversion2 =$2;
#       $rvversion1 = int($rvversion1);
#       $rvversion2 = int($rvversion2);
#       if ($rvversion1 >= 4 && $rvversion2 > 50) {
#           $updatelicense = 1;
#       }
#   }

    $updatelicense = 1;

# connect to xxx.
# Change to POST method to avoid type data directory to url, and get http: referer it should not return any referer
    my($request) = "/license/generator.php";
    my($data2send) = "mainip=$mainip";
    my($lendata) = length($data2send);
    my($referer) = "www.blindrefer.com";
    my($host) = "license.rvskin.com";
    my $iaddr = gethostbyname($host) || print "Unable to resolve $host\n";
#   my $iaddr = "66.246.44.104";
    my $proto = getprotobyname('tcp');
    socket(RVSKIN, AF_INET, SOCK_STREAM, $proto) || die"socket error: $!\n";
    my $port = "80";
    my $sin = sockaddr_in($port, $iaddr);
    connect("RVSKIN", $sin) || die "Unable to connect\n";
    send RVSKIN, "POST $request HTTP/1.0\n", 0;
    send RVSKIN, "Referer: http://$referer\n", 0;
    send RVSKIN, "Content-type: application/x-www-form-urlencoded\n", 0;
    send RVSKIN, "Content-length: $lendata\n\n", 0;
    send RVSKIN, "$data2send", 0;
    my $inheaders = 1;

    my $valid = '';
    my $msg = '';
    my(@datareturn) = <RVSKIN>;
    foreach my $temp (@datareturn) {
        if($inheaders) {
            $temp =~s/\n//g;
            $temp =~s/\s$//g;
        }

        if (!$inheaders) {
            if($temp =~/^(\w*)::(.*)/){ $valid = $1; $msg = "$2\n"; }
            else {$msg .="$temp";}
        }
        if ($temp =~/^$/ && $inheaders) { $inheaders = 0; }
    }

    if ($valid eq "valid") {
        if ($msg && $updatelicense) {
            open (my $LIC , '>', "/usr/local/cpanel/Cpanel/key");
            flock ($LIC,2);
            print $LIC "$msg";
            flock ($LIC,8);
            close ($LIC);
            system("chmod 644 /usr/local/cpanel/Cpanel/key >/dev/null 2>&1");
            system("echo $mainip > /usr/local/cpanel/Cpanel/rvspecialmainip");
            system("chmod 644 /usr/local/cpanel/Cpanel/rvspecialmainip  >/dev/null 2>&1");
        }
    }
    elsif ($valid eq "expired") {
# - Subscription expired;
        $self->{ScreenControl}->LogMsg($msg);
        $self->exitScript($msg);
    }
    elsif ($valid eq "invalid") {
#   --- Temporaray Disable to prevent it mess up existing customers ----
#         This will be implemeted on Jan 15,2004
#       system("rm -f /usr/local/cpanel/Cpanel/key >/dev/null 2>&1");
        $self->{ScreenControl}->LogMsg($msg);
        #$self->exitScript($msg);
    }
    else {
        $self->{ScreenControl}->DisplayMsg("$msg");
        $self->{ScreenControl}->LogMsg($msg);
        print "#########  Forbidden ###########\n";
# uplinks server have proxy problem and cause license.generator doesn't work
#       exit;
    }
# - No PTR records, might cause SSH_identification_error

    $self->callNextFunc(\%hParam);
}

sub Process_LicenseInfoGet {
    #TODO license checker
    my $self = shift;
    
    my ($param) = $_[0];
    my %hParam = %{$param};
    
    # $self->{'programName'}
    my $rvcode = RVSInstaller::Process::getRvCode($self->{'programName'}, $self->getInstallConfig('cpMode'));
    
    $hParam{'MainIP'} = RVSInstaller::Process::getMainIP();
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'}, '1', 'subMsg' . $self->{ACTION});
    push(@{$hParam{'boxMessages'}}, $self->{Language}->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'});
    $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
    
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Used xxx connection validate xxx for IP', 'SSL' ,'license') . ' ' . $hParam{'MainIP'}, '1', 'subMsg' . $self->{ACTION});
    push(@{$hParam{'boxMessages'}}, $self->{Language}->TranSlate('Used xxx connection validate xxx for IP', 'SSL' ,'license') . ' ' . $hParam{'MainIP'});
    $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Used xxx connection validate xxx for IP', 'SSL', 'license') . ' ' . $hParam{'MainIP'} . "\n");
    # <-- Connection to license site by SSL-->
       
    my %licenseInfo = %{$self->UrlConnection($self->getInstallConfig('SiteConf.license.address.site1'), 443, '', 1, $self->getInstallConfig('SiteConf.license.uri.site1') . '?rvcode=' . $rvcode)};
    if ( $licenseInfo{'Err'} ) {
        # <-- Connection error -->
        $licenseInfo{'Err'} =~s/\r|\n|\"//gi;
        $self->{ScreenControl}->DisplayMsg($self->{failedColor});
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sorry') . ', ' . $self->{Language}->TranSlate('cannot used xxx connection to', 'SSL') . ' ' . $self->getInstallConfig('SiteConf.license.address.site1') . ': ' . $licenseInfo{'Err'} , 1, 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m", 1);
        push(@{$hParam{'boxMessages'}}, 
            ' -- ' . $self->{Language}->TranSlate('Sorry') . ', ' . $self->{Language}->TranSlate('cannot used xxx connection to', 'SSL') . ' ' . $self->getInstallConfig('SiteConf.license.address.site1') . ': ' . $licenseInfo{'Err'}
        );
        $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
            
        # <-- Used NONE SSL Connection -->
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Used xxx connection validate xxx for IP', 'NONE-SSL' ,'license') . ' ' . $hParam{'MainIP'}, '1', 'subMsg' . $self->{ACTION});
        push(@{$hParam{'boxMessages'}}, 
            $self->{Language}->TranSlate('Used xxx connection validate xxx for IP', 'NONE-SSL' ,'license') . ' ' . $hParam{'MainIP'}
        );
        $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Used xxx connection validate xxx for IP', 'NONE-SSL', 'license') . ' ' . $hParam{'MainIP'} . "\n");
        %licenseInfo = ();
        %licenseInfo = %{$self->UrlConnection($self->getInstallConfig('SiteConf.license.address.site1'), 80, '', 0, $self->getInstallConfig('SiteConf.license.uri.site1') . '?rvcode=' . $rvcode)};
        if ( $licenseInfo{'Err'} ) {
            # <-- Connection error -->
            $licenseInfo{'Err'} =~s/\r|\n|\"//gi;
            
            $self->{ScreenControl}->LogMsg('SSL connection has error, ' . $licenseInfo{'Err'} . "\n");
            $self->{ScreenControl}->DisplayMsg($self->{failedColor});
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sorry') . ', ' . $self->{Language}->TranSlate('cannot connection to') . ' ' . $self->getInstallConfig('SiteConf.license.address.site1') . ': ' . $licenseInfo{'Err'} , 1, 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->DisplayMsg("\e[0m", 1);
           
            $self->{ScreenControl}->LogMsg('Sorry, cannot connection with SSL and NONE-SSL' . ".\n");
            $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
            # <-- End Process Installer -->
            $self->exitScript();
        }
    }
    
    $self->{ScreenControl}->LogMsg('Receive Data : ' . $licenseInfo{'Page'} . "\n");
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'}, '', 'subMsg' . $self->{ACTION});
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'} . ' has been completed.' . "\n");
    $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Pass') , '', 'subMsg' . $self->{ACTION});
    $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
    @{$hParam{'boxMessages'}} = ();
    push(@{$hParam{'boxMessages'}}, $self->{Language}->TranSlate('Validate license for IP') . ' ' . $hParam{'MainIP'} . ': ' . $self->{Language}->TranSlate('Pass'));
    $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'boxMessages'}});
    
    $hParam{'LicenseInfo'} = $licenseInfo{'Page'};
    push(@{$hParam{'BoxMessages'}}, @{$hParam{'boxMessages'}});
    
    $self->callNextFunc(\%hParam);
}

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

    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Product information'));
    my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
    $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
    
    if ( exists $hLicenseInfo{$self->{'programName'}}{'products'}{'name'} ) {
        $self->{ScreenControl}->DisplayMsg($hLicenseInfo{$self->{'programName'}}{'products'}{'name'}, '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg('Your license type ' . $hLicenseInfo{$self->{'programName'}}{'products'}{'name'} . "\n");
        push(@{$hParam{'BoxMessages'}}, 'Your license type: ' . $hLicenseInfo{$self->{'programName'}}{'products'}{'name'});
        $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}});
    }
    else {
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Unknown') , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->LogMsg('Your license type unknown' . "\n");
        push(@{$hParam{'BoxMessages'}}, 'Your license type: Unknown');
        $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}});
    }
    $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
    $self->callNextFunc(\%hParam);
}

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

    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Validate expired date'), '', 'subMsg' . $self->{ACTION});
    $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, $self->{Language}->TranSlate('Validate expired date') . '...');
    
    my (%hLicenseInfo) = RVSInstaller::Process::UnSerializerData($hParam{'LicenseInfo'});
    
    if ( exists $hLicenseInfo{$self->{'programName'}}{'expire-date'} && $hLicenseInfo{$self->{'programName'}}{'expire-date'} > time ) {
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($hLicenseInfo{$self->{'programName'}}{'expire-date'});
        $year += 1900;
        $mon = $self->{'MONS'}->{$mon};
        $self->{ScreenControl}->DisplayMsg("$mday $mon $year" , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->LogMsg('Your license expired  on ' . "$mday $mon $year\n");
        $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, $self->{Language}->TranSlate('Validate expired date') . ': ' . "$mday $mon $year");
    }
    elsif ( exists $hLicenseInfo{$self->{'programName'}}{'expire-date'} && $hLicenseInfo{$self->{'programName'}}{'expire-date'} < time ) {
         $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($hLicenseInfo{$self->{'programName'}}{'expire-date'});
        $year += 1900;
        $mon = $self->{'MONS'}->{$mon};
         $self->{ScreenControl}->DisplayMsg("Your license has expired. " .$hLicenseInfo{$self->{'programName'}}{'expire-date'}. "( $mday $mon $year)", '', 'subMsg' . $self->{ACTION});
         $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
         $self->{ScreenControl}->LogMsg('Your license has expired. ' . $hLicenseInfo{$self->{'programName'}}{'expire-date'} . "( $mday $mon $year )\n");
         $self->{ScreenControl}->DisplayBoxMsg(0, '', @{$hParam{'BoxMessages'}}, "Your license has expired. " .$hLicenseInfo{$self->{'programName'}}{'expire-date'}. "( $mday $mon $year)");
    } else {
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
        if ( exists $hLicenseInfo{'on error'} && $hLicenseInfo{'on error'} ) {
            $self->{ScreenControl}->DisplayMsg($hLicenseInfo{'error msg'} , '', 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->LogMsg($hLicenseInfo{'error msg'} . "\n");
            $self->{ScreenControl}->DisplayBoxMsg(0, '', $hLicenseInfo{'error msg'});
        }
        else {
            $self->{ScreenControl}->DisplayMsg("Cannot get license information form RVGlobalsoft site.", '', 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->LogMsg("Cannot get license information form RVGlobalsoft site." . "\n");
            $self->{ScreenControl}->DisplayBoxMsg(0, '', "Cannot get license information form RVGlobalsoft site.");
        }
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->exitScript();
    }
    $self->{ScreenControl}->CloseBoxMsg();
    $self->callNextFunc(\%hParam);
}

sub Process_GetLicense {
    my $self = shift;
    
    my ($param) = $_[0];
    $self->{ScreenControl}->DisplayMsg('', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->DisplayMsg("#\t\t" . $self->{Language}->TranSlate("Updated License Key") . '.', 1);
    $self->{ScreenControl}->DisplayMsg('########################################################################', 1);
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate("Updated License Key"));
    $self->{ScreenControl}->DisplayBoxMsg(1, $self->{Language}->TranSlate("Updated License Key"), 'Please wait...');
    $self->callNextFunc($param); 
}

sub Process_GetLicenseDow{
    my $self = shift;
    
    my ($param) = $_[0];
    my %hParam = RVSInstaller::Process::UnSerializerData($param);
    
    if ( !-e $self->getInstallConfig('sourcePath')) {
        mkdir($self->getInstallConfig('sourcePath'), 0755);
    }
    
    my $licFile = $self->{'programName'}.'.lic';
    $hParam{'EncryptType'} = 'ioncube';
    
    $hParam{'SaveReqFile'} = $self->getInstallConfig('sourcePath') . '/' . $self->getInstallConfig('LicenseReqFile');
       
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Setting xxx request license key', $self->{Language}->TranSlate($hParam{'EncryptType'})), '', 'subMsg' . $self->{ACTION});
    
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Setting xxx request license key', $self->{Language}->TranSlate($hParam{'EncryptType'})));
        
    if ( -e '/root/.accesshash' || $self->getInstallConfig('cpMode') eq 'Directadmin') {
        my ($aKey);
        $aKey = '';
        if (open(my $rh, '/root/.accesshash')) {
            while(my $line = <$rh>) {
                chomp($line);
                $line =~ s/\r|\n|\ //i;
                $aKey .= $line;
            }
            close($rh);
        }
    
        $self->{ScreenControl}->LogMsg('WHM Connection');
        my $callUrl =  '/cgi/rvmanager/modules/scripts/ioncube.php';
        
        my @page = ();
        if ( $self->getInstallConfig('cpMode') eq 'Directadmin') {
            my $saveFile = ' > ' . $hParam{'SaveReqFile'};
            my $cmdIoncube = 'php -c /usr/local/rvglobalsoft/rvmanager/modules/scripts/php.ini /usr/local/rvglobalsoft/rvmanager/modules/scripts/ioncube.php' . $saveFile;
            @page = system($cmdIoncube);
        } else {
            @page = RVSInstaller::Process::whmConnection($aKey, $callUrl);
            open(W , '>' . $hParam{'SaveReqFile'});
            foreach (@page) {
                $self->{ScreenControl}->LogMsg($_);
                print W $_;
            }
            close(W);
            copy($hParam{'SaveReqFile'}, $self->getInstallConfig('thisPath') . '/var/' . $self->getInstallConfig('LicenseReqFile'));
        }

        chmod(0777, $self->getInstallConfig('thisPath') . '/var/' . $self->getInstallConfig('LicenseReqFile'));
        
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Completed'));
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
    
        $hParam{'SaveToFilename'} = $self->{'programName'}.'.tar';
        $hParam{'LogFile'} = $self->getInstallConfig('sourcePath') . '/.rvlicense.log';
            
        if ( -e $hParam{'LogFile'} ) {
            unlink($hParam{'LogFile'});
        }
       
        my %licReq = ();
        
        my @allIPList = RVSInstaller::Process::getAllIP();
        $licReq{'timestamp'} = time();
        $licReq{'primary-ip'} = RVSInstaller::Process::getMainIP();
        $licReq{'program'} = $self->{'programName'};
        $licReq{'all-ip'} = join(',', @allIPList);
        $licReq{'cp'} = lc($self->getInstallConfig('cpMode'));
        $licReq{'vps'} = '';#RVL::LicenseCycle::isVps();
        $licReq{'license-code'} = join('', @page);
        $licReq{'license-code'} =~s/\r|\n//gi;
        $licReq{'rand'} = int(rand(9000)) + 1000; #range: 1000-9999
        
        my $licensePath = $self->getInstallConfig('thisPath') . '/var/license';
        if (-w $licensePath) {
            my $fileIpAll = $self->getInstallConfig('thisPath') . '/var/license/allip.ini';
            open(W, "> $fileIpAll");
            foreach my $value (@allIPList) {
                if ($value != '') {
                    print W $value . "=" . $value . "\n";
                }
            }
            close(W);
            chmod(0644,$fileIpAll);
        }
        
        my $dataReq = '?rvcode=' . RVSInstaller::Process::URLEncode(RVSInstaller::Process::SerializerData(\%licReq)) . '&file='.$hParam{'SaveToFilename'};

        my (%OPT);
        $OPT{'saveas'} = $self->getInstallConfig('sourcePath') . '/' . $hParam{'SaveToFilename'};
        $OPT{'URL'} = $self->getInstallConfig('SiteConf.licensekey.address.site1') . $self->getInstallConfig('SiteConf.licensekey.uri.site1').$dataReq;

        $self->{RVSDownload}->Register('saveas', $OPT{'saveas'});
        $self->{RVSDownload}->Register('URL', $OPT{'URL'});
        $self->{RVSDownload}->Register('evalOutput', 1);
        $self->{RVSDownload}->Register('format', "$self->{ScreenControl}->LogMsg('\$1' \. \"\\n\");$self->{ScreenControl}->DisplayMsg('\$1', '1', 'subMsg' . \$self->{ACTION});");
        
        #print "goto downloads>>" . $OPT{'URL'} . $dataReq;
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sendding the license request to xxx', $self->getInstallConfig('SiteConf.licensekey.address.site1')) , '1');
        
        $self->{RVSDownload}->Connection();
        chmod(0755, $self->getInstallConfig('sourcePath') . '/' . $hParam{'SaveToFilename'});
       
        my ($resourceMD5) =  RVSInstaller::Process::rvsMD5File($self->getInstallConfig('sourcePath') . '/' . $hParam{'SaveToFilename'});
        my (%licVal, $Data, %hValidate);
        $licVal{'program'} = $self->{'programName'};
        $licVal{'primary-ip'} = RVSInstaller::Process::getMainIP();
        $licVal{'validateFile'} = $resourceMD5;
        $licVal{'all-ip'} = join(',', @allIPList);
        $licVal{'cp'} = lc($self->getInstallConfig('cpMode'));
        $licVal{'vps'} = '';#RVL::LicenseCycle::isVps();

        $Data = RVSInstaller::Process::URLEncode(RVSInstaller::Process::SerializerData(\%licVal));
        $self->{ScreenControl}->LogMsg('License Key package MD5 : ' . $resourceMD5 . "\n");
        $self->{ScreenControl}->LogMsg('License Key package data : ' . $Data . "\n");
        
        $hValidate{'Page'} = '';
        $self->{ScreenControl}->LogMsg('Connection to ' . $self->getInstallConfig('SiteConf.licensekey.address.site1') . ' prot 443 SSL page ' . $self->getInstallConfig('SiteConf.licensekey.uri.site1'));
        %hValidate = %{$self->UrlConnection($self->getInstallConfig('SiteConf.licensekey.address.site1'), 443, '', 1, $self->getInstallConfig('SiteConf.licensekey.uri.site1') . '?rvcode=' . $Data)};
       
        if ($hValidate{'Err'} ) {
            # <-- NONE SSL Connection -->
            $self->{ScreenControl}->LogMsg('Connection to ' . $self->getInstallConfig('SiteConf.licensekey.address.site1') . ' prot 80  NONE SSL page ' .$self->getInstallConfig('SiteConf.licensekey.uri.site1'));
            %hValidate = %{$self->UrlConnection($self->getInstallConfig('SiteConf.licensekey.address.site1'), 80, '', 0, $self->getInstallConfig('SiteConf.licensekey.uri.site1') . '?rvcode=' . $Data)};
        }
        
        if ( $hValidate{'Err'} ) {
            $self->{ScreenControl}->DisplayMsg($hValidate{'Err'} , 1, 'subMsg' . $self->{ACTION});
            $hParam{'LicenseSkip'} = 1;
        } else {
            $hValidate{'Page'} =~s/\r|\n|\t//gi;
            $self->{ScreenControl}->LogMsg('REQ : [' . $hValidate{'Page'} . "]\n");
            if ( $hValidate{'Page'} ne '1') {
                $hParam{'LicenseSkip'} = 1;
                $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Invalid'), '', 'subMsg' . $self->{ACTION});
            } else {
                $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Running uncompressed the licenses key package'), '1', 'subMsg' . $self->{ACTION});
                chdir($self->getInstallConfig('sourcePath'));
                my (@logTarData); 
                $SIG{'PIPE'} = 'IGNORE';
                $SIG{'HUP'}  = 'IGNORE';
                $SIG{'ALRM'} = 'IGNORE';
                ############### download file  mylicense.tar and change permission and extract file ###########
                chmod(0755, $self->getInstallConfig('sourcePath') . '/' . $hParam{'SaveToFilename'});
                my $cmdTar = $self->{'cmd'}->{'tar'} . ' -jxvf ' . $hParam{'SaveToFilename'} . ' >/dev/null 2>&1';
                $self->{ScreenControl}->LogMsg('extract cmd=' . $cmdTar . "]\n");
                system($cmdTar);
                
                if (!-e $self->getInstallConfig('thisPath') . '/var/license') {
                    system('mkdir -p ' . $self->getInstallConfig('thisPath') . '/var/license');
                }
                #system('chown securervsite:securervsite ' . $self->getInstallConfig('thisPath') . '/var/license');
                
                if ( -e $self->getInstallConfig('thisPath') . '/var/license/' . $licFile ) {
                    unlink($self->getInstallConfig('thisPath') . '/var/license/' . $licFile );
                }
                
                chdir($self->getInstallConfig('thisPath'));
                 
                $hParam{'GetLicenseDow'} = 'Completed';
                $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
                $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Completed'), '', 'subMsg' . $self->{ACTION});
                $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
            }
        }
    } else {
        # <-- Not Read Root accesshash -->
        $hParam{'LicenseSkip'} = 1;
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Cannot read remote access key'), '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Cannot read remote access key'));
    }
    my (%hSendParam);
    $hSendParam{'LicenseSkip'} = $hParam{'LicenseSkip'};
    $hSendParam{'EncryptType'} = $hParam{'EncryptType'};
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    $hSendParam{'licFile'} = $licFile;
    $self->callNextFunc(\%hSendParam);
}

sub Process_GetLicenseFile {
    my $self = shift;
    my ($param) = $_[0];
    my (%hParam) = %{$param};
    
    $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Updatting xxx license key', $self->{'programName'}), '', 'subMsg' . $self->{ACTION});
    
    $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Updatting xxx license key', $self->{'programName'}));
   
    if ( $hParam{'LicenseSkip'} ) {
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Skip'), '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Updatting xxx license key', $self->{'programName'}) . ' has been skip.');
    } else {
        if ( -e $self->getInstallConfig('sourcePath') . '/' . $hParam{'licFile'} ) {
            $self->{ScreenControl}->LogMsg('Copy license file to program path');
            
            if ( -e $self->getInstallConfig('thisPath') . '/var/license/' . $hParam{'licFile'} ) {
                my ($os) = RVSInstaller::Process::callBackticks("$self->{'cmd'}->{'uname'} -s");
                my ($opt);
                if ( $os =~/freebsd/gi) {
                    system($self->{'cmd'}->{'chflags'} . ' noschg ' . $self->getInstallConfig('sourcePath') . '/' . $hParam{'licFile'} . ' >/dev/null 2>&1')
                } else {
                    system($self->{'cmd'}->{'chattr'} . ' -i ' . $self->getInstallConfig('sourcePath') . '/' . $hParam{'licFile'} . ' >/dev/null 2>&1')
                }
            }
            
            copy($self->getInstallConfig('sourcePath') . '/' . $hParam{'licFile'}, 
                $self->getInstallConfig('thisPath') . '/var/license/' . $hParam{'licFile'});
                
#            chmod(0464, $self->getInstallConfig('thisPath') . '/var/license/' . $hParam{'licFile'});
#            system('chown securervsite:securervsite ' . $self->getInstallConfig('thisPath') 
#                . '/var/license/' . $hParam{'licFile'});
            
#            unlink($self->getInstallConfig('thisPath') . '/' . $hParam{'licFile'});
#            
#            if ( !readlink($self->getInstallConfig('thisPath') . '/' . $hParam{'licFile'}) ) {
#                chdir($self->getInstallConfig('thisPath'));
#                symlink('var/license/' . $hParam{'licFile'} 
#                    , $hParam{'licFile'});
#                chdir($InstallConf{'ThisParh'});
#            }
            
            $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Completed'), '', 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
            $self->{ScreenControl}->LogMsg('Copy license file to program path has been completed');
        } else {
            $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Failed'), '', 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Find not found xxx', $self->{'programName'}.' license key'), '', 'subMsg' . $self->{ACTION}, '', '#FF0000');
            $self->{ScreenControl}->LogMsg($self->{Language}->TranSlate('Find not found xxx', $self->{'programName'}.' license key'));
        }
    }
    my (%hSendParam);
    $hSendParam{'LicenseSkip'} = $hParam{'LicenseSkip'};
    $hSendParam{'EncryptType'} = $hParam{'EncryptType'};
    $hSendParam{'reqPackage'} = $hParam{'reqPackage'};
    $hSendParam{'LicenseInfo'} = $hParam{'LicenseInfo'};
    $self->callNextFunc(\%hSendParam);
}

#### RVManager Group ####
sub Process_ValidateRVManager {
    my $self = shift;
    my $param = shift;
    
    print "Checking RVManager...\n";
    #update rvmanager
    
    #push old request file to tmp
    $self->{'stackReqPackage'} = $self->{'reqPackage'};
    
    $self->{'reqPackage'} = 'rvmanager-upgrade';
    
    my ($perlPath) = RVSInstaller::Process::getPerlPath();
    
    if (!-e '/usr/local/rvglobalsoft/rvmanager/autorvmanager.cgi') {
        if (-e $self->getInstallConfig('thisPath').'/auto/autorvmanager.cgi') {
            my $scriptName = sprintf($self->getInstallConfig('thisPath').'/auto/autorvmanager.cgi');
            chmod(0755, $scriptName);
            $self->{ScreenControl}->LogMsg('Update RVManager' . "\n");
            system('cd','/');
            my $pid = open(HANDLE, "|$perlPath ". $scriptName . ' '.$self->{'nextScriptParam'}.'|');
            close(HANDLE);
            waitpid($pid, 0);
        }
    } else {
        if (-e '/usr/local/rvglobalsoft/rvmanager/autorvmanager.cgi') {
            chmod(0755, '/usr/local/rvglobalsoft/rvmanager/autorvmanager.cgi');
            $self->{ScreenControl}->LogMsg('Update RVManager' . "\n");
            my $scriptName = sprintf("/usr/local/rvglobalsoft/rvmanager/autorvmanager.cgi");
            system('cd','/');
            my $pid = open(HANDLE, "|$perlPath ". $scriptName . ' '.$self->{'nextScriptParam'}. '|');
            close(HANDLE);
            waitpid($pid, 0);
        }
    }
    
    #ensure rvmanager has install correctly
    if ($self->getInstallConfig('cpMode') eq 'Cpanel') {
        if (!-x '/usr/local/cpanel/whostmgr/cgi/addon_rvmanager.cgi') {
            $self->exitScript($self->{Language}->TranSlate("Not found RVManager"));
        }
    } else {
        print "RVManager has installed\n";
    }
    
    if (defined($self->{'stackReqPackage'}) && $self->{'stackReqPackage'} ne '') {
        $self->{'reqPackage'} = $self->{'stackReqPackage'};
    }

    $self->callNextFunc($param);
}

sub Process_SetupInstaller_uncompressFileRVManager {
    my $self = shift;
    my @logTarData = ();
    system($self->{'cmd'}->{'tar'} . ' -jxvf ' . $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename")) if(-f $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename"));
    return 1;
    
    #TODO uncompress solution
    chdir($self->getInstallConfig('sourcePath'));
    my $pid3 = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $self->{'cmd'}->{'tar'} . ' -jxvf ' . $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename"));
    waitpid($pid3, 0);
    close(CMD_IN);
    my @errs = <CMD_ERR>;
    close(CMD_ERR);
    if (@errs) { 
        my $errMsg = join("", @errs);
            $errMsg=~s/\n$//;
            $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Failed'));
            $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
            $self->{ScreenControl}->DisplayMsg('', 1);
            $self->{ScreenControl}->DisplayMsg("$self->{failedColor}");
            $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sorry') . ', '.$errMsg, 0, 'subMsg' . $self->{ACTION}, '', '#FF0000');
            $self->{ScreenControl}->DisplayMsg("\e[0m", 1);
            $self->{ScreenControl}->LogMsg('Uncompress the package has been uncompleted, ' . $errMsg . ".\n");
            $self->exitScript();
    } else {
        while (my $pData = <CMD_OUT>) {
            $pData=~s/\r|\n//gi;
            $self->{ScreenControl}->DisplayMsg($pData , '1', 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->LogMsg($pData . "\n");
            push(@logTarData, $pData);
        }
        close(CMD_OUT); 
    }
    
    chdir($self->getInstallConfig('thisPath'));
    
    my $chData = 1;
    my $errorMsg = '';
    foreach my $data ( @logTarData ) {
        if ( $data =~ m/\/$/) {
            if ( !-d $data) {
                $errorMsg = sprintf("%s %s %s", $self->{Language}->TranSlate('the folder'), $data, $self->{Language}->TranSlate('cannot uncompressed'));
                $chData = 0;
                last;
            }
        }
        else {
            if ( !-e $data) {
                $errorMsg = sprintf("%s %s %s", $self->{Language}->TranSlate('the file'), $data, $self->{Language}->TranSlate('cannot uncompressed'));
                $chData = 0;
                last;
            }
        }
    }
    
    chdir($self->getInstallConfig('thisPath'));
    if ( !$chData ) {
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Failed'));
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->DisplayMsg('', 1);
        $self->{ScreenControl}->DisplayMsg("$self->{failedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sorry') . ', ' . $errorMsg . '.', 1, 'subMsg' . $self->{ACTION}, '', '#FF0000');
        $self->{ScreenControl}->DisplayMsg("\e[0m", 1);
        $self->{ScreenControl}->LogMsg('Uncompress the package has been uncompleted, ' . $errorMsg . ".\n");
        $self->exitScript();
    }
    else {
        if ( -e $self->getInstallPackage("$self->{'reqPackage'}.SaveFilename")) {
            unlink($self->getInstallPackage("$self->{'reqPackage'}.SaveFilename"));
        }
        
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{completedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Completed') , '', 'subMsg' . $self->{ACTION});
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->LogMsg('Uncompress the package has been completed' . "\n");
    }
}

sub Process_SetupInstaller_rsyncFileRVManagerAfterUncompress {
    my $self = shift;
    if(-e $self->getInstallConfig('sourcePath')){
    	system($self->{'cmd'}->{'rsync'} . ' -avz --timeout=60 ' . $self->getInstallConfig('sourcePath') . '/ ' . $self->getInstallConfig('thisPath'));
    }
    return 1;
    
    my $pid3 = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, $self->{'cmd'}->{'rsync'} . ' -avz --timeout=60 ' . $self->getInstallConfig('sourcePath') . '/ ' . $self->getInstallConfig('thisPath'));
    waitpid($pid3, 0);
    close(CMD_IN);
    my @errs = <CMD_ERR>;
    close(CMD_ERR);
    if (@errs) {
        my $errMsg = join("", @errs);
        $errMsg=~s/\n$//;
        $self->{ScreenControl}->DisplayMsg("<TAB>[ $self->{failedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Failed'));
        $self->{ScreenControl}->DisplayMsg("\e[0m ]", 1);
        $self->{ScreenControl}->DisplayMsg('', 1);
        $self->{ScreenControl}->DisplayMsg("$self->{failedColor}");
        $self->{ScreenControl}->DisplayMsg($self->{Language}->TranSlate('Sorry') . ', '.$errMsg, 0, 'subMsg' . $self->{ACTION}, '', '#FF0000');
        $self->{ScreenControl}->DisplayMsg("\e[0m", 1);
        $self->{ScreenControl}->LogMsg("Rsync the package has not completed, $errMsg.\n");
        $self->exitScript();
    } else {
        while (my $rsyncData = <CMD_OUT>) {
            $rsyncData=~s/\r|\n//gi;
            $self->{ScreenControl}->DisplayMsg($rsyncData, 1, 'subMsg' . $self->{ACTION});
            $self->{ScreenControl}->LogMsg($rsyncData . "\n");
        }
        close(CMD_OUT);
    }
}

1;
__END__

Copyright 2K16 - 2K18 Indonesian Hacker Rulez