1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Symfony\Component\ClassLoader\Psr4ClassLoader; |
4
|
|
|
use Elasticsearch\ClientBuilder; |
5
|
|
|
use Psr\Log\NullLogger; |
6
|
|
|
use GuzzleHttp\Ring\Client\CurlHandler; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* The Installer class installs phpMyFAQ. Classy. |
10
|
|
|
* |
11
|
|
|
* PHP Version 5.5 |
12
|
|
|
* |
13
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public License, |
14
|
|
|
* v. 2.0. If a copy of the MPL was not distributed with this file, You can |
15
|
|
|
* obtain one at http://mozilla.org/MPL/2.0/. |
16
|
|
|
* |
17
|
|
|
* @category phpMyFAQ |
18
|
|
|
* @author Florian Anderiasch <[email protected]> |
19
|
|
|
* @copyright 2012-2016 phpMyFAQ Team |
20
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
21
|
|
|
* @link http://www.phpmyfaq.de |
22
|
|
|
* @since 2012-08-27 |
23
|
|
|
*/ |
24
|
|
|
if (!defined('IS_VALID_PHPMYFAQ')) { |
25
|
|
|
exit(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Installer. |
30
|
|
|
* |
31
|
|
|
* @category phpMyFAQ |
32
|
|
|
* @author Florian Anderiasch <[email protected]> |
33
|
|
|
* @copyright 2012-2016 phpMyFAQ Team |
34
|
|
|
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
35
|
|
|
* @link http://www.phpmyfaq.de |
36
|
|
|
* @since 2012-08-27 |
37
|
|
|
*/ |
38
|
|
|
class PMF_Installer |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* PMF_System object. |
42
|
|
|
* |
43
|
|
|
* @var PMF_System |
44
|
|
|
*/ |
45
|
|
|
protected $_system; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Array with user rights. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $_mainRights = array( |
53
|
|
|
//1 => "adduser", |
|
|
|
|
54
|
|
|
array( |
55
|
|
|
'name' => 'adduser', |
56
|
|
|
'description' => 'Right to add user accounts', |
57
|
|
|
), |
58
|
|
|
//2 => "edituser", |
|
|
|
|
59
|
|
|
array( |
60
|
|
|
'name' => 'edituser', |
61
|
|
|
'description' => 'Right to edit user accounts', |
62
|
|
|
), |
63
|
|
|
//3 => "deluser", |
|
|
|
|
64
|
|
|
array( |
65
|
|
|
'name' => 'deluser', |
66
|
|
|
'description' => 'Right to delete user accounts', |
67
|
|
|
), |
68
|
|
|
//4 => "addbt", |
|
|
|
|
69
|
|
|
array( |
70
|
|
|
'name' => 'addbt', |
71
|
|
|
'description' => 'Right to add faq entries', |
72
|
|
|
), |
73
|
|
|
//5 => "editbt", |
|
|
|
|
74
|
|
|
array( |
75
|
|
|
'name' => 'editbt', |
76
|
|
|
'description' => 'Right to edit faq entries', |
77
|
|
|
), |
78
|
|
|
//6 => "delbt", |
|
|
|
|
79
|
|
|
array( |
80
|
|
|
'name' => 'delbt', |
81
|
|
|
'description' => 'Right to delete faq entries', |
82
|
|
|
), |
83
|
|
|
//7 => "viewlog", |
|
|
|
|
84
|
|
|
array( |
85
|
|
|
'name' => 'viewlog', |
86
|
|
|
'description' => 'Right to view logfiles', |
87
|
|
|
), |
88
|
|
|
//8 => "adminlog", |
|
|
|
|
89
|
|
|
array( |
90
|
|
|
'name' => 'adminlog', |
91
|
|
|
'description' => 'Right to view admin log', |
92
|
|
|
), |
93
|
|
|
//9 => "delcomment", |
|
|
|
|
94
|
|
|
array( |
95
|
|
|
'name' => 'delcomment', |
96
|
|
|
'description' => 'Right to delete comments', |
97
|
|
|
), |
98
|
|
|
//10 => "addnews", |
|
|
|
|
99
|
|
|
array( |
100
|
|
|
'name' => 'addnews', |
101
|
|
|
'description' => 'Right to add news', |
102
|
|
|
), |
103
|
|
|
//11 => "editnews", |
|
|
|
|
104
|
|
|
array( |
105
|
|
|
'name' => 'editnews', |
106
|
|
|
'description' => 'Right to edit news', |
107
|
|
|
), |
108
|
|
|
//12 => "delnews", |
|
|
|
|
109
|
|
|
array( |
110
|
|
|
'name' => 'delnews', |
111
|
|
|
'description' => 'Right to delete news', |
112
|
|
|
), |
113
|
|
|
//13 => "addcateg", |
|
|
|
|
114
|
|
|
array( |
115
|
|
|
'name' => 'addcateg', |
116
|
|
|
'description' => 'Right to add categories', |
117
|
|
|
), |
118
|
|
|
//14 => "editcateg", |
|
|
|
|
119
|
|
|
array( |
120
|
|
|
'name' => 'editcateg', |
121
|
|
|
'description' => 'Right to edit categories', |
122
|
|
|
), |
123
|
|
|
//15 => "delcateg", |
|
|
|
|
124
|
|
|
array( |
125
|
|
|
'name' => 'delcateg', |
126
|
|
|
'description' => 'Right to delete categories', |
127
|
|
|
), |
128
|
|
|
//16 => "passwd", |
|
|
|
|
129
|
|
|
array( |
130
|
|
|
'name' => 'passwd', |
131
|
|
|
'description' => 'Right to change passwords', |
132
|
|
|
), |
133
|
|
|
//17 => "editconfig", |
|
|
|
|
134
|
|
|
array( |
135
|
|
|
'name' => 'editconfig', |
136
|
|
|
'description' => 'Right to edit configuration', |
137
|
|
|
), |
138
|
|
|
//18 => "addatt", // Duplicate, removed with 2.7.3 |
|
|
|
|
139
|
|
|
//array( |
140
|
|
|
// 'name' => 'addatt', |
|
|
|
|
141
|
|
|
// 'description' => 'Right to add attachments' |
|
|
|
|
142
|
|
|
//), |
143
|
|
|
//19 => "backup delatt", // Duplicate, removed with 2.7.3 |
|
|
|
|
144
|
|
|
//array( |
145
|
|
|
// 'name' => 'delatt', |
|
|
|
|
146
|
|
|
// 'description' => 'Right to delete attachments' |
|
|
|
|
147
|
|
|
//), |
148
|
|
|
//20 => "backup", |
|
|
|
|
149
|
|
|
array( |
150
|
|
|
'name' => 'backup', |
151
|
|
|
'description' => 'Right to save backups', |
152
|
|
|
), |
153
|
|
|
//21 => "restore", |
|
|
|
|
154
|
|
|
array( |
155
|
|
|
'name' => 'restore', |
156
|
|
|
'description' => 'Right to load backups', |
157
|
|
|
), |
158
|
|
|
//22 => "delquestion", |
|
|
|
|
159
|
|
|
array( |
160
|
|
|
'name' => 'delquestion', |
161
|
|
|
'description' => 'Right to delete questions', |
162
|
|
|
), |
163
|
|
|
//23 => 'addglossary', |
|
|
|
|
164
|
|
|
array( |
165
|
|
|
'name' => 'addglossary', |
166
|
|
|
'description' => 'Right to add glossary entries', |
167
|
|
|
), |
168
|
|
|
//24 => 'editglossary', |
|
|
|
|
169
|
|
|
array( |
170
|
|
|
'name' => 'editglossary', |
171
|
|
|
'description' => 'Right to edit glossary entries', |
172
|
|
|
), |
173
|
|
|
//25 => 'delglossary' |
174
|
|
|
array( |
175
|
|
|
'name' => 'delglossary', |
176
|
|
|
'description' => 'Right to delete glossary entries', |
177
|
|
|
), |
178
|
|
|
//26 => 'changebtrevs' |
179
|
|
|
array( |
180
|
|
|
'name' => 'changebtrevs', |
181
|
|
|
'description' => 'Right to edit revisions', |
182
|
|
|
), |
183
|
|
|
//27 => "addgroup", |
|
|
|
|
184
|
|
|
array( |
185
|
|
|
'name' => 'addgroup', |
186
|
|
|
'description' => 'Right to add group accounts', |
187
|
|
|
), |
188
|
|
|
//28 => "editgroup", |
|
|
|
|
189
|
|
|
array( |
190
|
|
|
'name' => 'editgroup', |
191
|
|
|
'description' => 'Right to edit group accounts', |
192
|
|
|
), |
193
|
|
|
//29 => "delgroup", |
|
|
|
|
194
|
|
|
array( |
195
|
|
|
'name' => 'delgroup', |
196
|
|
|
'description' => 'Right to delete group accounts', |
197
|
|
|
), |
198
|
|
|
//30 => "addtranslation", |
|
|
|
|
199
|
|
|
array( |
200
|
|
|
'name' => 'addtranslation', |
201
|
|
|
'description' => 'Right to add translation', |
202
|
|
|
), |
203
|
|
|
//31 => "edittranslation", |
|
|
|
|
204
|
|
|
array( |
205
|
|
|
'name' => 'edittranslation', |
206
|
|
|
'description' => 'Right to edit translations', |
207
|
|
|
), |
208
|
|
|
//32 => "deltranslation", |
|
|
|
|
209
|
|
|
array( |
210
|
|
|
'name' => 'deltranslation', |
211
|
|
|
'description' => 'Right to delete translations', |
212
|
|
|
), |
213
|
|
|
// 33 => 'approverec' |
|
|
|
|
214
|
|
|
array( |
215
|
|
|
'name' => 'approverec', |
216
|
|
|
'description' => 'Right to approve records', |
217
|
|
|
), |
218
|
|
|
// 34 => 'addattachment' |
|
|
|
|
219
|
|
|
array( |
220
|
|
|
'name' => 'addattachment', |
221
|
|
|
'description' => 'Right to add attachments', |
222
|
|
|
), |
223
|
|
|
// 35 => 'editattachment' |
|
|
|
|
224
|
|
|
array( |
225
|
|
|
'name' => 'editattachment', |
226
|
|
|
'description' => 'Right to edit attachments', |
227
|
|
|
), |
228
|
|
|
// 36 => 'delattachment' |
|
|
|
|
229
|
|
|
array( |
230
|
|
|
'name' => 'delattachment', |
231
|
|
|
'description' => 'Right to delete attachments', |
232
|
|
|
), |
233
|
|
|
// 37 => 'dlattachment' |
|
|
|
|
234
|
|
|
array( |
235
|
|
|
'name' => 'dlattachment', |
236
|
|
|
'description' => 'Right to download attachments', |
237
|
|
|
), |
238
|
|
|
// 38 => 'dlattachment' |
|
|
|
|
239
|
|
|
array( |
240
|
|
|
'name' => 'reports', |
241
|
|
|
'description' => 'Right to generate reports', |
242
|
|
|
), |
243
|
|
|
// 39 => 'addfaq' |
|
|
|
|
244
|
|
|
array( |
245
|
|
|
'name' => 'addfaq', |
246
|
|
|
'description' => 'Right to add FAQs in frontend', |
247
|
|
|
), |
248
|
|
|
// 40 => 'addquestion' |
|
|
|
|
249
|
|
|
array( |
250
|
|
|
'name' => 'addquestion', |
251
|
|
|
'description' => 'Right to add questions in frontend', |
252
|
|
|
), |
253
|
|
|
// 41 => 'addcomment' |
|
|
|
|
254
|
|
|
array( |
255
|
|
|
'name' => 'addcomment', |
256
|
|
|
'description' => 'Right to add comments in frontend', |
257
|
|
|
), |
258
|
|
|
// 42 => 'editinstances' |
|
|
|
|
259
|
|
|
array( |
260
|
|
|
'name' => 'editinstances', |
261
|
|
|
'description' => 'Right to edit multi-site instances', |
262
|
|
|
), |
263
|
|
|
// 43 => 'addinstances' |
|
|
|
|
264
|
|
|
array( |
265
|
|
|
'name' => 'addinstances', |
266
|
|
|
'description' => 'Right to add multi-site instances', |
267
|
|
|
), |
268
|
|
|
// 44 => 'delinstances' |
|
|
|
|
269
|
|
|
array( |
270
|
|
|
'name' => 'delinstances', |
271
|
|
|
'description' => 'Right to delete multi-site instances', |
272
|
|
|
), |
273
|
|
|
// 45 => 'export' |
|
|
|
|
274
|
|
|
array( |
275
|
|
|
'name' => 'export', |
276
|
|
|
'description' => 'Right to export the complete FAQ', |
277
|
|
|
), |
278
|
|
|
); |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Configuration array. |
282
|
|
|
* |
283
|
|
|
* @var array |
284
|
|
|
*/ |
285
|
|
|
protected $_mainConfig = [ |
286
|
|
|
'main.currentVersion' => null, |
287
|
|
|
'main.currentApiVersion' => null, |
288
|
|
|
'main.language' => '__PHPMYFAQ_LANGUAGE__', |
289
|
|
|
'main.languageDetection' => 'true', |
290
|
|
|
'main.phpMyFAQToken' => null, |
291
|
|
|
'main.referenceURL' => '__PHPMYFAQ_REFERENCE_URL__', |
292
|
|
|
'main.administrationMail' => '[email protected]', |
293
|
|
|
'main.contactInformations' => '', |
294
|
|
|
'main.enableAdminLog' => 'true', |
295
|
|
|
'main.enableRewriteRules' => 'false', |
296
|
|
|
'main.enableUserTracking' => 'true', |
297
|
|
|
'main.metaDescription' => 'phpMyFAQ should be the answer for all questions in life', |
298
|
|
|
'main.metaKeywords' => '', |
299
|
|
|
'main.metaPublisher' => '__PHPMYFAQ_PUBLISHER__', |
300
|
|
|
'main.send2friendText' => '', |
301
|
|
|
'main.titleFAQ' => 'phpMyFAQ Codename Proteus', |
302
|
|
|
'main.urlValidateInterval' => '86400', |
303
|
|
|
'main.enableWysiwygEditor' => 'true', |
304
|
|
|
'main.enableWysiwygEditorFrontend' => 'false', |
305
|
|
|
'main.enableMarkdownEditor' => 'false', |
306
|
|
|
'main.templateSet' => 'default', |
307
|
|
|
'main.optionalMailAddress' => 'false', |
308
|
|
|
'main.dateFormat' => 'Y-m-d H:i', |
309
|
|
|
'main.maintenanceMode' => 'false', |
310
|
|
|
'main.enableGravatarSupport' => 'false', |
311
|
|
|
'main.enableRssFeeds' => 'true', |
312
|
|
|
'main.enableGzipCompression' => 'true', |
313
|
|
|
'main.enableLinkVerification' => 'true', |
314
|
|
|
'main.customPdfHeader' => '', |
315
|
|
|
'main.customPdfHFooter' => '', |
316
|
|
|
'main.enableSmartAnswering' => 'true', |
317
|
|
|
|
318
|
|
|
'records.numberOfRecordsPerPage' => '10', |
319
|
|
|
'records.numberOfShownNewsEntries' => '3', |
320
|
|
|
'records.defaultActivation' => 'false', |
321
|
|
|
'records.defaultAllowComments' => 'false', |
322
|
|
|
'records.enableVisibilityQuestions' => 'false', |
323
|
|
|
'records.numberOfRelatedArticles' => '5', |
324
|
|
|
'records.orderby' => 'id', |
325
|
|
|
'records.sortby' => 'DESC', |
326
|
|
|
'records.orderingPopularFaqs' => 'visits', |
327
|
|
|
'records.disableAttachments' => 'true', |
328
|
|
|
'records.maxAttachmentSize' => '100000', |
329
|
|
|
'records.attachmentsPath' => 'attachments', |
330
|
|
|
'records.attachmentsStorageType' => '0', |
331
|
|
|
'records.enableAttachmentEncryption' => 'false', |
332
|
|
|
'records.defaultAttachmentEncKey' => '', |
333
|
|
|
'records.enableCloseQuestion' => 'false', |
334
|
|
|
'records.enableDeleteQuestion' => 'false', |
335
|
|
|
'records.autosaveActive' => 'false', |
336
|
|
|
'records.autosaveSecs' => '180', |
337
|
|
|
'records.randomSort' => 'false', |
338
|
|
|
'records.allowCommentsForGuests' => 'true', |
339
|
|
|
'records.allowQuestionsForGuests' => 'true', |
340
|
|
|
'records.allowNewFaqsForGuests' => 'true', |
341
|
|
|
'records.hideEmptyCategories' => 'false', |
342
|
|
|
'records.allowDownloadsForGuests' => 'false', |
343
|
|
|
'records.numberMaxStoredRevisions' => '10', |
344
|
|
|
|
345
|
|
|
'search.numberSearchTerms' => '10', |
346
|
|
|
'search.relevance' => 'thema,content,keywords', |
347
|
|
|
'search.enableRelevance' => 'false', |
348
|
|
|
'search.enableHighlighting' => 'true', |
349
|
|
|
'search.searchForSolutionId' => 'true', |
350
|
|
|
'search.enableElasticsearch' => 'false', |
351
|
|
|
|
352
|
|
|
'security.permLevel' => 'basic', |
353
|
|
|
'security.ipCheck' => 'false', |
354
|
|
|
'security.enableLoginOnly' => 'false', |
355
|
|
|
'security.ldapSupport' => 'false', |
356
|
|
|
'security.bannedIPs' => '', |
357
|
|
|
'security.ssoSupport' => 'false', |
358
|
|
|
'security.ssoLogoutRedirect' => '', |
359
|
|
|
'security.useSslForLogins' => 'false', |
360
|
|
|
'security.useSslOnly' => 'false', |
361
|
|
|
'security.forcePasswordUpdate' => 'false', |
362
|
|
|
'security.enableRegistration' => 'true', |
363
|
|
|
|
364
|
|
|
'spam.checkBannedWords' => 'true', |
365
|
|
|
'spam.enableCaptchaCode' => null, |
366
|
|
|
'spam.enableSafeEmail' => 'true', |
367
|
|
|
'spam.manualActivation' => 'true', |
368
|
|
|
|
369
|
|
|
'socialnetworks.enableTwitterSupport' => 'false', |
370
|
|
|
'socialnetworks.twitterConsumerKey' => '', |
371
|
|
|
'socialnetworks.twitterConsumerSecret' => '', |
372
|
|
|
'socialnetworks.twitterAccessTokenKey' => '', |
373
|
|
|
'socialnetworks.twitterAccessTokenSecret' => '', |
374
|
|
|
'socialnetworks.enableFacebookSupport' => 'false', |
375
|
|
|
'socialnetworks.disableAll' => 'false', |
376
|
|
|
|
377
|
|
|
'seo.metaTagsHome' => 'index, follow', |
378
|
|
|
'seo.metaTagsFaqs' => 'index, follow', |
379
|
|
|
'seo.metaTagsCategories' => 'index, follow', |
380
|
|
|
'seo.metaTagsPages' => 'index, follow', |
381
|
|
|
'seo.metaTagsAdmin' => 'noindex, nofollow', |
382
|
|
|
|
383
|
|
|
'mail.remoteSMTP' => 'false', |
384
|
|
|
'mail.remoteSMTPServer' => '', |
385
|
|
|
'mail.remoteSMTPUsername' => '', |
386
|
|
|
'mail.remoteSMTPPassword' => '' |
387
|
|
|
]; |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* Constructor. |
391
|
|
|
* |
392
|
|
|
* @return PMF_Installer |
393
|
|
|
*/ |
394
|
|
|
public function __construct() |
395
|
|
|
{ |
396
|
|
|
$this->_system = new PMF_System(); |
397
|
|
|
$dynMainConfig = array( |
398
|
|
|
'main.currentVersion' => PMF_System::getVersion(), |
399
|
|
|
'main.currentApiVersion' => PMF_System::getApiVersion(), |
400
|
|
|
'main.phpMyFAQToken' => md5(uniqid(rand())), |
401
|
|
|
'spam.enableCaptchaCode' => (extension_loaded('gd') ? 'true' : 'false'), |
402
|
|
|
); |
403
|
|
|
$this->_mainConfig = array_merge($this->_mainConfig, $dynMainConfig); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Check absolutely necessary stuff and die. |
408
|
|
|
*/ |
409
|
|
|
public function checkBasicStuff() |
410
|
|
|
{ |
411
|
|
|
if (!$this->checkMinimumPhpVersion()) { |
412
|
|
|
printf( |
413
|
|
|
'<p class="alert alert-danger">Sorry, but you need PHP %s or later!</p>', |
414
|
|
|
PMF_System::VERSION_MINIMUM_PHP |
415
|
|
|
); |
416
|
|
|
PMF_System::renderFooter(); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
if (!function_exists('date_default_timezone_set')) { |
420
|
|
|
echo '<p class="alert alert-danger">Sorry, but setting a default timezone doesn\'t work in your environment!</p>'; |
421
|
|
|
PMF_System::renderFooter(); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
View Code Duplication |
if (!$this->_system->checkDatabase()) { |
425
|
|
|
echo '<p class="alert alert-danger">No supported database detected! Please install one of the following'. |
426
|
|
|
' database systems and enable the corresponding PHP extension in php.ini:</p>'; |
427
|
|
|
echo '<ul>'; |
428
|
|
|
foreach ($this->_system->getSupportedDatabases() as $database) { |
429
|
|
|
printf(' <li>%s</li>', $database[1]); |
430
|
|
|
} |
431
|
|
|
echo '</ul>'; |
432
|
|
|
PMF_System::renderFooter(); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
View Code Duplication |
if (!$this->_system->checkRequiredExtensions()) { |
436
|
|
|
echo '<p class="alert alert-danger">The following extensions are missing! Please enable the PHP extension(s) in '. |
437
|
|
|
'php.ini.</p>'; |
438
|
|
|
echo '<ul>'; |
439
|
|
|
foreach ($this->_system->getMissingExtensions() as $extension) { |
440
|
|
|
printf(' <li>ext/%s</li>', $extension); |
441
|
|
|
} |
442
|
|
|
echo '</ul>'; |
443
|
|
|
PMF_System::renderFooter(); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
if (!$this->_system->checkphpMyFAQInstallation()) { |
447
|
|
|
echo '<p class="alert alert-danger">It seems you\'re already running a version of phpMyFAQ. Please use the '. |
448
|
|
|
'<a href="update.php">update script</a>.</p>'; |
449
|
|
|
PMF_System::renderFooter(); |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Checks for the minimum PHP requirement and if the database credentials file is readable. |
455
|
|
|
* |
456
|
|
|
* @param string $type |
457
|
|
|
* |
458
|
|
|
* @return void |
459
|
|
|
*/ |
460
|
|
|
public function checkPreUpgrade($type = '') |
461
|
|
|
{ |
462
|
|
|
if (!$this->checkMinimumPhpVersion()) { |
463
|
|
|
printf( |
464
|
|
|
'<p class="alert alert-danger">Sorry, but you need PHP %s or later!</p>', |
465
|
|
|
PMF_System::VERSION_MINIMUM_PHP |
466
|
|
|
); |
467
|
|
|
PMF_System::renderFooter(); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
if (!is_readable(PMF_ROOT_DIR.'/inc/data.php') && !is_readable(PMF_ROOT_DIR.'/config/database.php')) { |
471
|
|
|
echo '<p class="alert alert-danger">It seems you never run a version of phpMyFAQ.<br>'. |
472
|
|
|
'Please use the <a href="setup.php">install script</a>.</p>'; |
473
|
|
|
PMF_System::renderFooter(); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
if ('' !== $type) { |
477
|
|
|
$databaseFound = false; |
478
|
|
|
foreach ($this->_system->getSupportedDatabases() as $database => $values) { |
479
|
|
|
if ($database === $type) { |
480
|
|
|
$databaseFound = true; |
481
|
|
|
break; |
482
|
|
|
} |
483
|
|
|
} |
484
|
|
|
if (!$databaseFound) { |
485
|
|
|
echo '<p class="alert alert-danger">It seems you\'re using an unsupported database version.<br>'. |
486
|
|
|
'We found '.ucfirst($database).'<br>'. |
|
|
|
|
487
|
|
|
'Please use the change the database type in config/database.php.</p>'; |
488
|
|
|
PMF_System::renderFooter(); |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Checks the minimum required PHP version, defined in PMF_System. |
495
|
|
|
* |
496
|
|
|
* @return bool |
497
|
|
|
*/ |
498
|
|
|
public function checkMinimumPhpVersion() |
499
|
|
|
{ |
500
|
|
|
if (version_compare(PHP_VERSION, PMF_System::VERSION_MINIMUM_PHP, '<')) { |
501
|
|
|
return false; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
return true; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* Checks if the file permissions are okay. |
509
|
|
|
*/ |
510
|
|
|
public function checkFilesystemPermissions() |
511
|
|
|
{ |
512
|
|
|
$instanceSetup = new PMF_Instance_Setup(); |
513
|
|
|
$instanceSetup->setRootDir(PMF_ROOT_DIR); |
514
|
|
|
|
515
|
|
|
$dirs = array('/attachments', '/config', '/data', '/images'); |
516
|
|
|
$failedDirs = $instanceSetup->checkDirs($dirs); |
517
|
|
|
$numDirs = sizeof($failedDirs); |
518
|
|
|
|
519
|
|
|
if (1 <= $numDirs) { |
520
|
|
|
printf( |
521
|
|
|
'<p class="alert alert-danger">The following %s could not be created or %s not writable:</p><ul>', |
522
|
|
|
(1 < $numDirs) ? 'directories' : 'directory', |
523
|
|
|
(1 < $numDirs) ? 'are' : 'is' |
524
|
|
|
); |
525
|
|
|
foreach ($failedDirs as $dir) { |
526
|
|
|
echo "<li>$dir</li>\n"; |
527
|
|
|
} |
528
|
|
|
printf( |
529
|
|
|
'</ul><p class="alert alert-danger">Please create %s manually and/or change access to chmod 775 (or '. |
530
|
|
|
'greater if necessary).</p>', |
531
|
|
|
(1 < $numDirs) ? 'them' : 'it' |
532
|
|
|
); |
533
|
|
|
PMF_System::renderFooter(); |
534
|
|
|
} |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* Checks some non critical settings and print some hints. |
539
|
|
|
* |
540
|
|
|
* @todo We should return an array of messages |
541
|
|
|
*/ |
542
|
|
|
public function checkNoncriticalSettings() |
543
|
|
|
{ |
544
|
|
|
if ((@ini_get('safe_mode') == 'On' || @ini_get('safe_mode') === 1)) { |
545
|
|
|
echo '<p class="alert alert-danger">The PHP safe mode is enabled. You may have problems when phpMyFAQ tries to write '. |
546
|
|
|
' in some directories.</p>'; |
547
|
|
|
} |
548
|
|
|
if (!extension_loaded('gd')) { |
549
|
|
|
echo '<p class="alert alert-danger">You don\'t have GD support enabled in your PHP installation. Please enable GD '. |
550
|
|
|
'support in your php.ini file otherwise you can\'t use Captchas for spam protection.</p>'; |
551
|
|
|
} |
552
|
|
|
if (!function_exists('imagettftext')) { |
553
|
|
|
echo '<p class="alert alert-danger">You don\'t have Freetype support enabled in the GD extension of your PHP '. |
554
|
|
|
'installation. Please enable Freetype support in GD extension otherwise the Captchas for spam '. |
555
|
|
|
'protection will be quite easy to break.</p>'; |
556
|
|
|
} |
557
|
|
|
if (!extension_loaded('curl') || !extension_loaded('openssl')) { |
558
|
|
|
echo '<p class="alert alert-danger">You don\'t have cURL and/or OpenSSL support enabled in your PHP installation. '. |
559
|
|
|
'Please enable cURL and/or OpenSSL support in your php.ini file otherwise you can\'t use the Twitter '. |
560
|
|
|
' support or Elasticsearch.</p>'; |
561
|
|
|
} |
562
|
|
|
if (!extension_loaded('fileinfo')) { |
563
|
|
|
echo '<p class="alert alert-danger">You don\'t have Fileinfo support enabled in your PHP installation. '. |
564
|
|
|
'Please enable Fileinfo support in your php.ini file otherwise you can\'t use our backup/restore '. |
565
|
|
|
'functionality.</p>'; |
566
|
|
|
} |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Checks if we can store data via sessions. If not, e.g. an user can't |
571
|
|
|
* login into the admin section. |
572
|
|
|
* |
573
|
|
|
* @return bool |
574
|
|
|
*/ |
575
|
|
|
public function checkSessionSettings() |
576
|
|
|
{ |
577
|
|
|
return true; |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Starts the installation. |
582
|
|
|
* |
583
|
|
|
* @param array $DB |
584
|
|
|
*/ |
585
|
|
|
public function startInstall(Array $DB = null) |
586
|
|
|
{ |
587
|
|
|
$query = $uninst = $dbSetup = []; |
588
|
|
|
|
589
|
|
|
// Check table prefix |
590
|
|
|
$dbSetup['dbPrefix'] = PMF_Filter::filterInput(INPUT_POST, 'sqltblpre', FILTER_SANITIZE_STRING, ''); |
591
|
|
|
if ('' !== $dbSetup['dbPrefix']) { |
592
|
|
|
PMF_Db::setTablePrefix($dbSetup['dbPrefix']); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
// Check database entries |
596
|
|
|
$dbSetup['dbType'] = PMF_Filter::filterInput(INPUT_POST, 'sql_type', FILTER_SANITIZE_STRING); |
597
|
|
|
if (!is_null($dbSetup['dbType'])) { |
598
|
|
|
$dbSetup['dbType'] = trim($dbSetup['dbType']); |
599
|
|
|
if (!file_exists(PMF_INCLUDE_DIR.'/PMF/Instance/Database/'.ucfirst($dbSetup['dbType']).'.php')) { |
600
|
|
|
printf( |
601
|
|
|
'<p class="alert alert-danger"><strong>Error:</strong> Invalid server type: %s</p>', |
602
|
|
|
$dbSetup['dbType'] |
603
|
|
|
); |
604
|
|
|
PMF_System::renderFooter(true); |
605
|
|
|
} |
606
|
|
|
} else { |
607
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please select a database type.</p>\n"; |
608
|
|
|
PMF_System::renderFooter(true); |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
$dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_server', FILTER_SANITIZE_STRING); |
612
|
|
View Code Duplication |
if (is_null($dbSetup['dbServer']) && !PMF_System::isSqlite($dbSetup['dbType'])) { |
613
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a database server.</p>\n"; |
614
|
|
|
PMF_System::renderFooter(true); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
$dbSetup['dbUser'] = PMF_Filter::filterInput(INPUT_POST, 'sql_user', FILTER_SANITIZE_STRING); |
618
|
|
View Code Duplication |
if (is_null($dbSetup['dbUser']) && !PMF_System::isSqlite($dbSetup['dbType'])) { |
619
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a database username.</p>\n"; |
620
|
|
|
PMF_System::renderFooter(true); |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
$dbSetup['dbPassword'] = PMF_Filter::filterInput(INPUT_POST, 'sql_password', FILTER_UNSAFE_RAW); |
624
|
|
|
if (is_null($dbSetup['dbPassword']) && !PMF_System::isSqlite($dbSetup['dbType'])) { |
625
|
|
|
// Password can be empty... |
626
|
|
|
$dbSetup['dbPassword'] = ''; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
$dbSetup['dbDatabaseName'] = PMF_Filter::filterInput(INPUT_POST, 'sql_db', FILTER_SANITIZE_STRING); |
630
|
|
View Code Duplication |
if (is_null($dbSetup['dbDatabaseName']) && !PMF_System::isSqlite($dbSetup['dbType'])) { |
631
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a database name.</p>\n"; |
632
|
|
|
PMF_System::renderFooter(true); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
if (PMF_System::isSqlite($dbSetup['dbType'])) { |
636
|
|
|
$dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_sqlitefile', FILTER_SANITIZE_STRING); |
637
|
|
|
if (is_null($dbSetup['dbServer'])) { |
638
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a SQLite database filename.</p>\n"; |
639
|
|
|
PMF_System::renderFooter(true); |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
// check database connection |
644
|
|
|
PMF_Db::setTablePrefix($dbSetup['dbPrefix']); |
645
|
|
|
$db = PMF_Db::factory($dbSetup['dbType']); |
646
|
|
|
$db->connect($dbSetup['dbServer'], $dbSetup['dbUser'], $dbSetup['dbPassword'], $dbSetup['dbDatabaseName']); |
647
|
|
|
if (!$db) { |
648
|
|
|
printf("<p class=\"alert alert-danger\"><strong>DB Error:</strong> %s</p>\n", $db->error()); |
649
|
|
|
PMF_System::renderFooter(true); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
$configuration = new PMF_Configuration($db); |
653
|
|
|
|
654
|
|
|
// |
655
|
|
|
// Check LDAP if enabled |
656
|
|
|
// |
657
|
|
|
$ldapEnabled = PMF_Filter::filterInput(INPUT_POST, 'ldap_enabled', FILTER_SANITIZE_STRING); |
658
|
|
|
if (extension_loaded('ldap') && !is_null($ldapEnabled)) { |
659
|
|
|
$ldapSetup = []; |
660
|
|
|
|
661
|
|
|
// check LDAP entries |
662
|
|
|
$ldapSetup['ldapServer'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_server', FILTER_SANITIZE_STRING); |
663
|
|
|
if (is_null($ldapSetup['ldapServer'])) { |
664
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a LDAP server.</p>\n"; |
665
|
|
|
PMF_System::renderFooter(true); |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
$ldapSetup['ldapPort'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_port', FILTER_VALIDATE_INT); |
669
|
|
|
if (is_null($ldapSetup['ldapPort'])) { |
670
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a LDAP port.</p>\n"; |
671
|
|
|
PMF_System::renderFooter(true); |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
$ldapSetup['ldapBase'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_base', FILTER_SANITIZE_STRING); |
675
|
|
|
if (is_null($ldapSetup['ldapBase'])) { |
676
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a LDAP base search DN.</p>\n"; |
677
|
|
|
PMF_System::renderFooter(true); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
// LDAP User and LDAP password are optional |
681
|
|
|
$ldapSetup['ldapUser'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_user', FILTER_SANITIZE_STRING, ''); |
682
|
|
|
$ldapSetup['ldapPassword'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_password', FILTER_SANITIZE_STRING, ''); |
683
|
|
|
|
684
|
|
|
// check LDAP connection |
685
|
|
|
require PMF_ROOT_DIR.'/inc/PMF/Ldap.php'; |
686
|
|
|
$ldap = new PMF_Ldap($configuration); |
687
|
|
|
$ldap->connect( |
688
|
|
|
$ldapSetup['ldapServer'], |
689
|
|
|
$ldapSetup['ldapPort'], |
690
|
|
|
$ldapSetup['ldapBase'], |
691
|
|
|
$ldapSetup['ldapUser'], |
692
|
|
|
$ldapSetup['ldapPassword'] |
693
|
|
|
); |
694
|
|
|
if (!$ldap) { |
695
|
|
|
echo '<p class="alert alert-danger"><strong>LDAP Error:</strong> '.$ldap->error()."</p>\n"; |
696
|
|
|
PMF_System::renderFooter(true); |
697
|
|
|
} |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
|
701
|
|
|
// |
702
|
|
|
// Check Elasticsearch if enabled |
703
|
|
|
// |
704
|
|
|
$esEnabled = PMF_Filter::filterInput(INPUT_POST, 'elasticsearch_enabled', FILTER_SANITIZE_STRING); |
705
|
|
|
if (!is_null($esEnabled)) { |
706
|
|
|
$esSetup = []; |
707
|
|
|
$esHostFilter = [ |
708
|
|
|
'elasticsearch_server' => [ |
709
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
710
|
|
|
'flags' => FILTER_REQUIRE_ARRAY |
711
|
|
|
] |
712
|
|
|
]; |
713
|
|
|
|
714
|
|
|
// ES hosts |
715
|
|
|
$esHosts = PMF_Filter::filterInputArray(INPUT_POST, $esHostFilter); |
716
|
|
|
if (is_null($esHosts)) { |
717
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add at least one Elasticsearch host.</p>\n"; |
718
|
|
|
PMF_System::renderFooter(true); |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
$esSetup['hosts'] = $esHosts['elasticsearch_server']; |
722
|
|
|
|
723
|
|
|
// ES Index name |
724
|
|
|
$esSetup['index'] = PMF_Filter::filterInput(INPUT_POST, 'elasticsearch_index', FILTER_SANITIZE_STRING); |
725
|
|
|
if (is_null($esSetup['index'])) { |
726
|
|
|
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add an Elasticsearch index name.</p>\n"; |
727
|
|
|
PMF_System::renderFooter(true); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
require_once PMF_INCLUDE_DIR.'/libs/react/promise/src/functions.php'; |
731
|
|
|
|
732
|
|
|
$psr4Loader = new Psr4ClassLoader(); |
733
|
|
|
$psr4Loader->addPrefix('Elasticsearch', PMF_INCLUDE_DIR.'/libs/elasticsearch/src/Elasticsearch'); |
734
|
|
|
$psr4Loader->addPrefix('GuzzleHttp\\Ring\\', PMF_INCLUDE_DIR.'/libs/guzzlehttp/ringphp/src'); |
735
|
|
|
$psr4Loader->addPrefix('Monolog', PMF_INCLUDE_DIR.'/libs/monolog/src/Monolog'); |
736
|
|
|
$psr4Loader->addPrefix('Psr', PMF_INCLUDE_DIR.'/libs/psr/log/Psr'); |
737
|
|
|
$psr4Loader->addPrefix('React\\Promise\\', PMF_INCLUDE_DIR.'/libs/react/promise/src'); |
738
|
|
|
$psr4Loader->register(); |
739
|
|
|
|
740
|
|
|
// check LDAP connection |
741
|
|
|
$esHosts = array_values($esHosts['elasticsearch_server']); |
742
|
|
|
$esClient = ClientBuilder::create() |
743
|
|
|
->setHosts($esHosts) |
744
|
|
|
->build(); |
745
|
|
|
|
746
|
|
|
if (!$esClient) { |
747
|
|
|
echo '<p class="alert alert-danger"><strong>Elasticsearch Error:</strong> No connection.</p>'; |
748
|
|
|
PMF_System::renderFooter(true); |
749
|
|
|
} |
750
|
|
|
} else { |
751
|
|
|
$esSetup = []; |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
// check loginname |
755
|
|
|
$loginname = PMF_Filter::filterInput(INPUT_POST, 'loginname', FILTER_SANITIZE_STRING); |
756
|
|
|
if (is_null($loginname)) { |
757
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Please add a loginname for your account.</p>'; |
758
|
|
|
PMF_System::renderFooter(true); |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
// check user entries |
762
|
|
|
$password = PMF_Filter::filterInput(INPUT_POST, 'password', FILTER_SANITIZE_STRING); |
763
|
|
|
if (is_null($password)) { |
764
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Please add a password for the your account.</p>'; |
765
|
|
|
PMF_System::renderFooter(true); |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
$password_retyped = PMF_Filter::filterInput(INPUT_POST, 'password_retyped', FILTER_SANITIZE_STRING); |
769
|
|
|
if (is_null($password_retyped)) { |
770
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Please add a retyped password.</p>'; |
771
|
|
|
PMF_System::renderFooter(true); |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
if (strlen($password) <= 5 || strlen($password_retyped) <= 5) { |
775
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Your password and retyped password are too short.'. |
776
|
|
|
' Please set your password and your retyped password with a minimum of 6 characters.</p>'; |
777
|
|
|
PMF_System::renderFooter(true); |
778
|
|
|
} |
779
|
|
|
if ($password != $password_retyped) { |
780
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Your password and retyped password are not equal.'. |
781
|
|
|
' Please check your password and your retyped password.</p>'; |
782
|
|
|
PMF_System::renderFooter(true); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
$language = PMF_Filter::filterInput(INPUT_POST, 'language', FILTER_SANITIZE_STRING, 'en'); |
786
|
|
|
$realname = PMF_Filter::filterInput(INPUT_POST, 'realname', FILTER_SANITIZE_STRING, ''); |
787
|
|
|
$email = PMF_Filter::filterInput(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL, ''); |
788
|
|
|
$permLevel = PMF_Filter::filterInput(INPUT_POST, 'permLevel', FILTER_SANITIZE_STRING, 'basic'); |
789
|
|
|
|
790
|
|
|
$instanceSetup = new PMF_Instance_Setup(); |
791
|
|
|
$instanceSetup->setRootDir(PMF_ROOT_DIR); |
792
|
|
|
|
793
|
|
|
// Write the DB variables in database.php |
794
|
|
|
if (!$instanceSetup->createDatabaseFile($dbSetup)) { |
795
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Setup cannot write to ./config/database.php.</p>'; |
796
|
|
|
$this->_system->cleanInstallation(); |
797
|
|
|
PMF_System::renderFooter(true); |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
// check LDAP is enabled |
801
|
|
View Code Duplication |
if (extension_loaded('ldap') && !is_null($ldapEnabled) && count($ldapSetup)) { |
|
|
|
|
802
|
|
|
if (!$instanceSetup->createLdapFile($ldapSetup, '')) { |
803
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Setup cannot write to ./config/ldap.php.</p>'; |
804
|
|
|
$this->_system->cleanInstallation(); |
805
|
|
|
PMF_System::renderFooter(true); |
806
|
|
|
} |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
// check if Elasticsearch is enabled |
810
|
|
View Code Duplication |
if (!is_null($esEnabled) && count($esSetup)) { |
|
|
|
|
811
|
|
|
if (!$instanceSetup->createElasticsearchFile($esSetup, '')) { |
812
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Setup cannot write to ./config/elasticsearch.php.</p>'; |
813
|
|
|
$this->_system->cleanInstallation(); |
814
|
|
|
PMF_System::renderFooter(true); |
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
// connect to the database using config/database.php |
819
|
|
|
require PMF_ROOT_DIR.'/config/database.php'; |
820
|
|
|
$db = PMF_Db::factory($dbSetup['dbType']); |
821
|
|
|
$db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']); |
822
|
|
|
if (!$db) { |
823
|
|
|
printf("<p class=\"alert alert-danger\"><strong>DB Error:</strong> %s</p>\n", $db->error()); |
824
|
|
|
$this->_system->cleanInstallation(); |
825
|
|
|
PMF_System::renderFooter(true); |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
$databaseInstaller = PMF_Instance_Database::factory($configuration, $dbSetup['dbType']); |
829
|
|
|
$databaseInstaller->createTables($dbSetup['dbPrefix']); |
830
|
|
|
|
831
|
|
|
$stopwords = new PMF_Instance_Database_Stopwords($configuration); |
832
|
|
|
$stopwords->executeInsertQueries($dbSetup['dbPrefix']); |
833
|
|
|
|
834
|
|
|
$this->_system->setDatabase($db); |
835
|
|
|
|
836
|
|
|
echo '<p>'; |
837
|
|
|
|
838
|
|
|
// Erase any table before starting creating the required ones |
839
|
|
|
if (!PMF_System::isSqlite($dbSetup['dbType'])) { |
840
|
|
|
$this->_system->dropTables($uninst); |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
// Start creating the required tables |
844
|
|
|
$count = 0; |
845
|
|
|
foreach ($query as $executeQuery) { |
846
|
|
|
$result = @$db->query($executeQuery); |
847
|
|
View Code Duplication |
if (!$result) { |
|
|
|
|
848
|
|
|
echo '<p class="alert alert-danger"><strong>Error:</strong> Please install your version of phpMyFAQ once again or send |
849
|
|
|
us a <a href=\"http://www.phpmyfaq.de\" target=\"_blank\">bug report</a>.</p>'; |
850
|
|
|
printf('<p class="alert alert-danger"><strong>DB error:</strong> %s</p>', $db->error()); |
851
|
|
|
printf('<code>%s</code>', htmlentities($executeQuery)); |
852
|
|
|
$this->_system->dropTables($uninst); |
853
|
|
|
$this->_system->cleanInstallation(); |
854
|
|
|
PMF_System::renderFooter(true); |
855
|
|
|
} |
856
|
|
|
usleep(1000); |
857
|
|
|
++$count; |
858
|
|
|
if (!($count % 10)) { |
859
|
|
|
echo '| '; |
860
|
|
|
} |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
$link = new PMF_Link(null, $configuration); |
864
|
|
|
|
865
|
|
|
// add main configuration, add personal settings |
866
|
|
|
$this->_mainConfig['main.metaPublisher'] = $realname; |
867
|
|
|
$this->_mainConfig['main.administrationMail'] = $email; |
868
|
|
|
$this->_mainConfig['main.language'] = $language; |
869
|
|
|
$this->_mainConfig['security.permLevel'] = $permLevel; |
870
|
|
|
|
871
|
|
|
foreach ($this->_mainConfig as $name => $value) { |
872
|
|
|
$configuration->add($name, $value); |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
$configuration->update(array('main.referenceURL' => $link->getSystemUri('/setup/index.php'))); |
876
|
|
|
$configuration->add('security.salt', md5($configuration->getDefaultUrl())); |
877
|
|
|
|
878
|
|
|
// add admin account and rights |
879
|
|
|
$admin = new PMF_User($configuration); |
880
|
|
View Code Duplication |
if (!$admin->createUser($loginname, $password, 1)) { |
881
|
|
|
printf( |
882
|
|
|
'<p class="alert alert-danger"><strong>Fatal installation error:</strong><br>'. |
883
|
|
|
"Couldn't create the admin user: %s</p>\n", |
884
|
|
|
$admin->error() |
885
|
|
|
); |
886
|
|
|
$this->_system->cleanInstallation(); |
887
|
|
|
PMF_System::renderFooter(true); |
888
|
|
|
} |
889
|
|
|
$admin->setStatus('protected'); |
890
|
|
|
$adminData = array( |
891
|
|
|
'display_name' => $realname, |
892
|
|
|
'email' => $email, |
893
|
|
|
); |
894
|
|
|
$admin->setUserData($adminData); |
895
|
|
|
|
896
|
|
|
// add default rights |
897
|
|
|
foreach ($this->_mainRights as $right) { |
898
|
|
|
$admin->perm->grantUserRight(1, $admin->perm->addRight($right)); |
899
|
|
|
} |
900
|
|
|
|
901
|
|
|
// Add anonymous user account |
902
|
|
|
$instanceSetup->createAnonymousUser($configuration); |
903
|
|
|
|
904
|
|
|
// Add master instance |
905
|
|
|
$instanceData = array( |
906
|
|
|
'url' => $link->getSystemUri($_SERVER['SCRIPT_NAME']), |
907
|
|
|
'instance' => $link->getSystemRelativeUri('setup/index.php'), |
908
|
|
|
'comment' => 'phpMyFAQ '.PMF_System::getVersion(), |
909
|
|
|
); |
910
|
|
|
$faqInstance = new PMF_Instance($configuration); |
911
|
|
|
$faqInstance->addInstance($instanceData); |
912
|
|
|
|
913
|
|
|
$faqInstanceMaster = new PMF_Instance_Master($configuration); |
914
|
|
|
$faqInstanceMaster->createMaster($faqInstance); |
915
|
|
|
|
916
|
|
|
// connect to Elasticsearch if enabled |
917
|
|
|
if (!is_null($esEnabled) && is_file(PMF_ROOT_DIR.'/config/elasticsearch.php')) { |
918
|
|
|
require PMF_ROOT_DIR.'/config/elasticsearch.php'; |
919
|
|
|
|
920
|
|
|
$configuration->setElasticsearchConfig($PMF_ES); |
|
|
|
|
921
|
|
|
|
922
|
|
|
$esClient = ClientBuilder::create() |
923
|
|
|
->setHosts($PMF_ES['hosts']) |
924
|
|
|
->build(); |
925
|
|
|
|
926
|
|
|
$configuration->setElasticsearch($esClient); |
927
|
|
|
|
928
|
|
|
$faqInstanceElasticsearch = new PMF_Instance_Elasticsearch($configuration); |
929
|
|
|
$faqInstanceElasticsearch->createIndex(); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
echo '</p>'; |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
/** |
936
|
|
|
* Cleanup all files after an installation. |
937
|
|
|
* |
938
|
|
|
* @return void |
939
|
|
|
*/ |
940
|
|
|
public function cleanUpFiles() |
941
|
|
|
{ |
942
|
|
|
// Remove 'index.php' file |
943
|
|
View Code Duplication |
if (@unlink(dirname($_SERVER['PATH_TRANSLATED']).'/index.php')) { |
|
|
|
|
944
|
|
|
echo "<p class=\"alert alert-success\">The file <em>./setup/index.php</em> was deleted automatically.</p>\n"; |
945
|
|
|
} else { |
946
|
|
|
echo "<p class=\"alert alert-danger\">Please delete the file <em>./setup/index.php</em> manually.</p>\n"; |
947
|
|
|
} |
948
|
|
|
// Remove 'update.php' file |
949
|
|
View Code Duplication |
if (@unlink(dirname($_SERVER['PATH_TRANSLATED']).'/update.php')) { |
|
|
|
|
950
|
|
|
echo "<p class=\"alert alert-success\">The file <em>./setup/update.php</em> was deleted automatically.</p>\n"; |
951
|
|
|
} else { |
952
|
|
|
echo "<p class=\"alert alert-danger\">Please delete the file <em>./setup/update.php</em> manually.</p>\n"; |
953
|
|
|
} |
954
|
|
|
} |
955
|
|
|
} |
956
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.