/
install.js
executable file
·361 lines (334 loc) · 14.4 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
* Teampass - a collaborative passwords manager.
* ---
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* ---
* @project Teampass
* @version
* @file install.js
* ---
* @author Nils Laumaillé (nils@teampass.net)
* @copyright 2009-2023 Teampass.net
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
* ---
* @see https://www.teampass.net
*/
$(function() {
$("#but_next").click(function(event) {
$("#step").val($(this).attr("target_id"));
document.upgrade.submit();
});
// no paste
$("#admin_pwd").bind("paste",function(e) {
alert("Paste option is disabled !!");
e.preventDefault();
});
/*
* Removing automatic action
// Auto start
if ($("#step").val() == 5) {
$('#but_launch').trigger('click');
}
*/
});
function aesEncrypt(text)
{
return Aes.Ctr.encrypt(text, "cpm", 128);
}
var global_error_on_query = false,
step = "",
dataToUse = "",
dbInfo = "",
index = "",
multiple = "",
jsonValues = "";
function checkPage()
{
step = $("#step").val();
dataToUse = "";
error = "";
index = "";
tasks = [];
dbInfo = [];
multiple = "";
tsk = "";
$("#step_error").addClass("hidden").html("");
$("#res_"+step).html("");
alertify
.message('Working on it... <i class="fas fa-cog fa-spin fa-2x"></i>', 0)
.dismissOthers();
if (step === "2") {
// STEP 2
if ($("#url_path").val() === "" || $("#absolute_path").val() === "") {
error = "Fields need to be filled in!";
} else {
jsonValues = {"absolute_path":$("#absolute_path").val(), "url_path":$("#url_path").val()};
dataToUse = JSON.stringify(jsonValues);
tasks = ["folder*install", "folder*includes", "folder*includes/config", "folder*includes/avatars", "folder*includes/libraries/csrfp/libs", "folder*includes/libraries/csrfp/js", "folder*includes/libraries/csrfp/log", "extension*mbstring", "extension*openssl", "extension*bcmath", "extension*iconv", "extension*gd", "extension*xml", "extension*curl", "version*php", "ini*max_execution_time", "extension*gmp", "folder*files", "folder*upload"];
multiple = true;
$("#hid_absolute_path").val($("#absolute_path").val());
$("#hid_url_path").val($("#url_path").val());
}
} else if (step === "3") {
// STEP 3
if ($("#db_host").val() === "" || $("#db_db").val() === "" || $("#db_login").val() === "" || $("#db_port").val() === "") {
error = "Fields need to be filled in!";
} else if ($("#db_pw").val().indexOf('"') > -1) {
error = "Double quotes in password not allowed!";
} else {
jsonValues = {"db_host":$("#db_host").val(), "db_bdd":$("#db_bdd").val(), "db_login":$("#db_login").val(), "db_pw":$("#db_pw").val(), "db_port":$("#db_port").val(), "absolute_path":$("#hid_absolute_path").val(), "url_path":$("#hid_url_path").val()};
dataToUse = JSON.stringify(jsonValues);
tasks = ["connection*test"];
multiple = "";
$("#hid_db_host").val($("#db_host").val());
$("#hid_db_bdd").val($("#db_bdd").val());
$("#hid_db_login").val($("#db_login").val());
$("#hid_db_pwd").val($("#db_pw").val());
$("#hid_db_port").val($("#db_port").val());
}
} else if (step === "4") {
// STEP 4
if ($("#admin_pwd").val() === "") {
alertify
.error('<i class="fas fa-ban mr-2"></i>You must define a password for Administrator account.', 10)
.dismissOthers();
return false;
} else if ($("#admin_pwd_confirm").val() === "") {
alertify
.error('<i class="fas fa-ban mr-2"></i>You must confirm the password for Administrator account.', 10)
.dismissOthers();
return false;
} else if ($("#admin_pwd_confirm").val() !== $("#admin_pwd").val()) {
alertify
.error('<i class="fas fa-ban mr-2"></i>Administrator passwords are not similar.', 10)
.dismissOthers();
return false;
} else{
$("#hid_db_pre").val($("#tbl_prefix").val());
jsonValues = {"tbl_prefix":sanitizeString($("#tbl_prefix").val()), "sk_path":sanitizeString($("#sk_path").val()), "admin_pwd":sanitizeString($("#admin_pwd").val()), "send_stats":""};
dataToUse = JSON.stringify(jsonValues);
tasks = ["misc*preparation"];
multiple = "";
}
} else if (step === "5") {
// STEP 5
dataToUse = "";
tasks = ["table*utf8", "table*api", "table*automatic_del", "table*cache", "table*cache_tree", "table*categories", "table*categories_folders", "table*categories_items", "table*defuse_passwords", "table*emails", "table*export", "table*files", "table*items", "table*items_change", "table*items_edition", "table*kb", "table*kb_categories", "table*kb_items", "table*ldap_groups_roles", "table*languages", "table*log_items", "table*log_system", "table*misc", "table*nested_tree", "table*notification", "table*otv", "table*processes", "table*processes_tasks", "table*processes_logs", "table*restriction_to_roles", "table*rights", "table*roles_title", "table*roles_values", "table*sharekeys_fields", "table*sharekeys_files", "table*sharekeys_items", "table*sharekeys_logs", "table*sharekeys_suggestions", "table*suggestion", "table*tags", "table*templates", "table*tokens", "table*users"];
multiple = true;
} else if (step === "6") {
// STEP 6
jsonValues = {"url_path":sanitizeString($("#hid_url_path").val())};
dataToUse = JSON.stringify(jsonValues);
tasks = ["install*init", "file*security", "file*settings.php", "file*csrfp-token", "install*cleanup", "install*cronJob"];
multiple = true;
}
// launch query
if (error === "" && multiple === true) {
global_error_on_query = false;
index = 0;
dbInfo = {"db_host" : $("#hid_db_host").val(), "db_bdd" : $("#hid_db_bdd").val(), "db_login" : $("#hid_db_login").val(), "db_pw" : $("#hid_db_pwd").val(), "db_port" : $("#hid_db_port").val(), "db_pre" : $("#hid_db_pre").val()};
$("#step_res").val("true");
$("#pop_db").html("");
var promise = tasks.slice(1)
.reduce(
(a,b) => a.then(doGetJson.bind(null, b)),
doGetJson(
tasks[0]
)
);
promise.then(function(){
// do something when all requests are ready
// all requests are complete
if ($("#step_res").val() === "false" || global_error_on_query === true) {
alertify
.error('<i class="fas fa-ban mr-2"></i>At least one task has failed! Please correct and relaunch.', 0)
.dismissOthers();
return false;
} else {
alertify
.success('<i class="fas fa-check text-success mr-2"></i><b>Done</b>.<br>Click next to continue', 1)
.dismissOthers();
$("#but_launch")
.prop("disabled", true)
.addClass("hidden");
$("#but_next")
.prop("disabled", false)
.removeClass("hidden");
// Hide restart button at end of step 6 if successful
if (step === "6") {
$("#but_restart")
.prop("disabled", true)
.addClass("hidden");
}
/*
* Removing automatic action
// Go to next step
if (step <= 6) {
setTimeout(
function(){
$('#but_next').trigger('click');
},
1000
);
}
*/
}
});
} else if (error === "" && multiple === "") {
tsk = tasks[0].split("*");
dbInfo = {"db_host" : $("#hid_db_host").val(), "db_bdd" : $("#hid_db_bdd").val(), "db_login" : $("#hid_db_login").val(), "db_pw" : $("#hid_db_pwd").val(), "db_port" : $("#hid_db_port").val()};
dataToUse = {
type: "step_"+step,
data: aesEncrypt(dataToUse),
activity: aesEncrypt(tsk[0]),
task: aesEncrypt(tsk[1]),
db: aesEncrypt(JSON.stringify(dbInfo)),
index: index,
multiple: multiple,
info: tsk[0]+"-"+tsk[1],
}
$.ajax({
url: "install.queries.php",
type : 'POST',
dataType : "json",
data : dataToUse,
complete : function(data){
data = $.parseJSON(data.responseText);
if (data[0].error !== "" ) {
alertify
.error('<i class="fas fa-ban mr-2"></i>Next ERROR occurred: <i>' + data[0].error + '</i><br />Please correct and relaunch.', 0)
.dismissOthers();
return false;
} else {
if (data[0].result !== undefined && data[0].result !== "" ) {
alertify
.success('<i class="fas fa-check text-success mr-2"></i>' + data[0].result + '.<br>Click next to continue', 0)
.dismissOthers();
}
$("#but_launch")
.prop("disabled", true)
.addClass("hidden");
$("#but_next")
.prop("disabled", false)
.removeClass("hidden");
}
/*
* Removing automatic action
// Go to next step
if (step <= 6) {
setTimeout(
function(){
$('#but_next').trigger('click');
},
1000
);
}
*/
}
});
} else {
$("#step_error").removeClass("hidden").html(error);
}
}
/**
*
* @param {string} task Task in string format
*/
function doGetJson(task)
{
console.log("\n\n--- PREPARATION---\n"+step+"\n"+dataToUse+"\n"+dbInfo+"\n"+index+"\n"+multiple+"\n"+task+"\n-------\n")
tsk = task.split("*");
return $.ajax({
url: "install.queries.php",
type : "POST",
dataType : "json",
async: false,
data : {
type: "step_"+step,
data: aesEncrypt(dataToUse), //
activity: aesEncrypt(tsk[0]),
task: aesEncrypt(tsk[1]),
db: aesEncrypt(JSON.stringify(dbInfo)),
index: index,
multiple: multiple,
info: tsk[0]+"-"+tsk[1]
}
})
.complete(function(data) {
console.log("\n\n--- RECEPTION---\n"+data+"\n-------\n")
if (data.responseText === "") {
alertify
.error('<i class="fas fa-ban mr-2">[ERROR] Answer from server is empty.', 10)
.dismissOthers();
} else {
data = $.parseJSON(data.responseText);
console.log("RETOUR:");
console.log(data)
if (data[0].error === "") {
if (step === "5") {
if (data[0].activity === "table") {
$("#pop_db").append("<li>Table <b>"+data[0].task+"</b> created</li>");
} else if (data[0].activity === "entry") {
$("#pop_db").append("<li>Entries <b>"+data[0].task+"</b> were added</li>");
}
} else {
$("#res"+step+"_check"+data[0].index).html('<i class="fas fa-check text-success"></i>');
}
if (data[0].result !== undefined && data[0].result !== "" ) {
alertify
.message(data[0].result, 10)
.dismissOthers();
}
} else {
$("#res"+step+"_check"+data[0].index).html('<span class="badge badge-danger"><i class="fas fa-ban text-warning mr-2"></i>' + data[0].error + "</i></span>");
global_error_on_query = true;
}
}
index++;
});
}
function GotoNextStep()
{
var step = $("#page_id").val(),
nextStep = parseInt(step) + 1;
if (nextStep === 7) {
$("#but_restart, #but_next, #but_launch").addClass("hidden");
$("#but_start").addClass("hidden");
$("#step_result").html("").addClass("hidden");
$("#step_name").html($("#menu_step"+nextStep).html());
$("#step_content").html($("#text_step"+nextStep).html());
$("#menu_step"+step).switchClass("li_inprogress", "li_done");
$("#menu_step"+nextStep).switchClass("", "li_inprogress");
$("#res_"+step).html("<img src=\"images/tick.png\">");
} else {
$("#page_id").val(nextStep);
$("#but_launch").removeClass("hidden").prop("disabled", false);
$("#but_launch").removeClass("hidden");
$("#but_restart").removeClass("hidden");
$("#but_next").prop("disabled", true);
$("#but_next").addClass("hidden");
$("#menu_step"+step).switchClass("li_inprogress", "li_done");
$("#menu_step"+nextStep).switchClass("", "li_inprogress");
$("#res_"+step).html("<img src=\"images/tick.png\">");
$("#step_result").html("");
$("#step_name").html($("#menu_step"+nextStep).html());
$("#step_content").html($("#text_step"+nextStep).html());
$('#admin_pwd').live("paste",function(e) {
alert("Paste option is disabled !!");
e.preventDefault();
});
$("#admin_pwd").live("keypress", function(e){
var key = e.charCode || e.keyCode || 0;
// allow backspace, tab, delete, arrows, letters, numbers and keypad numbers ONLY
return (
key !== 39
);
});
// Auto start as required
if (nextStep === "5" || nextStep === "6" ) {
checkPage();
}
}
}