Your IP : 216.73.216.224


Current Path : /var/www/html/administrator/components/com_jchat/Model/
Upload File :
Current File : /var/www/html/administrator/components/com_jchat/Model/AjaxserverModel.php

<?php
namespace JExtstore\Component\JChat\Administrator\Model;
/** 
 * @package JCHAT::AJAXSERVER::components::com_jchat 
 * @subpackage models
 * @author Joomla! Extensions Store
 * @copyright (C) 2024 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html  
 */
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerHelper;
use JExtstore\Component\JChat\Administrator\Framework\Http;
use JExtstore\Component\JChat\Administrator\Framework\Model as JChatModel;
use JExtstore\Component\JChat\Administrator\Framework\Exception as JChatException;

/**
 * Ajax Server model responsibilities
 *
 * @package JCHAT::AJAXSERVER::components::com_jchat  
 * @subpackage models
 * @since 2.9
 */
interface IAjaxserverModel {
	public function loadAjaxEntity($id, $param, $DIModels) ;
}

/** 
 * Classe che gestisce il recupero dei dati per il POST HTTP
 * @package JCHAT::AJAXSERVER::components::com_jchat  
 * @subpackage models
 * @since 2.9
 */
class AjaxserverModel extends JChatModel implements IAjaxserverModel {
	/**
	 * Get license informations about this user subscription license email code
	 * Use the RESTFul interface API on the remote License resource
	 *
	 * @static
	 * @access private
	 * @param Object[] $additionalModels Array for additional injected models type hinted by interface
	 * @return Object
	 */
	private function getLicenseStatus($additionalModels = null) {
		// Get email license code
		$code = ComponentHelper::getParams('com_jchat')->get('registration_email', null);
	
		// Instantiate HTTP client
		$HTTPClient = new Http();
	
		/*
		 * Status domain code
		 * Remote API Call
		 */
		$headers = array('Accept'=>'application/json', 'User-agent' => 'JChatsocial Enteprise updater');
		if($code) {
			try {
				$prodCode = 'jchatent';
				$cdFuncUsed = 'str_' . 'ro' . 't' . '13';
				$HTTPResponse = $HTTPClient->get($cdFuncUsed('uggc' . '://' . 'fgberwrkgrafvbaf' . '.bet') . "/option,com_easycommerce/action,licenseCode/email,$code/productcode,$prodCode", $headers);
			} catch (\Exception $e) {
				$HTTPResponse = new \stdClass();
				$HTTPResponse->body = '{"success":false,"reason":"connection_error","details":"' . $e->getMessage() . '"}';
			}
		} else {
			$HTTPResponse = new \stdClass();
			$HTTPResponse->body = '{"success":false,"reason":"nocode_inserted"}';
		}
			
		// Deserializing della response
		try {
			$objectHTTPResponse = json_decode($HTTPResponse->body);
			if(!is_object($objectHTTPResponse)) {
				throw new \Exception('decoding_error');
			}
		} catch (\Exception $e) {
			$HTTPResponse = new \stdClass();
			$HTTPResponse->body = '{"success":false,"reason":"' . $e->getMessage() . '"}';
			$objectHTTPResponse = json_decode($HTTPResponse->body);
		}
	
		return $objectHTTPResponse;
	}
	
	/**
	 * Perform the asyncronous update of the component
	 * 1- Dowload the remote update package file
	 * 2- Use the Joomla installer to install it
	 * 3- Return status to the js app
	 *
	 * @static
	 * @access private
	 * @param Object[] $additionalModels Array for additional injected models type hinted by interface
	 * @return Object
	 */
	private function downloadComponentUpdate($additionalModels = null) {
		// Response JSON object
		$response = new \stdClass ();
		$cdFuncUsed = 'str_' . 'ro' . 't' . '13';
		$ep = $cdFuncUsed('uggc' . '://' . 'fgberwrkgrafvbaf' . '.bet' . '/XZY1405SSUOnifs3243564864kfunex35tdrntq5895q.ugzy');
		$file_path = $this->app->getConfig()->get('tmp_path', '/tmp') . '/KML1405FFHBavsf3243564864xshark35gqeagd5895d.zip';
	
		try {
			// Ensure CURL support
			if (! function_exists ( 'curl_init' )) {
				throw new JChatException ( Text::_ ( 'COM_JCHAT_CURL_NOT_SUPPORTED' ), 'error' );
			}
	
			// Firstly test if the server is up and HTTP 200 OK
			$ch = curl_init($ep);
			curl_setopt( $ch, CURLOPT_NOBODY, true );
			curl_setopt( $ch, CURLOPT_HEADER, false );
			curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
			curl_setopt( $ch, CURLOPT_MAXREDIRS, 3 );
			curl_exec( $ch );
	
			$headerInfo = curl_getinfo( $ch );
			if($headerInfo['http_code'] != 200 || !$headerInfo['download_content_length']) {
				throw new JChatException ( Text::_ ( 'COM_JCHAT_ERROR_DOWNLOADING_REMOTE_FILE' ), 'error' );
			}
	
			// 1- Download the remote update package file and put in local file
			$fp = fopen ($file_path, 'w+');
			$ch = curl_init();
			curl_setopt( $ch, CURLOPT_URL, $ep );
			// curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
			curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
			curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
			curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 60 );
			curl_setopt( $ch, CURLOPT_FILE, $fp );
			curl_exec( $ch );
			fclose( $fp );
	
			if (!filesize($file_path)) {
				throw new JChatException ( Text::_ ( 'COM_JCHAT_ERROR_WRITING_LOCAL_FILE' ), 'error' );
			}
	
			// All went well
			$response->result = true;
		} catch ( JChatException $e ) {
			$response->result = false;
			$response->exception_message = $e->getMessage ();
			$response->errorlevel = $e->getExceptionLevel();
			return $response;
		} catch ( \Exception $e ) {
			$jchatException = new JChatException ( Text::sprintf ( 'COM_JCHAT_ERROR_UPDATING_COMPONENT', $e->getMessage () ), 'error' );
			$response->result = false;
			$response->exception_message = $jchatException->getMessage ();
			$response->errorlevel = $jchatException->getExceptionLevel();
			return $response;
		}
	
		return $response;
	}
	
	/**
	 * Perform the asyncronous update of the component
	 * 1- Dowload the remote update package file
	 * 2- Use the Joomla installer to install it
	 * 3- Return status to the js app
	 *
	 * @static
	 * @access private
	 * @param Object[] $additionalModels Array for additional injected models type hinted by interface
	 * @return Object
	 */
	private function installComponentUpdate($additionalModels = null) {
		// Response JSON object
		$response = new \stdClass ();
		$file_path = $this->app->getConfig()->get('tmp_path', '/tmp') . '/KML1405FFHBavsf3243564864xshark35gqeagd5895d.zip';
	
		try {
			// Unpack the downloaded package file.
			$package = InstallerHelper::unpack($file_path, true);
			if(!$package) {
				throw new JChatException ( Text::_ ( 'COM_JCHAT_ERROR_EXTRACTING_UPDATES' ), 'error' );
			}
	
			// 2- Use the Joomla installer to install it
			// New plugin installer
			$database = Factory::getContainer()->get('DatabaseDriver');
			$updateInstaller = new Installer ();
			$updateInstaller->setDatabase($database);
			if (! $updateInstaller->install ( $package['extractdir'] )) {
				throw new JChatException ( Text::_ ( 'COM_JCHAT_ERROR_INSTALLING_UPDATES' ), 'error' );
			}
	
			// Delete dirty files and folder
			unlink($file_path);
			$it = new \RecursiveDirectoryIterator($package['extractdir'], \RecursiveDirectoryIterator::SKIP_DOTS);
			$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
			foreach($files as $file) {
				if ($file->isDir()){
					@rmdir($file->getRealPath());
				} else {
					unlink($file->getRealPath());
				}
			}
			// Delete the now empty folder
			@rmdir($package['extractdir']);
	
			// All went well
			$response->result = true;
		} catch ( JChatException $e ) {
			$response->result = false;
			$response->exception_message = $e->getMessage ();
			$response->errorlevel = $e->getExceptionLevel();
			return $response;
		} catch ( \Exception $e ) {
			$jchatException = new JChatException ( Text::sprintf ( 'COM_JCHAT_ERROR_UPDATING_COMPONENT', $e->getMessage () ), 'error' );
			$response->result = false;
			$response->exception_message = $jchatException->getMessage ();
			$response->errorlevel = $jchatException->getExceptionLevel();
			return $response;
		}
	
		return $response;
	}
	
	/**
	 * Mimic an entities list, as ajax calls arrive are redirected to loadEntity public responsibility to get handled
	 * by specific subtask. Responses are returned to controller and encoded from view over HTTP to JS client
	 * 
	 * @access public 
	 * @param string $id Rappresenta l'op da eseguire tra le private properties
	 * @param mixed $param Parametri da passare al private handler
	 * @param Object[]& $DIModels
	 * @return Object& $utenteSelezionato
	 */
	public function loadAjaxEntity($id, $param , $DIModels) {
		//Delega la private functions delegata dalla richiesta sulla entity
		$response = $this->$id($param, $DIModels);

		return $response;
	}
}