CheckCore.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Carla Schroder <carla@owncloud.com>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\Core\Command\Integrity;
  27. use OC\Core\Command\Base;
  28. use OC\IntegrityCheck\Checker;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. /**
  32. * Class CheckCore
  33. *
  34. * @package OC\Core\Command\Integrity
  35. */
  36. class CheckCore extends Base {
  37. public function __construct(
  38. private Checker $checker,
  39. ) {
  40. parent::__construct();
  41. }
  42. /**
  43. * {@inheritdoc }
  44. */
  45. protected function configure() {
  46. parent::configure();
  47. $this
  48. ->setName('integrity:check-core')
  49. ->setDescription('Check integrity of core code using a signature.');
  50. }
  51. /**
  52. * {@inheritdoc }
  53. */
  54. protected function execute(InputInterface $input, OutputInterface $output): int {
  55. if (!$this->checker->isCodeCheckEnforced()) {
  56. $output->writeln('<comment>integrity:check-core can not be used on git checkouts</comment>');
  57. return 2;
  58. }
  59. $result = $this->checker->verifyCoreSignature();
  60. $this->writeArrayInOutputFormat($input, $output, $result);
  61. if (count($result) > 0) {
  62. $output->writeln('<error>' . count($result) . ' errors found</error>', OutputInterface::VERBOSITY_VERBOSE);
  63. return 1;
  64. }
  65. $output->writeln('<info>No errors found</info>', OutputInterface::VERBOSITY_VERBOSE);
  66. return 0;
  67. }
  68. }