forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_db.js
More file actions
115 lines (103 loc) · 3.76 KB
/
Copy pathadd_db.js
File metadata and controls
115 lines (103 loc) · 3.76 KB
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
//
//
// Updates database username dynamically, showing its prefix
App.Actions.DB.update_db_username_hint = function(elm, hint) {
if (hint.trim() == '') {
$(elm).parent().find('.hint').html('');
}
// remove prefix from value in order to eliminate duplicates
if (hint.indexOf(GLOBAL.DB_USER_PREFIX) == 0) {
hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length);
}
$(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint);
}
//
//
// Updates database name dynamically, showing its prefix
App.Actions.DB.update_db_databasename_hint = function(elm, hint) {
if (hint.trim() == '') {
$(elm).parent().find('.hint').html('');
}
// remove prefix from value in order to eliminate duplicates
if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) {
hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length);
}
$(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint);
}
//
// listener that triggers database user hint updating
App.Listeners.DB.keypress_db_username = function() {
var ref = $('input[name="v_dbuser"]');
var current_val = ref.val();
if (current_val.trim() != '') {
App.Actions.DB.update_db_username_hint(ref, current_val);
}
ref.bind('keypress input', function(evt) {
clearTimeout(window.frp_usr_tmt);
window.frp_usr_tmt = setTimeout(function() {
var elm = $(evt.target);
App.Actions.DB.update_db_username_hint(elm, $(elm).val());
}, 100);
});
}
//
// listener that triggers database name hint updating
App.Listeners.DB.keypress_db_databasename = function() {
var ref = $('input[name="v_database"]');
var current_val = ref.val();
if (current_val.trim() != '') {
App.Actions.DB.update_db_databasename_hint(ref, current_val);
}
ref.bind('keypress input', function(evt) {
clearTimeout(window.frp_dbn_tmt);
window.frp_dbn_tmt = setTimeout(function() {
var elm = $(evt.target);
App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
}, 100);
});
}
App.Actions.DB.update_v_password = function (){
var password = $('input[name="v_password"]').val();
var min_small = new RegExp(/^(?=.*[a-z]).+$/);
var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
var min_num = new RegExp(/^(?=.*\d).+$/);
var min_length = 8;
var score = 0;
if(password.length >= min_length) { score = score + 1; }
if(min_small.test(password)) { score = score + 1;}
if(min_cap.test(password)) { score = score + 1;}
if(min_num.test(password)) { score = score+ 1; }
$('#meter').val(score);
}
App.Listeners.DB.keypress_v_password = function() {
var ref = $('input[name="v_password"]');
ref.bind('keypress input', function(evt) {
clearTimeout(window.frp_usr_tmt);
window.frp_usr_tmt = setTimeout(function() {
var elm = $(evt.target);
App.Actions.DB.update_v_password(elm, $(elm).val());
}, 100);
});
}
App.Listeners.DB.keypress_v_password();
//
// Page entry point
// Trigger listeners
App.Listeners.DB.keypress_db_username();
App.Listeners.DB.keypress_db_databasename();
randomString = function(min_length = 16) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
var string_length = min_length;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substr(rnum, 1);
}
var regex = new RegExp(/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\d)[a-zA-Z\d]{8,}$/);
if(!regex.test(randomstring)){
randomString();
}else{
$('input[name=v_password]').val(randomstring);
App.Actions.DB.update_v_password();
}
}