1
|
|
|
/* |
2
|
|
|
* MikoPBX - free phone system for small business |
3
|
|
|
* Copyright © 2017-2022 Alexey Portnov and Nikolay Beketov |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program 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. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
16
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
const checkPasswordWorker = { |
20
|
|
|
initialize() { |
21
|
|
|
$(window).on('SecurityWarning', checkPasswordWorker.onWarning); |
22
|
|
|
}, |
23
|
|
|
onWarning(event, data) { |
24
|
|
|
let needShow = false; |
25
|
|
|
$("#updatePasswordWindow div.miko-settings-container").hide(); |
26
|
|
|
$.each(data.needUpdate, (key, value) => { |
27
|
|
|
$(`#updatePasswordWindow #${value}-container`).show(); |
28
|
|
|
needShow = true; |
29
|
|
|
}); |
30
|
|
|
if(needShow){ |
31
|
|
|
$('#updatePasswordWindow #savePassword').on('click', checkPasswordWorker.cbOnClickSavePassword); |
32
|
|
|
let modalWindow = $('#updatePasswordWindow'); |
33
|
|
|
modalWindow.on('keyup', () => { |
34
|
|
|
PasswordScore.checkPassStrength({ |
|
|
|
|
35
|
|
|
pass: $(`#updatePasswordWindow #WebAdminPassword`).val(), |
36
|
|
|
bar: $('.WebAdminPassword-score'), |
37
|
|
|
section: modalWindow, |
38
|
|
|
}); |
39
|
|
|
PasswordScore.checkPassStrength({ |
40
|
|
|
pass: $(`#updatePasswordWindow #SSHPassword`).val(), |
41
|
|
|
bar: $('.SSHPassword'), |
42
|
|
|
section: modalWindow, |
43
|
|
|
}); |
44
|
|
|
}); |
45
|
|
|
modalWindow.modal({ closable : false, }).modal('show') |
46
|
|
|
} |
47
|
|
|
}, |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Отправка формы обновления паролей SSH и Web. |
51
|
|
|
*/ |
52
|
|
|
cbOnClickSavePassword(){ |
53
|
|
|
$('#updatePasswordWindowResult').hide(); |
54
|
|
|
let errors = ''; |
55
|
|
|
let params = {}; |
56
|
|
|
$.each(['WebAdminPassword', 'SSHPassword'], (key, value) => { |
57
|
|
|
if(!$(`#updatePasswordWindow #${value}`).is(":visible")){ |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
let pass = $(`#updatePasswordWindow #${value}`).val(); |
61
|
|
|
let passRep = $(`#updatePasswordWindow #${value}Repeat`).val(); |
62
|
|
|
if( pass !== passRep){ |
63
|
|
|
errors+='<li>'+globalTranslate[`pass_Check${value}DontMatch`]+'</li>'; |
|
|
|
|
64
|
|
|
}else if(pass.trim() === ''){ |
65
|
|
|
errors+='<li>'+globalTranslate[`pass_Check${value}Empty`]+'</li>'; |
66
|
|
|
}else if(PasswordScore.scorePassword(pass) < 50){ |
|
|
|
|
67
|
|
|
errors+=`<li>${globalTranslate['pass_Check${value}Simple']}</li>`; |
68
|
|
|
}else{ |
69
|
|
|
params[value] = pass; |
70
|
|
|
} |
71
|
|
|
}); |
72
|
|
|
if(errors.trim() !== ''){ |
73
|
|
|
errors = `<ul class="ui list">${errors}</ul>`; |
74
|
|
|
checkPasswordWorker.showPasswordError(globalTranslate['pass_CheckWebPassErrorChange'], errors); |
|
|
|
|
75
|
|
|
}else{ |
76
|
|
|
checkPasswordWorker.savePasswords(params); |
77
|
|
|
} |
78
|
|
|
}, |
79
|
|
|
savePasswords(params){ |
80
|
|
|
$.post('/admin-cabinet/general-settings/save', params, function( data ) { |
81
|
|
|
if(data.success === false){ |
82
|
|
|
let errors = ''; |
83
|
|
|
if(typeof data.passwordCheckFail !== 'undefined'){ |
84
|
|
|
$.each(data.passwordCheckFail, (key, value) => { |
85
|
|
|
errors+='<li>'+globalTranslate[`pass_Check${value}Simple`]+'</li>'; |
|
|
|
|
86
|
|
|
}); |
87
|
|
|
}else{ |
88
|
|
|
errors+='<li>'+globalTranslate['er_InternalServerError']+'</li>'; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
if(errors.trim() !== ''){ |
91
|
|
|
checkPasswordWorker.showPasswordError(globalTranslate['pass_CheckWebPassErrorChange'], errors); |
92
|
|
|
} |
93
|
|
|
}else{ |
94
|
|
|
$('#updatePasswordWindow').modal({ closable : false, }).modal('hide') |
95
|
|
|
let event = document.createEvent('Event'); |
96
|
|
|
event.initEvent('ConfigDataChanged', false, true); |
97
|
|
|
window.dispatchEvent(event); |
98
|
|
|
} |
99
|
|
|
}); |
100
|
|
|
}, |
101
|
|
|
showPasswordError(header, body){ |
102
|
|
|
$('#updatePasswordWindowResult div').html(header); |
103
|
|
|
$('#updatePasswordWindowResult p').html(body); |
104
|
|
|
$('#updatePasswordWindowResult').show(); |
105
|
|
|
}, |
106
|
|
|
}; |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
$(document).ready(() => { |
110
|
|
|
checkPasswordWorker.initialize(); |
111
|
|
|
}); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.