ResetToken.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  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 OCA\UpdateNotification\BackgroundJob;
  27. use OCP\AppFramework\Utility\ITimeFactory;
  28. use OCP\BackgroundJob\TimedJob;
  29. use OCP\IAppConfig;
  30. use OCP\IConfig;
  31. /**
  32. * Deletes the updater secret after if it is older than 48h
  33. */
  34. class ResetToken extends TimedJob {
  35. /**
  36. * @param IConfig $config
  37. * @param ITimeFactory $timeFactory
  38. */
  39. public function __construct(
  40. ITimeFactory $time,
  41. private IConfig $config,
  42. private IAppConfig $appConfig,
  43. ) {
  44. parent::__construct($time);
  45. // Run all 10 minutes
  46. parent::setInterval(60 * 10);
  47. }
  48. /**
  49. * @param $argument
  50. */
  51. protected function run($argument) {
  52. if ($this->config->getSystemValueBool('config_is_read_only')) {
  53. return;
  54. }
  55. $secretCreated = $this->appConfig->getValueInt('core', 'updater.secret.created', $this->time->getTime());
  56. // Delete old tokens after 2 days
  57. if ($secretCreated >= 172800) {
  58. $this->config->deleteSystemValue('updater.secret');
  59. }
  60. }
  61. }