HEX
Server: Apache
System: Linux sg241.singhost.net 2.6.32-896.16.1.lve1.4.51.el6.x86_64 #1 SMP Wed Jan 17 13:19:23 EST 2018 x86_64
User: honghock (909)
PHP: 8.0.30
Disabled: passthru,system,shell_exec,show_source,exec,popen,proc_open
Upload Files
File: //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/modules/tryout/classes/CpHandle.php
<?php

class CpHandle extends SGL_Manager
{
    var $oCp = null;

	public function CpHandle()
	{
		parent::SGL_Manager();
	}

    public function init($cpmode = CPMODE, $userPrivilege=null)
    {
        $cpPrefix = 'CpHandle';
        $userPrivilege = is_null($userPrivilege)
            ? RvsLibs_User::getPrivilege() : $userPrivilege;
        SGL::logMessage('userPrivilege:---> ' .  $userPrivilege, PEAR_LOG_DEBUG);
        switch (strtolower($cpmode)) {
            case 'cpanel':
                $cpFile = 'Cpanel' . $userPrivilege;
                $strategy = $cpPrefix . '_' . $cpFile;

                break;
            case 'da':
                $cpFile = 'Da' . $userPrivilege;
                $strategy = $cpPrefix . '_' . $cpFile;
                break;
            case 'plesk':
                $cpFile = 'Plesk' . $userPrivilege;
                $strategy = $cpPrefix . '_' . $cpFile;
                break;
             case 'tryout':
             	//TODO $userPrivilege = 'User' fix ไปก่อน
             	//tryout มีปัญหา detect privilege;
             	$userPrivilege = 'User';
                $cpFile = 'Tryout' . $userPrivilege;
                $runtryoutOnPanel = self::_getRunTryoutOnPanel();

                if (isset($this->conf['localConfig']['moduleName']) && $this->conf['localConfig']['moduleName'] == 'tryout') {
                	require_once( SGL_MOD_DIR . '/../lib/RVSGL/CpHandle/TryoutLibs/' . ucfirst(strtolower($runtryoutOnPanel)) . '.php');
                } else {
                    /// include tryout libs for panel;
                    require_once dirname(__FILE__) . '/CpHandle/TryoutLibs/' . ucfirst(strtolower($runtryoutOnPanel)) . '.php';
                }

                $strategy = $cpPrefix . '_' . $cpFile;
                break;
            case 'nocp':
            default:
                $cpFile = 'Nocp' . $userPrivilege;
                $strategy = $cpPrefix . '_' . $cpFile;
        }
        // validate root go to user interface and go to admin interface auto but cannot redirect with action = sitebuilderAjaxExecute
        if ( isset($GLOBALS['isTest']) === false)  {
            $req   = SGL_Request::singleton();
            $isAjax = ($req->get('rvsMgr') && $req->get('rvsAct')) ? true : false;
            if (SGL_Session::getRoleId() == SGL_ADMIN && RvsLibs_User::isAdminGuiAllowed() === false && $isAjax === false) {
                $aUrl = array(
                    'moduleName'  => 'sitebuilder',
                    'managerName' => 'admin');
                SGL_HTTP::redirect($aUrl);
            }
        }

        if (isset($this->conf['localConfig']['moduleName']) && $this->conf['localConfig']['moduleName'] == 'tryout') {
        	$cpPathFile = SGL_MOD_DIR . '/../lib/RVSGL/' . $cpPrefix . '/' . $cpFile . '.php';
        } else {
            $cpPathFile = dirname(__FILE__) . '/' . $cpPrefix . '/' . $cpFile . '.php';
        }

        SGL::logMessage("User Handle File: " .  $cpPathFile, PEAR_LOG_DEBUG);

        if (class_exists($strategy) === false) {
            require_once $cpPathFile;
        }

        $obj = new $strategy();
        $ok = $obj->init();
        return SGL::isError($ok) ? $ok : $obj;
    }

    public static function singleton($autoload=false)
    {
        static $instance;

        // If the instance is not there, create one
        if (!isset($instance) || $autoload) {
            $class = __CLASS__;
            $obj =  new $class();
            $instance = $obj->init();
        }
        return $instance;
    }

    public static function factory()
    {
        self::_fixUndefindConf();
    	$obj = CpHandle::singleton();
        return $obj;
    }
    /*****************************************
     * fix กรณีที่ setup ใหม่ จะยังไม่ define ค่าพวกนี้มาให้
     ****************************************/
    private static  function _fixUndefindConf()
    {
    	if (defined('CPMODE') === false) {
    		define('CPMODE',null);
    	}
    	if (defined('RVS_USER_NAME') === false) {
    		define('RVS_USER_NAME',null);
    	}
    	if (defined('SGL_TMP_DIR') === false) {
    		define('SGL_TMP_DIR',null);
    	}
    	if (defined('RVS_IS_RESELLER') === false) {
    		define('RVS_IS_RESELLER',null);
    	}
    }

    ######################################################
    # Private function
    ######################################################

    private static function _getPrivilege()
    {
        return RvsLibs_User::getPrivilege();
    }

    private static function _getRunTryoutOnPanel()
    {
    	return 'cPanel';

    }

    public function getOsInfomation()
    {
    	$file = '/etc/redhat-release';
    	$aVersionFiles = array(
    			'/etc/centos-release' => 'parse_redhat',
    			'/etc/redhat-release' => 'parse_redhat',
    			'/etc/system-release' => 'parse_redhat',
    			'/etc/os-release' => 'parse_ubuntu',
    	);
    	foreach ($aVersionFiles as $file => $callback) {
	    	if (file_exists($file)) {
	    		$aInfo = array(
	    		    'OS Name' => 'Unknown',
	    			'OS Version' => 'Unknown',
	    		);
	    		switch ($callback)
	    		{
	    			case 'parse_redhat': $aInfo = $this->parse_redhat($file); break;
	    			case 'parse_ubuntu': $aInfo = $this->parse_ubuntu($file); break;
	    		}
	    		return $aInfo;
	    	}
    	}

    }

    private function parse_redhat($file)
    {
    	$aInfo = array(
    			'OS Name' => 'Unknown',
    			'OS Version' => 'Unknown',
    	);

    	try {
    		$inLine = trim(join(file($file)));
    		list($osName, $tmpLine) = split(' ', $inLine, 2);
    		$aInfo['OS Name'] = $osName;
    		if (preg_match('/(\d+\.\d+\.\d+)/si', $tmpLine, $aMatch)) {
    			$aInfo['OS Version'] = $aMatch[1];
    		} elseif (preg_match('/(\d+\.\d+)/si', $tmpLine, $aMatch)) {
    			$aInfo['OS Version'] = $aMatch[1];
    		} elseif (preg_match('/(\d+)/si', $tmpLine, $aMatch)) {
    			$aInfo['OS Version'] = $aMatch[1];
    		}
    	} catch (Exception $e) {
    		SGL::logMessage('Cannot parse OS Version: ' .  $e->getMessage(), PEAR_LOG_WARNING);
    		$aInfo = array(
    			'OS Name' => 'Unknown',
    			'OS Version' => 'Unknown',
    		);
    	}
    	return $aInfo;
    }

    private function parse_ubuntu($file)
    {
    	$aOSData = parse_ini_file($file);
    	$aInfo = array(
    			'OS Name' => isset($aOSData['NAME']) ? $aOSData['NAME'] : 'Unknown',
    			'OS Version' => isset($aOSData['VERSION_ID']) ? $aOSData['VERSION_ID'] :'Unknown',
    	);

    	return $aInfo;
    }

    public function getIoncubeVersion()
    {
    	$ioncubeVersion = 'Unknown';
    	if (function_exists('ioncube_loader_version')) {
    		$ioncubeVersion = ioncube_loader_version();
    	}
    	return $ioncubeVersion;
    }

    public function getCPMode()
    {
    	$controlpanelName = '';
    	switch (strtolower(CPMODE)) {
    		case 'cpanel': $controlpanelName = 'cPanel'; break;
    		case 'da': $controlpanelName = 'DirectAdmin'; break;
    		case 'plesk': $controlpanelName = 'Plesk'; break;
    		case 'tryout': $controlpanelName = 'Tryout'; break;
    		case 'nocp':default: $controlpanelName = 'NoCP'; break;
    	}
    	return $controlpanelName;
    }
    //private function pa
}