Passed
Push — master ( aac22b...ef06c3 )
by Morris
13:14 queued 12s
created

SetupController::displaySetupForbidden()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Damjan Georgievski <[email protected]>
7
 * @author ideaship <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 * @author Robin Appelman <[email protected]>
11
 * @author Robin McCorkell <[email protected]>
12
 * @author Thomas Müller <[email protected]>
13
 *
14
 * @license AGPL-3.0
15
 *
16
 * This code is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License, version 3,
18
 * as published by the Free Software Foundation.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License, version 3,
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
27
 *
28
 */
29
30
namespace OC\Core\Controller;
31
32
use OC\Setup;
33
use OCP\ILogger;
34
35
class SetupController {
36
	/** @var Setup */
37
	protected $setupHelper;
38
	/** @var string */
39
	private $autoConfigFile;
40
41
	/**
42
	 * @param Setup $setupHelper
43
	 */
44
	function __construct(Setup $setupHelper) {
45
		$this->autoConfigFile = \OC::$configDir.'autoconfig.php';
46
		$this->setupHelper = $setupHelper;
47
	}
48
49
	/**
50
	 * @param $post
51
	 */
52
	public function run($post) {
53
		// Check for autosetup:
54
		$post = $this->loadAutoConfig($post);
55
		$opts = $this->setupHelper->getSystemInfo();
56
57
		// convert 'abcpassword' to 'abcpass'
58
		if (isset($post['adminpassword'])) {
59
			$post['adminpass'] = $post['adminpassword'];
60
		}
61
		if (isset($post['dbpassword'])) {
62
			$post['dbpass'] = $post['dbpassword'];
63
		}
64
65
		if (!is_file(\OC::$configDir.'/CAN_INSTALL')) {
66
			$this->displaySetupForbidden();
67
			return;
68
		}
69
70
		if(isset($post['install']) AND $post['install']=='true') {
71
			// We have to launch the installation process :
72
			$e = $this->setupHelper->install($post);
73
			$errors = array('errors' => $e);
74
75
			if(count($e) > 0) {
76
				$options = array_merge($opts, $post, $errors);
77
				$this->display($options);
78
			} else {
79
				$this->finishSetup();
80
			}
81
		} else {
82
			$options = array_merge($opts, $post);
83
			$this->display($options);
84
		}
85
	}
86
87
	private function displaySetupForbidden() {
88
		\OC_Template::printGuestPage('', 'installation_forbidden');
89
	}
90
91
	public function display($post) {
92
		$defaults = array(
93
			'adminlogin' => '',
94
			'adminpass' => '',
95
			'dbuser' => '',
96
			'dbpass' => '',
97
			'dbname' => '',
98
			'dbtablespace' => '',
99
			'dbhost' => 'localhost',
100
			'dbtype' => '',
101
		);
102
		$parameters = array_merge($defaults, $post);
103
104
		\OC_Util::addScript('setup');
105
		\OC_Template::printGuestPage('', 'installation', $parameters);
106
	}
107
108
	public function finishSetup() {
109
		if( file_exists( $this->autoConfigFile )) {
110
			unlink($this->autoConfigFile);
111
		}
112
		\OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
113
114
		if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) {
115
			if (!unlink(\OC::$configDir.'/CAN_INSTALL')) {
116
				\OC_Template::printGuestPage('', 'installation_incomplete');
117
			}
118
		}
119
120
		\OC_Util::redirectToDefaultPage();
121
	}
122
123
	public function loadAutoConfig($post) {
124
		if( file_exists($this->autoConfigFile)) {
125
			\OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\Util::writeLog() has been deprecated: 13.0.0 use log of \OCP\ILogger ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

125
			/** @scrutinizer ignore-deprecated */ \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
126
			$AUTOCONFIG = array();
127
			include $this->autoConfigFile;
128
			$post = array_merge ($post, $AUTOCONFIG);
129
		}
130
131
		$dbIsSet = isset($post['dbtype']);
132
		$directoryIsSet = isset($post['directory']);
133
		$adminAccountIsSet = isset($post['adminlogin']);
134
135
		if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
136
			$post['install'] = 'true';
137
		}
138
		$post['dbIsSet'] = $dbIsSet;
139
		$post['directoryIsSet'] = $directoryIsSet;
140
141
		return $post;
142
	}
143
}
144