@copyright Copyright (C) 2021. All Rights Reserved. @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html ____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____ (_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _) .-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )( \____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__) /------------------------------------------------------------------------------------------------------*/ // No direct access to this file defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\MVC\Controller\FormController; use Joomla\Utilities\ArrayHelper; /** * Extensiondistributor Package Form Controller */ class ExtensiondistributorControllerPackage extends FormController { /** * Current or most recently performed task. * * @var string * @since 12.2 * @note Replaces _task. */ protected $task; public function __construct($config = array()) { $this->view_list = 'keys'; // safeguard for setting the return view listing to the default site view. parent::__construct($config); } public function update() { $app = JFactory::getApplication(); $cparams = JComponentHelper::getParams('com_extensiondistributor'); $releaseId = $app->input->get('release', null, 'int'); $key = $app->input->get('key'); $domain = $app->input->get('domain', null, 'base64'); $domain = base64_decode($domain); $ip = $app->input->get('ip', null, 'base64'); $ip = base64_decode($ip); $this->setRedirect( JRoute::_( JUri::root(), false ) ); // We check if a release ID was provided or we get the latest one if ($releaseId) { // We need to identify which type of release it is extension or package $release = ExtensiondistributorHelper::getReleaseFile($releaseId, $key); if ($release['file'] === false) { echo $release['msg']; return false; } else { $filename = $release['msg']; } } else { $app->enqueueMessage('We could not identify your request','error'); return false; } $folder = $cparams->get('releases_directory'); $folder = JPath::clean(JPATH_SITE . '/' . $folder . '/'); $file = $folder . $filename; if (!JFile::exists($file)) { $app->enqueueMessage(sprintf('The file %s is not available', $filename),'error'); return false; } $size = filesize($file); // All checks has been done we log the download $db = JFactory::getDbo(); $log = new stdClass(); $log->transaction = 'Joomla'; $log->package = ExtensiondistributorHelper::getVar('release',$releaseId,'id','package'); $log->user = ExtensiondistributorHelper::getVar('key',$key,'key','user'); $log->domain = $domain; $log->ip = $ip; $log->key = $key; $log->created = JFactory::getDate()->toSql(); $log->created_by = $log->user; $db->insertObject('#__extensiondistributor_download',$log); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header("Content-Transfer-Encoding: Binary"); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $size); ob_clean(); flush(); readfile($file); jexit(); } public function check() { $app = JFactory::getApplication(); $cparams = JComponentHelper::getParams('com_extensiondistributor'); $releaseId = $app->input->get('release', null, 'int'); $key = $app->input->get('key'); $release = ExtensiondistributorHelper::getReleaseFile($releaseId, $key); header('Content-Type: application/json'); echo json_encode($release); $app->close(); jexit(); } /** * Method to check if you can edit an existing record. * * Extended classes can override this if necessary. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key; default is id. * * @return boolean * * @since 12.2 */ protected function allowEdit($data = array(), $key = 'id') { // to insure no other tampering return false; } /** * Method override to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean * * @since 1.6 */ protected function allowAdd($data = array()) { // to insure no other tampering return false; } /** * Method to check if you can save a new or existing record. * * Extended classes can override this if necessary. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key. * * @return boolean * * @since 12.2 */ protected function allowSave($data, $key = 'id') { // to insure no other tampering return false; } /** * Function that allows child controller access to model data * after the data has been saved. * * @param JModelLegacy $model The data model object. * @param array $validData The validated data. * * @return void * * @since 12.2 */ protected function postSaveHook(JModelLegacy $model, $validData = array()) { } }