|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Teampass - a collaborative passwords manager. |
|
4
|
|
|
* --- |
|
5
|
|
|
* This library is distributed in the hope that it will be useful, |
|
6
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
8
|
|
|
* --- |
|
9
|
|
|
* @project Teampass |
|
10
|
|
|
* @file install.queries.php |
|
11
|
|
|
* --- |
|
12
|
|
|
* @author Nils Laumaillé ([email protected]) |
|
13
|
|
|
* @copyright 2009-2023 Teampass.net |
|
14
|
|
|
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0 |
|
15
|
|
|
* --- |
|
16
|
|
|
* @see https://www.teampass.net |
|
17
|
|
|
*/ |
|
18
|
|
|
use TiBeN\CrontabManager\CrontabJob; |
|
19
|
|
|
use TiBeN\CrontabManager\CrontabAdapter; |
|
20
|
|
|
use TiBeN\CrontabManager\CrontabRepository; |
|
21
|
|
|
use Defuse\Crypto\Key; |
|
22
|
|
|
use Defuse\Crypto\Crypto; |
|
23
|
|
|
use Defuse\Crypto\Exception as CryptoException; |
|
24
|
|
|
use EZimuel\PHPSecureSession; |
|
25
|
|
|
use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator; |
|
26
|
|
|
use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator; |
|
27
|
|
|
use TeampassClasses\SuperGlobal\SuperGlobal; |
|
28
|
|
|
use TeampassClasses\Language\Language; |
|
29
|
|
|
|
|
30
|
|
|
// Do initial test |
|
31
|
|
|
if (file_exists('../includes/config/settings.php') === false) { |
|
32
|
|
|
$settings_sample = 'includes/config/settings.sample.php'; |
|
33
|
|
|
$settings = 'includes/config/settings.php'; |
|
34
|
|
|
if (copy('../'.$settings_sample, '../'.$settings) === false) { |
|
35
|
|
|
echo '[{"error" : "File <i>' . $settings . '</i> could not be copied from <i>'.$settings_sample.'</i>.<br>Please do it on your own or change folder rights, and click START button!", "index" : "99", "multiple" : "' . $post_multiple . '"}]'; |
|
36
|
|
|
exit(); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Load functions |
|
41
|
|
|
require_once __DIR__.'/../sources/main.functions.php'; |
|
42
|
|
|
|
|
43
|
|
|
// init |
|
44
|
|
|
loadClasses('DB'); |
|
45
|
|
|
$superGlobal = new SuperGlobal(); |
|
46
|
|
|
$lang = new Language(); |
|
47
|
|
|
session_name('teampass_session'); |
|
48
|
|
|
session_start(); |
|
49
|
|
|
|
|
50
|
|
|
// Load config if $SETTINGS not defined |
|
51
|
|
|
try { |
|
52
|
|
|
include_once __DIR__.'/../includes/config/tp.config.php'; |
|
53
|
|
|
} catch (Exception $e) { |
|
54
|
|
|
throw new Exception("Error file '/includes/config/tp.config.php' not exists", 1); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// Define Timezone |
|
58
|
|
|
date_default_timezone_set(isset($SETTINGS['timezone']) === true ? $SETTINGS['timezone'] : 'UTC'); |
|
59
|
|
|
|
|
60
|
|
|
// Set header properties |
|
61
|
|
|
header('Content-type: text/html; charset=utf-8'); |
|
62
|
|
|
header('Cache-Control: no-cache, no-store, must-revalidate'); |
|
63
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
64
|
|
|
// increase the maximum amount of time a script is allowed to run |
|
65
|
|
|
set_time_limit(600); |
|
66
|
|
|
$session_db_encoding = 'utf8'; |
|
67
|
|
|
define('MIN_PHP_VERSION', 8.1); |
|
68
|
|
|
|
|
69
|
|
|
$superGlobal = new SuperGlobal(); |
|
70
|
|
|
$lang = new Language(); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Generates a random key. |
|
74
|
|
|
*/ |
|
75
|
|
|
function generateRandomKey() |
|
76
|
|
|
{ |
|
77
|
|
|
// load passwordLib library |
|
78
|
|
|
$generator = new ComputerPasswordGenerator(); |
|
79
|
|
|
$generator->setRandomGenerator(new Php7RandomGenerator()); |
|
80
|
|
|
$generator->setLength(40); |
|
81
|
|
|
$generator->setSymbols(false); |
|
82
|
|
|
$generator->setLowercase(true); |
|
83
|
|
|
$generator->setUppercase(true); |
|
84
|
|
|
$generator->setNumbers(true); |
|
85
|
|
|
|
|
86
|
|
|
$key = $generator->generatePasswords(); |
|
87
|
|
|
|
|
88
|
|
|
return $key[0]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Permits to encrypt a message using Defuse. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $message Message to encrypt |
|
95
|
|
|
* @param string $ascii_key Key to hash |
|
96
|
|
|
* |
|
97
|
|
|
* @return array String + Error |
|
98
|
|
|
*/ |
|
99
|
|
|
function encryptFollowingDefuse($message, $ascii_key) |
|
100
|
|
|
{ |
|
101
|
|
|
// convert KEY |
|
102
|
|
|
$key = Key::loadFromAsciiSafeString($ascii_key); |
|
103
|
|
|
|
|
104
|
|
|
try { |
|
105
|
|
|
$text = Crypto::encrypt($message, $key); |
|
106
|
|
|
} catch (CryptoException\WrongKeyOrModifiedCiphertextException $ex) { |
|
107
|
|
|
$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.'; |
|
108
|
|
|
} catch (CryptoException\BadFormatException $ex) { |
|
109
|
|
|
$err = $ex; |
|
110
|
|
|
} catch (CryptoException\EnvironmentIsBrokenException $ex) { |
|
111
|
|
|
$err = $ex; |
|
112
|
|
|
} catch (CryptoException\CryptoException $ex) { |
|
113
|
|
|
$err = $ex; |
|
114
|
|
|
} catch (CryptoException\IOException $ex) { |
|
115
|
|
|
$err = $ex; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return array( |
|
119
|
|
|
'string' => isset($text) ? $text : '', |
|
120
|
|
|
'error' => $err, |
|
|
|
|
|
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
// Prepare POST variables |
|
125
|
|
|
$post_type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
126
|
|
|
$post_data = filter_input(INPUT_POST, 'data', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES); |
|
127
|
|
|
$post_activity = filter_input(INPUT_POST, 'activity', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
128
|
|
|
$post_task = filter_input(INPUT_POST, 'task', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
129
|
|
|
$post_index = filter_input(INPUT_POST, 'index', FILTER_SANITIZE_NUMBER_INT); |
|
130
|
|
|
$post_multiple = filter_input(INPUT_POST, 'multiple', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
131
|
|
|
$post_db = filter_input(INPUT_POST, 'db', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
132
|
|
|
|
|
133
|
|
|
// Prepare SESSION variables |
|
134
|
|
|
$session_url_path = $superGlobal->get('url_path', 'SESSION'); |
|
135
|
|
|
$session_abspath = $superGlobal->get('absolute_path', 'SESSION'); |
|
136
|
|
|
$session_db_encoding = $superGlobal->get('db_encoding', 'SESSION'); |
|
137
|
|
|
if (empty($session_db_encoding) === true) { |
|
138
|
|
|
$session_db_encoding = 'utf8'; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$superGlobal->put('CPM', 1, 'SESSION'); |
|
142
|
|
|
|
|
143
|
|
|
if (null !== $post_type) { |
|
144
|
|
|
switch ($post_type) { |
|
145
|
|
|
case 'step_2': |
|
146
|
|
|
//decrypt |
|
147
|
|
|
require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
148
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128); |
|
149
|
|
|
$data = json_decode($json, true); |
|
150
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_activity, 'cpm', 128); |
|
151
|
|
|
$data = array_merge($data, array('activity' => $json)); |
|
152
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_task, 'cpm', 128); |
|
153
|
|
|
$data = array_merge($data, array('task' => $json)); |
|
154
|
|
|
|
|
155
|
|
|
$abspath = str_replace('\\', '/', $data['absolute_path']); |
|
156
|
|
|
if (substr($abspath, strlen($abspath) - 1) == '/') { |
|
157
|
|
|
$abspath = substr($abspath, 0, strlen($abspath) - 1); |
|
158
|
|
|
} |
|
159
|
|
|
$session_abspath = $abspath; |
|
160
|
|
|
$session_url_path = $data['url_path']; |
|
161
|
|
|
|
|
162
|
|
|
if (isset($data['activity']) && $data['activity'] === 'folder') { |
|
163
|
|
|
$targetPath = $abspath . '/' . $data['task'] . '/'; |
|
164
|
|
|
if (is_writable($targetPath) === true) { |
|
165
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
166
|
|
|
} else { |
|
167
|
|
|
echo '[{"error" : " Path ' . $targetPath . ' is not writable!", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
168
|
|
|
} |
|
169
|
|
|
break; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
if (isset($data['activity']) && $data['activity'] === 'extension') { |
|
173
|
|
|
if (extension_loaded($data['task'])) { |
|
174
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
175
|
|
|
} else { |
|
176
|
|
|
echo '[{"error" : " Extension ' . $data['task'] . ' is not loaded!", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
177
|
|
|
} |
|
178
|
|
|
break; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if (isset($data['activity']) && $data['activity'] === 'function') { |
|
182
|
|
|
if (function_exists($data['task'])) { |
|
183
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
184
|
|
|
} else { |
|
185
|
|
|
echo '[{"error" : " Function ' . $data['task'] . ' is not available!", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
186
|
|
|
} |
|
187
|
|
|
break; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
if (isset($data['activity']) && $data['activity'] === 'version') { |
|
191
|
|
|
if (version_compare(phpversion(), MIN_PHP_VERSION, '>=')) { |
|
192
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
193
|
|
|
} else { |
|
194
|
|
|
echo '[{"error" : "PHP version ' . phpversion() . ' is not OK (minimum is '.MIN_PHP_VERSION.')", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
195
|
|
|
} |
|
196
|
|
|
break; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
if (isset($data['activity']) && $data['activity'] === 'ini') { |
|
200
|
|
|
if (ini_get($data['task']) >= 30) { |
|
201
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '"}]'; |
|
202
|
|
|
} else { |
|
203
|
|
|
echo '[{"error" : "PHP \"Maximum execution time\" is set to ' . ini_get('max_execution_time') . ' seconds. Please try to set to 30s at least during installation.", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
204
|
|
|
} |
|
205
|
|
|
break; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
break; |
|
209
|
|
|
|
|
210
|
|
|
case 'step_3': |
|
211
|
|
|
//decrypt |
|
212
|
|
|
require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
213
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128); |
|
214
|
|
|
$data = json_decode($json, true); |
|
215
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128); |
|
216
|
|
|
$db = json_decode($json, true); |
|
217
|
|
|
|
|
218
|
|
|
$post_abspath = str_replace('\\', '/', $data['absolute_path']); |
|
219
|
|
|
if (substr($abspath, strlen($post_abspath) - 1) == '/') { |
|
220
|
|
|
$post_abspath = substr($post_abspath, 0, strlen($post_abspath) - 1); |
|
221
|
|
|
} |
|
222
|
|
|
$post_urlpath = $data['url_path']; |
|
223
|
|
|
|
|
224
|
|
|
// launch |
|
225
|
|
|
try { |
|
226
|
|
|
$dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']); |
|
|
|
|
|
|
227
|
|
|
} catch (Exception $e) { |
|
228
|
|
|
echo '[{"error" : "Cannot connect to Database - '.$e->getMessage().'"}]'; |
|
229
|
|
|
break; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
if ($dbTmp) { |
|
233
|
|
|
// create temporary INSTALL mysqli table |
|
234
|
|
|
$mysqli_result = mysqli_query( |
|
235
|
|
|
$dbTmp, |
|
236
|
|
|
'CREATE TABLE IF NOT EXISTS `_install` ( |
|
237
|
|
|
`key` varchar(100) NOT NULL, |
|
238
|
|
|
`value` varchar(500) NOT NULL, |
|
239
|
|
|
PRIMARY KEY (`key`) |
|
240
|
|
|
) CHARSET=utf8;' |
|
241
|
|
|
); |
|
242
|
|
|
//print_r($data); |
|
243
|
|
|
// store values |
|
244
|
|
|
foreach ($data as $key => $value) { |
|
245
|
|
|
$superGlobal->put($key, $value, 'SESSION'); |
|
246
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = '" . $key . "'")); |
|
|
|
|
|
|
247
|
|
|
if (intval($tmp) === 0) { |
|
248
|
|
|
mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('" . $key . "', '" . $value . "');"); |
|
249
|
|
|
} else { |
|
250
|
|
|
mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '" . $value . "' WHERE `key` = '" . $key . "';"); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = 'url_path'")); |
|
254
|
|
|
if (intval($tmp) === 0) { |
|
255
|
|
|
mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('url_path', '" . empty($post_urlpath) ? $db['url_path'] : $post_urlpath . "');"); |
|
256
|
|
|
}/* else { |
|
257
|
|
|
mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '". empty($session_url_path) ? $data['url_path'] : $session_url_path. "' WHERE `key` = 'url_path';"); |
|
258
|
|
|
}*/ |
|
259
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = 'absolute_path'")); |
|
260
|
|
|
if (intval($tmp) === 0) { |
|
261
|
|
|
mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('absolute_path', '" . empty($post_abspath) ? $data['absolute_path'] : $post_abspath . "');"); |
|
262
|
|
|
}/* else { |
|
263
|
|
|
mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '" . empty($session_abspath) ? $data['absolute_path'] : $session_abspath . "' WHERE `key` = 'absolute_path';"); |
|
264
|
|
|
}*/ |
|
265
|
|
|
|
|
266
|
|
|
echo '[{"error" : "", "result" : "Connection is successful", "multiple" : ""}]'; |
|
267
|
|
|
} else { |
|
268
|
|
|
echo '[{"error" : "' . addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())) . '", "result" : "Failed", "multiple" : ""}]'; |
|
269
|
|
|
} |
|
270
|
|
|
mysqli_close($dbTmp); |
|
271
|
|
|
break; |
|
272
|
|
|
|
|
273
|
|
|
case 'step_4': |
|
274
|
|
|
//decrypt |
|
275
|
|
|
require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
276
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128); |
|
277
|
|
|
$data = json_decode($json, true); |
|
278
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128); |
|
279
|
|
|
$db = json_decode($json, true); |
|
280
|
|
|
|
|
281
|
|
|
$dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']); |
|
282
|
|
|
|
|
283
|
|
|
// prepare data |
|
284
|
|
|
foreach ($data as $key => $value) { |
|
285
|
|
|
$data[$key] = str_replace(array('"', '\'), array('""', '\\\\'), $value); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
// check skpath |
|
289
|
|
|
if (empty($data['sk_path'])) { |
|
290
|
|
|
$data['sk_path'] = $session_abspath . '/includes'; |
|
291
|
|
|
} else { |
|
292
|
|
|
$data['sk_path'] = str_replace('\', '/', $data['sk_path']); |
|
293
|
|
|
} |
|
294
|
|
|
if (substr($data['sk_path'], strlen($data['sk_path']) - 1) == '/' || substr($data['sk_path'], strlen($data['sk_path']) - 1) == '"') { |
|
295
|
|
|
$data['sk_path'] = substr($data['sk_path'], 0, strlen($data['sk_path']) - 1); |
|
296
|
|
|
} |
|
297
|
|
|
if (is_dir($data['sk_path'])) { |
|
298
|
|
|
if (is_writable($data['sk_path'])) { |
|
299
|
|
|
// store all variables in SESSION |
|
300
|
|
|
foreach ($data as $key => $value) { |
|
301
|
|
|
$superGlobal->put($key, $value, 'SESSION'); |
|
302
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `_install` WHERE `key` = '" . $key . "'")); |
|
303
|
|
|
if (intval($tmp) === 0) { |
|
304
|
|
|
mysqli_query($dbTmp, "INSERT INTO `_install` (`key`, `value`) VALUES ('" . $key . "', '" . $value . "');"); |
|
305
|
|
|
} else { |
|
306
|
|
|
mysqli_query($dbTmp, "UPDATE `_install` SET `value` = '" . $value . "' WHERE `key` = '" . $key . "';"); |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
echo '[{"error" : "", "result" : "Information stored", "multiple" : ""}]'; |
|
310
|
|
|
} else { |
|
311
|
|
|
echo '[{"error" : "The Directory must be writable!", "result" : "Information stored", "multiple" : ""}]'; |
|
312
|
|
|
} |
|
313
|
|
|
} else { |
|
314
|
|
|
echo '[{"error" : "' . $data['sk_path'] . ' is not a Directory!", "result" : "Information stored", "multiple" : ""}]'; |
|
315
|
|
|
} |
|
316
|
|
|
mysqli_close($dbTmp); |
|
317
|
|
|
break; |
|
318
|
|
|
|
|
319
|
|
|
case 'step_5': |
|
320
|
|
|
//decrypt |
|
321
|
|
|
require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
322
|
|
|
$activity = Encryption\Crypt\aesctr::decrypt($post_activity, 'cpm', 128); |
|
323
|
|
|
$task = Encryption\Crypt\aesctr::decrypt($post_task, 'cpm', 128); |
|
324
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128); |
|
325
|
|
|
$db = json_decode($json, true); |
|
326
|
|
|
|
|
327
|
|
|
// launch |
|
328
|
|
|
$dbTmp = mysqli_connect($db['db_host'], $db['db_login'], $db['db_pw'], $db['db_bdd'], $db['db_port']); |
|
329
|
|
|
$dbBdd = $db['db_bdd']; |
|
330
|
|
|
if ($dbTmp) { |
|
331
|
|
|
$mysqli_result = ''; |
|
332
|
|
|
|
|
333
|
|
|
// read install variables |
|
334
|
|
|
$result = mysqli_query($dbTmp, 'SELECT * FROM `_install`'); |
|
335
|
|
|
while ($row = $result->fetch_array()) { |
|
336
|
|
|
$var[$row[0]] = $row[1]; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
if ($activity === 'table') { |
|
340
|
|
|
if ($task === 'utf8') { |
|
341
|
|
|
//FORCE UTF8 DATABASE |
|
342
|
|
|
mysqli_query($dbTmp, 'ALTER DATABASE `' . $dbBdd . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'); |
|
343
|
|
|
} elseif ($task === 'defuse_passwords') { |
|
344
|
|
|
$mysqli_result = mysqli_query( |
|
345
|
|
|
$dbTmp, |
|
346
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'defuse_passwords` ( |
|
347
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
348
|
|
|
`type` varchar(100) NOT NULL, |
|
349
|
|
|
`object_id` int(12) NOT NULL, |
|
350
|
|
|
`password` text NOT NULL, |
|
351
|
|
|
PRIMARY KEY (`increment_id`) |
|
352
|
|
|
) CHARSET=utf8;' |
|
353
|
|
|
); |
|
354
|
|
|
} elseif ($task === 'notification') { |
|
355
|
|
|
$mysqli_result = mysqli_query( |
|
356
|
|
|
$dbTmp, |
|
357
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'notification` ( |
|
358
|
|
|
`increment_id` INT(12) NOT NULL AUTO_INCREMENT, |
|
359
|
|
|
`item_id` INT(12) NOT NULL, |
|
360
|
|
|
`user_id` INT(12) NOT NULL, |
|
361
|
|
|
PRIMARY KEY (`increment_id`) |
|
362
|
|
|
) CHARSET=utf8;' |
|
363
|
|
|
); |
|
364
|
|
|
} elseif ($task === 'sharekeys_items') { |
|
365
|
|
|
$mysqli_result = mysqli_query( |
|
366
|
|
|
$dbTmp, |
|
367
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'sharekeys_items` ( |
|
368
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
369
|
|
|
`object_id` int(12) NOT NULL, |
|
370
|
|
|
`user_id` int(12) NOT NULL, |
|
371
|
|
|
`share_key` text NOT NULL, |
|
372
|
|
|
PRIMARY KEY (`increment_id`) |
|
373
|
|
|
) CHARSET=utf8;' |
|
374
|
|
|
); |
|
375
|
|
|
$mysqli_result = mysqli_query( |
|
376
|
|
|
$dbTmp, |
|
377
|
|
|
'ALTER TABLE `' . $var['tbl_prefix'] . 'sharekeys_items` |
|
378
|
|
|
ADD KEY `object_id_idx` (`object_id`), |
|
379
|
|
|
ADD KEY `user_id_idx` (`user_id`);' |
|
380
|
|
|
); |
|
381
|
|
|
} elseif ($task === 'sharekeys_logs') { |
|
382
|
|
|
$mysqli_result = mysqli_query( |
|
383
|
|
|
$dbTmp, |
|
384
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'sharekeys_logs` ( |
|
385
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
386
|
|
|
`object_id` int(12) NOT NULL, |
|
387
|
|
|
`user_id` int(12) NOT NULL, |
|
388
|
|
|
`share_key` text NOT NULL, |
|
389
|
|
|
PRIMARY KEY (`increment_id`) |
|
390
|
|
|
) CHARSET=utf8;' |
|
391
|
|
|
); |
|
392
|
|
|
$mysqli_result = mysqli_query( |
|
393
|
|
|
$dbTmp, |
|
394
|
|
|
'ALTER TABLE `' . $var['tbl_prefix'] . 'sharekeys_logs` |
|
395
|
|
|
ADD KEY `object_id_idx` (`object_id`), |
|
396
|
|
|
ADD KEY `user_id_idx` (`user_id`);' |
|
397
|
|
|
); |
|
398
|
|
|
} elseif ($task === 'sharekeys_fields') { |
|
399
|
|
|
$mysqli_result = mysqli_query( |
|
400
|
|
|
$dbTmp, |
|
401
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'sharekeys_fields` ( |
|
402
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
403
|
|
|
`object_id` int(12) NOT NULL, |
|
404
|
|
|
`user_id` int(12) NOT NULL, |
|
405
|
|
|
`share_key` text NOT NULL, |
|
406
|
|
|
PRIMARY KEY (`increment_id`) |
|
407
|
|
|
) CHARSET=utf8;' |
|
408
|
|
|
); |
|
409
|
|
|
} elseif ($task === 'sharekeys_suggestions') { |
|
410
|
|
|
$mysqli_result = mysqli_query( |
|
411
|
|
|
$dbTmp, |
|
412
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'sharekeys_suggestions` ( |
|
413
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
414
|
|
|
`object_id` int(12) NOT NULL, |
|
415
|
|
|
`user_id` int(12) NOT NULL, |
|
416
|
|
|
`share_key` text NOT NULL, |
|
417
|
|
|
PRIMARY KEY (`increment_id`) |
|
418
|
|
|
) CHARSET=utf8;' |
|
419
|
|
|
); |
|
420
|
|
|
} elseif ($task === 'sharekeys_files') { |
|
421
|
|
|
$mysqli_result = mysqli_query( |
|
422
|
|
|
$dbTmp, |
|
423
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'sharekeys_files` ( |
|
424
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
425
|
|
|
`object_id` int(12) NOT NULL, |
|
426
|
|
|
`user_id` int(12) NOT NULL, |
|
427
|
|
|
`share_key` text NOT NULL, |
|
428
|
|
|
PRIMARY KEY (`increment_id`) |
|
429
|
|
|
) CHARSET=utf8;' |
|
430
|
|
|
); |
|
431
|
|
|
} elseif ($task === 'items') { |
|
432
|
|
|
$mysqli_result = mysqli_query( |
|
433
|
|
|
$dbTmp, |
|
434
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "items` ( |
|
435
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
436
|
|
|
`label` varchar(500) NOT NULL, |
|
437
|
|
|
`description` text DEFAULT NULL, |
|
438
|
|
|
`pw` text DEFAULT NULL, |
|
439
|
|
|
`pw_iv` text DEFAULT NULL, |
|
440
|
|
|
`pw_len` int(5) NOT NULL DEFAULT '0', |
|
441
|
|
|
`url` text DEFAULT NULL, |
|
442
|
|
|
`id_tree` varchar(10) DEFAULT NULL, |
|
443
|
|
|
`perso` tinyint(1) NOT null DEFAULT '0', |
|
444
|
|
|
`login` varchar(200) DEFAULT NULL, |
|
445
|
|
|
`inactif` tinyint(1) NOT null DEFAULT '0', |
|
446
|
|
|
`restricted_to` varchar(200) DEFAULT NULL, |
|
447
|
|
|
`anyone_can_modify` tinyint(1) NOT null DEFAULT '0', |
|
448
|
|
|
`email` varchar(100) DEFAULT NULL, |
|
449
|
|
|
`notification` varchar(250) DEFAULT NULL, |
|
450
|
|
|
`viewed_no` int(12) NOT null DEFAULT '0', |
|
451
|
|
|
`complexity_level` varchar(3) NOT null DEFAULT '-1', |
|
452
|
|
|
`auto_update_pwd_frequency` tinyint(2) NOT null DEFAULT '0', |
|
453
|
|
|
`auto_update_pwd_next_date` varchar(100) NOT null DEFAULT '0', |
|
454
|
|
|
`encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set', |
|
455
|
|
|
`fa_icon` varchar(100) DEFAULT NULL, |
|
456
|
|
|
`item_key` varchar(500) NOT NULL DEFAULT '-1', |
|
457
|
|
|
`created_at` varchar(30) NULL, |
|
458
|
|
|
`updated_at` varchar(30) NULL, |
|
459
|
|
|
`deleted_at` varchar(30) NULL, |
|
460
|
|
|
PRIMARY KEY (`id`), |
|
461
|
|
|
KEY `restricted_inactif_idx` (`restricted_to`,`inactif`) |
|
462
|
|
|
) CHARSET=utf8;" |
|
463
|
|
|
); |
|
464
|
|
|
} elseif ($task === 'log_items') { |
|
465
|
|
|
$mysqli_result = mysqli_query( |
|
466
|
|
|
$dbTmp, |
|
467
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "log_items` ( |
|
468
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
469
|
|
|
`id_item` int(8) NOT NULL, |
|
470
|
|
|
`date` varchar(50) NOT NULL, |
|
471
|
|
|
`id_user` int(8) NOT NULL, |
|
472
|
|
|
`action` varchar(250) NULL, |
|
473
|
|
|
`raison` text NULL, |
|
474
|
|
|
`old_value` MEDIUMTEXT NULL DEFAULT NULL, |
|
475
|
|
|
`encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set', |
|
476
|
|
|
PRIMARY KEY (`increment_id`) |
|
477
|
|
|
) CHARSET=utf8;" |
|
478
|
|
|
); |
|
479
|
|
|
// create index |
|
480
|
|
|
mysqli_query( |
|
481
|
|
|
$dbTmp, |
|
482
|
|
|
'CREATE INDEX teampass_log_items_id_item_IDX ON ' . $var['tbl_prefix'] . 'log_items (id_item,date);' |
|
483
|
|
|
); |
|
484
|
|
|
} elseif ($task === 'misc') { |
|
485
|
|
|
$mysqli_result = mysqli_query( |
|
486
|
|
|
$dbTmp, |
|
487
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'misc` ( |
|
488
|
|
|
`increment_id` int(12) NOT null AUTO_INCREMENT, |
|
489
|
|
|
`type` varchar(50) NOT NULL, |
|
490
|
|
|
`intitule` varchar(100) NOT NULL, |
|
491
|
|
|
`valeur` varchar(500) NOT NULL, |
|
492
|
|
|
PRIMARY KEY (`increment_id`) |
|
493
|
|
|
) CHARSET=utf8;' |
|
494
|
|
|
); |
|
495
|
|
|
|
|
496
|
|
|
// include constants |
|
497
|
|
|
require_once '../includes/config/include.php'; |
|
498
|
|
|
|
|
499
|
|
|
// prepare config file |
|
500
|
|
|
$tp_config_file = '../includes/config/tp.config.php'; |
|
501
|
|
|
if (file_exists($tp_config_file)) { |
|
502
|
|
|
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'))))) { |
|
503
|
|
|
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 . '"}]'; |
|
504
|
|
|
break; |
|
505
|
|
|
} else { |
|
506
|
|
|
unlink($tp_config_file); |
|
507
|
|
|
} |
|
508
|
|
|
} |
|
509
|
|
|
$file_handler = fopen($tp_config_file, 'w'); |
|
510
|
|
|
$config_text = '<?php |
|
511
|
|
|
global $SETTINGS; |
|
512
|
|
|
$SETTINGS = array ('; |
|
513
|
|
|
|
|
514
|
|
|
// add by default settings |
|
515
|
|
|
$aMiscVal = array( |
|
516
|
|
|
array('admin', 'max_latest_items', '10'), |
|
517
|
|
|
array('admin', 'enable_favourites', '1'), |
|
518
|
|
|
array('admin', 'show_last_items', '1'), |
|
519
|
|
|
array('admin', 'enable_pf_feature', '0'), |
|
520
|
|
|
array('admin', 'log_connections', '1'), |
|
521
|
|
|
array('admin', 'log_accessed', '1'), |
|
522
|
|
|
array('admin', 'time_format', 'H:i:s'), |
|
523
|
|
|
array('admin', 'date_format', 'd/m/Y'), |
|
524
|
|
|
array('admin', 'duplicate_folder', '0'), |
|
525
|
|
|
array('admin', 'item_duplicate_in_same_folder', '0'), |
|
526
|
|
|
array('admin', 'duplicate_item', '0'), |
|
527
|
|
|
array('admin', 'number_of_used_pw', '3'), |
|
528
|
|
|
array('admin', 'manager_edit', '1'), |
|
529
|
|
|
array('admin', 'cpassman_dir', $var['absolute_path']), |
|
530
|
|
|
array('admin', 'cpassman_url', $var['url_path']), |
|
531
|
|
|
array('admin', 'favicon', $var['url_path'] . '/favicon.ico'), |
|
532
|
|
|
array('admin', 'path_to_upload_folder', $var['absolute_path'] . '/upload'), |
|
533
|
|
|
array('admin', 'path_to_files_folder', $var['absolute_path'] . '/files'), |
|
534
|
|
|
array('admin', 'url_to_files_folder', $var['url_path'] . '/files'), |
|
535
|
|
|
array('admin', 'activate_expiration', '0'), |
|
536
|
|
|
array('admin', 'pw_life_duration', '0'), |
|
537
|
|
|
array('admin', 'maintenance_mode', '1'), |
|
538
|
|
|
array('admin', 'enable_sts', '0'), |
|
539
|
|
|
array('admin', 'encryptClientServer', '1'), |
|
540
|
|
|
array('admin', 'teampass_version', TP_VERSION), |
|
541
|
|
|
array('admin', 'ldap_mode', '0'), |
|
542
|
|
|
array('admin', 'ldap_type', '0'), |
|
543
|
|
|
array('admin', 'ldap_suffix', '0'), |
|
544
|
|
|
array('admin', 'ldap_domain_dn', '0'), |
|
545
|
|
|
array('admin', 'ldap_domain_controler', '0'), |
|
546
|
|
|
array('admin', 'ldap_user_attribute', '0'), |
|
547
|
|
|
array('admin', 'ldap_ssl', '0'), |
|
548
|
|
|
array('admin', 'ldap_tls', '0'), |
|
549
|
|
|
array('admin', 'ldap_search_base', '0'), |
|
550
|
|
|
array('admin', 'ldap_port', '389'), |
|
551
|
|
|
array('admin', 'richtext', '0'), |
|
552
|
|
|
array('admin', 'allow_print', '0'), |
|
553
|
|
|
array('admin', 'roles_allowed_to_print', '0'), |
|
554
|
|
|
array('admin', 'show_description', '1'), |
|
555
|
|
|
array('admin', 'anyone_can_modify', '0'), |
|
556
|
|
|
array('admin', 'anyone_can_modify_bydefault', '0'), |
|
557
|
|
|
array('admin', 'nb_bad_authentication', '0'), |
|
558
|
|
|
array('admin', 'utf8_enabled', '1'), |
|
559
|
|
|
array('admin', 'restricted_to', '0'), |
|
560
|
|
|
array('admin', 'restricted_to_roles', '0'), |
|
561
|
|
|
array('admin', 'enable_send_email_on_user_login', '0'), |
|
562
|
|
|
array('admin', 'enable_user_can_create_folders', '0'), |
|
563
|
|
|
array('admin', 'insert_manual_entry_item_history', '0'), |
|
564
|
|
|
array('admin', 'enable_kb', '0'), |
|
565
|
|
|
array('admin', 'enable_email_notification_on_item_shown', '0'), |
|
566
|
|
|
array('admin', 'enable_email_notification_on_user_pw_change', '0'), |
|
567
|
|
|
array('admin', 'custom_logo', ''), |
|
568
|
|
|
array('admin', 'custom_login_text', ''), |
|
569
|
|
|
array('admin', 'default_language', 'english'), |
|
570
|
|
|
array('admin', 'send_stats', '0'), |
|
571
|
|
|
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;'), |
|
572
|
|
|
array('admin', 'send_stats_time', time() - 2592000), |
|
573
|
|
|
array('admin', 'get_tp_info', '1'), |
|
574
|
|
|
array('admin', 'send_mail_on_user_login', '0'), |
|
575
|
|
|
array('cron', 'sending_emails', '0'), |
|
576
|
|
|
array('admin', 'nb_items_by_query', 'auto'), |
|
577
|
|
|
array('admin', 'enable_delete_after_consultation', '0'), |
|
578
|
|
|
array('admin', 'enable_personal_saltkey_cookie', '0'), |
|
579
|
|
|
array('admin', 'personal_saltkey_cookie_duration', '31'), |
|
580
|
|
|
array('admin', 'email_smtp_server', ''), |
|
581
|
|
|
array('admin', 'email_smtp_auth', ''), |
|
582
|
|
|
array('admin', 'email_auth_username', ''), |
|
583
|
|
|
array('admin', 'email_auth_pwd', ''), |
|
584
|
|
|
array('admin', 'email_port', ''), |
|
585
|
|
|
array('admin', 'email_security', ''), |
|
586
|
|
|
array('admin', 'email_server_url', ''), |
|
587
|
|
|
array('admin', 'email_from', ''), |
|
588
|
|
|
array('admin', 'email_from_name', ''), |
|
589
|
|
|
array('admin', 'pwd_maximum_length', '40'), |
|
590
|
|
|
array('admin', 'google_authentication', '0'), |
|
591
|
|
|
array('admin', 'delay_item_edition', '0'), |
|
592
|
|
|
array('admin', 'allow_import', '0'), |
|
593
|
|
|
array('admin', 'proxy_ip', ''), |
|
594
|
|
|
array('admin', 'proxy_port', ''), |
|
595
|
|
|
array('admin', 'upload_maxfilesize', '10mb'), |
|
596
|
|
|
array('admin', 'upload_docext', 'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx'), |
|
597
|
|
|
array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png'), |
|
598
|
|
|
array('admin', 'upload_pkgext', '7z,rar,tar,zip'), |
|
599
|
|
|
array('admin', 'upload_otherext', 'sql,xml'), |
|
600
|
|
|
array('admin', 'upload_imageresize_options', '1'), |
|
601
|
|
|
array('admin', 'upload_imageresize_width', '800'), |
|
602
|
|
|
array('admin', 'upload_imageresize_height', '600'), |
|
603
|
|
|
array('admin', 'upload_imageresize_quality', '90'), |
|
604
|
|
|
array('admin', 'use_md5_password_as_salt', '0'), |
|
605
|
|
|
array('admin', 'ga_website_name', 'TeamPass for ChangeMe'), |
|
606
|
|
|
array('admin', 'api', '0'), |
|
607
|
|
|
array('admin', 'subfolder_rights_as_parent', '0'), |
|
608
|
|
|
array('admin', 'show_only_accessible_folders', '0'), |
|
609
|
|
|
array('admin', 'enable_suggestion', '0'), |
|
610
|
|
|
array('admin', 'otv_expiration_period', '7'), |
|
611
|
|
|
array('admin', 'default_session_expiration_time', '60'), |
|
612
|
|
|
array('admin', 'duo', '0'), |
|
613
|
|
|
array('admin', 'enable_server_password_change', '0'), |
|
614
|
|
|
array('admin', 'ldap_object_class', '0'), |
|
615
|
|
|
array('admin', 'bck_script_path', $var['absolute_path'] . '/backups'), |
|
616
|
|
|
array('admin', 'bck_script_filename', 'bck_teampass'), |
|
617
|
|
|
array('admin', 'syslog_enable', '0'), |
|
618
|
|
|
array('admin', 'syslog_host', 'localhost'), |
|
619
|
|
|
array('admin', 'syslog_port', '514'), |
|
620
|
|
|
array('admin', 'manager_move_item', '0'), |
|
621
|
|
|
array('admin', 'create_item_without_password', '0'), |
|
622
|
|
|
array('admin', 'otv_is_enabled', '0'), |
|
623
|
|
|
array('admin', 'agses_authentication_enabled', '0'), |
|
624
|
|
|
array('admin', 'item_extra_fields', '0'), |
|
625
|
|
|
array('admin', 'saltkey_ante_2127', 'none'), |
|
626
|
|
|
array('admin', 'migration_to_2127', 'done'), |
|
627
|
|
|
array('admin', 'files_with_defuse', 'done'), |
|
628
|
|
|
array('admin', 'timezone', 'UTC'), |
|
629
|
|
|
array('admin', 'enable_attachment_encryption', '1'), |
|
630
|
|
|
array('admin', 'personal_saltkey_security_level', '50'), |
|
631
|
|
|
array('admin', 'ldap_new_user_is_administrated_by', '0'), |
|
632
|
|
|
array('admin', 'disable_show_forgot_pwd_link', '0'), |
|
633
|
|
|
array('admin', 'offline_key_level', '0'), |
|
634
|
|
|
array('admin', 'enable_http_request_login', '0'), |
|
635
|
|
|
array('admin', 'ldap_and_local_authentication', '0'), |
|
636
|
|
|
array('admin', 'secure_display_image', '1'), |
|
637
|
|
|
array('admin', 'upload_zero_byte_file', '0'), |
|
638
|
|
|
array('admin', 'upload_all_extensions_file', '0'), |
|
639
|
|
|
array('admin', 'bck_script_passkey', generateRandomKey()), |
|
640
|
|
|
array('admin', 'admin_2fa_required', '1'), |
|
641
|
|
|
array('admin', 'password_overview_delay', '4'), |
|
642
|
|
|
array('admin', 'copy_to_clipboard_small_icons', '1'), |
|
643
|
|
|
array('admin', 'duo_ikey', ''), |
|
644
|
|
|
array('admin', 'duo_skey', ''), |
|
645
|
|
|
array('admin', 'duo_host', ''), |
|
646
|
|
|
array('admin', 'duo_failmode', 'secure'), |
|
647
|
|
|
array('admin', 'roles_allowed_to_print_select', ''), |
|
648
|
|
|
array('admin', 'clipboard_life_duration', '30'), |
|
649
|
|
|
array('admin', 'mfa_for_roles', ''), |
|
650
|
|
|
array('admin', 'tree_counters', '0'), |
|
651
|
|
|
array('admin', 'settings_offline_mode', '0'), |
|
652
|
|
|
array('admin', 'settings_tree_counters', '0'), |
|
653
|
|
|
array('admin', 'enable_massive_move_delete', '0'), |
|
654
|
|
|
array('admin', 'email_debug_level', '0'), |
|
655
|
|
|
array('admin', 'ga_reset_by_user', ''), |
|
656
|
|
|
array('admin', 'onthefly-backup-key', ''), |
|
657
|
|
|
array('admin', 'onthefly-restore-key', ''), |
|
658
|
|
|
array('admin', 'ldap_user_dn_attribute', ''), |
|
659
|
|
|
array('admin', 'ldap_dn_additional_user_dn', ''), |
|
660
|
|
|
array('admin', 'ldap_user_object_filter', ''), |
|
661
|
|
|
array('admin', 'ldap_bdn', ''), |
|
662
|
|
|
array('admin', 'ldap_hosts', ''), |
|
663
|
|
|
array('admin', 'ldap_password', ''), |
|
664
|
|
|
array('admin', 'ldap_username', ''), |
|
665
|
|
|
array('admin', 'api_token_duration', '60'), |
|
666
|
|
|
array('timestamp', 'last_folder_change', ''), |
|
667
|
|
|
array('admin', 'enable_tasks_manager', '1'), |
|
668
|
|
|
array('admin', 'task_maximum_run_time', '300'), |
|
669
|
|
|
array('admin', 'tasks_manager_refreshing_period', '20'), |
|
670
|
|
|
array('admin', 'maximum_number_of_items_to_treat', '100'), |
|
671
|
|
|
array('admin', 'ldap_tls_certifacte_check', 'LDAP_OPT_X_TLS_NEVER'), |
|
672
|
|
|
array('admin', 'enable_tasks_log', '0'), |
|
673
|
|
|
array('admin', 'upgrade_timestamp', time()), |
|
674
|
|
|
array('admin', 'enable_ad_users_with_ad_groups', '0'), |
|
675
|
|
|
array('admin', 'enable_ad_user_auto_creation', '0'), |
|
676
|
|
|
array('admin', 'ldap_group_object_filter', ''), |
|
677
|
|
|
array('admin', 'ldap_guid_attibute', 'objectguid'), |
|
678
|
|
|
array('admin', 'sending_emails_job_frequency', '2'), |
|
679
|
|
|
array('admin', 'user_keys_job_frequency', '1'), |
|
680
|
|
|
array('admin', 'items_statistics_job_frequency', '5'), |
|
681
|
|
|
array('admin', 'users_personal_folder_task', ''), |
|
682
|
|
|
array('admin', 'clean_orphan_objects_task', ''), |
|
683
|
|
|
array('admin', 'purge_temporary_files_task', ''), |
|
684
|
|
|
array('admin', 'rebuild_config_file', ''), |
|
685
|
|
|
array('admin', 'reload_cache_table_task', ''), |
|
686
|
|
|
array('admin', 'maximum_session_expiration_time', '60'), |
|
687
|
|
|
array('admin', 'items_ops_job_frequency', '1'), |
|
688
|
|
|
array('admin', 'enable_refresh_task_last_execution', '1'), |
|
689
|
|
|
); |
|
690
|
|
|
foreach ($aMiscVal as $elem) { |
|
691
|
|
|
//Check if exists before inserting |
|
692
|
|
|
$tmp = mysqli_num_rows( |
|
693
|
|
|
mysqli_query( |
|
694
|
|
|
$dbTmp, |
|
695
|
|
|
"SELECT * FROM `" . $var['tbl_prefix'] . "misc` |
|
696
|
|
|
WHERE type='" . $elem[0] . "' AND intitule='" . $elem[1] . "'" |
|
697
|
|
|
) |
|
698
|
|
|
); |
|
699
|
|
|
if (intval($tmp) === 0) { |
|
700
|
|
|
$queryRes = mysqli_query( |
|
701
|
|
|
$dbTmp, |
|
702
|
|
|
"INSERT INTO `" . $var['tbl_prefix'] . "misc` |
|
703
|
|
|
(`type`, `intitule`, `valeur`) VALUES |
|
704
|
|
|
('" . $elem[0] . "', '" . $elem[1] . "', '" . |
|
705
|
|
|
str_replace("'", '', $elem[2]) . "');" |
|
706
|
|
|
); // or die(mysqli_error($dbTmp)) |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
// append new setting in config file |
|
710
|
|
|
$config_text .= " |
|
711
|
|
|
'" . $elem[1] . "' => '" . str_replace("'", '', $elem[2]) . "',"; |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
// write to config file |
|
715
|
|
|
$result = fwrite( |
|
716
|
|
|
$file_handler, |
|
717
|
|
|
utf8_encode( |
|
718
|
|
|
$config_text . ' |
|
719
|
|
|
);' |
|
720
|
|
|
) |
|
721
|
|
|
); |
|
722
|
|
|
fclose($file_handler); |
|
723
|
|
|
|
|
724
|
|
|
// -- |
|
725
|
|
|
} elseif ($task === 'nested_tree') { |
|
726
|
|
|
$mysqli_result = mysqli_query( |
|
727
|
|
|
$dbTmp, |
|
728
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "nested_tree` ( |
|
729
|
|
|
`id` bigint(20) unsigned NOT null AUTO_INCREMENT, |
|
730
|
|
|
`parent_id` int(11) NOT NULL, |
|
731
|
|
|
`title` varchar(255) NOT NULL, |
|
732
|
|
|
`nleft` int(11) NOT NULL DEFAULT '0', |
|
733
|
|
|
`nright` int(11) NOT NULL DEFAULT '0', |
|
734
|
|
|
`nlevel` int(11) NOT NULL DEFAULT '0', |
|
735
|
|
|
`bloquer_creation` tinyint(1) NOT null DEFAULT '0', |
|
736
|
|
|
`bloquer_modification` tinyint(1) NOT null DEFAULT '0', |
|
737
|
|
|
`personal_folder` tinyint(1) NOT null DEFAULT '0', |
|
738
|
|
|
`renewal_period` int(5) NOT null DEFAULT '0', |
|
739
|
|
|
`fa_icon` VARCHAR(100) NOT NULL DEFAULT 'fas fa-folder', |
|
740
|
|
|
`fa_icon_selected` VARCHAR(100) NOT NULL DEFAULT 'fas fa-folder-open', |
|
741
|
|
|
`categories` longtext NOT NULL, |
|
742
|
|
|
`nb_items_in_folder` int(10) NOT NULL DEFAULT '0', |
|
743
|
|
|
`nb_subfolders` int(10) NOT NULL DEFAULT '0', |
|
744
|
|
|
`nb_items_in_subfolders` int(10) NOT NULL DEFAULT '0', |
|
745
|
|
|
PRIMARY KEY (`id`), |
|
746
|
|
|
KEY `nested_tree_parent_id` (`parent_id`), |
|
747
|
|
|
KEY `nested_tree_nleft` (`nleft`), |
|
748
|
|
|
KEY `nested_tree_nright` (`nright`), |
|
749
|
|
|
KEY `nested_tree_nlevel` (`nlevel`), |
|
750
|
|
|
KEY `personal_folder_idx` (`personal_folder`) |
|
751
|
|
|
) CHARSET=utf8;" |
|
752
|
|
|
); |
|
753
|
|
|
} elseif ($task === 'rights') { |
|
754
|
|
|
$mysqli_result = mysqli_query( |
|
755
|
|
|
$dbTmp, |
|
756
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "rights` ( |
|
757
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
758
|
|
|
`tree_id` int(12) NOT NULL, |
|
759
|
|
|
`fonction_id` int(12) NOT NULL, |
|
760
|
|
|
`authorized` tinyint(1) NOT null DEFAULT '0', |
|
761
|
|
|
PRIMARY KEY (`id`) |
|
762
|
|
|
) CHARSET=utf8;" |
|
763
|
|
|
); |
|
764
|
|
|
} elseif ($task === 'users') { |
|
765
|
|
|
$mysqli_result = mysqli_query( |
|
766
|
|
|
$dbTmp, |
|
767
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "users` ( |
|
768
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
769
|
|
|
`login` varchar(500) NOT NULL, |
|
770
|
|
|
`pw` varchar(400) NOT NULL, |
|
771
|
|
|
`groupes_visibles` varchar(1000) NOT NULL, |
|
772
|
|
|
`derniers` text NULL DEFAULT NULL, |
|
773
|
|
|
`key_tempo` varchar(100) NULL DEFAULT NULL, |
|
774
|
|
|
`last_pw_change` varchar(30) NULL DEFAULT NULL, |
|
775
|
|
|
`last_pw` text NULL DEFAULT NULL, |
|
776
|
|
|
`admin` tinyint(1) NOT null DEFAULT '0', |
|
777
|
|
|
`fonction_id` varchar(1000) NULL DEFAULT NULL, |
|
778
|
|
|
`groupes_interdits` varchar(1000) NULL DEFAULT NULL, |
|
779
|
|
|
`last_connexion` varchar(30) NULL DEFAULT NULL, |
|
780
|
|
|
`gestionnaire` int(11) NOT null DEFAULT '0', |
|
781
|
|
|
`email` varchar(300) NOT NULL DEFAULT 'none', |
|
782
|
|
|
`favourites` varchar(1000) NULL DEFAULT NULL, |
|
783
|
|
|
`latest_items` varchar(1000) NULL DEFAULT NULL, |
|
784
|
|
|
`personal_folder` int(1) NOT null DEFAULT '0', |
|
785
|
|
|
`disabled` tinyint(1) NOT null DEFAULT '0', |
|
786
|
|
|
`no_bad_attempts` tinyint(1) NOT null DEFAULT '0', |
|
787
|
|
|
`can_create_root_folder` tinyint(1) NOT null DEFAULT '0', |
|
788
|
|
|
`read_only` tinyint(1) NOT null DEFAULT '0', |
|
789
|
|
|
`timestamp` varchar(30) NOT null DEFAULT '0', |
|
790
|
|
|
`user_language` varchar(50) NOT null DEFAULT '0', |
|
791
|
|
|
`name` varchar(100) NULL DEFAULT NULL, |
|
792
|
|
|
`lastname` varchar(100) NULL DEFAULT NULL, |
|
793
|
|
|
`session_end` varchar(30) NULL DEFAULT NULL, |
|
794
|
|
|
`isAdministratedByRole` tinyint(5) NOT null DEFAULT '0', |
|
795
|
|
|
`psk` varchar(400) NULL DEFAULT NULL, |
|
796
|
|
|
`ga` varchar(50) NULL DEFAULT NULL, |
|
797
|
|
|
`ga_temporary_code` VARCHAR(20) NOT NULL DEFAULT 'none', |
|
798
|
|
|
`avatar` varchar(1000) NULL DEFAULT NULL, |
|
799
|
|
|
`avatar_thumb` varchar(1000) NULL DEFAULT NULL, |
|
800
|
|
|
`upgrade_needed` BOOLEAN NOT NULL DEFAULT FALSE, |
|
801
|
|
|
`treeloadstrategy` varchar(30) NOT null DEFAULT 'full', |
|
802
|
|
|
`can_manage_all_users` tinyint(1) NOT NULL DEFAULT '0', |
|
803
|
|
|
`usertimezone` VARCHAR(50) NOT NULL DEFAULT 'not_defined', |
|
804
|
|
|
`agses-usercardid` VARCHAR(50) NOT NULL DEFAULT '0', |
|
805
|
|
|
`encrypted_psk` text NULL DEFAULT NULL, |
|
806
|
|
|
`user_ip` varchar(400) NOT null DEFAULT 'none', |
|
807
|
|
|
`user_ip_lastdate` varchar(50) NULL DEFAULT NULL, |
|
808
|
|
|
`yubico_user_key` varchar(100) NOT null DEFAULT 'none', |
|
809
|
|
|
`yubico_user_id` varchar(100) NOT null DEFAULT 'none', |
|
810
|
|
|
`public_key` TEXT NULL DEFAULT NULL, |
|
811
|
|
|
`private_key` TEXT NULL DEFAULT NULL, |
|
812
|
|
|
`special` VARCHAR(250) NOT NULL DEFAULT 'none', |
|
813
|
|
|
`auth_type` VARCHAR(200) NOT NULL DEFAULT 'local', |
|
814
|
|
|
`is_ready_for_usage` BOOLEAN NOT NULL DEFAULT FALSE, |
|
815
|
|
|
`otp_provided` BOOLEAN NOT NULL DEFAULT FALSE, |
|
816
|
|
|
`roles_from_ad_groups` varchar(1000) NULL DEFAULT NULL, |
|
817
|
|
|
`ongoing_process_id` VARCHAR(100) NULL DEFAULT NULL, |
|
818
|
|
|
`mfa_enabled` tinyint(1) NOT null DEFAULT '1', |
|
819
|
|
|
`created_at` varchar(30) NULL DEFAULT NULL, |
|
820
|
|
|
`updated_at` varchar(30) NULL DEFAULT NULL, |
|
821
|
|
|
`deleted_at` varchar(30) NULL DEFAULT NULL, |
|
822
|
|
|
`keys_recovery_time` VARCHAR(500) NULL DEFAULT NULL, |
|
823
|
|
|
`aes_iv` TEXT NULL DEFAULT NULL, |
|
824
|
|
|
PRIMARY KEY (`id`), |
|
825
|
|
|
UNIQUE KEY `login` (`login`) |
|
826
|
|
|
) CHARSET=utf8;" |
|
827
|
|
|
); |
|
828
|
|
|
|
|
829
|
|
|
require_once '../includes/config/include.php'; |
|
830
|
|
|
// check that admin accounts doesn't exist |
|
831
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `" . $var['tbl_prefix'] . "users` WHERE login = 'admin'")); |
|
832
|
|
|
if ($tmp === 0) { |
|
833
|
|
|
$mysqli_result = mysqli_query( |
|
834
|
|
|
$dbTmp, |
|
835
|
|
|
"INSERT INTO `" . $var['tbl_prefix'] . "users` (`id`, `login`, `pw`, `admin`, `gestionnaire`, `personal_folder`, `groupes_visibles`, `email`, `encrypted_psk`, `last_pw_change`, `name`, `lastname`, `can_create_root_folder`, `public_key`, `private_key`, `is_ready_for_usage`, `otp_provided`) VALUES ('1', 'admin', '" . bCrypt($var['admin_pwd'], '13') . "', '1', '0', '0', '0', '" . $var['admin_email'] . "', '', '" . time() . "', 'Change me', 'Change me', '1', 'none', 'none', '1', '1')" |
|
836
|
|
|
); |
|
837
|
|
|
} else { |
|
838
|
|
|
$mysqli_result = mysqli_query($dbTmp, 'UPDATE `' . $var['tbl_prefix'] . "users` SET `pw` = '" . bCrypt($var['admin_pwd'], '13') . "' WHERE login = 'admin' AND id = '1'"); |
|
839
|
|
|
} |
|
840
|
|
|
|
|
841
|
|
|
// check that API doesn't exist |
|
842
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `" . $var['tbl_prefix'] . "users` WHERE id = '" . API_USER_ID . "'")); |
|
843
|
|
|
if ($tmp === 0) { |
|
844
|
|
|
$mysqli_result = mysqli_query( |
|
845
|
|
|
$dbTmp, |
|
846
|
|
|
"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`, `is_ready_for_usage`, `otp_provided`) VALUES ('" . API_USER_ID . "', 'API', '', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0', '0', '1')" |
|
847
|
|
|
); |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
// check that OTV doesn't exist |
|
851
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `" . $var['tbl_prefix'] . "users` WHERE id = '" . OTV_USER_ID . "'")); |
|
852
|
|
|
if ($tmp === 0) { |
|
853
|
|
|
$mysqli_result = mysqli_query( |
|
854
|
|
|
$dbTmp, |
|
855
|
|
|
"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`, `is_ready_for_usage`, `otp_provided`) VALUES ('" . OTV_USER_ID . "', 'OTV', '', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0', '0', '1')" |
|
856
|
|
|
); |
|
857
|
|
|
} |
|
858
|
|
|
} elseif ($task === 'tags') { |
|
859
|
|
|
$mysqli_result = mysqli_query( |
|
860
|
|
|
$dbTmp, |
|
861
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'tags` ( |
|
862
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
863
|
|
|
`tag` varchar(30) NOT NULL, |
|
864
|
|
|
`item_id` int(12) NOT NULL, |
|
865
|
|
|
PRIMARY KEY (`id`) |
|
866
|
|
|
) CHARSET=utf8;' |
|
867
|
|
|
); |
|
868
|
|
|
} elseif ($task === 'log_system') { |
|
869
|
|
|
$mysqli_result = mysqli_query( |
|
870
|
|
|
$dbTmp, |
|
871
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'log_system` ( |
|
872
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
873
|
|
|
`type` varchar(20) NOT NULL, |
|
874
|
|
|
`date` varchar(30) NOT NULL, |
|
875
|
|
|
`label` text NOT NULL, |
|
876
|
|
|
`qui` varchar(255) NOT NULL, |
|
877
|
|
|
`field_1` varchar(250) DEFAULT NULL, |
|
878
|
|
|
PRIMARY KEY (`id`) |
|
879
|
|
|
) CHARSET=utf8;' |
|
880
|
|
|
); |
|
881
|
|
|
} elseif ($task === 'files') { |
|
882
|
|
|
$mysqli_result = mysqli_query( |
|
883
|
|
|
$dbTmp, |
|
884
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "files` ( |
|
885
|
|
|
`id` int(11) NOT null AUTO_INCREMENT, |
|
886
|
|
|
`id_item` int(11) NOT NULL, |
|
887
|
|
|
`name` TEXT NOT NULL, |
|
888
|
|
|
`size` int(10) NOT NULL, |
|
889
|
|
|
`extension` varchar(10) NOT NULL, |
|
890
|
|
|
`type` varchar(255) NOT NULL, |
|
891
|
|
|
`file` varchar(50) NOT NULL, |
|
892
|
|
|
`status` varchar(50) NOT NULL DEFAULT '0', |
|
893
|
|
|
`content` longblob DEFAULT NULL, |
|
894
|
|
|
`confirmed` INT(1) NOT NULL DEFAULT '0', |
|
895
|
|
|
PRIMARY KEY (`id`) |
|
896
|
|
|
) CHARSET=utf8;" |
|
897
|
|
|
); |
|
898
|
|
|
} elseif ($task === 'cache') { |
|
899
|
|
|
$mysqli_result = mysqli_query( |
|
900
|
|
|
$dbTmp, |
|
901
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "cache` ( |
|
902
|
|
|
`increment_id`INT(12) NOT NULL AUTO_INCREMENT, |
|
903
|
|
|
`id` int(12) NOT NULL, |
|
904
|
|
|
`label` varchar(500) NOT NULL, |
|
905
|
|
|
`description` MEDIUMTEXT NULL DEFAULT NULL, |
|
906
|
|
|
`tags` text DEFAULT NULL, |
|
907
|
|
|
`id_tree` int(12) NOT NULL, |
|
908
|
|
|
`perso` tinyint(1) NOT NULL, |
|
909
|
|
|
`restricted_to` varchar(200) DEFAULT NULL, |
|
910
|
|
|
`login` text DEFAULT NULL, |
|
911
|
|
|
`folder` text NOT NULL, |
|
912
|
|
|
`author` varchar(50) NOT NULL, |
|
913
|
|
|
`renewal_period` tinyint(4) NOT NULL DEFAULT '0', |
|
914
|
|
|
`timestamp` varchar(50) DEFAULT NULL, |
|
915
|
|
|
`url` text NULL DEFAULT NULL, |
|
916
|
|
|
`encryption_type` VARCHAR(50) DEFAULT NULL DEFAULT '0', |
|
917
|
|
|
PRIMARY KEY (`increment_id`) |
|
918
|
|
|
) CHARSET=utf8;" |
|
919
|
|
|
); |
|
920
|
|
|
} elseif ($task === 'roles_title') { |
|
921
|
|
|
$mysqli_result = mysqli_query( |
|
922
|
|
|
$dbTmp, |
|
923
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "roles_title` ( |
|
924
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
925
|
|
|
`title` varchar(50) NOT NULL, |
|
926
|
|
|
`allow_pw_change` TINYINT(1) NOT null DEFAULT '0', |
|
927
|
|
|
`complexity` INT(5) NOT null DEFAULT '0', |
|
928
|
|
|
`creator_id` int(11) NOT null DEFAULT '0', |
|
929
|
|
|
PRIMARY KEY (`id`) |
|
930
|
|
|
) CHARSET=utf8;" |
|
931
|
|
|
); |
|
932
|
|
|
|
|
933
|
|
|
// create Default role |
|
934
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `" . $var['tbl_prefix'] . "roles_title` WHERE id = '0'")); |
|
935
|
|
|
if ($tmp === 0) { |
|
936
|
|
|
$mysqli_result = mysqli_query( |
|
937
|
|
|
$dbTmp, |
|
938
|
|
|
"INSERT INTO `" . $var['tbl_prefix'] . "roles_title` (`id`, `title`, `allow_pw_change`, `complexity`, `creator_id`) VALUES (NULL, 'Default', '0', '48', '0')" |
|
939
|
|
|
); |
|
940
|
|
|
} |
|
941
|
|
|
} elseif ($task === 'roles_values') { |
|
942
|
|
|
$mysqli_result = mysqli_query( |
|
943
|
|
|
$dbTmp, |
|
944
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "roles_values` ( |
|
945
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT PRIMARY KEY, |
|
946
|
|
|
`role_id` int(12) NOT NULL, |
|
947
|
|
|
`folder_id` int(12) NOT NULL, |
|
948
|
|
|
`type` varchar(5) NOT NULL DEFAULT 'R', |
|
949
|
|
|
KEY `role_id_idx` (`role_id`) |
|
950
|
|
|
) CHARSET=utf8;" |
|
951
|
|
|
); |
|
952
|
|
|
} elseif ($task === 'kb') { |
|
953
|
|
|
$mysqli_result = mysqli_query( |
|
954
|
|
|
$dbTmp, |
|
955
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "kb` ( |
|
956
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
957
|
|
|
`category_id` int(12) NOT NULL, |
|
958
|
|
|
`label` varchar(200) NOT NULL, |
|
959
|
|
|
`description` text NOT NULL, |
|
960
|
|
|
`author_id` int(12) NOT NULL, |
|
961
|
|
|
`anyone_can_modify` tinyint(1) NOT null DEFAULT '0', |
|
962
|
|
|
PRIMARY KEY (`id`) |
|
963
|
|
|
) CHARSET=utf8;" |
|
964
|
|
|
); |
|
965
|
|
|
} elseif ($task === 'kb_categories') { |
|
966
|
|
|
$mysqli_result = mysqli_query( |
|
967
|
|
|
$dbTmp, |
|
968
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'kb_categories` ( |
|
969
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
|
970
|
|
|
`category` varchar(50) NOT NULL, |
|
971
|
|
|
PRIMARY KEY (`id`) |
|
972
|
|
|
) CHARSET=utf8;' |
|
973
|
|
|
); |
|
974
|
|
|
} elseif ($task === 'kb_items') { |
|
975
|
|
|
$mysqli_result = mysqli_query( |
|
976
|
|
|
$dbTmp, |
|
977
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'kb_items` ( |
|
978
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
979
|
|
|
`kb_id` int(12) NOT NULL, |
|
980
|
|
|
`item_id` int(12) NOT NULL, |
|
981
|
|
|
PRIMARY KEY (`increment_id`) |
|
982
|
|
|
) CHARSET=utf8;' |
|
983
|
|
|
); |
|
984
|
|
|
} elseif ($task == 'restriction_to_roles') { |
|
985
|
|
|
$mysqli_result = mysqli_query( |
|
986
|
|
|
$dbTmp, |
|
987
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'restriction_to_roles` ( |
|
988
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
989
|
|
|
`role_id` int(12) NOT NULL, |
|
990
|
|
|
`item_id` int(12) NOT NULL, |
|
991
|
|
|
PRIMARY KEY (`increment_id`) |
|
992
|
|
|
) CHARSET=utf8;' |
|
993
|
|
|
); |
|
994
|
|
|
} elseif ($task === 'languages') { |
|
995
|
|
|
$mysqli_result = mysqli_query( |
|
996
|
|
|
$dbTmp, |
|
997
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'languages` ( |
|
998
|
|
|
`id` INT(10) NOT null AUTO_INCREMENT, |
|
999
|
|
|
`name` VARCHAR(50) NOT null , |
|
1000
|
|
|
`label` VARCHAR(50) NOT null , |
|
1001
|
|
|
`code` VARCHAR(10) NOT null , |
|
1002
|
|
|
`flag` VARCHAR(50) NOT NULL, |
|
1003
|
|
|
`code_poeditor` VARCHAR(30) NOT NULL, |
|
1004
|
|
|
PRIMARY KEY (`id`) |
|
1005
|
|
|
) CHARSET=utf8;' |
|
1006
|
|
|
); |
|
1007
|
|
|
|
|
1008
|
|
|
// add lanaguages |
|
1009
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `" . $var['tbl_prefix'] . "languages` WHERE name = 'french'")); |
|
1010
|
|
|
if ($tmp === 0) { |
|
1011
|
|
|
$mysql_result = mysqli_query( |
|
1012
|
|
|
$dbTmp, |
|
1013
|
|
|
"INSERT INTO `" . $var['tbl_prefix'] . "languages` (`id`, `name`, `label`, `code`, `flag`, `code_poeditor`) VALUES |
|
1014
|
|
|
(1, 'french', 'French', 'fr', 'fr.png', 'fr'), |
|
1015
|
|
|
(2, 'english', 'English', 'us', 'us.png', 'en'), |
|
1016
|
|
|
(3, 'spanish', 'Spanish', 'es', 'es.png', 'es'), |
|
1017
|
|
|
(4, 'german', 'German', 'de', 'de.png', 'de'), |
|
1018
|
|
|
(5, 'czech', 'Czech', 'cs', 'cz.png', 'cs'), |
|
1019
|
|
|
(6, 'italian', 'Italian', 'it', 'it.png', 'it'), |
|
1020
|
|
|
(7, 'russian', 'Russian', 'ru', 'ru.png', 'ru'), |
|
1021
|
|
|
(8, 'turkish', 'Turkish', 'tr', 'tr.png', 'tr'), |
|
1022
|
|
|
(9, 'norwegian', 'Norwegian', 'no', 'no.png', 'no'), |
|
1023
|
|
|
(10, 'japanese', 'Japanese', 'ja', 'ja.png', 'ja'), |
|
1024
|
|
|
(11, 'portuguese', 'Portuguese', 'pr', 'pr.png', 'pt'), |
|
1025
|
|
|
(12, 'portuguese_br', 'Portuguese (Brazil)', 'pr-bt', 'pr-bt.png', 'pt-br'), |
|
1026
|
|
|
(13, 'chinese', 'Chinese', 'zh-Hans', 'cn.png', 'zh-Hans'), |
|
1027
|
|
|
(14, 'swedish', 'Swedish', 'se', 'se.png', 'sv'), |
|
1028
|
|
|
(15, 'dutch', 'Dutch', 'nl', 'nl.png', 'nl'), |
|
1029
|
|
|
(16, 'catalan', 'Catalan', 'ca', 'ct.png', 'ca'), |
|
1030
|
|
|
(17, 'bulgarian', 'Bulgarian', 'bg', 'bg.png', 'bg'), |
|
1031
|
|
|
(18, 'greek', 'Greek', 'gr', 'gr.png', 'el'), |
|
1032
|
|
|
(19, 'hungarian', 'Hungarian', 'hu', 'hu.png', 'hu'), |
|
1033
|
|
|
(20, 'polish', 'Polish', 'pl', 'pl.png', 'pl'), |
|
1034
|
|
|
(21, 'romanian', 'Romanian', 'ro', 'ro.png', 'ro'), |
|
1035
|
|
|
(22, 'ukrainian', 'Ukrainian', 'ua', 'ua.png', 'uk'), |
|
1036
|
|
|
(23, 'vietnamese', 'Vietnamese', 'vi', 'vi.png', 'vi'), |
|
1037
|
|
|
(24, 'estonian', 'Estonian', 'et', 'ee.png', 'et');" |
|
1038
|
|
|
); |
|
1039
|
|
|
} |
|
1040
|
|
|
} elseif ($task === 'emails') { |
|
1041
|
|
|
$mysqli_result = mysqli_query( |
|
1042
|
|
|
$dbTmp, |
|
1043
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'emails` ( |
|
1044
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1045
|
|
|
`timestamp` INT(30) NOT null , |
|
1046
|
|
|
`subject` TEXT NOT null , |
|
1047
|
|
|
`body` TEXT NOT null , |
|
1048
|
|
|
`receivers` TEXT NOT null , |
|
1049
|
|
|
`status` VARCHAR(30) NOT NULL, |
|
1050
|
|
|
PRIMARY KEY (`increment_id`) |
|
1051
|
|
|
) CHARSET=utf8;' |
|
1052
|
|
|
); |
|
1053
|
|
|
} elseif ($task === 'automatic_del') { |
|
1054
|
|
|
$mysqli_result = mysqli_query( |
|
1055
|
|
|
$dbTmp, |
|
1056
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'automatic_del` ( |
|
1057
|
|
|
`item_id` int(11) NOT NULL, |
|
1058
|
|
|
`del_enabled` tinyint(1) NOT NULL, |
|
1059
|
|
|
`del_type` tinyint(1) NOT NULL, |
|
1060
|
|
|
`del_value` varchar(35) NOT NULL, |
|
1061
|
|
|
PRIMARY KEY (`item_id`) |
|
1062
|
|
|
) CHARSET=utf8;' |
|
1063
|
|
|
); |
|
1064
|
|
|
} elseif ($task === 'items_edition') { |
|
1065
|
|
|
$mysqli_result = mysqli_query( |
|
1066
|
|
|
$dbTmp, |
|
1067
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'items_edition` ( |
|
1068
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1069
|
|
|
`item_id` int(11) NOT NULL, |
|
1070
|
|
|
`user_id` int(12) NOT NULL, |
|
1071
|
|
|
`timestamp` varchar(50) NOT NULL, |
|
1072
|
|
|
KEY `item_id_idx` (`item_id`), |
|
1073
|
|
|
PRIMARY KEY (`increment_id`) |
|
1074
|
|
|
) CHARSET=utf8;' |
|
1075
|
|
|
); |
|
1076
|
|
|
} elseif ($task === 'categories') { |
|
1077
|
|
|
$mysqli_result = mysqli_query( |
|
1078
|
|
|
$dbTmp, |
|
1079
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "categories` ( |
|
1080
|
|
|
`id` int(12) NOT NULL AUTO_INCREMENT, |
|
1081
|
|
|
`parent_id` int(12) NOT NULL, |
|
1082
|
|
|
`title` varchar(255) NOT NULL, |
|
1083
|
|
|
`level` int(2) NOT NULL, |
|
1084
|
|
|
`description` text NULL, |
|
1085
|
|
|
`type` varchar(50) NULL default '', |
|
1086
|
|
|
`masked` tinyint(1) NOT NULL default '0', |
|
1087
|
|
|
`order` int(12) NOT NULL default '0', |
|
1088
|
|
|
`encrypted_data` tinyint(1) NOT NULL default '1', |
|
1089
|
|
|
`role_visibility` varchar(255) NOT NULL DEFAULT 'all', |
|
1090
|
|
|
`is_mandatory` tinyint(1) NOT NULL DEFAULT '0', |
|
1091
|
|
|
`regex` varchar(255) NULL default '', |
|
1092
|
|
|
PRIMARY KEY (`id`) |
|
1093
|
|
|
) CHARSET=utf8;" |
|
1094
|
|
|
); |
|
1095
|
|
|
} elseif ($task === 'categories_items') { |
|
1096
|
|
|
$mysqli_result = mysqli_query( |
|
1097
|
|
|
$dbTmp, |
|
1098
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "categories_items` ( |
|
1099
|
|
|
`id` int(12) NOT NULL AUTO_INCREMENT, |
|
1100
|
|
|
`field_id` int(11) NOT NULL, |
|
1101
|
|
|
`item_id` int(11) NOT NULL, |
|
1102
|
|
|
`data` text NOT NULL, |
|
1103
|
|
|
`data_iv` text NOT NULL, |
|
1104
|
|
|
`encryption_type` VARCHAR(20) NOT NULL DEFAULT 'not_set', |
|
1105
|
|
|
`is_mandatory` BOOLEAN NOT NULL DEFAULT FALSE , |
|
1106
|
|
|
PRIMARY KEY (`id`) |
|
1107
|
|
|
) CHARSET=utf8;" |
|
1108
|
|
|
); |
|
1109
|
|
|
} elseif ($task === 'categories_folders') { |
|
1110
|
|
|
$mysqli_result = mysqli_query( |
|
1111
|
|
|
$dbTmp, |
|
1112
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'categories_folders` ( |
|
1113
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1114
|
|
|
`id_category` int(12) NOT NULL, |
|
1115
|
|
|
`id_folder` int(12) NOT NULL, |
|
1116
|
|
|
PRIMARY KEY (`increment_id`) |
|
1117
|
|
|
) CHARSET=utf8;' |
|
1118
|
|
|
); |
|
1119
|
|
|
} elseif ($task === 'api') { |
|
1120
|
|
|
$mysqli_result = mysqli_query( |
|
1121
|
|
|
$dbTmp, |
|
1122
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'api` ( |
|
1123
|
|
|
`increment_id` int(20) NOT NULL AUTO_INCREMENT, |
|
1124
|
|
|
`type` varchar(15) NOT NULL, |
|
1125
|
|
|
`label` varchar(255) DEFAULT NULL, |
|
1126
|
|
|
`value` text DEFAULT NULL, |
|
1127
|
|
|
`timestamp` varchar(50) NOT NULL, |
|
1128
|
|
|
`user_id` int(13) DEFAULT NULL, |
|
1129
|
|
|
PRIMARY KEY (`increment_id`), |
|
1130
|
|
|
KEY `USER` (`user_id`) |
|
1131
|
|
|
) CHARSET=utf8;' |
|
1132
|
|
|
); |
|
1133
|
|
|
} elseif ($task === 'otv') { |
|
1134
|
|
|
$mysqli_result = mysqli_query( |
|
1135
|
|
|
$dbTmp, |
|
1136
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "otv` ( |
|
1137
|
|
|
`id` int(10) NOT NULL AUTO_INCREMENT, |
|
1138
|
|
|
`timestamp` text NOT NULL, |
|
1139
|
|
|
`code` varchar(100) NOT NULL, |
|
1140
|
|
|
`item_id` int(12) NOT NULL, |
|
1141
|
|
|
`originator` int(12) NOT NULL, |
|
1142
|
|
|
`encrypted` text NOT NULL, |
|
1143
|
|
|
`views` INT(10) NOT NULL DEFAULT '0', |
|
1144
|
|
|
`max_views` INT(10) NULL DEFAULT NULL, |
|
1145
|
|
|
`time_limit` varchar(100) DEFAULT NULL, |
|
1146
|
|
|
`shared_globaly` INT(1) NOT NULL DEFAULT '0', |
|
1147
|
|
|
PRIMARY KEY (`id`) |
|
1148
|
|
|
) CHARSET=utf8;" |
|
1149
|
|
|
); |
|
1150
|
|
|
} elseif ($task === 'suggestion') { |
|
1151
|
|
|
$mysqli_result = mysqli_query( |
|
1152
|
|
|
$dbTmp, |
|
1153
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "suggestion` ( |
|
1154
|
|
|
`id` tinyint(12) NOT NULL AUTO_INCREMENT, |
|
1155
|
|
|
`label` varchar(255) NOT NULL, |
|
1156
|
|
|
`pw` text NOT NULL, |
|
1157
|
|
|
`pw_iv` text NOT NULL, |
|
1158
|
|
|
`pw_len` int(5) NOT NULL, |
|
1159
|
|
|
`description` text NOT NULL, |
|
1160
|
|
|
`author_id` int(12) NOT NULL, |
|
1161
|
|
|
`folder_id` int(12) NOT NULL, |
|
1162
|
|
|
`comment` text NOT NULL, |
|
1163
|
|
|
`suggestion_type` varchar(10) NOT NULL default 'new', |
|
1164
|
|
|
`encryption_type` varchar(20) NOT NULL default 'not_set', |
|
1165
|
|
|
PRIMARY KEY (`id`) |
|
1166
|
|
|
) CHARSET=utf8;" |
|
1167
|
|
|
); |
|
1168
|
|
|
|
|
1169
|
|
|
$mysqli_result = mysqli_query( |
|
1170
|
|
|
$dbTmp, |
|
1171
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "export` ( |
|
1172
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1173
|
|
|
`export_tag` varchar(20) NOT NULL, |
|
1174
|
|
|
`item_id` int(12) NOT NULL, |
|
1175
|
|
|
`label` varchar(500) NOT NULL, |
|
1176
|
|
|
`login` varchar(100) NOT NULL, |
|
1177
|
|
|
`description` text NOT NULL, |
|
1178
|
|
|
`pw` text NOT NULL, |
|
1179
|
|
|
`path` varchar(500) NOT NULL, |
|
1180
|
|
|
`email` varchar(500) NOT NULL default 'none', |
|
1181
|
|
|
`url` varchar(500) NOT NULL default 'none', |
|
1182
|
|
|
`kbs` varchar(500) NOT NULL default 'none', |
|
1183
|
|
|
`tags` varchar(500) NOT NULL default 'none', |
|
1184
|
|
|
`folder_id` varchar(10) NOT NULL, |
|
1185
|
|
|
`perso` tinyint(1) NOT NULL default '0', |
|
1186
|
|
|
`restricted_to` varchar(200) DEFAULT NULL, |
|
1187
|
|
|
PRIMARY KEY (`increment_id`) |
|
1188
|
|
|
) CHARSET=utf8;" |
|
1189
|
|
|
); |
|
1190
|
|
|
} elseif ($task === 'tokens') { |
|
1191
|
|
|
$mysqli_result = mysqli_query( |
|
1192
|
|
|
$dbTmp, |
|
1193
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'tokens` ( |
|
1194
|
|
|
`id` int(12) NOT NULL AUTO_INCREMENT, |
|
1195
|
|
|
`user_id` int(12) NOT NULL, |
|
1196
|
|
|
`token` varchar(255) NOT NULL, |
|
1197
|
|
|
`reason` varchar(255) NOT NULL, |
|
1198
|
|
|
`creation_timestamp` varchar(50) NOT NULL, |
|
1199
|
|
|
`end_timestamp` varchar(50) DEFAULT NULL, |
|
1200
|
|
|
PRIMARY KEY (`id`) |
|
1201
|
|
|
) CHARSET=utf8;' |
|
1202
|
|
|
); |
|
1203
|
|
|
} elseif ($task === 'items_change') { |
|
1204
|
|
|
$mysqli_result = mysqli_query( |
|
1205
|
|
|
$dbTmp, |
|
1206
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "items_change` ( |
|
1207
|
|
|
`id` int(12) NOT NULL AUTO_INCREMENT, |
|
1208
|
|
|
`item_id` int(12) NOT NULL, |
|
1209
|
|
|
`label` varchar(255) NOT NULL DEFAULT 'none', |
|
1210
|
|
|
`pw` text NOT NULL, |
|
1211
|
|
|
`login` varchar(255) NOT NULL DEFAULT 'none', |
|
1212
|
|
|
`email` varchar(255) NOT NULL DEFAULT 'none', |
|
1213
|
|
|
`url` varchar(255) NOT NULL DEFAULT 'none', |
|
1214
|
|
|
`description` text NOT NULL, |
|
1215
|
|
|
`comment` text NOT NULL, |
|
1216
|
|
|
`folder_id` tinyint(12) NOT NULL, |
|
1217
|
|
|
`user_id` int(12) NOT NULL, |
|
1218
|
|
|
`timestamp` varchar(50) NOT NULL DEFAULT 'none', |
|
1219
|
|
|
PRIMARY KEY (`id`) |
|
1220
|
|
|
) CHARSET=utf8;" |
|
1221
|
|
|
); |
|
1222
|
|
|
} elseif ($task === 'templates') { |
|
1223
|
|
|
$mysqli_result = mysqli_query( |
|
1224
|
|
|
$dbTmp, |
|
1225
|
|
|
'CREATE TABLE IF NOT EXISTS `' . $var['tbl_prefix'] . 'templates` ( |
|
1226
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1227
|
|
|
`item_id` int(12) NOT NULL, |
|
1228
|
|
|
`category_id` int(12) NOT NULL, |
|
1229
|
|
|
PRIMARY KEY (`increment_id`) |
|
1230
|
|
|
) CHARSET=utf8;' |
|
1231
|
|
|
); |
|
1232
|
|
|
} elseif ($task === 'cache_tree') { |
|
1233
|
|
|
$mysqli_result = mysqli_query( |
|
1234
|
|
|
$dbTmp, |
|
1235
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "cache_tree` ( |
|
1236
|
|
|
`increment_id` smallint(32) NOT NULL AUTO_INCREMENT, |
|
1237
|
|
|
`data` longtext DEFAULT NULL CHECK (json_valid(`data`)), |
|
1238
|
|
|
`visible_folders` longtext NOT NULL, |
|
1239
|
|
|
`timestamp` varchar(50) NOT NULL, |
|
1240
|
|
|
`user_id` int(12) NOT NULL, |
|
1241
|
|
|
`folders` longtext DEFAULT NULL, |
|
1242
|
|
|
PRIMARY KEY (`increment_id`) |
|
1243
|
|
|
) CHARSET=utf8;" |
|
1244
|
|
|
); |
|
1245
|
|
|
} else if ($task === 'processes_tasks') { |
|
1246
|
|
|
$mysqli_result = mysqli_query( |
|
1247
|
|
|
$dbTmp, |
|
1248
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "processes_tasks` ( |
|
1249
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1250
|
|
|
`process_id` int(12) NOT NULL, |
|
1251
|
|
|
`created_at` varchar(50) NOT NULL, |
|
1252
|
|
|
`updated_at` varchar(50) DEFAULT NULL, |
|
1253
|
|
|
`finished_at` varchar(50) DEFAULT NULL, |
|
1254
|
|
|
`task` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`task`)), |
|
1255
|
|
|
`system_process_id` int(12) DEFAULT NULL, |
|
1256
|
|
|
`is_in_progress` tinyint(1) NOT NULL DEFAULT 0, |
|
1257
|
|
|
`sub_task_in_progress` tinyint(1) NOT NULL DEFAULT 0, |
|
1258
|
|
|
PRIMARY KEY (`increment_id`) |
|
1259
|
|
|
) CHARSET=utf8;" |
|
1260
|
|
|
); |
|
1261
|
|
|
$mysqli_result = mysqli_query( |
|
1262
|
|
|
$dbTmp, |
|
1263
|
|
|
'ALTER TABLE `' . $var['tbl_prefix'] . 'processes_tasks` |
|
1264
|
|
|
ADD KEY `process_id_idx` (`process_id`);' |
|
1265
|
|
|
); |
|
1266
|
|
|
} else if ($task === 'processes') { |
|
1267
|
|
|
$mysqli_result = mysqli_query( |
|
1268
|
|
|
$dbTmp, |
|
1269
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "processes` ( |
|
1270
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1271
|
|
|
`created_at` varchar(50) NOT NULL, |
|
1272
|
|
|
`started_at` varchar(50) DEFAULT NULL, |
|
1273
|
|
|
`updated_at` varchar(50) DEFAULT NULL, |
|
1274
|
|
|
`finished_at` varchar(50) DEFAULT NULL, |
|
1275
|
|
|
`process_id` int(12) DEFAULT NULL, |
|
1276
|
|
|
`process_type` varchar(100) NOT NULL, |
|
1277
|
|
|
`output` text DEFAULT NULL, |
|
1278
|
|
|
`arguments` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`arguments`)), |
|
1279
|
|
|
`is_in_progress` tinyint(1) NOT NULL DEFAULT 0, |
|
1280
|
|
|
`item_id` INT(12) NULL, |
|
1281
|
|
|
PRIMARY KEY (`increment_id`) |
|
1282
|
|
|
) CHARSET=utf8;" |
|
1283
|
|
|
); |
|
1284
|
|
|
} else if ($task === 'processes_logs') { |
|
1285
|
|
|
$mysqli_result = mysqli_query( |
|
1286
|
|
|
$dbTmp, |
|
1287
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "processes_logs` ( |
|
1288
|
|
|
`increment_id` int(12) NOT NULL AUTO_INCREMENT, |
|
1289
|
|
|
`created_at` varchar(20) NOT NULL, |
|
1290
|
|
|
`job` varchar(50) NOT NULL, |
|
1291
|
|
|
`status` varchar(10) NOT NULL, |
|
1292
|
|
|
`updated_at` varchar(20) DEFAULT NULL, |
|
1293
|
|
|
`finished_at` varchar(20) DEFAULT NULL, |
|
1294
|
|
|
`treated_objects` varchar(20) DEFAULT NULL, |
|
1295
|
|
|
PRIMARY KEY (`increment_id`) |
|
1296
|
|
|
) CHARSET=utf8;" |
|
1297
|
|
|
); |
|
1298
|
|
|
} else if ($task === 'ldap_groups_roles') { |
|
1299
|
|
|
$mysqli_result = mysqli_query( |
|
1300
|
|
|
$dbTmp, |
|
1301
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "ldap_groups_roles` ( |
|
1302
|
|
|
`increment_id` INT(12) NOT NULL AUTO_INCREMENT, |
|
1303
|
|
|
`role_id` INT(12) NOT NULL, |
|
1304
|
|
|
`ldap_group_id` VARCHAR(500) NOT NULL, |
|
1305
|
|
|
`ldap_group_label` VARCHAR(255) NOT NULL, |
|
1306
|
|
|
PRIMARY KEY (`increment_id`), |
|
1307
|
|
|
KEY `ROLE` (`role_id`) |
|
1308
|
|
|
) CHARSET=utf8;" |
|
1309
|
|
|
); |
|
1310
|
|
|
} else if ($task === 'items_otp') { |
|
1311
|
|
|
$mysqli_result = mysqli_query( |
|
1312
|
|
|
$dbTmp, |
|
1313
|
|
|
"CREATE TABLE IF NOT EXISTS `" . $var['tbl_prefix'] . "items_otp` ( |
|
1314
|
|
|
`increment_id` int(12) NOT NULL, |
|
1315
|
|
|
`item_id` int(12) NOT NULL, |
|
1316
|
|
|
`secret` text NOT NULL, |
|
1317
|
|
|
`timestamp` varchar(100) NOT NULL, |
|
1318
|
|
|
`enabled` tinyint(1) NOT NULL DEFAULT 0, |
|
1319
|
|
|
`phone_number` varchar(25) NOT NULL, |
|
1320
|
|
|
PRIMARY KEY (`increment_id`), |
|
1321
|
|
|
KEY `ITEM` (`item_id`) |
|
1322
|
|
|
) CHARSET=utf8;" |
|
1323
|
|
|
); |
|
1324
|
|
|
} |
|
1325
|
|
|
// CARREFULL - WHEN ADDING NEW TABLE |
|
1326
|
|
|
// Add the command inside install.js file |
|
1327
|
|
|
// in task array at step 5 |
|
1328
|
|
|
} |
|
1329
|
|
|
// answer back |
|
1330
|
|
|
if ($mysqli_result) { |
|
1331
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '", "task" : "' . $task . '", "activity" : "' . $activity . '"}]'; |
|
1332
|
|
|
} else { |
|
1333
|
|
|
echo '[{"error" : "' . addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_error($dbTmp))) . '", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '", "table" : "' . $task . '"}]'; |
|
1334
|
|
|
} |
|
1335
|
|
|
} else { |
|
1336
|
|
|
echo '[{"error" : "' . addslashes(str_replace(array("'", "\n", "\r"), array('"', '', ''), mysqli_connect_error())) . '", "result" : "Failed", "multiple" : ""}]'; |
|
1337
|
|
|
} |
|
1338
|
|
|
|
|
1339
|
|
|
mysqli_close($dbTmp); |
|
1340
|
|
|
// Destroy session without writing to disk |
|
1341
|
|
|
define('NODESTROY_SESSION', 'true'); |
|
1342
|
|
|
session_destroy(); |
|
1343
|
|
|
break; |
|
1344
|
|
|
|
|
1345
|
|
|
case 'step_6': |
|
1346
|
|
|
//decrypt |
|
1347
|
|
|
require_once 'libs/aesctr.php'; // AES Counter Mode implementation |
|
1348
|
|
|
$activity = Encryption\Crypt\aesctr::decrypt($post_activity, 'cpm', 128); |
|
1349
|
|
|
$data_sent = Encryption\Crypt\aesctr::decrypt($post_data, 'cpm', 128); |
|
1350
|
|
|
$data_sent = json_decode($data_sent, true); |
|
1351
|
|
|
$task = Encryption\Crypt\aesctr::decrypt($post_task, 'cpm', 128); |
|
1352
|
|
|
$json = Encryption\Crypt\aesctr::decrypt($post_db, 'cpm', 128); |
|
1353
|
|
|
$db = json_decode($json, true); |
|
1354
|
|
|
|
|
1355
|
|
|
$dbTmp = mysqli_connect( |
|
1356
|
|
|
$db['db_host'], |
|
1357
|
|
|
$db['db_login'], |
|
1358
|
|
|
$db['db_pw'], |
|
1359
|
|
|
$db['db_bdd'], |
|
1360
|
|
|
$db['db_port'] |
|
1361
|
|
|
); |
|
1362
|
|
|
|
|
1363
|
|
|
// read install variables |
|
1364
|
|
|
$result = mysqli_query($dbTmp, 'SELECT * FROM `_install`'); |
|
1365
|
|
|
while ($row = $result->fetch_array()) { |
|
1366
|
|
|
$var[$row[0]] = $row[1]; |
|
1367
|
|
|
} |
|
1368
|
|
|
|
|
1369
|
|
|
// launch |
|
1370
|
|
|
if (empty($var['sk_path'])) { |
|
1371
|
|
|
$securePath = $var['absolute_path']; |
|
1372
|
|
|
} else { |
|
1373
|
|
|
//ensure $var['sk_path'] has no trailing slash |
|
1374
|
|
|
$var['sk_path'] = rtrim(str_replace('\/', '//', $var['sk_path']), '/\\'); |
|
1375
|
|
|
$securePath = $var['sk_path']; |
|
1376
|
|
|
} |
|
1377
|
|
|
|
|
1378
|
|
|
$events = ''; |
|
1379
|
|
|
|
|
1380
|
|
|
if ($activity === 'file') { |
|
1381
|
|
|
if ($task === 'settings.php') { |
|
1382
|
|
|
// first is to create teampass-seckey.txt |
|
1383
|
|
|
// 0- check if exists |
|
1384
|
|
|
$filesecure = generateRandomKey(); |
|
1385
|
|
|
define('SECUREFILE', $filesecure); |
|
1386
|
|
|
$filename_seckey = $securePath . '/' . $filesecure; |
|
1387
|
|
|
|
|
1388
|
|
|
if (file_exists($filename_seckey)) { |
|
1389
|
|
|
if (!copy($filename_seckey, $filename_seckey . '.' . date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) { |
|
1390
|
|
|
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 . '"}]'; |
|
1391
|
|
|
break; |
|
1392
|
|
|
} else { |
|
1393
|
|
|
unlink($filename); |
|
1394
|
|
|
} |
|
1395
|
|
|
} |
|
1396
|
|
|
|
|
1397
|
|
|
// 1- generate saltkey |
|
1398
|
|
|
$key = Key::createNewRandomKey(); |
|
1399
|
|
|
$new_salt = $key->saveToAsciiSafeString(); |
|
1400
|
|
|
|
|
1401
|
|
|
// 2- store key in file |
|
1402
|
|
|
file_put_contents( |
|
1403
|
|
|
$filename_seckey, |
|
1404
|
|
|
$new_salt |
|
1405
|
|
|
); |
|
1406
|
|
|
|
|
1407
|
|
|
// Now create settings file |
|
1408
|
|
|
$filename = '../includes/config/settings.php'; |
|
1409
|
|
|
|
|
1410
|
|
|
if (file_exists($filename)) { |
|
1411
|
|
|
if (!copy($filename, $filename . '.' . date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) { |
|
1412
|
|
|
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 . '"}]'; |
|
1413
|
|
|
break; |
|
1414
|
|
|
} else { |
|
1415
|
|
|
unlink($filename); |
|
1416
|
|
|
} |
|
1417
|
|
|
} |
|
1418
|
|
|
//echo ">". $db['db_pw']." -- ".$new_salt." ;; "; |
|
1419
|
|
|
// Encrypt the DB password |
|
1420
|
|
|
$encrypted_text = encryptFollowingDefuse( |
|
1421
|
|
|
$db['db_pw'], |
|
1422
|
|
|
$new_salt |
|
1423
|
|
|
)['string']; |
|
1424
|
|
|
|
|
1425
|
|
|
// Open and write Settings file |
|
1426
|
|
|
$file_handler = fopen($filename, 'w'); |
|
1427
|
|
|
$result = fwrite( |
|
1428
|
|
|
$file_handler, |
|
1429
|
|
|
utf8_encode( |
|
1430
|
|
|
'<?php |
|
1431
|
|
|
// DATABASE connexion parameters |
|
1432
|
|
|
define("DB_HOST", "' . $db['db_host'] . '"); |
|
1433
|
|
|
define("DB_USER", "' . $db['db_login'] . '"); |
|
1434
|
|
|
define("DB_PASSWD", "' . str_replace('$', '\$', $encrypted_text) . '"); |
|
1435
|
|
|
define("DB_NAME", "' . $db['db_bdd'] . '"); |
|
1436
|
|
|
define("DB_PREFIX", "' . $var['tbl_prefix'] . '"); |
|
1437
|
|
|
define("DB_PORT", "' . $db['db_port'] . '"); |
|
1438
|
|
|
define("DB_ENCODING", "' . $session_db_encoding . '"); |
|
1439
|
|
|
define("DB_SSL", false); // if DB over SSL then comment this line |
|
1440
|
|
|
// if DB over SSL then uncomment the following lines |
|
1441
|
|
|
//define("DB_SSL", array( |
|
1442
|
|
|
// "key" => "", |
|
1443
|
|
|
// "cert" => "", |
|
1444
|
|
|
// "ca_cert" => "", |
|
1445
|
|
|
// "ca_path" => "", |
|
1446
|
|
|
// "cipher" => "" |
|
1447
|
|
|
//)); |
|
1448
|
|
|
define("DB_CONNECT_OPTIONS", array( |
|
1449
|
|
|
MYSQLI_OPT_CONNECT_TIMEOUT => 10 |
|
1450
|
|
|
)); |
|
1451
|
|
|
define("SECUREPATH", "' . $securePath . '"); |
|
1452
|
|
|
define("SECUREFILE", "' . $filesecure. '"); |
|
1453
|
|
|
|
|
1454
|
|
|
if (null !== $session->get(\'system-timezone\')) { |
|
1455
|
|
|
date_default_timezone_set($session->get(\'system-timezone\')); |
|
1456
|
|
|
} |
|
1457
|
|
|
' |
|
1458
|
|
|
) |
|
1459
|
|
|
); |
|
1460
|
|
|
fclose($file_handler); |
|
1461
|
|
|
|
|
1462
|
|
|
// Create TP USER |
|
1463
|
|
|
require_once '../includes/config/include.php'; |
|
1464
|
|
|
$tmp = mysqli_num_rows(mysqli_query($dbTmp, "SELECT * FROM `" . $var['tbl_prefix'] . "users` WHERE id = '" . TP_USER_ID . "'")); |
|
1465
|
|
|
if ($tmp === 0) { |
|
1466
|
|
|
// generate key for password |
|
1467
|
|
|
$pwd = GenerateCryptKey(25, true, true, true, true); |
|
1468
|
|
|
$encrypted_pwd = cryption( |
|
1469
|
|
|
$pwd, |
|
1470
|
|
|
$new_salt, |
|
1471
|
|
|
'encrypt' |
|
1472
|
|
|
)['string']; |
|
1473
|
|
|
|
|
1474
|
|
|
// GEnerate new public and private keys |
|
1475
|
|
|
$userKeys = generateUserKeys($pwd); |
|
1476
|
|
|
|
|
1477
|
|
|
$mysqli_result = mysqli_query( |
|
1478
|
|
|
$dbTmp, |
|
1479
|
|
|
"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`, `public_key`, `private_key`, `is_ready_for_usage`, `otp_provided`) VALUES ('" . TP_USER_ID . "', 'TP', '".$encrypted_pwd."', '', '', '', '', '', '1', '', '', '', '0', '', '', '', '0', '".$userKeys['public_key']."', '".$userKeys['private_key']."', '1', '1')" |
|
1480
|
|
|
); |
|
1481
|
|
|
} |
|
1482
|
|
|
|
|
1483
|
|
|
if ($result === false) { |
|
1484
|
|
|
echo '[{"error" : "Setting.php file could not be created. Please check the path and the rights", "result":"", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1485
|
|
|
} else { |
|
1486
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1487
|
|
|
} |
|
1488
|
|
|
} elseif ($task === 'security') { |
|
1489
|
|
|
// Sort out the file permissions |
|
1490
|
|
|
|
|
1491
|
|
|
// is server Windows or Linux? |
|
1492
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { |
|
1493
|
|
|
// Change directory permissions |
|
1494
|
|
|
if (is_null($session_abspath) === false) { |
|
1495
|
|
|
$result = recursiveChmod($session_abspath, 0770, 0740); |
|
1496
|
|
|
if ($result) { |
|
1497
|
|
|
$result = recursiveChmod($session_abspath . '/files', 0770, 0770); |
|
1498
|
|
|
} |
|
1499
|
|
|
if ($result) { |
|
1500
|
|
|
$result = recursiveChmod($session_abspath . '/upload', 0770, 0770); |
|
1501
|
|
|
} |
|
1502
|
|
|
} |
|
1503
|
|
|
} |
|
1504
|
|
|
$result = true; |
|
1505
|
|
|
if ($result === false) { |
|
|
|
|
|
|
1506
|
|
|
echo '[{"error" : "Cannot change directory permissions - please fix manually", "result":"", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1507
|
|
|
} else { |
|
1508
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1509
|
|
|
} |
|
1510
|
|
|
} elseif ($task === 'csrfp-token') { |
|
1511
|
|
|
// update CSRFP TOKEN |
|
1512
|
|
|
$csrfp_file_sample = '../includes/libraries/csrfp/libs/csrfp.config.sample.php'; |
|
1513
|
|
|
$csrfp_file = '../includes/libraries/csrfp/libs/csrfp.config.php'; |
|
1514
|
|
|
if (file_exists($csrfp_file)) { |
|
1515
|
|
|
if (!copy($csrfp_file, $csrfp_file . '.' . date('Y_m_d', mktime(0, 0, 0, (int) date('m'), (int) date('d'), (int) date('y'))))) { |
|
1516
|
|
|
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 . '"}]'; |
|
1517
|
|
|
break; |
|
1518
|
|
|
} else { |
|
1519
|
|
|
$events .= "The file $csrfp_file already exist. A copy has been created.<br />"; |
|
1520
|
|
|
} |
|
1521
|
|
|
} |
|
1522
|
|
|
unlink($csrfp_file); // delete existing csrfp.config file |
|
1523
|
|
|
copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file |
|
1524
|
|
|
$data = file_get_contents($csrfp_file); |
|
1525
|
|
|
$newdata = str_replace('"CSRFP_TOKEN" => ""', '"CSRFP_TOKEN" => "' . bin2hex(openssl_random_pseudo_bytes(25)) . '"', $data); |
|
1526
|
|
|
$jsUrl = $data_sent['url_path'] . '/includes/libraries/csrfp/js/csrfprotector.js'; |
|
1527
|
|
|
$newdata = str_replace('"jsUrl" => ""', '"jsUrl" => "' . $jsUrl . '"', $newdata); |
|
1528
|
|
|
file_put_contents('../includes/libraries/csrfp/libs/csrfp.config.php', $newdata); |
|
1529
|
|
|
|
|
1530
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1531
|
|
|
} |
|
1532
|
|
|
} elseif ($activity === 'install') { |
|
1533
|
|
|
if ($task === 'cleanup') { |
|
1534
|
|
|
// Mark a tag to force Install stuff (folders, files and table) to be cleanup while first login |
|
1535
|
|
|
mysqli_query($dbTmp, "INSERT INTO `" . $var['tbl_prefix'] . "misc` (`type`, `intitule`, `valeur`) VALUES ('install', 'clear_install_folder', 'true')"); |
|
1536
|
|
|
|
|
1537
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1538
|
|
|
} elseif ($task === 'init') { |
|
1539
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1540
|
|
|
} elseif ($task === 'cronJob') { |
|
1541
|
|
|
// Create cronjob |
|
1542
|
|
|
// get php location |
|
1543
|
|
|
require_once 'tp.functions.php'; |
|
1544
|
|
|
$phpLocation = findPhpBinary(); |
|
1545
|
|
|
if ($phpLocation['error'] === false) { |
|
1546
|
|
|
// Instantiate the adapter and repository |
|
1547
|
|
|
try { |
|
1548
|
|
|
$crontabRepository = new CrontabRepository(new CrontabAdapter()); |
|
1549
|
|
|
$results = $crontabRepository->findJobByRegex('/Teampass\ scheduler/'); |
|
1550
|
|
|
if (count($results) === 0) { |
|
1551
|
|
|
// Add the job |
|
1552
|
|
|
$crontabJob = new CrontabJob(); |
|
1553
|
|
|
$crontabJob |
|
1554
|
|
|
->setMinutes('*') |
|
1555
|
|
|
->setHours('*') |
|
1556
|
|
|
->setDayOfMonth('*') |
|
1557
|
|
|
->setMonths('*') |
|
1558
|
|
|
->setDayOfWeek('*') |
|
1559
|
|
|
->setTaskCommandLine($phpLocation . ' ' . $SETTINGS['cpassman_dir'] . '/sources/scheduler.php') |
|
1560
|
|
|
->setComments('Teampass scheduler'); |
|
1561
|
|
|
|
|
1562
|
|
|
$crontabRepository->addJob($crontabJob); |
|
1563
|
|
|
$crontabRepository->persist(); |
|
1564
|
|
|
} |
|
1565
|
|
|
} catch (Exception $e) { |
|
1566
|
|
|
// do nothing |
|
1567
|
|
|
} |
|
1568
|
|
|
} else { |
|
1569
|
|
|
echo '[{"error" : "Cannot find PHP binary location. Please add a cronjob manually (see documentation).", "result":"", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1570
|
|
|
} |
|
1571
|
|
|
echo '[{"error" : "", "index" : "' . $post_index . '", "multiple" : "' . $post_multiple . '"}]'; |
|
1572
|
|
|
} |
|
1573
|
|
|
} |
|
1574
|
|
|
|
|
1575
|
|
|
mysqli_close($dbTmp); |
|
1576
|
|
|
// Destroy session without writing to disk |
|
1577
|
|
|
define('NODESTROY_SESSION', 'true'); |
|
1578
|
|
|
session_destroy(); |
|
1579
|
|
|
break; |
|
1580
|
|
|
} |
|
1581
|
|
|
} |
|
1582
|
|
|
|