-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathWebInstaller.php
233 lines (187 loc) · 6.94 KB
/
WebInstaller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/**
* Web based installer
*/
class WebInstaller extends \Idno\Core\Installer
{
private static $installer;
private $template;
private $ssl_required = false;
public function __construct()
{
\Idno\Core\Bonita\Main::additionalPath(dirname(__FILE__));
$this->template = new \Idno\Core\Bonita\Templates(); // Use basic template here
$this->template->setTemplateType('default');
parent::__construct();
}
/**
* @deprecated This needs to be moved into the front end js to handle proxies etc
* @return boolean
*/
public function rewriteWorking()
{
$subdir = ''; // Known no longer supports subdirectory installations.
$host = strtolower($_SERVER['HTTP_HOST']);
if (!empty(Idno\Common\Page::isSSL())) {
$schema = 'https://';
} else {
$schema = 'http://';
}
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $schema . $host . $subdir . '/js/canary.js');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
$curl_result = curl_exec($curl_handle);
$curl_status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
if ($curl_status < 200 || $curl_status > 299) {
return false;
}
curl_close($curl_handle);
return true;
}
protected function pageSettings()
{
$template = $this->template;
$ok = true;
$messages = '';
$site_title = \Idno\Core\Input::getInput('site_title');
$mysql_user = \Idno\Core\Input::getInput('mysql_user');
$mysql_host = \Idno\Core\Input::getInput('mysql_host');
$mysql_pass = \Idno\Core\Input::getInput('mysql_pass');
$mysql_name = \Idno\Core\Input::getInput('mysql_name');
$upload_path = \Idno\Core\Input::getInput('upload_path', dirname(dirname(__FILE__)) . '/Uploads/');
// if (!WebInstaller::installer()->rewriteWorking()) {
// $messages .= '<p>Rewriting appears to be disabled. Usually this means "AllowOverride None" is set in apache2.conf ';
// $messages .= 'which prevents Known\'s .htaccess from doing its thing. We tried to fetch a URL that should redirect ';
// $messages .= 'to known.min.js</p>';
// $messages .= '<p>You can usually fix this by setting <code>AllowOverride All</code> in your Apache configuration.</p>';
// $messages .= '<p>If you think this is an error, you can continue, but you might have problems later on.</p>';
// $ok = false;
// }
if (!empty($mysql_name) && !empty($mysql_host)) {
try {
$this->installSchema($mysql_host, $mysql_name, $mysql_user, $mysql_pass);
} catch (Exception $e) {
$messages .= '<p>We couldn\'t connect to your database. Please check your settings and try again. Here\'s the error we got:</p>';
$messages .= '<blockquote><p>' . $e->getMessage() . '</p></blockquote>';
$ok = false;
}
}
$upload_path = realpath($upload_path);
if (!empty($upload_path)) {
if (substr($upload_path, -1) != '/' && substr($upload_path, -1) != '\\') {
$upload_path .= '/';
}
try {
$this->checkUploadDirectory($upload_path);
} catch (\Exception $e) {
$ok = false;
$messages .= '<p>' . $e->getMessage() . '</p>';
}
} else {
$ok = false;
if (!empty($mysql_user)) {
$messages .= '<p>You need to specify an upload path.</p>';
}
}
if ($ok && !empty($upload_path) && !empty($mysql_name) && !empty($mysql_host)) {
try {
$this->writeApacheConfig();
} catch (\Exception $e) {
$ok = false;
$messages .= '<p>' . $e->getMessage() . '</p>';
}
try {
$ini_file = $this->buildConfig(
[
'dbname' => $mysql_name,
'dbpass' => $mysql_pass,
'dbuser' => $mysql_user,
'dbhost' => $mysql_host,
'uploadpath' => $upload_path,
]
);
$this->writeConfig($ini_file);
} catch (\Exception $ex) {
$ok = false;
$template->__(
[
'title' => 'Save configuration file',
'body' => $template->__(
[
'ini_file' => $ini_file,
]
)->draw('pages/write-config'),
]
)->drawPage();
}
}
if ($ok) {
if (WebInstaller::installer()->isInstalled()) {
header('Location: ../begin/register?set_name=' . urlencode($site_title));
exit;
}
}
$template->__(
[
'title' => 'Settings',
'body' => $template->__(
[
'site_title' => $site_title,
'mysql_user' => $mysql_user,
'mysql_host' => $mysql_host,
'mysql_pass' => $mysql_pass,
'mysql_name' => $mysql_name,
'upload_path' => $upload_path,
'messages' => $messages,
]
)->draw('pages/settings'),
]
)->drawPage();
}
public function run()
{
// See if we've installed things already
if ($this->isInstalled()) {
header('Location: ../'); exit;
}
$template = $this->template;
switch (\Idno\Core\Input::getInput('stage')) {
case 'settings' :
$this->pageSettings();
break;
case 'requirements' :
$template->__(
[
'title' => 'Requirements',
'body' => $template->__(
[
'ssl-required' => $this->ssl_required
]
)->draw('pages/requirements'),
]
)->drawPage();
break;
// Welcome message
default:
$template->__(
[
'body' => $template->draw('pages/begin')
]
)->drawPage();
}
}
/**
* Return the current installer
*
* @return WebInstaller
*/
public static function installer()
{
if (!empty(self::$installer)) {
return self::$installer;
}
self::$installer = new WebInstaller();
return self::$installer;
}
}