CheckApp.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\Integrity;
  8. use OC\Core\Command\Base;
  9. use OC\IntegrityCheck\Checker;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. /**
  15. * Class CheckApp
  16. *
  17. * @package OC\Core\Command\Integrity
  18. */
  19. class CheckApp extends Base {
  20. public function __construct(
  21. private Checker $checker,
  22. ) {
  23. parent::__construct();
  24. }
  25. /**
  26. * {@inheritdoc }
  27. */
  28. protected function configure() {
  29. parent::configure();
  30. $this
  31. ->setName('integrity:check-app')
  32. ->setDescription('Check integrity of an app using a signature.')
  33. ->addArgument('appid', InputArgument::REQUIRED, 'Application to check')
  34. ->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Path to application. If none is given it will be guessed.');
  35. }
  36. /**
  37. * {@inheritdoc }
  38. */
  39. protected function execute(InputInterface $input, OutputInterface $output): int {
  40. $appid = $input->getArgument('appid');
  41. $path = (string)$input->getOption('path');
  42. $result = $this->checker->verifyAppSignature($appid, $path, true);
  43. $this->writeArrayInOutputFormat($input, $output, $result);
  44. if (count($result) > 0) {
  45. $output->writeln('<error>' . count($result) . ' errors found</error>', OutputInterface::VERBOSITY_VERBOSE);
  46. return 1;
  47. }
  48. $output->writeln('<info>No errors found</info>', OutputInterface::VERBOSITY_VERBOSE);
  49. return 0;
  50. }
  51. }