StatusController.php in Acquia Connector 8.2
File
src/Controller/StatusController.php
View source
<?php
namespace Drupal\acquia_connector\Controller;
use Drupal\acquia_connector\Subscription;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Access\AccessResultAllowed;
use Drupal\Core\Access\AccessResultForbidden;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
class StatusController extends ControllerBase {
public function refresh() {
$subscription = new Subscription();
$subscription
->update();
return $this
->redirect('system.status');
}
public function json() {
\Drupal::service('page_cache_kill_switch')
->trigger();
$performance_config = $this
->config('system.performance');
$data = [
'version' => '1.0',
'data' => [
'maintenance_mode' => (bool) $this
->state()
->get('system.maintenance_mode'),
'cache' => $performance_config
->get('cache.page.use_internal'),
'block_cache' => FALSE,
],
];
return new JsonResponse($data);
}
public function access() {
$request = \Drupal::request();
$nonce = $request
->get('nonce', FALSE);
$connector_config = $this
->config('acquia_connector.settings');
if (!$nonce) {
return AccessResultForbidden::forbidden();
}
$sub_data = $this
->state()
->get('acquia_subscription_data');
$sub_uuid = $this
->getIdFromSub($sub_data);
if (!empty($sub_uuid)) {
$expected_hash = hash('sha1', "{$sub_uuid}:{$nonce}");
if ($request
->get('key', FALSE) === $expected_hash) {
return AccessResultAllowed::allowed();
}
}
if ($connector_config
->get('debug')) {
$info = [
'sub_data' => $sub_data,
'sub_uuid_from_data' => $sub_uuid,
'expected_hash' => $expected_hash,
'get' => $request->query
->all(),
'server' => $request->server
->all(),
'request' => $request->request
->all(),
];
$this
->getLogger('acquia_agent')
->notice('Site status request: @data', [
'@data' => var_export($info, TRUE),
]);
}
return AccessResultForbidden::forbidden();
}
public function getIdFromSub(array $sub_data) {
if (!empty($sub_data['uuid'])) {
return $sub_data['uuid'];
}
$url = UrlHelper::parse($sub_data['href']);
$parts = explode('/', $url['path']);
array_pop($parts);
return end($parts);
}
}