Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: Add details to CodeIntegrity setup check #43575

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/settings/css/settings.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/css/settings.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions apps/settings/css/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,9 @@ doesnotexist:-o-prefocus, .strengthify-wrapper {
}

.trusted-domain-warning {
color: #fff;
color: var(--color-main-text);
padding: 5px;
background: #ce3702;
background: var(--color-error);
border-radius: 5px;
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}
Expand All @@ -1270,6 +1270,7 @@ doesnotexist:-o-prefocus, .strengthify-wrapper {

li {
margin: 10px 0;
white-space: pre-wrap;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@come-nc this one is for the admin settings page to show the output correctly.

}

ul {
Expand Down
32 changes: 1 addition & 31 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,37 +124,7 @@ public function getFailedIntegrityCheckFiles(): DataDisplayResponse {
$completeResults = $this->checker->getResults();

if (!empty($completeResults)) {
$formattedTextResponse = 'Technical information
=====================
The following list covers which files have failed the integrity check. Please read
the previous linked documentation to learn more about the errors and how to fix
them.

Results
=======
';
foreach ($completeResults as $context => $contextResult) {
$formattedTextResponse .= "- $context\n";

foreach ($contextResult as $category => $result) {
$formattedTextResponse .= "\t- $category\n";
if ($category !== 'EXCEPTION') {
foreach ($result as $key => $results) {
$formattedTextResponse .= "\t\t- $key\n";
}
} else {
foreach ($result as $key => $results) {
$formattedTextResponse .= "\t\t- $results\n";
}
}
}
}

$formattedTextResponse .= '
Raw output
==========
';
$formattedTextResponse .= print_r($completeResults, true);
$formattedTextResponse = json_encode($completeResults, JSON_PRETTY_PRINT);
} else {
$formattedTextResponse = 'No errors have been found.';
}
Expand Down
41 changes: 36 additions & 5 deletions apps/settings/lib/SetupChecks/CodeIntegrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,51 @@ public function run(): SetupResult {
} elseif ($this->checker->hasPassedCheck()) {
return SetupResult::success($this->l10n->t('No altered files'));
} else {
$completeResults = $this->checker->getResults();
$formattedTextResponse = '';
if (!empty($completeResults)) {
$formattedTextResponse = '#### ' . $this->l10n->t('Technical information');
$formattedTextResponse .= "\n" . $this->l10n->t('The following list covers which files have failed the integrity check.');
$formattedTextResponse .= "\n";
foreach ($completeResults as $context => $contextResult) {
$formattedTextResponse .= "- $context\n";

foreach ($contextResult as $category => $result) {
$categoryName = match($category) {
'EXCEPTION' => $this->l10n->t('Exception'),
'EXTRA_FILE' => $this->l10n->t('Unexpected file'),
'FILE_MISSING' => $this->l10n->t('Missing file'),
'INVALID_HASH' => $this->l10n->t('Invalid file (hash mismatch)'),
default => $category,
};
$formattedTextResponse .= "\t- $categoryName\n";
if ($category !== 'EXCEPTION') {
foreach ($result as $key => $results) {
$formattedTextResponse .= "\t\t- $key\n";
}
} else {
foreach ($result as $key => $results) {
$formattedTextResponse .= "\t\t- $results\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should $results be escaped for markdown special chars?

Also, these complete results will show in occ setupchecks output and in standard admin page, no?
Should we add there some special handling to see double new-line as an end of summary?

}
}
}
}
}

return SetupResult::error(
$this->l10n->t('Some files have not passed the integrity check. {link1} {link2}'),
$this->l10n->t('Some files have not passed the integrity check. {rawOutput} {rescan}') . "\n\n" . $formattedTextResponse,
$this->urlGenerator->linkToDocs('admin-code-integrity'),
[
'link1' => [
'rawOutput' => [
'type' => 'highlight',
'id' => 'getFailedIntegrityCheckFiles',
'name' => 'List of invalid files…',
'name' => $this->l10n->t('Raw output…'),
'link' => $this->urlGenerator->linkToRoute('settings.CheckSetup.getFailedIntegrityCheckFiles'),
],
'link2' => [
'rescan' => [
'type' => 'highlight',
'id' => 'rescanFailedIntegrityCheck',
'name' => 'Rescan…',
'name' => $this->l10n->t('Rescan…'),
'link' => $this->urlGenerator->linkToRoute('settings.CheckSetup.rescanFailedIntegrityCheck'),
],
],
Expand Down
Loading