188 lines
5.9 KiB
PHP
188 lines
5.9 KiB
PHP
<?php
|
|
/*----------------------------------------------------------------------------------| www.vdm.io |----/
|
|
Agence Agerix
|
|
/-------------------------------------------------------------------------------------------------------/
|
|
|
|
@version 1.x.x
|
|
@build 2nd June, 2022
|
|
@created 12th December, 2020
|
|
@package Extension Distributor
|
|
@subpackage maintenance.php
|
|
@author Emmanuel Danan <https://agerix.fr>
|
|
@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\BaseController;
|
|
use Joomla\Utilities\ArrayHelper;
|
|
|
|
/**
|
|
* Extensiondistributor Maintenance Base Controller
|
|
*/
|
|
class ExtensiondistributorControllerMaintenance extends BaseController
|
|
{
|
|
public function __construct($config)
|
|
{
|
|
parent::__construct($config);
|
|
}
|
|
|
|
public function dashboard()
|
|
{
|
|
$this->setRedirect(JRoute::_('index.php?option=com_extensiondistributor', false));
|
|
return;
|
|
}
|
|
|
|
public function saveconfig()
|
|
{
|
|
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
|
|
|
|
global $cparams;
|
|
$componentid = JComponentHelper::getComponent('com_extensiondistributor')->id;
|
|
$app = JFactory::getApplication();
|
|
$return = 'index.php?option=com_extensiondistributor&view=maintenance';
|
|
$secure = $app->input->get('secure',0,'int') ? 'secure' : 'unsecure';
|
|
|
|
$this->setRedirect(
|
|
JRoute::_(
|
|
$return, false
|
|
)
|
|
);
|
|
|
|
$old['releases_directory'] = JPath::clean(JPATH_SITE . '/' . $cparams->get('releases_directory','packages') . '/');
|
|
$old['jcb_directory'] = JPath::clean(JPATH_SITE . '/' . $cparams->get('jcb_directory','jcb') . '/');
|
|
$old['updates_directory'] = JPath::clean(JPATH_SITE . '/' . $cparams->get('updates_directory','updates') . '/');
|
|
$old['import_directory'] = JPath::clean(JPATH_SITE . '/' . $cparams->get('import_directory','extmanagerimport') . '/');
|
|
|
|
$new['releases_directory'] = JPath::clean(JPATH_SITE . '/' . $app->input->get('releases_directory',null,'string') . '/');
|
|
$new['jcb_directory'] = JPath::clean(JPATH_SITE . '/' . $app->input->get('jcb_directory',null,'string') . '/');
|
|
$new['updates_directory'] = JPath::clean(JPATH_SITE . '/' . $app->input->get('updates_directory',null,'string') . '/');
|
|
$new['import_directory'] = JPath::clean(JPATH_SITE . '/' . $app->input->get('import_directory',null,'string') . '/');
|
|
|
|
foreach ($old as $k => $v) {
|
|
if (!is_null($new[$k])) {
|
|
if ($k !== 'updates_directory') {
|
|
if (JFolder::exists($v))
|
|
{
|
|
if (!JFolder::exists($new[$k])) {
|
|
JFolder::create($new[$k]);
|
|
}
|
|
JFolder::move($v,$new[$k]);
|
|
ExtensiondistributorHelper::secureFolder($new[$k],$secure);
|
|
$cparams->set($k, $app->input->get($k,null,'string'));
|
|
$table = JTable::getInstance('extension');
|
|
$table->load($componentid);
|
|
$table->bind(array('params' => $cparams->toString()));
|
|
// Check for error
|
|
if (!$table->check()) {
|
|
$this->setError('lastcreatedate: check: ' . $table->getError());
|
|
return false;
|
|
}
|
|
// Save to database
|
|
if (!$table->store()) {
|
|
$this->setError('lastcreatedate: store: ' . $table->getError());
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$app->enqueueMessage('Configuration successfully updated!');
|
|
|
|
return true;
|
|
}
|
|
|
|
public function renameAllFiles()
|
|
{
|
|
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
|
|
|
|
$return = 'index.php?option=com_extensiondistributor&view=maintenance';
|
|
|
|
$this->setRedirect(
|
|
JRoute::_(
|
|
$return, false
|
|
)
|
|
);
|
|
|
|
$app = JFactory::getApplication();
|
|
$app->enqueueMessage('Renamed! (Not yet active)');
|
|
|
|
return true;
|
|
}
|
|
|
|
public function deleteFile()
|
|
{
|
|
JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
|
|
|
|
global $cparams;
|
|
$app = JFactory::getApplication();
|
|
$return = 'index.php?option=com_extensiondistributor&view=maintenance';
|
|
$path = JPATH_SITE . '/' . $cparams->get('releases_directory','packages') . '/';
|
|
$path = JPath::clean($path);
|
|
$filename = $app->input->get('id',null,'base64');
|
|
|
|
$this->setRedirect(
|
|
JRoute::_(
|
|
$return, false
|
|
)
|
|
);
|
|
|
|
if (is_null($filename)) {
|
|
$app->enqueueMessage('No file has been chosen','error');
|
|
return false;
|
|
}
|
|
if (!JFile::exists($path.base64_decode($filename))) {
|
|
$app->enqueueMessage('The file does not exist','error');
|
|
return false;
|
|
}
|
|
|
|
JFile::delete($path.base64_decode($filename));
|
|
$app->enqueueMessage('File successfully deleted!');
|
|
|
|
return true;
|
|
}
|
|
|
|
public function deleteAllFiles()
|
|
{
|
|
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
|
|
|
|
global $cparams;
|
|
$app = JFactory::getApplication();
|
|
$return = 'index.php?option=com_extensiondistributor&view=maintenance';
|
|
$path = JPATH_SITE . '/' . $cparams->get('releases_directory','packages') . '/';
|
|
$path = JPath::clean($path);
|
|
|
|
$this->setRedirect(
|
|
JRoute::_(
|
|
$return, false
|
|
)
|
|
);
|
|
|
|
$model = $this->getModel('maintenance');
|
|
$orphans = $model->getOrphans();
|
|
|
|
if (!ExtensiondistributorHelper::checkArray($orphans)) {
|
|
$app->enqueueMessage('Nothing to delete','error');
|
|
return false;
|
|
}
|
|
|
|
foreach ($orphans as $orphan) {
|
|
if (JFile::exists($path.$orphan)) {
|
|
JFile::delete($path.$orphan);
|
|
}
|
|
}
|
|
$app->enqueueMessage(sprintf('%s files successfully deleted!',count($orphans)));
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|