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