These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | * @file load.php |
||
5 | * @author Nils Laumaillé |
||
6 | * @version 2.1.27 |
||
7 | * @copyright (c) 2009-2017 Nils Laumaillé |
||
8 | * @licensing GNU AFFERO GPL 3.0 |
||
9 | * @link http://www.teampass.net |
||
10 | * |
||
11 | * This library is distributed in the hope that it will be useful, |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
14 | */ |
||
15 | |||
16 | if (!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1) { |
||
17 | die('Hacking attempt...2'); |
||
18 | } |
||
19 | |||
20 | // Common elements |
||
21 | $htmlHeaders = ' |
||
22 | <link rel="stylesheet" href="includes/js/jquery-ui/jquery-ui.min.css" type="text/css" /> |
||
23 | <link rel="stylesheet" href="includes/js/jquery-ui/jquery-ui.structure.min.css" type="text/css" /> |
||
24 | <link rel="stylesheet" href="includes/js/jquery-ui/jquery-ui.theme.min.css" type="text/css" /> |
||
25 | <script type="text/javascript" src="includes/js/jquery-ui/external/jquery/jquery.js"></script> |
||
26 | <script type="text/javascript" src="includes/js/jquery-ui/jquery-ui.min.js"></script> |
||
27 | <script src="includes/js/jeditable/jquery.jeditable.js" type="text/javascript"></script> |
||
28 | <script type="text/javascript" src="includes/js/tooltipster/js/jquery.tooltipster.min.js"></script> |
||
29 | <link rel="stylesheet" href="includes/js/tooltipster/css/tooltipster.css" type="text/css" /> |
||
30 | <script type="text/javascript" src="includes/js/simplePassMeter/simplePassMeter.js"></script> |
||
31 | <script type="text/javascript" src="includes/libraries/Encryption/Crypt/aes.js"></script> |
||
32 | <script type="text/javascript" src="includes/libraries/Encryption/Crypt/aes-ctr.js"></script> |
||
33 | <script type="text/javascript" src="includes/libraries/Plupload/plupload.full.min.js"></script> |
||
34 | <link rel="stylesheet" href="includes/js/nprogress/nprogress.css" type="text/css" /> |
||
35 | <script type="text/javascript" src="includes/js/nprogress/nprogress.js"></script> |
||
36 | <script type="text/javascript" src="includes/js/functions.js"></script> |
||
37 | <link rel="stylesheet" href="includes/font-awesome/css/font-awesome.min.css" type="text/css" /> |
||
38 | <link rel="stylesheet" href="includes/css/passman.css" type="text/css" /> |
||
39 | <link rel="stylesheet" href="includes/js/select2/css/select2.min.css" type="text/css" /> |
||
40 | <script type="text/javascript" src="includes/js/select2/js/select2.full.min.js"></script> |
||
41 | |||
42 | |||
43 | <script type="text/javascript" src="includes/libraries/Authentication/agses/agses.jquery.js"></script> |
||
44 | <link rel="stylesheet" href="includes/libraries/Authentication/agses/agses.css" type="text/css" />'; |
||
45 | // For ITEMS page, load specific CSS files for treeview |
||
46 | if (isset($_GET['page']) && $_GET['page'] == "items") { |
||
47 | $htmlHeaders .= ' |
||
48 | <link rel="stylesheet" href="includes/js/jstree/themes/default/style.css" type="text/css" /> |
||
49 | <script type="text/javascript" src="includes/js/jstree/jstree.min.js"></script> |
||
50 | <script type="text/javascript" src="includes/js/jstree/jquery.cookie.js"></script> |
||
51 | <script type="text/javascript" src="includes/js/bgiframe/jquery.bgiframe.min.js"></script> |
||
52 | <script type="text/javascript" src="includes/js/ckeditor/ckeditor.js"></script> |
||
53 | <script type="text/javascript" src="includes/js/ckeditor/adapters/jquery.js"></script> |
||
54 | <link rel="stylesheet" type="text/css" href="includes/js/multiselect/jquery.multiselect.css" /> |
||
55 | <script type="text/javascript" src="includes/js/multiselect/jquery.multiselect.min.js"></script> |
||
56 | <link rel="stylesheet" type="text/css" href="includes/js/multiselect/jquery.multiselect.filter.css" /> |
||
57 | <script type="text/javascript" src="includes/js/multiselect/jquery.multiselect.filter.js"></script> |
||
58 | <script type="text/javascript" src="includes/js/tinysort/jquery.tinysort.min.js"></script> |
||
59 | <script type="text/javascript" src="includes/js/clipboard/clipboard.min.js"></script> |
||
60 | <!-- |
||
61 | <link rel="stylesheet" href="includes/bootstrap/css/bootstrap.min.css" /> |
||
62 | <script src="includes/bootstrap/js/bootstrap.min.js"></script> |
||
63 | --> |
||
64 | <link rel="stylesheet" type="text/css" href="includes/css/items.css" />'; |
||
65 | } else if (isset($_GET['page']) && $_GET['page'] == "manage_settings") { |
||
66 | $htmlHeaders .= ' |
||
67 | <link rel="stylesheet" href="includes/js/toggles/css/toggles.css" /> |
||
68 | <link rel="stylesheet" href="includes/js/toggles/css/toggles-modern.css" /> |
||
69 | <script src="includes/js/toggles/toggles.min.js" type="text/javascript"></script> |
||
70 | <script type="text/javascript" src="includes/libraries/Plupload/plupload.full.min.js"></script> |
||
71 | <link rel="stylesheet" type="text/css" href="includes/js/multiselect/jquery.multiselect.css" /> |
||
72 | <script type="text/javascript" src="includes/js/multiselect/jquery.multiselect.min.js"></script> |
||
73 | <link rel="stylesheet" type="text/css" href="includes/js/multiselect/jquery.multiselect.filter.css" /> |
||
74 | <script type="text/javascript" src="includes/js/multiselect/jquery.multiselect.filter.js"></script>'; |
||
75 | } else if (isset($_GET['page']) && $_GET['page'] == "manage_main") { |
||
76 | $htmlHeaders .= ' |
||
77 | <link rel="stylesheet" href="includes/js/toggles/css/toggles.css" /> |
||
78 | <link rel="stylesheet" href="includes/js/toggles/css/toggles-modern.css" /> |
||
79 | <script src="includes/js/toggles/toggles.min.js" type="text/javascript"></script>'; |
||
80 | } else if (isset($_GET['page']) && ($_GET['page'] == "manage_users" || $_GET['page'] == "manage_folders")) { |
||
81 | $htmlHeaders .= ' |
||
82 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/jquery.dataTables.min.css" /> |
||
83 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/dataTables.jqueryui.min.css" /> |
||
84 | <script type="text/javascript" src="includes/js/datatable/js/jquery.dataTables.min.js"></script> |
||
85 | <script type="text/javascript" src="includes/js/datatable/js/dataTables.jqueryui.min.js"></script> |
||
86 | <link rel="stylesheet" type="text/css" href="includes/js/multiselect/jquery.multiselect.css" /> |
||
87 | <script type="text/javascript" src="includes/js/multiselect/jquery.multiselect.min.js"></script> |
||
88 | <link rel="stylesheet" type="text/css" href="includes/js/multiselect/jquery.multiselect.filter.css" /> |
||
89 | <script type="text/javascript" src="includes/js/multiselect/jquery.multiselect.filter.js"></script>'; |
||
90 | } else if (isset($_GET['page']) && $_GET['page'] == "manage_views") { |
||
91 | $htmlHeaders .= ' |
||
92 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/jquery.dataTables.min.css" /> |
||
93 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/dataTables.jqueryui.min.css" /> |
||
94 | <script type="text/javascript" src="includes/js/datatable/js/jquery.dataTables.js"></script> |
||
95 | <script type="text/javascript" src="includes/js/datatable/js/dataTables.jqueryui.js"></script>'; |
||
96 | } else if (isset($_GET['page']) && ($_GET['page'] == "find" || $_GET['page'] == "kb")) { |
||
97 | $htmlHeaders .= ' |
||
98 | <script type="text/javascript" src="includes/js/ckeditor/ckeditor.js"></script> |
||
99 | <script type="text/javascript" src="includes/js/ckeditor/adapters/jquery.js"></script> |
||
100 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/jquery.dataTables.min.css" /> |
||
101 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/dataTables.jqueryui.min.css" /> |
||
102 | <script type="text/javascript" src="includes/js/datatable/js/jquery.dataTables.min.js"></script> |
||
103 | <script type="text/javascript" src="includes/js/datatable/js/dataTables.jqueryui.min.js"></script> |
||
104 | <link rel="stylesheet" type="text/css" href="includes/js/ui-multiselect/css/ui.multiselect.css" /> |
||
105 | <script type="text/javascript" src="includes/js/ui-multiselect/js/ui.multiselect.min.js"></script> |
||
106 | <link rel="stylesheet" type="text/css" href="includes/css/kb.css" />'; |
||
107 | } else if (isset($_GET['page']) && ($_GET['page'] == "suggestion")) { |
||
108 | $htmlHeaders .= ' |
||
109 | <link rel="stylesheet" type="text/css" href="includes/css/kb.css" /> |
||
110 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/jquery.dataTables.min.css" /> |
||
111 | <link rel="stylesheet" type="text/css" href="includes/js/datatable/css/dataTables.jqueryui.min.css" /> |
||
112 | <script type="text/javascript" src="includes/js/datatable/js/jquery.dataTables.min.js"></script> |
||
113 | <script type="text/javascript" src="includes/js/datatable/js/dataTables.jqueryui.min.js"></script>'; |
||
114 | } else if (!isset($_GET['page'])) { |
||
115 | $htmlHeaders .= ' |
||
116 | <script type="text/javascript" src="includes/js/numeric/jquery.numeric.js"></script>'; |
||
117 | if (!empty($_SESSION['user_id']) && isset($_SESSION['user_id'])) { |
||
118 | $htmlHeaders .= ' |
||
119 | <!--<script type="text/javascript" src="includes/libraries/Plupload/plupload.full.min.js"></script>-->'; |
||
120 | } |
||
121 | } |
||
122 | // Get Favicon |
||
123 | $htmlHeaders .= isset($_SESSION['settings']['favicon']) ? ' |
||
124 | <link rel="icon" href="'.$_SESSION['settings']['favicon'].'" type="image/vnd.microsoft.ico" />' : ''; |
||
125 | |||
126 | // get some init |
||
0 ignored issues
–
show
|
|||
127 | //if (!isset($_SESSION["key"])) $_SESSION["key"] = "nothing"; |
||
128 | //if (!isset($_SESSION["user_id"])) $_SESSION["user_id"] = ""; |
||
129 | |||
130 | $htmlHeaders .= ' |
||
131 | <script type="text/javascript"> |
||
132 | <!-- // --><![CDATA[ |
||
133 | |||
134 | //Menu actions |
||
135 | function MenuAction(val, user_id) |
||
136 | { |
||
137 | NProgress.start(); |
||
138 | if (val == "deconnexion") { |
||
139 | //sessionStorage.clear(); |
||
140 | window.location.href = "logout.php?user_id="+user_id |
||
141 | } else { |
||
142 | $("#menu_action").val("action"); |
||
143 | if (val == "") document.location.href="index.php"; |
||
144 | else document.location.href="index.php?page="+val; |
||
145 | } |
||
146 | } |
||
147 | |||
148 | function aes_encrypt(text) |
||
149 | { |
||
150 | return Aes.Ctr.encrypt(text, "'.$_SESSION['key'].'", 256); |
||
151 | } |
||
152 | |||
153 | |||
154 | function launchIdentify(isDuo, redirect, psk) |
||
155 | { |
||
156 | $("#connection_error").hide(); |
||
157 | if (redirect == undefined) redirect = ""; //Check if redirection |
||
158 | // Check form data |
||
159 | if (psk == 1 && $("#psk").val() == "") { |
||
160 | $("#psk").addClass("ui-state-error"); |
||
161 | return false; |
||
162 | } else if (psk == 1) { |
||
163 | $("#psk").removeClass("ui-state-error"); |
||
164 | } |
||
165 | if ($("#pw").val() == "") { |
||
166 | $("#pw").addClass("ui-state-error"); |
||
167 | return false; |
||
168 | } |
||
169 | if ($("#login").val() == "") { |
||
170 | $("#login").addClass("ui-state-error"); |
||
171 | return false; |
||
172 | } |
||
173 | // launch identification |
||
174 | $("#pw, #login").removeClass("ui-state-error"); |
||
175 | $("#ajax_loader_connexion").show(); |
||
176 | |||
177 | //create random string |
||
178 | var randomstring =CreateRandomString(10); |
||
179 | |||
180 | var data = ""; |
||
181 | if ($("#ga_code").val() != undefined) { |
||
182 | data = \', "GACode":"\'+sanitizeString($("#ga_code").val())+\'"\'; |
||
183 | } |
||
184 | if ($("#psk").val() != undefined) { |
||
185 | data = \', "psk":"\'+sanitizeString($("#psk").val())+\'"\'+ |
||
186 | \', "psk_confirm":"\'+sanitizeString($("#psk_confirm").val())+\'"\'; |
||
187 | } |
||
188 | |||
189 | // get timezone |
||
190 | var d = new Date(); |
||
191 | var TimezoneOffset = d.getTimezoneOffset()*60; |
||
192 | |||
193 | data = \'{"login":"\'+sanitizeString($("#login").val())+\'" , "pw":"\'+sanitizeString($("#pw").val())+\'" , "duree_session":"\'+$("#duree_session").val()+\'" , "screenHeight":"\'+$("body").innerHeight()+\'" , "randomstring":"\'+randomstring+\'" , "TimezoneOffset":"\'+TimezoneOffset+\'"\'+data+\'}\'; |
||
194 | |||
195 | // Handle if DUOSecurity is enabled |
||
196 | if (isDuo == 0 || (isDuo == 1 && $("#login").val() == "admin")) { |
||
197 | identifyUser(redirect, psk, data, randomstring); |
||
198 | } else { |
||
199 | $("#duo_data").val(data); |
||
200 | loadDuoDialog(); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | //Identify user |
||
205 | function identifyUser(redirect, psk, data, randomstring) |
||
206 | { |
||
207 | //send query |
||
208 | $.post( |
||
209 | "sources/identify.php", |
||
210 | { |
||
211 | type : "identify_user", |
||
212 | data : prepareExchangedData(data, "encode", "'.$_SESSION["key"].'") |
||
213 | }, |
||
214 | function(data) { |
||
215 | if (data[0].value == randomstring) { |
||
216 | $("#connection_error").hide(); |
||
217 | //redirection for admin is specific |
||
218 | if (data[0].user_admin == "1") window.location.href="index.php?page=manage_main"; |
||
219 | else if (data[0].initial_url != "") window.location.href=data[0].initial_url; |
||
220 | else window.location.href="index.php?page=items"; |
||
221 | } else if (data[0].value == "user_is_locked") { |
||
222 | $("#connection_error").html("'.addslashes($LANG['account_is_locked']).'").show(); |
||
223 | } else if (data[0].value == "bad_psk") { |
||
224 | $("#ajax_loader_connexion").hide(); |
||
225 | $("#connection_error").html("'.addslashes($LANG['bad_psk']).'").show(); |
||
226 | } else if (data[0].value == "bad_psk_confirmation") { |
||
227 | $("#ajax_loader_connexion").hide(); |
||
228 | $("#connection_error").html("'.addslashes($LANG['bad_psk_confirmation']).'").show(); |
||
229 | } else if (data[0].value == "psk_required") { |
||
230 | $("#ajax_loader_connexion").hide(); |
||
231 | $("#connection_error").html("' . addslashes($LANG['psk_required']) . '"); |
||
232 | $("#connection_error, #connect_psk_confirm").show(); |
||
233 | } else if (data[0].value == "user_not_exists") { |
||
234 | $("#connection_error").html("'.addslashes($LANG['error_bad_credentials']).'").show(); |
||
235 | } else if (!isNaN(parseFloat(data[0].value)) && isFinite(data[0].value)) { |
||
236 | $("#connection_error").html("'.addslashes($LANG['login_attempts_on'])." ".(@$_SESSION['settings']['nb_bad_authentication'] + 1).'").show(); |
||
237 | } else if (data[0].value == "error") { |
||
238 | $("#mysql_error_warning").html(data[0].text).show(); |
||
239 | $("#div_mysql_error").show().dialog("open"); |
||
240 | } else if (data[0].value == "new_ldap_account_created") { |
||
241 | $("#connection_error").html("'.addslashes($LANG['reload_page_after_user_account_creation']).'").show().switchClass("ui-state-error", "ui-state-default"); |
||
242 | setTimeout( |
||
243 | function (){ |
||
244 | window.location.href="index.php" |
||
245 | }, |
||
246 | 2000 |
||
247 | ); |
||
248 | } else if (data[0].value == "false_onetimepw") { |
||
249 | $("#connection_error").html("'.addslashes($LANG['bad_onetime_password']).'").show(); |
||
250 | } else if (data[0].pwd_attempts >=3 ||data[0].error == "bruteforce_wait") { |
||
251 | // now user needs to wait 10 secs before new passwd |
||
252 | $("#connection_error").html("'.addslashes($LANG['error_bad_credentials_more_than_3_times']).'").show(); |
||
253 | } else if (data[0].error == "bad_credentials") { |
||
254 | $("#connection_error").html("'.addslashes($LANG['error_bad_credentials']).'").show(); |
||
255 | } else if (data[0].error == "ga_code_wrong") { |
||
256 | $("#connection_error").html("'.addslashes($LANG['ga_bad_code']).'").show(); |
||
257 | } else if (data[0].value === "agses_error") { |
||
258 | $("#connection_error").html(data[0].error).show(); |
||
259 | } else if (data[0].error == "ga_temporary_code_wrong") { |
||
260 | $("#connection_error").html("'.addslashes($LANG['ga_bad_code']).'").show(); |
||
261 | } else if (data[0].error == "ga_temporary_code_correct") { |
||
262 | $("#ga_code").val("").focus(); |
||
263 | $("#2fa_new_code_div").html(data[0].value+"<br />'.addslashes($LANG['ga_flash_qr_and_login']).'").show(); |
||
264 | } else if (data[0].value === "install_error") { |
||
265 | $("#connection_error").html(data[0].error).show(); |
||
266 | } else { |
||
267 | $("#connection_error").html("'.addslashes($LANG['error_bad_credentials']).'").show(); |
||
268 | } |
||
269 | |||
270 | $("#ajax_loader_connexion").hide(); |
||
271 | }, |
||
272 | "json" |
||
273 | ); |
||
274 | } |
||
275 | |||
276 | function getGASynchronization() |
||
277 | { |
||
278 | if ($("#login").val() != "" && $("#pw").val() != "") { |
||
279 | $("#ajax_loader_connexion").show(); |
||
280 | $("#connection_error").hide(); |
||
281 | $("#div_ga_url").hide(); |
||
282 | data = \'{"login":"\'+sanitizeString($("#login").val())+\'" ,\'+ |
||
283 | \'"pw":"\'+sanitizeString($("#pw").val())+\'"}\'; |
||
284 | //send query |
||
285 | $.post( |
||
286 | "sources/main.queries.php", |
||
287 | { |
||
288 | type : "ga_generate_qr", |
||
289 | data : prepareExchangedData(data, "encode", "'.$_SESSION["key"].'"), |
||
290 | send_email : "1" |
||
291 | }, |
||
292 | function(data) { |
||
293 | if (data[0].error === "0") { |
||
294 | //$("#ga_qr").attr("src", data[0].ga_url); |
||
295 | $("#div_ga_url").show(); |
||
296 | } else if (data[0].error === "not_allowed") { |
||
297 | $("#connection_error").html("'.addslashes($LANG['2FA_new_code_by_user_not_allowed']).'").show(); |
||
298 | $("#div_ga_url").hide(); |
||
299 | } else { |
||
300 | $("#connection_error").html("'.addslashes($LANG['index_bas_pw']).'").show(); |
||
301 | $("#div_ga_url").hide(); |
||
302 | } |
||
303 | $("#ajax_loader_connexion").hide(); |
||
304 | }, |
||
305 | "json" |
||
306 | ); |
||
307 | } else { |
||
308 | $("#connection_error").html("'.addslashes($LANG['ga_enter_credentials']).'").show(); |
||
309 | } |
||
310 | } |
||
311 | |||
312 | function send_user_new_temporary_ga_code() { |
||
313 | $("#div_loading").show(); |
||
314 | |||
315 | data = \'{"login":"\'+sanitizeString($("#login").val())+\'" ,\'+ |
||
316 | \'"pw":"\'+sanitizeString($("#pw").val())+\'"}\'; |
||
317 | |||
318 | $.post( |
||
319 | "sources/main.queries.php", |
||
320 | { |
||
321 | type : "ga_generate_qr", |
||
322 | data : prepareExchangedData(data, "encode", "'.$_SESSION["key"].'"), |
||
323 | send_email : "1" |
||
324 | }, |
||
325 | function(data) { |
||
326 | if (data[0].error === "0") { |
||
327 | $("#div_dialog_message").html(data[0].msg).dialog("open"); |
||
328 | } else { |
||
329 | |||
330 | } |
||
331 | $("#div_loading").hide(); |
||
332 | }, |
||
333 | "json" |
||
334 | ); |
||
335 | } |
||
336 | |||
337 | /* |
||
338 | * Manage generation of new password |
||
339 | */ |
||
340 | function GenerateNewPassword(key, login) |
||
341 | { |
||
342 | $("#ajax_loader_send_mail").show(); |
||
343 | // prepare data |
||
344 | data = \'{"login":"\'+sanitizeString(login)+\'" ,\'+ |
||
345 | \'"key":"\'+sanitizeString(key)+\'"}\'; |
||
346 | //send query |
||
347 | $.post("sources/main.queries.php", { |
||
348 | type : "generate_new_password", |
||
349 | data : prepareExchangedData(data, "encode", "'.$_SESSION["key"].'") |
||
350 | }, |
||
351 | function(data) { |
||
352 | if (data == "done") { |
||
353 | window.location.href="index.php"; |
||
354 | } else { |
||
355 | $("#generate_new_pw_error").show().html(data); |
||
356 | } |
||
357 | $("#ajax_loader_send_mail").hide(); |
||
358 | } |
||
359 | ); |
||
360 | } |
||
361 | |||
362 | |||
363 | function loadProfileDialog() |
||
364 | { |
||
365 | $("#dialog_user_profil").dialog({ |
||
366 | open: function(event, ui) { |
||
367 | $("#div_user_profil").load( |
||
368 | "'.$_SESSION['settings']['cpassman_url'].'/profile.php?key='.$_SESSION['key'].'", function(){} |
||
369 | ); |
||
370 | }, |
||
371 | close: function() { |
||
372 | // in case of user changed language then reload the current page |
||
373 | if ($("#userlanguage_'.$_SESSION['user_id'].'").text() !== "'.$_SESSION['user_language'].'") { |
||
374 | //location.reload(); |
||
375 | //document.location.href="index.php?language=" + $("#userlanguage_'.$_SESSION['user_id'].'").text(); |
||
376 | var url = window.location.href; |
||
377 | if (url.indexOf("?") > -1) { |
||
378 | url += "&language=" + $("#userlanguage_'.$_SESSION['user_id'].'").text(); |
||
379 | } else { |
||
380 | url += "?language=" + $("#userlanguage_'.$_SESSION['user_id'].'").text(); |
||
381 | } |
||
382 | document.location.href = url; |
||
383 | } |
||
384 | } |
||
385 | }).dialog("open"); |
||
386 | } |
||
387 | |||
388 | /* |
||
389 | * Clean disconnection of user for security reasons. |
||
390 | * |
||
391 | $(window).bind("beforeunload", function() { |
||
392 | if ($("#menu_action").val() == "") { |
||
393 | sessionStorage.clear(); |
||
394 | //Forces the disconnection of the user |
||
395 | $.ajax({ |
||
396 | type: "POST", |
||
397 | url : "error.php", |
||
398 | data : "session=expired" |
||
399 | }); |
||
400 | } |
||
401 | });*/ |
||
402 | |||
403 | |||
404 | function displayItemNumber (item_id, tree_id) |
||
405 | { |
||
406 | if (window.location.href.indexOf("page=items") == -1) { |
||
407 | location.replace("'.$_SESSION['settings']['cpassman_url'].'/index.php?page=items&group="+tree_id+"&id="+item_id); |
||
408 | } else { |
||
409 | $("#items_list").html("<ul class=\'liste_items\' id=\'full_items_list\'></ul>"); |
||
410 | AfficherDetailsItem(item_id); |
||
411 | if (tree_id != $("#hid_cat").val()) { |
||
412 | ListerItems(tree_id); |
||
413 | } |
||
414 | } |
||
415 | } |
||
416 | |||
417 | function refreshListLastSeenItems() |
||
418 | { |
||
419 | // refresh list of last items seen |
||
420 | if ("'.$_SESSION["key"].'" == "") return false; |
||
421 | $.post( |
||
422 | "sources/main.queries.php", |
||
423 | { |
||
424 | type : "refresh_list_items_seen", |
||
425 | key : "'.$_SESSION["key"].'" |
||
426 | }, |
||
427 | function(data) { |
||
428 | data = $.parseJSON(data); |
||
429 | //check if format error |
||
430 | if (data.error == "") { |
||
431 | if (data.text == null) { |
||
432 | $("#last_seen_items_list").html("<li>'.$LANG['none'].'</li>"); |
||
433 | } else { |
||
434 | $("#last_seen_items_list").html(data.text); |
||
435 | } |
||
436 | // rebuild menu |
||
437 | $("#menu_last_seen_items").menu("refresh"); |
||
438 | // show notification |
||
439 | if (data.existing_suggestions != 0) { |
||
440 | blink("#menu_button_suggestion", -1, 500, "ui-state-error"); |
||
441 | } |
||
442 | } else { |
||
443 | $("#main_info_box_text").html(data.error); |
||
444 | setTimeout(function(){$("#main_info_box").effect( "fade", "slow" );}, 1000); |
||
445 | } |
||
446 | } |
||
447 | ); |
||
448 | } |
||
449 | |||
450 | // DUO box - identification |
||
451 | function loadDuoDialog() |
||
452 | { |
||
453 | // show dialog |
||
454 | $("#dialog_duo").dialog({ |
||
455 | width: 600, |
||
456 | height: 500, |
||
457 | title: "DUO Security", |
||
458 | open: function(event, ui) { |
||
459 | $("#div_duo").load( |
||
460 | "'.$_SESSION['settings']['cpassman_url'].'/duo.load.php", function(){} |
||
461 | ); |
||
462 | } |
||
463 | }).dialog("open"); |
||
464 | } |
||
465 | |||
466 | // DUO box - wait |
||
467 | function loadDuoDialogWait() |
||
468 | { |
||
469 | $("#div_duo").html("<center><i class=\"fa fa-cog fa-spin fa-2x\"></i><br /><br />'.$LANG['please_wait'].'</center>"); |
||
470 | $("#dialog_duo").dialog({ |
||
471 | width: 400, |
||
472 | height: 250, |
||
473 | title: "DUO Security - '.$LANG['please_wait'].' ..." |
||
474 | }).dialog("open"); |
||
475 | } |
||
476 | |||
477 | function ChangeMyPass() |
||
478 | { |
||
479 | if ($("#new_pw").val() != "" && $("#new_pw").val() == $("#new_pw2").val()) { |
||
480 | if (parseInt($("#pw_strength_value").val()) >= parseInt($("#user_pw_complexity").val())) { |
||
481 | var data = "{\"new_pw\":\""+sanitizeString($("#new_pw").val())+"\"}"; |
||
482 | $.post( |
||
483 | "sources/main.queries.php", |
||
484 | { |
||
485 | type : "change_pw", |
||
486 | change_pw_origine : "first_change", |
||
487 | complexity : $("#user_pw_complexity").val(), |
||
488 | key : "'.$_SESSION['key'].'", |
||
489 | data : prepareExchangedData(data, "encode", "'.$_SESSION['key'].'>") |
||
490 | }, |
||
491 | function(data) { |
||
492 | if (data[0].error == "complexity_level_not_reached") { |
||
493 | $("#new_pw, #new_pw2").val(""); |
||
494 | $("#change_pwd_error").addClass("ui-state-error ui-corner-all").show().html("<span>'.$LANG['error_complex_not_enought'].'></span>"); |
||
495 | } else { |
||
496 | location.reload(true); |
||
497 | } |
||
498 | }, |
||
499 | "json" |
||
500 | ); |
||
501 | } else { |
||
502 | $("#change_pwd_error").addClass("ui-state-error ui-corner-all").show().html("'.addslashes($LANG['error_complex_not_enought']).'"); |
||
503 | } |
||
504 | } else { |
||
505 | $("#change_pwd_error").addClass("ui-state-error ui-corner-all").show().html("'.addslashes($LANG['index_pw_error_identical']).'"); |
||
506 | } |
||
507 | } |
||
508 | |||
509 | /* |
||
510 | ** |
||
511 | */ |
||
512 | function prepareMsgToDisplay(type, msg) { |
||
513 | var html; |
||
514 | if (type === "error") { |
||
515 | html = "<i class=\'fa fa-warning fa-lg mi-red\'></i> "; |
||
516 | |||
517 | if (msg === "not_allowed") { |
||
518 | html += "'.addslashes($LANG['error_not_allowed_to']).'"; |
||
519 | } else if (msg === "key_not_conform") { |
||
520 | html += "Key verification for Query is not correct!"; |
||
521 | } |
||
522 | } else if (type === "info") { |
||
523 | html = "<i class=\'fa fa-info-circle fa-lg\'></i> "; |
||
524 | if (msg === "done") { |
||
525 | html += "'.addslashes($LANG['alert_message_done']).'"; |
||
526 | } |
||
527 | } |
||
528 | |||
529 | return html; |
||
530 | } |
||
531 | |||
532 | $(function() { |
||
533 | // AGSES authentication |
||
534 | if ($("#axs_canvas").length > 0) { |
||
535 | // show the agsesflicker |
||
536 | $("#login, #agses_cardid").blur(function() { |
||
537 | // exclude if login is empty or Admin |
||
538 | if ($("#login").val() === "" || $("#login").val() === "admin") return false; |
||
539 | |||
540 | $("#pw").attr("disabled", true); |
||
541 | |||
542 | // special check for agses_cardid |
||
543 | // must contain 12 numbers |
||
544 | if ($("#agses_cardid").val() !== "") { |
||
545 | var agses_carid_error = ""; |
||
546 | if ($("#agses_cardid").val().length !== 12) { |
||
547 | agses_carid_error = "Card ID MUST contain 12 numbers"; |
||
548 | } else if (isNaN($("#agses_cardid").val())) { |
||
549 | agses_carid_error = "Card ID contains only numbers"; |
||
550 | } |
||
551 | |||
552 | if (agses_carid_error !== "") { |
||
553 | $("#agses_cardid_div").after("<div class=\"ui-state-error ui-corner-all\" id=\"tmp_agses_div\" style=\"padding:5px; text-align:center; width:454px;\">ERROR: "+agses_carid_error+"</div>"); |
||
554 | $("#tmp_agses_div").show(1).delay(2000).fadeOut(500); |
||
555 | $("#agses_cardid_div").show(); |
||
556 | return false; |
||
557 | } |
||
558 | } |
||
559 | |||
560 | // show a wait message |
||
561 | $("#agses_cardid_div").after("<div class=\"ui-state-focus ui-corner-all\" id=\"tmp_agses_wait_div\" style=\"padding:5px; text-align:center; width:454px;\"><i class=\"fa fa-cog fa-spin fa-1x\"></i> '.addslashes($LANG['admin_agses_wait']).'</div>"); |
||
562 | |||
563 | // send query |
||
564 | $.post( |
||
565 | "sources/identify.php", |
||
566 | { |
||
567 | type : "identify_user_with_agses", |
||
568 | login: sanitizeString($("#login").val()), |
||
569 | cardid: sanitizeString($("#agses_cardid").val()), |
||
570 | key: "'.$_SESSION['key'].'" |
||
571 | }, |
||
572 | function(data) { |
||
573 | // init |
||
574 | $("#pw").attr("disabled", false); |
||
575 | $("#agses_flickercode_div").hide(); |
||
576 | $("#user_pwd").text("'.addslashes($LANG['index_password']).'"); |
||
577 | |||
578 | if (data[0].error !== "" && data[0].agses_message === "") { |
||
579 | // an error occured during query |
||
580 | if (data[0].error === "no_agses_info") { |
||
581 | data[0].error = "'.addslashes($LANG['agses_error_missing_api_data']).'"; |
||
582 | } |
||
583 | $("#agses_cardid_div").after("<div class=\"ui-state-error ui-corner-all\" id=\"tmp_agses_div\" style=\"padding:5px; text-align:center; width:454px;\">ERROR: "+data[0].error+"</div>"); |
||
584 | $("#tmp_agses_div").show(1).delay(3000).fadeOut(1000); |
||
585 | |||
586 | } else if (data[0].agses_message !== "" && (data[0].agses_message.indexOf("ERROR ") === 0 || data[0].agses_status === "no_user_card_id")) { |
||
587 | // Agses returned an error |
||
588 | $("#agses_cardid_div").show(); |
||
589 | $("#agses_cardid").focus(); |
||
590 | |||
591 | $("#agses_cardid_div").after("<div class=\"ui-state-error ui-corner-all\" id=\"tmp_agses_div\" style=\"padding:5px; text-align:center; width:454px;\">ERROR: "+data[0].agses_message+"</div>"); |
||
592 | $("#tmp_agses_div").show(1).delay(3000).fadeOut(1000); |
||
593 | |||
594 | } else if (data[0].agses_message !== "") { |
||
595 | // show agses flicker |
||
596 | $("#agses_cardid_div").hide(); |
||
597 | // check if already generated |
||
598 | if ($("#axs_canvas").data("agsesFlicker") !== undefined) { |
||
599 | $("#axs_canvas").agsesFlicker({ |
||
600 | "message": data[0].agses_message, |
||
601 | }); |
||
602 | } else { |
||
603 | // generateflickercode |
||
604 | $("#axs_canvas").agsesInit({ |
||
605 | "message": data[0].agses_message, |
||
606 | }); |
||
607 | } |
||
608 | $("#agses_flickercode_div").show(); |
||
609 | $("#user_pwd").text("'.addslashes($LANG['index_agses_key']).'"); |
||
610 | |||
611 | } else if (data[0].agses_message === "") { |
||
612 | // user needs to enter his user card id |
||
613 | $("#agses_cardid_div").show(); |
||
614 | $("#user_pwd").text("'.addslashes($LANG['index_password']).'"); |
||
615 | $("#agses_cardid").focus(); |
||
616 | |||
617 | } else { |
||
618 | // something wrong |
||
619 | // typically the user login does not exist |
||
620 | $("#agses_flickercode_div, #agses_cardid_div").hide(); |
||
621 | $("#user_pwd").text("'.addslashes($LANG['index_password']).'"); |
||
622 | $("#agses_cardid_div").after("<div class=\"ui-state-error ui-corner-all\" id=\"tmp_agses_div\" style=\"padding:5px; text-align:center; width:454px;\">ERROR: "+data[0].error+"</div>"); |
||
623 | $("#tmp_agses_div").show(1).delay(3000).fadeOut(1000); |
||
624 | } |
||
625 | |||
626 | // remove wait message |
||
627 | $("#tmp_agses_wait_div").remove(); |
||
628 | }, |
||
629 | "json" |
||
630 | ); |
||
631 | }) |
||
632 | } |
||
633 | |||
634 | // manage countdown for session expiration |
||
635 | countdown(); |
||
636 | |||
637 | // load DUO login |
||
638 | if ($("#duo_sig_response").val() != "") { |
||
639 | $("#login").val($("#duo_login").val()); |
||
640 | |||
641 | // checking that response is corresponding to user credentials |
||
642 | $.post( |
||
643 | "sources/identify.php", |
||
644 | { |
||
645 | type : "identify_duo_user_check", |
||
646 | login: sanitizeString($("#login").val()), |
||
647 | sig_response: $("#duo_sig_response").val() |
||
648 | }, |
||
649 | function(data) { |
||
650 | var ret = data[0].resp.split("|"); |
||
651 | if (ret[0] === "ERR") { |
||
652 | $("#div_duo").html("ERROR " + ret[1]); |
||
653 | } else { |
||
654 | // finally launch identification process inside Teampass. |
||
655 | loadDuoDialogWait(); |
||
656 | |||
657 | $.post( |
||
658 | "sources/identify.php", |
||
659 | { |
||
660 | type : "identify_user", |
||
661 | data : prepareExchangedData($("#duo_data").val(), "encode", "'.$_SESSION['key'].'") |
||
662 | }, |
||
663 | function(data) { |
||
664 | $("#connection_error").hide(); |
||
665 | //redirection for admin is specific |
||
666 | if (data[0].user_admin == "1") window.location.href="index.php?page=manage_main"; |
||
667 | else $( "#duo_form" ).submit(); |
||
668 | }, |
||
669 | "json" |
||
670 | ); |
||
671 | } |
||
672 | }, |
||
673 | "json" |
||
674 | ); |
||
675 | } |
||
676 | |||
677 | $(".button, .btn").button(); |
||
678 | |||
679 | //TOOLTIPS |
||
680 | $("#main *, #footer *, #icon_last_items *, #top *, button, .tip").tooltipster({ |
||
681 | maxWidth: 400, |
||
682 | contentAsHTML: true, |
||
683 | multiple: true |
||
684 | }); |
||
685 | $("#user_session").val(sessionStorage.password); |
||
686 | |||
687 | $(".menu").menu({ |
||
688 | icon: {}, |
||
689 | position: { my: "left top", at: "left bottom" }, |
||
690 | _closeOnDocumentClick: function( event ) { |
||
691 | return true; |
||
692 | } |
||
693 | }); |
||
694 | |||
695 | //Display Tabs |
||
696 | $("#item_edit_tabs, #item_tabs").tabs(); |
||
697 | |||
698 | //BUTTON |
||
699 | $("#but_identify_user").hover( |
||
700 | function() { |
||
701 | $(this).addClass("ui-state-hover"); |
||
702 | }, |
||
703 | function() { |
||
704 | $(this).removeClass("ui-state-hover"); |
||
705 | } |
||
706 | ).mousedown(function() { |
||
707 | $(this).addClass("ui-state-active"); |
||
708 | }) |
||
709 | .mouseup(function() { |
||
710 | $(this).removeClass("ui-state-active"); |
||
711 | }); |
||
712 | |||
713 | //WARNING FOR QUERY ERROR |
||
714 | $("#div_mysql_error").dialog({ |
||
715 | bgiframe: true, |
||
716 | modal: true, |
||
717 | autoOpen: false, |
||
718 | width: 700, |
||
719 | height: 150, |
||
720 | title: "'.$LANG['error_mysql'].'", |
||
721 | buttons: { |
||
722 | "'.$LANG['ok'].'": function() { |
||
723 | $(this).dialog("close"); |
||
724 | } |
||
725 | } |
||
726 | }); |
||
727 | |||
728 | //DIALOG FOR USER PROFILE |
||
729 | $("#dialog_user_profil").dialog({ |
||
730 | bgiframe: true, |
||
731 | modal: true, |
||
732 | autoOpen: false, |
||
733 | width: 500, |
||
734 | height: 520, |
||
735 | title: "'.$LANG['user_profile_dialogbox_menu'].'", |
||
736 | buttons: { |
||
737 | "'.$LANG['close'].'": function() { |
||
738 | $(this).dialog("close"); |
||
739 | } |
||
740 | }, |
||
741 | close: function() { |
||
742 | $("#dialog_user_profil").dialog("option", "height", 430); |
||
743 | $("#div_user_profil").html("<i class=\'fa fa-cog fa-spin fa-2x\'></i> <b>'.$LANG['please_wait'].'</b>"); |
||
744 | } |
||
745 | }); |
||
746 | |||
747 | //MESSAGE DIALOG |
||
748 | $("#div_dialog_message").dialog({ |
||
749 | bgiframe: true, |
||
750 | modal: true, |
||
751 | autoOpen: false, |
||
752 | width: 400, |
||
753 | height: 150, |
||
754 | title: "'.$LANG['div_dialog_message_title'].'", |
||
755 | buttons: { |
||
756 | "'.$LANG['ok'].'": function() { |
||
757 | $("#div_dialog_message").dialog("close"); |
||
758 | } |
||
759 | }, |
||
760 | beforeClose: function(){ |
||
761 | $("#div_dialog_message_text").html(""); |
||
762 | }, |
||
763 | close: function() { |
||
764 | $("#div_dialog_message").dialog("close"); |
||
765 | } |
||
766 | }); |
||
767 | |||
768 | // DIALOG BOX FOR SETTING PERSONAL SALTKEY |
||
769 | $("#div_set_personal_saltkey").dialog({ |
||
770 | bgiframe: true, |
||
771 | modal: true, |
||
772 | autoOpen: false, |
||
773 | width: 500, |
||
774 | height: 190, |
||
775 | title: "'.$LANG['home_personal_saltkey_label'].'", |
||
776 | open: function( event, ui ) { |
||
777 | $("#input_personal_saltkey").val("'.addslashes(str_replace(""", '"', $_SESSION['my_sk'])).'"); |
||
778 | }, |
||
779 | buttons: { |
||
780 | "'.$LANG['save_button'].'": function() { |
||
781 | LoadingPage(); |
||
782 | var data = "{\"psk\":\""+sanitizeString($("#input_personal_saltkey").val())+"\"}"; |
||
783 | //Send query |
||
784 | $.post( |
||
785 | "sources/main.queries.php", |
||
786 | { |
||
787 | type : "store_personal_saltkey", |
||
788 | data : prepareExchangedData(data, "encode", "'.$_SESSION['key'].'") |
||
789 | }, |
||
790 | function(data) { |
||
791 | data = prepareExchangedData(data , "decode", "'.$_SESSION['key'].'"); |
||
792 | if (data.error !== "") { |
||
793 | // display error |
||
794 | $("#main_info_box_text").html(data.error); |
||
795 | $("#main_info_box").show().position({ |
||
796 | my: "center", |
||
797 | at: "center top+75", |
||
798 | of: "#top" |
||
799 | }); |
||
800 | setTimeout(function(){$("#main_info_box").effect( "fade", "slow" );}, 5000); |
||
801 | } else { |
||
802 | $("#main_info_box_text").html("'.$LANG['alert_message_done'].' '.$txt['alert_page_will_reload'].'"); |
||
803 | $("#main_info_box").show().position({ |
||
804 | my: "center", |
||
805 | at: "center top+75", |
||
806 | of: "#top" |
||
807 | }); |
||
808 | setTimeout(function(){$("#main_info_box").effect( "fade", "slow" );}, 1000); |
||
809 | location.reload(); |
||
810 | } |
||
811 | LoadingPage(); |
||
812 | $("#input_personal_saltkey").val(""); |
||
813 | } |
||
814 | ); |
||
815 | $(this).dialog("close"); |
||
816 | }, |
||
817 | "'.$LANG['cancel_button'].'": function() { |
||
818 | $(this).dialog("close"); |
||
819 | } |
||
820 | } |
||
821 | }); |
||
822 | |||
823 | // DIALOG BOX FOR CHANGING PERSONAL SALTKEY |
||
824 | $("#div_change_personal_saltkey").dialog({ |
||
825 | bgiframe: true, |
||
826 | modal: true, |
||
827 | autoOpen: false, |
||
828 | width: 450, |
||
829 | height: 310, |
||
830 | title: "'.$LANG['menu_title_new_personal_saltkey'].'", |
||
831 | open: function() { |
||
832 | $("#new_personal_saltkey").val(""); |
||
833 | $("#old_personal_saltkey").val("'.addslashes(str_replace(""", '"', $_SESSION['my_sk'])).'"); |
||
834 | }, |
||
835 | buttons: { |
||
836 | "'.$LANG['ok'].'": function() { |
||
837 | $("#div_change_personal_saltkey_wait").show(); |
||
838 | var data_to_share = "{\"sk\":\"" + sanitizeString($("#new_personal_saltkey").val()) + "\", \"old_sk\":\"" + sanitizeString($("#old_personal_saltkey").val()) + "\"}"; |
||
839 | |||
840 | $("#div_change_personal_saltkey_wait_progress").html(" 0%"); |
||
841 | |||
842 | //Send query |
||
843 | $.post( |
||
844 | "sources/main.queries.php", |
||
845 | { |
||
846 | type : "change_personal_saltkey", |
||
847 | data_to_share : prepareExchangedData(data_to_share, "encode", "'.$_SESSION['key'].'"), |
||
848 | key : "'.$_SESSION['key'].'" |
||
849 | }, |
||
850 | function(data) { |
||
851 | data = prepareExchangedData(data , "decode", "'.$_SESSION['key'].'"); |
||
852 | if (data.error == "no") { |
||
853 | changePersonalSaltKey(data_to_share, data.list, data.nb_total); |
||
854 | } else { |
||
855 | |||
856 | } |
||
857 | /* |
||
858 | $("#div_change_personal_saltkey_wait").hide(); |
||
859 | $("#div_change_personal_saltkey").dialog("close"); |
||
860 | */ |
||
861 | } |
||
862 | ); |
||
863 | }, |
||
864 | "'.$LANG['cancel_button'].'": function() { |
||
865 | $(this).dialog("close"); |
||
866 | } |
||
867 | }, |
||
868 | close: function() { |
||
869 | $("#div_change_personal_saltkey_wait").hide(); |
||
870 | } |
||
871 | }); |
||
872 | |||
873 | // DIALOG FOR PSK |
||
874 | $("#psk_confirm").focusout(function() { |
||
875 | if ($("#psk_confirm").val() != $("#psk").val()) { |
||
876 | $("#but_identify_user").prop("disabled", true); |
||
877 | $("#psk, #psk_confirm").addClass("ui-state-error"); |
||
878 | } else { |
||
879 | $("#but_identify_user").prop("disabled", false); |
||
880 | $("#psk, #psk_confirm").removeClass("ui-state-error"); |
||
881 | } |
||
882 | }); |
||
883 | |||
884 | // DIALOG BOX FOR ASKING PASSWORD |
||
885 | $("#div_forgot_pw").dialog({ |
||
886 | bgiframe: true, |
||
887 | modal: true, |
||
888 | autoOpen: false, |
||
889 | width: 400, |
||
890 | height: 250, |
||
891 | title: "'.$LANG['forgot_my_pw'].'", |
||
892 | buttons: { |
||
893 | "'.$LANG['send'].'": function() { |
||
894 | $("#div_forgot_pw_alert").html(""); |
||
895 | $("#div_forgot_pw_status").show(); |
||
896 | $.post( |
||
897 | "sources/main.queries.php", |
||
898 | { |
||
899 | type : "send_pw_by_email", |
||
900 | email : $("#forgot_pw_email").val(), |
||
901 | login : $("#forgot_pw_login").val() |
||
902 | }, |
||
903 | function(data) { |
||
904 | $("#div_forgot_pw_status").hide(); |
||
905 | if (data[0].error != "") { |
||
906 | $("#div_forgot_pw_alert").html(data[0].message).addClass("ui-state-error").show(); |
||
907 | } else { |
||
908 | $("#div_forgot_pw_alert").html(""); |
||
909 | $("#div_dialog_message_text").html(data[0].message); |
||
910 | $("#div_forgot_pw").dialog("close"); |
||
911 | $("#div_dialog_message").dialog("open"); |
||
912 | } |
||
913 | }, |
||
914 | "json" |
||
915 | ); |
||
916 | }, |
||
917 | "'.$LANG['cancel_button'].'": function() { |
||
918 | $("#div_forgot_pw_alert").html(""); |
||
919 | $("#forgot_pw_email").val(""); |
||
920 | $(this).dialog("close"); |
||
921 | } |
||
922 | } |
||
923 | }); |
||
924 | |||
925 | |||
926 | // DIALOG for div_increase_session_time |
||
927 | $("#div_increase_session_time").dialog({ |
||
928 | bgiframe: true, |
||
929 | modal: true, |
||
930 | autoOpen: false, |
||
931 | width: 400, |
||
932 | height: 150, |
||
933 | title: "'.$LANG['index_add_one_hour'].'", |
||
934 | buttons: { |
||
935 | "'.$LANG['confirm'].'": function() { |
||
936 | if (isInteger($("#input_session_duration").val())) { |
||
937 | IncreaseSessionTime("'.$LANG['alert_message_done'].'", "'.$LANG['please_wait'].'", $("#input_session_duration").val()); |
||
938 | $("#div_increase_session_time").dialog("close"); |
||
939 | } |
||
940 | }, |
||
941 | "'.$LANG['cancel_button'].'": function() { |
||
942 | $(this).dialog("close"); |
||
943 | } |
||
944 | }, |
||
945 | beforeClose: function(){ |
||
946 | $("#input_session_duration_warning").html(""); |
||
947 | }, |
||
948 | close: function() { |
||
949 | $("#div_increase_session_time").dialog("close"); |
||
950 | } |
||
951 | }); |
||
952 | |||
953 | //PREPARE MAIN MENU |
||
954 | $("#main_menu button, #personal_menu_actions button").button(); |
||
955 | |||
956 | //PREPARE LANGUGAGE DROPDOWN |
||
957 | $(".dropdown dt").click(function() { |
||
958 | $(".dropdown dd ul").toggle(); |
||
959 | }); |
||
960 | |||
961 | $(".dropdown dd ul li a").click(function() { |
||
962 | var text = $(this).html(); |
||
963 | $(".dropdown dt a span").html(text); |
||
964 | $(".dropdown dd ul").hide(); |
||
965 | $("#result").html("Selected value is: " + getSelectedValue("sample")); |
||
966 | }); |
||
967 | |||
968 | function getSelectedValue(id) |
||
969 | { |
||
970 | return $("#" + id).find("dt a span.value").html(); |
||
971 | } |
||
972 | |||
973 | $(document).bind("click", function(e) { |
||
974 | var $clicked = $(e.target); |
||
975 | if (! $clicked.parents().hasClass("dropdown")) |
||
976 | $(".dropdown dd ul").hide(); |
||
977 | }); |
||
978 | //END |
||
979 | |||
980 | $.ajaxSetup({ |
||
981 | error: function(jqXHR, exception) { |
||
982 | if (jqXHR.status === 0) { |
||
983 | $("#div_dialog_message").show(); |
||
984 | $("#div_dialog_message_text").html("Not connect. Verify Network."); |
||
985 | } else if (jqXHR.status == 404) { |
||
986 | $("#div_dialog_message").show(); |
||
987 | $("#div_dialog_message_text").html("Requested page not found. [404]"); |
||
988 | } else if (jqXHR.status == 500) { |
||
989 | $("#div_dialog_message").show(); |
||
990 | $("#div_dialog_message_text").html("Internal Server Error [500]."); |
||
991 | } else if (exception === "parsererror") { |
||
992 | $("#div_dialog_message").show(); |
||
993 | $("#div_dialog_message_text").html("Requested JSON parse failed."); |
||
994 | } else if (exception === "timeout") { |
||
995 | $("#div_dialog_message").show(); |
||
996 | $("#div_dialog_message_text").html("Time out error."); |
||
997 | } else if (exception === "abort") { |
||
998 | $("#div_dialog_message").show(); |
||
999 | $("#div_dialog_message_text").html("Ajax request aborted."); |
||
1000 | } else { |
||
1001 | $("#div_dialog_message").show(); |
||
1002 | $("#div_dialog_message_text").html("Uncaught Error.<br />" + jqXHR.responseText); |
||
1003 | } |
||
1004 | } |
||
1005 | }); |
||
1006 | |||
1007 | |||
1008 | //Password meter for item creation |
||
1009 | $("#new_pw").simplePassMeter({ |
||
1010 | "requirements": {}, |
||
1011 | "container": "#pw_strength", |
||
1012 | "defaultText" : "'.$LANG['index_pw_level_txt'].'", |
||
1013 | "ratings": [ |
||
1014 | {"minScore": 0, |
||
1015 | "className": "meterFail", |
||
1016 | "text": "'.$LANG['complex_level0'].'" |
||
1017 | }, |
||
1018 | {"minScore": 25, |
||
1019 | "className": "meterWarn", |
||
1020 | "text": "'.$LANG['complex_level1'].'" |
||
1021 | }, |
||
1022 | {"minScore": 50, |
||
1023 | "className": "meterWarn", |
||
1024 | "text": "'.$LANG['complex_level2'].'" |
||
1025 | }, |
||
1026 | {"minScore": 60, |
||
1027 | "className": "meterGood", |
||
1028 | "text": "'.$LANG['complex_level3'].'" |
||
1029 | }, |
||
1030 | {"minScore": 70, |
||
1031 | "className": "meterGood", |
||
1032 | "text": "'.$LANG['complex_level4'].'" |
||
1033 | }, |
||
1034 | {"minScore": 80, |
||
1035 | "className": "meterExcel", |
||
1036 | "text": "'.$LANG['complex_level5'].'" |
||
1037 | }, |
||
1038 | {"minScore": 90, |
||
1039 | "className": "meterExcel", |
||
1040 | "text": "'.$LANG['complex_level6'].'" |
||
1041 | } |
||
1042 | ] |
||
1043 | }); |
||
1044 | $("#new_pw").bind({ |
||
1045 | "score.simplePassMeter" : function(jQEvent, score) { |
||
1046 | $("#pw_strength_value").val(score); |
||
1047 | } |
||
1048 | }).change({ |
||
1049 | "score.simplePassMeter" : function(jQEvent, score) { |
||
1050 | $("#pw_strength_value").val(score); |
||
1051 | } |
||
1052 | }); |
||
1053 | |||
1054 | // get list of last items |
||
1055 | refreshListLastSeenItems(); |
||
1056 | |||
1057 | // prevent usage of symbols in Personal saltkey |
||
1058 | $(".text_without_symbols").bind("keydown", function (event) { |
||
1059 | switch (event.keyCode) { |
||
1060 | case 8: // Backspace |
||
1061 | case 9: // Tab |
||
1062 | case 13: // Enter |
||
1063 | case 37: // Left |
||
1064 | case 38: // Up |
||
1065 | case 39: // Right |
||
1066 | case 40: // Down |
||
1067 | break; |
||
1068 | default: |
||
1069 | var regex = new RegExp("^[a-zA-Z0-9.,/#&$@()%*]+$"); |
||
1070 | var key = event.key; |
||
1071 | if (!regex.test(key)) { |
||
1072 | $("#set_personal_saltkey_warning").html("'.addslashes($LANG['character_not_allowed']).'").stop(true,true).show().fadeOut(1000); |
||
1073 | event.preventDefault(); |
||
1074 | return false; |
||
1075 | } |
||
1076 | if (key !== "Alt" && key !== "Control" && key !== "Shift") $("#set_personal_saltkey_last_letter").html(key).stop(true,true).show().fadeOut(1400); |
||
1077 | break; |
||
1078 | } |
||
1079 | }).bind("paste",function(e){ |
||
1080 | $("#set_personal_saltkey_warning").html("'.addslashes($LANG['error_not_allowed_to']).'").stop(true,true).show().fadeOut(1000); |
||
1081 | e.preventDefault(); |
||
1082 | }); |
||
1083 | |||
1084 | setTimeout(function() { NProgress.done(); $(".fade").removeClass("out"); }, 1000); |
||
1085 | });'; |
||
1086 | |||
1087 | if (isset($_GET['page']) && $_GET['page'] == "find") { |
||
1088 | // JAVASCRIPT FOR FIND PAGE |
||
1089 | $htmlHeaders .= ' |
||
1090 | '; |
||
1091 | } else if (isset($_GET['page']) && $_GET['page'] == "manage_main") { |
||
1092 | // JAVASCRIPT FOR ADMIN PAGE |
||
1093 | $htmlHeaders .= ' |
||
1094 | //Function loads informations from cpassman FTP |
||
1095 | function LoadCPMInfo() |
||
1096 | { |
||
1097 | //Lauchn ajax query |
||
1098 | $.post( |
||
1099 | "sources/admin.queries.php", |
||
1100 | { |
||
1101 | type : "cpm_status" |
||
1102 | }, |
||
1103 | function(data) { |
||
1104 | if (data[0].error == "connection") { |
||
1105 | $("#CPM_infos").html("Server connection is impossible ... check your Internet/firewall configuration"); |
||
1106 | } else if (data[0].error == "conf_block") { |
||
1107 | $("#CPM_infos").html("No display available. Feature disabled in configuration."); |
||
1108 | } else { |
||
1109 | $("#CPM_infos").html("<span style=\'font-weight:bold;\'>'.$LANG['admin_info'].'</span>"+data[0].output+"</ul>"); |
||
1110 | } |
||
1111 | }, |
||
1112 | "json" |
||
1113 | ); |
||
1114 | } |
||
1115 | |||
1116 | /* |
||
1117 | * get statistics values |
||
1118 | */ |
||
1119 | function showStatsValues() { |
||
1120 | // send query |
||
1121 | $.post( |
||
1122 | "sources/admin.queries.php", |
||
1123 | { |
||
1124 | type : "get_values_for_statistics", |
||
1125 | key : "'.$_SESSION['key'].'" |
||
1126 | }, |
||
1127 | function(data) { |
||
1128 | //decrypt data |
||
1129 | try { |
||
1130 | data = prepareExchangedData(data , "decode", "'.$_SESSION['key'].'"); |
||
1131 | } catch (e) { |
||
1132 | // error |
||
1133 | $("#message_box").html("An error appears. Answer from Server cannot be parsed!<br />Returned data:<br />"+data).show().fadeOut(4000); |
||
1134 | |||
1135 | return; |
||
1136 | } |
||
1137 | if (data.error === "") { |
||
1138 | $("#value_items").html(data.stat_items); |
||
1139 | var ips = ""; |
||
1140 | $.each(data.stat_country, function( index, value ) { |
||
1141 | if (value > 0) { |
||
1142 | if (ips === "") ips = index+":"+value; |
||
1143 | else ips += ";"+index+":"+value; |
||
1144 | } |
||
1145 | }); |
||
1146 | $("#value_country").html(ips); |
||
1147 | $("#value_folders").html(data.stat_folders); |
||
1148 | $("#value_items_shared").html(data.stat_items_shared); |
||
1149 | $("#value_folders_shared").html(data.stat_folders_shared); |
||
1150 | $("#value_php").html(data.stat_phpversion); |
||
1151 | $("#value_users").html(data.stat_users); |
||
1152 | $("#value_admin").html(data.stat_admins); |
||
1153 | $("#value_manager").html(data.stat_managers); |
||
1154 | $("#value_ro").html(data.stat_ro); |
||
1155 | $("#value_teampassv").html(data.stat_teampassversion); |
||
1156 | $("#value_duo").html(data.stat_duo); |
||
1157 | $("#value_kb").html(data.stat_kb); |
||
1158 | $("#value_pf").html(data.pf); |
||
1159 | $("#value_ldap").html(data.stat_ldap); |
||
1160 | $("#value_agses").html(data.stat_agses); |
||
1161 | $("#value_suggestion").html(data.stat_suggestion); |
||
1162 | $("#value_api").html(data.stat_api); |
||
1163 | $("#value_customfields").html(data.stat_customfields); |
||
1164 | $("#value_syslog").html(data.stat_syslog); |
||
1165 | $("#value_2fa").html(data.stat_2fa); |
||
1166 | $("#value_https").html(data.stat_stricthttps); |
||
1167 | $("#value_mysql").html(data.stat_mysqlversion); |
||
1168 | $("#value_pf").html(data.stat_pf); |
||
1169 | $("#value_fav").html(data.stat_fav); |
||
1170 | var langs = ""; |
||
1171 | $.each(data.stat_languages, function( index, value ) { |
||
1172 | if (value > 0) { |
||
1173 | if (langs === "") langs = index+":"+value; |
||
1174 | else langs += ";"+index+":"+value; |
||
1175 | } |
||
1176 | }); |
||
1177 | $("#value_languages").html(langs); |
||
1178 | } |
||
1179 | } |
||
1180 | ); |
||
1181 | } |
||
1182 | |||
1183 | //Load function on page load |
||
1184 | $(function() { |
||
1185 | $("#but_save_send_stat").button(); |
||
1186 | |||
1187 | // calculate statistic values |
||
1188 | showStatsValues(); |
||
1189 | |||
1190 | if ($("#setting_send_stats").val() !== "1") { |
||
1191 | // show anonymous stats tab |
||
1192 | $("#tabs").tabs({active: 1}); |
||
1193 | } else { |
||
1194 | // show communication mean tab |
||
1195 | $("#tabs").tabs({active: 0}); |
||
1196 | } |
||
1197 | |||
1198 | $(".toggle").toggles({ |
||
1199 | drag: true, // allow dragging the toggle between positions |
||
1200 | click: true, // allow clicking on the toggle |
||
1201 | text: { |
||
1202 | on: "'.$LANG['yes'].'", // text for the ON position |
||
1203 | off: "'.$LANG['no'].'" // and off |
||
1204 | }, |
||
1205 | on: true, // is the toggle ON on init |
||
1206 | easing: "swing", // animation transition easing function |
||
1207 | animate: 250, // animation time (ms) |
||
1208 | width: 50, // width used if not set in css |
||
1209 | height: 20, // height if not set in css |
||
1210 | type: "compact" // if this is set to select then the select style toggle will be used |
||
1211 | }); |
||
1212 | $(".toggle").on("toggle", function(e, active) { |
||
1213 | if (active) { |
||
1214 | $("#send_stats_input").val(1); |
||
1215 | } else { |
||
1216 | $("#send_stats_input").val(0); |
||
1217 | } |
||
1218 | }); |
||
1219 | |||
1220 | $("#but_save_send_stat").click(function() { |
||
1221 | var list = ""; |
||
1222 | $(".stat_option:checked").each(function() { |
||
1223 | list += $(this).attr("id")+";"; |
||
1224 | }); |
||
1225 | // store in DB |
||
1226 | $.post( |
||
1227 | "sources/admin.queries.php", |
||
1228 | { |
||
1229 | type : "save_sending_statistics", |
||
1230 | list : list, |
||
1231 | status : $("#send_stats_input").val(), |
||
1232 | key : "'.$_SESSION['key'].'" |
||
1233 | }, |
||
1234 | function(data) { |
||
1235 | if (data[0].error === "" && data[0].result === "Done") { |
||
1236 | $("#but_save_send_stat").val("'.$LANG['alert_message_done'].'"); |
||
1237 | setTimeout( |
||
1238 | function() { |
||
1239 | $("#but_save_send_stat").val("'.$LANG['save_statistics_choice'].'"); |
||
1240 | }, |
||
1241 | 2000 |
||
1242 | ); |
||
1243 | |||
1244 | // if enabled, then send stats right now |
||
1245 | if ($("#send_stats_input").val() === "1") { |
||
1246 | // send statistics |
||
1247 | $.post( |
||
1248 | "sources/main.queries.php", |
||
1249 | { |
||
1250 | type : "sending_statistics", |
||
1251 | key : "'.$_SESSION['key'].'" |
||
1252 | } |
||
1253 | ); |
||
1254 | } |
||
1255 | } |
||
1256 | }, |
||
1257 | "json" |
||
1258 | ); |
||
1259 | }); |
||
1260 | |||
1261 | // manage checkbox |
||
1262 | $(".stat_option").change(function(){ |
||
1263 | var myid = $(this).attr("id").split("_"); |
||
1264 | if (this.checked) { |
||
1265 | $("#value_"+myid[1]).show(); |
||
1266 | } else { |
||
1267 | $("#value_"+myid[1]).hide(); |
||
1268 | } |
||
1269 | }); |
||
1270 | |||
1271 | $("#cb_select_all").click(function() { |
||
1272 | if ($("#cb_select_all").prop("checked")) { |
||
1273 | $(".stat_option").prop("checked", true); |
||
1274 | } else { |
||
1275 | $(".stat_option").prop("checked", false); |
||
1276 | } |
||
1277 | }); |
||
1278 | |||
1279 | LoadCPMInfo(); |
||
1280 | });'; |
||
1281 | } else if (isset($_GET['page']) && $_GET['page'] == "favourites") { |
||
1282 | // JAVASCRIPT FOR FAVOURITES PAGE |
||
1283 | $htmlHeaders .= ' |
||
1284 | $(function() { |
||
1285 | // DIALOG BOX FOR DELETING FAVOURITE |
||
1286 | $("#div_delete_fav").dialog({ |
||
1287 | bgiframe: true, |
||
1288 | modal: true, |
||
1289 | autoOpen: false, |
||
1290 | width: 300, |
||
1291 | height: 160, |
||
1292 | title: "'.$LANG['item_menu_del_from_fav'].'", |
||
1293 | buttons: { |
||
1294 | "'.$LANG['index_change_pw_confirmation'].'": function() { |
||
1295 | //Lauchn ajax query |
||
1296 | $.post( |
||
1297 | "sources/favourites.queries.php", |
||
1298 | { |
||
1299 | type : "del_fav", |
||
1300 | id : $("#detele_fav_id").val() |
||
1301 | }, |
||
1302 | function(data) { |
||
1303 | $("#row-" + $("#detele_fav_id").val()).remove(); |
||
1304 | $("#div_delete_fav").dialog("close"); |
||
1305 | } |
||
1306 | ); |
||
1307 | }, |
||
1308 | "'.$LANG['cancel_button'].'": function() { |
||
1309 | $(this).dialog("close"); |
||
1310 | } |
||
1311 | } |
||
1312 | }); |
||
1313 | }) |
||
1314 | |||
1315 | function prepare_delete_fav(id) |
||
1316 | { |
||
1317 | $("#detele_fav_id").val(id); |
||
1318 | OpenDialog("div_delete_fav"); |
||
1319 | }'; |
||
1320 | } else if (isset($_GET['page']) && isset($_SESSION['user_id'])) { |
||
1321 | // simulate a CRON activity (only 4 secs after page loading) |
||
1322 | // check for existing suggestions / changes |
||
1323 | $htmlHeaders .= ' |
||
1324 | setTimeout( |
||
1325 | function() { |
||
1326 | $.post( |
||
1327 | "sources/main.queries.php", |
||
1328 | { |
||
1329 | type : "is_existings_suggestions", |
||
1330 | key : "'.$_SESSION['key'].'" |
||
1331 | }, |
||
1332 | function(data) { |
||
1333 | //check if format error |
||
1334 | if (data[0].error === "" && parseInt(data[0].count) > 0) { |
||
1335 | // incase we need to show the menu button |
||
1336 | if (data[0].show_sug_in_menu === "1") { |
||
1337 | $("#menu_suggestion_position") |
||
1338 | .append("<a class=\"btn btn-default\" href=\"#\"><i class=\"fa fa-lightbulb-o fa-2x tip\" id=\"menu_icon_suggestions\" title=\"'.$LANG['suggestion_menu'].'\"></i></a>") |
||
1339 | .click (function() { |
||
1340 | MenuAction("suggestion"); |
||
1341 | }); |
||
1342 | $(".btn").button(); |
||
1343 | $(".tip").tooltipster({multiple: true}); |
||
1344 | } |
||
1345 | |||
1346 | $("#menu_icon_suggestions").addClass("mi-red"); |
||
1347 | |||
1348 | setInterval(function(){blink()}, 700); |
||
1349 | function blink() { |
||
1350 | $("#menu_icon_suggestions").fadeTo(100, 0.1).fadeTo(200, 1.0); |
||
1351 | } |
||
1352 | } |
||
1353 | }, |
||
1354 | "json" |
||
1355 | ); |
||
1356 | }, |
||
1357 | 4000 |
||
1358 | );'; |
||
1359 | } |
||
1360 | |||
1361 | $htmlHeaders .= ' |
||
1362 | // ]]> |
||
1363 | </script>'; |
||
1364 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.