2009-10-15 21:19:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2009-10-29 06:58:56 +00:00
|
|
|
* Administrative script for running authorized file operations.
|
|
|
|
*
|
2012-09-14 15:19:14 +00:00
|
|
|
* Using this script, the site owner (the user actually owning the files on the
|
|
|
|
* webserver) can authorize certain file-related operations to proceed with
|
|
|
|
* elevated privileges, for example to deploy and upgrade modules or themes.
|
|
|
|
* Users should not visit this page directly, but instead use an administrative
|
|
|
|
* user interface which knows how to redirect the user to this script as part of
|
|
|
|
* a multistep process. This script actually performs the selected operations
|
|
|
|
* without loading all of Drupal, to be able to more gracefully recover from
|
2024-01-11 14:36:13 +00:00
|
|
|
* errors. Access to the script is controlled by a global kill switch in
|
2013-01-07 11:45:26 +00:00
|
|
|
* settings.php ('allow_authorize_operations') and via the 'administer software
|
2012-09-14 15:19:14 +00:00
|
|
|
* updates' permission.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
2009-10-29 06:58:56 +00:00
|
|
|
* There are helper functions for setting up an operation to run via this
|
|
|
|
* system in modules/system/system.module. For more information, see:
|
|
|
|
* @link authorize Authorized operation helper functions @endlink
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
|
|
|
|
2014-06-26 10:47:01 +00:00
|
|
|
use Drupal\Core\DrupalKernel;
|
2016-05-16 12:05:48 +00:00
|
|
|
use Drupal\Core\Form\EnforcedResponseException;
|
2014-09-29 13:41:29 +00:00
|
|
|
use Drupal\Core\Url;
|
2014-11-21 09:31:37 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
2014-06-26 10:47:01 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2014-10-09 11:58:40 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2014-04-25 19:13:44 +00:00
|
|
|
use Drupal\Core\Site\Settings;
|
2020-06-23 09:35:08 +00:00
|
|
|
use Drupal\Core\Routing\RouteObjectInterface;
|
2019-08-12 21:45:20 +00:00
|
|
|
use Symfony\Component\Routing\Route;
|
2013-09-15 06:52:34 +00:00
|
|
|
|
2011-10-31 04:05:57 +00:00
|
|
|
// Change the directory to the Drupal root.
|
|
|
|
chdir('..');
|
|
|
|
|
2015-03-11 08:31:22 +00:00
|
|
|
$autoloader = require_once 'autoload.php';
|
2013-09-02 19:53:23 +00:00
|
|
|
|
2009-10-15 21:19:31 +00:00
|
|
|
/**
|
2012-09-14 15:19:14 +00:00
|
|
|
* Global flag to identify update.php and authorize.php runs.
|
|
|
|
*
|
|
|
|
* Identifies update.php and authorize.php runs, avoiding unwanted operations
|
2013-06-05 07:47:39 +00:00
|
|
|
* such as css/js preprocessing and translation, and solves some theming issues.
|
|
|
|
* The flag is checked in other places in Drupal code (not just authorize.php).
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
2011-11-29 09:56:53 +00:00
|
|
|
const MAINTENANCE_MODE = 'update';
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
/**
|
2011-09-10 15:37:08 +00:00
|
|
|
* Determines if the current user is allowed to run authorize.php.
|
2009-10-15 21:19:31 +00:00
|
|
|
*
|
2024-01-11 14:36:13 +00:00
|
|
|
* The kill switch in settings.php overrides all else, otherwise, the user must
|
2009-10-15 21:19:31 +00:00
|
|
|
* have access to the 'administer software updates' permission.
|
|
|
|
*
|
2015-03-19 12:34:11 +00:00
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
2016-04-16 12:17:32 +00:00
|
|
|
* The incoming request.
|
2015-03-19 12:34:11 +00:00
|
|
|
*
|
2013-06-29 16:26:55 +00:00
|
|
|
* @return bool
|
2012-09-14 15:19:14 +00:00
|
|
|
* TRUE if the current user can run authorize.php, and FALSE if not.
|
2009-10-15 21:19:31 +00:00
|
|
|
*/
|
2015-03-19 12:34:11 +00:00
|
|
|
function authorize_access_allowed(Request $request) {
|
|
|
|
$account = \Drupal::service('authentication')->authenticate($request);
|
|
|
|
if ($account) {
|
|
|
|
\Drupal::currentUser()->setAccount($account);
|
|
|
|
}
|
2014-07-20 10:28:21 +00:00
|
|
|
return Settings::get('allow_authorize_operations', TRUE) && \Drupal::currentUser()->hasPermission('administer software updates');
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 09:31:37 +00:00
|
|
|
try {
|
|
|
|
$request = Request::createFromGlobals();
|
|
|
|
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
|
2019-08-12 21:45:20 +00:00
|
|
|
$kernel->boot();
|
|
|
|
// A route is required for route matching.
|
|
|
|
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
|
|
|
|
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
|
|
|
|
$kernel->preHandle($request);
|
|
|
|
// Ensure our request includes the session if appropriate.
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
|
|
$request->setSession($kernel->getContainer()->get('session'));
|
|
|
|
}
|
2014-11-21 09:31:37 +00:00
|
|
|
}
|
|
|
|
catch (HttpExceptionInterface $e) {
|
|
|
|
$response = new Response('', $e->getStatusCode());
|
|
|
|
$response->prepare($request)->send();
|
|
|
|
exit;
|
|
|
|
}
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
// We have to enable the user and system modules, even to check access and
|
2011-09-24 20:44:06 +00:00
|
|
|
// display errors via the maintenance theme.
|
Issue #340723 by ParisLiakos, sun, Berdir, glennpratt, Cottser, swentel, alexpott, tstoeckler, Xano, tim.plunkett, BassistJimmyJam | beejeebus: Make modules and installation profiles only require .info.yml files.
2014-03-17 14:43:29 +00:00
|
|
|
\Drupal::moduleHandler()->addModule('system', 'core/modules/system');
|
|
|
|
\Drupal::moduleHandler()->addModule('user', 'core/modules/user');
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::moduleHandler()->load('system');
|
|
|
|
\Drupal::moduleHandler()->load('user');
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
// Initialize the maintenance theme for this administrative script.
|
|
|
|
drupal_maintenance_theme();
|
|
|
|
|
2014-11-23 10:04:08 +00:00
|
|
|
$content = [];
|
2009-10-15 21:19:31 +00:00
|
|
|
$show_messages = TRUE;
|
|
|
|
|
2015-06-23 16:24:29 +00:00
|
|
|
$is_allowed = authorize_access_allowed($request);
|
|
|
|
|
|
|
|
// Build content.
|
|
|
|
if ($is_allowed) {
|
2009-10-15 21:19:31 +00:00
|
|
|
// Load both the Form API and Batch API.
|
2013-05-09 09:25:10 +00:00
|
|
|
require_once __DIR__ . '/includes/form.inc';
|
|
|
|
require_once __DIR__ . '/includes/batch.inc';
|
2009-10-15 21:19:31 +00:00
|
|
|
|
2020-02-20 21:38:33 +00:00
|
|
|
$page_title = $request->getSession()->get('authorize_page_title', t('Authorize file system changes'));
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
// See if we've run the operation and need to display a report.
|
2020-02-20 21:38:33 +00:00
|
|
|
if ($results = $request->getSession()->remove('authorize_results')) {
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
// Clear the session out.
|
2020-02-20 21:38:33 +00:00
|
|
|
$request->getSession()->remove('authorize_operation');
|
|
|
|
$request->getSession()->remove('authorize_filetransfer_info');
|
2009-10-15 21:19:31 +00:00
|
|
|
|
|
|
|
if (!empty($results['page_title'])) {
|
2014-03-04 17:54:37 +00:00
|
|
|
$page_title = $results['page_title'];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
if (!empty($results['page_message'])) {
|
2018-01-22 15:28:16 +00:00
|
|
|
\Drupal::messenger()->addMessage($results['page_message']['message'], $results['page_message']['type']);
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 01:20:24 +00:00
|
|
|
$content['authorize_report'] = [
|
2014-02-06 17:19:40 +00:00
|
|
|
'#theme' => 'authorize_report',
|
|
|
|
'#messages' => $results['messages'],
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2010-01-30 07:59:26 +00:00
|
|
|
|
2009-10-15 21:19:31 +00:00
|
|
|
if (is_array($results['tasks'])) {
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
$links = $results['tasks'];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
2010-11-30 06:19:47 +00:00
|
|
|
else {
|
Issue #2829185 by vaplas, Jo Fitzgerald, anmolgoyal74, chipway, gaurav.kapoor, mark_fullmer, amit.drupal, cilefen, longwave, xjm, wturrell, anavarre: Fix spelling errors in Drupal core comments
2018-09-20 16:12:38 +00:00
|
|
|
// Since this is being called outside of the primary front controller,
|
Issue #1885564 by joelpittet, SebCorbin, Cottser, mpdonadio, David_Rothstein, drupalninja99, jenlampton, lauriii, rteijeiro, mbrett5062, akalata, Devin Carlson, trevorkjorlien, longwave, socketwench, shanethehat, aboros: theme.maintenance.inc (authorize.php) - Convert theme_ functions to Twig
2015-08-11 22:54:49 +00:00
|
|
|
// the base_url needs to be set explicitly to ensure that links are
|
|
|
|
// relative to the site root.
|
|
|
|
// @todo Simplify with https://www.drupal.org/node/2548095
|
|
|
|
$default_options = [
|
|
|
|
'#type' => 'link',
|
|
|
|
'#options' => [
|
|
|
|
'absolute' => TRUE,
|
|
|
|
'base_url' => $GLOBALS['base_url'],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$links = [
|
|
|
|
$default_options + [
|
|
|
|
'#url' => Url::fromRoute('system.admin'),
|
|
|
|
'#title' => t('Administration pages'),
|
|
|
|
],
|
|
|
|
$default_options + [
|
|
|
|
'#url' => Url::fromRoute('<front>'),
|
|
|
|
'#title' => t('Front page'),
|
|
|
|
],
|
|
|
|
];
|
2010-11-30 06:19:47 +00:00
|
|
|
}
|
2011-09-10 15:37:08 +00:00
|
|
|
|
2017-03-04 01:20:24 +00:00
|
|
|
$content['next_steps'] = [
|
2014-02-06 17:19:40 +00:00
|
|
|
'#theme' => 'item_list',
|
|
|
|
'#items' => $links,
|
|
|
|
'#title' => t('Next steps'),
|
2017-03-04 01:20:24 +00:00
|
|
|
];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
// If a batch is running, let it run.
|
2013-09-15 06:52:34 +00:00
|
|
|
elseif ($request->query->has('batch')) {
|
Issue #2042447 by David_Rothstein, joelpittet, stefan.r, SebCorbin, mpdonadio, steinmb, webchick, Cottser, miniwebs2, Vj, Gilbert Rehling, nuwe, yched, StuartJNCC, Fabianx, yktdan, herom: Install a module user interface does not install modules (or themes)
2015-08-07 09:02:58 +00:00
|
|
|
$content = _batch_page($request);
|
|
|
|
// If _batch_page() returns a response object (likely a JsonResponse for
|
|
|
|
// JavaScript-based batch processing), send it immediately.
|
|
|
|
if ($content instanceof Response) {
|
|
|
|
$content->send();
|
|
|
|
exit;
|
|
|
|
}
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-20 21:38:33 +00:00
|
|
|
if (!$request->getSession()->has('authorize_operation') || !$request->getSession()->has('authorize_filetransfer_info')) {
|
2014-11-23 10:04:08 +00:00
|
|
|
$content = ['#markup' => t('It appears you have reached this page in error.')];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
elseif (!$batch = batch_get()) {
|
|
|
|
// We have a batch to process, show the filetransfer form.
|
2016-05-16 12:05:48 +00:00
|
|
|
try {
|
|
|
|
$content = \Drupal::formBuilder()->getForm('Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm');
|
|
|
|
}
|
|
|
|
catch (EnforcedResponseException $e) {
|
|
|
|
$e->getResponse()->send();
|
|
|
|
exit;
|
|
|
|
}
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// We defer the display of messages until all operations are done.
|
|
|
|
$show_messages = !(($batch = batch_get()) && isset($batch['running']));
|
|
|
|
}
|
|
|
|
else {
|
2014-06-26 18:55:12 +00:00
|
|
|
\Drupal::logger('access denied')->warning('authorize.php');
|
2014-03-04 17:54:37 +00:00
|
|
|
$page_title = t('Access denied');
|
2014-11-23 10:04:08 +00:00
|
|
|
$content = ['#markup' => t('You are not allowed to access this page.')];
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 16:24:29 +00:00
|
|
|
$bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
|
2017-03-04 01:20:24 +00:00
|
|
|
$response = $bare_html_page_renderer->renderBarePage($content, $page_title, 'maintenance_page', [
|
2015-06-23 16:24:29 +00:00
|
|
|
'#show_messages' => $show_messages,
|
2017-03-04 01:20:24 +00:00
|
|
|
]);
|
2015-06-23 16:24:29 +00:00
|
|
|
if (!$is_allowed) {
|
|
|
|
$response->setStatusCode(403);
|
2009-10-15 21:19:31 +00:00
|
|
|
}
|
2015-06-23 16:24:29 +00:00
|
|
|
$response->send();
|