repairconfig.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Repair;
  23. use OC\Hooks\BasicEmitter;
  24. use OC\RepairStep;
  25. use Sabre\DAV\Exception;
  26. /**
  27. * Class RepairConfig
  28. *
  29. * @package OC\Repair
  30. */
  31. class RepairConfig extends BasicEmitter implements RepairStep {
  32. /**
  33. * @return string
  34. */
  35. public function getName() {
  36. return 'Repair config';
  37. }
  38. /**
  39. * Updates the configuration after running an update
  40. */
  41. public function run() {
  42. $this->addSecret();
  43. $this->removePortsFromTrustedDomains();
  44. }
  45. /**
  46. * Adds a secret to config.php
  47. */
  48. private function addSecret() {
  49. if(\OC::$server->getConfig()->getSystemValue('secret', null) === null) {
  50. $secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
  51. \OC::$server->getConfig()->setSystemValue('secret', $secret);
  52. }
  53. }
  54. /**
  55. * Remove ports from existing trusted domains in config.php
  56. */
  57. private function removePortsFromTrustedDomains() {
  58. $trustedDomains = \OC::$server->getConfig()->getSystemValue('trusted_domains', array());
  59. $newTrustedDomains = array();
  60. foreach($trustedDomains as $domain) {
  61. $pos = strrpos($domain, ':');
  62. if ($pos !== false) {
  63. $port = substr($domain, $pos + 1);
  64. if (is_numeric($port)) {
  65. $domain = substr($domain, 0, $pos);
  66. }
  67. }
  68. $newTrustedDomains[] = $domain;
  69. }
  70. \OC::$server->getConfig()->setSystemValue('trusted_domains', $newTrustedDomains);
  71. }
  72. }