|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr> |
| 7 | + * |
| 8 | + * @author Thomas Citharel <nextcloud@tcit.fr> |
| 9 | + * |
| 10 | + * @license GNU AGPL version 3 or any later version |
| 11 | + * |
| 12 | + * This program is free software: you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU Affero General Public License as |
| 14 | + * published by the Free Software Foundation, either version 3 of the |
| 15 | + * License, or (at your option) any later version. |
| 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 |
| 23 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | + * |
| 25 | + */ |
| 26 | +namespace OC\Repair\NC25; |
| 27 | + |
| 28 | +use OC\Authentication\Token\TokenCleanupJob; |
| 29 | +use OCP\HintException; |
| 30 | +use OCP\IConfig; |
| 31 | +use OCP\Migration\IOutput; |
| 32 | +use OCP\Migration\IRepairStep; |
| 33 | +use OCP\Security\ISecureRandom; |
| 34 | + |
| 35 | +class AddMissingSecretJob implements IRepairStep { |
| 36 | + private IConfig $config; |
| 37 | + private ISecureRandom $random; |
| 38 | + |
| 39 | + public function __construct(IConfig $config, ISecureRandom $random) { |
| 40 | + $this->config = $config; |
| 41 | + $this->random = $random; |
| 42 | + } |
| 43 | + |
| 44 | + public function getName(): string { |
| 45 | + return 'Add possibly missing system config'; |
| 46 | + } |
| 47 | + |
| 48 | + public function run(IOutput $output): void { |
| 49 | + $passwordSalt = $this->config->getSystemValue('passwordsalt', null); |
| 50 | + if ($passwordSalt === null) { |
| 51 | + try { |
| 52 | + $this->config->setSystemValue('passwordsalt', $this->random->generate(30)); |
| 53 | + } catch (HintException $e) { |
| 54 | + $output->warning("passwordsalt is missing from your config.php and your config.php is read only. Please fix it manually."); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + $secret = $this->config->getSystemValue('secret', null); |
| 59 | + if ($secret === null) { |
| 60 | + try { |
| 61 | + $this->config->setSystemValue('secret', $this->random->generate(48)); |
| 62 | + } catch (HintException $e) { |
| 63 | + $output->warning("secret is missing from your config.php and your config.php is read only. Please fix it manually."); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments