CHips L MINI SHELL

CHips L pro

Current Path : /opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/lib/RVSGL/CpHandle/
Upload File :
Current File : //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/lib/RVSGL/CpHandle/CpanelReseller.php

<?php

require_once dirname(__FILE__) . '/InterfaceForAdmin.php';
require_once dirname(__FILE__) . '/CpanelLibs.php';

/*
 * Admin is use function in InterfaceAmin and InterfaceUser
 * Admin จำเป็นต้องใช้ทุก function ของ User จึง implements ทั้ง Interface
 * CpHandle_InterfaceForAdmin
 * CpHandle_InterfaceForUser
 * */
class CpHandle_CpanelReseller extends CpHandle_CpanelLibs  implements CpHandle_InterfaceForAdmin
{

	function CpHandle_CpanelRoot() {}

    public function init()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $usePort = (SGL_Config::get('WHMRemoteAccess.whmSSL') == true) ? '2087' : '2086';
        $accesskey = $this->_getAccessKey();
        if (SGL::isError($accesskey) === true) return $accesskey;

        $this->registerRemoteWHM('localhost', RVS_USER_NAME, $usePort, 'hash', $accesskey);
        return true;
    }
    
    public function FrameTarget()
    {
    	return 'mainFrame';
    }
    
    public function replateAtOnUserName($userName)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return $userName;
    }

    public function actionAJExternal($url)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        return 'actionAJExternal("' . $url. '")';
    }
    
    public function isSkipAllowUserPerms()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
    	return false;
    }
    
    public function getPathPHPsuexec()
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        return false;
    }
    
    public function getHomeDir($user=RVS_USER_NAME)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        $aHomeDir = posix_getpwnam($user);
        if (empty($aHomeDir['dir']) === true) {
            $aHomeDir['dir'] = '/home/' . $user;
        }
        return $aHomeDir['dir'];
    }

	public function listAccts($owner=null)
	{
		SGL::logMessage(null, PEAR_LOG_DEBUG);
		$accts = array();
        $aAcctList = $this->runCpOnCurl('array', 'listaccts');
        $owner = is_null($owner) ? $owner : RVS_USER_NAME;
        if (SGL::isError($aAcctList) == true) {
            $accts['ERROR_MSG'] =  $aAcctList->getMessage();
            SGL_Error::pop();
            return $accts;
            
        } else {        	
        	if (is_array($aAcctList) && isset($aAcctList['acct']['user']) === true) {
        		//1 account
        		if (is_null($owner) === false && $aAcctList['acct']['user'] != '' 
        		  && $aAcctList['acct']['owner'] == $owner 
        		  && $aAcctList['acct']['user'] != $owner) {
        			array_push($accts, $aAcctList['acct']['user']);
        		} elseif (is_null($owner) === true && $aAcctList['acct']['user'] != '') {
        			array_push($accts, $aAcctList['acct']['user']);
        		}
        	} elseif (is_array($aAcctList) && isset($aAcctList['acct']) === true) {
        		//หลาย account
        		foreach ($aAcctList['acct'] as $k => $aValues) {
        			if (isset($aValues['user']) === true && $aValues['user'] != '') {
        				if (is_null($owner) === false 
        				    && $aValues['owner'] == $owner 
        				    && $aValues['user'] != $owner) {
        					array_push($accts, $aValues['user']);
        				} elseif (is_null($owner) === true) {
        					array_push($accts, $aValues['user']);
        				}
        			}
        		}
        	}
        }
        return $accts;
	}
	
    public function listAllAcctsData()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $aAcctData = array();
        $aAcctList = $this->runCpOnCurl('array', 'listaccts');
        if (SGL::isError($aAcctList) == true) {
        	return $aAcctList;
        }

        if (is_array($aAcctList) && isset($aAcctList['acct']['user'])) {
        	//1 account
        	$aAcctData = array($aAcctList['acct']);
        } elseif (is_array($aAcctList) && isset($aAcctList['acct'])) {
        	//หลาย account
        	$aAcctData = $aAcctList['acct'];
        }
        return $aAcctData;
    }

    public function getResellers()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $aResellerList = $this->runCpOnCurl('array', 'listresellers');
        $aResellerList = (is_array($aResellerList) && isset($aResellerList['reseller'])) ? $aResellerList['reseller'] : array();
        if (is_array($aResellerList) === false) {
        	$aResellerList = array($aResellerList);
        }
        return $aResellerList;
    }

    public function getWhmRemoteFrame()
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	return 0;
    }
    
    public function checkRVSkinWHMAddon(&$input)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $rvskinPath = RvsLibs_File::buildPath(array('/usr', 'local', 'cpanel', 'base', 'frontend', 'rvorange', 'rvskin'));
        if (is_dir($rvskinPath)) {
            $homeDir = posix_getpwnam('rvadmin');
            if (!$homeDir['dir']) {
                $homeDir['dir'] = RvsLibs_File::buildPath(array('/home', 'rvadmin'));
            }

            $addonConf = array();
            $defaultAddonPath = RvsLibs_File::buildPath(array($homeDir['dir'], '_defaultaddon'));
            if (is_file($defaultAddonPath)) {
                $addonConf = RvsLibs_File::file($defaultAddonPath);
            }

            $integration = 1;
            foreach ($addonConf as $line) {
                if ( RvsLibs_String::preg_match('/^whmaddon_rvsitebuilder/i', $line, $match)) {
                    $integration = 0;
                }
            }
            if ($integration) {
                $input->WHMIntegration = $integration;
                $menuLink = '/rvaddonconfig/addonconfig.php?';
                $menuLink .= 'addonSelect_rvsitebuilder=1&';
                $menuLink .= 'addonName_rvsitebuilder=' . RvsLibs_Url::url_encode('RV SiteBuilder') . '&';
                $menuLink .= 'addonFeature_rvsitebuilder=' . RvsLibs_Url::url_encode('rvsitebuilder') . '&';
                $menuLink .= 'addonCellsfile_rvsitebuilder=' . RvsLibs_Url::url_encode('/usr/local/cpanel/base/frontend/x/cells/rvsitebuilder.html') . '&';
                $menuLink .= 'addonsrc_rvsitebuilder=' . RvsLibs_Url::url_encode('/3rdparty/rvsitebuilder/rvsitebuilder.gif') . '&';
                $menuLink .= 'addonhref_rvsitebuilder=' . RvsLibs_Url::url_encode('/3rdparty/rvsitebuilder/' . INDEX_PHPSU . '/sitebuilder/sitebuilderhome') . '&';
                $menuLink .= 'addonfilename_rvsitebuilder=' . RvsLibs_Url::url_encode('/3rdparty/rvsitebuilder/' . INDEX_PHPSU . '/sitebuilder/sitebuilderhome') . '&';
                $menuLink .= 'addongroup_rvsitebuilder=p' . '&';
                $menuLink .= 'ownerDir=' . RvsLibs_Url::url_encode($homeDir['dir']) . '&';
                $menuLink .= 'langDir=' . RvsLibs_Url::url_encode($homeDir['dir'] . '/rvlang') . '&';
                $menuLink .= 'featureList=rvsitebuilder;' . '&';
                $menuLink .= 'rvTheme=' . RvsLibs_Url::url_encode('rvblue;rvgreen;rvlightblue;rvlightgreen;rvlightmaroon;rvlightolive;rvlightorange;rvlightteal;rvlightviolet;rvmaroon;rvolive;rvorange;rvteal;rvviolet');
                $input->WHMIntegrationURL = $menuLink;
            }
        }
        return true;
	}
    public function isValidIncludeFileLang($aConfTemplateList)
    {
       
        return  false;
    }
	
    public function isCpanel()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return true;
    }
    
    public function isNotTryout()
    {
        //log loop SGL::logMessage(null, PEAR_LOG_DEBUG);
        return true;
    }
    

    public function getHashUrl()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $hashUrl = preg_replace(array("/:2082/", "/:2083/", "/\/\/cpanel./"), array(":2086", ":2087", "//whm."), INDEX_URL);
        return $hashUrl;
    }
    
    public function getTmpPath()
    {
    	/*
    	 return (RVS_USER_NAME == 'root') 
    		? RvsLibs_File::buildPath(array(RVS_USER_HOME, '.rvsitebuilder', 'tmp')) 
    		: RvsLibs_File::buildPath(array(RVS_USER_HOME, 'tmp'));;
    	 */
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	return RvsLibs_File::buildPath(array(RVS_USER_HOME, 'tmp'));
    }
    
	public function checkFileConfigLicenseCycle($cycleNow = 0, $errorNotExit = 0, $skipMsg = 0)
	{
	    SGL::logMessage(null, PEAR_LOG_DEBUG);
	    require_once dirname(dirname(__FILE__)) . '/LicenseCycle.php';
	    $oCycle = new LicenseCycle();
	    $oCycle->FileConfigLicenseCycle($cycleNow, $errorNotExit, $skipMsg);
	    return true;
	}

    public function whmRequest($request,$host,$user,$accesshash,$usessl)
    {
       SGL::logMessage(null, PEAR_LOG_DEBUG);  
       return $this->_whmreq($request,$host,$user,$accesshash,$usessl);
    }
    
    public function isAllowImportProject()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return (isset($this->conf['Admin']['Owner']['AllowImportProject'])) 
            ? $this->conf['Admin']['Owner']['AllowImportProject'] 
            : '0';
    }
	
    ######################################################
    # Private function
    ######################################################
    
    /**
     * Get WHM remote Accress Key for Reseller
     */
    private function _getAccessKey()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);

        $accessKey = '';
        $hashFile = RvsLibs_File::buildPath(array(RVS_USER_HOME,  '.accesshash'));
        
        if (is_file($hashFile) === false) {
        	SGL::logMessage($hashFile, PEAR_LOG_DEBUG);
        	SGL::logMessage('Require remote access key. Please go to WHM >> Main >> Cluster/Remote Access >> Setup Remote Access Key and come back', PEAR_LOG_DEBUG);
            return false;
        	//return pear error ไม่ได้นะคับ เพราะจะทำให้สร้าง <iframe เพื่อรัน setrhash ไม่ได้
            //return SGL::raiseError('Require remote access key. Please go to WHM >> Main >> Cluster/Remote Access >> Setup Remote Access Key and come back');
        }
        
        $accessKey = RvsLibs_File::file($hashFile);
        $accessKey = implode("", $accessKey);
        $accessKey = RvsLibs_String::preg_replace("'(\r|\n)'","",$accessKey);

        return $accessKey;
    }
    
    ######################################################
    ######################################################
    
    public function getLogoutUrl()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return '/logout';
    }
    
    /**
     * detac path file php.ini
     * @see sitebuilder/classes/CpHandle/CpHandle_InterfaceForAdmin#detectPathPHP()
     */
    public function detectPathPHP()
    {
        if (!function_exists('get_cfg_var')) {
            return false;
        }
        
        $pathPHPini = get_cfg_var('cfg_file_path');
        $pathPHPini = trim($pathPHPini);
        return ($pathPHPini == '/usr/local/lib/php.ini' || $pathPHPini == '/usr/lib/php.ini') ? true : false;
        
        /*
        if (CPMODE == 'cpanel') {
            $pathPHPini = get_cfg_var('cfg_file_path');
            $pathPHPini = trim($pathPHPini);
            $checkphpini = ($pathPHPini == '/usr/local/lib/php.ini' || $pathPHPini == '/usr/lib/php.ini') ? false : true;
            if ($checkphpini === false) {
                $output->warningMakecpphp = true;
            }
        }
        */
    }
    
    public function getCPDATA($username=RVS_USER_NAME)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $aCpLine = RvsLibs_File::file('/var/cpanel/users/' . $username);
        $aCpdata = array(); 
        foreach ($aCpLine as $cpLine) {
            $cpLine = RvsLibs_String::preg_replace("/\r|\n/","",$cpLine);
            list($cpKey, $cpValue) = RvsLibs_String::dbeExplode("=", $cpLine);
            if (isset($cpKey)) {
                $aCpdata[$cpKey] =  $cpValue;
            }
        }
        return $aCpdata;
    }
    
    public function getUserDNS($all = 0)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $aUserDNS = array();
        if ($all != 0) {
            foreach ($GLOBALS['CPANEL']['CPDATA'] as $key => $val) {
                if (RvsLibs_String::preg_match('/^DNS/', $key, $match)) {
                    array_push($aUserDNS, $val);
                }
            }
        } else {
            $aUserDNS = isset($GLOBALS['CPANEL']['CPDATA']['DNS']) ? $GLOBALS['CPANEL']['CPDATA']['DNS'] : '';
        }
        return $aUserDNS;
    }
    
    public function getControlPanelUrl()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return INDEX_URL . '/xfercpanel';
    }
    
    public function isAllowExportProject()
    {
        return (isset($this->conf['Admin']['Owner']['AllowExportProject'])) 
            ? $this->conf['Admin']['Owner']['AllowExportProject'] 
            : '0';
    }
    
    public function isTryout()
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	return false;
    }

    /**
     * Is mode nocp
     *
     * @author Puttipong <puttipong@rvglobalsoft.com>
     * @return Boolean False
     */
    public function isNocp()
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	return false;
    }

     /**
     * Validate update RVSitebuilder
     * 
     * @author Puttipong <puttipong@rvglobalsoft.com>
     * @return mix Array or Boolean
     */
    public function getUpgradeRVSitebuilder()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $dirInstall = RvsLibs_File::buildPath(array('/usr', 'local', 'cpanel', 'whostmgr', 'docroot', 'cgi', 'rvsitebuilderinstaller', 'RVSInstaller'));
        $fileAutoInstall = RvsLibs_File::buildPath(array('/usr', 'local', 'cpanel', 'whostmgr', 'docroot', 'cgi', 'rvsitebuilderinstaller', 'autoinstaller.cgi'));
        return (is_dir($dirInstall) === true && is_file($fileAutoInstall) === true)
                        ? $fileAutoInstall : false;                        
    }
    
    public function runDetectPhpSuexec($dePhpSuexec)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	$phpSuExec = RvsLibs_System::runDetectPhpSuexec();
    	if($phpSuExec != $dePhpSuexec) {
    		RvsLibs_Config::autoUpdatePhpSuExecToMainIpConf($phpSuExec, $this->conf);
    	}
        
        /*if (!file_exists('/usr/local/cpanel/bin/rebuild_phpconf')) {
            $phpSuexec = $this->_createNewSuexec($phpSuexec);

        } else {
            if (file_exists(SGL_TMP_DIR . '/phpconf.log')) {
                RvsLibs_System::unlink(SGL_TMP_DIR . '/phpconf.log');
            }
            @exec('/usr/local/cpanel/bin/rebuild_phpconf --current > ' . SGL_TMP_DIR . '/phpconf.log');
            if (file_exists(SGL_TMP_DIR . '/phpconf.log')) {
                $phpConf = array();
                $lines = RvsLibs_File::file(SGL_TMP_DIR . '/phpconf.log');
                foreach ($lines as $line_num => $line) {
                    if (RvsLibs_String::preg_match('#^Available handlers:(.*?)$#si', $line, $aMatch)) {
                        foreach(explode(' ', $aMatch[1]) as $v) {
                            $v = RvsLibs_String::trim($v);
                            if ($v != '') {
                                $phpConf['handlers'][] = $v;
                            }
                        }
                    } elseif (RvsLibs_String::preg_match('#^DEFAULT PHP:(.*?)$#si', $line, $aMatch)) {
                        $phpConf['default-ver'] = RvsLibs_String::trim($aMatch[1]);
                    } elseif (RvsLibs_String::preg_match('#^PHP(.*?) SAPI:(.*?)$#si', $line, $aMatch)) {
                        $phpConf['SAPI'][RvsLibs_String::trim($aMatch[1])] = RvsLibs_String::trim($aMatch[2]);
                    } elseif (RvsLibs_String::preg_match('#^SUEXEC:(.*?)$#si', $line, $aMatch)) {
                        $phpConf['suexec'] = RvsLibs_String::trim($aMatch[1]);
                    }
                }

                if (isset($phpConf['SAPI'][$phpConf['default-ver']])) {
                    SGL::logMessage('Default version:' . $phpConf['default-ver'] . ', SAPI: ' . $phpConf['SAPI'][$phpConf['default-ver']] . ', suexec:' . $phpConf['suexec'], PEAR_LOG_DEBUG);
                    $phpSuexec = 0;
                    $phpSuexec = $this->_switchAutoUpdatePhpSu($phpSuexec, $phpConf, $this->conf);

                    if ($phpSuexec) {
                        SGL::logMessage('PHPSuExec is enabled', PEAR_LOG_DEBUG);
                    } else {
                        SGL::logMessage('PHPSuExec is disabled', PEAR_LOG_DEBUG);
                    }
                }
            }
        }*/
        return $phpSuExec;
    }
    
 /*private function _switchAutoUpdatePhpSu($phpSuexec, $phpConf, $conf)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        switch ($phpConf['SAPI'][$phpConf['default-ver']]) {
            case 'suphp':*/
                /*  if "DEFAULT PHP" is "4" and "PHP4 SAPI" is "suphp"
                 or "DEFAULT PHP" is "5" and "PHP5 SAPI" is "suphp" */
                //$phpSuexec = 1;
                //if root user call tark update config phpsu to 1
                /*$this->_autoUpdatePhpSuExecToMainIpConf($phpSuexec, $conf);
                break;
            case 'fcgi':
            case 'cgi':
                if ($phpConf['suexec'] == 'enabled') {
                    /* if "DEFAULT PHP" is "4" and "PHP4 SAPI" is not "suphp"
                     or "DEFAULT PHP" is "5" and "PHP5 SAPI" is not "suphp"
                     and suexec is enabled */
                    //$phpSuexec = 1;
                    //if root user call tark update config phpsu to 1
                    /*$this->_autoUpdatePhpSuExecToMainIpConf($phpSuexec, $conf);
                } else {
                    $phpSuexec = 0;
                    //if root user call tark update config phpsu to 0
                    $this->_autoUpdatePhpSuExecToMainIpConf($phpSuexec, $conf);
                }
                break;
            case 'dso':
            case 'none':
            default:
                $phpSuexec = 0;
                //if root user call tark update config phpsu to 0
                $this->_autoUpdatePhpSuExecToMainIpConf($phpSuexec, $conf);
                break;
        }
        return $phpSuexec;
    }*/
    
    /**
     * update phpSuExec auto in MainIP.conf.php
     *
     * @param <int> $phpSuExec   1 or 0 only
     * @param <array> $conf
     * @return boolean
     * 
     * @author apiruk boonruksa 20/01/2009
     */
    
    /*private function _autoUpdatePhpSuExecToMainIpConf($phpSuExec, $conf)
    {
        SGL::logMessage("**** phpSuExec= " . $phpSuExec . ' $conf[\'SiteBuilder\'][\'modPhpSuExec\']= ' . $conf['SiteBuilder']['modPhpSuExec'], PEAR_LOG_DEBUG);
        if (RVS_IS_ADMIN == 1 && isset($conf['SiteBuilder']['modPhpSuExec']) && $conf['SiteBuilder']['modPhpSuExec'] != $phpSuExec) {
            $conf['SiteBuilder']['modPhpSuExec'] = sprintf("%s", $phpSuExec);
            $c = SGL_Config::singleton();
            $c->replace($conf);
            $configFile = SGL_VAR_DIR . '/' . SGL_SERVER_NAME . '.conf.php';
            if (is_file($configFile)) {
                $ok = $c->save($configFile);
                if (SGL::isError($ok)) {
                    SGL::logMessage("**** Cannot save modPhpSuExec to MainIP.con.php", PEAR_LOG_ERR);
                    SGL_Install_Common::errorPush($ok);
                    return false;
                }
            } else {
                SGL::logMessage("**** Cannot locate " . $configFile, PEAR_LOG_ERR);
                return false;
            }
        }
        SGL::logMessage("**** save phpSuExec to MainIP.conf.php successfull value is " . $phpSuExec, PEAR_LOG_DEBUG);
        return true;
    }*/

    public function isValidClearCacheAndRVSiteFIX()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return true;
    }
    
    /**
     * get file encode .txt
     * @see sitebuilder/classes/CpHandle/CpHandle_InterfaceForUser#getTypeFileEncode($fileName)
     */
    public function getTypeFileEncode($fileName)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $TypeFileEncode = '';
        if (RvsLibs_System::function_exists('finfo_open') && RvsLibs_System::function_exists('finfo_file')) {
            $finfo = @finfo_open(FILEINFO_MIME_ENCODING);
            $TypeFileEncode = @finfo_file($finfo, $fileName);
        } elseif (RvsLibs_System::function_exists('system')) {
                $store = RVS_USER_HOME . '/.rvsitebuilder/fileencode.txt';
                $command = "/usr/local/cpanel/bin/guess_file_encoding " . $fileName . " > " . $store;
                @system($command);
                SGL::logMessage('command : ' . $command, PEAR_LOG_DEBUG);
                $TypeFileEncode = RvsLibs_File::_getFileEncode($store);
        }
        return $TypeFileEncode;
    }
    
    /**
     * Make remove tryout
     * 
     * @author Puttipong <puttipong@rvglobalsoft.com>
     * @param Array $option
     */
    public function makeRemoveTryout($option = array())
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	
    	$fileTryoutSetting = RvsLibs_File::buildPath(array(RVS_USER_HOME, '.rvsitebuilder', 'tryout_setting.ini.php'));
    	$aSetting = (is_file($fileTryoutSetting) === true) ? RvsLibs_Config::parse_ini_file($fileTryoutSetting) : array();
    	$databaseName = (isset($aSetting['database_name']) === true)? $aSetting['database_name'] : '';
    	$databaseUser = (isset($aSetting['database_user']) === true) ? $aSetting['database_user'] : '';
    	$subdomainPath = (isset($aSetting['subdomain_path']) === true) ? $aSetting['subdomain_path'] : '';

    	$fileTryoutConf = RvsLibs_File::buildPath(array($subdomainPath, 'tryout_config.ini.php'));
    	$aConf = (is_file($fileTryoutConf) === true) ? RvsLibs_Config::parse_ini_file($fileTryoutConf) : array();
        $domain = (isset($aConfig['dns']) === true) ? $aConf['dns'] : '';
        
        $cpTag = '';
        if ($option['delSubdomain'] == 1) {
            $cpTag .= <<< EOF
<deletesubdomain>
<![CDATA[
    <cpanel SubDomain="delsubdomain('{$domain}')">
]]>
</deletesubdomain>
EOF;
        }
            
        if ($option['delUser'] == 1) {
        	$cpTag .= <<< EOF
<deleteuserdb>
<![CDATA[
    <cpanel Mysql="deluserdb('{$databaseName}', '{$databaseUser}')">
]]>
</deleteuserdb>

<deleteuser>
<![CDATA[
    <cpanel Mysql="deluser('{$databaseUser}')">
]]>
</deleteuser>
EOF;
        }
        
        if ($option['delDatabase'] == 1) {
        	$cpTag .= <<< EOF
<deletedatabase>
<![CDATA[
    <cpanel Mysql="deldb('{$databaseName}')">
]]>
</deletedatabase>       	
EOF;
        }
        
        $delDirectory = (isset($option['delDirectory']) === true && $option['delDirectory'] == 1) ? 1 : 0;
        $cpTag .= <<< EOF
<deletetryout>
<![CDATA[
    <cpanel Rvsitebuilder="removeTryoutProjectCode('{$subdomainPath}', '{$delDirectory}')">
]]>
</deletetryout>   
EOF;
        $this->runCpOnIframe(__FUNCTION__, $cpTag);
    }
    
	public function isVaildTemplatePrivate() 
	{
		//SGL::logMessage(null, PEAR_LOG_DEBUG);
	    return false;
	}
	
    public function skipValidTemplate()
    {
    	//SGL::logMessage('RETURN FALSE', PEAR_LOG_DEBUG);
    	return false;
    }
    
   public function isValidUpdateRollbackVersion()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return false;
    }
    
    public function isDirectAdmin()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return false;
    }
    
    public function getRvBinPath()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return '/var/cpanel/rvglobalsoft/rvsitebuilder/rvbin/rvswrapper';
    }
    
     public function isAdmin($username = RVS_USER_NAME)
     {
     	SGL::logMessage(null, PEAR_LOG_DEBUG);
     	return ($username == 'root')? true : false;
        
     }
    
    public function ownerIsAdmin($ownername = RVS_OWNER_USER_NAME)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	return ($ownername == 'root')? true : false;
    }
    
    public function UserUploadSymLinksecureCommand($realPathUserUpload)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	$pathUserUploadSymLink = RvsLibs_File::buildPath(array(SGL_USERDATA_PATH, RVS_USER_NAME, 'upload'));
    	if (is_link($pathUserUploadSymLink) === false) {
    		if (file_exists($pathUserUploadSymLink) === true) {
    			RvsLibs_System::rm(array('-rf', $pathUserUploadSymLink));
    		}
    		///create symlink ใน path rvsitebuilder/www/userdata/$USERNAME/upload    
    		if (is_dir(RvsLibs_File::buildPath(array(SGL_USERDATA_PATH, RVS_USER_NAME))) == false) {
    			$resSecure = RvsLibs_System::secureCommand('makeuserdatapath');
    			if (SGL::isError($resSecure)) {
    				SGL::raiseMsg(RvsLibs_String::translate('Cannot create user folder because '.$resSecure->getMessage()));
    				SGL_Error::pop();
    				exit;
    			}
    		}
    	    RvsLibs_User::createUserSymlinkUserFolder($realPathUserUpload, $pathUserUploadSymLink);
    	}
    }
    
    public function makeUploadFolder($userUploadPath, $pathLinkUpload, $userDataPath)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	if (!is_link($pathLinkUpload) && is_dir($userDataPath) ) {
    		return  symlink($userUploadPath, $pathLinkUpload);
    	}
    	return false;
    }
    
   public function createUserSymlinkUserFolder($pathUserUpload, $pathUploadLink)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
    	RvsLibs_User::createUserSymlinkUserFolder($pathUserUpload, $pathUploadLink);
    }
    
   public function moveUploadedFile($tempFile, $destination)
   {
    SGL::logMessage(null, PEAR_LOG_DEBUG);
    return RvsLibs_File::moveUploadedFile($tempFile, $destination);
   }
   
   public function isUploadedFile($tempFile)
   {
    SGL::logMessage(null, PEAR_LOG_DEBUG);
    return RvsLibs_File::isUploadedFile($tempFile);
   }
   public function makeLink($source, $des)
   {
	   	SGL::logMessage('tempFile :: ' . $source, PEAR_LOG_DEBUG);
	   	SGL::logMessage('destination::' . $des, PEAR_LOG_DEBUG);
	   	RvsLibs_System::ln(array('-s', $source, $des));
   }
   
    function secureCommandMakeLinkProjectId($projectId)
    {
        $resSecure = RvsLibs_System::secureCommand('makeprojectsymlink', array('project-id' => $projectId));
        if (SGL::isError($resSecure) === true) {
            return SGL::raiseError(
                RvsLibs_String::translate(
                      'Cannot create project folder symlink, becase %MSG.'
                      , 'vprintf'
                      , array('MSG' => $resSecure->getMessage())
                )
            );
        }
        return true;
    }
    
    public function isTryoutOpenbaseDir($user)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        $GLOBALS['CPANEL']['CPDATA'] = $this->getCPDATA($user);
        $aUserDns = RvsLibs_User::getUserDNS(1);
       
        $pattern1 = '/^custom_vhost_template_ap1:\s\/var\/cpanel\/rvglobalsoft\/rvsitebuilder\/panelmenus\/cpanel\/apachetemplate\/tryout.rvsitebuilder.apache1$/';
        $pattern2 = '/^custom_vhost_template_ap2:\s\/var\/cpanel\/rvglobalsoft\/rvsitebuilder\/panelmenus\/cpanel\/apachetemplate\/tryout.rvsitebuilder.apache2$/';
        
        foreach($aUserDns as $userDns) {
            $pathDNS = RvsLibs_File::buildPath(array('/var', 'cpanel', 'userdata', $user, $userDns));
             
             if(is_file($pathDNS)) {
    
                $aData = file($pathDNS);
                $countLine = 0;
                 
                foreach ($aData as $line) {
                    if (RvsLibs_String::preg_match($pattern1, trim($line)) || (RvsLibs_String::preg_match($pattern2, trim($line)))) {
                    
                        $countLine ++;
    
                        if ($countLine == 2) {
                             SGL::logMessage('Tryout ABC :: 3 ' , PEAR_LOG_DEBUG);
                            return true;

                        }
                    }
                }
             }
        }
        return false;
    }
    
    public function buildProjectUrlForDa()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
    }
    public function isRealConfigUpLoadMaxFileSize()
    {
        return ini_get('upload_max_filesize');
    }
    
    /**
     * Make userdata path
     * @return unknown_type
     */
    function makeuserdatapath($userdataPath)
    {
        return RvsLibs_System::secureCommand('makeuserdatapath');
    }
    
    /**
     * 
     * Make Restore Online Counter
     * 
     * @author Puttipong <puttipong at rvglobalsoft.com>
     * 
     * @param $projectId <STRING>
     * @return TRUE
     */
    public function makeRestoreOnlineCounter($projectId=null) {
        if (isset($projectId) && $projectId != '') {
            if (class_exists('Online_CounterMgr') === false) {
                require_once RvsLibs_File::buildPath(array(SGL_MOD_DIR, 'sitebuilder', 'classes', 'Online_CounterMgr.php'));
            }
            $oCounter = new Online_CounterMgr();
            $oCounter->makeRestoreOnlineCounter($projectId);
            
            $imgCounterProject = RvsLibs_File::buildPath(array(REAL_PROJECT_PATH, $projectId, 'images', 'counter02.gif'));
            if (file_exists($imgCounterProject) == true) {
            } else {
                $imgCounterAdmin = RvsLibs_File::buildPath(array(SGL_WEB_ROOT, 'themes', 'default', 'sitebuilder','images', 'counter02.gif'));
                if (file_exists($imgCounterAdmin) == true) {
                    RvsLibs_System::copy(array($imgCounterAdmin, $imgCounterProject));
                }
            }
        }
        
        return true;
    }
    
}

?>

Copyright 2K16 - 2K18 Indonesian Hacker Rulez