Passed
Push — teampass_3.0 ( 416a97...870788 )
by Nils
06:42
created

encryptFollowingDefuse()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 34
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 16
Bugs 0 Features 0
Metric Value
cc 7
eloc 26
c 16
b 0
f 0
nc 12
nop 2
dl 0
loc 34
rs 8.5706
1
<?php
2
/**
3
 * @author        Nils Laumaillé <[email protected]>
4
 *
5
 * @version       2.1.27
6
 *
7
 * @copyright     2009-2019 Nils Laumaillé
8
 * @license       GNU GPL-3.0
9
 *
10
 * @see          https://www.teampass.net
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
require_once '../sources/SecureHandler.php';
17
session_name('teampass_session');
18
session_start();
19
error_reporting(E_ERROR | E_PARSE);
20
header('Content-type: text/html; charset=utf-8');
21
$session_db_encoding = 'utf8';
22
23
function chmodRecursive($dir, $dirPermissions, $filePermissions)
24
{
25
    $pointer_dir = opendir($dir);
26
    $res = true;
27
    while ($file = readdir($pointer_dir)) {
0 ignored issues
show
Bug introduced by
It seems like $pointer_dir can also be of type false; however, parameter $dir_handle of readdir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

27
    while ($file = readdir(/** @scrutinizer ignore-type */ $pointer_dir)) {
Loading history...
28
        if (($file == '.') || ($file == '..')) {
29
            continue;
30
        }
31
32
        $fullPath = $dir.'/'.$file;
33
34
        if (is_dir($fullPath)) {
35
            if ($res = @chmod($fullPath, $dirPermissions)) {
36
                $res = @chmodRecursive($fullPath, $dirPermissions, $filePermissions);
37
            }
38
        } else {
39
            $res = chmod($fullPath, $filePermissions);
40
        }
41
        if (!$res) {
42
            closedir($pointer_dir);
0 ignored issues
show
Bug introduced by
It seems like $pointer_dir can also be of type false; however, parameter $dir_handle of closedir() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

42
            closedir(/** @scrutinizer ignore-type */ $pointer_dir);
Loading history...
43
44
            return false;
45
        }
46
    }
47
    closedir($pointer_dir);
48
    if (is_dir($dir) && $res) {
49
        $res = @chmod($dir, $dirPermissions);
50
    }
51
52
    return $res;
53
}
54
55
/**
56
 * genHash().
57
 *
58
 * Generate a hash for user login
59
 *
60
 * @param string $password
61
 */
62
function bCrypt($password, $cost)
63
{
64
    $salt = sprintf('$2y$%02d$', $cost);
65
    if (function_exists('openssl_random_pseudo_bytes')) {
66
        $salt .= bin2hex(openssl_random_pseudo_bytes(11));
67
    } else {
68
        $chars = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
69
        for ($i = 0; $i < 22; ++$i) {
70
            $salt .= $chars[mt_rand(0, 63)];
71
        }
72
    }
73
74
    return crypt($password, $salt);
75
}
76
77
/**
78
 * Generates a random key.
79
 */
80
function generateRandomKey()
81
{
82
    // load passwordLib library
83
    $path = '../includes/libraries/PasswordGenerator/Generator/';
84
    include_once $path.'ComputerPasswordGenerator.php';
85
86
    $generator = new PasswordGenerator\Generator\ComputerPasswordGenerator();
87
88
    $generator->setLength(40);
89
    $generator->setSymbols(false);
90
    $generator->setLowercase(true);
91
    $generator->setUppercase(true);
92
    $generator->setNumbers(true);
93
94
    $key = $generator->generatePasswords();
95
96
    return $key[0];
97
}
98
99
/**
100
 * Permits to encrypt a message using Defuse.
101
 *
102
 * @param string $message   Message to encrypt
103
 * @param string $ascii_key Key to hash
104
 *
105
 * @return array String + Error
106
 */
107
function encryptFollowingDefuse($message, $ascii_key)
108
{
109
    // load PhpEncryption library
110
    $path = '../includes/libraries/Encryption/Encryption/';
111
    require_once $path.'Crypto.php';
112
    require_once $path.'Encoding.php';
113
    require_once $path.'DerivedKeys.php';
114
    require_once $path.'Key.php';
115
    require_once $path.'KeyOrPassword.php';
116
    require_once $path.'File.php';
117
    require_once $path.'RuntimeTests.php';
118
    require_once $path.'KeyProtectedByPassword.php';
119
    require_once $path.'Core.php';
120
121
    // convert KEY
122
    $key = \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key);
123
124
    try {
125
        $text = \Defuse\Crypto\Crypto::encrypt($message, $key);
126
    } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
127
        $err = 'an attack! either the wrong key was loaded, or the ciphertext has changed since it was created either corrupted in the database or intentionally modified by someone trying to carry out an attack.';
128
    } catch (Defuse\Crypto\Exception\BadFormatException $ex) {
129
        $err = $ex;
130
    } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
131
        $err = $ex;
132
    } catch (Defuse\Crypto\Exception\CryptoException $ex) {
133
        $err = $ex;
134
    } catch (Defuse\Crypto\Exception\IOException $ex) {
135
        $err = $ex;
136
    }
137
138
    return array(
139
        'string' => isset($text) ? $text : '',
140
        'error' => $err,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $err does not seem to be defined for all execution paths leading up to this point.
Loading history...
141
    );
142
}
143
144
// Prepare POST variables
145
$post_type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING);
146
$post_data = filter_input(INPUT_POST, 'data', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
147
$post_activity = filter_input(INPUT_POST, 'activity', FILTER_SANITIZE_STRING);
148
$post_task = filter_input(INPUT_POST, 'task', FILTER_SANITIZE_STRING);
149
$post_index = filter_input(INPUT_POST, 'index', FILTER_SANITIZE_NUMBER_INT);
150
$post_multiple = filter_input(INPUT_POST, 'multiple', FILTER_SANITIZE_STRING);
151
$post_db = filter_input(INPUT_POST, 'db', FILTER_SANITIZE_STRING);
152
153
// Load libraries
154
require_once '../includes/libraries/protect/SuperGlobal/SuperGlobal.php';
155
$superGlobal = new protect\SuperGlobal\SuperGlobal();
156
157
// Prepare SESSION variables
158
$session_url_path = $superGlobal->get('url_path', 'SESSION');
159
$session_abspath = $superGlobal->get('abspath', 'SESSION');
160
$session_db_encoding = $superGlobal->get('db_encoding', 'SESSION');
161
162
$superGlobal->put('CPM', 1, 'SESSION');
163
164
if (null !== $post_type) {
165
    switch ($post_type) {
166
        case 'step_2':
167
            //decrypt
168
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
169
            $json = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128);
0 ignored issues
show
Bug introduced by
'cpm' of type string is incompatible with the type Encryption\Crypt\the expected by parameter $password of Encryption\Crypt\aesctr::decrypt(). ( Ignorable by Annotation )

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

169
            $json = Encryption\Crypt\aesctr::decrypt($post_data, /** @scrutinizer ignore-type */ 'cpm', 128);
Loading history...
170
            $data = json_decode($json, true);
171
            $json = Encryption\Crypt\aesctr::decrypt($post_activity, 'cpm', 128);
172
            $data = array_merge($data, array('activity' => $json));
173
            $json = Encryption\Crypt\aesctr::decrypt($post_task, 'cpm', 128);
174
            $data = array_merge($data, array('task' => $json));
175
176
            $abspath = str_replace('\\', '/', $data['root_path']);
177
            if (substr($abspath, strlen($abspath) - 1) == '/') {
178
                $abspath = substr($abspath, 0, strlen($abspath) - 1);
179
            }
180
            $session_abspath = $abspath;
181
            $session_url_path = $data['url_path'];
182
183
            if (isset($data['activity']) && $data['activity'] === 'folder') {
184
                if (is_writable($abspath.'/'.$data['task'].'/') === true) {
185
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
186
                } else {
187
                    echo '[{"error" : " Path '.$data['task'].' is not writable!", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
188
                }
189
                break;
190
            }
191
192
            if (isset($data['activity']) && $data['activity'] === 'extension') {
193
                if (extension_loaded($data['task'])) {
194
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
195
                } else {
196
                    echo '[{"error" : " Extension '.$data['task'].' is not loaded!", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
197
                }
198
                break;
199
            }
200
201
            if (isset($data['activity']) && $data['activity'] === 'function') {
202
                if (function_exists($data['task'])) {
203
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
204
                } else {
205
                    echo '[{"error" : " Function '.$data['task'].' is not available!", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
206
                }
207
                break;
208
            }
209
210
            if (isset($data['activity']) && $data['activity'] === 'version') {
211
                if (version_compare(phpversion(), '5.5.0', '>=')) {
212
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
213
                } else {
214
                    echo '[{"error" : "PHP version '.phpversion().' is not OK (minimum is 5.5.0)", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
215
                }
216
                break;
217
            }
218
219
            if (isset($data['activity']) && $data['activity'] === 'ini') {
220
                if (ini_get($data['task']) >= 60) {
221
                    echo '[{"error" : "", "index" : "'.$post_index.'"}]';
222
                } else {
223
                    echo '[{"error" : "PHP \"Maximum execution time\" is set to '.ini_get('max_execution_time').' seconds. Please try to set to 60s at least during installation.", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
224
                }
225
                break;
226
            }
227
            break;
228
229
        case 'step_3':
230
            //decrypt
231
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
232
            $json = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128);
233
            $data = json_decode($json, true);
234
            $json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128);
235
            $db = json_decode($json, true);
236
237
            // launch
238
            if ($dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port'])) {
239
                // create temporary INSTALL mysqli table
240
                $mysqli_result = mysqli_query(
241
                    $dbTmp,
242
                    'CREATE TABLE IF NOT EXISTS `_install` (
243
                    `key` varchar(100) NOT NULL,
244
                    `value` varchar(500) NOT NULL,
245
                    PRIMARY KEY (`key`)
246
                    ) CHARSET=utf8;'
247
                );
248
                // store values
249
                foreach ($data as $key => $value) {
250
                    $superGlobal->put($key, $value, 'SESSION');
251
                    $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = '".$key."'"));
0 ignored issues
show
Bug introduced by
It seems like mysqli_query($dbTmp, 'SE...key` = '' . $key . ''') can also be of type boolean; however, parameter $result of mysqli_num_rows() does only seem to accept mysqli_result, maybe add an additional type check? ( Ignorable by Annotation )

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

251
                    $tmp = mysqli_num_rows(/** @scrutinizer ignore-type */ mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = '".$key."'"));
Loading history...
252
                    if (intval($tmp) === 0) {
253
                        mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('".$key."', '".$value."');");
254
                    } else {
255
                        mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".$value."' WHERE `key` = '".$key."';");
256
                    }
257
                }
258
                $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = 'url_path'"));
259
                if (intval($tmp) === 0) {
260
                    mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('url_path', '".empty($session_url_path) ? $db['url_path'] : $session_url_path."');");
261
                } else {
262
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($session_url_path) ? $db['url_path'] : $session_url_path, "' WHERE `key` = 'url_path';");
0 ignored issues
show
Unused Code introduced by
The call to mysqli_query() has too many arguments starting with '' WHERE `key` = 'url_path';'. ( Ignorable by Annotation )

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

262
                    /** @scrutinizer ignore-call */ 
263
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($session_url_path) ? $db['url_path'] : $session_url_path, "' WHERE `key` = 'url_path';");

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
263
                }
264
                $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = 'abspath'"));
265
                if (intval($tmp) === 0) {
266
                    mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('abspath', '".empty($session_abspath) ? $db['abspath'] : $session_abspath."');");
267
                } else {
268
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".empty($session_abspath) ? $db['abspath'] : $session_abspath."' WHERE `key` = 'abspath';");
269
                }
270
271
                echo '[{"error" : "", "result" : "Connection is successful", "multiple" : ""}]';
272
            } else {
273
                echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]';
274
            }
275
            mysqli_close($dbTmp);
276
            break;
277
278
        case 'step_4':
279
            //decrypt
280
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
281
            $json = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128);
282
            $data = json_decode($json, true);
283
            $json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128);
284
            $db = json_decode($json, true);
285
286
            $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
287
288
            // prepare data
289
            foreach ($data as $key => $value) {
290
                $data[$key] = str_replace(array('&quot;', '&#92;'), array('""', '\\\\'), $value);
291
            }
292
293
            // check skpath
294
            if (empty($data['sk_path'])) {
295
                $data['sk_path'] = $session_abspath.'/includes';
296
            } else {
297
                $data['sk_path'] = str_replace('&#92;', '/', $data['sk_path']);
298
            }
299
            if (substr($data['sk_path'], strlen($data['sk_path']) - 1) == '/' || substr($data['sk_path'], strlen($data['sk_path']) - 1) == '"') {
300
                $data['sk_path'] = substr($data['sk_path'], 0, strlen($data['sk_path']) - 1);
301
            }
302
            if (is_dir($data['sk_path'])) {
303
                if (is_writable($data['sk_path'])) {
304
                    // store all variables in SESSION
305
                    foreach ($data as $key => $value) {
306
                        $superGlobal->put($key, $value, 'SESSION');
307
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = '".$key."'"));
308
                        if (intval($tmp) === 0) {
309
                            mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('".$key."', '".$value."');");
310
                        } else {
311
                            mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".$value."' WHERE `key` = '".$key."';");
312
                        }
313
                    }
314
                    echo '[{"error" : "", "result" : "Information stored", "multiple" : ""}]';
315
                } else {
316
                    echo '[{"error" : "The Directory must be writable!", "result" : "Information stored", "multiple" : ""}]';
317
                }
318
            } else {
319
                echo '[{"error" : "'.$data['sk_path'].' is not a Directory!", "result" : "Information stored", "multiple" : ""}]';
320
            }
321
            mysqli_close($dbTmp);
322
            break;
323
324
        case 'step_5':
325
            //decrypt
326
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
327
            $activity = Encryption\Crypt\aesctr::decrypt($post_activity, 'cpm', 128);
328
            $task = Encryption\Crypt\aesctr::decrypt($post_task, 'cpm', 128);
329
            $json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128);
330
            $db = json_decode($json, true);
331
332
            // launch
333
            $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
334
            $dbBdd = $db['db_bdd'];
335
            if ($dbTmp) {
0 ignored issues
show
introduced by
$dbTmp is of type mysqli, thus it always evaluated to true.
Loading history...
336
                $mysqli_result = '';
337
338
                // read install variables
339
                $result = mysqli_query($dbTmp, 'SELECT * FROM `_install`');
340
                while ($row = $result->fetch_array()) {
341
                    $var[$row[0]] = $row[1];
342
                }
343
344
                if ($activity === 'table') {
345
                    if ($task === 'utf8') {
346
                        //FORCE UTF8 DATABASE
347
                        mysqli_query($dbTmp, 'ALTER DATABASE `'.$dbBdd.'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
348
                    } elseif ($task === 'items') {
349
                        $mysqli_result = mysqli_query(
350
                            $dbTmp,
351
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."items` (
352
                            `id` int(12) NOT null AUTO_INCREMENT,
353
                            `label` varchar(500) NOT NULL,
354
                            `description` text DEFAULT NULL,
355
                            `pw` text DEFAULT NULL,
356
                            `pw_iv` text DEFAULT NULL,
357
                            `pw_len` int(5) NOT NULL DEFAULT '0',
358
                            `url` varchar(500) DEFAULT NULL,
359
                            `id_tree` varchar(10) DEFAULT NULL,
360
                            `perso` tinyint(1) NOT null DEFAULT '0',
361
                            `login` varchar(200) DEFAULT NULL,
362
                            `inactif` tinyint(1) NOT null DEFAULT '0',
363
                            `restricted_to` varchar(200) DEFAULT NULL,
364
                            `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',
365
                            `email` varchar(100) DEFAULT NULL,
366
                            `notification` varchar(250) DEFAULT NULL,
367
                            `viewed_no` int(12) NOT null DEFAULT '0',
368
                            `complexity_level` varchar(3) NOT null DEFAULT '-1',
369
                            `auto_update_pwd_frequency` tinyint(2) NOT null DEFAULT '0',
370
                            `auto_update_pwd_next_date` varchar(100) NOT null DEFAULT '0',
371
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
372
                            PRIMARY KEY (`id`),
373
                            KEY    `restricted_inactif_idx` (`restricted_to`,`inactif`)
374
                            ) CHARSET=utf8;"
375
                        );
376
                    } elseif ($task === 'log_items') {
377
                        $mysqli_result = mysqli_query(
378
                            $dbTmp,
379
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."log_items` (
380
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
381
                            `id_item` int(8) NOT NULL,
382
                            `date` varchar(50) NOT NULL,
383
                            `id_user` int(8) NOT NULL,
384
                            `action` varchar(250) NULL,
385
                            `raison` text NULL,
386
                            `raison_iv` text NULL,
387
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
388
                            PRIMARY KEY (`increment_id`)
389
                            ) CHARSET=utf8;"
390
                        );
391
                        // create index
392
                        mysqli_query(
393
                            $dbTmp,
394
                            'CREATE INDEX teampass_log_items_id_item_IDX ON '.$var['tbl_prefix'].'log_items (id_item,date);'
395
                        );
396
                    } elseif ($task === 'misc') {
397
                        $mysqli_result = mysqli_query(
398
                            $dbTmp,
399
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'misc` (
400
                            `increment_id` int(12) NOT null AUTO_INCREMENT,
401
                            `type` varchar(50) NOT NULL,
402
                            `intitule` varchar(100) NOT NULL,
403
                            `valeur` varchar(500) NOT NULL,
404
                            PRIMARY KEY (`increment_id`)
405
                            ) CHARSET=utf8;'
406
                        );
407
408
                        // include constants
409
                        require_once '../includes/config/include.php';
410
411
                        // prepare config file
412
                        $tp_config_file = '../includes/config/tp.config.php';
413
                        if (file_exists($tp_config_file)) {
414
                            if (!copy($tp_config_file, $tp_config_file.'.'.date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) {
415
                                echo '[{"error" : "includes/config/tp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
416
                                break;
417
                            } else {
418
                                unlink($tp_config_file);
419
                            }
420
                        }
421
                        $file_handler = fopen($tp_config_file, 'w');
422
                        $config_text = '<?php
423
global $SETTINGS;
424
$SETTINGS = array (';
425
426
                        // add by default settings
427
                        $aMiscVal = array(
428
                            array('admin', 'max_latest_items', '10'),
429
                            array('admin', 'enable_favourites', '1'),
430
                            array('admin', 'show_last_items', '1'),
431
                            array('admin', 'enable_pf_feature', '0'),
432
                            array('admin', 'log_connections', '0'),
433
                            array('admin', 'log_accessed', '1'),
434
                            array('admin', 'time_format', 'H:i:s'),
435
                            array('admin', 'date_format', 'd/m/Y'),
436
                            array('admin', 'duplicate_folder', '0'),
437
                            array('admin', 'item_duplicate_in_same_folder', '0'),
438
                            array('admin', 'duplicate_item', '0'),
439
                            array('admin', 'number_of_used_pw', '3'),
440
                            array('admin', 'manager_edit', '1'),
441
                            array('admin', 'cpassman_dir', $var['abspath']),
442
                            array('admin', 'cpassman_url', $var['url_path']),
443
                            array('admin', 'favicon', $var['url_path'].'/favicon.ico'),
444
                            array('admin', 'path_to_upload_folder', $var['abspath'].'/upload'),
445
                            array('admin', 'url_to_upload_folder', $var['url_path'].'/upload'),
446
                            array('admin', 'path_to_files_folder', $var['abspath'].'/files'),
447
                            array('admin', 'url_to_files_folder', $var['url_path'].'/files'),
448
                            array('admin', 'activate_expiration', '0'),
449
                            array('admin', 'pw_life_duration', '0'),
450
                            array('admin', 'maintenance_mode', '1'),
451
                            array('admin', 'enable_sts', '0'),
452
                            array('admin', 'encryptClientServer', '1'),
453
                            array('admin', 'cpassman_version', $SETTINGS_EXT['version']),
454
                            array('admin', 'ldap_mode', '0'),
455
                            array('admin', 'ldap_type', '0'),
456
                            array('admin', 'ldap_suffix', '0'),
457
                            array('admin', 'ldap_domain_dn', '0'),
458
                            array('admin', 'ldap_domain_controler', '0'),
459
                            array('admin', 'ldap_user_attribute', '0'),
460
                            array('admin', 'ldap_ssl', '0'),
461
                            array('admin', 'ldap_tls', '0'),
462
                            array('admin', 'ldap_elusers', '0'),
463
                            array('admin', 'ldap_search_base', '0'),
464
                            array('admin', 'ldap_port', '389'),
465
                            array('admin', 'richtext', '0'),
466
                            array('admin', 'allow_print', '0'),
467
                            array('admin', 'roles_allowed_to_print', '0'),
468
                            array('admin', 'show_description', '1'),
469
                            array('admin', 'anyone_can_modify', '0'),
470
                            array('admin', 'anyone_can_modify_bydefault', '0'),
471
                            array('admin', 'nb_bad_authentication', '0'),
472
                            array('admin', 'utf8_enabled', '1'),
473
                            array('admin', 'restricted_to', '0'),
474
                            array('admin', 'restricted_to_roles', '0'),
475
                            array('admin', 'enable_send_email_on_user_login', '0'),
476
                            array('admin', 'enable_user_can_create_folders', '0'),
477
                            array('admin', 'insert_manual_entry_item_history', '0'),
478
                            array('admin', 'enable_kb', '0'),
479
                            array('admin', 'enable_email_notification_on_item_shown', '0'),
480
                            array('admin', 'enable_email_notification_on_user_pw_change', '0'),
481
                            array('admin', 'custom_logo', ''),
482
                            array('admin', 'custom_login_text', ''),
483
                            array('admin', 'default_language', 'english'),
484
                            array('admin', 'send_stats', '0'),
485
                            array('admin', 'send_statistics_items', 'stat_country;stat_users;stat_items;stat_items_shared;stat_folders;stat_folders_shared;stat_admins;stat_managers;stat_ro;stat_mysqlversion;stat_phpversion;stat_teampassversion;stat_languages;stat_kb;stat_suggestion;stat_customfields;stat_api;stat_2fa;stat_agses;stat_duo;stat_ldap;stat_syslog;stat_stricthttps;stat_fav;stat_pf;'),
486
                            array('admin', 'send_stats_time', time() - 2592000),
487
                            array('admin', 'get_tp_info', '1'),
488
                            array('admin', 'send_mail_on_user_login', '0'),
489
                            array('cron', 'sending_emails', '0'),
490
                            array('admin', 'nb_items_by_query', 'auto'),
491
                            array('admin', 'enable_delete_after_consultation', '0'),
492
                            array('admin', 'enable_personal_saltkey_cookie', '0'),
493
                            array('admin', 'personal_saltkey_cookie_duration', '31'),
494
                            array('admin', 'email_smtp_server', ''),
495
                            array('admin', 'email_smtp_auth', ''),
496
                            array('admin', 'email_auth_username', ''),
497
                            array('admin', 'email_auth_pwd', ''),
498
                            array('admin', 'email_port', ''),
499
                            array('admin', 'email_security', ''),
500
                            array('admin', 'email_server_url', ''),
501
                            array('admin', 'email_from', ''),
502
                            array('admin', 'email_from_name', ''),
503
                            array('admin', 'pwd_maximum_length', '40'),
504
                            array('admin', 'google_authentication', '0'),
505
                            array('admin', 'delay_item_edition', '0'),
506
                            array('admin', 'allow_import', '0'),
507
                            array('admin', 'proxy_ip', ''),
508
                            array('admin', 'proxy_port', ''),
509
                            array('admin', 'upload_maxfilesize', '10mb'),
510
                            array('admin', 'upload_docext', 'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx'),
511
                            array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png'),
512
                            array('admin', 'upload_pkgext', '7z,rar,tar,zip'),
513
                            array('admin', 'upload_otherext', 'sql,xml'),
514
                            array('admin', 'upload_imageresize_options', '1'),
515
                            array('admin', 'upload_imageresize_width', '800'),
516
                            array('admin', 'upload_imageresize_height', '600'),
517
                            array('admin', 'upload_imageresize_quality', '90'),
518
                            array('admin', 'use_md5_password_as_salt', '0'),
519
                            array('admin', 'ga_website_name', 'TeamPass for ChangeMe'),
520
                            array('admin', 'api', '0'),
521
                            array('admin', 'subfolder_rights_as_parent', '0'),
522
                            array('admin', 'show_only_accessible_folders', '0'),
523
                            array('admin', 'enable_suggestion', '0'),
524
                            array('admin', 'otv_expiration_period', '7'),
525
                            array('admin', 'default_session_expiration_time', '60'),
526
                            array('admin', 'duo', '0'),
527
                            array('admin', 'enable_server_password_change', '0'),
528
                            array('admin', 'ldap_object_class', '0'),
529
                            array('admin', 'bck_script_path', $var['abspath'].'/backups'),
530
                            array('admin', 'bck_script_filename', 'bck_teampass'),
531
                            array('admin', 'syslog_enable', '0'),
532
                            array('admin', 'syslog_host', 'localhost'),
533
                            array('admin', 'syslog_port', '514'),
534
                            array('admin', 'manager_move_item', '0'),
535
                            array('admin', 'create_item_without_password', '0'),
536
                            array('admin', 'otv_is_enabled', '0'),
537
                            array('admin', 'agses_authentication_enabled', '0'),
538
                            array('admin', 'item_extra_fields', '0'),
539
                            array('admin', 'saltkey_ante_2127', 'none'),
540
                            array('admin', 'migration_to_2127', 'done'),
541
                            array('admin', 'files_with_defuse', 'done'),
542
                            array('admin', 'timezone', 'UTC'),
543
                            array('admin', 'enable_attachment_encryption', '1'),
544
                            array('admin', 'personal_saltkey_security_level', '50'),
545
                            array('admin', 'ldap_new_user_is_administrated_by', '0'),
546
                            array('admin', 'disable_show_forgot_pwd_link', '0'),
547
                            array('admin', 'offline_key_level', '0'),
548
                            array('admin', 'enable_http_request_login', '0'),
549
                            array('admin', 'ldap_and_local_authentication', '0'),
550
                            array('admin', 'secure_display_image', '1'),
551
                            array('admin', 'upload_zero_byte_file', '0'),
552
                            array('admin', 'upload_all_extensions_file', '0'),
553
                            array('admin', 'bck_script_passkey', generateRandomKey()),
554
                            array('admin', 'admin_2fa_required', '1'),
555
                        );
556
                        foreach ($aMiscVal as $elem) {
557
                            //Check if exists before inserting
558
                            $tmp = mysqli_num_rows(
559
                                mysqli_query(
560
                                    $dbTmp,
561
                                    'SELECT * FROM `'.$var['tbl_prefix']."misc`
562
                                    WHERE type='".$elem[0]."' AND intitule='".$elem[1]."'"
563
                                )
564
                            );
565
                            if (intval($tmp) === 0) {
566
                                $queryRes = mysqli_query(
567
                                    $dbTmp,
568
                                    'INSERT INTO `'.$var['tbl_prefix']."misc`
569
                                    (`type`, `intitule`, `valeur`) VALUES
570
                                    ('".$elem[0]."', '".$elem[1]."', '".
571
                                    str_replace("'", '', $elem[2])."');"
572
                                ); // or die(mysqli_error($dbTmp))
573
                            }
574
575
                            // append new setting in config file
576
                            $config_text .= "
577
    '".$elem[1]."' => '".str_replace("'", '', $elem[2])."',";
578
                        }
579
580
                        // write to config file
581
                        $result = fwrite(
582
                            $file_handler,
0 ignored issues
show
Bug introduced by
It seems like $file_handler can also be of type false; however, parameter $handle of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

582
                            /** @scrutinizer ignore-type */ $file_handler,
Loading history...
583
                            utf8_encode(
584
                                $config_text.'
585
);'
586
                            )
587
                        );
588
                        fclose($file_handler);
0 ignored issues
show
Bug introduced by
It seems like $file_handler can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

588
                        fclose(/** @scrutinizer ignore-type */ $file_handler);
Loading history...
589
                    } elseif ($task === 'nested_tree') {
590
                        $mysqli_result = mysqli_query(
591
                            $dbTmp,
592
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."nested_tree` (
593
                            `id` bigint(20) unsigned NOT null AUTO_INCREMENT,
594
                            `parent_id` int(11) NOT NULL,
595
                            `title` varchar(255) NOT NULL,
596
                            `nleft` int(11) NOT NULL DEFAULT '0',
597
                            `nright` int(11) NOT NULL DEFAULT '0',
598
                            `nlevel` int(11) NOT NULL DEFAULT '0',
599
                            `bloquer_creation` tinyint(1) NOT null DEFAULT '0',
600
                            `bloquer_modification` tinyint(1) NOT null DEFAULT '0',
601
                            `personal_folder` tinyint(1) NOT null DEFAULT '0',
602
                            `renewal_period` int(5) NOT null DEFAULT '0',
603
                            PRIMARY KEY (`id`),
604
                            KEY `nested_tree_parent_id` (`parent_id`),
605
                            KEY `nested_tree_nleft` (`nleft`),
606
                            KEY `nested_tree_nright` (`nright`),
607
                            KEY `nested_tree_nlevel` (`nlevel`),
608
                            KEY `personal_folder_idx` (`personal_folder`)
609
                            ) CHARSET=utf8;"
610
                        );
611
                    } elseif ($task === 'rights') {
612
                        $mysqli_result = mysqli_query(
613
                            $dbTmp,
614
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."rights` (
615
                            `id` int(12) NOT null AUTO_INCREMENT,
616
                            `tree_id` int(12) NOT NULL,
617
                            `fonction_id` int(12) NOT NULL,
618
                            `authorized` tinyint(1) NOT null DEFAULT '0',
619
                            PRIMARY KEY (`id`)
620
                            ) CHARSET=utf8;"
621
                        );
622
                    } elseif ($task === 'users') {
623
                        $mysqli_result = mysqli_query(
624
                            $dbTmp,
625
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."users` (
626
                            `id` int(12) NOT null AUTO_INCREMENT,
627
                            `login` varchar(50) NOT NULL,
628
                            `pw` varchar(400) NOT NULL,
629
                            `groupes_visibles` varchar(1000) NOT NULL,
630
                            `derniers` text NULL,
631
                            `key_tempo` varchar(100) NULL,
632
                            `last_pw_change` varchar(30) NULL,
633
                            `last_pw` text NULL,
634
                            `admin` tinyint(1) NOT null DEFAULT '0',
635
                            `fonction_id` varchar(1000) NULL,
636
                            `groupes_interdits` varchar(1000) NULL,
637
                            `last_connexion` varchar(30) NULL,
638
                            `gestionnaire` int(11) NOT null DEFAULT '0',
639
                            `email` varchar(300) NOT NULL DEFAULT 'none',
640
                            `favourites` varchar(1000) NULL,
641
                            `latest_items` varchar(1000) NULL,
642
                            `personal_folder` int(1) NOT null DEFAULT '0',
643
                            `disabled` tinyint(1) NOT null DEFAULT '0',
644
                            `no_bad_attempts` tinyint(1) NOT null DEFAULT '0',
645
                            `can_create_root_folder` tinyint(1) NOT null DEFAULT '0',
646
                            `read_only` tinyint(1) NOT null DEFAULT '0',
647
                            `timestamp` varchar(30) NOT null DEFAULT '0',
648
                            `user_language` varchar(50) NOT null DEFAULT '0',
649
                            `name` varchar(100) NULL,
650
                            `lastname` varchar(100) NULL,
651
                            `session_end` varchar(30) NULL,
652
                            `isAdministratedByRole` tinyint(5) NOT null DEFAULT '0',
653
                            `psk` varchar(400) NULL,
654
                            `ga` varchar(50) NULL,
655
                            `ga_temporary_code` VARCHAR(20) NOT NULL DEFAULT 'none',
656
                            `avatar` varchar(1000) NULL DEFAULT NULL,
657
                            `avatar_thumb` varchar(1000) NULL DEFAULT NULL,
658
                            `upgrade_needed` BOOLEAN NOT NULL DEFAULT FALSE,
659
                            `treeloadstrategy` varchar(30) NOT null DEFAULT 'full',
660
                            `can_manage_all_users` tinyint(1) NOT NULL DEFAULT '0',
661
                            `usertimezone` VARCHAR(50) NOT NULL DEFAULT 'not_defined',
662
                            `agses-usercardid` VARCHAR(50) NOT NULL DEFAULT '0',
663
                            `encrypted_psk` text NULL,
664
                            `user_ip` varchar(400) NOT null DEFAULT 'none',
665
                            `user_ip_lastdate` varchar(50) NULL DEFAULT NULL,
666
                            `user_api_key` varchar(500) NOT null DEFAULT 'none',
667
                            `yubico_user_key` varchar(100) NOT null DEFAULT 'none',
668
                            `yubico_user_id` varchar(100) NOT null DEFAULT 'none',
669
                            PRIMARY KEY (`id`),
670
                            UNIQUE KEY `login` (`login`)
671
                            ) CHARSET=utf8;"
672
                        );
673
674
                        require_once '../includes/config/include.php';
675
                        // check that admin accounts doesn't exist
676
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, 'SELECT * FROM `'.$var['tbl_prefix']."users` WHERE login = 'admin'"));
677
                        if ($tmp === 0) {
678
                            $mysqli_result = mysqli_query(
679
                                $dbTmp,
680
                                'INSERT INTO `'.$var['tbl_prefix']."users` (`id`, `login`, `pw`, `admin`, `gestionnaire`, `personal_folder`, `groupes_visibles`, `email`, `encrypted_psk`, `last_pw_change`) VALUES ('1', 'admin', '".bCrypt($var['admin_pwd'], '13')."', '1', '0', '0', '', '', '', '".time()."')"
681
                            );
682
                        } else {
683
                            $mysqli_result = mysqli_query($dbTmp, 'UPDATE `'.$var['tbl_prefix']."users` SET `pw` = '".bCrypt($var['admin_pwd'], '13')."' WHERE login = 'admin' AND id = '1'");
684
                        }
685
686
                        // check that API doesn't exist
687
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, 'SELECT * FROM `'.$var['tbl_prefix']."users` WHERE id = '".API_USER_ID."'"));
688
                        if ($tmp === 0) {
689
                            $mysqli_result = mysqli_query(
690
                                $dbTmp,
691
                                'INSERT INTO `'.$var['tbl_prefix']."users` (`id`, `login`, `pw`, `groupes_visibles`, `derniers`, `key_tempo`, `last_pw_change`, `last_pw`, `admin`, `fonction_id`, `groupes_interdits`, `last_connexion`, `gestionnaire`, `email`, `favourites`, `latest_items`, `personal_folder`) VALUES ('".API_USER_ID."', 'API', '', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0')"
692
                            );
693
                        }
694
695
                        // check that OTV doesn't exist
696
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, 'SELECT * FROM `'.$var['tbl_prefix']."users` WHERE id = '".OTV_USER_ID."'"));
697
                        if ($tmp === 0) {
698
                            $mysqli_result = mysqli_query(
699
                                $dbTmp,
700
                                'INSERT INTO `'.$var['tbl_prefix']."users` (`id`, `login`, `pw`, `groupes_visibles`, `derniers`, `key_tempo`, `last_pw_change`, `last_pw`, `admin`, `fonction_id`, `groupes_interdits`, `last_connexion`, `gestionnaire`, `email`, `favourites`, `latest_items`, `personal_folder`) VALUES ('".OTV_USER_ID."', 'OTV', '', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0')"
701
                            );
702
                        }
703
                    } elseif ($task === 'tags') {
704
                        $mysqli_result = mysqli_query(
705
                            $dbTmp,
706
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'tags` (
707
                            `id` int(12) NOT null AUTO_INCREMENT,
708
                            `tag` varchar(30) NOT NULL,
709
                            `item_id` int(12) NOT NULL,
710
                            PRIMARY KEY (`id`)
711
                            ) CHARSET=utf8;'
712
                        );
713
                    } elseif ($task === 'log_system') {
714
                        $mysqli_result = mysqli_query(
715
                            $dbTmp,
716
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'log_system` (
717
                            `id` int(12) NOT null AUTO_INCREMENT,
718
                            `type` varchar(20) NOT NULL,
719
                            `date` varchar(30) NOT NULL,
720
                            `label` text NOT NULL,
721
                            `qui` varchar(255) NOT NULL,
722
                            `field_1` varchar(250) DEFAULT NULL,
723
                            PRIMARY KEY (`id`)
724
                            ) CHARSET=utf8;'
725
                        );
726
                    } elseif ($task === 'files') {
727
                        $mysqli_result = mysqli_query(
728
                            $dbTmp,
729
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."files` (
730
                            `id` int(11) NOT null AUTO_INCREMENT,
731
                            `id_item` int(11) NOT NULL,
732
                            `name` varchar(100) NOT NULL,
733
                            `size` int(10) NOT NULL,
734
                            `extension` varchar(10) NOT NULL,
735
                            `type` varchar(255) NOT NULL,
736
                            `file` varchar(50) NOT NULL,
737
                            `status` varchar(50) NOT NULL DEFAULT '0',
738
                            `content` longblob DEFAULT NULL,
739
                            PRIMARY KEY (`id`)
740
                           ) CHARSET=utf8;"
741
                        );
742
                    } elseif ($task === 'cache') {
743
                        $mysqli_result = mysqli_query(
744
                            $dbTmp,
745
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."cache` (
746
                            `increment_id`INT(12) NOT NULL AUTO_INCREMENT,
747
                            `id` int(12) NOT NULL,
748
                            `label` varchar(500) NOT NULL,
749
                            `description` text NOT NULL,
750
                            `tags` text DEFAULT NULL,
751
                            `id_tree` int(12) NOT NULL,
752
                            `perso` tinyint(1) NOT NULL,
753
                            `restricted_to` varchar(200) DEFAULT NULL,
754
                            `login` varchar(200) DEFAULT NULL,
755
                            `folder` varchar(300) NOT NULL,
756
                            `author` varchar(50) NOT NULL,
757
                            `renewal_period` tinyint(4) NOT NULL DEFAULT '0',
758
                            `timestamp` varchar(50) DEFAULT NULL,
759
                            `url` varchar(500) NOT NULL DEFAULT '0',
760
                            `encryption_type` VARCHAR(50) DEFAULT NULL DEFAULT '0',
761
                            PRIMARY KEY (`increment_id`)
762
                            ) CHARSET=utf8;"
763
                        );
764
                    } elseif ($task === 'roles_title') {
765
                        $mysqli_result = mysqli_query(
766
                            $dbTmp,
767
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."roles_title` (
768
                            `id` int(12) NOT null AUTO_INCREMENT,
769
                            `title` varchar(50) NOT NULL,
770
                            `allow_pw_change` TINYINT(1) NOT null DEFAULT '0',
771
                            `complexity` INT(5) NOT null DEFAULT '0',
772
                            `creator_id` int(11) NOT null DEFAULT '0',
773
                            PRIMARY KEY (`id`)
774
                            ) CHARSET=utf8;"
775
                        );
776
                    } elseif ($task === 'roles_values') {
777
                        $mysqli_result = mysqli_query(
778
                            $dbTmp,
779
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."roles_values` (
780
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT PRIMARY KEY,
781
                            `role_id` int(12) NOT NULL,
782
                            `folder_id` int(12) NOT NULL,
783
                            `type` varchar(5) NOT NULL DEFAULT 'R',
784
                            KEY `role_id_idx` (`role_id`)
785
                            ) CHARSET=utf8;"
786
                        );
787
                    } elseif ($task === 'kb') {
788
                        $mysqli_result = mysqli_query(
789
                            $dbTmp,
790
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."kb` (
791
                            `id` int(12) NOT null AUTO_INCREMENT,
792
                            `category_id` int(12) NOT NULL,
793
                            `label` varchar(200) NOT NULL,
794
                            `description` text NOT NULL,
795
                            `author_id` int(12) NOT NULL,
796
                            `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',
797
                            PRIMARY KEY (`id`)
798
                            ) CHARSET=utf8;"
799
                        );
800
                    } elseif ($task === 'kb_categories') {
801
                        $mysqli_result = mysqli_query(
802
                            $dbTmp,
803
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'kb_categories` (
804
                            `id` int(12) NOT null AUTO_INCREMENT,
805
                            `category` varchar(50) NOT NULL,
806
                            PRIMARY KEY (`id`)
807
                            ) CHARSET=utf8;'
808
                        );
809
                    } elseif ($task === 'kb_items') {
810
                        $mysqli_result = mysqli_query(
811
                            $dbTmp,
812
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'kb_items` (
813
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
814
                            `kb_id` int(12) NOT NULL,
815
                            `item_id` int(12) NOT NULL,
816
                            PRIMARY KEY (`increment_id`)
817
                           ) CHARSET=utf8;'
818
                        );
819
                    } elseif ($task == 'restriction_to_roles') {
820
                        $mysqli_result = mysqli_query(
821
                            $dbTmp,
822
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'restriction_to_roles` (
823
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
824
                            `role_id` int(12) NOT NULL,
825
                            `item_id` int(12) NOT NULL,
826
                            PRIMARY KEY (`increment_id`)
827
                            ) CHARSET=utf8;'
828
                        );
829
                    } elseif ($task === 'languages') {
830
                        $mysqli_result = mysqli_query(
831
                            $dbTmp,
832
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'languages` (
833
                            `id` INT(10) NOT null AUTO_INCREMENT,
834
                            `name` VARCHAR(50) NOT null ,
835
                            `label` VARCHAR(50) NOT null ,
836
                            `code` VARCHAR(10) NOT null ,
837
                            `flag` VARCHAR(30) NOT NULL,
838
                            PRIMARY KEY (`id`)
839
                            ) CHARSET=utf8;'
840
                        );
841
842
                        // add lanaguages
843
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, 'SELECT * FROM `'.$var['tbl_prefix']."languages` WHERE name = 'french'"));
844
                        if ($tmp[0] == 0) {
845
                            $mysql_result = mysqli_query(
846
                                $dbTmp,
847
                                'INSERT INTO `'.$var['tbl_prefix']."languages` (`name`, `label`, `code`, `flag`) VALUES
848
                                ('french', 'French' , 'fr', 'fr.png'),
849
                                ('english', 'English' , 'us', 'us.png'),
850
                                ('spanish', 'Spanish' , 'es', 'es.png'),
851
                                ('german', 'German' , 'de', 'de.png'),
852
                                ('czech', 'Czech' , 'cz', 'cz.png'),
853
                                ('italian', 'Italian' , 'it', 'it.png'),
854
                                ('russian', 'Russian' , 'ru', 'ru.png'),
855
                                ('turkish', 'Turkish' , 'tr', 'tr.png'),
856
                                ('norwegian', 'Norwegian' , 'no', 'no.png'),
857
                                ('japanese', 'Japanese' , 'ja', 'ja.png'),
858
                                ('portuguese', 'Portuguese' , 'pr', 'pr.png'),
859
                                ('portuguese_br', 'Portuguese (Brazil)' , 'pr-bt', 'pr-bt.png'),
860
                                ('chinese', 'Chinese' , 'cn', 'cn.png'),
861
                                ('swedish', 'Swedish' , 'se', 'se.png'),
862
                                ('dutch', 'Dutch' , 'nl', 'nl.png'),
863
                                ('catalan', 'Catalan' , 'ct', 'ct.png'),
864
                                ('bulgarian', 'Bulgarian' , 'bg', 'bg.png'),
865
                                ('greek', 'Greek' , 'gr', 'gr.png'),
866
                                ('hungarian', 'Hungarian' , 'hu', 'hu.png'),
867
                                ('polish', 'Polish' , 'pl', 'pl.png'),
868
                                ('romanian', 'Romanian' , 'ro', 'ro.png'),
869
                                ('ukrainian', 'Ukrainian' , 'ua', 'ua.png'),
870
                                ('vietnamese', 'Vietnamese' , 'vi', 'vi.png'),
871
                                ('estonian', 'Estonian' , 'ee', 'ee.png');"
872
                            );
873
                        }
874
                    } elseif ($task === 'emails') {
875
                        $mysqli_result = mysqli_query(
876
                            $dbTmp,
877
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'emails` (
878
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
879
                            `timestamp` INT(30) NOT null ,
880
                            `subject` VARCHAR(255) NOT null ,
881
                            `body` TEXT NOT null ,
882
                            `receivers` VARCHAR(255) NOT null ,
883
                            `status` VARCHAR(30) NOT NULL,
884
                            PRIMARY KEY (`increment_id`)
885
                            ) CHARSET=utf8;'
886
                        );
887
                    } elseif ($task === 'automatic_del') {
888
                        $mysqli_result = mysqli_query(
889
                            $dbTmp,
890
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'automatic_del` (
891
                            `item_id` int(11) NOT NULL,
892
                            `del_enabled` tinyint(1) NOT NULL,
893
                            `del_type` tinyint(1) NOT NULL,
894
                            `del_value` varchar(35) NOT NULL,
895
                            PRIMARY KEY (`item_id`)
896
                            ) CHARSET=utf8;'
897
                        );
898
                    } elseif ($task === 'items_edition') {
899
                        $mysqli_result = mysqli_query(
900
                            $dbTmp,
901
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'items_edition` (
902
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
903
                            `item_id` int(11) NOT NULL,
904
                            `user_id` int(12) NOT NULL,
905
                            `timestamp` varchar(50) NOT NULL,
906
                            KEY `item_id_idx` (`item_id`),
907
                            PRIMARY KEY (`increment_id`)
908
                            ) CHARSET=utf8;'
909
                        );
910
                    } elseif ($task === 'categories') {
911
                        $mysqli_result = mysqli_query(
912
                            $dbTmp,
913
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."categories` (
914
                            `id` int(12) NOT NULL AUTO_INCREMENT,
915
                            `parent_id` int(12) NOT NULL,
916
                            `title` varchar(255) NOT NULL,
917
                            `level` int(2) NOT NULL,
918
                            `description` text NULL,
919
                            `type` varchar(50) NULL default '',
920
                            `masked` tinyint(1) NOT NULL default '0',
921
                            `order` int(12) NOT NULL default '0',
922
                            `encrypted_data` tinyint(1) NOT NULL default '1',
923
                            `role_visibility` varchar(255) NOT NULL DEFAULT 'all',
924
                            `is_mandatory` tinyint(1) NOT NULL DEFAULT '0',
925
                            PRIMARY KEY (`id`)
926
                            ) CHARSET=utf8;"
927
                        );
928
                    } elseif ($task === 'categories_items') {
929
                        $mysqli_result = mysqli_query(
930
                            $dbTmp,
931
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."categories_items` (
932
                            `id` int(12) NOT NULL AUTO_INCREMENT,
933
                            `field_id` int(11) NOT NULL,
934
                            `item_id` int(11) NOT NULL,
935
                            `data` text NOT NULL,
936
                            `data_iv` text NOT NULL,
937
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
938
                            `is_mandatory` BOOLEAN NOT NULL DEFAULT FALSE ,
939
                            PRIMARY KEY (`id`)
940
                            ) CHARSET=utf8;"
941
                        );
942
                    } elseif ($task === 'categories_folders') {
943
                        $mysqli_result = mysqli_query(
944
                            $dbTmp,
945
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'categories_folders` (
946
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
947
                            `id_category` int(12) NOT NULL,
948
                            `id_folder` int(12) NOT NULL,
949
                            PRIMARY KEY (`increment_id`)
950
                            ) CHARSET=utf8;'
951
                        );
952
                    } elseif ($task === 'api') {
953
                        $mysqli_result = mysqli_query(
954
                            $dbTmp,
955
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'api` (
956
                            `id` int(20) NOT NULL AUTO_INCREMENT,
957
                            `type` varchar(15) NOT NULL,
958
                            `label` varchar(255) NOT NULL,
959
                            `value` varchar(255) NOT NULL,
960
                            `timestamp` varchar(50) NOT NULL,
961
                            PRIMARY KEY (`id`)
962
                            ) CHARSET=utf8;'
963
                        );
964
                    } elseif ($task === 'otv') {
965
                        $mysqli_result = mysqli_query(
966
                            $dbTmp,
967
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'otv` (
968
                            `id` int(10) NOT NULL AUTO_INCREMENT,
969
                            `timestamp` text NOT NULL,
970
                            `code` varchar(100) NOT NULL,
971
                            `item_id` int(12) NOT NULL,
972
                            `originator` int(12) NOT NULL,
973
                            PRIMARY KEY (`id`)
974
                            ) CHARSET=utf8;'
975
                        );
976
                    } elseif ($task === 'suggestion') {
977
                        $mysqli_result = mysqli_query(
978
                            $dbTmp,
979
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."suggestion` (
980
                            `id` tinyint(12) NOT NULL AUTO_INCREMENT,
981
                            `label` varchar(255) NOT NULL,
982
                            `pw` text NOT NULL,
983
                            `pw_iv` text NOT NULL,
984
                            `pw_len` int(5) NOT NULL,
985
                            `description` text NOT NULL,
986
                            `author_id` int(12) NOT NULL,
987
                            `folder_id` int(12) NOT NULL,
988
                            `comment` text NOT NULL,
989
                            `suggestion_type` varchar(10) NOT NULL default 'new',
990
                            PRIMARY KEY (`id`)
991
                            ) CHARSET=utf8;"
992
                        );
993
994
                        $mysqli_result = mysqli_query(
995
                            $dbTmp,
996
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."export` (
997
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
998
                            `id` int(12) NOT NULL,
999
                            `label` varchar(500) NOT NULL,
1000
                            `login` varchar(100) NOT NULL,
1001
                            `description` text NOT NULL,
1002
                            `pw` text NOT NULL,
1003
                            `path` varchar(500) NOT NULL,
1004
                            `email` varchar(500) NOT NULL default 'none',
1005
                            `url` varchar(500) NOT NULL default 'none',
1006
                            `kbs` varchar(500) NOT NULL default 'none',
1007
                            `tags` varchar(500) NOT NULL default 'none',
1008
                            PRIMARY KEY (`increment_id`)
1009
                            ) CHARSET=utf8;"
1010
                        );
1011
                    } elseif ($task === 'tokens') {
1012
                        $mysqli_result = mysqli_query(
1013
                            $dbTmp,
1014
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'tokens` (
1015
                            `id` int(12) NOT NULL AUTO_INCREMENT,
1016
                            `user_id` int(12) NOT NULL,
1017
                            `token` varchar(255) NOT NULL,
1018
                            `reason` varchar(255) NOT NULL,
1019
                            `creation_timestamp` varchar(50) NOT NULL,
1020
                            `end_timestamp` varchar(50) NOT NULL,
1021
                            PRIMARY KEY (`id`)
1022
                            ) CHARSET=utf8;'
1023
                        );
1024
                    } elseif ($task === 'items_change') {
1025
                        $mysqli_result = mysqli_query(
1026
                            $dbTmp,
1027
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix']."items_change` (
1028
                            `id` int(12) NOT NULL AUTO_INCREMENT,
1029
                            `item_id` int(12) NOT NULL,
1030
                            `label` varchar(255) NOT NULL DEFAULT 'none',
1031
                            `pw` text NOT NULL,
1032
                            `login` varchar(255) NOT NULL DEFAULT 'none',
1033
                            `email` varchar(255) NOT NULL DEFAULT 'none',
1034
                            `url` varchar(255) NOT NULL DEFAULT 'none',
1035
                            `description` text NOT NULL,
1036
                            `comment` text NOT NULL,
1037
                            `folder_id` tinyint(12) NOT NULL,
1038
                            `user_id` int(12) NOT NULL,
1039
                            `timestamp` varchar(50) NOT NULL DEFAULT 'none',
1040
                            PRIMARY KEY (`id`)
1041
                            ) CHARSET=utf8;"
1042
                        );
1043
                    } elseif ($task === 'templates') {
1044
                        $mysqli_result = mysqli_query(
1045
                            $dbTmp,
1046
                            'CREATE TABLE IF NOT EXISTS `'.$var['tbl_prefix'].'templates` (
1047
                            `increment_id` int(12) NOT NULL AUTO_INCREMENT,
1048
                            `item_id` int(12) NOT NULL,
1049
                            `category_id` int(12) NOT NULL,
1050
                            PRIMARY KEY (`increment_id`)
1051
                            ) CHARSET=utf8;'
1052
                        );
1053
                    }
1054
                }
1055
                // answer back
1056
                if ($mysqli_result) {
1057
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'", "task" : "'.$task.'", "activity" : "'.$activity.'"}]';
1058
                } else {
1059
                    echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_error())).'", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'", "table" : "'.$task.'"}]';
0 ignored issues
show
Bug introduced by
The call to mysqli_error() has too few arguments starting with link. ( Ignorable by Annotation )

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

1059
                    echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), /** @scrutinizer ignore-call */ mysqli_error())).'", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'", "table" : "'.$task.'"}]';

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1060
                }
1061
            } else {
1062
                echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]';
1063
            }
1064
1065
            mysqli_close($dbTmp);
1066
            // Destroy session without writing to disk
1067
            define('NODESTROY_SESSION', 'true');
1068
            session_destroy();
1069
            break;
1070
1071
        case 'step_6':
1072
            //decrypt
1073
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
1074
            $activity = Encryption\Crypt\aesctr::decrypt($post_activity, 'cpm', 128);
1075
            $data_sent = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128);
1076
            $data_sent = json_decode($data_sent, true);
1077
            $task = Encryption\Crypt\aesctr::decrypt($post_task, 'cpm', 128);
1078
            $json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128);
1079
            $db = json_decode($json, true);
1080
1081
            $dbTmp = mysqli_connect(
1082
                $db['db_host'],
1083
                $db['db_login'],
1084
                $db['db_pw'],
1085
                $db['db_bdd'],
1086
                $db['db_port']
1087
            );
1088
1089
            // read install variables
1090
            $result = mysqli_query($dbTmp, 'SELECT * FROM `_install`');
1091
            while ($row = $result->fetch_array()) {
1092
                $var[$row[0]] = $row[1];
1093
            }
1094
1095
            // launch
1096
            if (empty($var['sk_path'])) {
1097
                $skFile = $var['abspath'].'/includes/sk.php';
1098
                $securePath = $var['abspath'];
1099
            } else {
1100
                //ensure $var['sk_path'] has no trailing slash
1101
                $var['sk_path'] = rtrim($var['sk_path'], '/\\');
1102
                $skFile = $var['sk_path'].'/sk.php';
1103
                $securePath = $var['sk_path'];
1104
            }
1105
1106
            $events = '';
1107
1108
            if ($activity === 'file') {
1109
                if ($task === 'settings.php') {
1110
                    // first is to create teampass-seckey.txt
1111
                    // 0- check if exists
1112
                    $filename_seckey = $securePath.'/teampass-seckey.txt';
1113
1114
                    if (file_exists($filename_seckey)) {
1115
                        if (!copy($filename_seckey, $filename_seckey.'.'.date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) {
1116
                            echo '[{"error" : "File `$filename_seckey` already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1117
                            break;
1118
                        } else {
1119
                            unlink($filename);
1120
                        }
1121
                    }
1122
1123
                    // 1- generate saltkey
1124
                    require_once '../includes/libraries/Encryption/Encryption/Crypto.php';
1125
                    require_once '../includes/libraries/Encryption/Encryption/Encoding.php';
1126
                    require_once '../includes/libraries/Encryption/Encryption/DerivedKeys.php';
1127
                    require_once '../includes/libraries/Encryption/Encryption/Key.php';
1128
                    require_once '../includes/libraries/Encryption/Encryption/KeyOrPassword.php';
1129
                    require_once '../includes/libraries/Encryption/Encryption/File.php';
1130
                    require_once '../includes/libraries/Encryption/Encryption/RuntimeTests.php';
1131
                    require_once '../includes/libraries/Encryption/Encryption/KeyProtectedByPassword.php';
1132
                    require_once '../includes/libraries/Encryption/Encryption/Core.php';
1133
1134
                    $key = \Defuse\Crypto\Key::createNewRandomKey();
1135
                    $new_salt = $key->saveToAsciiSafeString();
1136
1137
                    // 2- store key in file
1138
                    file_put_contents(
1139
                        $filename_seckey,
1140
                        $new_salt
1141
                    );
1142
1143
                    // Now create settings file
1144
                    $filename = '../includes/config/settings.php';
1145
1146
                    if (file_exists($filename)) {
1147
                        if (!copy($filename, $filename.'.'.date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) {
1148
                            echo '[{"error" : "Setting.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1149
                            break;
1150
                        } else {
1151
                            unlink($filename);
1152
                        }
1153
                    }
1154
1155
                    // Encrypt the DB password
1156
                    $encrypted_text = encryptFollowingDefuse(
1157
                        $db['db_pw'],
1158
                        $new_salt
1159
                    )['string'];
1160
1161
                    // Open and write Settings file
1162
                    $file_handler = fopen($filename, 'w');
1163
                    $result = fwrite(
1164
                        $file_handler,
1165
                        utf8_encode(
1166
                            '<?php
1167
global $lang, $txt, $pathTeampas, $urlTeampass, $pwComplexity, $mngPages;
1168
global $server, $user, $pass, $database, $pre, $db, $port, $encoding;
1169
1170
### DATABASE connexion parameters ###
1171
$server = "'.$db['db_host'].'";
1172
$user = "'.$db['db_login'].'";
1173
$pass = "'.str_replace('$', '\$', $encrypted_text).'";
1174
$database = "'.$db['db_bdd'].'";
1175
$pre = "'.$var['tbl_prefix'].'";
1176
$port = '.$db['db_port'].';
1177
$encoding = "'.$session_db_encoding."\";
1178
1179
@date_default_timezone_set(\$_SESSION['settings']['timezone']);
1180
@define('SECUREPATH', '".$securePath."');
1181
if (file_exists(\"".str_replace('\\', '/', $skFile).'")) {
1182
    require_once "'.str_replace('\\', '/', $skFile).'";
1183
}
1184
'
1185
                        )
1186
                    );
1187
                    fclose($file_handler);
1188
                    if ($result === false) {
1189
                        echo '[{"error" : "Setting.php file could not be created. Please check the path and the rights", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1190
                    } else {
1191
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1192
                    }
1193
                } elseif ($task === 'sk.php') {
1194
                    //Create sk.php file
1195
                    if (file_exists($skFile)) {
1196
                        if (!copy($skFile, $skFile.'.'.date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) {
1197
                            echo '[{"error" : "sk.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1198
                            break;
1199
                        } else {
1200
                            unlink($skFile);
1201
                        }
1202
                    }
1203
                    $file_handler = fopen($skFile, 'w');
1204
1205
                    $result = fwrite(
1206
                        $file_handler,
1207
                        utf8_encode(
1208
                            "<?php
1209
@define('COST', '13'); // Don't change this.
1210
@define('AKEY', '');
1211
@define('IKEY', '');
1212
@define('SKEY', '');
1213
@define('HOST', '');
1214
?>"
1215
                        )
1216
                    );
1217
                    fclose($file_handler);
1218
1219
                    // finalize
1220
                    if ($result === false) {
1221
                        echo '[{"error" : "sk.php file could not be created. Please check the path and the rights.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1222
                    } else {
1223
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1224
                    }
1225
                } elseif ($task === 'security') {
1226
                    // Sort out the file permissions
1227
1228
                    // is server Windows or Linux?
1229
                    if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
1230
                        // Change directory permissions
1231
                        $result = chmodRecursive($session_abspath, 0770, 0740);
1232
                        if ($result) {
1233
                            $result = chmodRecursive($session_abspath.'/files', 0770, 0770);
1234
                        }
1235
                        if ($result) {
1236
                            $result = chmodRecursive($session_abspath.'/upload', 0770, 0770);
1237
                        }
1238
                    }
1239
1240
                    if ($result === false) {
1241
                        echo '[{"error" : "Cannot change directory permissions - please fix manually", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1242
                    } else {
1243
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1244
                    }
1245
                } elseif ($task === 'csrfp-token') {
1246
                    // update CSRFP TOKEN
1247
                    $csrfp_file_sample = '../includes/libraries/csrfp/libs/csrfp.config.sample.php';
1248
                    $csrfp_file = '../includes/libraries/csrfp/libs/csrfp.config.php';
1249
                    if (file_exists($csrfp_file)) {
1250
                        if (!copy($csrfp_file, $csrfp_file.'.'.date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) {
1251
                            echo '[{"error" : "csrfp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1252
                            break;
1253
                        } else {
1254
                            $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
1255
                        }
1256
                    }
1257
                    unlink($csrfp_file); // delete existing csrfp.config file
1258
                    copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
1259
                    $data = file_get_contents($csrfp_file);
1260
                    $newdata = str_replace('"CSRFP_TOKEN" => ""', '"CSRFP_TOKEN" => "'.bin2hex(openssl_random_pseudo_bytes(25)).'"', $data);
1261
                    $jsUrl = $data_sent['url_path'].'/includes/libraries/csrfp/js/csrfprotector.js';
1262
                    $newdata = str_replace('"jsUrl" => ""', '"jsUrl" => "'.$jsUrl.'"', $newdata);
1263
                    file_put_contents('../includes/libraries/csrfp/libs/csrfp.config.php', $newdata);
1264
1265
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1266
                }
1267
            } elseif ($activity === 'install') {
1268
                if ($task === 'cleanup') {
1269
                    // Mark a tag to force Install stuff (folders, files and table) to be cleanup while first login
1270
                    mysqli_query($dbTmp, 'INSERT INTO `'.$var['tbl_prefix']."misc` (`type`, `intitule`, `valeur`) VALUES ('install', 'clear_install_folder', 'true')");
1271
1272
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1273
                }
1274
            }
1275
1276
            mysqli_close($dbTmp);
1277
            // Destroy session without writing to disk
1278
            define('NODESTROY_SESSION', 'true');
1279
            session_destroy();
1280
            break;
1281
    }
1282
}
1283