File: //opt/cloudlinux/alt-php53/root/usr/share/pear/RVSeagullMod/lib/RVSGL/rvsLibs/User.php
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// WebSite: http://www.rvglobalsoft.com
// Unauthorized copying is strictly forbidden and may result in severe legal action.
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
//
// =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
// Copyright (c) 2006 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 RV Site Builder.
// 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.
// +---------------------------------------------------------------------------+
// $Id$
// +---------------------------------------------------------------------------+
/**
* RvSiteBuilder user(s) libary
*
* @package RvsLibs
* @author Pairote Manunphol <pairote@rvglobalsoft.com>
* @version $Revision$
* @since PHP 5.1
*/
if (class_exists('RvsLibs_User_Delete') === false) {
class RvsLibs_User_Delete
{
}
}
if (class_exists('RvsLibs_User_Set') === false) {
class RvsLibs_User_Set extends RvsLibs_User_Delete
{
/**
* Add now user id to database
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $username; If null it will be automatic find username
* @return stringReturn user Id
*/
public static function addnewUserId($username = null)
{
/// Get username :: BooM
$username = (is_null($username) === true)
? RvsLibs_User::getUsername()
: $username;
/// Generate ID :: BooM
$id = RvsLibs_String::genUniqueId();
/// Add id and username to database :: BooM
//fixed PHPMD scan 07/07/2554
if (class_exists('DaoFactory')) {
DaoFactory::Usr()->insertUsr($id, $username);
}
/// Return Id
return $id;
}
}
}
if (class_exists('RvsLibs_User_Get') === false) {
class RvsLibs_User_Get extends RvsLibs_User_Set
{
/**
* get ie version only
* is not ie return 0
* preg_match('/(Trident\/\d{1,2}).\d{1,2}/ims', $browser, $trident);
preg_match('/MSIE (.*?);/ims', $browser, $ie);
//$version = $ie[1]
//$trident = $trident[1]
*
* @param unknown $userAgent
* @return Ambigous <string, number>
* @author apiruk@rvglobalsoft.com
*/
public static function getIEversion($userAgent)
{
$browser = strtolower($userAgent);
SGL::logMessage('userAgent:' . $browser, PEAR_LOG_DEBUG);
$version = 0;
if (strpos($browser, 'msie 10') != false || strpos($browser, 'trident/6.0') != false) {
//ie 10 only
$version = 10;
} elseif (strpos($browser, 'rv:11.0') != false || strpos($browser, 'trident/7.0;') != false) {
//ie 11 only
$version = 11;
} elseif (RvsLibs_String::preg_match('/msie/ims', $browser)
&& RvsLibs_String::preg_match('/trident\/7\.0;/ims', $browser) == false) {
//ie 7 8 9
$ie_version = RvsLibs_String::preg_replace('/.*msie/sm', '', $browser);
$ie_version = substr($ie_version, 0, 4);
$version = intval($ie_version);
}
SGL::logMessage('version: ' . $version, PEAR_LOG_DEBUG);
return $version;
}
/**
* Get users status
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $rvsUserId; If null it will be automatic find user id
* @param string $rvsRootId; If null it will be automatic find ROOT id
* @param string $isReseller; Flag if this user is reseller
*
* @return string; Return root, reseller or user
*/
public static function getUserStatus($userId = null, $rootId = null, $isReseller = RVS_IS_RESELLER)
{
/// If user Id is null, call function getRvsUsrId for get user Id :: BooM
$userId = (is_null($userId) === false)
? $userId
: RvsLibs_User::getUserId();
/// If Riit Id is null, call function getRvsRootId for get root Id :: BooM
$rootId = (is_null($rootId) === false)
? $rootId
: RvsLibs_User::getRootId();
/// Set default status to user :: BooM
$userStatus = 'user';
if ($userId == $rootId) {
/// Set status to root :: BooM
// da = 'admin', cpanel = 'root'
$userStatus = RVS_ROOT_USER_NAME;
} elseif (($isReseller == '1')) {
/// Set status ti reseller :: BooM
$userStatus = 'reseller';
}
return $userStatus;
}
/**
* Get Username
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param bool $checkErrorMode; Flag if want to test error mode
*
* @return string; return PEAR::Error if not defined "RVS_USER_NAME"
*/
public static function getUsername($checkCPMode = false, $checkErrorMode = false)
{
if ( defined('RVS_USER_NAME') && $checkErrorMode === false) {
/// If define constant RVS_USER_NAME and not flag test error mode :: BooM
/* modify CpHandel by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
return $oCp;
}
return ($checkCPMode === true)
? $oCp->replateAtOnUserName(RVS_USER_NAME)
: RVS_USER_NAME;
} else {
/// If NOT define constant RVS_USER_NAME or not flag test error mode :: BooM
return SGL::raiseError(RvsLibs_String::translate('Not defined RVS_USER_NAME.'));
}
}
/**
* Get user Id
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @return string
*/
public static function getUserId()
{
if (!isset($GLOBALS['_SGL']['rvsUsrID'])) {
// getRvsUsrId function is called in all SiteBuilder modules except SiteBuilder
// So we check the custom permissionn (based on username) here
/// Find usr id by username :: BooM
$res = RvsLibs_User::findUserId();
/// If not found user add new user to database
/// , and set user id to GLOBALS :: BooM
$GLOBALS['_SGL']['rvsUsrID'] = (is_null($res) === false)
? $res
: RvsLibs_User::addnewUserId();
}
/// Return user Id
return $GLOBALS['_SGL']['rvsUsrID'];
}
/**
* Get ROOT Id
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $rootname
* @return string
*/
public static function getRootId($rootname = RVS_ROOT_USER_NAME)
{
if (!isset($GLOBALS['_SGL']['rvsRootID'])) {
/// Find root Id by root name :: BooM
$rootId = RvsLibs_User::findUserId($rootname);
/// return $rootId if found, but if not found root id (null).
/// Add new root name to database. :: BooM
$GLOBALS['_SGL']['rvsRootID'] = (is_null($rootId) === false)
? $rootId
: RvsLibs_User::addnewUserId($rootname);
}
return $GLOBALS['_SGL']['rvsRootID'];
}
/**
* find user id in database
*
* @param string $username; If null it will be automatic find username
* @return string; Return user Id,
* and return null if not found user id in database.
*/
public static function findUserId($username = null)
{
/// Get username :: BooM
$username = (is_null($username) === true)
? RvsLibs_User::getUsername()
: $username;
/// Find user id by username in database :: BooM
if (class_exists('DaoFactory')) {
$res = DaoFactory::Usr()->findUsrIdByUsername($username, 'getrow');
}
/// Return user id and if cannot found user id in database return null
return isset($res['rvs_usr_id'])
? $res['rvs_usr_id']
: null;
}
/**
* get user import template
*
* @return String
*/
public static function getUserImportTemplate()
{
$rootInternalPath = RVS_ROOT_HOME . '/.rvsitebuilder/internalimport.txt';
if (is_file($rootInternalPath) == true
&& (RvsLibs_User::getUserStatus() == 'root')) {
return 'internal';
} else {
return RvsLibs_User::getUserStatus();
}
}
/*
*
*
* if (!isset($GLOBALS['_SGL']['rvsUsrID'])) {
// getRvsUsrId function is called in all SiteBuilder modules except SiteBuilder
// So we check the custom permissionn (based on username) here
if (CPMODE != "tryout") {
//$this->checkAccountPerms();
}
/// Find usr id by username :: BooM
$res = RvsLibs_User::findUserId();
/// If not found user add new user to database
/// , and set user id to GLOBALS :: BooM
$GLOBALS['_SGL']['rvsUsrID'] = (is_null($res) === false)
? $res
: RvsLibs_User::addnewUserId();
}
*
*/
public static function getOwnerId($rvsOwnerName = RVS_OWNER_USER_NAME)
{
if (!isset($GLOBALS['_SGL']['rvsOwnerID'])) {
//fixed PHPMD scan 07/07/2554
//$rvsOwnerId = 0;
/// Find Owner id by Owner Name :: BooM
$res = DaoFactory::Usr()->findUsrIdByUsername($rvsOwnerName, 'getrow');
if ($res) {
// return owner_id
$GLOBALS['_SGL']['rvsOwnerID'] = $res['rvs_usr_id'];
} else {
$rvsUsrId = RvsLibs_String::genUniqueId();
/// Insert owner data :: BooM
$res = DaoFactory::Usr()->insertUsr($rvsUsrId, $rvsOwnerName);
// get rvs_owner_id;
$GLOBALS['_SGL']['rvsOwnerID'] = $rvsUsrId;
// return owner_id
}
}
return $GLOBALS['_SGL']['rvsOwnerID'];
}
public static function getUserNameById($usrId)
{
$res = DaoFactory::Usr()->findUsrByUsrId($usrId, 'getone', array('user_name'));
if (SGL::isError($res) === true) {
return SGL::raiseError(
RvsLibs_String::translate(
'Find user error : %MSG'
, 'vprintf'
, array('MSG' => $res->getMessage())
)
);
}
return $res;
}
/**
* List user's domain name
* @param $all
* 0 = get main domain, 1 = all domain.
*/
public static function getUserDNS($all = 0)
{
/*modify CpHandle by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
return $oCp;
/*
return SGL::raiseError(RvsLibs_String::translate('CpWaring %MESSAGE', 'vprintf', array('MESSAGE' => $oCp->getMessage())));
*/
}
return $oCp->getUserDNS($all);
}
public static function getPublishUrl()
{
return SGL_Session::get('publish_domain');
}
/**
* get WEB_THEME_PATH/userdata/{adminuser}
*/
public static function getAdminWWWPath($username = RVS_USER_NAME)
{
$path = WEB_THEME_PATH . '/userdata/' . $username;
SGL::logMessage($path, PEAR_LOG_DEBUG);
return $path;
}
}
}
if (class_exists('RvsLibs_User_Validate') === false) {
class RvsLibs_User_Validate extends RvsLibs_User_Get
{
/**
* This user is ROOT
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $username
* @return bool; Return TRUE if user is ROOT
* , and return FALSE if user is not ROOT
*/
public static function isRoot($username = RVS_USER_NAME)
{
/// Return true if username is root
/// and return false if username not root :: BooM
// optimize :nipaporn
return ($username === RVS_ROOT_USER_NAME) ? true : false;
}
/**
* Owner of user is ROOT
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $ownername
* @return bool; Return TRUE if owner of user is ROOT
* , and return FALSE if owner of user is RESELLER
*/
public static function ownerIsRoot($ownername = RVS_OWNER_USER_NAME)
{
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL_Error::pop();
return false;
}
return $oCp->ownerIsAdmin($ownername);
}
/**
* Owner of user is reseller
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $ownername
* @return bool; Return TRUE if owner of user is RESELLER
* , and return FLASE is owner of user is ROOT
*
*/
public static function ownerIsReseller($ownername = RVS_OWNER_USER_NAME)
{
/// Return false if owner name is root
/// and return true if owner name not root :: BooM
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL_Error::pop();
return false;
}
return ($oCp->ownerIsAdmin($ownername)) ? false : true;
}
/**
* Checks if the the user is can access to RVSiteBuilder
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $username; This a option for test mode.
* setting username for test.
*
* @param bool $testMode; This a option for test mode.
* Flag for test. It will be not die if raiseError.
*
* @param bool $ownerIsReseller; This a option for test mode.
* Do you want setting owner of user to reseller? (true|false)
*
* @param bool $notAllowWithResellerControlList; This a option for test mode.
* Do you want to disble reseller? (true|false)
*
* @param bool $notAllowWithUserControlList; This a option for test mode.
* Do you want to disble user? (true|false)
*
* @return bool; Return true if allow this user access to RVSiteBuilder
* , and return raiseError if not allow this user access to RVSiteBuilder
*/
public static function isAllowUserPerms($username = RVS_USER_NAME, $testMode = false,
$ownerIsReseller = null, $notAllowWithResellerControlList = null,
$notAllowWithUserControlList = null)
{
SGL::logMessage('rvdebug: user:' . $username . ' owner:' . RVS_OWNER_USER_NAME, PEAR_LOG_DEBUG);
/*modify CpHandle by nipaporn*/
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL_Error::pop();
return false;
}
if ($username === RVS_ROOT_USER_NAME || $oCp->isSkipAllowUserPerms()) {
/// allow if this user is root
return true;
}
$ownerIsReseller = (is_null($ownerIsReseller) === true)
? RvsLibs_User::ownerIsReseller()
: $ownerIsReseller;
$notAllowWithResellerControlList = (is_null($notAllowWithResellerControlList) === true)
? RvsLibs_User::isnotAllowWithResellerControlList()
: $notAllowWithResellerControlList;
$notAllowWithUserControlList = (is_null($notAllowWithUserControlList) === true)
? RvsLibs_User::isnotAllowWithUserControlList()
: $notAllowWithUserControlList;
/*
SGL::logMessage('rvdebug: RVS_IS_RESELLER:' . RVS_IS_RESELLER, PEAR_LOG_DEBUG);
SGL::logMessage('rvdebug: ownerIsReseller:' . $ownerIsReseller, PEAR_LOG_DEBUG);
SGL::logMessage('rvdebug: notAllowWithResellerControlList:' . $notAllowWithResellerControlList, PEAR_LOG_DEBUG);
SGL::logMessage('rvdebug: notAllowWithUserControlList:' . $notAllowWithUserControlList, PEAR_LOG_DEBUG);
*/
if (RVS_IS_RESELLER == 1
&& $notAllowWithResellerControlList === true) {
/// Return raiseError if owner of user is RESELLER
/// and ROOT is not allow this reseller name
/// in Reseller Control List configulation ::BooM
return SGL::raiseError(
RvsLibs_String::translate(
'access denied by owner control list.'
, 'vprintf'
, array('username' => $username)
)
, SGL_ERROR_INVALIDAUTH
, ($testMode === false) ? PEAR_ERROR_DIE : ''
);
}
if (RVS_IS_RESELLER != 1 && $notAllowWithUserControlList === true && RVS_USER_NAME != RVS_OWNER_USER_NAME) {
/// Return raiseError if owner of user (ROOT/RESELLER)
/// is NOT allow this user to access RVSiteBuilder
/// in User Control List configulation :: BooM
return SGL::raiseError(
RvsLibs_String::translate(
'access denied by user control list.'
, 'vprintf'
, array('username' => $username)
)
, SGL_ERROR_INVALIDAUTH
, ($testMode === false) ? PEAR_ERROR_DIE : ''
);
}
return true;
}
/**
* Is NOT allow user access to RVSiteBuilder with user control list
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $username
* @param string $ownerHomeDir
* @return bool; Return TRUE if owner of user NOT allow user to access RVSiteBuilder
* , and return FALSE if owner of user is allow user to access RVSiteBuilder.
* (in User Control List)
*/
public static function isnotAllowWithUserControlList($username = RVS_USER_NAME, $ownerHomeDir = RVS_OWNER_HOME)
{
SGL::logMessage('rvdebug: username:' . $username, PEAR_LOG_DEBUG);
/// Set RVSiteBuilder owner directory :: BooM
$prefixOwnerDir = RvsLibs_File::buildPath(
array($ownerHomeDir, '.rvsitebuilder')
);
/// Set file disable RVSiteBuilder toggle :: BooM
$disableToggleFile = RvsLibs_File::buildPath(
array($prefixOwnerDir, 'disablervsitebuilder.txt')
);
/// Set file RVSiteBuilder enable user list :: BooM
$enableListFile = RvsLibs_File::buildPath(
array($prefixOwnerDir, 'enablelist.txt')
);
/// Set file RVSiteBuilder disable user list :: BooM
$disableListFile = RvsLibs_File::buildPath(
array($prefixOwnerDir, 'disablelist.txt')
);
$isDisable = (RvsLibs_Config::getControlList(
$username
, $disableToggleFile
, $enableListFile
, $disableListFile
) === false) ? true : false;
SGL::logMessage('rvdebug: isDisable: ' . $isDisable, PEAR_LOG_DEBUG);
if ($isDisable === false
&& RVS_IS_RESELLER != 1
&& self::isnotAllowWithResellerControlList(RVS_OWNER_USER_NAME) === true) {
// check perm user only
// disable a reseller and clients under
SGL::raiseError(RvsLibs_String::translate('User access denied as inheritted from your reseller access disabled by admin', 'vprintf', array('username' => $username)), SGL_ERROR_INVALIDAUTH, PEAR_ERROR_DIE);
return true;
} else {
return $isDisable;
}
}
/**
* Is NOT allow reseller access to RVSiteBuilder whih reseller control list
*
* @author Parinya Chaipetch <parinya@rvglobalsoft.com>
*
* @param string $resellername
* @param string $rootHomeDir
* @return bool; Return TRUE if ROOT not allow reseller access to RVSiteBuilder
* , and return FALSE if root is allow reseller access to RVSiteBuilder
* (in Reseller Control List)
*/
public static function isnotAllowWithResellerControlList($resellername = RVS_USER_NAME, $rootHomeDir = RVS_ROOT_HOME)
{
/// Set RVSiteBuilder ROOT directory :: BooM
$prefixRootDir = RvsLibs_File::buildPath(
array($rootHomeDir, '.rvsitebuilder')
);
/// Set file disable all reseller access to RVSiteBuilder :: BooM
$disableToggleFileForReseller = RvsLibs_File::buildPath(
array($prefixRootDir, 'disablervsitebuilder_reseller.txt')
);
/// Set file reseller list can access to RVSiteBuilder :: BooM
$enableListFileForReseller = RvsLibs_File::buildPath(
array($prefixRootDir, 'enablelist_reseller.txt')
);
/// Set file reseller list con not access to RVSiteBuilder :: BooM
$disableListFileForReseller = RvsLibs_File::buildPath(
array($prefixRootDir, 'disablelist_reseller.txt')
);
return (RvsLibs_Config::getControlList(
$resellername
, $disableToggleFileForReseller
, $enableListFileForReseller
, $disableListFileForReseller
) === false) ? true : false;
}
public static function checkAccountPerms($ownerUserName = RVS_OWNER_USER_NAME)
{
$userName = RvsLibs_User::getUsername(true);
$a = RvsLibs_File::buildPath(
array(RVS_OWNER_HOME, '.rvsitebuilder', 'disablervsitebuilder.txt')
);
$b = RvsLibs_File::buildPath(
array(RVS_OWNER_HOME, '.rvsitebuilder', 'enablelist.txt')
);
$c = RvsLibs_File::buildPath(
array(RVS_OWNER_HOME, '.rvsitebuilder', 'disablelist.txt')
);
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL_Error::pop();
return false;
}
if ($oCp->ownerIsAdmin($ownerUserName)) {
RvsLibs_User::_checkPermsConfig($a,$b,$c);
} else {
//fixed PHPMD scan 07/07/2554
RvsLibs_User::checkResellerPerms(1);
if ($userName != RVS_OWNER_USER_NAME) {
RvsLibs_User::_checkPermsConfig($a,$b,$c);
}
}
return true;
}
public static function checkResellerPerms($checkReseller = null)
{
$a = RvsLibs_File::buildPath(
array(RVS_ROOT_HOME, '.rvsitebuilder', 'disablervsitebuilder_reseller.txt')
);
$b = RvsLibs_File::buildPath(
array(RVS_ROOT_HOME, '.rvsitebuilder', 'enablelist_reseller.txt')
);
$c = RvsLibs_File::buildPath(
array(RVS_ROOT_HOME, '.rvsitebuilder', 'disablelist_reseller.txt')
);
if (is_null($checkReseller) === true) {
RvsLibs_User::_checkPermsConfig($a, $b, $c);
} else {
RvsLibs_User::_checkPermsConfig($a, $b, $c, $checkReseller);
}
}
protected static function _checkPermsConfig($disableToggle, $enableList, $disableList, $checkReseller = 0)
{
$aEnableList = array();
$aDisableList = array();
$userName = RvsLibs_User::getUsername(true);
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
SGL_Error::pop();
return false;
}
if ($oCp->isAdmin($userName)) {
return true;
}
if (is_file($disableToggle)) {
if (is_file($enableList)) {
$aEnableList = RvsLibs_File::file($enableList);
if (SGL::isError($aEnableList) === true) {
return false;
} else {
//optimize:pharadol
for ($i = 0, $max = count($aEnableList); $i < $max; $i++) {
if (($checkReseller == 0 && RvsLibs_String::trim($aEnableList[$i]) == $userName) ||
($checkReseller == 1 && RvsLibs_String::trim($aEnableList[$i]) == RVS_OWNER_USER_NAME)) {
return true;
}
}
}
}
if ($checkReseller) {
SGL::raiseError(RvsLibs_String::translate('access denied by owner control list.', 'vprintf', array('username' => $userName)), SGL_ERROR_INVALIDAUTH, PEAR_ERROR_DIE);
} else {
SGL::raiseError(RvsLibs_String::translate('access denied by user control list.', 'vprintf', array('username' => $userName)), SGL_ERROR_INVALIDAUTH, PEAR_ERROR_DIE);
}
} else {
if (is_file($disableList)) {
$aDisableList = file($disableList);
if (SGL::isError($aDisableList) === true) {
return false;
} else {
//optimize:pharadol
for ($i = 0, $max = count($aDisableList); $i < $max; $i++) {
if (($checkReseller == 0 && RvsLibs_String::trim($aDisableList[$i]) == $userName)
|| ($checkReseller == 1 && RvsLibs_String::trim($aDisableList[$i]) == RVS_OWNER_USER_NAME)) {
if ($checkReseller) {
SGL::raiseError(
RvsLibs_String::translate(
'access denied by owner control list.'
, 'vprintf'
, array('username' => $userName)
)
, SGL_ERROR_INVALIDAUTH
, PEAR_ERROR_DIE
);
} else {
SGL::raiseError(
RvsLibs_String::translate(
'access denied by user control list.'
, 'vprintf'
, array('username' => $userName)
)
, SGL_ERROR_INVALIDAUTH
, PEAR_ERROR_DIE
);
}
}
}
}
}
}
return true;
}
public static function validateUserTemplateManager()
{
$usrTemplateMgr = RvsLibs_File::buildPath(
array(SGL_PATH, 'modules', 'sitebuilderpro', 'classes', 'UserTemplateManagerMgr.php')
);
if (RvsLibs_License::isLicensePro() === false ) {
return false;
} elseif ( file_exists($usrTemplateMgr) ) {
include_once $usrTemplateMgr;
} else {
return false;
}
$oUser = new UserTemplateManagerMgr();
if ( !$oUser->isImportTemplateRvsitebuilderPro() ) {
return false;
}
return true;
}
public static function validateAllowUserImportTemplate($isTest=false)
{
$userStatus = RvsLibs_User::getUserStatus();
// Validate User Import
if ( $userStatus == "user" && RvsLibs_User::validateUserTemplateManager() === false ) {
RvsLibs_String::translate(
SGL::raiseMsg('Sorry, User Import Template for sitebuilder PRO')
);
if ($isTest === false) {
SGL_HTTP::redirect(array('managerName' => 'sitebuilder'));
}
}
// Validate skip allow user import template
if ( $userStatus == "user" && !RvsLibs_Config::getOwnerConf('AllowUserImportTemplate')) {
RvsLibs_String::translate(
SGL::raiseMsg('Sorry, Admin skip import template.')
);
if ($isTest === false) {
SGL_HTTP::redirect(array('managerName' => 'sitebuilder'));
}
}
}
}
}
if (class_exists('RvsLibs_User') === false) {
class RvsLibs_User extends RvsLibs_User_Validate
{
public static function cleanFileTmpInHomeUser()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$pathRvsitebuilder = RVS_USER_HOME . '/.rvsitebuilder';
if ($handle = opendir($pathRvsitebuilder)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (preg_match_all('/^\.(.*?)\.in$|^\.(.*?)\.cpanelComplete$|^\.(.*?)\.out$/',$file,$aMatch)) {
$pathMatch = $pathRvsitebuilder . '/' . $aMatch[0][0];
@unlink($pathMatch);
}
if (preg_match_all('/^CPONIFRAME_(.*?)\.in$|^CPONIFRAME_(.*?)\.cpanelComplete$|^CPONIFRAME_(.*?)\.out$/',$file,$aMatch)) {
$pathMatch = $pathRvsitebuilder . '/' . $aMatch[0][0];
@unlink($pathMatch);
}
}
}
closedir($handle);
}
}
public static function cleanFileTmpInPublishPath($publishPath, $aIgnore = array())
{
if ($handle = opendir($publishPath)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && preg_match_all('/^[a-z0-9]{32,32}\.css$/',$file,$aMatch) && !in_array($file, $aIgnore)) {
$pathMatch = $publishPath . '/' . $aMatch[0][0];
@unlink($pathMatch);
}
}
closedir($handle);
}
}
/**
* clean RVS_USER_HOME/.rvsitebuilder/tmp
* clean RVS_USER_HOME/.rvsitebuilder/cache
* @return unknown_type
*/
public static function cleanTmpAndCacheUser()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
if (rand(1, 100) == 59) {
//clean tmp
$resTmp = RVS_USER_HOME . '/.rvsitebuilder/tmp';
if ( is_dir($resTmp) ) {
//$aTmpFiles = System::find("$resTmp -name *");
$sessId = 'sess_' . session_id();
//fixed PHPMD scan 07/07/2554
//$ignoreSessID = array($sessId)
$aFile = RvsLibs_System::ls(array('-a', $resTmp), array($sessId));
if (count($aFile['files'])) {
@System::rm($aFile['files']);
}
}
//clean cache
if (is_dir(RVS_USER_HOME.'/.rvsitebuilder/cache')) {
RvsLibs_System::rm(array('-rf', RVS_USER_HOME.'/.rvsitebuilder/cache'));
}
}
}
/**
* Check link is not symlink but it is Folder
* delete folder and create new symlink
*
* @param string $pathUserUpload
* @param string $pathUploadLink
* @return true/false
*/
public static function createUserSymlinkUserFolderDa($pathUserUpload, $pathUploadLink)
{
SGL::logMessage('pathUserUpload=' . $pathUserUpload .'|pathUploadLink=' . $pathUploadLink, PEAR_LOG_DEBUG);
//ปลายทางไม่ไม่ใช่ dir ให้สร้าง
//RVS_USER_HOME/.rvsitebuilder/upload
if (!is_dir($pathUserUpload)) {
$res = RvsLibs_System::mkDir(array('-p', $pathUserUpload));
if (SGL::isError($res) === true) {
echo 'Cannot create upload path ' . $res->getMessage();
exit;
}
}
//ต้นทางเป็น dir ให้ลบ
if (is_link($pathUploadLink)) {
RvsLibs_System::unlink(array($pathUploadLink));
}
if (!is_dir($pathUploadLink)) {
$res = RvsLibs_System::mkDir(array('-p', $pathUploadLink));
if (SGL::isError($res) === true) {
echo 'Cannot create upload path ' . $res->getMessage();
exit;
}
}
$path = SGL_USERDATA_PATH . '/' . RVS_USER_NAME;
if (is_dir($path) === false) {
RvsLibs_System::mkdir(array('-p',$path));
}
}
/**
* Check link is not symlink but it is Folder
* delete folder and create new symlink
*
* @param string $pathUserUpload
* @param string $pathUploadLink
* @return true/false
*/
public static function createUserSymlinkUserFolder($pathUserUpload, $pathUploadLink)
{
SGL::logMessage('pathUserUpload=' . $pathUserUpload .'|pathUploadLink=' . $pathUploadLink, PEAR_LOG_DEBUG);
//ปลายทางไม่ไม่ใช่ dir ให้สร้าง
//RVS_USER_HOME/.rvsitebuilder/upload
if (!is_dir($pathUserUpload)) {
$res = RvsLibs_System::mkDir(array('-p', $pathUserUpload));
if (SGL::isError($res) === true) {
echo 'Cannot create upload path ' . $res->getMessage();
exit;
}
}
//ถ้า link เป็น dir ให้ลบ
if (is_dir($pathUploadLink)) {
RvsLibs_System::rm(array('-rf',$pathUploadLink));
}
$path = SGL_USERDATA_PATH . '/' . RVS_USER_NAME;
if (is_dir($path) === false) {
RvsLibs_System::mkdir(array('-p',$path));
}
//สร้าง link ใหม่
if (!is_link($pathUploadLink)) {
return (symlink($pathUserUpload, $pathUploadLink)) ? true: false;
}
return false;
}
public static function getPrivilege()
{
if (isset($GLOBALS['isTest'])) {
if (SGL_Session::getRoleId() == 1) {
return 'Root';
} elseif (SGL_Session::getRoleId() == 2) {
return 'Reseller';
} else {
return 'User';
}
}
if (RVS_IS_ADMIN == 1) {
$privilege = 'Root';
} elseif (RVS_IS_RESELLER) {
$privilege = (self::isAdminGuiAllowed() === true) ? 'Reseller' : 'User';
} else {
$privilege = 'User';
}
SGL::logMessage('privilege = ' . strtolower($privilege) . ' UserName: ' . RVS_USER_NAME, PEAR_LOG_DEBUG);
return $privilege;
}
public static function isAdminGuiAllowed()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$c = SGL_Config::singleton();
$req = SGL_Request::singleton();
$moduleName = $req->getModuleName();
//load current module's config if not present
$conf = $c->ensureModuleConfigLoaded($moduleName);
$mgrName = SGL_Inflector::caseFix($req->getManagerName() . 'Mgr');
if ((isset($conf[$mgrName]['adminGuiAllowed'])
&& $conf[$mgrName]['adminGuiAllowed'])
|| (isset($conf[$mgrName]['userAndAdminGuiAllowed'])
&& $conf[$mgrName]['userAndAdminGuiAllowed'])) {
return true;
} else {
return false;
}
}
/**
* กรณีที่เครื่องไม่ต้องการเก็บ analytics ให้สร้าง file
* SGL_VAR_DIR . '/skipRunAnalytics'
* เนื่องบางเครื่องรัน analytics แล้วช้า
*/
public static function isSkipAnalytics()
{
$file = SGL_VAR_DIR . '/skipRunAnalytics';
$isSkip = (is_file($file) == true) ? true : false;
SGL::logMessage($file . ' ==> isSkip: ' . $isSkip, PEAR_LOG_DEBUG);
return $isSkip;
}
}//End Class
}
?>