#!/usr/bin/perl
package RVL::Session;
# 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 CGI::Session;
use CGI;
use vars qw( %STATIC );
use define 'SGL_SESSION_UPDATE_WINDOW' => 10;
use Class::Std::Utils;
{
sub new {
my ($class, $opt) = @_;
my ($this) = bless( {}, $class);
my ($cgi) = new CGI;
my ($sessionName) = (RVL::Config::singleton()->get('cookie.name')) ? RVL::Config::singleton()->get('cookie.name') : 'RVLSESSID';
$sessionName = ($sessionName) ? $sessionName : 'RVLSESSID';
CGI::Session->name($sessionName);
my ($session) = new CGI::Session(undef, $cgi, {Directory=> RVL::CpHandle::singleton()->getHomeDir() . '/tmp'});
#$session->expire('+1M');
return $session;
}
sub singleton {
my ($class) = __PACKAGE__;
if (!defined $RVL::INSTANCE{$class}) {
$RVL::INSTANCE{$class} = $class->new();
}
return $RVL::INSTANCE{$class}
}
sub isFirstAnonRequest {
my ($clean) = @_;
#$RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'}
if (defined $clean) {
RVL::Session::singleton()->clear('isFirstAnonRequest');
if (defined $RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'}) {
delete $RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'};
}
return 1;
} elsif (RVL::Session::getRoleId() eq __CONSTANT__::RVL_GUEST
&& !defined $RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'}) {
$RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'} = !defined(RVL::Session::singleton()->param('isFirstAnonRequest'));
if (!defined(RVL::Session::singleton()->param('isFirstAnonRequest'))) {
RVL::Session::singleton()->param(-name => 'isFirstAnonRequest', -value => 1);
}
return defined($RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'})
? $RVL::Session::STATIC{'isFirstAnonRequest'}{'ret'}
: 0;
}
}
sub getRoleId {
if (RVL::Session::singleton()->param('rid')) {
return RVL::Session::singleton()->param('rid');
} else {
return '';
}
}
sub get {
my ($sessVarName) = $_[0];
return RVL::Session::singleton()->param($sessVarName);
}
=head3
RVL::Session::set({-name => value});
=cut
sub set {
my ($sessVarName, $sessVarValue) = @_;
RVL::Session::singleton()->param($sessVarName, $sessVarValue);
}
sub remove {
my ($sess) = $_[0];
RVL::Session::singleton()->clear($sess);
}
sub updateIdle {
my ($ret) = 0;
if (!RVL::Session::isTimedOut()) {
my ($time) = time();
my ($lastRefreshed) = defined(RVL::Session::singleton()->param('lastRefreshed'))
? RVL::Session::singleton()->param('lastRefreshed')
: 0;
my ($timeIdle) = $time - $lastRefreshed;
if ($timeIdle gt __CONSTANT__::RVL_SESSION_UPDATE_WINDOW ) {
RVL::Session::singleton()->param(-name => 'lastRefreshed', -value => time());
}
$ret = 1;
}
return $ret;
}
sub isTimedOut{
my ($currentTime) = time();
my ($lastPageRefreshTime) = defined(RVL::Session::singleton()->param('lastRefreshed'))
? RVL::Session::singleton()->param('lastRefreshed')
: 0;
my ($timeout) = defined(RVL::Session::singleton()->param('aPrefs.sessionTimeout'))
? RVL::Session::singleton()->param('aPrefs.sessionTimeout')
: 0;
if ($timeout eq 0) {
return 0;
}
my ($useTime) = $currentTime - $lastPageRefreshTime;
if ($useTime gt $timeout) {
return 1;
} else {
return 0;
}
}
sub isAnonymous {
if (defined RVL::Session::singleton()->param('uid')) {
return 0;
} else {
return 1;
}
}
}
1;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez