-
Notifications
You must be signed in to change notification settings - Fork 10
/
install.php
630 lines (583 loc) · 31 KB
/
install.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
<?php
/**
* INSTALLATION SCRIPT.
*
* @package main
* @author Giorgio Consorti <g.consorti@lynxlab.com>
* @copyright Copyright (c) 2020, Lynx s.r.l.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License v.2
* @link
* @version 0.1
*/
function output_buffer_off() {
if (!headers_sent()) {
// Disable gzip in PHP.
ini_set('zlib.output_compression', 0);
// Turn off output buffering
ini_set('output_buffering', 'off');
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
// Force disable compression in a header.
// Required for flush in some cases (Apache + mod_proxy, nginx, php-fpm).
header('Content-Encoding: none');
//prevent apache from buffering it for deflate/gzip
header("Content-type: text/html");
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.
}
// Fill-up 5 kB buffer (should be enough in most cases).
echo str_pad(' ', 5 * 1024);
// Flush all buffers.
do {
$flushed = @ob_end_flush();
} while ($flushed);
ob_implicit_flush(1);
@ob_flush();
flush();
}
function sendOK() {
return sendToBrowser('[ OK ]');
}
function sendFail() {
return sendToBrowser('[ FAIL ]');
}
function sendSkip() {
return sendToBrowser('[ SKIP ]');
}
function getBaseUrl()
{
// output: /myproject/index.php
$currentPath = $_SERVER['PHP_SELF'];
// output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
$pathInfo = pathinfo($currentPath);
// output: localhost
$hostName = $_SERVER['HTTP_HOST'];
// output: http://
$proto = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? $_SERVER['HTTP_X_FORWARDED_PROTO'] : $_SERVER["SERVER_PROTOCOL"];
$protocol = strtolower(substr($proto,0,5))=='https'?'https':'http';
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : $protocol;
// return: http://localhost/myproject/
return $protocol.'://'.$hostName.trim($pathInfo['dirname']," /")."/";
}
function sendToBrowser ($message) {
$style = '';
$color = 'lightgray';
if (strpos($message, 'text/javascript')!==false) {
echo $message;
} else {
if (strpos($message, '...')!==false) {
$style = 'width:auto; float: left; margin-right: 1em;';
$message = sprintf("%-75s", $message);
}
if (strpos($message, '[')!==false || strpos($message, ' SKIP ')!==false) $color='yellow';
if (strpos($message, '**')!==false || strpos($message, ' FAIL ')!==false) $color='red';
if (strpos($message, ' OK ')!==false) $color='#37fd37';
echo '<pre style=\'color:'.$color.'; margin:0; font-size:1.1em; font-family:monospace; '.$style.'\'>';
echo $message;
echo '</pre>';
echo '<script type="text/javascript">window.scrollTo(0,document.body.scrollHeight);</script>';
}
echo str_pad(' ', 4 * 1024);
flush();
}
function createDB($saveData, $dbname, $options=[]) {
$pdo = new PDO(
'mysql:host='.$saveData['HOST'].';dbname=INFORMATION_SCHEMA',
$saveData['USER'],
$saveData['PASSWORD'], $options
);
$stmt = $pdo->query("CREATE DATABASE `".$dbname."` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
if ($stmt) {
return new PDO(
'mysql:host='.$saveData['HOST'].';dbname='.$dbname,
$saveData['USER'],
$saveData['PASSWORD'], $options
);
} else {
throw new Exception(translateFN("Errore creazione Database"), 1);
}
}
function checkDB ($saveData, $dbname, $options=[]) {
$pdo = new PDO(
'mysql:host='.$saveData['HOST'].';dbname=INFORMATION_SCHEMA',
$saveData['USER'],
$saveData['PASSWORD'], $options
);
$stmt = $pdo->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$dbname."'");
if ((bool) $stmt->fetchColumn()) {
return new PDO(
'mysql:host='.$saveData['HOST'].';dbname='.$dbname,
$saveData['USER'],
$saveData['PASSWORD'], $options
);
}
return false;
}
function isEmptyDB($pdoconn, $dbname) {
$stmt = $pdoconn->query("SHOW TABLES FROM `$dbname`");
return $stmt->rowCount() == 0;
}
function importSQL ($filename, $pdoconn) {
if (is_file($filename) && is_readable($filename)) {
$sqlScript = file($filename);
$query = '';
foreach ($sqlScript as $line) {
$startWith = substr(trim($line), 0 ,2);
$endWith = substr(trim($line), -1 ,1);
if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '*/' || trim($startWith) == '*' || $startWith == '//') {
continue;
}
$query = $query . $line;
if ($endWith == ';') {
$buffer = $pdoconn->prepare($query);
$buffer->execute();
unset($buffer);
$query= '';
}
}
} else throw new Exception(translateFN('File non trovato').' '.$filename);
}
putenv('PORTAL_NAME=ADA Install');
putenv('HTTP_ROOT_DIR='.getBaseUrl());
/**
* Files that MUST exists and be copied before doing anything
*/
foreach ([
__DIR__ . '/config_path_DEFAULT.inc.php',
__DIR__ . '/config/config_install_DEFAULT.inc.php'] as $mustfile) {
if (!is_file($mustfile)) {
die ("NO $mustfile, aborting installation!");
}
$destfile = str_replace('_DEFAULT','',$mustfile);
if (!is_file($destfile)) {
if (false === copy ($mustfile, $destfile)) {
die("Cannot copy to $destfile, aborting installation!");
}
}
}
require_once realpath(dirname(__FILE__)).'/config_path.inc.php';
require_once ROOT_DIR.'/include/layout_classes.inc.php';
require_once ROOT_DIR.'/include/output_classes.inc.php';
require_once ROOT_DIR.'/include/DB_read.inc.php';
require_once ROOT_DIR.'/include/user_class.inc.php';
/**
* redirect to homepage if ADA is installed, either with install script or manually
*/
if (is_dir('clients') && count(glob(ROOT_DIR."/clients/*/client_conf.inc.php"))>0) {
redirect(HTTP_ROOT_DIR);
}
if (!function_exists('translateFN')) {
function translateFN($msg) { return $msg; }
}
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
if (session_status() !== PHP_SESSION_NONE) {
session_start();
$_SESSION = [];
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
}
output_buffer_off();
ini_set('max_execution_time', 300);
$postData = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$postData = array_map(function($el) {
if (is_string($el)) return trim($el);
return $el;
}, $postData);
if (array_key_exists('HTTP_ROOT_DIR', $postData)) {
$postData['HTTP_ROOT_DIR'] = rtrim($postData['HTTP_ROOT_DIR'], '/') . '/';
}
$disabledModules = [];
$modulesSQL = [];
if (array_key_exists('MODULES_DISABLE', $postData)) {
$disabledModules = explode(',',$postData['MODULES_DISABLE']);
$disabledModules = array_map('trim', $disabledModules);
}
$multiprovider = true;
// put here filenames to be imported in the common db and each provider db if multiprovider eq 0
// $inBothIfNonMulti=['ada_gdpr_policy.sql', 'ada_login_module.sql'];
$inBothIfNonMulti=[];
// put here filenames to be imported in the common db if multiprovider eq 1
$inCommonIfMulti=['ada_gdpr_policy.sql', 'ada_login_module.sql'];
// put here filenames to be ALWAYS imported in the common db
$inCommon=['ada_apps_module.sql', 'ada_secretquestion_module.sql', 'ada_impexport_module.sql'];
$defaultProvider = array_key_exists('DEFAULT_PROVIDER', $postData) && intval($postData['DEFAULT_PROVIDER'])>0 ? intval($postData['DEFAULT_PROVIDER']) : 0;
$adminUserId = 1; // id of the adminAda user
$switcherIds = [
'default' => [],
'provider' => [],
];
$authorIds = [
'default' => [],
'provider' => [],
];
$newUsers = [];
try {
if (array_key_exists('MYSQL', $postData) && array_key_exists('COMMON', $postData['MYSQL']) && is_array($postData['MYSQL']['COMMON']) && count($postData['MYSQL']['COMMON']) == 3) {
$providers = isset($postData['PROVIDER']) && is_array($postData['PROVIDER']) ? $postData['PROVIDER'] : [];
foreach ($providers as $i=>$provider) {
$providers[$i]['pointer'] = str_replace(' ', '_', trim($provider['NAME']));
}
$options = [
// PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];
$commonExisted = true;
$commonpdo = checkDB($postData['MYSQL']['COMMON'], $postData['COMMONDB'], $options);
if ($commonpdo === false) {
sendToBrowser(sprintf(translateFN('Creazione Database %s').' ...', $postData['COMMONDB']));
$commonExisted = false;
$commonEmpty = true;
$commonpdo = createDB($postData['MYSQL']['COMMON'], $postData['COMMONDB'], $options);
sendOK();
} else {
sendToBrowser(sprintf(translateFN('Database %s esistente').' ...', $postData['COMMONDB']));
$commonEmpty = isEmptyDB($commonpdo, $postData['COMMONDB']);
sendOk();
}
sendToBrowser(translateFN("Importazione Database common").' ...');
if ($commonEmpty) {
importSQL(ROOT_DIR . '/db/install/ada-empty-common.sql', $commonpdo);
sendOK();
} else sendSkip();
// SET THE PASSWORD PROVIDED IN ADMIN_PASSWORD FOR USER 'adminAda'
sendToBrowser(translateFN('Impostazione password utenti').' ...');
$sql = "UPDATE utente SET password=SHA1(\"".$postData['ADMIN_PASSWORD']."\") WHERE password=\"\";";
$stmt = $commonpdo->prepare($sql);
$stmt->execute();
sendOK();
foreach ($providers as $i=>$provider) {
set_time_limit(300);
$providers[$i]['pdoexisted'] = true;
$providers[$i]['pdo'] = checkDB($postData['MYSQL'][$i], $provider['DB'], $options);
if ($providers[$i]['pdo'] === false) {
sendToBrowser(sprintf(translateFN('Creazione Database %s').' ...', $provider['DB']));
$providers[$i]['pdoexisted'] = false;
$providers[$i]['empty'] = true;
$providers[$i]['pdo'] = createDB($postData['MYSQL'][$i], $provider['DB'], $options);
sendOK();
} else {
sendToBrowser(sprintf(translateFN('Database %s esistente').' ...', $provider['DB']));
$providers[$i]['empty'] = isEmptyDB($providers[$i]['pdo'], $provider['DB']);
sendOk();
}
sendToBrowser(sprintf(translateFN('Importazione Database %s').' ...', $provider['DB']));
if ($providers[$i]['empty']) {
$sqlFile = ROOT_DIR . '/db/ada_provider_empty.sql';
$usersKey = 'provider';
if ($i == $defaultProvider) {
$usersKey = 'default';
if (is_readable(ROOT_DIR . '/db/install/ada_default_empty.sql')) {
$sqlFile = ROOT_DIR . '/db/install/ada_default_empty.sql';
}
} else if (is_readable(ROOT_DIR . '/db/install/ada_provider_empty.sql')) {
$sqlFile = ROOT_DIR . '/db/install/ada_provider_empty.sql';
}
importSQL($sqlFile, $providers[$i]['pdo']);
$sql = "INSERT INTO tester(nome,puntatore) VALUES ('".$provider['NAME']."', '".$providers[$i]['pointer']."');";
$stmt = $commonpdo->prepare($sql);
$stmt->execute();
$providerId = $commonpdo->lastInsertId();
unset($stmt);
foreach(array_merge([$adminUserId], $switcherIds[$usersKey], $authorIds[$usersKey]) as $anUserId) {
$uRow = "SELECT * FROM ".$postData['COMMONDB'].".utente WHERE id_utente=$anUserId;";
$stmt = $commonpdo->prepare($uRow);
$stmt->execute();
$uData = $stmt->fetch(PDO::FETCH_ASSOC);
$fields = '`' . implode('`, `', array_keys($uData)) . '`';
$fields_data = implode(', ', array_map(function() { return '?'; }, $uData));
$sql = "INSERT INTO `".$provider['DB']."`.`utente` (${fields}) VALUES (${fields_data});";
$stmt = $providers[$i]['pdo']->prepare($sql);
$stmt->execute(array_values($uData));
unset($stmt);
$sql = "INSERT INTO utente_tester(id_utente, id_tester) VALUES ($anUserId, $providerId);";
$stmt = $commonpdo->prepare($sql);
$stmt->execute();
unset($stmt);
$updateUser = false;
if ($anUserId == $adminUserId) {
$sql = "INSERT INTO ".$provider['DB'].".`amministratore_sistema` (id_utente_amministratore_sist) VALUES ($adminUserId);";
$stmt = $providers[$i]['pdo']->prepare($sql);
$stmt->execute();
unset($stmt);
} else if (in_array($anUserId, $authorIds[$usersKey])) {
$sql = "INSERT INTO `".$provider['DB']."`.`autore` (`id_utente_autore`, `profilo`, `tariffa`) VALUES ($anUserId, NULL, 0);".
"UPDATE `".$provider['DB']."`.`modello_corso` SET `id_utente_autore`=$anUserId, `data_pubblicazione`=".time().", `data_creazione`=".time().";".
"UPDATE `".$provider['DB']."`.`nodo` SET `id_utente`=$anUserId, `data_creazione`=".time().";";
$stmt = $providers[$i]['pdo']->prepare($sql);
$stmt->execute();
unset($stmt);
$updateUser = true;
$userPrefix = 'autore';
} else if (in_array($anUserId, $switcherIds[$usersKey])) {
$updateUser = true;
$userPrefix = 'coordinatore';
}
if ($updateUser) {
$sql = "UPDATE `utente` SET `cognome`='".$provider['NAME']."', `username`='$userPrefix.".$providers[$i]['pointer']."' WHERE `id_utente`=$anUserId;";
$stmt = $commonpdo->prepare($sql);
$stmt->execute();
unset($stmt);
$stmt = $providers[$i]['pdo']->prepare($sql);
$stmt->execute();
unset($stmt);
array_push($newUsers, $userPrefix.'.'.$providers[$i]['pointer']);
$updateUser = false;
}
}
sendOK();
} else sendSkip();
sendToBrowser(sprintf(translateFN("Configurazione provider %s").'...', $provider['NAME']));
if (!is_file(ROOT_DIR . '/clients/'.$providers[$i]['pointer'].'/client_conf.inc.php')) {
if (!is_dir(ROOT_DIR . '/clients/'.$providers[$i]['pointer'])) {
mkdir(ROOT_DIR . '/clients/'.$providers[$i]['pointer'], 0770, true);
}
$outfile = str_replace(
[ '${UPPERPROVIDER}', '${ASISPROVIDER}_provider', '${PROV_HTTP}', '${MYSQL_USER}', '${MYSQL_PASSWORD}', '${MYSQL_HOST}', ],
[ strtoupper($providers[$i]['pointer']), $provider['DB'], $postData['HTTP_ROOT_DIR'], $postData['MYSQL'][$i]['USER'], $postData['MYSQL'][$i]['PASSWORD'], $postData['MYSQL'][$i]['HOST'], ],
file_get_contents(ROOT_DIR . '/clients_DEFAULT/install-templates/client_conf.inc.php')
);
if (false === file_put_contents(ROOT_DIR . '/clients/'.$providers[$i]['pointer'].'/client_conf.inc.php', $outfile)) {
throw new Exception(translateFN('Impossibile scrivere il file di configurazione del provider'));
} else sendOK();
} else sendSkip();
}
if (is_dir(MODULES_DIR)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(MODULES_DIR . DIRECTORY_SEPARATOR));
$regIter = new RegexIterator($iterator, '/^.+\.sql$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($regIter as $x) {
$modulesSQL = array_merge($modulesSQL, $x);
}
usort($modulesSQL, function($a, $b) {
// dirty hack to order by filename, having files that starts with a number as last elements
return strnatcmp('1'.basename($a). DIRECTORY_SEPARATOR . $a, '1'.basename($b) . DIRECTORY_SEPARATOR . $b );
});
// import modules sql in the databases
if (is_array($modulesSQL) && count($modulesSQL)>0) {
foreach($modulesSQL as $sqlFile) {
set_time_limit(300);
if (stristr($sqlFile, "menu") !== false ||
in_array(basename($sqlFile), $inCommon) ||
(!$multiprovider && in_array(basename($sqlFile), $inBothIfNonMulti)) ||
( $multiprovider && in_array(basename($sqlFile), $inCommonIfMulti))) {
sendToBrowser(translateFN("Importazione").' '.ltrim(str_replace(ROOT_DIR. '/modules', '', $sqlFile),'\/').' in '.$postData['COMMONDB'].' ...');
if ($commonEmpty) {
importSQL($sqlFile, $commonpdo);
sendOK();
} else sendSkip();
}
}
unset($commonpdo);
// done with the common db, now the providers
foreach ($providers as $i=>$provider) {
foreach($modulesSQL as $sqlFile) {
set_time_limit(300);
if (stristr($sqlFile, "menu") === false &&
!in_array(basename($sqlFile), $inCommon) &&
!( $multiprovider && in_array(basename($sqlFile), $inCommonIfMulti))
) {
sendToBrowser(translateFN("Importazione").' '.ltrim(str_replace(ROOT_DIR. '/modules', '', $sqlFile),'\/').' in '.$provider['DB'].' ...');
if ($providers[$i]['empty']) {
importSQL($sqlFile, $provider['pdo']);
sendOK();
} else sendSkip();
}
}
unset($providers[$i]['pdo']);
}
}
gc_collect_cycles();
// modules config files setup
$regIter = new RegexIterator($iterator, '/^[a-z:|\/].+[\/|\\\]config\_DEFAULT\.inc\.php$/i', RecursiveRegexIterator::GET_MATCH);
$configFiles = [];
foreach ($regIter as $x) {
$configFiles = array_merge($configFiles, $x);
}
if (is_array($configFiles) && count($configFiles)>0) {
foreach($configFiles as $configFile) {
$dirname = dirname($configFile);
$modulename = basename(str_replace('config','',$dirname));
sendToBrowser(translateFN("Configurazione modulo").' '.$modulename.' ...');
if (!in_array($modulename, $disabledModules)) {
if (is_dir($dirname) && is_writable($dirname)) {
$destFile = $dirname. DIRECTORY_SEPARATOR . str_replace('_DEFAULT','',basename($configFile));
if (!is_file($destFile)) {
if (copy($configFile, $destFile)) sendOK();
else sendFail();
} else sendSkip();
} else {
sendFail();
sendToBrowser('** '.translateFN('Impossibile scrivere nella directory del modulo'));
}
} else sendSkip();
}
}
// modules composer dependencies download
$regIter = new RegexIterator($iterator, '/^[a-z:|\/].+[\/|\\\]composer\.json$/i', RecursiveRegexIterator::GET_MATCH);
$composerFiles = [];
foreach ($regIter as $x) {
$composerFiles = array_merge($composerFiles, $x);
}
if (is_array($composerFiles) && count($composerFiles)>0) {
// Composer in php code, thanks to https://stackoverflow.com/a/17244866
define('COMPOSER_DIRECTORY', ADA_UPLOAD_PATH . 'composer');
define('COMPOSER_URL', 'https://getcomposer.org/download/1.10.20/composer.phar');
if (!is_dir(COMPOSER_DIRECTORY)) mkdir(COMPOSER_DIRECTORY);
if (file_exists(COMPOSER_DIRECTORY.'/vendor/autoload.php') !== true) {
set_time_limit(300);
sendToBrowser(translateFN('Download composer').'...');
copy(COMPOSER_URL, COMPOSER_DIRECTORY . DIRECTORY_SEPARATOR . 'Composer.phar');
sendOK();
sendToBrowser(translateFN('Estrazione composer').'...');
$composerPhar = new Phar(COMPOSER_DIRECTORY . DIRECTORY_SEPARATOR . 'Composer.phar');
$composerPhar->extractTo(COMPOSER_DIRECTORY);
sendOK();
unset($composerPhar);
}
ini_set('memory_limit', '1024M');
// Composer\Factory::getHomeDir() method needs COMPOSER_HOME environment variable set
putenv('COMPOSER_HOME=' . COMPOSER_DIRECTORY);
putenv('COMPOSER_MEMORY_LIMIT=128M');
//This requires the phar to have been extracted successfully.
require_once (COMPOSER_DIRECTORY.'/vendor/autoload.php');
foreach($composerFiles as $composerFile) {
$dirname = dirname($composerFile);
$modulename = basename($dirname);
if (stristr($composerFile,'vendor') === false) {
set_time_limit(300);
sendToBrowser(translateFN('Installazione dipendenze per il modulo').' '.$modulename.' ...');
// if (!in_array($modulename, $disabledModules)) {
if (is_dir($dirname) && is_writable($dirname)) {
$logfile = fopen(ROOT_DIR . DIRECTORY_SEPARATOR .'log' . DIRECTORY_SEPARATOR . 'composer-install.log', 'a');
fwrite ($logfile, sprintf("\n\n******** %s ********\n", $modulename));
chdir($dirname);
// Create the commands
$input = new Symfony\Component\Console\Input\StringInput('update -vvv -n --no-cache');
// Create the application and run it with the commands
$application = new Composer\Console\Application();
$application->setAutoExit(false); // prevent `$application->run` method from exitting the script
$application->setCatchExceptions(false);
$output = $application->run($input, new Symfony\Component\Console\Output\StreamOutput($logfile));
if ($output == 0) {
sendOK();
} else {
sendFail();
sendToBrowser('** '.translateFN('Problemi con composer'));
}
chdir(__DIR__);
fclose($logfile);
} else {
sendFail();
sendToBrowser('** '.translateFN('Impossibile scrivere nella directory del modulo'));
}
// } else sendSkip();
}
}
}
}
// create file with environment vars, this MUST BE the last step and if the ENV_FILENAME
// is written without errors, it should be safe to consider ADA as installed
sendToBrowser(translateFN('Generazione file configurazione').' ...');
if (!is_file(ENV_FILENAME)) {
// form variable to environment variable name mappings
$formtoenv = [
'PORTAL_NAME' => 'PORTAL_NAME',
'COMMONDB' => 'MYSQL_DATABASE',
'HTTP_ROOT_DIR' => 'HTTP_ROOT_DIR',
'ADA_ADMIN_MAIL_ADDRESS' => 'ADA_ADMIN_MAIL_ADDRESS',
'ADA_NOREPLY_MAIL_ADDRESS' => 'ADA_NOREPLY_MAIL_ADDRESS'
];
$envlines = [
'ADA_OR_WISP' => "putenv('ADA_OR_WISP=ADA')",
'MULTIPROVIDER' => "putenv('MULTIPROVIDER=".intval($multiprovider)."')",
'MYSQL_USER' => "putenv('MYSQL_USER=".$postData['MYSQL']['COMMON']['USER']."')",
'MYSQL_PASSWORD' => "putenv('MYSQL_PASSWORD=".$postData['MYSQL']['COMMON']['PASSWORD']."')" ,
'MYSQL_HOST' => "putenv('MYSQL_HOST=".$postData['MYSQL']['COMMON']['HOST']."')",
'DEFAULT_PROVIDER_POINTER' => "putenv('DEFAULT_PROVIDER_POINTER=".$providers[$defaultProvider]['pointer']."')",
'DEFAULT_PROVIDER_DB' => "putenv('DEFAULT_PROVIDER_DB=".$providers[$defaultProvider]['DB']."')",
'DEFAULT_PROVIDER_DB_USER' => "putenv('DEFAULT_PROVIDER_DB_USER=".$postData['MYSQL'][$defaultProvider]['USER']."')",
'DEFAULT_PROVIDER_DB_PASS' => "putenv('DEFAULT_PROVIDER_DB_PASS=".$postData['MYSQL'][$defaultProvider]['PASSWORD']."')",
'DEFAULT_PROVIDER_DB_HOST' => "putenv('DEFAULT_PROVIDER_DB_HOST=".$postData['MYSQL'][$defaultProvider]['HOST']."')",
];
foreach($formtoenv as $formkey => $envvar) {
if (array_key_exists($formkey, $postData) && strlen($postData[$formkey])>0) {
if ($formkey == 'HTTP_ROOT_DIR') {
$postData[$formkey] = rtrim($postData[$formkey], DIRECTORY_SEPARATOR);
}
$envlines[$formkey] = "putenv('$envvar=".$postData[$formkey]."')";
}
}
if (false === file_put_contents(ENV_FILENAME, "<?php".PHP_EOL.implode(';'.PHP_EOL, array_values($envlines)).";".PHP_EOL)) {
throw new Exception(translateFN('Impossibile scrivere il file di configurazione principale'));
} else {
chmod(ENV_FILENAME, 0440);
sendOK();
}
} else sendSkip();
sendToBrowser(translateFN('Rimozione file temopranei').' ...');
delTree(COMPOSER_DIRECTORY) ? sendOK() : sendFail();
if (is_array($newUsers) && count($newUsers)>0) {
sendToBrowser(PHP_EOL.PHP_EOL."<div style='font-size:1.2em;color:#ff9d51;'>Trascrivere in un posto sicuro lo username e la password degli utenti generati che sono:<strong>".PHP_EOL.implode(PHP_EOL, $newUsers).PHP_EOL."</strong>la password è quella fornita durante l'installazione.</div>".PHP_EOL);
}
sendToBrowser(' ');
sendToBrowser(PHP_EOL."<strong>".translateFN("ADA è installata, naviga su:") . " <a style='color:lime;' href='".
$postData['HTTP_ROOT_DIR']."' target='_top'>".$postData['HTTP_ROOT_DIR']."</a></strong>");
sendToBrowser('<script type="text/javascript">window.parent.postMessage("doneOK", "*");</script>');
} else throw new Exception(translateFN('Parametri MySQL/MariaDB non validi'), 1);
} catch (\Exception $e) {
sendFail();
sendToBrowser('** '.$e->getMessage().' ('.$e->getCode().')');
sendToBrowser('<script type="text/javascript">window.parent.postMessage("doneException", "*");</script>');
die();
}
} else {
session_start();
$_SESSION['sess_userObj'] = new ADAGuest();
$self = whoami();
$modulesAv = [];
$modulesDIS = [ 'secretquestion','code_man' ];
$modulesHidden = [ 'event-dispatcher', 'gdpr', 'login', 'test' ];
if (is_dir(MODULES_DIR)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(MODULES_DIR . DIRECTORY_SEPARATOR));
$regIter = new RegexIterator($iterator, '/^[a-z:|\/].+[\/|\\\]config\_DEFAULT\.inc\.php$/i', RecursiveRegexIterator::GET_MATCH);
$configFiles = [];
foreach ($regIter as $x) {
$configFiles = array_merge($configFiles, $x);
}
if (is_array($configFiles) && count($configFiles)>0) {
foreach($configFiles as $configFile) {
$dirname = dirname($configFile);
$modulesAv[] = basename(str_replace('config','',$dirname));
}
}
}
$modulesAv = array_diff($modulesAv, $modulesHidden);
sort($modulesAv);
sort($modulesDIS);
$modulesDIS = array_intersect($modulesDIS, $modulesAv);
/**
* Sends data to the rendering engine
*/
ARE::render(
[
'node_type' => null,
'family' => 'ada_blu',
'node_author_id' => null,
'node_course_id' => null,
'module_dir' => null
],
[
'modsavailable' => count($modulesAv)>0 ? translateFN('Moduli disabilitabili').': '.implode(', ', $modulesAv) : null,
'modsdisabled' => implode(', ',$modulesDIS)
],
null,
[
'onload_func' => 'initDoc();'
]
);
}