Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
30 / 30 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| PopplerSetupCheck | |
100.00% |
30 / 30 |
|
100.00% |
6 / 6 |
16 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCategory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| run | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
5 | |||
| checkPdfSig | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| checkPdfinfo | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\SetupCheck; |
| 10 | |
| 11 | use OCP\IL10N; |
| 12 | use OCP\SetupCheck\ISetupCheck; |
| 13 | use OCP\SetupCheck\SetupResult; |
| 14 | |
| 15 | class PopplerSetupCheck implements ISetupCheck { |
| 16 | private IL10N $l10n; |
| 17 | |
| 18 | public function __construct(IL10N $l10n) { |
| 19 | $this->l10n = $l10n; |
| 20 | } |
| 21 | |
| 22 | #[\Override] |
| 23 | public function getName(): string { |
| 24 | return 'Poppler utils'; |
| 25 | } |
| 26 | |
| 27 | #[\Override] |
| 28 | public function getCategory(): string { |
| 29 | return 'system'; |
| 30 | } |
| 31 | |
| 32 | #[\Override] |
| 33 | public function run(): SetupResult { |
| 34 | $pdfsigOk = $this->checkPdfSig(); |
| 35 | $pdfinfoOk = $this->checkPdfinfo(); |
| 36 | |
| 37 | if ($pdfsigOk && $pdfinfoOk) { |
| 38 | return SetupResult::success( |
| 39 | // TRANSLATORS %s is the pdfsig version, the second %s is the pdfinfo version detected on the server. |
| 40 | $this->l10n->t('pdfsig version: %s, pdfinfo version: %s', [$pdfsigOk, $pdfinfoOk]) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | $messages = []; |
| 45 | // TRANSLATORS Hint shown to the administrator when poppler-utils is not installed on the server. |
| 46 | $tip = $this->l10n->t('Install the package poppler-utils on your operating system to enable PDF signature validation and page dimension detection.'); |
| 47 | |
| 48 | if (!$pdfsigOk) { |
| 49 | // TRANSLATORS Shown when the pdfsig binary from poppler-utils is missing or not working. |
| 50 | $messages[] = $this->l10n->t('pdfsig not installed or not working'); |
| 51 | } |
| 52 | if (!$pdfinfoOk) { |
| 53 | // TRANSLATORS Shown when the pdfinfo binary from poppler-utils is missing or not working. |
| 54 | $messages[] = $this->l10n->t('pdfinfo not installed or not working'); |
| 55 | } |
| 56 | |
| 57 | // Since Poppler is optional, return info instead of error |
| 58 | return SetupResult::info(implode('; ', $messages), $tip); |
| 59 | } |
| 60 | |
| 61 | private function checkPdfSig(): ?string { |
| 62 | exec('pdfsig -v 2>&1', $output, $retval); |
| 63 | if ($retval !== 0 || empty($output)) { |
| 64 | return null; |
| 65 | } |
| 66 | $full = implode(PHP_EOL, $output); |
| 67 | if (preg_match('/pdfsig version (?<version>.*)/', $full, $matches)) { |
| 68 | return $matches['version']; |
| 69 | } |
| 70 | return null; |
| 71 | } |
| 72 | |
| 73 | private function checkPdfinfo(): ?string { |
| 74 | exec('pdfinfo -v 2>&1', $output, $retval); |
| 75 | if ($retval !== 0 || empty($output)) { |
| 76 | return null; |
| 77 | } |
| 78 | $full = implode(PHP_EOL, $output); |
| 79 | if (preg_match('/pdfinfo version (?<version>.*)/', $full, $matches)) { |
| 80 | return $matches['version']; |
| 81 | } |
| 82 | return null; |
| 83 | } |
| 84 | } |