1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @package upgrade_run_db_original.php |
4
|
|
|
* @author Nils Laumaillé <[email protected]> |
5
|
|
|
* @version 2.1.27 |
6
|
|
|
* @copyright 2009-2018 Nils Laumaillé |
7
|
|
|
* @license GNU GPL-3.0 |
8
|
|
|
* @link https://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
|
|
|
|
15
|
|
|
require_once('../sources/SecureHandler.php'); |
16
|
|
|
session_start(); |
17
|
|
|
error_reporting(E_ERROR | E_PARSE); |
18
|
|
|
$_SESSION['db_encoding'] = "utf8"; |
19
|
|
|
$_SESSION['CPM'] = 1; |
20
|
|
|
|
21
|
|
|
require_once '../includes/language/english.php'; |
22
|
|
|
require_once '../includes/config/include.php'; |
23
|
|
|
if (!file_exists("../includes/config/settings.php")) { |
24
|
|
|
echo 'document.getElementById("res_step1_error").innerHTML = "";'; |
25
|
|
|
echo 'document.getElementById("res_step1_error").innerHTML = '. |
26
|
|
|
'"File settings.php does not exist in folder includes/! '. |
27
|
|
|
'If it is an upgrade, it should be there, otherwise select install!";'; |
28
|
|
|
echo 'document.getElementById("loader").style.display = "none";'; |
29
|
|
|
exit; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
require_once '../includes/config/settings.php'; |
33
|
|
|
require_once '../sources/main.functions.php'; |
34
|
|
|
|
35
|
|
|
$_SESSION['settings']['loaded'] = ""; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
################ |
39
|
|
|
## Function permits to check if a column exists, and if not to add it |
40
|
|
|
################ |
41
|
|
|
function addColumnIfNotExist($dbname, $column, $columnAttr = "VARCHAR(255) NULL") |
42
|
|
|
{ |
43
|
|
|
global $db_link; |
|
|
|
|
44
|
|
|
$exists = false; |
45
|
|
|
$columns = mysqli_query($db_link, "show columns from $dbname"); |
46
|
|
|
while ($col = mysqli_fetch_assoc($columns)) { |
|
|
|
|
47
|
|
|
if ($col['Field'] == $column) { |
48
|
|
|
$exists = true; |
|
|
|
|
49
|
|
|
return true; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
if (!$exists) { |
|
|
|
|
53
|
|
|
return mysqli_query($db_link, "ALTER TABLE `$dbname` ADD `$column` $columnAttr"); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function addIndexIfNotExist($table, $index, $sql) |
60
|
|
|
{ |
61
|
|
|
global $db_link; |
|
|
|
|
62
|
|
|
|
63
|
|
|
$mysqli_result = mysqli_query($db_link, "SHOW INDEX FROM $table WHERE key_name LIKE \"$index\""); |
64
|
|
|
$res = mysqli_fetch_row($mysqli_result); |
|
|
|
|
65
|
|
|
|
66
|
|
|
// if index does not exist, then add it |
67
|
|
|
if (!$res) { |
68
|
|
|
$res = mysqli_query( |
69
|
|
|
$db_link, |
70
|
|
|
"ALTER TABLE `$table` ".$sql |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $res; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function tableExists($tablename) |
78
|
|
|
{ |
79
|
|
|
global $db_link, $database; |
|
|
|
|
80
|
|
|
|
81
|
|
|
$res = mysqli_query( |
82
|
|
|
$db_link, |
83
|
|
|
"SELECT COUNT(*) as count |
84
|
|
|
FROM information_schema.tables |
85
|
|
|
WHERE table_schema = '".$database."' |
86
|
|
|
AND table_name = '$tablename'" |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
if ($res > 0) { |
90
|
|
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
//define pbkdf2 iteration count |
97
|
|
|
@define('ITCOUNT', '2072'); |
98
|
|
|
|
99
|
|
|
$return_error = ""; |
100
|
|
|
|
101
|
|
|
// do initial upgrade |
102
|
|
|
|
103
|
|
|
//include librairies |
104
|
|
|
require_once '../includes/libraries/Tree/NestedTree/NestedTree.php'; |
105
|
|
|
|
106
|
|
|
//Build tree |
107
|
|
|
$tree = new Tree\NestedTree\NestedTree( |
108
|
|
|
$pre.'nested_tree', |
109
|
|
|
'id', |
110
|
|
|
'parent_id', |
111
|
|
|
'title' |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
// dataBase |
115
|
|
|
$res = ""; |
116
|
|
|
|
117
|
|
|
// Test DB connexion |
118
|
|
|
$pass = defuse_return_decrypted($pass); |
119
|
|
|
if (mysqli_connect( |
120
|
|
|
$server, |
121
|
|
|
$user, |
122
|
|
|
$pass, |
123
|
|
|
$database, |
124
|
|
|
$port |
125
|
|
|
) |
126
|
|
|
) { |
127
|
|
|
$db_link = mysqli_connect( |
128
|
|
|
$server, |
129
|
|
|
$user, |
130
|
|
|
$pass, |
131
|
|
|
$database, |
132
|
|
|
$port |
133
|
|
|
); |
134
|
|
|
} else { |
135
|
|
|
$res = "Impossible to get connected to server. Error is: ".addslashes(mysqli_connect_error()); |
136
|
|
|
echo '[{"finish":"1", "msg":"", "error":"Impossible to get connected to server. Error is: '.addslashes(mysqli_connect_error()).'!"}]'; |
137
|
|
|
mysqli_close($db_link); |
138
|
|
|
exit(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// 2.1.27 check with DEFUSE |
142
|
|
|
// check if library defuse already on-going here |
143
|
|
|
// if yes, then don't execute re-encryption |
144
|
|
|
if (isset($_SESSION['tp_defuse_installed']) !== true) { |
145
|
|
|
$_SESSION['tp_defuse_installed'] = false; |
146
|
|
|
$columns = mysqli_query( |
147
|
|
|
$db_link, |
148
|
|
|
"show columns from ".$pre."items" |
149
|
|
|
); |
150
|
|
|
while ($c = mysqli_fetch_assoc($columns)) { |
|
|
|
|
151
|
|
|
if ($c['Field'] === "encryption_type") { |
152
|
|
|
$_SESSION['tp_defuse_installed'] = true; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
## Populate table MISC |
158
|
|
|
$val = array( |
159
|
|
|
array('admin', 'max_latest_items', '10', 0), |
160
|
|
|
array('admin', 'enable_favourites', '1', 0), |
161
|
|
|
array('admin', 'show_last_items', '1', 0), |
162
|
|
|
array('admin', 'enable_pf_feature', '0', 0), |
163
|
|
|
array('admin', 'menu_type', 'context', 0), |
164
|
|
|
array('admin', 'log_connections', '0', 0), |
165
|
|
|
array('admin', 'time_format', 'H:i:s', 0), |
166
|
|
|
array('admin', 'date_format', 'd/m/Y', 0), |
167
|
|
|
array('admin', 'duplicate_folder', '0', 0), |
168
|
|
|
array('admin', 'duplicate_item', '0', 0), |
169
|
|
|
array('admin', 'item_duplicate_in_same_folder', '0', 0), |
170
|
|
|
array('admin', 'number_of_used_pw', '3', 0), |
171
|
|
|
array('admin', 'manager_edit', '1', 0), |
172
|
|
|
array('admin', 'cpassman_dir', '', 0), |
173
|
|
|
array('admin', 'cpassman_url', '', 0), |
174
|
|
|
array('admin', 'favicon', '', 0), |
175
|
|
|
array('admin', 'activate_expiration', '0', 0), |
176
|
|
|
array('admin', 'pw_life_duration', '30', 0), |
177
|
|
|
//array('admin', 'maintenance_mode','1',1), |
|
|
|
|
178
|
|
|
array('admin', 'cpassman_version', $SETTINGS_EXT['version'], 1), |
179
|
|
|
array('admin', 'ldap_mode', '0', 0), |
180
|
|
|
array('admin', 'ldap_type', '0', 0), |
181
|
|
|
array('admin', 'ldap_suffix', '0', 0), |
182
|
|
|
array('admin', 'ldap_domain_dn', '0', 0), |
183
|
|
|
array('admin', 'ldap_domain_controler', '0', 0), |
184
|
|
|
array('admin', 'ldap_user_attribute', '0', 0), |
185
|
|
|
array('admin', 'ldap_ssl', '0', 0), |
186
|
|
|
array('admin', 'ldap_tls', '0', 0), |
187
|
|
|
array('admin', 'ldap_elusers', '0', 0), |
188
|
|
|
array('admin', 'richtext', 0, 0), |
189
|
|
|
array('admin', 'allow_print', 0, 0), |
190
|
|
|
array('admin', 'roles_allowed_to_print', 0, 0), |
191
|
|
|
array('admin', 'show_description', 1, 0), |
192
|
|
|
array('admin', 'anyone_can_modify', 0, 0), |
193
|
|
|
array('admin', 'anyone_can_modify_bydefault', 0, 0), |
194
|
|
|
array('admin', 'nb_bad_authentication', 0, 0), |
195
|
|
|
array('admin', 'restricted_to', 0, 0), |
196
|
|
|
array('admin', 'restricted_to_roles', 0, 0), |
197
|
|
|
array('admin', 'utf8_enabled', 1, 0), |
198
|
|
|
array('admin', 'custom_logo', '', 0), |
199
|
|
|
array('admin', 'custom_login_text', '', 0), |
200
|
|
|
array('admin', 'log_accessed', '1', 1), |
201
|
|
|
array('admin', 'default_language', 'english', 0), |
202
|
|
|
array( |
203
|
|
|
'admin', |
204
|
|
|
'send_stats', |
205
|
|
|
empty($_SESSION['send_stats']) ? '0' : $_SESSION['send_stats'], |
206
|
|
|
1 |
207
|
|
|
), |
208
|
|
|
array('admin', 'get_tp_info', '1', 0), |
209
|
|
|
array('admin', 'send_mail_on_user_login', '0', 0), |
210
|
|
|
array('cron', 'sending_emails', '0', 0), |
211
|
|
|
array('admin', 'nb_items_by_query', 'auto', 0), |
212
|
|
|
array('admin', 'enable_delete_after_consultation', '0', 0), |
213
|
|
|
array( |
214
|
|
|
'admin', |
215
|
|
|
'path_to_upload_folder', |
216
|
|
|
strrpos($_SERVER['DOCUMENT_ROOT'], "/") == 1 ? |
217
|
|
|
(strlen($_SERVER['DOCUMENT_ROOT']) - 1).substr( |
218
|
|
|
$_SERVER['PHP_SELF'], |
219
|
|
|
0, |
220
|
|
|
strlen($_SERVER['PHP_SELF']) - 25 |
221
|
|
|
).'/upload' |
222
|
|
|
: |
223
|
|
|
$_SERVER['DOCUMENT_ROOT'].substr( |
224
|
|
|
$_SERVER['PHP_SELF'], |
225
|
|
|
0, |
226
|
|
|
strlen($_SERVER['PHP_SELF']) - 25 |
227
|
|
|
).'/upload', |
228
|
|
|
0 |
229
|
|
|
), |
230
|
|
|
array( |
231
|
|
|
'admin', |
232
|
|
|
'url_to_upload_folder', |
233
|
|
|
'http://'.$_SERVER['HTTP_HOST'].substr( |
234
|
|
|
$_SERVER['PHP_SELF'], |
235
|
|
|
0, |
236
|
|
|
strrpos($_SERVER['PHP_SELF'], '/') - 8 |
237
|
|
|
).'/upload', |
238
|
|
|
0 |
239
|
|
|
), |
240
|
|
|
array('admin', 'enable_personal_saltkey_cookie', '0', 0), |
241
|
|
|
array('admin', 'personal_saltkey_cookie_duration', '31', 0), |
242
|
|
|
array( |
243
|
|
|
'admin', |
244
|
|
|
'path_to_files_folder', |
245
|
|
|
strrpos($_SERVER['DOCUMENT_ROOT'], "/") == 1 ? |
246
|
|
|
(strlen($_SERVER['DOCUMENT_ROOT']) - 1).substr( |
247
|
|
|
$_SERVER['PHP_SELF'], |
248
|
|
|
0, |
249
|
|
|
strlen($_SERVER['PHP_SELF']) - 25 |
250
|
|
|
).'/files' |
251
|
|
|
: |
252
|
|
|
$_SERVER['DOCUMENT_ROOT'].substr( |
253
|
|
|
$_SERVER['PHP_SELF'], |
254
|
|
|
0, |
255
|
|
|
strlen($_SERVER['PHP_SELF']) - 25 |
256
|
|
|
).'/files', |
257
|
|
|
0 |
258
|
|
|
), |
259
|
|
|
array( |
260
|
|
|
'admin', |
261
|
|
|
'url_to_files_folder', |
262
|
|
|
'http://'.$_SERVER['HTTP_HOST'].substr( |
263
|
|
|
$_SERVER['PHP_SELF'], |
264
|
|
|
0, |
265
|
|
|
strrpos($_SERVER['PHP_SELF'], '/') - 8 |
266
|
|
|
).'/files', |
267
|
|
|
0 |
268
|
|
|
), |
269
|
|
|
array('admin', 'pwd_maximum_length', '40', 0), |
270
|
|
|
array('admin', 'ga_website_name', 'TeamPass for ChangeMe', 0), |
271
|
|
|
array('admin', 'email_smtp_server', @$_SESSION['smtp_server'], 0), |
272
|
|
|
array('admin', 'email_smtp_auth', @$_SESSION['smtp_auth'], 0), |
273
|
|
|
array('admin', 'email_auth_username', @$_SESSION['smtp_auth_username'], 0), |
274
|
|
|
array('admin', 'email_auth_pwd', @$_SESSION['smtp_auth_password'], 0), |
275
|
|
|
array('admin', 'email_port', @$_SESSION['smtp_port'], 0), |
276
|
|
|
array('admin', 'email_security', @$_SESSION['smtp_security'], 0), |
277
|
|
|
array('admin', 'email_from', @$_SESSION['email_from'], 0), |
278
|
|
|
array('admin', 'email_from_name', @$_SESSION['email_from_name'], 0), |
279
|
|
|
array('admin', 'google_authentication', 0, 0), |
280
|
|
|
array('admin', 'delay_item_edition', 0, 0), |
281
|
|
|
array('admin', 'allow_import', 0, 0), |
282
|
|
|
array('admin', 'proxy_port', 0, 0), |
283
|
|
|
array('admin', 'proxy_port', 0, 0), |
284
|
|
|
array('admin', 'upload_maxfilesize', '10mb', 0), |
285
|
|
|
array( |
286
|
|
|
'admin', |
287
|
|
|
'upload_docext', |
288
|
|
|
'doc,docx,dotx,xls,xlsx,xltx,rtf,csv,txt,pdf,ppt,pptx,pot,dotx,xltx', |
289
|
|
|
0 |
290
|
|
|
), |
291
|
|
|
array('admin', 'upload_imagesext', 'jpg,jpeg,gif,png', 0), |
292
|
|
|
array('admin', 'upload_pkgext', '7z,rar,tar,zip', 0), |
293
|
|
|
array('admin', 'upload_otherext', 'sql,xml', 0), |
294
|
|
|
array('admin', 'upload_imageresize_options', '1', 0), |
295
|
|
|
array('admin', 'upload_imageresize_width', '800', 0), |
296
|
|
|
array('admin', 'upload_imageresize_height', '600', 0), |
297
|
|
|
array('admin', 'upload_imageresize_quality', '90', 0), |
298
|
|
|
array('admin', 'enable_send_email_on_user_login', '0', 0), |
299
|
|
|
array('admin', 'enable_user_can_create_folders', '0', 0), |
300
|
|
|
array('admin', 'insert_manual_entry_item_history', '0', 0), |
301
|
|
|
array('admin', 'enable_kb', '0', 0), |
302
|
|
|
array('admin', 'enable_email_notification_on_item_shown', '0', 0), |
303
|
|
|
array('admin', 'enable_email_notification_on_user_pw_change', '0', 0), |
304
|
|
|
array('admin', 'enable_sts', '0', 0), |
305
|
|
|
array('admin', 'encryptClientServer', '1', 0), |
306
|
|
|
array('admin', 'use_md5_password_as_salt', '0', 0), |
307
|
|
|
array('admin', 'api', '0', 0), |
308
|
|
|
array('admin', 'subfolder_rights_as_parent', '0', 0), |
309
|
|
|
array('admin', 'show_only_accessible_folders', '0', 0), |
310
|
|
|
array('admin', 'enable_suggestion', '0', 0), |
311
|
|
|
array('admin', 'email_server_url', '', 0), |
312
|
|
|
array('admin', 'otv_expiration_period', '7', 0), |
313
|
|
|
array('admin', 'default_session_expiration_time', '60', 0), |
314
|
|
|
array('admin', 'duo', '0', 0), |
315
|
|
|
array('admin', 'enable_server_password_change', '0', 0), |
316
|
|
|
array('admin', 'bck_script_path', $_SESSION['abspath']."/backups", 0), |
317
|
|
|
array('admin', 'bck_script_filename', 'bck_cpassman', 0) |
318
|
|
|
); |
319
|
|
|
$res1 = "na"; |
320
|
|
|
foreach ($val as $elem) { |
321
|
|
|
//Check if exists before inserting |
322
|
|
|
$queryRes = mysqli_query( |
323
|
|
|
$db_link, |
324
|
|
|
"SELECT COUNT(*) FROM ".$pre."misc |
|
|
|
|
325
|
|
|
WHERE type='".$elem[0]."' AND intitule='".$elem[1]."'" |
326
|
|
|
); |
327
|
|
|
if (mysqli_error($db_link)) { |
328
|
|
|
echo '[{"finish":"1", "msg":"", "error":"MySQL Error! Last input is "'.$elem[1].' - '. |
|
|
|
|
329
|
|
|
addslashes($queryRes).'"}]'; |
|
|
|
|
330
|
|
|
exit(); |
331
|
|
|
} else { |
332
|
|
|
$resTmp = mysqli_fetch_row($queryRes); |
|
|
|
|
333
|
|
|
if ($resTmp[0] === 0) { |
334
|
|
|
$queryRes = mysqli_query( |
335
|
|
|
$db_link, |
336
|
|
|
"INSERT INTO `".$pre."misc` |
|
|
|
|
337
|
|
|
(`type`, `intitule`, `valeur`) VALUES |
338
|
|
|
('".$elem[0]."', '".$elem[1]."', '". |
339
|
|
|
str_replace("'", "", $elem[2])."');" |
340
|
|
|
); |
341
|
|
|
if (mysqli_error($db_link)) { |
342
|
|
|
echo '[{"finish":"1", "msg":"", "error":"MySQL Error1! '.addslashes(mysqli_error($db_link)).'"}]'; |
343
|
|
|
exit(); |
344
|
|
|
} |
345
|
|
|
} else { |
346
|
|
|
// Force update for some settings |
347
|
|
|
if ($elem[3] === 1) { |
348
|
|
|
$queryRes = mysqli_query( |
349
|
|
|
$db_link, |
350
|
|
|
"UPDATE `".$pre."misc` |
|
|
|
|
351
|
|
|
SET `valeur` = '".$elem[2]."' |
352
|
|
|
WHERE `type` = '".$elem[0]."' AND `intitule` = '".$elem[1]."'" |
353
|
|
|
); |
354
|
|
|
if (mysqli_error($db_link)) { |
355
|
|
|
echo '[{"finish":"1", "msg":"", "error":"MySQL Error2! '.addslashes(mysqli_error($db_link)).'"}]'; |
356
|
|
|
exit(); |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
## Alter ITEMS table |
365
|
|
|
$res2 = addColumnIfNotExist( |
366
|
|
|
$pre."items", |
367
|
|
|
"anyone_can_modify", |
368
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
369
|
|
|
); |
370
|
|
|
$res2 = addColumnIfNotExist( |
371
|
|
|
$pre."items", |
372
|
|
|
"email", |
373
|
|
|
"VARCHAR(100) DEFAULT NULL" |
374
|
|
|
); |
375
|
|
|
$res2 = addColumnIfNotExist( |
376
|
|
|
$pre."items", |
377
|
|
|
"notification", |
378
|
|
|
"VARCHAR(250) DEFAULT NULL" |
379
|
|
|
); |
380
|
|
|
$res2 = addColumnIfNotExist( |
381
|
|
|
$pre."items", |
382
|
|
|
"viewed_no", |
383
|
|
|
"INT(12) NOT null DEFAULT '0'" |
384
|
|
|
); |
385
|
|
|
$res2 = addColumnIfNotExist( |
386
|
|
|
$pre."items", |
387
|
|
|
"complexity_level", |
388
|
|
|
"varchar(2) NOT null DEFAULT '-1'" |
389
|
|
|
); |
390
|
|
|
$res2 = addColumnIfNotExist( |
391
|
|
|
$pre."roles_values", |
392
|
|
|
"type", |
393
|
|
|
"VARCHAR(5) NOT NULL DEFAULT 'R'" |
394
|
|
|
); |
395
|
|
|
$res2 = addColumnIfNotExist( |
396
|
|
|
$pre."users", |
397
|
|
|
"upgrade_needed", |
398
|
|
|
"BOOLEAN NOT NULL DEFAULT FALSE" |
399
|
|
|
); |
400
|
|
|
|
401
|
|
|
$res2 = addIndexIfNotExist($pre.'items', 'restricted_inactif_idx', 'ADD INDEX `restricted_inactif_idx` (`restricted_to`,`inactif`)'); |
402
|
|
|
|
403
|
|
|
# Alter tables |
404
|
|
|
mysqli_query( |
405
|
|
|
$db_link, |
406
|
|
|
"ALTER TABLE ".$pre."log_items MODIFY id_user INT(8)" |
407
|
|
|
); |
408
|
|
|
mysqli_query( |
409
|
|
|
$db_link, |
410
|
|
|
"ALTER TABLE ".$pre."restriction_to_roles MODIFY role_id INT(12)" |
411
|
|
|
); |
412
|
|
|
mysqli_query( |
413
|
|
|
$db_link, |
414
|
|
|
"ALTER TABLE ".$pre."restriction_to_roles MODIFY item_id INT(12)" |
415
|
|
|
); |
416
|
|
|
mysqli_query( |
417
|
|
|
$db_link, |
418
|
|
|
"ALTER TABLE ".$pre."items MODIFY pw TEXT" |
419
|
|
|
); |
420
|
|
|
mysqli_query( |
421
|
|
|
$db_link, |
422
|
|
|
"ALTER TABLE ".$pre."users MODIFY pw VARCHAR(400)" |
423
|
|
|
); |
424
|
|
|
mysqli_query( |
425
|
|
|
$db_link, |
426
|
|
|
"ALTER TABLE ".$pre."cache CHANGE `login` `login` VARCHAR( 200 ) CHARACTER NULL" |
427
|
|
|
); |
428
|
|
|
mysqli_query( |
429
|
|
|
$db_link, |
430
|
|
|
"ALTER TABLE ".$pre."log_system CHANGE `field_1` `field_1` VARCHAR( 250 ) NULL" |
431
|
|
|
); |
432
|
|
|
mysqli_query( |
433
|
|
|
$db_link, |
434
|
|
|
"ALTER TABLE ".$pre."keys CHANGE `table` `sql_table` VARCHAR( 25 ) NULL" |
435
|
|
|
); |
436
|
|
|
mysqli_query( |
437
|
|
|
$db_link, |
438
|
|
|
"ALTER TABLE ".$pre."users MODIFY `key_tempo` varchar(100) NULL" |
439
|
|
|
); |
440
|
|
|
mysqli_query( |
441
|
|
|
$db_link, |
442
|
|
|
"ALTER TABLE ".$pre."categories CHANGE `type` `type` varchar(50) NULL default ''" |
443
|
|
|
); |
444
|
|
|
mysqli_query( |
445
|
|
|
$db_link, |
446
|
|
|
"ALTER TABLE ".$pre."categories CHANGE `order` `order` int(12) NOT NULL default '0'" |
447
|
|
|
); |
448
|
|
|
mysqli_query( |
449
|
|
|
$db_link, |
450
|
|
|
"ALTER TABLE ".$pre."users CHANGE `derniers` `derniers` text NULL" |
451
|
|
|
); |
452
|
|
|
mysqli_query( |
453
|
|
|
$db_link, |
454
|
|
|
"ALTER TABLE ".$pre."users CHANGE `key_tempo` `key_tempo` varchar(100) NULL" |
455
|
|
|
); |
456
|
|
|
mysqli_query( |
457
|
|
|
$db_link, |
458
|
|
|
"ALTER TABLE ".$pre."users CHANGE `last_pw_change` `last_pw_change` varchar(30) NULL" |
459
|
|
|
); |
460
|
|
|
mysqli_query( |
461
|
|
|
$db_link, |
462
|
|
|
"ALTER TABLE ".$pre."users CHANGE `last_pw` `last_pw` text NULL" |
463
|
|
|
); |
464
|
|
|
mysqli_query( |
465
|
|
|
$db_link, |
466
|
|
|
"ALTER TABLE ".$pre."users CHANGE `fonction_id` `fonction_id` varchar(255) NULL" |
467
|
|
|
); |
468
|
|
|
mysqli_query( |
469
|
|
|
$db_link, |
470
|
|
|
"ALTER TABLE ".$pre."users CHANGE `groupes_interdits` `groupes_interdits` varchar(255) NULL" |
471
|
|
|
); |
472
|
|
|
mysqli_query( |
473
|
|
|
$db_link, |
474
|
|
|
"ALTER TABLE ".$pre."users CHANGE `last_connexion` `last_connexion` varchar(30) NULL" |
475
|
|
|
); |
476
|
|
|
mysqli_query( |
477
|
|
|
$db_link, |
478
|
|
|
"ALTER TABLE ".$pre."users CHANGE `favourites` `favourites` varchar(300) NULL" |
479
|
|
|
); |
480
|
|
|
mysqli_query( |
481
|
|
|
$db_link, |
482
|
|
|
"ALTER TABLE ".$pre."users CHANGE `latest_items` `latest_items` varchar(300) NULL" |
483
|
|
|
); |
484
|
|
|
mysqli_query( |
485
|
|
|
$db_link, |
486
|
|
|
"ALTER TABLE ".$pre."users CHANGE `avatar` `avatar` varchar(255) NOT null DEFAULT ''" |
487
|
|
|
); |
488
|
|
|
mysqli_query( |
489
|
|
|
$db_link, |
490
|
|
|
"ALTER TABLE ".$pre."users CHANGE `avatar_thumb` `avatar_thumb` varchar(255) NOT null DEFAULT ''" |
491
|
|
|
); |
492
|
|
|
mysqli_query( |
493
|
|
|
$db_link, |
494
|
|
|
"ALTER TABLE ".$pre."log_items CHANGE `raison` `raison` text NULL" |
495
|
|
|
); |
496
|
|
|
mysqli_query( |
497
|
|
|
$db_link, |
498
|
|
|
"ALTER TABLE ".$pre."log_items CHANGE `raison_iv` `raison_iv` text NULL" |
499
|
|
|
); |
500
|
|
|
mysqli_query( |
501
|
|
|
$db_link, |
502
|
|
|
"ALTER TABLE ".$pre."roles_values CHANGE `type` `type` VARCHAR( 5 ) NOT NULL DEFAULT 'R'" |
503
|
|
|
); |
504
|
|
|
mysqli_query( |
505
|
|
|
$db_link, |
506
|
|
|
"ALTER TABLE ".$pre."suggestion CHANGE `suggestion_key` `pw_iv` TEXT NULL" |
507
|
|
|
); |
508
|
|
|
mysqli_query( |
509
|
|
|
$db_link, |
510
|
|
|
"ALTER TABLE ".$pre."suggestion CHANGE `key` `pw_iv` TEXT NULL" |
511
|
|
|
); |
512
|
|
|
mysqli_query( |
513
|
|
|
$db_link, |
514
|
|
|
"ALTER TABLE ".$pre."suggestion CHANGE `password` `pw` TEXT NULL" |
515
|
|
|
); |
516
|
|
|
|
517
|
|
|
## Alter USERS table |
518
|
|
|
$res2 = addColumnIfNotExist( |
519
|
|
|
$pre."users", |
520
|
|
|
"favourites", |
521
|
|
|
"VARCHAR(300)" |
522
|
|
|
); |
523
|
|
|
$res2 = addColumnIfNotExist( |
524
|
|
|
$pre."users", |
525
|
|
|
"latest_items", |
526
|
|
|
"VARCHAR(300)" |
527
|
|
|
); |
528
|
|
|
$res2 = addColumnIfNotExist( |
529
|
|
|
$pre."users", |
530
|
|
|
"personal_folder", |
531
|
|
|
"INT(1) NOT null DEFAULT '0'" |
532
|
|
|
); |
533
|
|
|
$res2 = addColumnIfNotExist( |
534
|
|
|
$pre."users", |
535
|
|
|
"disabled", |
536
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
537
|
|
|
); |
538
|
|
|
$res2 = addColumnIfNotExist( |
539
|
|
|
$pre."users", |
540
|
|
|
"no_bad_attempts", |
541
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
542
|
|
|
); |
543
|
|
|
$res2 = addColumnIfNotExist( |
544
|
|
|
$pre."users", |
545
|
|
|
"can_create_root_folder", |
546
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
547
|
|
|
); |
548
|
|
|
$res2 = addColumnIfNotExist( |
549
|
|
|
$pre."users", |
550
|
|
|
"read_only", |
551
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
552
|
|
|
); |
553
|
|
|
$res2 = addColumnIfNotExist( |
554
|
|
|
$pre."users", |
555
|
|
|
"timestamp", |
556
|
|
|
"VARCHAR(30) NOT null DEFAULT '0'" |
557
|
|
|
); |
558
|
|
|
$res2 = addColumnIfNotExist( |
559
|
|
|
$pre."users", |
560
|
|
|
"user_language", |
561
|
|
|
"VARCHAR(30) NOT null DEFAULT 'english'" |
562
|
|
|
); |
563
|
|
|
$res2 = addColumnIfNotExist( |
564
|
|
|
$pre."users", |
565
|
|
|
"name", |
566
|
|
|
"VARCHAR(100) DEFAULT NULL" |
567
|
|
|
); |
568
|
|
|
$res2 = addColumnIfNotExist( |
569
|
|
|
$pre."users", |
570
|
|
|
"lastname", |
571
|
|
|
"VARCHAR(100) DEFAULT NULL" |
572
|
|
|
); |
573
|
|
|
$res2 = addColumnIfNotExist( |
574
|
|
|
$pre."users", |
575
|
|
|
"session_end", |
576
|
|
|
"VARCHAR(30) DEFAULT NULL" |
577
|
|
|
); |
578
|
|
|
$res2 = addColumnIfNotExist( |
579
|
|
|
$pre."users", |
580
|
|
|
"isAdministratedByRole", |
581
|
|
|
"TINYINT(5) NOT null DEFAULT '0'" |
582
|
|
|
); |
583
|
|
|
$res2 = addColumnIfNotExist( |
584
|
|
|
$pre."users", |
585
|
|
|
"psk", |
586
|
|
|
"VARCHAR(400) DEFAULT NULL" |
587
|
|
|
); |
588
|
|
|
$res2 = addColumnIfNotExist( |
589
|
|
|
$pre."users", |
590
|
|
|
"ga", |
591
|
|
|
"VARCHAR(50) DEFAULT NULL" |
592
|
|
|
); |
593
|
|
|
$res2 = addColumnIfNotExist( |
594
|
|
|
$pre."users", |
595
|
|
|
"avatar", |
596
|
|
|
"VARCHAR(255) NOT null DEFAULT ''" |
597
|
|
|
); |
598
|
|
|
$res2 = addColumnIfNotExist( |
599
|
|
|
$pre."users", |
600
|
|
|
"avatar_thumb", |
601
|
|
|
"VARCHAR(255) NOT null DEFAULT ''" |
602
|
|
|
); |
603
|
|
|
$res2 = addColumnIfNotExist( |
604
|
|
|
$pre."users", |
605
|
|
|
"treeloadstrategy", |
606
|
|
|
"VARCHAR(30) NOT null DEFAULT 'full'" |
607
|
|
|
); |
608
|
|
|
|
609
|
|
|
$res2 = addColumnIfNotExist( |
610
|
|
|
$pre."log_items", |
611
|
|
|
"raison_iv", |
612
|
|
|
"TEXT null" |
613
|
|
|
); |
614
|
|
|
$res2 = addColumnIfNotExist( |
615
|
|
|
$pre."categories_items", |
616
|
|
|
"data_iv", |
617
|
|
|
"TEXT NOT null" |
618
|
|
|
); |
619
|
|
|
$res2 = addColumnIfNotExist( |
620
|
|
|
$pre."items", |
621
|
|
|
"pw_iv", |
622
|
|
|
"TEXT NOT null" |
623
|
|
|
); |
624
|
|
|
$res2 = addColumnIfNotExist( |
625
|
|
|
$pre."items", |
626
|
|
|
"pw_len", |
627
|
|
|
"INT(5) NOT null DEFAULT '0'" |
628
|
|
|
); |
629
|
|
|
$res2 = addColumnIfNotExist( |
630
|
|
|
$pre."items", |
631
|
|
|
"auto_update_pwd_frequency", |
632
|
|
|
"TINYINT(2) NOT NULL DEFAULT '0'" |
633
|
|
|
); |
634
|
|
|
$res2 = addColumnIfNotExist( |
635
|
|
|
$pre."items", |
636
|
|
|
"auto_update_pwd_next_date", |
637
|
|
|
"INT(15) NOT NULL DEFAULT '0'" |
638
|
|
|
); |
639
|
|
|
$res2 = addColumnIfNotExist( |
640
|
|
|
$pre."cache", |
641
|
|
|
"renewal_period", |
642
|
|
|
"TINYINT(4) NOT null DEFAULT '0'" |
643
|
|
|
); |
644
|
|
|
$res2 = addColumnIfNotExist( |
645
|
|
|
$pre."suggestion", |
646
|
|
|
"pw_len", |
647
|
|
|
"int(5) NOT null DEFAULT '0'" |
648
|
|
|
); |
649
|
|
|
|
650
|
|
|
// Clean timestamp for users table |
651
|
|
|
mysqli_query($db_link, "UPDATE ".$pre."users SET timestamp = ''"); |
652
|
|
|
|
653
|
|
|
## Alter nested_tree table |
654
|
|
|
$res2 = addColumnIfNotExist( |
655
|
|
|
$pre."nested_tree", |
656
|
|
|
"personal_folder", |
657
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
658
|
|
|
); |
659
|
|
|
$res2 = addColumnIfNotExist( |
660
|
|
|
$pre."nested_tree", |
661
|
|
|
"renewal_period", |
662
|
|
|
"TINYINT(4) NOT null DEFAULT '0'" |
663
|
|
|
); |
664
|
|
|
|
665
|
|
|
addIndexIfNotExist( |
666
|
|
|
$pre.'nested_tree', |
667
|
|
|
'personal_folder_idx', |
668
|
|
|
'ADD INDEX `personal_folder_idx` (`personal_folder`)' |
669
|
|
|
); |
670
|
|
|
|
671
|
|
|
|
672
|
|
|
#to 1.08 |
|
|
|
|
673
|
|
|
//include('upgrade_db_1.08.php'); |
674
|
|
|
|
675
|
|
|
## TABLE TAGS |
676
|
|
|
$res8 = mysqli_query( |
677
|
|
|
$db_link, |
678
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."tags` ( |
679
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
680
|
|
|
`tag` varchar(30) NOT NULL, |
681
|
|
|
`item_id` int(12) NOT NULL, |
682
|
|
|
PRIMARY KEY (`id`), |
683
|
|
|
UNIQUE KEY `id` (`id`) |
684
|
|
|
);" |
685
|
|
|
); |
686
|
|
|
if (mysqli_error($db_link)) { |
687
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table TAGS! '.addslashes(mysqli_error($db_link)).'"}]'; |
688
|
|
|
mysqli_close($db_link); |
689
|
|
|
exit(); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
## TABLE LOG_SYSTEM |
693
|
|
|
$res8 = mysqli_query( |
694
|
|
|
$db_link, |
695
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."log_system` ( |
696
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
697
|
|
|
`type` varchar(20) NOT NULL, |
698
|
|
|
`date` varchar(30) NOT NULL, |
699
|
|
|
`label` text NOT NULL, |
700
|
|
|
`qui` varchar(30) NOT NULL, |
701
|
|
|
PRIMARY KEY (`id`) |
702
|
|
|
);" |
703
|
|
|
); |
704
|
|
|
if (empty(mysqli_error($db_link)) === true) { |
705
|
|
|
mysqli_query( |
706
|
|
|
$db_link, |
707
|
|
|
"ALTER TABLE ".$pre."log_system |
708
|
|
|
ADD `field_1` VARCHAR(250) NOT NULL" |
709
|
|
|
); |
710
|
|
|
} else { |
711
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table LOG_SYSTEM! '.addslashes(mysqli_error($db_link)).'"}]'; |
712
|
|
|
mysqli_close($db_link); |
713
|
|
|
exit(); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
## TABLE 10 - FILES |
717
|
|
|
$res9 = mysqli_query( |
718
|
|
|
$db_link, |
719
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."files` ( |
720
|
|
|
`id` int(11) NOT null AUTO_INCREMENT, |
721
|
|
|
`id_item` int(11) NOT NULL, |
722
|
|
|
`name` varchar(100) NOT NULL, |
723
|
|
|
`size` int(10) NOT NULL, |
724
|
|
|
`extension` varchar(10) NOT NULL, |
725
|
|
|
`type` varchar(50) NOT NULL, |
726
|
|
|
`file` varchar(50) NOT NULL, |
727
|
|
|
PRIMARY KEY (`id`) |
728
|
|
|
);" |
729
|
|
|
); |
730
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
731
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table FILES! '.addslashes(mysqli_error($db_link)).'"}]'; |
732
|
|
|
mysqli_close($db_link); |
733
|
|
|
exit(); |
734
|
|
|
} |
735
|
|
|
mysqli_query( |
736
|
|
|
$db_link, |
737
|
|
|
"ALTER TABLE `".$pre."files` |
738
|
|
|
CHANGE id id INT(11) AUTO_INCREMENT PRIMARY KEY;" |
739
|
|
|
); |
740
|
|
|
mysqli_query( |
741
|
|
|
$db_link, |
742
|
|
|
"ALTER TABLE `".$pre."files` |
743
|
|
|
CHANGE name name VARCHAR(100) NOT NULL;" |
744
|
|
|
); |
745
|
|
|
|
746
|
|
|
## TABLE CACHE |
747
|
|
|
mysqli_query($db_link, "DROP TABLE IF EXISTS `".$pre."cache`"); |
748
|
|
|
$res8 = mysqli_query( |
749
|
|
|
$db_link, |
750
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."cache` ( |
751
|
|
|
`id` int(12) NOT NULL, |
752
|
|
|
`label` varchar(50) NOT NULL, |
753
|
|
|
`description` text NOT NULL, |
754
|
|
|
`tags` text NOT NULL, |
755
|
|
|
`id_tree` int(12) NOT NULL, |
756
|
|
|
`perso` tinyint(1) NOT NULL, |
757
|
|
|
`restricted_to` varchar(200) NOT NULL, |
758
|
|
|
`login` varchar(200) NOT NULL, |
759
|
|
|
`folder` varchar(300) NOT NULL, |
760
|
|
|
`author` varchar(50) NOT NULL, |
761
|
|
|
`renewal_period` TINYINT(4) NOT null DEFAULT '0' |
762
|
|
|
);" |
763
|
|
|
); |
764
|
|
|
if (empty(mysqli_error($db_link)) === true) { |
765
|
|
|
//ADD VALUES |
766
|
|
|
$sql = "SELECT * |
767
|
|
|
FROM ".$pre."items as i |
768
|
|
|
INNER JOIN ".$pre."log_items as l ON (l.id_item = i.id) |
769
|
|
|
AND l.action = 'at_creation' |
770
|
|
|
WHERE i.inactif=0"; |
771
|
|
|
$rows = mysqli_query($db_link, $sql); |
772
|
|
|
while ($reccord = mysqli_fetch_array($rows)) { |
|
|
|
|
773
|
|
|
//Get all TAGS |
774
|
|
|
$tags = ""; |
775
|
|
|
$itemsRes = mysqli_query( |
776
|
|
|
$db_link, |
777
|
|
|
"SELECT tag FROM ".$pre."tags |
778
|
|
|
WHERE item_id=".$reccord['id'] |
779
|
|
|
) or die(mysqli_error($db_link)); |
|
|
|
|
780
|
|
|
$itemTags = mysqli_fetch_array($itemsRes); |
781
|
|
|
if (!empty($itemTags)) { |
782
|
|
|
foreach ($itemTags as $itemTag) { |
783
|
|
|
if (!empty($itemTag['tag'])) { |
784
|
|
|
$tags .= $itemTag['tag']." "; |
785
|
|
|
} |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
//form id_tree to full foldername |
789
|
|
|
$folder = ""; |
790
|
|
|
$arbo = $tree->getPath($reccord['id_tree'], true); |
791
|
|
|
foreach ($arbo as $elem) { |
792
|
|
|
$folder .= htmlspecialchars(stripslashes($elem->title), ENT_QUOTES)." > "; |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
//store data |
796
|
|
|
mysqli_query( |
797
|
|
|
$db_link, |
798
|
|
|
"INSERT INTO ".$pre."cache |
799
|
|
|
VALUES ( |
800
|
|
|
'".$reccord['id']."', |
801
|
|
|
'".$reccord['label']."', |
802
|
|
|
'".$reccord['description']."', |
803
|
|
|
'".$tags."', |
804
|
|
|
'".$reccord['id_tree']."', |
805
|
|
|
'".$reccord['perso']."', |
806
|
|
|
'".$reccord['restricted_to']."', |
807
|
|
|
'".$reccord['login']."', |
808
|
|
|
'".$folder."', |
809
|
|
|
'".$reccord['id_user']."', |
810
|
|
|
0 |
811
|
|
|
)" |
812
|
|
|
); |
813
|
|
|
} |
814
|
|
|
} else { |
815
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table CACHE! '.addslashes(mysqli_error($db_link)).'"}]'; |
816
|
|
|
mysqli_close($db_link); |
817
|
|
|
exit(); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
/* |
821
|
|
|
* Change table FUNCTIONS |
822
|
|
|
* By 2 tables ROLES |
823
|
|
|
*/ |
824
|
|
|
$res9 = mysqli_query( |
825
|
|
|
$db_link, |
826
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."roles_title` ( |
827
|
|
|
`id` int(12) NOT NULL, |
828
|
|
|
`title` varchar(50) NOT NULL, |
829
|
|
|
`allow_pw_change` TINYINT(1) NOT null DEFAULT '0', |
830
|
|
|
`complexity` INT(5) NOT null DEFAULT '0', |
831
|
|
|
`creator_id` int(11) NOT null DEFAULT '0' |
832
|
|
|
);" |
833
|
|
|
); |
834
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
835
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table roles_title! '.addslashes(mysqli_error($db_link)).'"}]'; |
836
|
|
|
mysqli_close($db_link); |
837
|
|
|
exit(); |
838
|
|
|
} |
839
|
|
|
addColumnIfNotExist( |
840
|
|
|
$pre."roles_title", |
841
|
|
|
"allow_pw_change", |
842
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
843
|
|
|
); |
844
|
|
|
addColumnIfNotExist( |
845
|
|
|
$pre."roles_title", |
846
|
|
|
"complexity", |
847
|
|
|
"INT(5) NOT null DEFAULT '0'" |
848
|
|
|
); |
849
|
|
|
addColumnIfNotExist( |
850
|
|
|
$pre."roles_title", |
851
|
|
|
"creator_id", |
852
|
|
|
"INT(11) NOT null DEFAULT '0'" |
853
|
|
|
); |
854
|
|
|
|
855
|
|
|
$res10 = mysqli_query( |
856
|
|
|
$db_link, |
857
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."roles_values` ( |
858
|
|
|
`role_id` int(12) NOT NULL, |
859
|
|
|
`folder_id` int(12) NOT NULL |
860
|
|
|
);" |
861
|
|
|
); |
862
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
863
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table roles_values! '.addslashes(mysqli_error($db_link)).'"}]'; |
864
|
|
|
mysqli_close($db_link); |
865
|
|
|
exit(); |
866
|
|
|
} |
867
|
|
|
if (tableExists($pre."functions")) { |
868
|
|
|
$tableFunctionExists = true; |
869
|
|
|
} else { |
870
|
|
|
$tableFunctionExists = false; |
871
|
|
|
} |
872
|
|
|
if ($tableFunctionExists === true) { |
873
|
|
|
//Get data from tables FUNCTIONS and populate new ROLES tables |
874
|
|
|
$rows = mysqli_query( |
875
|
|
|
$db_link, |
876
|
|
|
"SELECT * FROM ".$pre."functions" |
877
|
|
|
); |
878
|
|
|
while ($reccord = mysqli_fetch_array($rows)) { |
879
|
|
|
//Add new role title |
880
|
|
|
mysqli_query( |
881
|
|
|
$db_link, |
882
|
|
|
"INSERT INTO ".$pre."roles_title |
883
|
|
|
VALUES ( |
884
|
|
|
'".$reccord['id']."', |
885
|
|
|
'".$reccord['title']."' |
886
|
|
|
)" |
887
|
|
|
); |
888
|
|
|
|
889
|
|
|
//Add each folder in roles_values |
890
|
|
|
foreach (explode(';', $reccord['groupes_visibles']) as $folderId) { |
891
|
|
|
if (!empty($folderId)) { |
892
|
|
|
mysqli_query( |
893
|
|
|
$db_link, |
894
|
|
|
"INSERT INTO ".$pre."roles_values |
895
|
|
|
VALUES ( |
896
|
|
|
'".$reccord['id']."', |
897
|
|
|
'".$folderId."' |
898
|
|
|
)" |
899
|
|
|
); |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
//Now alter table roles_title in order to create a primary index |
905
|
|
|
mysqli_query( |
906
|
|
|
$db_link, |
907
|
|
|
"ALTER TABLE `".$pre."roles_title` |
908
|
|
|
ADD PRIMARY KEY(`id`)" |
909
|
|
|
); |
910
|
|
|
mysqli_query( |
911
|
|
|
$db_link, |
912
|
|
|
"ALTER TABLE `".$pre."roles_title` |
913
|
|
|
CHANGE `id` `id` INT(12) NOT null AUTO_INCREMENT " |
914
|
|
|
); |
915
|
|
|
addColumnIfNotExist( |
916
|
|
|
$pre."roles_title", |
917
|
|
|
"allow_pw_change", |
918
|
|
|
"TINYINT(1) NOT null DEFAULT '0'" |
919
|
|
|
); |
920
|
|
|
|
921
|
|
|
//Drop old table |
922
|
|
|
mysqli_query($db_link, "DROP TABLE ".$pre."functions"); |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
## TABLE KB |
926
|
|
|
$res = mysqli_query( |
927
|
|
|
$db_link, |
928
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."kb` ( |
929
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
930
|
|
|
`category_id` int(12) NOT NULL, |
931
|
|
|
`label` varchar(200) NOT NULL, |
932
|
|
|
`description` text NOT NULL, |
933
|
|
|
`author_id` int(12) NOT NULL, |
934
|
|
|
`anyone_can_modify` tinyint(1) NOT null DEFAULT '0', |
935
|
|
|
PRIMARY KEY (`id`) |
936
|
|
|
);" |
937
|
|
|
); |
938
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
939
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table KB! '.addslashes(mysqli_error($db_link)).'"}]'; |
940
|
|
|
mysqli_close($db_link); |
941
|
|
|
exit(); |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
## TABLE KB_CATEGORIES |
945
|
|
|
$res = mysqli_query( |
946
|
|
|
$db_link, |
947
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."kb_categories` ( |
948
|
|
|
`id` int(12) NOT null AUTO_INCREMENT, |
949
|
|
|
`category` varchar(50) NOT NULL, |
950
|
|
|
PRIMARY KEY (`id`) |
951
|
|
|
);" |
952
|
|
|
); |
953
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
954
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table KB_CATEGORIES! '.addslashes(mysqli_error($db_link)).'"}]'; |
955
|
|
|
mysqli_close($db_link); |
956
|
|
|
exit(); |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
## TABLE KB_ITEMS |
960
|
|
|
$res = mysqli_query( |
961
|
|
|
$db_link, |
962
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."kb_items` ( |
963
|
|
|
`kb_id` tinyint(12) NOT NULL, |
964
|
|
|
`item_id` tinyint(12) NOT NULL |
965
|
|
|
);" |
966
|
|
|
); |
967
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
968
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table KB_ITEMS! '.addslashes(mysqli_error($db_link)).'"}]'; |
969
|
|
|
mysqli_close($db_link); |
970
|
|
|
exit(); |
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
## TABLE restriction_to_roles |
974
|
|
|
$res = mysqli_query( |
975
|
|
|
$db_link, |
976
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."restriction_to_roles` ( |
977
|
|
|
`role_id` tinyint(12) NOT NULL, |
978
|
|
|
`item_id` tinyint(12) NOT NULL |
979
|
|
|
) CHARSET=utf8;" |
980
|
|
|
); |
981
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
982
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table RESTRICTION_TO_ROLES! '.addslashes(mysqli_error($db_link)).'"}]'; |
983
|
|
|
mysqli_close($db_link); |
984
|
|
|
exit(); |
985
|
|
|
} else { |
986
|
|
|
$res = addIndexIfNotExist($pre.'restriction_to_roles', 'role_id_idx', 'ADD INDEX `role_id_idx` (`role_id`)'); |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
## TABLE Languages |
990
|
|
|
$res = mysqli_query( |
991
|
|
|
$db_link, |
992
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."languages` ( |
993
|
|
|
`id` INT(10) NOT null AUTO_INCREMENT PRIMARY KEY , |
994
|
|
|
`name` VARCHAR(50) NOT null , |
995
|
|
|
`label` VARCHAR(50) NOT null , |
996
|
|
|
`code` VARCHAR(10) NOT null , |
997
|
|
|
`flag` VARCHAR(30) NOT NULL |
998
|
|
|
) CHARSET=utf8;" |
999
|
|
|
); |
1000
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1001
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table LANGUAGES! '.addslashes(mysqli_error($db_link)).'"}]'; |
1002
|
|
|
mysqli_close($db_link); |
1003
|
|
|
exit(); |
1004
|
|
|
} |
1005
|
|
|
$resTmp = mysqli_fetch_row( |
1006
|
|
|
mysqli_query($db_link, "SELECT COUNT(*) FROM ".$pre."languages") |
1007
|
|
|
); |
1008
|
|
|
mysqli_query($db_link, "TRUNCATE TABLE ".$pre."languages"); |
1009
|
|
|
mysqli_query( |
1010
|
|
|
$db_link, |
1011
|
|
|
"INSERT IGNORE INTO `".$pre."languages` |
1012
|
|
|
(`id`, `name`, `label`, `code`, `flag`) VALUES |
1013
|
|
|
('', 'french', 'French' , 'fr', 'fr.png'), |
1014
|
|
|
('', 'english', 'English' , 'us', 'us.png'), |
1015
|
|
|
('', 'spanish', 'Spanish' , 'es', 'es.png'), |
1016
|
|
|
('', 'german', 'German' , 'de', 'de.png'), |
1017
|
|
|
('', 'czech', 'Czech' , 'cz', 'cz.png'), |
1018
|
|
|
('', 'italian', 'Italian' , 'it', 'it.png'), |
1019
|
|
|
('', 'russian', 'Russian' , 'ru', 'ru.png'), |
1020
|
|
|
('', 'turkish', 'Turkish' , 'tr', 'tr.png'), |
1021
|
|
|
('', 'norwegian', 'Norwegian' , 'no', 'no.png'), |
1022
|
|
|
('', 'japanese', 'Japanese' , 'ja', 'ja.png'), |
1023
|
|
|
('', 'portuguese', 'Portuguese' , 'pr', 'pr.png'), |
1024
|
|
|
('', 'chinese', 'Chinese' , 'cn', 'cn.png'), |
1025
|
|
|
('', 'swedish', 'Swedish' , 'se', 'se.png'), |
1026
|
|
|
('', 'dutch', 'Dutch' , 'nl', 'nl.png'), |
1027
|
|
|
('', 'catalan', 'Catalan' , 'ct', 'ct.png'), |
1028
|
|
|
('', 'vietnamese', 'Vietnamese' , 'vi', 'vi.png'), |
1029
|
|
|
('', 'estonian', 'Estonian' , 'ee', 'ee.png');" |
1030
|
|
|
); |
1031
|
|
|
|
1032
|
|
|
## TABLE EMAILS |
1033
|
|
|
$res = mysqli_query( |
1034
|
|
|
$db_link, |
1035
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."emails` ( |
1036
|
|
|
`timestamp` INT(30) NOT null , |
1037
|
|
|
`subject` VARCHAR(255) NOT null , |
1038
|
|
|
`body` TEXT NOT null , |
1039
|
|
|
`receivers` VARCHAR(255) NOT null , |
1040
|
|
|
`status` VARCHAR(30) NOT NULL |
1041
|
|
|
) CHARSET=utf8;" |
1042
|
|
|
); |
1043
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1044
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table EMAILS! '.addslashes(mysqli_error($db_link)).'"}]'; |
1045
|
|
|
mysqli_close($db_link); |
1046
|
|
|
exit(); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
## TABLE AUTOMATIC DELETION |
1050
|
|
|
$res = mysqli_query( |
1051
|
|
|
$db_link, |
1052
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."automatic_del` ( |
1053
|
|
|
`item_id` int(11) NOT NULL, |
1054
|
|
|
`del_enabled` tinyint(1) NOT NULL, |
1055
|
|
|
`del_type` tinyint(1) NOT NULL, |
1056
|
|
|
`del_value` varchar(35) NOT NULL |
1057
|
|
|
) CHARSET=utf8;" |
1058
|
|
|
); |
1059
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1060
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table AUTOMATIC_DEL! '.addslashes(mysqli_error($db_link)).'"}]'; |
1061
|
|
|
mysqli_close($db_link); |
1062
|
|
|
exit(); |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
## TABLE items_edition |
1066
|
|
|
$res = mysqli_query( |
1067
|
|
|
$db_link, |
1068
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."items_edition` ( |
1069
|
|
|
`item_id` int(11) NOT NULL, |
1070
|
|
|
`user_id` int(11) NOT NULL, |
1071
|
|
|
`timestamp` varchar(50) NOT NULL |
1072
|
|
|
) CHARSET=utf8;" |
1073
|
|
|
); |
1074
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1075
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table items_edition! '.addslashes(mysqli_error($db_link)).'"}]'; |
1076
|
|
|
mysqli_close($db_link); |
1077
|
|
|
exit(); |
1078
|
|
|
} |
1079
|
|
|
|
1080
|
|
|
## TABLE categories |
1081
|
|
|
$res = mysqli_query( |
1082
|
|
|
$db_link, |
1083
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."categories` ( |
1084
|
|
|
`id` int(12) NOT NULL AUTO_INCREMENT, |
1085
|
|
|
`parent_id` int(12) NOT NULL, |
1086
|
|
|
`title` varchar(255) NOT NULL, |
1087
|
|
|
`level` int(2) NOT NULL, |
1088
|
|
|
`description` text NOT NULL, |
1089
|
|
|
`type` varchar(50) NOT NULL, |
1090
|
|
|
`order` int(12) NOT NULL, |
1091
|
|
|
PRIMARY KEY (`id`) |
1092
|
|
|
) CHARSET=utf8;" |
1093
|
|
|
); |
1094
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1095
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table CATEGORIES! '.addslashes(mysqli_error($db_link)).'"}]'; |
1096
|
|
|
mysqli_close($db_link); |
1097
|
|
|
exit(); |
1098
|
|
|
} |
1099
|
|
|
|
1100
|
|
|
## TABLE categories_items |
1101
|
|
|
$res = mysqli_query( |
1102
|
|
|
$db_link, |
1103
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."categories_items` ( |
1104
|
|
|
`id` int(12) NOT NULL AUTO_INCREMENT, |
1105
|
|
|
`field_id` int(11) NOT NULL, |
1106
|
|
|
`item_id` int(11) NOT NULL, |
1107
|
|
|
`data` text NOT NULL, |
1108
|
|
|
PRIMARY KEY (`id`) |
1109
|
|
|
) CHARSET=utf8;" |
1110
|
|
|
); |
1111
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1112
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table categories_items! '.addslashes(mysqli_error($db_link)).'"}]'; |
1113
|
|
|
mysqli_close($db_link); |
1114
|
|
|
exit(); |
1115
|
|
|
} |
1116
|
|
|
|
1117
|
|
|
## TABLE categories_folders |
1118
|
|
|
$res = mysqli_query( |
1119
|
|
|
$db_link, |
1120
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."categories_folders` ( |
1121
|
|
|
`id_category` int(12) NOT NULL, |
1122
|
|
|
`id_folder` int(12) NOT NULL |
1123
|
|
|
) CHARSET=utf8;" |
1124
|
|
|
); |
1125
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1126
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table categories_folders! '.addslashes(mysqli_error($db_link)).'"}]'; |
1127
|
|
|
mysqli_close($db_link); |
1128
|
|
|
exit(); |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
## TABLE api |
1132
|
|
|
$res = mysqli_query( |
1133
|
|
|
$db_link, |
1134
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."api` ( |
1135
|
|
|
`id` int(20) NOT NULL AUTO_INCREMENT, |
1136
|
|
|
`type` varchar(15) NOT NULL, |
1137
|
|
|
`label` varchar(255) NOT NULL, |
1138
|
|
|
`value` varchar(255) NOT NULL, |
1139
|
|
|
`timestamp` varchar(50) NOT NULL, |
1140
|
|
|
PRIMARY KEY (`id`) |
1141
|
|
|
) CHARSET=utf8;" |
1142
|
|
|
); |
1143
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1144
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table API! '.addslashes(mysqli_error($db_link)).'"}]'; |
1145
|
|
|
mysqli_close($db_link); |
1146
|
|
|
exit(); |
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
## TABLE otv |
1150
|
|
|
$res = mysqli_query( |
1151
|
|
|
$db_link, |
1152
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."otv` ( |
1153
|
|
|
`id` int(10) NOT NULL AUTO_INCREMENT, |
1154
|
|
|
`timestamp` text NOT NULL, |
1155
|
|
|
`code` varchar(100) NOT NULL, |
1156
|
|
|
`item_id` int(12) NOT NULL, |
1157
|
|
|
`originator` tinyint(12) NOT NULL, |
1158
|
|
|
PRIMARY KEY (`id`) |
1159
|
|
|
) CHARSET=utf8;" |
1160
|
|
|
); |
1161
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1162
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table OTV! '.addslashes(mysqli_error($db_link)).'"}]'; |
1163
|
|
|
mysqli_close($db_link); |
1164
|
|
|
exit(); |
1165
|
|
|
} |
1166
|
|
|
|
1167
|
|
|
## TABLE suggestion |
1168
|
|
|
$res = mysqli_query( |
1169
|
|
|
$db_link, |
1170
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."suggestion` ( |
1171
|
|
|
`id` tinyint(12) NOT NULL AUTO_INCREMENT, |
1172
|
|
|
`label` varchar(255) NOT NULL, |
1173
|
|
|
`pw` text NOT NULL, |
1174
|
|
|
`pw_iv` text NOT NULL, |
1175
|
|
|
`pw_len` int(5) NOT NULL, |
1176
|
|
|
`description` text NOT NULL, |
1177
|
|
|
`author_id` int(12) NOT NULL, |
1178
|
|
|
`folder_id` int(12) NOT NULL, |
1179
|
|
|
`comment` text NOT NULL, |
1180
|
|
|
PRIMARY KEY (`id`) |
1181
|
|
|
) CHARSET=utf8;" |
1182
|
|
|
); |
1183
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1184
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table SUGGESTIONS! '.addslashes(mysqli_error($db_link)).'"}]'; |
1185
|
|
|
mysqli_close($db_link); |
1186
|
|
|
exit(); |
1187
|
|
|
} |
1188
|
|
|
|
1189
|
|
|
# TABLE EXPORT |
1190
|
|
|
mysqli_query( |
1191
|
|
|
$db_link, |
1192
|
|
|
"CREATE TABLE IF NOT EXISTS `".$pre."export` ( |
1193
|
|
|
`id` int(12) NOT NULL, |
1194
|
|
|
`label` varchar(255) NOT NULL, |
1195
|
|
|
`login` varchar(100) NOT NULL, |
1196
|
|
|
`description` text NOT NULL, |
1197
|
|
|
`pw` text NOT NULL, |
1198
|
|
|
`path` varchar(255) NOT NULL |
1199
|
|
|
) CHARSET=utf8;" |
1200
|
|
|
); |
1201
|
|
|
if (empty(mysqli_error($db_link)) === false) { |
1202
|
|
|
echo '[{"finish":"1", "msg":"", "error":"An error appears on table export! '.addslashes(mysqli_error($db_link)).'"}]'; |
1203
|
|
|
mysqli_close($db_link); |
1204
|
|
|
exit(); |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
//CLEAN UP ITEMS TABLE |
1208
|
|
|
$allowedTags = '<b><i><sup><sub><em><strong><u><br><br /><a><strike><ul>'. |
1209
|
|
|
'<blockquote><blockquote><img><li><h1><h2><h3><h4><h5><ol><small><font>'; |
1210
|
|
|
$cleanRes = mysqli_query( |
1211
|
|
|
$db_link, |
1212
|
|
|
"SELECT id,description FROM `".$pre."items`" |
1213
|
|
|
); |
1214
|
|
|
while ($cleanData = mysqli_fetch_array($cleanRes)) { |
1215
|
|
|
mysqli_query( |
1216
|
|
|
$db_link, |
1217
|
|
|
"UPDATE `".$pre."items` |
1218
|
|
|
SET description = '".strip_tags($cleanData['description'], $allowedTags). |
1219
|
|
|
"' WHERE id = ".$cleanData['id'] |
1220
|
|
|
); |
1221
|
|
|
} |
1222
|
|
|
|
1223
|
|
|
// 2.1.23 - check if personal need to be upgraded |
1224
|
|
|
$tmpResult = mysqli_query( |
1225
|
|
|
$db_link, |
1226
|
|
|
"SELECT `pw`, `pw_iv` FROM ".$pre."items WHERE perso='1'" |
1227
|
|
|
); |
1228
|
|
|
$tmp = mysqli_fetch_row($tmpResult); |
1229
|
|
|
if ($tmp[1] === "" && substr($tmp[0], 0, 3) !== "def") { |
1230
|
|
|
mysqli_query($db_link, "UPDATE ".$pre."users SET upgrade_needed = true WHERE 1 = 1"); |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/*// Since 2.1.17, encrypt process is changed. |
|
|
|
|
1234
|
|
|
// Previous PW need to be re-encrypted |
1235
|
|
|
if (@mysqli_query( |
1236
|
|
|
$db_link, |
1237
|
|
|
"SELECT valeur FROM ".$pre."misc |
1238
|
|
|
WHERE type='admin' AND intitule = 'encryption_protocol'" |
1239
|
|
|
)) { |
1240
|
|
|
$tmpResult = mysqli_query( |
1241
|
|
|
$db_link, |
1242
|
|
|
"SELECT valeur FROM ".$pre."misc |
1243
|
|
|
WHERE type='admin' AND intitule = 'encryption_protocol'" |
1244
|
|
|
); |
1245
|
|
|
$tmp = mysqli_fetch_row($tmpResult); |
1246
|
|
|
if ($tmp[0] != "ctr") { |
1247
|
|
|
//count elem |
1248
|
|
|
$res = mysqli_query( |
1249
|
|
|
$db_link, |
1250
|
|
|
"SELECT COUNT(*) FROM ".$pre."items |
1251
|
|
|
WHERE perso = '0'" |
1252
|
|
|
); |
1253
|
|
|
$data = mysqli_fetch_row($res); |
1254
|
|
|
if ($data[0] > 0) { |
1255
|
|
|
echo '$("#change_pw_encryption, #change_pw_encryption_progress").show();'; |
1256
|
|
|
echo '$("#change_pw_encryption_progress").html('. |
1257
|
|
|
'"Number of Passwords to re-encrypt: '.$data[0].'");'; |
1258
|
|
|
echo '$("#change_pw_encryption_total").val("'.$data[0].'")'; |
1259
|
|
|
exit(); |
1260
|
|
|
} |
1261
|
|
|
|
1262
|
|
|
} |
1263
|
|
|
}*/ |
1264
|
|
|
|
1265
|
|
|
mysqli_close($db_link); |
1266
|
|
|
|
1267
|
|
|
echo '[{"finish":"1", "msg":"Database has been populated with Original Data.", "error":""}]'; |
1268
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.