@@ -36,116 +36,116 @@ |
||
| 36 | 36 | use OCP\ILogger; |
| 37 | 37 | |
| 38 | 38 | class SetupController { |
| 39 | - /** @var Setup */ |
|
| 40 | - protected $setupHelper; |
|
| 41 | - /** @var string */ |
|
| 42 | - private $autoConfigFile; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param Setup $setupHelper |
|
| 46 | - */ |
|
| 47 | - public function __construct(Setup $setupHelper) { |
|
| 48 | - $this->autoConfigFile = \OC::$configDir.'autoconfig.php'; |
|
| 49 | - $this->setupHelper = $setupHelper; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param $post |
|
| 54 | - */ |
|
| 55 | - public function run($post) { |
|
| 56 | - // Check for autosetup: |
|
| 57 | - $post = $this->loadAutoConfig($post); |
|
| 58 | - $opts = $this->setupHelper->getSystemInfo(); |
|
| 59 | - |
|
| 60 | - // convert 'abcpassword' to 'abcpass' |
|
| 61 | - if (isset($post['adminpassword'])) { |
|
| 62 | - $post['adminpass'] = $post['adminpassword']; |
|
| 63 | - } |
|
| 64 | - if (isset($post['dbpassword'])) { |
|
| 65 | - $post['dbpass'] = $post['dbpassword']; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if (!is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 69 | - $this->displaySetupForbidden(); |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - if (isset($post['install']) and $post['install'] == 'true') { |
|
| 74 | - // We have to launch the installation process : |
|
| 75 | - $e = $this->setupHelper->install($post); |
|
| 76 | - $errors = ['errors' => $e]; |
|
| 77 | - |
|
| 78 | - if (count($e) > 0) { |
|
| 79 | - $options = array_merge($opts, $post, $errors); |
|
| 80 | - $this->display($options); |
|
| 81 | - } else { |
|
| 82 | - $this->finishSetup(isset($post['install-recommended-apps'])); |
|
| 83 | - } |
|
| 84 | - } else { |
|
| 85 | - $options = array_merge($opts, $post); |
|
| 86 | - $this->display($options); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - private function displaySetupForbidden() { |
|
| 91 | - \OC_Template::printGuestPage('', 'installation_forbidden'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function display($post) { |
|
| 95 | - $defaults = [ |
|
| 96 | - 'adminlogin' => '', |
|
| 97 | - 'adminpass' => '', |
|
| 98 | - 'dbuser' => '', |
|
| 99 | - 'dbpass' => '', |
|
| 100 | - 'dbname' => '', |
|
| 101 | - 'dbtablespace' => '', |
|
| 102 | - 'dbhost' => 'localhost', |
|
| 103 | - 'dbtype' => '', |
|
| 104 | - ]; |
|
| 105 | - $parameters = array_merge($defaults, $post); |
|
| 106 | - |
|
| 107 | - \OC_Template::printGuestPage('', 'installation', $parameters); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - private function finishSetup(bool $installRecommended) { |
|
| 111 | - if (file_exists($this->autoConfigFile)) { |
|
| 112 | - unlink($this->autoConfigFile); |
|
| 113 | - } |
|
| 114 | - \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
|
| 115 | - |
|
| 116 | - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 117 | - if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 118 | - \OC_Template::printGuestPage('', 'installation_incomplete'); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if ($installRecommended) { |
|
| 123 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 124 | - $location = $urlGenerator->getAbsoluteURL('index.php/core/apps/recommended'); |
|
| 125 | - header('Location: ' . $location); |
|
| 126 | - exit(); |
|
| 127 | - } |
|
| 128 | - \OC_Util::redirectToDefaultPage(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function loadAutoConfig($post) { |
|
| 132 | - if (file_exists($this->autoConfigFile)) { |
|
| 133 | - \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO); |
|
| 134 | - $AUTOCONFIG = []; |
|
| 135 | - include $this->autoConfigFile; |
|
| 136 | - $post = array_merge($post, $AUTOCONFIG); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $dbIsSet = isset($post['dbtype']); |
|
| 140 | - $directoryIsSet = isset($post['directory']); |
|
| 141 | - $adminAccountIsSet = isset($post['adminlogin']); |
|
| 142 | - |
|
| 143 | - if ($dbIsSet and $directoryIsSet and $adminAccountIsSet) { |
|
| 144 | - $post['install'] = 'true'; |
|
| 145 | - } |
|
| 146 | - $post['dbIsSet'] = $dbIsSet; |
|
| 147 | - $post['directoryIsSet'] = $directoryIsSet; |
|
| 148 | - |
|
| 149 | - return $post; |
|
| 150 | - } |
|
| 39 | + /** @var Setup */ |
|
| 40 | + protected $setupHelper; |
|
| 41 | + /** @var string */ |
|
| 42 | + private $autoConfigFile; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param Setup $setupHelper |
|
| 46 | + */ |
|
| 47 | + public function __construct(Setup $setupHelper) { |
|
| 48 | + $this->autoConfigFile = \OC::$configDir.'autoconfig.php'; |
|
| 49 | + $this->setupHelper = $setupHelper; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param $post |
|
| 54 | + */ |
|
| 55 | + public function run($post) { |
|
| 56 | + // Check for autosetup: |
|
| 57 | + $post = $this->loadAutoConfig($post); |
|
| 58 | + $opts = $this->setupHelper->getSystemInfo(); |
|
| 59 | + |
|
| 60 | + // convert 'abcpassword' to 'abcpass' |
|
| 61 | + if (isset($post['adminpassword'])) { |
|
| 62 | + $post['adminpass'] = $post['adminpassword']; |
|
| 63 | + } |
|
| 64 | + if (isset($post['dbpassword'])) { |
|
| 65 | + $post['dbpass'] = $post['dbpassword']; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if (!is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 69 | + $this->displaySetupForbidden(); |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + if (isset($post['install']) and $post['install'] == 'true') { |
|
| 74 | + // We have to launch the installation process : |
|
| 75 | + $e = $this->setupHelper->install($post); |
|
| 76 | + $errors = ['errors' => $e]; |
|
| 77 | + |
|
| 78 | + if (count($e) > 0) { |
|
| 79 | + $options = array_merge($opts, $post, $errors); |
|
| 80 | + $this->display($options); |
|
| 81 | + } else { |
|
| 82 | + $this->finishSetup(isset($post['install-recommended-apps'])); |
|
| 83 | + } |
|
| 84 | + } else { |
|
| 85 | + $options = array_merge($opts, $post); |
|
| 86 | + $this->display($options); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + private function displaySetupForbidden() { |
|
| 91 | + \OC_Template::printGuestPage('', 'installation_forbidden'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function display($post) { |
|
| 95 | + $defaults = [ |
|
| 96 | + 'adminlogin' => '', |
|
| 97 | + 'adminpass' => '', |
|
| 98 | + 'dbuser' => '', |
|
| 99 | + 'dbpass' => '', |
|
| 100 | + 'dbname' => '', |
|
| 101 | + 'dbtablespace' => '', |
|
| 102 | + 'dbhost' => 'localhost', |
|
| 103 | + 'dbtype' => '', |
|
| 104 | + ]; |
|
| 105 | + $parameters = array_merge($defaults, $post); |
|
| 106 | + |
|
| 107 | + \OC_Template::printGuestPage('', 'installation', $parameters); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + private function finishSetup(bool $installRecommended) { |
|
| 111 | + if (file_exists($this->autoConfigFile)) { |
|
| 112 | + unlink($this->autoConfigFile); |
|
| 113 | + } |
|
| 114 | + \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); |
|
| 115 | + |
|
| 116 | + if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 117 | + if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { |
|
| 118 | + \OC_Template::printGuestPage('', 'installation_incomplete'); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if ($installRecommended) { |
|
| 123 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 124 | + $location = $urlGenerator->getAbsoluteURL('index.php/core/apps/recommended'); |
|
| 125 | + header('Location: ' . $location); |
|
| 126 | + exit(); |
|
| 127 | + } |
|
| 128 | + \OC_Util::redirectToDefaultPage(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function loadAutoConfig($post) { |
|
| 132 | + if (file_exists($this->autoConfigFile)) { |
|
| 133 | + \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO); |
|
| 134 | + $AUTOCONFIG = []; |
|
| 135 | + include $this->autoConfigFile; |
|
| 136 | + $post = array_merge($post, $AUTOCONFIG); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $dbIsSet = isset($post['dbtype']); |
|
| 140 | + $directoryIsSet = isset($post['directory']); |
|
| 141 | + $adminAccountIsSet = isset($post['adminlogin']); |
|
| 142 | + |
|
| 143 | + if ($dbIsSet and $directoryIsSet and $adminAccountIsSet) { |
|
| 144 | + $post['install'] = 'true'; |
|
| 145 | + } |
|
| 146 | + $post['dbIsSet'] = $dbIsSet; |
|
| 147 | + $post['directoryIsSet'] = $directoryIsSet; |
|
| 148 | + |
|
| 149 | + return $post; |
|
| 150 | + } |
|
| 151 | 151 | } |