#!/usr/bin/perl
package RVL::LicenseCycle;
# WebSite: http://www.rvglobalsoft.com
# Unauthorized copying is strictly forbidden and may result in severe legal action.
# Copyright (c) 2013 RV Global Soft Co.,Ltd. All rights reserved.
#
# =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
# Copyright (c) 2013 RV Global Soft Co.,Ltd. All rights reserved.
# This Agreement is a legal contract, which specifies the terms of the license
# and warranty limitation between you and RV Global Soft Co.,Ltd. and RV2Factor Product for RV Global Soft.
# You should carefully read the following terms and conditions before
# installing or using this software. Unless you have a different license
# agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
# indicates your acceptance of the license and warranty limitation terms
# contained in this Agreement. If you do not agree to the terms of this
# Agreement, promptly delete and destroy all copies of the Software.
#
# ===== Grant of License =======
# The Software may only be installed and used on a single host machine.
#
# ===== Disclaimer of Warranty =======
# THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
# WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
# WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE
# AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
# FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE
# ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
# LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
# IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
# CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
# OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
# BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
# NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
# RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
# RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
# BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
# ===============================
use strict;
use warnings;
use Cwd qw'realpath cwd';
use File::Basename;
use File::Copy;
use IPC::Open3;
use RVL::Serialize ();
use MIME::Base64;
use Socket;
no strict 'subs';
use Class::Std::Utils;
{
sub new {
my ($class, $opt) = @_;
my $self = {};
$self->{timeNow} = time();
$self->{progName} = lc(RVL::Config::get('site.rvproduct'));
$self->{lcConfigFile} = __CONSTANT__::RVL_VAR_DIR.'/rvlicense.ini';
$self->{lcFile} = __CONSTANT__::RVL_VAR_DIR.'/license/'.$self->{progName}.'.lic';
$self->{lcConfig} = {};
bless $self, $class;
return $self;
}
sub checkFileConfigLicenseCycle {
my $self = shift;
my ($force) = @_;
return;
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
RVL::logMessage("Product Name: " . $self->{progName}, __CONSTANT__::RVL_LOG_DEBUG);
return if (!RVL::CpHandle::singleton->isRoot());
#Only ROOT can save file
my $checkTime = 0;
if (-e $self->{lcConfigFile}) {
$self->{lcConfig} = RVL::File::parse_ini_file($self->{lcConfigFile});
if (!defined($self->{lcConfig}->{'expire'})) {
$self->{lcConfig}->{'expire'} = 0;
}
if (defined($self->{lcConfig}->{'checktime'}) && int($self->{lcConfig}->{'checktime'}) > 0) {
$checkTime = $self->{lcConfig}->{'checktime'};
}
}
my $ctime = $checkTime - $self->{timeNow};
my $t24h = 86400; # 24 hours, 60*60*24
if ($checkTime <= $self->{timeNow} || !-e $self->{lcFile} || $force) {
RVL::logMessage('Cycle license now!', __CONSTANT__::RVL_LOG_DEBUG);
#getlicense /validate
my $data = RVL::LicenseCycle::checkLicenseInfo($self->{progName});
my $expireOn = 0;
if (!defined($self->{progName})) {
$expireOn = ($self->{lcConfig}->{'expire'} - $self->{timeNow}) / $t24h;
} elsif (defined($data->{'on error'}) && $data->{'on error'}) {
RVL::logMessage($data->{'error msg'}, __CONSTANT__::RVL_LOG_DEBUG);
undef $expireOn;
if (-e $self->{lcFile}) {
unlink($self->{lcFile});
}
} else {
$data = (defined($data->{$self->{progName}})) ? $data->{$self->{progName}} : {};
$self->{lcConfig}->{'expire'} = (defined($data->{'expire-date'})) ? $data->{'expire-date'} : 0;
$self->validateLicense($data, $force);
$expireOn = ($self->{lcConfig}->{'expire'} - $self->{timeNow}) / $t24h;
}
if (defined($expireOn) && $expireOn > 1) {
$self->{lcConfig}->{'checktime'} = $self->{timeNow} + $t24h;
} elsif (defined($expireOn) && $expireOn == 0) {
my $expSet = $data->{'expire-date'} - $self->{timeNow};
$self->{lcConfig}->{'checktime'} = int(($self->{timeNow} + ($expSet / 2)));
} else {
$self->{lcConfig}->{'checktime'} = $self->{timeNow};
}
if (!-e $self->{lcFile}) {
RVL::logMessage('Cannot locate license file.', __CONSTANT__::RVL_LOG_DEBUG);
}
$self->saveConfig();
}
}
sub checkLicenseInfo {
my $progName = shift;
my $url = 'license.rvglobalsoft.com';
my $rvcode = RVL::LicenseCycle::getrvcode($progName);
my $uri = '/licensemgr/license/getlicense/?rvcode='.$rvcode;
my $site = 'http://'.$url.$uri;
my $content = RVL::Net::getContentByUrl($site);
my $data = RVL::LicenseCycle::rvcodedecode(URI::Escape::uri_unescape($content));
return $data;
}
sub validateLicense {
my $self = shift;
my $data = shift;
my $force = shift;
$data->{'expire-date'} = (defined($data->{'expire-date'})) ? $data->{'expire-date'} : 0;
if ($data->{'expire-date'} <= $self->{timeNow}) {
if (-e $self->{lcFile}) {
unlink($self->{lcFile});
}
#date
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=(localtime($data->{'expire-date'}));
my $expiredate = sprintf("%02d/%02d/%04d", $mday, ($mon+1), ($year+1900));
RVL::logMessage(sprintf('Sorry, your license has been expired on %s.' . $expiredate), __CONSTANT__::RVL_LOG_DEBUG);
} else {
my $expireConf = (defined($self->{lcConfig}->{'expire'})) ? $self->{lcConfig}->{'expire'} : 0;
if ($expireConf ne $data->{'expire-date'} || !-e $self->{lcFile} || $force) {
RVL::logMessage("Not have file license", __CONSTANT__::RVL_LOG_DEBUG);
RVL::logMessage("force = 1", __CONSTANT__::RVL_LOG_DEBUG);
$self->getLicenseFile($data);
}
}
}
sub getLicenseFile {
my $self = shift;
my $data = shift;
my $host = 'license.rvglobalsoft.com';
my $rvcode = RVL::LicenseCycle::getrvcode($self->{progName});
my $uri = '/licensemgr/license/genlicense/?rvcode='.$rvcode;
my $saveAs = __CONSTANT__::RVL_VAR_DIR.'/tmp/'.$self->{progName}.'-lic.tar';
my $TARPATH = __CONSTANT__::RVL_VAR_DIR.'/tmp';
my $isSaveFile = 0;
my $site = 'http://'.$host.$uri;
my $content = RVL::Net::getContentByUrl($site);
my $filePointer;
if (defined($saveAs) && $saveAs ne '') {
if (!-e $TARPATH) {
mkdir($TARPATH, 0755);
}
if (-e $saveAs) {
unlink($saveAs);
}
if (open($filePointer, '>', $saveAs)) {
$isSaveFile = 1;
}
}
if ($isSaveFile) {
print $filePointer $content;
close($filePointer);
}
if (-s $saveAs) {
my $oldPath = cwd();
my $tarPath = dirname($saveAs);
chdir($tarPath);
#extract file
my $pid3 = open3(*CMD_IN, *CMD_OUT, *CMD_ERR, 'tar -xopf ' . $saveAs);
waitpid($pid3, 0);
close(CMD_IN);
my @errs = <CMD_ERR>;
close(CMD_ERR);
close(CMD_OUT);
my $licFile = '';
my $installFilePath = $self->{lcFile};
$licFile = $tarPath.'/'.$self->{progName}.'.lic';
if (-e $licFile) {
if (!-e dirname($installFilePath)) {
mkdir(dirname($installFilePath), 0755);
}
#copy file to program path
if (copy($licFile, $installFilePath)) {
unlink($licFile);
RVL::logMessage('Update license key has completed.', __CONSTANT__::RVL_LOG_DEBUG);
}
$self->{lcConfig}->{'expire'} = $data->{'expire-date'};
}
chdir($oldPath);
unlink($saveAs);
}
}
sub saveConfig {
my $self = shift;
RVL::logMessage('License cycle Save IP configuration. '.$self->{lcConfigFile}, __CONSTANT__::RVL_LOG_DEBUG);
my $saveData = {};
$saveData->{'expire'} = (defined($self->{lcConfig}->{'expire'}))
? $self->{lcConfig}->{'expire'}
: '';
$saveData->{'checktime'} = $self->{lcConfig}->{'checktime'};
RVL::File::write_ini_file($self->{lcConfigFile}, $saveData);
if (-e $self->{lcConfigFile} && -w $self->{lcConfigFile}) {
chmod(0777, $self->{lcConfigFile});
}
RVL::logMessage('License cycle Save IP configuration has been completed.', __CONSTANT__::RVL_LOG_DEBUG);
}
sub getrvcode {
my $progName = shift;
# primary-ip
# program
# all-ip
my %rvcode = ();
my $allIp = join(',', RVL::System::getIPList(1));
$rvcode{'timestamp'} = time();
$rvcode{'primary-ip'} = RVL::System::getIPList();
$rvcode{'program'} = $progName;
$rvcode{'all-ip'} = $allIp;
$rvcode{'cp'} = lc(RVL::CpHandle::singleton->getCpMode());
$rvcode{'vps'} = '';#RVL::LicenseCycle::isVps();
$rvcode{'license-code'} = RVL::LicenseCycle::getAdapterData();
$rvcode{'rand'} = int(rand(9000)) + 1000; #range: 1000-9999
#serialize data
return URI::Escape::uri_escape(RVL::LicenseCycle::rvcodeencode(\%rvcode));
}
sub getAdapterData {
#ioncube
my $page = '';
my $inifile = __CONSTANT__::RVL_PATH.'/modules/scripts/php.ini';
my $phpfile = __CONSTANT__::RVL_PATH.'/modules/scripts/ioncube.php';
if (-z $inifile && -z $phpfile) {
my $cmdIoncube = "php -c $inifile $phpfile 2>/dev/null";
$page = RVManager::callBackticks($cmdIoncube);
}
return $page;
}
sub isVps {
return '' unless $^O;
# use Sys::Detect::Virtualization;
#
# my $detector = eval { Sys::Detect::Virtualization->new({verbose => 0}) };
# return '' if( $@ );
#
# my @found = $detector->detect();
# if( @found ) {
# return 1;
# } else {
# return 0;
# }
}
sub rvcodeencode {
return MIME::Base64::encode(RVL::Serialize::serialize($_[0]));
}
sub rvcodedecode{
return RVL::Serialize::unserialize(MIME::Base64::decode($_[0]));
}
}
1;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez