2013-09-10 20:19:42 +02:00
|
|
|
<?php
|
2024-05-27 10:08:53 +02:00
|
|
|
|
2013-10-02 18:23:47 +02:00
|
|
|
/**
|
2024-05-27 10:08:53 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-10-02 18:23:47 +02:00
|
|
|
*/
|
2016-01-20 10:20:36 +01:00
|
|
|
namespace OC\Core\Controller;
|
2013-09-10 20:19:42 +02:00
|
|
|
|
2015-03-10 23:44:29 +01:00
|
|
|
use OC\Setup;
|
2025-03-13 08:55:37 +01:00
|
|
|
use OCP\IInitialStateService;
|
|
|
|
use OCP\IURLGenerator;
|
2025-02-25 18:44:02 +01:00
|
|
|
use OCP\Template\ITemplateManager;
|
2023-09-19 10:50:16 +02:00
|
|
|
use OCP\Util;
|
2023-09-21 17:25:52 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2014-10-27 12:51:26 +01:00
|
|
|
|
2016-01-20 10:20:36 +01:00
|
|
|
class SetupController {
|
2022-04-12 17:55:01 +02:00
|
|
|
private string $autoConfigFile;
|
2014-11-18 23:47:00 +01:00
|
|
|
|
2023-06-20 11:47:04 +03:30
|
|
|
public function __construct(
|
|
|
|
protected Setup $setupHelper,
|
2023-09-21 17:25:52 +02:00
|
|
|
protected LoggerInterface $logger,
|
2025-02-25 18:44:02 +01:00
|
|
|
protected ITemplateManager $templateManager,
|
2025-03-13 08:55:37 +01:00
|
|
|
protected IInitialStateService $initialStateService,
|
|
|
|
protected IURLGenerator $urlGenerator,
|
2023-06-20 11:47:04 +03:30
|
|
|
) {
|
2016-08-02 15:28:19 +02:00
|
|
|
$this->autoConfigFile = \OC::$configDir . 'autoconfig.php';
|
2014-10-27 12:51:26 +01:00
|
|
|
}
|
|
|
|
|
2022-04-12 17:55:01 +02:00
|
|
|
public function run(array $post): void {
|
2013-09-10 20:19:42 +02:00
|
|
|
// Check for autosetup:
|
|
|
|
$post = $this->loadAutoConfig($post);
|
2015-03-10 23:44:29 +01:00
|
|
|
$opts = $this->setupHelper->getSystemInfo();
|
2013-09-10 20:19:42 +02:00
|
|
|
|
2015-03-07 13:10:43 +00:00
|
|
|
// convert 'abcpassword' to 'abcpass'
|
|
|
|
if (isset($post['adminpassword'])) {
|
|
|
|
$post['adminpass'] = $post['adminpassword'];
|
|
|
|
}
|
|
|
|
if (isset($post['dbpassword'])) {
|
|
|
|
$post['dbpass'] = $post['dbpassword'];
|
|
|
|
}
|
|
|
|
|
2021-06-19 21:06:57 +01:00
|
|
|
if (!$this->setupHelper->canInstallFileExists()) {
|
2019-04-04 23:32:00 +02:00
|
|
|
$this->displaySetupForbidden();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-05 15:12:57 +02:00
|
|
|
if (isset($post['install']) and $post['install'] == 'true') {
|
2013-09-10 20:19:42 +02:00
|
|
|
// We have to launch the installation process :
|
2015-03-10 23:44:29 +01:00
|
|
|
$e = $this->setupHelper->install($post);
|
2020-03-26 09:30:18 +01:00
|
|
|
$errors = ['errors' => $e];
|
2013-09-10 20:19:42 +02:00
|
|
|
|
|
|
|
if (count($e) > 0) {
|
2014-03-13 20:05:11 +01:00
|
|
|
$options = array_merge($opts, $post, $errors);
|
2013-09-10 20:19:42 +02:00
|
|
|
$this->display($options);
|
2014-09-22 19:43:55 +02:00
|
|
|
} else {
|
2022-01-14 19:32:10 +00:00
|
|
|
$this->finishSetup();
|
2013-09-10 20:19:42 +02:00
|
|
|
}
|
2014-09-22 19:43:55 +02:00
|
|
|
} else {
|
2014-03-13 20:05:11 +01:00
|
|
|
$options = array_merge($opts, $post);
|
|
|
|
$this->display($options);
|
2013-09-10 20:19:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 17:25:52 +02:00
|
|
|
private function displaySetupForbidden(): void {
|
2025-02-25 18:44:02 +01:00
|
|
|
$this->templateManager->printGuestPage('', 'installation_forbidden');
|
2019-04-04 23:32:00 +02:00
|
|
|
}
|
|
|
|
|
2025-02-25 18:44:02 +01:00
|
|
|
public function display(array $post): void {
|
2020-03-26 09:30:18 +01:00
|
|
|
$defaults = [
|
2014-01-31 16:57:49 +01:00
|
|
|
'adminlogin' => '',
|
|
|
|
'adminpass' => '',
|
|
|
|
'dbuser' => '',
|
|
|
|
'dbpass' => '',
|
|
|
|
'dbname' => '',
|
|
|
|
'dbtablespace' => '',
|
2014-07-04 13:24:00 +02:00
|
|
|
'dbhost' => 'localhost',
|
2014-03-13 20:05:11 +01:00
|
|
|
'dbtype' => '',
|
2025-03-13 08:55:37 +01:00
|
|
|
'hasAutoconfig' => false,
|
|
|
|
'serverRoot' => \OC::$SERVERROOT,
|
2020-03-26 09:30:18 +01:00
|
|
|
];
|
2014-01-31 16:57:49 +01:00
|
|
|
$parameters = array_merge($defaults, $post);
|
2014-01-31 16:43:12 +01:00
|
|
|
|
2023-09-19 10:50:16 +02:00
|
|
|
Util::addStyle('server', null);
|
|
|
|
|
|
|
|
// include common nextcloud webpack bundle
|
|
|
|
Util::addScript('core', 'common');
|
|
|
|
Util::addScript('core', 'main');
|
2025-03-13 08:55:37 +01:00
|
|
|
Util::addScript('core', 'install');
|
2023-09-19 10:50:16 +02:00
|
|
|
Util::addTranslations('core');
|
|
|
|
|
2025-03-13 08:55:37 +01:00
|
|
|
$this->initialStateService->provideInitialState('core', 'config', $parameters);
|
|
|
|
$this->initialStateService->provideInitialState('core', 'data', false);
|
|
|
|
$this->initialStateService->provideInitialState('core', 'links', [
|
|
|
|
'adminInstall' => $this->urlGenerator->linkToDocs('admin-install'),
|
|
|
|
'adminSourceInstall' => $this->urlGenerator->linkToDocs('admin-source_install'),
|
|
|
|
'adminDBConfiguration' => $this->urlGenerator->linkToDocs('admin-db-configuration'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->templateManager->printGuestPage('', 'installation');
|
2013-09-10 20:19:42 +02:00
|
|
|
}
|
|
|
|
|
2023-09-21 17:25:52 +02:00
|
|
|
private function finishSetup(): void {
|
2020-04-09 16:07:47 +02:00
|
|
|
if (file_exists($this->autoConfigFile)) {
|
2014-11-18 23:47:00 +01:00
|
|
|
unlink($this->autoConfigFile);
|
|
|
|
}
|
2016-01-22 11:49:28 +01:00
|
|
|
\OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
|
2019-04-04 23:32:00 +02:00
|
|
|
|
2021-06-19 21:06:57 +01:00
|
|
|
if ($this->setupHelper->shouldRemoveCanInstallFile()) {
|
2025-02-25 18:44:02 +01:00
|
|
|
$this->templateManager->printGuestPage('', 'installation_incomplete');
|
2019-04-04 23:32:00 +02:00
|
|
|
}
|
|
|
|
|
2022-01-14 19:32:10 +00:00
|
|
|
header('Location: ' . \OC::$server->getURLGenerator()->getAbsoluteURL('index.php/core/apps/recommended'));
|
|
|
|
exit();
|
2013-09-10 20:19:42 +02:00
|
|
|
}
|
|
|
|
|
2025-02-17 18:06:45 +01:00
|
|
|
/**
|
|
|
|
* @psalm-taint-escape file we trust file path given in POST for setup
|
|
|
|
*/
|
2022-04-12 17:55:01 +02:00
|
|
|
public function loadAutoConfig(array $post): array {
|
2020-04-09 16:07:47 +02:00
|
|
|
if (file_exists($this->autoConfigFile)) {
|
2023-09-21 17:25:52 +02:00
|
|
|
$this->logger->info('Autoconfig file found, setting up Nextcloud…');
|
2020-03-26 09:30:18 +01:00
|
|
|
$AUTOCONFIG = [];
|
2014-11-18 23:47:00 +01:00
|
|
|
include $this->autoConfigFile;
|
2025-03-13 08:55:37 +01:00
|
|
|
$post['hasAutoconfig'] = count($AUTOCONFIG) > 0;
|
2020-04-09 16:05:56 +02:00
|
|
|
$post = array_merge($post, $AUTOCONFIG);
|
2013-09-10 20:19:42 +02:00
|
|
|
}
|
2014-01-31 16:43:12 +01:00
|
|
|
|
2014-02-05 18:23:40 +01:00
|
|
|
$dbIsSet = isset($post['dbtype']);
|
|
|
|
$directoryIsSet = isset($post['directory']);
|
|
|
|
$adminAccountIsSet = isset($post['adminlogin']);
|
|
|
|
|
2020-04-09 14:04:56 +02:00
|
|
|
if ($dbIsSet and $directoryIsSet and $adminAccountIsSet) {
|
2014-01-31 16:43:12 +01:00
|
|
|
$post['install'] = 'true';
|
|
|
|
}
|
|
|
|
|
2013-09-10 20:19:42 +02:00
|
|
|
return $post;
|
|
|
|
}
|
|
|
|
}
|