Skip to content

Commit 2129ad9

Browse files
committed
Merge branch '4.0-dev' into 4.0-dev-update-file-and-folder-removal-in-script-2021-05-08
2 parents 2b0d13e + 1210615 commit 2129ad9

File tree

28 files changed

+793
-4205
lines changed

28 files changed

+793
-4205
lines changed

administrator/components/com_joomlaupdate/restore.php

Lines changed: 728 additions & 3649 deletions
Large diffs are not rendered by default.

administrator/components/com_joomlaupdate/src/Controller/DisplayController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
\defined('_JEXEC') or die;
1313

14-
use Joomla\CMS\Client\ClientHelper;
1514
use Joomla\CMS\Language\Text;
1615
use Joomla\CMS\MVC\Controller\BaseController;
1716
use Joomla\CMS\Response\JsonResponse;
@@ -46,8 +45,6 @@ public function display($cachable = false, $urlparams = false)
4645
// Get and render the view.
4746
if ($view = $this->getView($vName, $vFormat))
4847
{
49-
ClientHelper::setCredentialsFromRequest('ftp');
50-
5148
// Get the model for the view.
5249
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
5350
$model = $this->getModel('Update');

administrator/components/com_joomlaupdate/src/Controller/UpdateController.php

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
\defined('_JEXEC') or die;
1313

14-
use Joomla\CMS\Client\ClientHelper;
1514
use Joomla\CMS\Factory;
1615
use Joomla\CMS\Filesystem\File;
1716
use Joomla\CMS\Language\Text;
@@ -41,7 +40,7 @@ public function download()
4140
$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
4241
$options['text_file'] = 'joomla_update.php';
4342
Log::addLogger($options, Log::INFO, array('Update', 'databasequery', 'jerror'));
44-
$user = Factory::getUser();
43+
$user = $this->app->getIdentity();
4544

4645
try
4746
{
@@ -52,8 +51,6 @@ public function download()
5251
// Informational log only
5352
}
5453

55-
$this->_applyCredentials();
56-
5754
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
5855
$model = $this->getModel('Update');
5956
$result = $model->download();
@@ -119,7 +116,7 @@ public function download()
119116
public function install()
120117
{
121118
$this->checkToken('get');
122-
Factory::getApplication()->setUserState('com_joomlaupdate.oldversion', JVERSION);
119+
$this->app->setUserState('com_joomlaupdate.oldversion', JVERSION);
123120

124121
$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
125122
$options['text_file'] = 'joomla_update.php';
@@ -134,12 +131,10 @@ public function install()
134131
// Informational log only
135132
}
136133

137-
$this->_applyCredentials();
138-
139134
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
140135
$model = $this->getModel('Update');
141136

142-
$file = Factory::getApplication()->getUserState('com_joomlaupdate.file', null);
137+
$file = $this->app->getUserState('com_joomlaupdate.file', null);
143138
$model->createRestorationFile($file);
144139

145140
$this->display();
@@ -178,8 +173,6 @@ public function finalise()
178173
// Informational log only
179174
}
180175

181-
$this->_applyCredentials();
182-
183176
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
184177
$model = $this->getModel('Update');
185178

@@ -222,8 +215,6 @@ public function cleanup()
222215
// Informational log only
223216
}
224217

225-
$this->_applyCredentials();
226-
227218
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
228219
$model = $this->getModel('Update');
229220

@@ -276,9 +267,7 @@ public function upload()
276267
$this->checkToken();
277268

278269
// Did a non Super User tried to upload something (a.k.a. pathetic hacking attempt)?
279-
Factory::getUser()->authorise('core.admin') or jexit(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
280-
281-
$this->_applyCredentials();
270+
$this->app->getIdentity()->authorise('core.admin') or jexit(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
282271

283272
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
284273
$model = $this->getModel('Update');
@@ -313,13 +302,13 @@ public function captive()
313302
$this->checkToken('get');
314303

315304
// Did a non Super User tried to upload something (a.k.a. pathetic hacking attempt)?
316-
if (!Factory::getUser()->authorise('core.admin'))
305+
if (!$this->app->getIdentity()->authorise('core.admin'))
317306
{
318307
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
319308
}
320309

321310
// Do I really have an update package?
322-
$tempFile = Factory::getApplication()->getUserState('com_joomlaupdate.temp_file', null);
311+
$tempFile = $this->app->getUserState('com_joomlaupdate.temp_file', null);
323312

324313
if (empty($tempFile) || !File::exists($tempFile))
325314
{
@@ -434,33 +423,6 @@ public function display($cachable = false, $urlparams = array())
434423
return $this;
435424
}
436425

437-
/**
438-
* Applies FTP credentials to Joomla! itself, when required
439-
*
440-
* @return void
441-
*
442-
* @since 2.5.4
443-
*/
444-
protected function _applyCredentials()
445-
{
446-
$this->app->getUserStateFromRequest('com_joomlaupdate.method', 'method', 'direct', 'cmd');
447-
448-
if (!ClientHelper::hasCredentials('ftp'))
449-
{
450-
$user = $this->app->getUserStateFromRequest('com_joomlaupdate.ftp_user', 'ftp_user', null, 'raw');
451-
$pass = $this->app->getUserStateFromRequest('com_joomlaupdate.ftp_pass', 'ftp_pass', null, 'raw');
452-
453-
if ($user != '' && $pass != '')
454-
{
455-
// Add credentials to the session
456-
if (!ClientHelper::setCredentials('ftp', $user, $pass))
457-
{
458-
$this->app->enqueueMessage(Text::_('JLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED'), 'warning');
459-
}
460-
}
461-
}
462-
}
463-
464426
/**
465427
* Checks the admin has super administrator privileges and then proceeds with the final & cleanup steps.
466428
*
@@ -474,7 +436,7 @@ public function finaliseconfirm()
474436
$this->checkToken();
475437

476438
// Did a non Super User try do this?
477-
if (!Factory::getUser()->authorise('core.admin'))
439+
if (!$this->app->getIdentity()->authorise('core.admin'))
478440
{
479441
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
480442
}

administrator/components/com_joomlaupdate/src/Helper/Select.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

administrator/components/com_joomlaupdate/src/Model/UpdateModel.php

Lines changed: 1 addition & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
\defined('_JEXEC') or die;
1313

1414
use Joomla\CMS\Authentication\Authentication;
15-
use Joomla\CMS\Client\ClientHelper;
16-
use Joomla\CMS\Client\FtpClient;
1715
use Joomla\CMS\Component\ComponentHelper;
1816
use Joomla\CMS\Extension\ExtensionHelper;
1917
use Joomla\CMS\Factory;
2018
use Joomla\CMS\Filesystem\File;
21-
use Joomla\CMS\Filesystem\Folder;
22-
use Joomla\CMS\Filesystem\Path;
2319
use Joomla\CMS\Filter\InputFilter;
2420
use Joomla\CMS\Http\Http;
2521
use Joomla\CMS\Http\HttpFactory;
@@ -252,27 +248,6 @@ public function getUpdateInformation()
252248
return $this->updateInformation;
253249
}
254250

255-
/**
256-
* Returns an array with the configured FTP options.
257-
*
258-
* @return array
259-
*
260-
* @since 2.5.4
261-
*/
262-
public function getFTPOptions()
263-
{
264-
$config = Factory::getApplication()->getConfig();
265-
266-
return array(
267-
'host' => $config->get('ftp_host'),
268-
'port' => $config->get('ftp_port'),
269-
'username' => $config->get('ftp_user'),
270-
'password' => $config->get('ftp_pass'),
271-
'directory' => $config->get('ftp_root'),
272-
'enabled' => $config->get('ftp_enable'),
273-
);
274-
}
275-
276251
/**
277252
* Removes all of the updates from the table and enable all update streams.
278253
*
@@ -494,14 +469,10 @@ public function createRestorationFile($basename = null)
494469
// Get a password
495470
$password = UserHelper::genRandomPassword(32);
496471
$app = Factory::getApplication();
497-
$app->setUserState('com_joomlaupdate.password', $password);
498472

499473
// Trigger event before joomla update.
500474
$app->triggerEvent('onJoomlaBeforeUpdate');
501475

502-
// Do we have to use FTP?
503-
$method = Factory::getApplication()->getUserStateFromRequest('com_joomlaupdate.method', 'method', 'direct', 'cmd');
504-
505476
// Get the absolute path to site's root.
506477
$siteroot = JPATH_SITE;
507478

@@ -529,7 +500,7 @@ public function createRestorationFile($basename = null)
529500
'kickstart.tuning.max_exec_time' => '5',
530501
'kickstart.tuning.run_time_bias' => '75',
531502
'kickstart.tuning.min_exec_time' => '0',
532-
'kickstart.procengine' => '$method',
503+
'kickstart.procengine' => 'direct',
533504
'kickstart.setup.sourcefile' => '$file',
534505
'kickstart.setup.destdir' => '$siteroot',
535506
'kickstart.setup.restoreperms' => '0',
@@ -539,133 +510,6 @@ public function createRestorationFile($basename = null)
539510
'kickstart.setup.postrenamefiles' => false
540511
ENDDATA;
541512

542-
if ($method != 'direct')
543-
{
544-
/*
545-
* Fetch the FTP parameters from the request. Note: The password should be
546-
* allowed as raw mode, otherwise something like !@<sdf34>43H% would be
547-
* sanitised to !@43H% which is just plain wrong.
548-
*/
549-
$ftp_host = $app->input->get('ftp_host', '');
550-
$ftp_port = $app->input->get('ftp_port', '21');
551-
$ftp_user = $app->input->get('ftp_user', '');
552-
$ftp_pass = addcslashes($app->input->get('ftp_pass', '', 'raw'), "'\\");
553-
$ftp_root = $app->input->get('ftp_root', '');
554-
555-
// Is the tempdir really writable?
556-
$writable = @is_writable($tempdir);
557-
558-
if ($writable)
559-
{
560-
// Let's be REALLY sure.
561-
$fp = @fopen($tempdir . '/test.txt', 'w');
562-
563-
if ($fp === false)
564-
{
565-
$writable = false;
566-
}
567-
else
568-
{
569-
fclose($fp);
570-
unlink($tempdir . '/test.txt');
571-
}
572-
}
573-
574-
// If the tempdir is not writable, create a new writable subdirectory.
575-
if (!$writable)
576-
{
577-
$FTPOptions = ClientHelper::getCredentials('ftp');
578-
$ftp = FtpClient::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
579-
$dest = Path::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $tempdir . '/admintools'), '/');
580-
581-
if (!@mkdir($tempdir . '/admintools'))
582-
{
583-
$ftp->mkdir($dest);
584-
}
585-
586-
if (!@chmod($tempdir . '/admintools', 511))
587-
{
588-
$ftp->chmod($dest, 511);
589-
}
590-
591-
$tempdir .= '/admintools';
592-
}
593-
594-
// \Just in case the temp-directory was off-root, try using the default tmp directory.
595-
$writable = @is_writable($tempdir);
596-
597-
if (!$writable)
598-
{
599-
$tempdir = JPATH_ROOT . '/tmp';
600-
601-
// Does the JPATH_ROOT/tmp directory exist?
602-
if (!is_dir($tempdir))
603-
{
604-
Folder::create($tempdir, 511);
605-
$htaccessContents = "order deny,allow\ndeny from all\nallow from none\n";
606-
File::write($tempdir . '/.htaccess', $htaccessContents);
607-
}
608-
609-
// If it exists and it is unwritable, try creating a writable admintools subdirectory.
610-
if (!is_writable($tempdir))
611-
{
612-
$FTPOptions = ClientHelper::getCredentials('ftp');
613-
$ftp = FtpClient::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
614-
$dest = Path::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $tempdir . '/admintools'), '/');
615-
616-
if (!@mkdir($tempdir . '/admintools'))
617-
{
618-
$ftp->mkdir($dest);
619-
}
620-
621-
if (!@chmod($tempdir . '/admintools', 511))
622-
{
623-
$ftp->chmod($dest, 511);
624-
}
625-
626-
$tempdir .= '/admintools';
627-
}
628-
}
629-
630-
// If we still have no writable directory, we'll try /tmp and the system's temp-directory.
631-
$writable = @is_writable($tempdir);
632-
633-
if (!$writable)
634-
{
635-
if (@is_dir('/tmp') && @is_writable('/tmp'))
636-
{
637-
$tempdir = '/tmp';
638-
}
639-
else
640-
{
641-
// Try to find the system temp path.
642-
$tmpfile = @tempnam('dummy', '');
643-
$systemp = @dirname($tmpfile);
644-
@unlink($tmpfile);
645-
646-
if (!empty($systemp))
647-
{
648-
if (@is_dir($systemp) && @is_writable($systemp))
649-
{
650-
$tempdir = $systemp;
651-
}
652-
}
653-
}
654-
}
655-
656-
$data .= <<<ENDDATA
657-
,
658-
'kickstart.ftp.ssl' => '0',
659-
'kickstart.ftp.passive' => '1',
660-
'kickstart.ftp.host' => '$ftp_host',
661-
'kickstart.ftp.port' => '$ftp_port',
662-
'kickstart.ftp.user' => '$ftp_user',
663-
'kickstart.ftp.pass' => '$ftp_pass',
664-
'kickstart.ftp.dir' => '$ftp_root',
665-
'kickstart.ftp.tempdir' => '$tempdir'
666-
ENDDATA;
667-
}
668-
669513
$data .= ');';
670514

671515
// Remove the old file, if it's there...

0 commit comments

Comments
 (0)