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/NocpLibs.php

<?php
class CpHandle_NocpLibs extends CpHandle
{
	private $debugMode = true;
	
	public function runCpOnCurl()
	{

	}

	public function runCpOnIframe($module, $cpanelTag)
	{
		if (SGL_Config::get('log.enabled') != 1) {
			$this->debugMode = false;
		}
		
		if (defined('RVS_SKIP_FIREPHP_LOG') === false)
            define('RVS_SKIP_FIREPHP_LOG' , true);
            
		$module = ($module) ? $module : "rvsitebuilder";

		$complierPath = $this->_getCpIframeComplierPath();
		if (SGL::isError($complierPath) === true) {
			return $complierPath;
		}
        
		/// Build path
		$fileInput = RvsLibs_File::buildPath(array($complierPath, $module . '.in'));
		$fileModeComplete = RvsLibs_File::buildPath(array($complierPath, $module . '.cpanelComplete'));
		
		/// Clean old file
		if (is_file($fileInput)) {
            RvsLibs_System::unlink($fileInput);
        }
        
        if (is_file($fileModeComplete)) {
            RvsLibs_System::unlink($fileModeComplete);
        }

		$file = RvsLibs_File::fopen($fileInput, 'w');
		
		if (SGL::isError($file) === true) {
			return $file;
		} else {
			RvsLibs_File::fwrite($file, $cpanelTag);
			RvsLibs_File::fclose($file);
		}
		
		$hashid = md5_file($fileInput);
		
		$cpComplierFile = SGL_BASE_URL . '/nocp_panel/compliecpTag.php?complierid=' . $module . '&hashid=' . $hashid;

		SGL::logMessage("******" . $cpComplierFile, PEAR_LOG_DEBUG);
		// run javascript display loading
        echo $this->_buildCpIframe($cpComplierFile);

		$this->_flush();
		
		$cpRes = $this->_getCpanelTagData($module);
		return $cpRes;
	}
	
	public function fetchStatus($res=array())
	{
        $status = 'Unknow status.';
        foreach ($res as $line) {
            if (RvsLibs_String::preg_match('/^status=(.*)$/si', RvsLibs_String::trim($line), $aMatch)) {
                $status = RvsLibs_String::trim($aMatch[1]);
                break;
            }
        }
        return $status;
	}
	
    public function fetchDBInfomation($aData)
    {
    	/// Set defult struct.
        $aDbConf = array(
            'countdb' => '',
            'maxdb' => -1,
            'listdbs' => array(),
            'listusers' => array(),
        );
        /// fetch data to struct
        foreach ($aData as $v) {
            if (RvsLibs_String::preg_match('#^countdb=#', $v, $aMatch)) {
                list($key, $value) = RvsLibs_String::mb_split('=', $v, 2);
                $aDbConf['countdb'] = RvsLibs_String::trim($value);
            } 
            
            if (RvsLibs_String::preg_match('#^maxdb=#', $v, $aMatch)) {
                list($key, $value) = RvsLibs_String::mb_split('=', $v, 2);
                $aDbConf['maxdb'] = RvsLibs_String::trim($value);
            } 
            
            if (RvsLibs_String::preg_match('#^listdbs=#', $v, $aMatch)) {
                list($key, $value) = RvsLibs_String::mb_split('=', $v, 2);
                $av = RvsLibs_String::dbeExplode(',', $value);
                foreach ($av as $vd) {
                    $aDbConf['listdbs'][$vd] = RvsLibs_String::trim($vd);
                }
            } 
            
            if (RvsLibs_String::preg_match('#^listusers=#', $v, $aMatch)) {
                list($key, $value) = RvsLibs_String::mb_split('=', $v, 2);
                $av = RvsLibs_String::dbeExplode(',', $value);
                foreach ($av as $vd) {
                    $aDbConf['listusers'][$vd] = RvsLibs_String::trim($vd);
                }
            }
        }
        
        return $aDbConf;
    }
    
    
    /**
     * Get WHM remote Accress Key
     */
    public function getCpAccessKey()
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        return '';
    }
    
  /**
     * Get data response
     *
     * @param array $aData
     * @return bool
     */
    public function getDataResponse($isOk)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        foreach ($aData as $v) {
            if (RvsLibs_String::preg_match('#^status=(.*)#', $v, $aMatch)) {
                if (RvsLibs_String::strtolower($aMatch[1]) == 'ok') {
                    return true;
                } else {
                    SGL::raiseMsg($aMatch[1]);
                    return false;
                }
            }
        }
        RvsLibs_String::translate(SGL::raiseMsg('Cannot detect respont'));
        return false;
    }
    
    ##################################
    ########## PRIVATE FUNCTION ##########
    ##################################

    private function _getCpanelTagData($module)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $timeout = 50;
        $fileOutput = $module . '.cpanelComplete';
        $aCpData = array();
        $runTime = 0;
        $fileOutputUser = RvsLibs_File::buildPath(array(RVS_USER_HOME, '.rvsitebuilder', $fileOutput));

        while ($runTime < $timeout) {
            if ( file_exists($fileOutputUser) ) {
                $aCpData = $this->_openCpData($fileOutputUser);
                if (SGL::isError($aCpData)) {
                    SGL::logMessage('Error : ' . $aCpData->getMessage(), PEAR_LOG_DEBUG);
                    SGL_Error::pop();
                    $aCpData = array();
                }
                RvsLibs_System::unlink($fileOutputUser);
                break;
            } elseif ( file_exists('/tmp/' . $fileOutput)) {
                $aCpData = $this->_openCpData('/tmp/' . $fileOutput);
                if (SGL::isError($aCpData)) {
                    SGL::logMessage('Error : ' . $aCpData->getMessage(), PEAR_LOG_DEBUG);
                    SGL_Error::pop();
                    $aCpData = array();
                }
                RvsLibs_System::unlink('/tmp/' . $fileOutput);
                break;
            }
            sleep(1);
            $runTime++;
        }
        
        if ($runTime >= $timeout) {
        	echo $this->_buildUnloadingCode();
            die ("Cannot get cPanel data. Connection timeout. File not found {$fileOutputUser} and /tmp/{$fileOutput} in {$timeout} sec.");
        }
        //  javascript close id loading

        echo $this->_buildUnloadingCode();

        $aCpData = RvsLibs_String::dbeExplode('__RVSITEBUILDER__', $aCpData);
        if (isset($aCpData[0]) && RvsLibs_String::trim($aCpData[0]) == "") {
            unset($aCpData[0]); 
        }
        return $aCpData;
    }
    
     private function _openCpData($file)
    {
        SGL::logMessage("=== open file::" . $file, PEAR_LOG_DEBUG);
        $aCpData = array();
        $aCpData = RvsLibs_File::file($file);
        if (SGL::isError($aCpData) === true) {
            return $aCpData;
        }

        array_walk($aCpData, array($this, '_trimValues'), '__RVSITEBUILDER__');
        
        foreach ($aCpData as $k => $v) {
            if ($v == "") {
                unset($aCpData[$k]); 
            }
        }
        
        // optimize :nipaporn
        RvsLibs_System::unlink( str_replace(".cpanelComplete", ".in", $file));
        return join($aCpData);
    }
    
    private function _getCpIframeComplierPath()
    {
    	$rvsPath = RvsLibs_File::buildPath(array(RVS_USER_HOME, '.rvsitebuilder'));
    	
        if ( file_exists($rvsPath) && is_readable($rvsPath) ) {
            return $rvsPath;
        } elseif ( is_readable('/tmp') ) {
            return '/tmp';
        } else {
            SGL::logMessage('Cannot run cPanel tag', PEAR_LOG_ERR);
            return SGL::raiseError('The path ' . $rvsPath . ' and /tmp cannot readable.');
        }
    }
    
	/**
	 * Build code iframe for run CP
	 * @param <string> $urlSrc
	 * @return <string>
	 */
	private function _buildCpIframe($urlSrc)
	{
		$imageSrc =  PUBLIC_IMG_URL.'/cocock.gif';
        $frameId = rand(0, 9999);
        
        $frameWidth = '0%';
        $frameHeight = '0%';
        if ($this->debugMode) {
        	$frameWidth = '100%';
            $frameHeight = '150';
        }
        
        $htmlCode = <<<EOF
<iframe name="cpanelcomplier{$frameId}" src="{$urlSrc}" width="{$frameWidth}" height="{$frameHeight}" scrolling="auto" frameborder="0">
[ Your user agent does not support frames or is currently configured not to display frames. ]
</iframe>
<div style="visibility: hidden; position: absolute; top: 150px;">.</div>
EOF;

        return $htmlCode;
	}
	
	/**
	 * Javascript close id loading
	 * @return <string>
	 */
	private function _buildUnloadingCode()
	{
		$code = <<<EOF
<script>
if(document.getElementById('cpLoading')){
document.getElementById('cpLoading').style.display='none';
}
</script>
EOF;

        return $code;
	}
	
	/**
	 *  Flush output buffering
	 * @return <bool>
	 */
	private function _flush()
	{
		// make sure output buffering is off before we start it
        // this will ensure same effect whether or not ob is enabled already
		while (ob_get_level()) {
            ob_end_flush();
        }
        // start output buffering
        if (ob_get_length() === false) {
            ob_start();
        }
        ob_flush();
        flush();
        return true;
	}
	
    private function _trimValues(&$value, $key, $prefix)
    {
        $value = RvsLibs_String::trim($value);
        if ($value != "") {
            $value = $prefix . $value;
        }
    }

	####################################
	############# END PRIVATE #############
	####################################
    
}

Copyright 2K16 - 2K18 Indonesian Hacker Rulez