Completed
Push — development ( cdf132...19f93d )
by Nils
09:09
created

install.queries.php ➔ chmod_r()   D

Complexity

Conditions 9
Paths 13

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 19
nc 13
nop 3
dl 0
loc 30
rs 4.909
c 0
b 0
f 0
1
<?php
2
/**
3
 * @file          install.queries.php
4
 * @author        Nils Laumaillé
5
 * @version       2.1.27
6
 * @copyright     (c) 2009-2017 Nils Laumaillé
7
 * @licensing     GNU AFFERO GPL 3.0
8
 * @link          http://www.teampass.net
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
require_once('../sources/SecureHandler.php');
15
session_start();
16
error_reporting(E_ERROR | E_PARSE);
17
header("Content-type: text/html; charset=utf-8");
18
$session_db_encoding = "utf8";
19
20
function chmodRecursive($dir, $dirPermissions, $filePermissions)
21
{
22
    $pointer_dir = opendir($dir);
23
    $res = true;
24
    while ($file = readdir($pointer_dir)) {
25
        if (($file == ".") || ($file == "..")) {
26
            continue;
27
        }
28
29
        $fullPath = $dir."/".$file;
30
31
        if (is_dir($fullPath)) {
32
            if ($res = @chmod($fullPath, $dirPermissions)) {
33
                $res = @chmodRecursive($fullPath, $dirPermissions, $filePermissions);
34
            }
35
        } else {
36
            $res = chmod($fullPath, $filePermissions);
37
        }
38
        if (!$res) {
39
            closedir($pointer_dir);
40
            return false;
41
        }
42
    }
43
    closedir($pointer_dir);
44
    if (is_dir($dir) && $res) {
45
            $res = @chmod($dir, $dirPermissions);
46
    }
47
48
    return $res;
49
}
50
51
/**
52
 * genHash()
53
 *
54
 * Generate a hash for user login
55
 * @param string $password
56
 */
57 View Code Duplication
function bCrypt($password, $cost)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
{
59
    $salt = sprintf('$2y$%02d$', $cost);
60
    if (function_exists('openssl_random_pseudo_bytes')) {
61
        $salt .= bin2hex(openssl_random_pseudo_bytes(11));
62
    } else {
63
        $chars = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
64
        for ($i = 0; $i < 22; $i++) {
65
            $salt .= $chars[mt_rand(0, 63)];
66
        }
67
    }
68
    return crypt($password, $salt);
69
}
70
71
72
// Prepare POST variables
73
$post_type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING);
74
$post_data = filter_input(INPUT_POST, 'data', FILTER_SANITIZE_STRING);
75
$post_activity = filter_input(INPUT_POST, 'activity', FILTER_SANITIZE_STRING);
76
$post_task = filter_input(INPUT_POST, 'task', FILTER_SANITIZE_STRING);
77
$post_index = filter_input(INPUT_POST, 'index', FILTER_SANITIZE_NUMBER_INT);
78
$post_multiple = filter_input(INPUT_POST, 'multiple', FILTER_SANITIZE_STRING);
79
$post_db = filter_input(INPUT_POST, 'db', FILTER_SANITIZE_STRING);
80
81
// Load libraries
82
require_once '../includes/libraries/protect/SuperGlobal/SuperGlobal.php';
83
$superGlobal = new protect\SuperGlobal\SuperGlobal();
84
85
// Prepare SESSION variables
86
$session_url_path = $superGlobal->get("url_path", "SESSION");
87
$session_abspath = $superGlobal->get("abspath", "SESSION");
88
$session_db_encoding = $superGlobal->get("db_encoding", "SESSION");
89
90
$superGlobal->put("CPM", 1, "SESSION");
91
92
if (null !== $post_type) {
93
    switch ($post_type) {
94
        case "step_2":
95
            //decrypt
96
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
97
            $json = Encryption\Crypt\aesctr::decrypt($post_data, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
98
            $data = json_decode($json, true);
99
            $json = Encryption\Crypt\aesctr::decrypt($post_activity, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
            $data = array_merge($data, array("activity" => $json));
101
            $json = Encryption\Crypt\aesctr::decrypt($post_task, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
            $data = array_merge($data, array("task" => $json));
103
104
            $abspath = str_replace('\\', '/', $data['root_path']);
105 View Code Duplication
            if (substr($abspath, strlen($abspath) - 1) == "/") {
106
                $abspath = substr($abspath, 0, strlen($abspath) - 1);
107
            }
108
            $session_abspath = $abspath;
109
            $session_url_path = $data['url_path'];
110
111
            if (isset($data['activity']) && $data['activity'] === "folder") {
112
                if (is_writable($abspath."/".$data['task']."/") === true) {
113
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
114
                } else {
115
                    echo '[{"error" : " Path '.$data['task'].' is not writable!", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
116
                }
117
                break;
118
            }
119
120 View Code Duplication
            if (isset($data['activity']) && $data['activity'] === "extension") {
121
                if (extension_loaded($data['task'])) {
122
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
123
                } else {
124
                    echo '[{"error" : " Extension '.$data['task'].' is not loaded!", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
125
                }
126
                break;
127
            }
128
129 View Code Duplication
            if (isset($data['activity']) && $data['activity'] === "function") {
130
                if (function_exists($data['task'])) {
131
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
132
                } else {
133
                    echo '[{"error" : " Function '.$data['task'].' is not available!", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
134
                }
135
                break;
136
            }
137
138
            if (isset($data['activity']) && $data['activity'] === "version") {
139 View Code Duplication
                if (version_compare(phpversion(), '5.5.0', '>=')) {
140
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
141
                } else {
142
                    echo '[{"error" : "PHP version '.phpversion().' is not OK (minimum is 5.5.0)", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
143
                }
144
                break;
145
            }
146
147
            if (isset($data['activity']) && $data['activity'] === "ini") {
148 View Code Duplication
                if (ini_get($data['task']) >= 60) {
149
                    echo '[{"error" : "", "index" : "'.$post_index.'"}]';
150
                } else {
151
                    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.'"}]';
152
                }
153
                break;
154
            }
155
            break;
156
157
        case "step_3":
158
            //decrypt
159
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
160
            $json = Encryption\Crypt\aesctr::decrypt($post_data, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
161
            $data = json_decode($json, true);
162
            $json = Encryption\Crypt\aesctr::decrypt($post_db, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
163
            $db = json_decode($json, true);
164
165
            // launch
166
            if ($dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port'])) {
167
                // create temporary INSTALL mysqli table
168
                $mysqli_result = mysqli_query(
169
                    $dbTmp,
170
                    "CREATE TABLE IF NOT EXISTS `_install` (
171
                    `key` varchar(100) NOT NULL,
172
                    `value` varchar(500) NOT NULL
173
                    ) CHARSET=utf8;"
174
                );
175
                // store values
176 View Code Duplication
                foreach ($data as $key => $value) {
177
                    $superGlobal->put($key, $value, "SESSION");
178
                    $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = '".$key."'"));
179
                    if ($tmp[0] == 0 || empty($tmp[0])) {
180
                        mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('".$key."', '".$value."');");
181
                    } else {
182
                        mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".$value."' WHERE `key` = '".$key."';");
183
                    }
184
                }
185
                $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = 'url_path'"));
186 View Code Duplication
                if ($tmp[0] == 0 || empty($tmp[0])) {
187
                    mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('url_path', '", empty($session_url_path) ? $db['url_path'] : $session_url_path, "');");
188
                } else {
189
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($session_url_path) ? $db['url_path'] : $session_url_path, "' WHERE `key` = 'url_path';");
190
                }
191
                $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = 'abspath'"));
192 View Code Duplication
                if ($tmp[0] == 0 || empty($tmp[0])) {
193
                    mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('abspath', '", empty($session_abspath) ? $db['abspath'] : $session_abspath, "');");
194
                } else {
195
                    mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '", empty($session_abspath) ? $db['abspath'] : $session_abspath, "' WHERE `key` = 'abspath';");
196
                }
197
198
                echo '[{"error" : "", "result" : "Connection is successful", "multiple" : ""}]';
199 View Code Duplication
            } else {
200
                echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]';
201
            }
202
            mysqli_close($dbTmp);
203
            break;
204
205
        case "step_4":
206
            //decrypt
207
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
208
            $json = Encryption\Crypt\aesctr::decrypt($post_data, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
209
            $data = json_decode($json, true);
210
            $json = Encryption\Crypt\aesctr::decrypt($post_db, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
211
            $db = json_decode($json, true);
212
213
            $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
214
215
            // prepare data
216
            foreach ($data as $key => $value) {
217
                $data[$key] = str_replace(array('&quot;', '&#92;'), array('""', '\\\\'), $value);
218
            }
219
220
            // check skpath
221
            if (empty($data['sk_path'])) {
222
                $data['sk_path'] = $session_abspath."/includes";
223
            } else {
224
                $data['sk_path'] = str_replace("&#92;", "/", $data['sk_path']);
225
            }
226
            if (substr($data['sk_path'], strlen($data['sk_path']) - 1) == "/" || substr($data['sk_path'], strlen($data['sk_path']) - 1) == "\"") {
227
                $data['sk_path'] = substr($data['sk_path'], 0, strlen($data['sk_path']) - 1);
228
            }
229
            if (is_dir($data['sk_path'])) {
230
                if (is_writable($data['sk_path'])) {
231
                    // store all variables in SESSION
232 View Code Duplication
                    foreach ($data as $key => $value) {
233
                        $superGlobal->put($key, $value, "SESSION");
234
                        $tmp = mysqli_fetch_row(mysqli_query($dbTmp, "SELECT COUNT(*) FROM `_install` WHERE `key` = '".$key."'"));
235
                        if ($tmp[0] == 0 || empty($tmp[0])) {
236
                            mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('".$key."', '".$value."');");
237
                        } else {
238
                            mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '".$value."' WHERE `key` = '".$key."';");
239
                        }
240
                    }
241
                    echo '[{"error" : "", "result" : "Information stored", "multiple" : ""}]';
242
                } else {
243
                    echo '[{"error" : "The Directory must be writable!", "result" : "Information stored", "multiple" : ""}]';
244
                }
245
            } else {
246
                echo '[{"error" : "'.$data['sk_path'].' is not a Directory!", "result" : "Information stored", "multiple" : ""}]';
247
            }
248
            mysqli_close($dbTmp);
249
            break;
250
251
        case "step_5":
252
            //decrypt
253
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
254
            $activity = Encryption\Crypt\aesctr::decrypt($post_activity, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
255
            $task = Encryption\Crypt\aesctr::decrypt($post_task, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
256
            $json = Encryption\Crypt\aesctr::decrypt($post_db, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
257
            $db = json_decode($json, true);
258
259
            // launch
260
            $dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
261
            $dbBdd = $db['db_bdd'];
262
            if ($dbTmp) {
263
                $mysqli_result = "";
264
265
                // read install variables
266
                $result = mysqli_query($dbTmp, "SELECT * FROM `_install`");
267
                while ($row = $result->fetch_array()) {
268
                    $var[$row[0]] = $row[1];
269
                }
270
271
                if ($activity === "table") {
272
                    //FORCE UTF8 DATABASE
273
                    mysqli_query($dbTmp, "ALTER DATABASE `".$dbBdd."` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
274
                    if ($task === "items") {
275
                        $mysqli_result = mysqli_query(
276
                            $dbTmp,
277
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."items` (
278
                            `id` int(12) NOT null AUTO_INCREMENT,
279
                            `label` varchar(500) NOT NULL,
280
                            `description` text DEFAULT NULL,
281
                            `pw` text DEFAULT NULL,
282
                            `pw_iv` text DEFAULT NULL,
283
                            `pw_len` int(5) NOT NULL DEFAULT '0',
284
                            `url` varchar(500) DEFAULT NULL,
285
                            `id_tree` varchar(10) DEFAULT NULL,
286
                            `perso` tinyint(1) NOT null DEFAULT '0',
287
                            `login` varchar(200) DEFAULT NULL,
288
                            `inactif` tinyint(1) NOT null DEFAULT '0',
289
                            `restricted_to` varchar(200) DEFAULT NULL,
290
                            `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',
291
                            `email` varchar(100) DEFAULT NULL,
292
                            `notification` varchar(250) DEFAULT NULL,
293
                            `viewed_no` int(12) NOT null DEFAULT '0',
294
                            `complexity_level` varchar(3) NOT null DEFAULT '-1',
295
                            `auto_update_pwd_frequency` tinyint(2) NOT null DEFAULT '0',
296
                            `auto_update_pwd_next_date` varchar(100) NOT null DEFAULT '0',
297
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
298
                            PRIMARY KEY (`id`),
299
                            KEY    `restricted_inactif_idx` (`restricted_to`,`inactif`)
300
                            ) CHARSET=utf8;"
301
                        );
302
                    } elseif ($task === "log_items") {
303
                        $mysqli_result = mysqli_query(
304
                            $dbTmp,
305
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."log_items` (
306
                            `id_item` int(8) NOT NULL,
307
                            `date` varchar(50) NOT NULL,
308
                            `id_user` int(8) NOT NULL,
309
                            `action` varchar(250) NULL,
310
                            `raison` text NULL,
311
                            `raison_iv` text NULL,
312
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set'
313
                            ) CHARSET=utf8;"
314
                        );
315
                        // create index
316
                        mysqli_query(
317
                            $dbTmp,
318
                            "CREATE INDEX teampass_log_items_id_item_IDX ON ".$var['tbl_prefix']."log_items (id_item,date);"
319
                        );
320
                    } elseif ($task === "misc") {
321
                        $mysqli_result = mysqli_query(
322
                            $dbTmp,
323
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."misc` (
324
                            `id` int(12) NOT null AUTO_INCREMENT,
325
                            `type` varchar(50) NOT NULL,
326
                            `intitule` varchar(100) NOT NULL,
327
                            `valeur` varchar(500) NOT NULL,
328
                            PRIMARY KEY (`id`)
329
                            ) CHARSET=utf8;"
330
                        );
331
332
                        // include constants
333
                        require_once "../includes/config/include.php";
334
335
                        // prepare config file
336
                        $tp_config_file = "../includes/config/tp.config.php";
337 View Code Duplication
                        if (file_exists($tp_config_file)) {
338
                            if (!copy($tp_config_file, $tp_config_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
339
                                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.'"}]';
340
                                break;
341
                            } else {
342
                                unlink($tp_config_file);
343
                            }
344
                        }
345
                        $fh = fopen($tp_config_file, 'w');
346
                        $config_text = "<?php
347
global \$SETTINGS;
348
\$SETTINGS = array (";
349
350
                        // add by default settings
351
                        $aMiscVal = array(
352
                            array('admin', 'max_latest_items', '10'),
353
                            array('admin', 'enable_favourites', '1'),
354
                            array('admin', 'show_last_items', '1'),
355
                            array('admin', 'enable_pf_feature', '0'),
356
                            array('admin', 'log_connections', '0'),
357
                            array('admin', 'log_accessed', '1'),
358
                            array('admin', 'time_format', 'H:i:s'),
359
                            array('admin', 'date_format', 'd/m/Y'),
360
                            array('admin', 'duplicate_folder', '0'),
361
                            array('admin', 'item_duplicate_in_same_folder', '0'),
362
                            array('admin', 'duplicate_item', '0'),
363
                            array('admin', 'number_of_used_pw', '3'),
364
                            array('admin', 'manager_edit', '1'),
365
                            array('admin', 'cpassman_dir', $var['abspath']),
366
                            array('admin', 'cpassman_url', $var['url_path']),
367
                            array('admin', 'favicon', $var['url_path'].'/favicon.ico'),
368
                            array('admin', 'path_to_upload_folder', $var['abspath'].'/upload'),
369
                            array('admin', 'url_to_upload_folder', $var['url_path'].'/upload'),
370
                            array('admin', 'path_to_files_folder', $var['abspath'].'/files'),
371
                            array('admin', 'url_to_files_folder', $var['url_path'].'/files'),
372
                            array('admin', 'activate_expiration', '0'),
373
                            array('admin', 'pw_life_duration', '0'),
374
                            array('admin', 'maintenance_mode', '1'),
375
                            array('admin', 'enable_sts', '0'),
376
                            array('admin', 'encryptClientServer', '1'),
377
                            array('admin', 'cpassman_version', $SETTINGS_EXT['version']),
378
                            array('admin', 'ldap_mode', '0'),
379
                            array('admin', 'ldap_type', '0'),
380
                            array('admin', 'ldap_suffix', '0'),
381
                            array('admin', 'ldap_domain_dn', '0'),
382
                            array('admin', 'ldap_domain_controler', '0'),
383
                            array('admin', 'ldap_user_attribute', '0'),
384
                            array('admin', 'ldap_ssl', '0'),
385
                            array('admin', 'ldap_tls', '0'),
386
                            array('admin', 'ldap_elusers', '0'),
387
                            array('admin', 'ldap_search_base', '0'),
388
                            array('admin', 'richtext', '0'),
389
                            array('admin', 'allow_print', '0'),
390
                            array('admin', 'roles_allowed_to_print', '0'),
391
                            array('admin', 'show_description', '1'),
392
                            array('admin', 'anyone_can_modify', '0'),
393
                            array('admin', 'anyone_can_modify_bydefault', '0'),
394
                            array('admin', 'nb_bad_authentication', '0'),
395
                            array('admin', 'utf8_enabled', '1'),
396
                            array('admin', 'restricted_to', '0'),
397
                            array('admin', 'restricted_to_roles', '0'),
398
                            array('admin', 'enable_send_email_on_user_login', '0'),
399
                            array('admin', 'enable_user_can_create_folders', '0'),
400
                            array('admin', 'insert_manual_entry_item_history', '0'),
401
                            array('admin', 'enable_kb', '0'),
402
                            array('admin', 'enable_email_notification_on_item_shown', '0'),
403
                            array('admin', 'enable_email_notification_on_user_pw_change', '0'),
404
                            array('admin', 'custom_logo', ''),
405
                            array('admin', 'custom_login_text', ''),
406
                            array('admin', 'default_language', 'english'),
407
                            array('admin', 'send_stats', '0'),
408
                            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;'),
409
                            array('admin', 'send_stats_time', time() - 2592000),
410
                            array('admin', 'get_tp_info', '1'),
411
                            array('admin', 'send_mail_on_user_login', '0'),
412
                            array('cron', 'sending_emails', '0'),
413
                            array('admin', 'nb_items_by_query', 'auto'),
414
                            array('admin', 'enable_delete_after_consultation', '0'),
415
                            array('admin', 'enable_personal_saltkey_cookie', '0'),
416
                            array('admin', 'personal_saltkey_cookie_duration', '31'),
417
                            array('admin', 'email_smtp_server', ''),
418
                            array('admin', 'email_smtp_auth', ''),
419
                            array('admin', 'email_auth_username', ''),
420
                            array('admin', 'email_auth_pwd', ''),
421
                            array('admin', 'email_port', ''),
422
                            array('admin', 'email_security', ''),
423
                            array('admin', 'email_server_url', ''),
424
                            array('admin', 'email_from', ''),
425
                            array('admin', 'email_from_name', ''),
426
                            array('admin', 'pwd_maximum_length', '40'),
427
                            array('admin', 'google_authentication', '0'),
428
                            array('admin', 'delay_item_edition', '0'),
429
                            array('admin', 'allow_import', '0'),
430
                            array('admin', 'proxy_ip', ''),
431
                            array('admin', 'proxy_port', ''),
432
                            array('admin', 'upload_maxfilesize', '10mb'),
433
                            array('admin', 'upload_docext', 'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx'),
434
                            array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png'),
435
                            array('admin', 'upload_pkgext', '7z,rar,tar,zip'),
436
                            array('admin', 'upload_otherext', 'sql,xml'),
437
                            array('admin', 'upload_imageresize_options', '1'),
438
                            array('admin', 'upload_imageresize_width', '800'),
439
                            array('admin', 'upload_imageresize_height', '600'),
440
                            array('admin', 'upload_imageresize_quality', '90'),
441
                            array('admin', 'use_md5_password_as_salt', '0'),
442
                            array('admin', 'ga_website_name', 'TeamPass for ChangeMe'),
443
                            array('admin', 'api', '0'),
444
                            array('admin', 'subfolder_rights_as_parent', '0'),
445
                            array('admin', 'show_only_accessible_folders', '0'),
446
                            array('admin', 'enable_suggestion', '0'),
447
                            array('admin', 'otv_expiration_period', '7'),
448
                            array('admin', 'default_session_expiration_time', '60'),
449
                            array('admin', 'duo', '0'),
450
                            array('admin', 'enable_server_password_change', '0'),
451
                            array('admin', 'ldap_object_class', '0'),
452
                            array('admin', 'bck_script_path', $var['abspath']."/backups"),
453
                            array('admin', 'bck_script_filename', 'bck_teampass'),
454
                            array('admin', 'syslog_enable', '0'),
455
                            array('admin', 'syslog_host', 'localhost'),
456
                            array('admin', 'syslog_port', '514'),
457
                            array('admin', 'manager_move_item', '0'),
458
                            array('admin', 'create_item_without_password', '0'),
459
                            array('admin', 'otv_is_enabled', '0'),
460
                            array('admin', 'agses_authentication_enabled', '0'),
461
                            array('admin', 'item_extra_fields', '0'),
462
                            array('admin', 'saltkey_ante_2127', 'none'),
463
                            array('admin', 'migration_to_2127', 'done'),
464
                            array('admin', 'files_with_defuse', 'done'),
465
                            array('admin', 'timezone', 'UTC')
466
                        );
467
                        foreach ($aMiscVal as $elem) {
468
                            //Check if exists before inserting
469
                            $tmp = mysqli_num_rows(
470
                                mysqli_query(
471
                                    $dbTmp,
472
                                    "SELECT * FROM `".$var['tbl_prefix']."misc`
473
                                    WHERE type='".$elem[0]."' AND intitule='".$elem[1]."'"
474
                                )
475
                            );
476
                            if ($tmp[0] == 0) {
477
                                $queryRes = mysqli_query(
478
                                    $dbTmp,
479
                                    "INSERT INTO `".$var['tbl_prefix']."misc`
480
                                    (`type`, `intitule`, `valeur`) VALUES
481
                                    ('".$elem[0]."', '".$elem[1]."', '".
482
                                    str_replace("'", "", $elem[2])."');"
483
                                ); // or die(mysqli_error($dbTmp))
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
484
                            }
485
486
                            // append new setting in config file
487
                            $config_text .= "
488
    '".$elem[1]."' => '".str_replace("'", "", $elem[2])."',";
489
                        }
490
491
                        // write to config file
492
                        $result = fwrite(
493
                            $fh,
494
                            utf8_encode(
495
                                substr_replace($config_text, "", -1)."
496
);"
497
                            )
498
                        );
499
                        fclose($fh);
500
                    } elseif ($task === "nested_tree") {
501
                        $mysqli_result = mysqli_query(
502
                            $dbTmp,
503
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."nested_tree` (
504
                            `id` bigint(20) unsigned NOT null AUTO_INCREMENT,
505
                            `parent_id` int(11) NOT NULL,
506
                            `title` varchar(255) NOT NULL,
507
                            `nleft` int(11) NOT NULL DEFAULT '0',
508
                            `nright` int(11) NOT NULL DEFAULT '0',
509
                            `nlevel` int(11) NOT NULL DEFAULT '0',
510
                            `bloquer_creation` tinyint(1) NOT null DEFAULT '0',
511
                            `bloquer_modification` tinyint(1) NOT null DEFAULT '0',
512
                            `personal_folder` tinyint(1) NOT null DEFAULT '0',
513
                            `renewal_period` TINYINT(4) NOT null DEFAULT '0',
514
                            PRIMARY KEY (`id`),
515
                            UNIQUE KEY `id` (`id`),
516
                            KEY `nested_tree_parent_id` (`parent_id`),
517
                            KEY `nested_tree_nleft` (`nleft`),
518
                            KEY `nested_tree_nright` (`nright`),
519
                            KEY `nested_tree_nlevel` (`nlevel`),
520
                            KEY `personal_folder_idx` (`personal_folder`)
521
                            ) CHARSET=utf8;"
522
                        );
523
                    } elseif ($task === "rights") {
524
                        $mysqli_result = mysqli_query(
525
                            $dbTmp,
526
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."rights` (
527
                            `id` int(12) NOT null AUTO_INCREMENT,
528
                            `tree_id` int(12) NOT NULL,
529
                            `fonction_id` int(12) NOT NULL,
530
                            `authorized` tinyint(1) NOT null DEFAULT '0',
531
                            PRIMARY KEY (`id`)
532
                            ) CHARSET=utf8;"
533
                        );
534
                    } elseif ($task === "users") {
535
                        $mysqli_result = mysqli_query(
536
                            $dbTmp,
537
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."users` (
538
                            `id` int(12) NOT null AUTO_INCREMENT,
539
                            `login` varchar(50) NOT NULL,
540
                            `pw` varchar(400) NOT NULL,
541
                            `groupes_visibles` varchar(250) NOT NULL,
542
                            `derniers` text NULL,
543
                            `key_tempo` varchar(100) NULL,
544
                            `last_pw_change` varchar(30) NULL,
545
                            `last_pw` text NULL,
546
                            `admin` tinyint(1) NOT null DEFAULT '0',
547
                            `fonction_id` varchar(255) NULL,
548
                            `groupes_interdits` varchar(255) NULL,
549
                            `last_connexion` varchar(30) NULL,
550
                            `gestionnaire` int(11) NOT null DEFAULT '0',
551
                            `email` varchar(300) NOT NULL,
552
                            `favourites` varchar(300) NULL,
553
                            `latest_items` varchar(300) NULL,
554
                            `personal_folder` int(1) NOT null DEFAULT '0',
555
                            `disabled` tinyint(1) NOT null DEFAULT '0',
556
                            `no_bad_attempts` tinyint(1) NOT null DEFAULT '0',
557
                            `can_create_root_folder` tinyint(1) NOT null DEFAULT '0',
558
                            `read_only` tinyint(1) NOT null DEFAULT '0',
559
                            `timestamp` varchar(30) NOT null DEFAULT '0',
560
                            `user_language` varchar(50) NOT null DEFAULT '0',
561
                            `name` varchar(100) NULL,
562
                            `lastname` varchar(100) NULL,
563
                            `session_end` varchar(30) NULL,
564
                            `isAdministratedByRole` tinyint(5) NOT null DEFAULT '0',
565
                            `psk` varchar(400) NULL,
566
                            `ga` varchar(50) NULL,
567
                            `ga_temporary_code` VARCHAR(20) NOT NULL DEFAULT 'none',
568
                            `avatar` varchar(255) NULL,
569
                            `avatar_thumb` varchar(255) NULL,
570
                            `upgrade_needed` BOOLEAN NOT NULL DEFAULT FALSE,
571
                            `treeloadstrategy` varchar(30) NOT null DEFAULT 'full',
572
                            `can_manage_all_users` tinyint(1) NOT NULL DEFAULT '0',
573
                            `usertimezone` VARCHAR(50) NOT NULL DEFAULT 'not_defined',
574
                            `agses-usercardid` VARCHAR(50) NOT NULL DEFAULT '0',
575
                            `encrypted_psk` text NULL,
576
                            `user_ip` varchar(60) NOT null DEFAULT 'none',
577
                            PRIMARY KEY (`id`),
578
                            UNIQUE KEY `login` (`login`)
579
                            ) CHARSET=utf8;"
580
                        );
581
                    } elseif ($task === "tags") {
582
                        $mysqli_result = mysqli_query(
583
                            $dbTmp,
584
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."tags` (
585
                            `id` int(12) NOT null AUTO_INCREMENT,
586
                            `tag` varchar(30) NOT NULL,
587
                            `item_id` int(12) NOT NULL,
588
                            PRIMARY KEY (`id`),
589
                            UNIQUE KEY `id` (`id`)
590
                            ) CHARSET=utf8;"
591
                        );
592
                    } elseif ($task === "log_system") {
593
                        $mysqli_result = mysqli_query(
594
                            $dbTmp,
595
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."log_system` (
596
                            `id` int(12) NOT null AUTO_INCREMENT,
597
                            `type` varchar(20) NOT NULL,
598
                            `date` varchar(30) NOT NULL,
599
                            `label` text NOT NULL,
600
                            `qui` varchar(255) NOT NULL,
601
                            `field_1` varchar(250) DEFAULT NULL,
602
                            PRIMARY KEY (`id`)
603
                            ) CHARSET=utf8;"
604
                        );
605
                    } elseif ($task === "files") {
606
                        $mysqli_result = mysqli_query(
607
                            $dbTmp,
608
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."files` (
609
                            `id` int(11) NOT null AUTO_INCREMENT,
610
                            `id_item` int(11) NOT NULL,
611
                            `name` varchar(100) NOT NULL,
612
                            `size` int(10) NOT NULL,
613
                            `extension` varchar(10) NOT NULL,
614
                            `type` varchar(255) NOT NULL,
615
                            `file` varchar(50) NOT NULL,
616
                            `status` varchar(50) NOT NULL DEFAULT '0',
617
                            PRIMARY KEY (`id`)
618
                           ) CHARSET=utf8;"
619
                        );
620
                    } elseif ($task === "cache") {
621
                        $mysqli_result = mysqli_query(
622
                            $dbTmp,
623
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."cache` (
624
                            `id` int(12) NOT NULL,
625
                            `label` varchar(500) NOT NULL,
626
                            `description` text NOT NULL,
627
                            `tags` text DEFAULT NULL,
628
                            `id_tree` int(12) NOT NULL,
629
                            `perso` tinyint(1) NOT NULL,
630
                            `restricted_to` varchar(200) DEFAULT NULL,
631
                            `login` varchar(200) DEFAULT NULL,
632
                            `folder` varchar(300) NOT NULL,
633
                            `author` varchar(50) NOT NULL,
634
                            `renewal_period` tinyint(4) NOT NULL DEFAULT '0',
635
                            `timestamp` varchar(50) DEFAULT NULL,
636
                            `url` varchar(500) NOT NULL DEFAULT '0',
637
                            `encryption_type` VARCHAR(50) DEFAULT NULL DEFAULT '0'
638
                            ) CHARSET=utf8;"
639
                        );
640
                    } elseif ($task === "roles_title") {
641
                        $mysqli_result = mysqli_query(
642
                            $dbTmp,
643
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."roles_title` (
644
                            `id` int(12) NOT null AUTO_INCREMENT,
645
                            `title` varchar(50) NOT NULL,
646
                            `allow_pw_change` TINYINT(1) NOT null DEFAULT '0',
647
                            `complexity` INT(5) NOT null DEFAULT '0',
648
                            `creator_id` int(11) NOT null DEFAULT '0',
649
                            PRIMARY KEY (`id`)
650
                            ) CHARSET=utf8;"
651
                        );
652
                    } elseif ($task === "roles_values") {
653
                        $mysqli_result = mysqli_query(
654
                            $dbTmp,
655
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."roles_values` (
656
                            `role_id` int(12) NOT NULL,
657
                            `folder_id` int(12) NOT NULL,
658
                            `type` varchar(5) NOT NULL DEFAULT 'R',
659
                            KEY `role_id_idx` (`role_id`)
660
                            ) CHARSET=utf8;"
661
                        );
662
                    } elseif ($task === "kb") {
663
                        $mysqli_result = mysqli_query(
664
                            $dbTmp,
665
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."kb` (
666
                            `id` int(12) NOT null AUTO_INCREMENT,
667
                            `category_id` int(12) NOT NULL,
668
                            `label` varchar(200) NOT NULL,
669
                            `description` text NOT NULL,
670
                            `author_id` int(12) NOT NULL,
671
                            `anyone_can_modify` tinyint(1) NOT null DEFAULT '0',
672
                            PRIMARY KEY (`id`)
673
                            ) CHARSET=utf8;"
674
                        );
675
                    } elseif ($task === "kb_categories") {
676
                        $mysqli_result = mysqli_query(
677
                            $dbTmp,
678
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."kb_categories` (
679
                            `id` int(12) NOT null AUTO_INCREMENT,
680
                            `category` varchar(50) NOT NULL,
681
                            PRIMARY KEY (`id`)
682
                            ) CHARSET=utf8;"
683
                        );
684
                    } elseif ($task === "kb_items") {
685
                        $mysqli_result = mysqli_query(
686
                            $dbTmp,
687
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."kb_items` (
688
                            `kb_id` int(12) NOT NULL,
689
                            `item_id` int(12) NOT NULL
690
                           ) CHARSET=utf8;"
691
                        );
692 View Code Duplication
                    } elseif ($task == "restriction_to_roles") {
693
                        $mysqli_result = mysqli_query(
694
                            $dbTmp,
695
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."restriction_to_roles` (
696
                            `role_id` int(12) NOT NULL,
697
                            `item_id` int(12) NOT NULL,
698
                            KEY `role_id_idx`  (`role_id`)
699
                            ) CHARSET=utf8;"
700
                        );
701
                    } elseif ($task === "languages") {
702
                        $mysqli_result = mysqli_query(
703
                            $dbTmp,
704
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."languages` (
705
                            `id` INT(10) NOT null AUTO_INCREMENT PRIMARY KEY ,
706
                            `name` VARCHAR(50) NOT null ,
707
                            `label` VARCHAR(50) NOT null ,
708
                            `code` VARCHAR(10) NOT null ,
709
                            `flag` VARCHAR(30) NOT NULL
710
                            ) CHARSET=utf8;"
711
                        );
712
713
                        // add lanaguages
714
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."languages` WHERE name = 'french'"));
715
                        if ($tmp[0] == 0) {
716
                            $mysql_result = mysqli_query(
717
                                $dbTmp,
718
                                "INSERT INTO `".$var['tbl_prefix']."languages` (`name`, `label`, `code`, `flag`) VALUES
719
                                ('french', 'French' , 'fr', 'fr.png'),
720
                                ('english', 'English' , 'us', 'us.png'),
721
                                ('spanish', 'Spanish' , 'es', 'es.png'),
722
                                ('german', 'German' , 'de', 'de.png'),
723
                                ('czech', 'Czech' , 'cz', 'cz.png'),
724
                                ('italian', 'Italian' , 'it', 'it.png'),
725
                                ('russian', 'Russian' , 'ru', 'ru.png'),
726
                                ('turkish', 'Turkish' , 'tr', 'tr.png'),
727
                                ('norwegian', 'Norwegian' , 'no', 'no.png'),
728
                                ('japanese', 'Japanese' , 'ja', 'ja.png'),
729
                                ('portuguese', 'Portuguese' , 'pr', 'pr.png'),
730
                                ('portuguese_br', 'Portuguese (Brazil)' , 'pr-bt', 'pr-bt.png'),
731
                                ('chinese', 'Chinese' , 'cn', 'cn.png'),
732
                                ('swedish', 'Swedish' , 'se', 'se.png'),
733
                                ('dutch', 'Dutch' , 'nl', 'nl.png'),
734
                                ('catalan', 'Catalan' , 'ct', 'ct.png'),
735
                                ('vietnamese', 'Vietnamese' , 'vi', 'vi.png'),
736
                                ('estonian', 'Estonian' , 'ee', 'ee.png');"
737
                            );
738
                        }
739
                    } elseif ($task === "emails") {
740
                        $mysqli_result = mysqli_query(
741
                            $dbTmp,
742
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."emails` (
743
                            `timestamp` INT(30) NOT null ,
744
                            `subject` VARCHAR(255) NOT null ,
745
                            `body` TEXT NOT null ,
746
                            `receivers` VARCHAR(255) NOT null ,
747
                            `status` VARCHAR(30) NOT NULL
748
                            ) CHARSET=utf8;"
749
                        );
750
                    } elseif ($task === "automatic_del") {
751
                        $mysqli_result = mysqli_query(
752
                            $dbTmp,
753
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."automatic_del` (
754
                            `item_id` int(11) NOT NULL,
755
                            `del_enabled` tinyint(1) NOT NULL,
756
                            `del_type` tinyint(1) NOT NULL,
757
                            `del_value` varchar(35) NOT NULL
758
                            ) CHARSET=utf8;"
759
                        );
760
                    } elseif ($task === "items_edition") {
761
                        $mysqli_result = mysqli_query(
762
                            $dbTmp,
763
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."items_edition` (
764
                            `item_id` int(11) NOT NULL,
765
                            `user_id` int(12) NOT NULL,
766
                            `timestamp` varchar(50) NOT NULL
767
                            ) CHARSET=utf8;"
768
                        );
769
                    } elseif ($task === "categories") {
770
                        $mysqli_result = mysqli_query(
771
                            $dbTmp,
772
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."categories` (
773
                            `id` int(12) NOT NULL AUTO_INCREMENT,
774
                            `parent_id` int(12) NOT NULL,
775
                            `title` varchar(255) NOT NULL,
776
                            `level` int(2) NOT NULL,
777
                            `description` text NULL,
778
                            `type` varchar(50) NULL default '',
779
                            `order` int(12) NOT NULL default '0',
780
                            `encrypted_data` tinyint(1) NOT NULL default '1',
781
                            PRIMARY KEY (`id`)
782
                            ) CHARSET=utf8;"
783
                        );
784
                    } elseif ($task === "categories_items") {
785
                        $mysqli_result = mysqli_query(
786
                            $dbTmp,
787
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."categories_items` (
788
                            `id` int(12) NOT NULL AUTO_INCREMENT,
789
                            `field_id` int(11) NOT NULL,
790
                            `item_id` int(11) NOT NULL,
791
                            `data` text NOT NULL,
792
                            `data_iv` text NOT NULL,
793
                            `encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set',
794
                            PRIMARY KEY (`id`)
795
                            ) CHARSET=utf8;"
796
                        );
797
                    } elseif ($task === "categories_folders") {
798
                        $mysqli_result = mysqli_query(
799
                            $dbTmp,
800
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."categories_folders` (
801
                            `id_category` int(12) NOT NULL,
802
                            `id_folder` int(12) NOT NULL
803
                            ) CHARSET=utf8;"
804
                        );
805
                    } elseif ($task === "api") {
806
                        $mysqli_result = mysqli_query(
807
                            $dbTmp,
808
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."api` (
809
                            `id` int(20) NOT NULL AUTO_INCREMENT,
810
                            `type` varchar(15) NOT NULL,
811
                            `label` varchar(255) NOT NULL,
812
                            `value` varchar(255) NOT NULL,
813
                            `timestamp` varchar(50) NOT NULL,
814
                            PRIMARY KEY (`id`)
815
                            ) CHARSET=utf8;"
816
                        );
817
                    } elseif ($task === "otv") {
818
                        $mysqli_result = mysqli_query(
819
                            $dbTmp,
820
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."otv` (
821
                            `id` int(10) NOT NULL AUTO_INCREMENT,
822
                            `timestamp` text NOT NULL,
823
                            `code` varchar(100) NOT NULL,
824
                            `item_id` int(12) NOT NULL,
825
                            `originator` int(12) NOT NULL,
826
                            PRIMARY KEY (`id`)
827
                            ) CHARSET=utf8;"
828
                        );
829
                    } elseif ($task === "suggestion") {
830
                        $mysqli_result = mysqli_query(
831
                            $dbTmp,
832
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."suggestion` (
833
                            `id` tinyint(12) NOT NULL AUTO_INCREMENT,
834
                            `label` varchar(255) NOT NULL,
835
                            `pw` text NOT NULL,
836
                            `pw_iv` text NOT NULL,
837
                            `pw_len` int(5) NOT NULL,
838
                            `description` text NOT NULL,
839
                            `author_id` int(12) NOT NULL,
840
                            `folder_id` int(12) NOT NULL,
841
                            `comment` text NOT NULL,
842
                            `suggestion_type` varchar(10) NOT NULL default 'new',
843
                            PRIMARY KEY (`id`)
844
                            ) CHARSET=utf8;"
845
                        );
846
847
                        $mysqli_result = mysqli_query(
848
                            $dbTmp,
849
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."export` (
850
                            `id` int(12) NOT NULL,
851
                            `label` varchar(255) NOT NULL,
852
                            `login` varchar(100) NOT NULL,
853
                            `description` text NOT NULL,
854
                            `pw` text NOT NULL,
855
                            `path` varchar(500) NOT NULL,
856
                            `email` varchar(500) NOT NULL default 'none',
857
                            `url` varchar(500) NOT NULL default 'none',
858
                            `kbs` varchar(500) NOT NULL default 'none',
859
                            `tags` varchar(500) NOT NULL default 'none'
860
                            ) CHARSET=utf8;"
861
                        );
862
                    } elseif ($task === "tokens") {
863
                        $mysqli_result = mysqli_query(
864
                            $dbTmp,
865
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."tokens` (
866
                            `id` int(12) NOT NULL AUTO_INCREMENT,
867
                            `user_id` int(12) NOT NULL,
868
                            `token` varchar(255) NOT NULL,
869
                            `reason` varchar(255) NOT NULL,
870
                            `creation_timestamp` varchar(50) NOT NULL,
871
                            `end_timestamp` varchar(50) NOT NULL,
872
                            PRIMARY KEY (`id`)
873
                            ) CHARSET=utf8;"
874
                        );
875
                    } elseif ($task === "items_change") {
876
                        $mysqli_result = mysqli_query(
877
                            $dbTmp,
878
                            "CREATE TABLE IF NOT EXISTS `".$var['tbl_prefix']."items_change` (
879
                            `id` int(12) NOT NULL AUTO_INCREMENT,
880
                            `item_id` int(12) NOT NULL,
881
                            `label` varchar(255) NOT NULL DEFAULT 'none',
882
                            `pw` text NOT NULL,
883
                            `login` varchar(255) NOT NULL DEFAULT 'none',
884
                            `email` varchar(255) NOT NULL DEFAULT 'none',
885
                            `url` varchar(255) NOT NULL DEFAULT 'none',
886
                            `description` text NOT NULL,
887
                            `comment` text NOT NULL,
888
                            `folder_id` tinyint(12) NOT NULL,
889
                            `user_id` int(12) NOT NULL,
890
                            `timestamp` varchar(50) NOT NULL DEFAULT 'none',
891
                            PRIMARY KEY (`id`)
892
                            ) CHARSET=utf8;"
893
                        );
894
                    }
895
                } elseif ($activity === "populate") {
896
                    // include constants
897
                    require_once "../includes/config/include.php";
898
899
                    if ($task === "admin") {
900
                        // check that admin accounts doesn't exist
901
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE login = 'admin'"));
902
                        if ($tmp == 0) {
903
                            $mysqli_result = mysqli_query(
904
                                $dbTmp,
905
                                "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()."')"
906
                            );
907
                        } else {
908
                            $mysqli_result = mysqli_query($dbTmp, "UPDATE `".$var['tbl_prefix']."users` SET `pw` = '".bCrypt($var['admin_pwd'], '13')."' WHERE login = 'admin' AND id = '1'");
909
                        }
910
911
                        // check that API doesn't exist
912
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE id = '".API_USER_ID."'"));
913 View Code Duplication
                        if ($tmp == 0) {
914
                            $mysqli_result = mysqli_query(
915
                                $dbTmp,
916
                                "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')"
917
                            );
918
                        }
919
920
                        // check that OTV doesn't exist
921
                        $tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `".$var['tbl_prefix']."users` WHERE id = '".OTV_USER_ID."'"));
922 View Code Duplication
                        if ($tmp == 0) {
923
                            $mysqli_result = mysqli_query(
924
                                $dbTmp,
925
                                "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')"
926
                            );
927
                        }
928
                    }
929
                }
930
                // answer back
931
                if ($mysqli_result) {
932
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'", "task" : "'.$task.'", "activity" : "'.$activity.'"}]';
933
                } else {
934
                    echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_error())).'", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'", "table" : "'.$task.'"}]';
935
                }
936 View Code Duplication
            } else {
937
                echo '[{"error" : "'.addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())).'", "result" : "Failed", "multiple" : ""}]';
938
            }
939
940
            mysqli_close($dbTmp);
941
            // Destroy session without writing to disk
942
            define('NODESTROY_SESSION', 'true');
943
            session_destroy();
944
            break;
945
946
        case "step_6":
947
            //decrypt
948
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
949
            $activity = Encryption\Crypt\aesctr::decrypt($post_activity, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
950
            $data_sent = Encryption\Crypt\aesctr::decrypt($post_data, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
951
            $data_sent = json_decode($data_sent, true);
952
            $task = Encryption\Crypt\aesctr::decrypt($post_task, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
953
            $json = Encryption\Crypt\aesctr::decrypt($post_db, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
954
            $db = json_decode($json, true);
955
956
            $dbTmp = mysqli_connect(
957
                $db['db_host'],
958
                $db['db_login'],
959
                $db['db_pw'],
960
                $db['db_bdd'],
961
                $db['db_port']
962
            );
963
964
            // read install variables
965
            $result = mysqli_query($dbTmp, "SELECT * FROM `_install`");
966
            while ($row = $result->fetch_array()) {
967
                $var[$row[0]] = $row[1];
968
            }
969
970
            // launch
971
            if (empty($var['sk_path'])) {
972
                $skFile = $var['abspath'].'/includes/sk.php';
973
                $securePath = $var['abspath'];
974
            } else {
975
                //ensure $var['sk_path'] has no trailing slash
976
                $var['sk_path'] = rtrim($var['sk_path'], '/\\');
977
                $skFile = $var['sk_path'].'/sk.php';
978
                $securePath = $var['sk_path'];
979
            }
980
981
            $events = "";
982
983
            if ($activity === "file") {
984
                if ($task === "settings.php") {
985
                    $filename = "../includes/config/settings.php";
986
987 View Code Duplication
                    if (file_exists($filename)) {
988
                        if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
989
                            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.'"}]';
990
                            break;
991
                        } else {
992
                            $events .= "The file $filename already exist. A copy has been created.<br />";
993
                            unlink($filename);
994
                        }
995
                    }
996
997
                    // Encrypt the DB password
998
                    require_once "../sources/main.functions.php";
999
                    $encrypted_text = cryption($db['db_pw'], "", "encrypt")['string'];
1000
1001
                    // Open and write Settings file
1002
                    $fh = fopen($filename, 'w');
1003
                    $result = fwrite(
1004
                        $fh,
1005
                        utf8_encode(
1006
                            "<?php
1007
global \$lang, \$txt, \$pathTeampas, \$urlTeampass, \$pwComplexity, \$mngPages;
1008
global \$server, \$user, \$pass, \$database, \$pre, \$db, \$port, \$encoding;
1009
1010
### DATABASE connexion parameters ###
1011
\$server = \"".$db['db_host']."\";
1012
\$user = \"".$db['db_login']."\";
1013
\$pass = \"".str_replace("$", "\\$", $encrypted_text)."\";
1014
\$database = \"".$db['db_bdd']."\";
1015
\$pre = \"".$var['tbl_prefix']."\";
1016
\$port = ".$db['db_port'].";
1017
\$encoding = \"".$session_db_encoding."\";
1018
1019
@date_default_timezone_set(\$_SESSION['settings']['timezone']);
1020
@define('SECUREPATH', '".$securePath."');
1021
if (file_exists(\"".str_replace('\\', '/', $skFile)."\")) {
1022
    require_once \"".str_replace('\\', '/', $skFile)."\";
1023
}
1024
"
1025
                        )
1026
                    );
1027
                    fclose($fh);
1028 View Code Duplication
                    if ($result === false) {
1029
                        echo '[{"error" : "Setting.php file could not be created. Please check the path and the rights", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1030
                    } else {
1031
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1032
                    }
1033
                } elseif ($task === "sk.php") {
1034
//Create sk.php file
1035 View Code Duplication
                    if (file_exists($skFile)) {
1036
                        if (!copy($skFile, $skFile.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1037
                            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.'"}]';
1038
                            break;
1039
                        } else {
1040
                            unlink($skFile);
1041
                        }
1042
                    }
1043
                    $fh = fopen($skFile, 'w');
1044
1045
                    $result = fwrite(
1046
                        $fh,
1047
                        utf8_encode(
1048
                            "<?php
1049
@define('COST', '13'); // Don't change this.
1050
@define('AKEY', '');
1051
@define('IKEY', '');
1052
@define('SKEY', '');
1053
@define('HOST', '');
1054
?>"
1055
                        )
1056
                    );
1057
                    fclose($fh);
1058
1059
                    // finalize
1060 View Code Duplication
                    if ($result === false) {
1061
                        echo '[{"error" : "sk.php file could not be created. Please check the path and the rights.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1062
                    } else {
1063
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1064
                    }
1065
                } elseif ($task === "security") {
1066
                    # Sort out the file permissions
1067
1068
                    // is server Windows or Linux?
1069
                    if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
1070
                        // Change directory permissions
1071
                        $result = chmodRecursive($session_abspath, 0770, 0740);
1072
                        if ($result) {
1073
                            $result = chmodRecursive($session_abspath.'/files', 0770, 0770);
1074
                        }
1075
                        if ($result) {
1076
                            $result = chmodRecursive($session_abspath.'/upload', 0770, 0770);
1077
                        }
1078
                    }
1079
1080 View Code Duplication
                    if ($result === false) {
1081
                        echo '[{"error" : "Cannot change directory permissions - please fix manually", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1082
                    } else {
1083
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1084
                    }
1085
                } elseif ($task === "teampass-seckey") {
1086
                    // create teampass-seckey.txt
1087
                    require_once '../includes/libraries/Encryption/Encryption/Crypto.php';
1088
                    require_once '../includes/libraries/Encryption/Encryption/Encoding.php';
1089
                    require_once '../includes/libraries/Encryption/Encryption/DerivedKeys.php';
1090
                    require_once '../includes/libraries/Encryption/Encryption/Key.php';
1091
                    require_once '../includes/libraries/Encryption/Encryption/KeyOrPassword.php';
1092
                    require_once '../includes/libraries/Encryption/Encryption/File.php';
1093
                    require_once '../includes/libraries/Encryption/Encryption/RuntimeTests.php';
1094
                    require_once '../includes/libraries/Encryption/Encryption/KeyProtectedByPassword.php';
1095
                    require_once '../includes/libraries/Encryption/Encryption/Core.php';
1096
1097
                    $key = \Defuse\Crypto\Key::createNewRandomKey();
1098
                    $new_salt = $key->saveToAsciiSafeString();
1099
1100
                    file_put_contents(
1101
                        $securePath."/teampass-seckey.txt",
1102
                        $new_salt
1103
                    );
1104
1105
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1106
                } elseif ($task === "csrfp-token") {
1107
                    // update CSRFP TOKEN
1108
                    $csrfp_file_sample = "../includes/libraries/csrfp/libs/csrfp.config.sample.php";
1109
                    $csrfp_file = "../includes/libraries/csrfp/libs/csrfp.config.php";
1110 View Code Duplication
                    if (file_exists($csrfp_file)) {
1111
                        if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1112
                            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.'"}]';
1113
                            break;
1114
                        } else {
1115
                            $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
1116
                        }
1117
                    }
1118
                    unlink($csrfp_file); // delete existing csrfp.config file
1119
                    copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
1120
                    $data = file_get_contents($csrfp_file);
1121
                    $newdata = str_replace('"CSRFP_TOKEN" => ""', '"CSRFP_TOKEN" => "'.bin2hex(openssl_random_pseudo_bytes(25)).'"', $data);
1122
                    $jsUrl = $data_sent['url_path'].'/includes/libraries/csrfp/js/csrfprotector.js';
1123
                    $newdata = str_replace('"jsUrl" => ""', '"jsUrl" => "'.$jsUrl.'"', $newdata);
1124
                    file_put_contents("../includes/libraries/csrfp/libs/csrfp.config.php", $newdata);
1125
1126
                    echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1127
                }
1128
            }
1129
1130
            mysqli_close($dbTmp);
1131
            // Destroy session without writing to disk
1132
            define('NODESTROY_SESSION', 'true');
1133
            session_destroy();
1134
            break;
1135
1136
        case "step_7":
1137
            // Decrypt
1138
            require_once 'libs/aesctr.php'; // AES Counter Mode implementation
1139
            $activity = Encryption\Crypt\aesctr::decrypt($post_activity, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1140
            $task = Encryption\Crypt\aesctr::decrypt($post_task, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1141
            $json = Encryption\Crypt\aesctr::decrypt($post_db, "cpm", 128);
0 ignored issues
show
Documentation introduced by
'cpm' is of type string, but the function expects a object<Encryption\Crypt\the>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1142
            $db = json_decode($json, true);
1143
            // launch
1144
            $dbTmp = @mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']);
1145
1146
            if ($activity === "file") {
1147
                if ($task === "deleteInstall") {
1148
                    function delTree($dir)
1149
                    {
1150
                        $files = array_diff(scandir($dir), array('.', '..'));
1151
1152
                        foreach ($files as $file) {
1153
                            (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
1154
                        }
1155
                        return rmdir($dir);
1156
                    }
1157
1158
                    $result = true;
1159
                    $errorMsg = "Cannot delete `install` folder. Please do it manually.";
1160
                    if (file_exists($session_abspath.'/install')) {
1161
                        // set the permissions on the install directory and delete
1162
                        // is server Windows or Linux?
1163
                        if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
1164
                            chmodRecursive($session_abspath.'/install', 0755, 0440);
1165
                        }
1166
                        $result = delTree($session_abspath.'/install');
1167
                    }
1168
1169
                    // delete temporary install table
1170
                    $result = mysqli_query($dbTmp, "DROP TABLE `_install`");
1171
                    $errorMsg = "Cannot remove `_install` table. Please do it manually.";
1172
1173 View Code Duplication
                    if ($result === false) {
1174
                        echo '[{"error" : "'.$errorMsg.'", "index" : "'.$post_index.'", "result" : "", "multiple" : ""}]';
1175
                    } else {
1176
                        echo '[{"error" : "", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1177
                    }
1178
                }
1179
            }
1180
            // delete install table
1181
            //
1182
            mysqli_close($dbTmp);
1183
            // Destroy session without writing to disk
1184
            define('NODESTROY_SESSION', 'true');
1185
            session_destroy();
1186
            break;
1187
    }
1188
}
1189