#!/usr/bin/perl
##LICENSE##
package RVSInstaller::Installer;
use strict;
#use warnings;
use Carp;
use Socket;
use POSIX;
use File::Basename;
use Data::Dumper;
use MIME::Base64;
use IPC::Open2;
BEGIN {
push(@INC, dirname(dirname(__FILE__)));
}
use RVSInstaller::Config qw(%InstallConf $NEWLINE $BROWSER $WEBROOT %MONS $INS_PHP_FILE_TYPE $INS_CGI_FILE_TYPE);
use RVSInstaller::Process;
use RVSInstaller::Serializer;
use RVSInstaller::ScreenControl;
use RVSInstaller::Language;
use RVSInstaller::RVSDownload;
use RVSInstaller::Template;
#use base qw(RVSInstaller::AbstractProcess);
use vars qw($DEBUG $nextScriptParam
$cmd_cp $cmd_cp_all $cmd_mv $cmd_rm $cmd_mkdir $cmd_ln $cmd_rsync $cmd_tar
$cmd_replace $cmd_uname $cmd_df $cmd_chmod
$cmd_replace $cmd_echo $cmd_lsattr $cmd_cat $cmd_date $cmd_locale $cmd_localedef $cmd_uname $cmd_perl
);
sub new {
my $class = shift;
#my $self = RVSInstaller::AbstractProcess->new( @_ );
my $self = {
INSTALLTITLE => "RVPackage Installer",
@_,
};
$self->{InstallConf} = {%InstallConf};
$self->{MONS} = {%MONS};
# $self->{objLANG} = $self->{objLANG};
bless $self, $class;
$self->loadvars();
return $self;
}
#sub AUTOLOAD {
# my $self = shift;
# my $attr = our $AUTOLOAD;
# $attr =~ s/.*:://;
# print "__PACKAGE__::$attr\n";
# return unless $attr =~ /Process\_/; # skip DESTROY and all-cap methods
# #croak "invalid attribute method: ->$attr( )" unless $ok_field{$attr};
# $self->{$attr} = shift if @_;
# print $self->{$attr};
# return $self->{$attr};
#}
sub startInstaller {
my $self = shift;
$self->initFunc();
$self->initLang();
$self->initTemplate();
$self->initData();
#$self->Validate();
}
sub initFunc {
my $self = shift;
$self->{FuncConf} = {
'begin' => {
'next' => 'UpdateInstaller',
'group' => 'init',
},
'UpdateInstaller' => {
'next' => 'DowInstaller',
'group' => 'UpdateInstaller',
},
'DowInstaller' => {
'next' => 'SetupInstaller',
'group' => 'UpdateInstaller',
},
'SetupInstaller' => {
'next' => 'end',
'group' => 'UpdateInstaller',
},
'end' => {
'next' => '',
'group' => 'init',
},
};
}
sub initLang {
my $self = shift;
$self->{objLANG} = RVSInstaller::Language->new(
'Path' => $self->{InstallConf}{'ThisPath'} . '/lang',
'Language' => 'en',
'GlobalFile' => 'global',
'GlobalFileType' => 'ini.php',
'LangFile' => 'autoinstaller',
'LangFileType' => 'ini',
);
return $self->{objLANG};
}
sub initTemplate {
my $self = shift;
$self->{template} = RVSInstaller::Template->new(
masterTemplate => 'index.htm',
%{$self->{initValue}->{template}},
output => {
INS_PHP_FILE_TYPE => $INS_PHP_FILE_TYPE,
INS_WEB_THEME_URL => $WEBROOT,
INS_WEB_ROOT => $WEBROOT,
INSTALLTITLE => $self->{INSTALLTITLE},
}
);
return $self->{template};
}
sub setInitTemplate {
my $self = shift;
my %param = @_;
$self->{initValue}->{template} = {%param};
}
#sub initData {
# my $self = shift;
#
# $SIG{'PIPE'} = 'IGNORE';
# $SIG{'HUP'} = 'IGNORE';
# $SIG{'ALRM'} = 'IGNORE';
#
# $| = 1;
#
# if ( $BROWSER == 0 && $> != 0 ) {
# print STDERR $0 . " must be ran as root".$NEWLINE.$NEWLINE;
# #exit(-1);
# }
#
# $self->{completedColor} = "\e[1m\e[36m";
# $self->{failedColor} = "\e[1m\e[31m";
#
# if ( $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="' . $WEBROOT . '/include/install.js.' . $INS_PHP_FILE_TYPE . '?installtitle='.$self->{INSTALLTITLE}.'" language="javascript" type="text/javascript"></script>';
# print "<body>\n";
## print $self->{template}->displayTemplate();
# $BROWSER = 1;
# }
# else {
# $BROWSER = 0;
# }
#
# if ( !-f $self->{InstallConf}{'ThisPath'} . "/.skipcheckroot") {
# my ($user) = RVSInstaller::Process::callBackticks("whoami");
# if ( $user ne "root\n" ) {
# $self->exitScript($self->{InstallConf}{'ThisPath'} . "/.skipcheckroot" . $self->{objLANG}->TranSlate("You must run this script as root else you may not have privileges to properly restore all files"));
# }
# }
#
# $| = 1;
#}
#sub loadvars{
# my $self = shift;
# $cmd_cp = whichCmd('cp');
# $cmd_mv = whichCmd('mv');
# $cmd_rm = whichCmd('rm');
# $cmd_mkdir = whichCmd('mkdir');
#
# $cmd_ln = whichCmd('ln');
# $cmd_rsync = whichCmd('rsync');
# $cmd_tar = whichCmd('tar');
#
# $cmd_replace = whichCmd('replace');
# $cmd_uname = whichCmd('uname');
# $cmd_df = whichCmd('df');
# $cmd_chmod = whichCmd('chmod');
#
# $cmd_replace = whichCmd('replace');
# $cmd_echo = whichCmd('echo');
# $cmd_lsattr = whichCmd('lsattr');
# $cmd_cat = whichCmd('cat');
# $cmd_date = whichCmd('date');
# $cmd_locale = whichCmd('locale');
# $cmd_localedef = whichCmd('localedef');
# $cmd_uname = whichCmd('uname');
# $cmd_perl = whichCmd('perl');
#}
#sub Validate {
# my $self = shift;
# my (%FORM, $INPUT, $callAction);
# if ( $BROWSER ) {
# %FORM = RVSInstaller::Process::ParseForm();
# if (%FORM) {
# $nextScriptParam = '?';
# my ($insertAnd);
# foreach my $key (keys %FORM) {
# next if ($FORM{$key} =~/^$/gi);
# $nextScriptParam .= $insertAnd . $key . "=" . $FORM{$key};
# $insertAnd = '&';
# }
# }
# } else {
# %FORM = RVSInstaller::Process::ParseOpt();
# if (%FORM) {
# $nextScriptParam = ' ';
# my ($insertAnd);
# foreach my $key (keys %FORM) {
#
# next if ($FORM{$key} =~/^$/gi && ($key ne 'force' ||$key ne 'help'));
# if ($key ne 'force') {
# $nextScriptParam .= $insertAnd . "-" . $key . "=" . $FORM{$key};
# } else {
# $nextScriptParam .= $insertAnd . "--force";
# }
# $insertAnd = ' ';
# }
# }
# }
#
# if ($FORM{'debug'} eq 'ENV') {
# foreach my $key (keys %ENV) {
# print "\$ENV{'" . $key . "'} = " . $ENV{$key} . "<br />\n";
# }
# 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;
# }
# }
# #'/var/cpanel/rvglobalsoft/.rvsitebuilder/.getlatestversion'
# #TODO แก้ rvsitebuilder
# if (-f $self->{InstallConf}{'Installation'}{$self->{InstallConf}{'cpMode'}}{'companyPath'} . '/.rvsitebuilder/.getlatestversion') {
# my (%hParam);
# if ($INPUT) {
# %hParam = %{$INPUT};
# $hParam{'getversion'} = 'latest';
# $INPUT = \%hParam;
# }
# else {
# $hParam{'getversion'} = 'latest';
# $INPUT = \%hParam;
# }
# }
#
# if ( $FORM{'getversion'}) {
# my (%hParam);
# if ($INPUT) {
# %hParam = %{$INPUT};
# $hParam{'getversion'} = $FORM{'getversion'};
# $INPUT = \%hParam;
# }
# else {
# $hParam{'getversion'} = $FORM{'getversion'};
# $INPUT = \%hParam;
# }
# }
#
# if ( $FORM{'force'}) {
# my (%hParam);
# if ($INPUT) {
# %hParam = %{$INPUT};
# $hParam{'force'} = 1;
# $INPUT = \%hParam;
# }
# else {
# $hParam{'force'} = 1;
# $INPUT = \%hParam;
# }
# }
#
# my ($callFunc) = $callAction . $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->{FuncConf}->{$self->{ACTION}}->{'next'};
# my ($nextGroup) = $self->{FuncConf}->{$nextFunc}->{'group'} ;
# if ( $BROWSER ) {
# if ( "$nextFunc" ne "$self->{ACTION}" && "$self->{ACTION}" ne 'begin') {
# RVSInstaller::ScreenControl::jsChangeImg($self->{ACTION}, '2');
# RVSInstaller::ScreenControl::jsChangeArrow($self->{ACTION}, '1');
# RVSInstaller::ScreenControl::jsSetFontColor('msg' . $self->{ACTION}, '#7CABC1');
# RVSInstaller::ScreenControl::jsSetFontColor('subMsg' . $self->{ACTION}, '#7CABC1');
# RVSInstaller::ScreenControl::jsSetFontWeight('msg' . $self->{ACTION}, 'normal');
# RVSInstaller::ScreenControl::jsSetFontWeight('subMsg' . $self->{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($self->{objLANG}->TranSlate("Please wait") . ' ...', '', 'subMsg' . $nextFunc);
# }
# }
#
# if ( $self->{FuncConf}->{$nextFunc}->{'group'} ne $self->{FuncConf}->{$self->{ACTION}}->{'group'}) {
# if ( $self->{FuncConf}->{$self->{ACTION}}->{'group'} ne 'init') {
# RVSInstaller::ScreenControl::jsChangeSta($self->{FuncConf}->{$self->{ACTION}}->{'group'}, '1');
# }
# }
# }
# my ($callNext) = 'Process_' . $nextFunc;
# $self->{ACTION} = $nextFunc;
# if ($self->can($callNext)) {
# eval($self->$callNext($param));
# if ($@) {
# print $@;
# }
# } else {
# print "Not Found method $callNext\n" if ( $DEBUG );;
# }
# exitScript();
#}
#
##TODO xxx
#
#sub exitScript {
# my $self = shift;
# my ($exitMsg) = $_[0];
# RVSInstaller::ScreenControl::DisplayMsg($exitMsg, 1, 'ErrorDisplay');
# if ( $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->{objLANG}->TranSlate("is not compiled");
# }
#
# my ($SSLresult, %headers);
# eval {
# local $SIG{ALRM} = sub { return $self->{objLANG}->TranSlate("Connection Timeout"); };
# alarm 15;
# ($page, $SSLresult, %headers) = Net::SSLeay::get_https($domain , $port, $request) or return 'Error : ' . $!;
# alarm 0;
# };
# }
# else {
#
# $SIG{'PIPE'} = $SIG{'ALRM'} = sub {
# print "Unable to retrieve file\n";
# die;
# };
# # <-- Port 80 -->
# my $poto = getprotobyname('tcp');
#
# my $ipaddr = inet_aton($domain);
# if (!defined ($ipaddr)) {
# return $self->{objLANG}->TranSlate("Get protocal by hostname failed") . '.';
# }
#
# socket(SOCKET, AF_INET, SOCK_STREAM, $poto) or sub { return "socket error" . ": $!"; };
#
# $port = getservbyname( 'http', 'tcp' );
# my $sin = sockaddr_in($port, $ipaddr);
#
# connect (SOCKET, $sin) or sub { return $self->{objLANG}->TranSlate("Cannot create socket connection to") . ' ' . $domain . '.'; };
# #send SOCKET, "GET " . $request . " HTTP/1.0\n\n", 0;
# send SOCKET, "GET $request HTTP/1.0\r\nHost: $domain\r\n\r\n", 0;
# my $inheaders = 1;
# my $httpStatus;
# my ($pages) = '';
# while (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->{objLANG}->TranSlate('Sorry cannot connection to xxx please following it', $domain, $port);
# }
#}
#
#sub whichCmd {
# my ($cmd) = $_[0];
# return if ($cmd eq '');
# return if ($cmd =~/\//);
#
# my $whichCmd = '';
# my $binpath = '';
# my @binpathList = (
# '/bin',
# '/usr/bin',
# '/usr/local/bin',
# '/sbin',
# '/usr/sbin',
# '/usr/local/sbin'
# );
#
# foreach my $path(@binpathList) {
# if ( -x $path . '/' . 'which') {
# $whichCmd = $path . '/' . 'which';
# last;
# }
# }
# if ($whichCmd eq '') {
# RVSInstaller::ScreenControl::DisplayMsg(1, '', 'which command is not support.');
# RVSInstaller::ScreenControl::LogMsg('which command is not support.');
# return $binpath;
# }
#
# $binpath = callBackticks("$whichCmd $cmd");
# chomp ($binpath);
# $binpath =~s/\n|\r//gi;
#
# if ($binpath eq '' || $binpath=~/null/) {
# foreach my $path(@binpathList) {
# if ( -x $path . '/' . $cmd) {
# $binpath = $path . '/' . $cmd;
# last;
# }
# }
# }
#
# if ($binpath eq '') {
# RVSInstaller::ScreenControl::DisplayMsg(1, '', $cmd . ' is not support.');
# RVSInstaller::ScreenControl::LogMsg($cmd . ' is not support.');
#
# } elsif (!-x $binpath) {
# RVSInstaller::ScreenControl::DisplayMsg(1, '', $cmd . ' is not executeable.');
# RVSInstaller::ScreenControl::LogMsg($cmd . ' is not executeable.');
# }
#
# return $binpath;
#}
#
#sub callBackticks {
# my $cmd = $_[0];
# if (-f '/tmp/.rvsBackticks') {
# system('rm -f /tmp/.rvsBackticks');
# }
#
# system("$cmd > /tmp/.rvsBackticks");
# my ($resuft);
# if (-f '/tmp/.rvsBackticks') {
# my ($fd);
# open($fd, '<', '/tmp/.rvsBackticks');
# $resuft = join('',<$fd>);
# close($fd);
# system('rm -f /tmp/.rvsBackticks');
# } else {
# $resuft = `$cmd`;
# }
# return $resuft;
#}
1;
__END__
Copyright 2K16 - 2K18 Indonesian Hacker Rulez