#!/usr/bin/perl
##LICENSE##
package RVSInstaller::Config;
use strict;
use warnings;
use Carp;
use File::Basename qw(&basename &dirname);
use vars qw( $VERSION );
$VERSION = "0.01";
sub new {
my ($class, %args) = @_;
my $self = {
programName => '',
companyName => 'rvglobalsoft',
%args,
};
croak "__PACKAGE__ Constructor require 'programName' parameter to create object" if (!defined($self->{'programName'}));
bless $self, $class;
$self->initConfig();
return $self;
}
#sub import {
# my $caller = caller;
# eval "use $caller;"; # let them finish loading
# foreach my $i (grep { defined &{$_} } keys %{__PACKAGE__.'::'}) {
# die __PACKAGE__ . " is listed as a base type in $caller, but the $i method is not implemented!"
# unless defined &{$caller.'::'.$i};
# }
#}
sub initConfig {
my $self = shift;
#DEFAULT CONFIG
if ( $ENV{'HTTP_USER_AGENT'} ) {
$self->{'NEWLINE'} = "<br />\n";
$self->{'BROWSER'} = 1;
my $webroot = $ENV{'SCRIPT_URI'} ? $ENV{'SCRIPT_URI'} : $ENV{'SCRIPT_NAME'};
$webroot = dirname($webroot);
$self->{'WEBROOT'} = ($webroot !~/^\//i) ? '/' . $webroot : $webroot;
} else {
$self->{'NEWLINE'} = "\n";
$self->{'BROWSER'} = 0;
$self->{'WEBROOT'} = ''
}
$self->{'MONS'} = {
'0' => 'Jan',
'1' => 'Feb',
'2' => 'Mar',
'3' => 'Apr',
'4' => 'May',
'5' => 'Jun',
'6' => 'Jul',
'7' => 'Aug',
'8' => 'Sep',
'9' => 'Oct',
'10' => 'Nov',
'11' => 'Dec',
};
$self->{'funcConf'} = {
'begin' => {
'next' => 'UpdateInstaller',
'group' => 'init',
},
'UpdateInstaller' => {
'next' => 'DownloadInstaller',
'group' => 'UpdateInstaller',
},
'DownloadInstaller' => {
'next' => 'SetupInstaller',
'group' => 'UpdateInstaller',
},
'SetupInstaller' => {
'next' => 'end',
'group' => 'UpdateInstaller',
},
'end' => {
'next' => '',
'group' => 'init',
},
};
# START INIT INSTALL CONFIG
my ($CPMODE) = "Nocp";
if (-e "/usr/local/cpanel/cpkeyclt") {
$CPMODE = "Cpanel";
} elsif (-e "/etc/psa/psa.key") {
$CPMODE = "Plesk";
} elsif (-e "/usr/local/directadmin/conf/license.key") {
$CPMODE = "Directadmin";
} else {
$CPMODE = "Nocp";
}
$self->{'installConf'}->{'companyPath'} = sprintf('/usr/local/%s', $self->{'companyName'});
$self->{'installConf'}->{'thisPath'} = sprintf('%s/%s', $self->{'installConf'}->{'companyPath'}, $self->{'programName'});
$self->{'installConf'} = {
'companyPath' => sprintf('/usr/local/%s', $self->{'companyName'}),
'thisPath' => sprintf('%s/%s', $self->{'installConf'}->{'companyPath'}, $self->{'programName'}),
'RVSInstaller' => sprintf('%s/%s', $self->{'installConf'}->{'thisPath'}, 'RVSInstaller'),
'sourcePath' => sprintf('%s/%s', $self->{'installConf'}->{'thisPath'}, 'sources'),
'packagePath' => sprintf('%s/%s', $self->{'installConf'}->{'thisPath'}, 'packages'),
'includePath' => sprintf('%s/%s', $self->{'installConf'}->{'thisPath'}, 'include'),
'libPath' => sprintf('%s/lib', $self->{'installConf'}->{'companyPath'}),
'SiteConf' => {
'license' => {
'address' => {
'site1' => 'license.rvglobalsoft.com',
'site2' => 'license.rvglobalsoft.com',
},
'uri' => {
'site1' => '/licensemgr/license/getlicense/',
'site2' => '/licensemgr/license/getlicense/',
},
},
'license2' => {
'address' => {
'site1' => 'license2.rvglobalsoft.com',
'site2' => 'license2.rvglobalsoft.com',
},
'uri' => {
'site1' => '/getinfo/rvlogin/rvcode/',
'site2' => '/getinfo/rvlogin/rvcode/',
},
},
'licensekey' => {
'address' => {
'site1' => 'license.rvglobalsoft.com',
'stie2' => 'license.rvglobalsoft.com',
},
'uri' => {
'site1' => '/licensemgr/license/genlicense/',
'site2' => '/licensemgr/license/genlicense/',
},
},
'download' => {
'address' => {
'site1' => 'download.rvglobalsoft.com',
'site2' => 'download.rvglobalsoft.com',
},
'uri' => {
'site1' => '/download.php',
'site2' => '/download.php',
},
},
},
'Packages' => {
'rvmanager-upgrade' => {
'ProductName' => 'RVManager Installer',
'ProductCode' => 'rvmanager-upgrade',
'SaveFilename' => 'rvmanagerauto.tar.bz2',
'auto' => {
'installer' => 'autorvmanager',
'real' => 'real_autorvmanager',
}
},
'rvmanager-package' => {
'ProductName' => 'RVManager',
'ProductCode' => 'rvmanager-package',
'SaveFilename' => 'rvmanager.tar.bz2',
},
},
'LicenseReqFile' => 'license-req.txt',
'cpMode' => $CPMODE,
};
if ($self->{'installConf'}->{'cpMode'} eq 'Cpanel') {
$self->{'INS_PHP_FILE_TYPE'} = 'php';
$self->{'INS_CGI_FILE_TYPE'} = 'cgi';
} elsif ($self->{'installConf'}->{'cpMode'} eq 'Plesk') {
$self->{'INS_PHP_FILE_TYPE'} = 'raw';
$self->{'INS_CGI_FILE_TYPE'} = 'raw';
if ($self->{'BROWSER'}) {
$self->{'WEBROOT'} = sprintf('http://%s:2222/CMD_PLUGINS_ADMIN/%s', $ENV{'HOSTNAME'}, $self->{'programName'});
}
} else {
$self->{'INS_PHP_FILE_TYPE'} = 'php';
$self->{'INS_CGI_FILE_TYPE'} = 'cgi';
}
# END INIT INSTALL CONFIG
}
sub isBrowser {
my $self = shift;
return $self->{'BROWSER'};
}
sub setAllFunctionConfig {
my ($self, $func) = @_;
$self->{'funcConf'} = {
%{$func},
}
}
sub setFunctionConfig {
my $self = shift;
my $keysFunc = shift;
my $valFunc = shift;
if ($keysFunc =~ m/[\w_]+\.[\w_]+/i) {
my $data = $self->_buildKeyConfig($keysFunc, $valFunc);
my $firstkey = (keys %{$data})[0];
$self->{'funcConf'}->{$firstkey} = $self->_addKeytoConfig(\$self->{'funcConf'}->{$firstkey}, $data->{$firstkey});
} else {
$self->{'funcConf'}->{$keysFunc} = $valFunc;
}
}
sub getFunctionConfig {
my $self = shift;
my $keysFunc = shift;
my $keyData = {};
if ($keysFunc =~ m/[\w_]+\.[\w_]+/i) {
my $data = $self->_buildKeyConfig($keysFunc, '');
$keyData = $self->_getKeyFromConfig(\$self->{'funcConf'}, $data);
} else {
$keyData = $self->{'funcConf'}->{$keysFunc};
}
return $keyData;
}
sub _buildKeyConfig {
my $self = shift;
my $remain = shift;
my $value = shift;
my ($key, $remainder) = split('\.', $remain, 2);
if ($remainder) {
return { $key => $self->_buildKeyConfig($remainder, $value) };
} else {
return { $key => $value };
}
}
sub _addKeytoConfig {
my $self = shift;
my $defaultref = shift;
my $newdata = shift;
my $default = $$defaultref;
foreach my $key (keys %{$newdata}) {
if (ref($newdata->{$key}) eq 'HASH') {
$default->{$key} = $self->_addKeytoConfig(\$default->{$key}, $newdata->{$key})
} else {
$default->{$key} = $newdata->{$key};
}
}
return $default;
}
sub _getKeyFromConfig {
my $self = shift;
my $defaultref = shift;
my $searchdata = shift;
my $default = $$defaultref;
my $returndata = '';
foreach my $key (keys %{$searchdata}) {
if (ref($searchdata->{$key}) eq 'HASH') {
$returndata = $self->_getKeyFromConfig(\$default->{$key}, $searchdata->{$key})
} else {
$returndata = $default->{$key};
}
}
return $returndata;
}
sub setInstallConfig {
my $self = shift;
my $keysFunc = shift;
my $valFunc = shift;
if ($keysFunc =~ m/[\w_]+\.[\w_]+/i) {
my $data = $self->_buildKeyConfig($keysFunc, $valFunc);
my $firstkey = (keys %{$data})[0];
$self->{'installConf'}->{$firstkey} = $self->_addKeytoConfig(\$self->{'installConf'}->{$firstkey}, $data->{$firstkey});
} else {
$self->{'installConf'}->{$keysFunc} = $valFunc;
}
}
sub getInstallConfig {
my $self = shift;
my $keysFunc = shift;
my $keyData = {};
if ($keysFunc =~ m/[\w_]+\.[\w_]+/i) {
my $data = $self->_buildKeyConfig($keysFunc, '');
$keyData = $self->_getKeyFromConfig(\$self->{'installConf'}, $data);
} else {
$keyData = $self->{'installConf'}->{$keysFunc};
}
return $keyData;
}
sub setInstallPackage {
my $self = shift;
my $keysFunc = shift;
my $valFunc = shift;
if ($keysFunc !~ m/^Packages\./) {
$keysFunc = sprintf('Packages.%s', $keysFunc);
}
$self->setInstallConfig($keysFunc, $valFunc);
}
sub getInstallPackage {
my $self = shift;
my $keysFunc = shift;
my $keyData = {};
if ($keysFunc !~ m/^Packages\./) {
$keysFunc = sprintf('Packages.%s', $keysFunc);
}
$keyData = $self->getInstallConfig($keysFunc);
return $keyData;
}
sub setInstallLicenseKey {
my $self = shift;
my $keysFunc = shift;
my $valFunc = shift;
if ($keysFunc !~ m/^LicenseKey\./) {
$keysFunc = sprintf('LicenseKey.%s', $keysFunc);
}
$self->setInstallConfig($keysFunc, $valFunc);
}
sub getInstallLicenseKey {
my $self = shift;
my $keysFunc = shift;
my $keyData = {};
if ($keysFunc !~ m/^LicenseKey\./) {
$keysFunc = sprintf('LicenseKey.%s', $keysFunc);
}
$keyData = $self->getInstallConfig($keysFunc);
return $keyData;
}
sub setInstallLicenseReqFile {
my $self = shift;
my $keysFunc = shift;
my $valFunc = shift;
if ($keysFunc !~ m/^LicenseReqFile\./) {
$keysFunc = sprintf('LicenseReqFile.%s', $keysFunc);
}
$self->setInstallConfig($keysFunc, $valFunc);
}
sub getInstallLicenseReqFile {
my $self = shift;
my $keysFunc = shift;
my $keyData = {};
if ($keysFunc !~ m/^LicenseReqFile\./) {
$keysFunc = sprintf('LicenseReqFile.%s', $keysFunc);
}
$keyData = $self->getInstallConfig($keysFunc);
return $keyData;
}
### NEED CLEANUP
#
#%InstallConf = (
# 'Packages' => {
# 'rvsitebuilder-lite' => {
# 'md5log' => 'rvsitebuilder.md5',
# 'ProductName' => 'RVSiteBuilder Lite',
# 'ProductCode' => 'rvsitebuilder4-lite',
# 'SaveFilename' => 'rvsitebuilder.tar.bz2',
# },
# 'rvsitebuilder-pro' => {
# 'md5log' => 'rvsitebuilder_pro.md5',
# 'ProductName' => 'RVSiteBuilder Pro',
# 'ProductCode' => 'rvsitebuilder4-pro',
# 'SaveFilename' => 'rvsitebuilder-pro.tar.bz2',
# },
# 'rvsitebuilder-template-lite' => {
# 'md5log' => 'rvsitebuildergraphic.md5',
# 'ProductName' => 'Template for RVSiteBuilder Lite',
# 'ProductCode' => 'rvsitebuilder4-template-lite',
# 'SaveFilename' => 'rvstemplate.tar.bz2',
# },
# 'rvsitebuilder-template-pro' => {
# 'md5log' => 'rvsitebuildergraphic_pro.md5',
# 'ProductName' => 'Template for RVSiteBuilder Pro',
# 'ProductCode' => 'rvsitebuilder4-template-pro',
# 'SaveFilename' => 'rvstemplate-pro.tar.bz2',
# },
# 'rvsitebuilder-upgrade' => {
# 'ProductName' => 'RVSiteBuilder Installer',
# 'ProductCode' => 'rvsitebuilder4-upgrade',
# 'SaveFilename' => 'rvsitebuilderinstaller.tar',
# },
# },
# 'LicenseKey' => {
# 'rvsitebuilder-lite' => 'rvsitebuilder.lic',
# 'rvsitebuilder-pro' => 'rvsitebuilder-pro.lic',
# },
# 'LicenseReqFile' => 'license-req.txt',
#);
#
###################### START CPANEL
#if ( $InstallConf{'cpMode'} eq 'cpanel' ) {
#$INS_PHP_FILE_TYPE = 'php';
#$INS_CGI_FILE_TYPE = 'cgi';
## <-- cPanel Config -->
#$InstallConf{'Installation'}{'cpanel'}{'root'} = '/var/cpanel';
##/var/cpanel/rvglobalsoft
#$InstallConf{'Installation'}{'cpanel'}{'companyPath'} = $InstallConf{'Installation'}{'cpanel'}{'root'} . '/' . $InstallConf{'CompanyName'};
#$InstallConf{'Installation'}{'cpanel'}{'programPath'} = $InstallConf{'Installation'}{'cpanel'}{'companyPath'} . '/' . $InstallConf{'ProgramName'};
#$InstallConf{'Installation'}{'cpanel'}{'TemplatePath'} = $InstallConf{'Installation'}{'cpanel'}{'programPath'};
#$InstallConf{'Installation'}{'cpanel'}{'ManagerPath'} = '/usr/local/cpanel/whostmgr/docroot/cgi';
#$InstallConf{'Installation'}{'cpanel'}{'UserInterface'} = '/usr/local/cpanel/base/3rdparty';
#$InstallConf{'Installation'}{'cpanel'}{'SkinPath'} = '/usr/local/cpanel/base/frontend/x';
#$InstallConf{'Installation'}{'cpanel'}{'ModulePath'} = '/usr/local/cpanel/Cpanel';
#$InstallConf{'Installation'}{'cpanel'}{'ModulePrem'} = oct("0644");
#
#if ( -e $InstallConf{'Installation'}{'cpanel'}{'programPath'} . '/www/setup.php') {
# $InstallConf{'Installation'}{'cpanel'}{'SetupWizardURL'} = $ENV{'cp_security_token'} . '/cgi/rvsitebuilder/setup.php';
# $InstallConf{'Installation'}{'cpanel'}{'clearCacheURL'} = $ENV{'cp_security_token'} . '/cgi/rvsitebuilder/index.php?/default/maintenance/action/clearCache/rvsautoclearcache/1';
#} else {
# $InstallConf{'Installation'}{'cpanel'}{'SetupWizardURL'} = $ENV{'cp_security_token'} . '/cgi/rvsitebuilder/index.php';
# $InstallConf{'Installation'}{'cpanel'}{'clearCacheURL'} = $ENV{'cp_security_token'} . '/cgi/rvsitebuilder/index.php?/maintenance/maintenance/action/clearCache/frmCache%5Bperms%5D/1/siteBuilderUpdate/1/submitted/1';
#}
#
#$InstallConf{'Installation'}{'cpanel'}{'InstallerFullPath'} = '/usr/local/cpanel/whostmgr/docroot/cgi/rvsitebuilderinstaller';
#$InstallConf{'Installation'}{'cpanel'}{'phpexecPath'} = '/usr/local/cpanel/3rdparty/bin/php';
#}
###################### END CPANEL
#
#
###################### START Directadmin
#if ( $InstallConf{'cpMode'} eq 'da' ) {
# $INS_PHP_FILE_TYPE = 'raw';
# $INS_CGI_FILE_TYPE = 'raw';
# my $URL = 'http://' . $ENV{'HOSTNAME'} .':2222/CMD_PLUGINS';
# $WEBROOT = 'http://' .$ENV{'HOSTNAME'} . ':2222/CMD_PLUGINS_ADMIN/rvsitebuilderinstaller';
#
# if ($ENV{'REQUEST_URI'}) {
# $BROWSER = 1;
# }
## <-- cPanel Config -->
#$InstallConf{'Installation'}{'da'}{'root'} = '/usr/local';
#$InstallConf{'Installation'}{'da'}{'companyPath'} = $InstallConf{'Installation'}{'da'}{'root'} . '/' . $InstallConf{'CompanyName'};
#$InstallConf{'Installation'}{'da'}{'programPath'} = $InstallConf{'Installation'}{'da'}{'companyPath'} . '/' . $InstallConf{'ProgramName'};
#$InstallConf{'Installation'}{'da'}{'TemplatePath'} = '/usr/local/directadmin/plugins/rvsitebuilder/images';
#$InstallConf{'Installation'}{'da'}{'ManagerPath'} = '/usr/local/rvglobalsoft/rvsitebuilderinstaller';
##not sure
#$InstallConf{'Installation'}{'da'}{'UserInterface'} = '/usr/local/cpanel/base/3rdparty';
#$InstallConf{'Installation'}{'da'}{'SkinPath'} = '/usr/local/cpanel/base/frontend/x';
#$InstallConf{'Installation'}{'da'}{'ModulePath'} = '/usr/local/cpanel/Cpanel';
#$InstallConf{'Installation'}{'da'}{'ModulePrem'} = oct("0644");
#
#if ( -e $InstallConf{'Installation'}{'da'}{'programPath'} . '/www/setup.raw') {
# $InstallConf{'Installation'}{'da'}{'SetupWizardURL'} = $URL . '/rvsitebuilder/setup.raw';
# $InstallConf{'Installation'}{'da'}{'clearCacheURL'} = $URL . '/rvsitebuilder/index.raw?/default/maintenance/action/clearCache/rvsautoclearcache/1';
#} else {
# $InstallConf{'Installation'}{'da'}{'SetupWizardURL'} = $URL . '/rvsitebuilder/index.raw';
# $InstallConf{'Installation'}{'da'}{'clearCacheURL'} = $URL . '/rvsitebuilder/index.raw?/maintenance/maintenance/action/clearCache/frmCache%5Bperms%5D/1/siteBuilderUpdate/1/submitted/1';
#}
#
#
#$InstallConf{'Installation'}{'da'}{'InstallerFullPath'} = '/usr/local/rvglobalsoft/rvsitebuilderinstaller';
#$InstallConf{'Installation'}{'da'}{'phpexecPath'} = '/usr/bin/php';
#}
###################### END Directadmin
#
##remove comment to view all constants
##print Dumper(%InstallConf);
#
#$InstallConf{'cpModeConfigPath'} = $InstallConf{'Installation'}{$InstallConf{'cpMode'}};
1;
__END__
Copyright 2K16 - 2K18 Indonesian Hacker Rulez