chg: [diagnostic] Smarter PHP extension diagnostics

pull/6605/head
Jakub Onderka 2020-11-17 13:09:32 +01:00
parent 8c87998981
commit 5a597ca3db
4 changed files with 65 additions and 36 deletions

View File

@ -5725,16 +5725,42 @@ class Server extends AppModel
public function extensionDiagnostics()
{
try {
$file = new File(APP . DS . 'composer.json');
$composer = $this->jsonDecode($file->read());
$extensions = [];
foreach ($composer['require'] as $require => $foo) {
if (substr($require, 0, 4) === 'ext-') {
$extensions[substr($require, 4)] = true;
}
}
foreach ($composer['suggest'] as $suggest => $reason) {
if (substr($suggest, 0, 4) === 'ext-') {
$extensions[substr($suggest, 4)] = $reason;
}
}
} catch (Exception $e) {
$extensions = ['redis' => '', 'gd' => '', 'ssdeep' => '', 'zip' => '', 'intl' => '']; // Default extensions
}
$results = array();
$extensions = array('redis', 'gd', 'ssdeep', 'zip', 'intl');
foreach ($extensions as $extension) {
$results['web']['extensions'][$extension] = extension_loaded($extension);
foreach ($extensions as $extension => $reason) {
$results['extensions'][$extension] = [
'loaded_web' => phpversion($extension),
'loaded_cli' => false,
'required' => $reason === true,
'info' => $reason === true ? null : $reason,
];
}
if (!is_readable(APP . '/files/scripts/selftest.php')) {
$results['cli'] = false;
} else {
$execResult = exec('php ' . APP . '/files/scripts/selftest.php');
$results['cli'] = json_decode($execResult, true);
$execResult = exec('php ' . APP . '/files/scripts/selftest.php ' . escapeshellarg(json_encode(array_keys($extensions))));
$execResult = $this->jsonDecode($execResult);
$results['cli']['phpversion'] = $execResult['phpversion'];
foreach ($execResult['extensions'] as $extension => $loaded) {
$results['extensions'][$extension]['loaded_cli'] = $loaded;
}
}
return $results;
}

View File

@ -171,29 +171,31 @@
<?php
endforeach;
?>
<h4><?php echo __('PHP Extensions');?></h4>
<?php
foreach (array('web', 'cli') as $context):
?>
<div style="background-color:#f7f7f9;width:400px;">
<b><?php echo ucfirst(h($context));?></b><br />
<?php
if (isset($extensions[$context]['extensions'])):
foreach ($extensions[$context]['extensions'] as $extension => $status):
?>
<?php echo h($extension); ?>:… <span style="color:<?php echo $status ? 'green' : 'red';?>;font-weight:bold;"><?php echo $status ? __('OK') : __('Not loaded'); ?></span><br />
<?php
endforeach;
else:
?>
<span class="red"><?php echo __('Issues reading PHP settings. This could be due to the test script not being readable.');?></span>
<?php
endif;
?>
</div><br />
<?php
endforeach;
?>
<h4><?= __('PHP Extensions') ?></h4>
<table class="table table-condensed table-bordered" style="width: 40vw">
<thead>
<tr>
<th><?= __('Extension') ?></th>
<th><?= __('Required') ?></th>
<th><?= __('Why to install') ?></th>
<th><?= __('Web') ?></th>
<th><?= __('CLI') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($extensions['extensions'] as $extension => $info): ?>
<tr>
<td class="bold"><?= h($extension) ?></td>
<td><?= $info['required'] ? '<i class="black fa fa-check" role="img" aria-label="' . __('Yes') . '"></i>' : '<i class="black fa fa-times" role="img" aria-label="' . __('No') . '"></i>' ?></td>
<td><?= $info['info'] ?></td>
<?php foreach (['loaded_web', 'loaded_cli'] as $type): ?>
<td><?= $info[$type] ? '<i class="green fa fa-check" role="img" aria-label="' . __('Yes') . '"></i> (' . h($info[$type]) .')' : '<i class="red fa fa-times" role="img" aria-label="' . __('No') . '"></i>' ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
echo '<div style="width:400px;">';
echo $this->element('/genericElements/IndexTable/index_table', array(

View File

@ -16,11 +16,14 @@
"php-parallel-lint/php-parallel-lint": "^1.2"
},
"suggest": {
"ext-openssl": "Enabling the openssl extension allows you to access https URLs",
"ext-redis": "For working background jobs and feed and warninglist chaches",
"ext-gd": "For creating image thumbnails",
"ext-openssl": "Enabling the openssl extension allows you to access HTTPS URLs",
"ext-redis": "For working background jobs and feed and warninglist caches",
"ext-zip": "Enabling processing feeds that are ZIP compressed",
"ext-zlib": "Allow gzip compression of HTTP requests",
"ext-zlib": "Allow gzip compression of HTTP responses",
"ext-intl": "For handling IDN domain names",
"ext-ssdeep": "For ssdeep hashes correlation",
"ext-bcmath": "For faster validating IBAN numbers",
"elasticsearch/elasticsearch": "For logging to elasticsearch",
"aws/aws-sdk-php": "To upload samples to S3"
},

View File

@ -1,8 +1,6 @@
<?php
$extensions = array('redis', 'gd', 'ssdeep', 'zip', 'intl');
$results = array();
$results['phpversion'] = phpversion();
foreach ($extensions as $extension) {
$results['extensions'][$extension] = extension_loaded($extension);
$results = ['phpversion' => phpversion()];
foreach (json_decode($argv[1], true) as $extension) {
$results['extensions'][$extension] = phpversion($extension);
}
echo json_encode($results);