/
load.js.php
executable file
·1759 lines (1569 loc) · 75 KB
/
load.js.php
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
/**
* 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 3.0.0.23
* @file load.js.php
* ---
*
* @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
*/
if (isset($_SESSION['CPM']) === false || (int) $_SESSION['CPM'] !== 1) {
die('Hacking attempt...');
}
// Is maintenance on-going?
if (
isset($SETTINGS['maintenance_mode']) === true
&& (int) $SETTINGS['maintenance_mode'] === 1
&& ($session_user_admin === null
|| (int) $session_user_admin === 1)
) {
?>
<script type="text/javascript">
toastr.remove();
toastr.info(
'<?php echo langHdl('index_maintenance_mode_admin'); ?>',
'<?php echo langHdl('information'); ?>', {
timeOut: 0
}
);
</script>
<?php
}
?>
<script type="text/javascript">
var userScrollPosition = 0,
debugJavascript = false;
let hourInMinutes = 60;
/**
* Add 1 hour to session duration
**/
function IncreaseSessionTime(duration)
{
duration = duration || hourInMinutes;
$.post(
'sources/main.queries.php',
{
type : 'increase_session_time',
type_category: 'action_user',
duration : parseInt(duration, 10) * hourInMinutes,
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
if (data[0].new_value !== 'expired') {
$('#temps_restant').val(data[0].new_value);
$('#date_end_session').val(data[0].new_value);
$('#countdown').css('color', 'white');
} else {
$(location).attr('href', 'index.php?session=expired');
}
},
'json'
);
}
// Start real time
// get list of last items
if (store.get('teampassUser') !== undefined && parseInt(store.get('teampassUser').user_id) > 0
&& String('<?php echo $_SESSION['key']; ?>') === store.get('teampassUser').sessionKey
&& (Date.now() - store.get('teampassUser').sessionStartTimestamp) < (store.get('teampassUser').sessionDuration * 1000)
) {
$.when(
// Load teampass settings
loadSettings()
).then(function() {
$.when(
// Refresh list of last items shopwn
refreshListLastSeenItems()
).then(function() {
// Check if new privatekey needs to be adapted
var data = {
'user_id': store.get('teampassUser').user_id,
'fields' : 'special, auth_type',
}
$.post(
"sources/main.queries.php", {
type: "get_user_info",
type_category: 'action_user',
data: prepareExchangedData(JSON.stringify(data), 'encode', '<?php echo $_SESSION['key']; ?>'),
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
//decrypt data
data = decodeQueryReturn(data, '<?php echo $_SESSION['key']; ?>');
if (debugJavascript === true) {
console.info('Get user info results:');
console.log(data);
}
// update local storage
store.update(
'teampassUser', {},
function(teampassUser) {
teampassUser.special = data.queryResults.special;
teampassUser.auth_type = data.queryResults.auth_type;
}
);
if (data.error === false && data.queryResults.special === 'generate-keys') {
// Now we need to perform re-encryption due to LDAP password change
if (debugJavascript === true) console.log('User has to regenerate keys')
// HIde
$('.content-header, .content').addClass('hidden');
$('#dialog-user-temporary-code-info').html('<i class="icon fas fa-info mr-2"></i><?php echo langHdl('renecyption_expected');?>');
// Show passwords inputs and form
$('#dialog-user-temporary-code').removeClass('hidden');
// ----
} else if (data.error === false && data.queryResults.special === 'auth-pwd-change' && data.queryResults.auth_type === 'local') {
// USer's password has been reseted, he shall change it
if (debugJavascript === true) console.log('User has to change his auth password')
// HIde
$('.content-header, .content').addClass('hidden');
// Show passwords inputs and form
$('#dialog-user-change-password-info')
.html('<i class="icon fas fa-info mr-2"></i><?php echo langHdl('user_has_to_change_password_info');?>')
.removeClass('hidden');
$('#dialog-user-change-password').removeClass('hidden');
// ----
} else if (data.error === false && data.queryResults.special === 'auth-pwd-change' && data.queryResults.auth_type === 'ldap') {
// USer's password has been reseted, he shall change it
if (debugJavascript === true) console.log('LDAP user password has to change his auth password')
// HIde
$('.content-header, .content').addClass('hidden');
// Show passwords inputs and form
$('#dialog-ldap-user-change-password-info')
.html('<i class="icon fas fa-info mr-2"></i><?php echo langHdl('ldap_user_has_changed_his_password');?>')
.removeClass('hidden');
$('#dialog-ldap-user-change-password').removeClass('hidden');
// ----
} else if (
(data.error === false && data.queryResults.special === 'user_added_from_ldap' && data.queryResults.auth_type === 'ldap')
|| (typeof data.queryResults !== 'undefined' && data.queryResults.special === 'otc_is_required_on_next_login')
) {
// USer's password has been reseted, he shall change it
if (debugJavascript === true) console.log('NEW LDAP user password - we need to encrypt items')
// HIde
$('.content-header, .content').addClass('hidden');
// Show form
$('#dialog-ldap-user-build-keys-database').removeClass('hidden');
} else if (typeof data.queryResults !== 'undefined' && data.queryResults.special === 'recrypt-private-key') {
// USer's password has been reseted, he shall change it
if (debugJavascript === true) console.log('NEW LDAP - we need to encrypt private key')
// HIde
$('.content-header, .content').addClass('hidden');
// Show form
$('#dialog-ldap-user-change-password').removeClass('hidden');
}
}
);
}).then(function() {
if (store.get('teampassSettings') === undefined || parseInt(store.get('teampassSettings').enable_tasks_manager) === 0) {
console.log('Now sending emails')
setTimeout(
function() {
$.when(
// send email
$.post(
"sources/main.queries.php", {
type: "send_waiting_emails",
type_category: 'action_mail',
key: "<?php echo $_SESSION['key']; ?>"
}
)
).then(function() {
// send statistics
$.post(
"sources/main.queries.php", {
type: "sending_statistics",
type_category: 'action_system',
key: "<?php echo $_SESSION['key']; ?>"
}
);
});
},
3000
);
}
// Save user location
//console.info("DEBUG - Save user location -"+store.get('teampassUser').location_stored)
if (store.get('teampassUser').location_stored !== 1) {
// Save user location
$.post(
"sources/users.queries.php", {
type: 'save_user_location',
step: "perform",
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
// update local storage
store.update(
'teampassUser', {},
function(teampassUser) {
teampassUser.location_stored = 1;
}
);
}
);
}
});
});
}
//-- end
// Countdown
countdown();
$(".show_hide_password a").on('click', function(event) {
event.preventDefault();
if($('.how_hide_password input').attr("type") === "text"){
$('.show_hide_password input').attr('type', 'password');
$('.show_hide_password i').addClass( "fa-eye-slash" );
$('.show_hide_password i').removeClass( "fa-eye" );
}else if($('#show_hide_password input').attr("type") === "password"){
$('.show_hide_password input').attr('type', 'text');
$('.show_hide_password i').removeClass( "fa-eye-slash" );
$('.show_hide_password i').addClass( "fa-eye" );
}
});
if (store.get('teampassUser') !== undefined &&
store.get('teampassUser').special === 'generate-keys'
) {
// Now we need to perform re-encryption due to LDAP password change
console.log('User has to regenerate keys')
// HIde
$('.content-header, .content').addClass('hidden');
$('#dialog-user-temporary-code-info').html('<i class="icon fas fa-info mr-2"></i><?php echo langHdl('renecyption_expected');?>');
// Show passwords inputs and form
$('#dialog-user-temporary-code').removeClass('hidden');
// ---
} else if (store.get('teampassUser') !== undefined &&
store.get('teampassUser').special === 'ldap_password_has_changed_do_reencryption'
) {
// Now we need to perform re-encryption due to LDAP password change
console.log('show password change')
// HIde
$('.content-header, .content, #button_do_sharekeys_reencryption').addClass('hidden');
$('#warning-text-reencryption').html('<i class="icon fas fa-info mr-2"></i>'.langHdl('ldap_password_change_warning'));
// Show passwords inputs and form
$('#dialog-encryption-keys, .ask-for-previous-password').removeClass('hidden');
$('#sharekeys_reencryption_target_user').val(store.get('teampassUser').user_id);
$('#button_do_sharekeys_reencryption').removeClass('hidden');
// ---
} else if (store.get('teampassUser') !== undefined &&
store.get('teampassUser').shown_warning_unsuccessful_login === false
) {
// If login attempts experimented
// Prepare modal
showModalDialogBox(
'#warningModal',
'<i class="fas fa-user-shield fa-lg warning mr-2"></i><?php echo langHdl('caution'); ?>',
'<?php echo langHdl('login_attempts_identified_since_last_connection'); ?>',
'<?php echo langHdl('see_detail'); ?>',
'<?php echo langHdl('cancel'); ?>'
);
// Actions on modal buttons
$(document).on('click', '#warningModalButtonClose', function() {
store.update(
'teampassUser', {},
function(teampassUser) {
teampassUser.shown_warning_unsuccessful_login = true;
}
);
});
$(document).on('click', '#warningModalButtonAction', function() {
// SHow user
toastr.remove();
toastr.info('<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>');
// Action
store.update(
'teampassUser', {},
function(teampassUser) {
teampassUser.shown_warning_unsuccessful_login = true;
}
);
document.location.href = "index.php?page=profile&tab=timeline";
});
} else if (store.get('teampassUser') !== undefined &&
store.get('teampassUser').special === 'private_items_to_encrypt'
) {
// If user has to re-encrypt his personal item passwords
$('#dialog-encryption-personal-items-after-upgrade').removeClass('hidden');
$('.content, .content-header').addClass('hidden');
// Actions on modal buttons
$(document).on('click', '#button_do_personal_items_reencryption', function() {
// SHow user
toastr.remove();
toastr.info('<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>');
defusePskRemoval(store.get('teampassUser').user_id, 'psk', 0);
function defusePskRemoval(userId, step, start)
{
if (step === 'psk') {
// Inform user
$("#user-current-defuse-psk-progress").html('<b><?php echo langHdl('encryption_keys'); ?> </b> [' + start + ' - ' + (parseInt(start) + <?php echo NUMBER_ITEMS_IN_BATCH;?>) + '] ' +
'... <?php echo langHdl('please_wait'); ?><i class="fas fa-spinner fa-pulse ml-3 text-primary"></i>');
var data = {
'userPsk' : $('#user-current-defuse-psk').val(),
'start': start,
'length': <?php echo NUMBER_ITEMS_IN_BATCH;?>,
'user_id': userId,
};
// Do query
$.post(
"sources/main.queries.php", {
'type': "user_psk_reencryption",
'type_category': 'action_key',
'data': prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
'key': '<?php echo $_SESSION['key']; ?>'
},
function(data) {
data = prepareExchangedData(data, "decode", "<?php echo $_SESSION['key']; ?>");
if (debugJavascript === true) console.log(data)
if (data.error === true) {
// error
toastr.remove();
toastr.error(
data.message,
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
// Enable buttons
$("#user-current-defuse-psk-progress").html('<?php echo langHdl('provide_current_psk_and_click_launch'); ?>');
$('#button_do_sharekeys_reencryption, #button_close_sharekeys_reencryption').removeAttr('disabled');
return false;
} else {
// Start looping on all steps of re-encryption
defusePskRemoval(data.userId, data.step, data.start);
}
}
);
} else {
// Finished
$("#user-current-defuse-psk-progress").html('<i class="fas fa-check text-success mr-3"></i><?php echo langHdl('done'); ?>');
toastr.remove();
}
}
});
$(document).on('click', '#button_close_personal_items_reencryption', function() {
$('#dialog-encryption-personal-items-after-upgrade').addClass('hidden');
$('.content, .content-header').removeClass('hidden');
});
}
// Show tooltips
$('.infotip').tooltip();
// Sidebar redirection
$('.nav-link').click(function() {
if ($(this).data('name') !== undefined) {
//NProgress.start();
document.location.href = "index.php?page=" + $(this).data('name');
}
});
// User menu action
$('.user-menu').click(function() {
if ($(this).data('name') !== undefined) {
if ($(this).data('name') === 'increase_session') {
showExtendSession();
} else if ($(this).data('name') === 'sync-new-ldap-password') {
// This case permits to handle a case where user has changed his password in LDAP
console.log('show sync-new-ldap-password')
if (debugJavascript === true) console.log('LDAP user password has to change his auth password')
// HIde
$('.content-header, .content').addClass('hidden');
// Show passwords inputs and form
$('#dialog-ldap-user-change-password-info')
.html('<i class="icon fas fa-info mr-2"></i><?php echo langHdl('ldap_user_has_changed_his_password');?>')
.removeClass('hidden');
$('#dialog-ldap-user-change-password').removeClass('hidden');
// ----
} else if ($(this).data('name') === 'password-change') {
console.log('show password change')
// HIde
$('.content-header, .content, #button_do_user_change_password').addClass('hidden');
// Add DoCheck button
$('#button_do_user_change_password').after('<button class="btn btn-primary" id="button_do_pwds_checks"><?php echo langHdl('perform_checks'); ?></button>');
// Show passwords inputs and form
$('#dialog-user-change-password-progress').html('<i class="icon fas fa-info mr-2"></i><?php echo langHdl('change_your_password_info_message'); ?>');
$('#dialog-user-change-password').removeClass('hidden');
// Actions
$('#button_do_pwds_checks').click(function() {
if ($('#profile-password').val() !== $('#profile-password-confirm').val()) {
$('#button_do_user_change_password').addClass('hidden');
toastr.remove();
toastr.error(
'<?php echo langHdl('passwords_not_the_same'); ?>',
'<?php echo langHdl('caution'); ?>', {
timeOut: 3000,
progressBar: true
}
);
} else if (parseInt($('#profile-password-complex').val()) >= parseInt(store.get('teampassSettings').personal_saltkey_security_level)) {
$('#button_do_user_change_password').removeClass('hidden');
$('#button_do_pwds_checks').remove();
toastr.remove();
toastr.info(
'<?php echo langHdl('hit_launch_to_start'); ?>',
'<?php echo langHdl('ready_to_go'); ?>', {
timeOut: 3000,
progressBar: true
}
);
} else {
$('#button_do_user_change_password').addClass('hidden');
toastr.remove();
toastr.error(
'<?php echo langHdl('complexity_level_not_reached'); ?>',
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
}
});
// ----
} else if ($(this).data('name') === 'profile') {
// Show profile page
document.location.href = "index.php?page=profile";
} else if ($(this).data('name') === 'logout') {
// Logout directly to login form
window.location.href = "./includes/core/logout.php?user_id=" + <?php echo $_SESSION['user_id']; ?>
}
}
});
$('.close-element').click(function() {
$(this).closest('.card').addClass('hidden');
$('.content-header, .content').removeClass('hidden');
});
/**
* When clicking save Personal saltkey
*/
/*
$('#button_save_user_psk').click(function() {
toastr.remove();
toastr.info(
'<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>'
);
// Prepare data
var data = {
"psk": sanitizeString($("#user_personal_saltkey").val()),
"complexity": $("#psk_strength_value").val()
};
//
$.post(
"sources/main.queries.php", {
type: "store_personal_saltkey",
data: prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
key: '<?php echo $_SESSION['key']; ?>'
},
function(data) {
data = prepareExchangedData(data, '<?php echo $_SESSION['key']; ?>');
// Is there an error?
if (data.error === true) {
toastr.remove();
toastr.error(
'<?php echo langHdl('warning'); ?>',
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
} else {
store.update(
'teampassUser',
function(teampassUser) {
teampassUser.pskDefinedInDatabase = 1;
}
)
store.update(
'teampassUser',
function(teampassUser) {
teampassUser.pskSetForSession = data.encrypted_psk;
}
)
toastr.remove();
toastr.success(
'<?php echo langHdl('alert_page_will_reload'); ?>'
);
location.reload();
}
}
);
});
*/
// For Personal Saltkey
$("#profile-password").simplePassMeter({
"requirements": {},
"container": "#profile-password-strength",
"defaultText": "<?php echo langHdl('index_pw_level_txt'); ?>",
"ratings": [{
"minScore": 0,
"className": "meterFail",
"text": "<?php echo langHdl('complex_level0'); ?>"
},
{
"minScore": 25,
"className": "meterWarn",
"text": "<?php echo langHdl('complex_level1'); ?>"
},
{
"minScore": 50,
"className": "meterWarn",
"text": "<?php echo langHdl('complex_level2'); ?>"
},
{
"minScore": 60,
"className": "meterGood",
"text": "<?php echo langHdl('complex_level3'); ?>"
},
{
"minScore": 70,
"className": "meterGood",
"text": "<?php echo langHdl('complex_level4'); ?>"
},
{
"minScore": 80,
"className": "meterExcel",
"text": "<?php echo langHdl('complex_level5'); ?>"
},
{
"minScore": 90,
"className": "meterExcel",
"text": "<?php echo langHdl('complex_level6'); ?>"
}
]
});
$("#profile-password").bind({
"score.simplePassMeter": function(jQEvent, score) {
$("#profile-password-complex").val(score);
}
}).change({
"score.simplePassMeter": function(jQEvent, score) {
$("#profile-password-complex").val(score);
}
});
// Hide sidebar footer icons when reducing sidebar
$('a[data-widget="pushmenu"]').click(function(event) {
if ($('#sidebar-footer').hasClass('hidden') === true) {
setTimeout(function() {
$('#sidebar-footer').removeClass('hidden');
}, 300);
} else {
$('#sidebar-footer').addClass('hidden');
}
});
var clipboardCopy = new ClipboardJS(".clipboard-copy", {
text: function(trigger) {
var elementId = $(trigger).data('clipboard-text');
if (debugJavascript === true) console.log($('#' + elementId).val())
return String($('#' + elementId).val());
}
});
clipboardCopy.on('success', function(e) {
toastr.remove();
toastr.info(
'<?php echo langHdl('copy_to_clipboard'); ?>',
'<?php echo langHdl('information'); ?>', {
timeOut: 2000
}
);
});
// Progress bar
setTimeout(
function() {
$(".fade").removeClass("out");
},
1000
);
/**
* USER HAS DECIDED TO CHANGE HIS AUTH PASSWORD
*/
$(document).on('click', '#dialog-user-change-password-do', function() {
// Start by changing the user password and send it by email
if ($('#profile-password-confirm').val() !== $('#profile-password').val()) {
// Show error
toastr.remove();
toastr.error(
'<?php echo langHdl('index_pw_error_identical'); ?>',
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
return false;
}
if ($('#profile-current-password').val() !== "" && $('#profile-password').val() !== "" && $('#profile-password-confirm').val() !== "") {
// Case where a user is changing his authentication password
console.log('Reencryption based upon user decision to change his auth password');
// Show progress
$('#dialog-user-change-password-progress').html('<b><?php echo langHdl('please_wait'); ?></b><i class="fas fa-spinner fa-pulse ml-3 text-primary"></i>');
toastr.remove();
toastr.info(
'<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>'
);
// Disable buttons
$('#dialog-user-change-password-do, #dialog-user-change-password-close').attr('disabled', 'disabled');
data = {
'user_id': store.get('teampassUser').user_id,
'old_password': $('#profile-current-password').val(),
'new_password': $('#profile-password').val(),
}
if (debugJavascript === true) console.log(data);
// Check user current password
// and change the password
// and use the password to re-encrypt the privatekey
$.post(
'sources/main.queries.php', {
type: 'change_user_auth_password',
type_category: 'action_password',
data: prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
data = prepareExchangedData(data, 'decode', '<?php echo $_SESSION['key']; ?>');
if (debugJavascript === true) console.log(data);
if (data.error !== false) {
// Show error
toastr.remove();
toastr.error(
data.message,
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
$("#dialog-user-change-password-progress").html('<?php echo langHdl('fill_in_fields_and_hit_launch'); ?>');
// Enable buttons
$('#dialog-user-change-password-do, #dialog-user-change-password-close').removeAttr('disabled');
} else {
// SUCCESS
$('#dialog-user-change-password-close').removeAttr('disabled');
toastr.remove();
toastr.success(
data.message,
'<?php echo langHdl('success'); ?>', {
timeOut: 5000,
progressBar: true
}
);
$("#dialog-user-change-password-progress").html('');
$('#dialog-user-change-password').addClass('hidden');
$('.content-header, .content').removeClass('hidden');
}
}
);
} else {
// Show error
toastr.remove();
toastr.error(
'<?php echo langHdl('password_cannot_be_empty'); ?>',
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
}
});
$(document).on('click', '#dialog-user-change-password-close', function() {
// HIde
$('.content-header, .content').removeClass('hidden');
// SHow form
$('#dialog-user-change-password, #dialog-user-change-password-info').addClass('hidden');
});
/**
* ADMIN HAS DECIDED TO CHANGE THE USER'S AUTH PASSWORD
*/
$(document).on('click', '#dialog-admin-change-user-password-do', function() {
// When an admin changes the user auth password
console.log('Reencryption based upon admin decision to change user auth password');
// Show progress
$('#dialog-admin-change-user-password-progress').html('<b><?php echo langHdl('please_wait'); ?></b><i class="fas fa-spinner fa-pulse ml-3 text-primary"></i>');
toastr.remove();
toastr.info(
'<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>'
);
// Disable buttons
$('#dialog-admin-change-user-password-do, #dialog-admin-change-user-password-close').attr('disabled', 'disabled');
// ENsure we have a user id
if ($('#admin_change_user_password_target_user').val() !== '') {
// Case where change is for user's account
data = {
'user_id': $('#admin_change_user_password_target_user').val(),
'special': 'auth-pwd-change',
'password': '',
'self_change': false,
}
//console.log(data);
$.post(
'sources/main.queries.php', {
type: 'initialize_user_password',
type_category: 'action_password',
data: prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
data = prepareExchangedData(data, 'decode', '<?php echo $_SESSION['key']; ?>');
if (debugJavascript === true) console.log(data)
store.set(
'teampassUser', {
admin_user_password: data.user_pwd,
admin_user_email: data.user_email,
}
);
if (data.error !== false) {
// Show error
toastr.remove();
toastr.error(
data.message,
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
// Enable buttons
$('#dialog-admin-change-user-password-do, #dialog-admin-change-user-password-close').removeAttr('disabled');
} else {
// Inform user
userShareKeysReencryption(
$('#admin_change_user_password_target_user').val(),
false,
'dialog-admin-change-user-password'
);
}
}
);
}
});
$(document).on('click', '#dialog-admin-change-user-password-close', function() {
// HIde
$('.content-header, .content').removeClass('hidden');
// SHow form
$('#dialog-admin-change-user-password').addClass('hidden');
});
$(document).on('click', '.temp-button', function() {
if ($(this).data('action') === "show-user-pwd") {
// show password
$('#temp-user-pwd').attr('type', 'text');
$(this).prop( "disabled", true );
setTimeout(
() => {
$('#temp-user-pwd').attr('type', 'hidden');
$(this).prop( "disabled", false );
},
5000
);
} else if ($(this).data('action') === "send-user-pwd") {
// Send email
console.log('Preparing for email sending');
// Prepare data
var data = {
'receipt': $('#temp-user-email').val(),
'subject': '[Teampass] <?php echo langHdl('your_new_password');?>',
'body': '<?php echo langHdl('email_body_temporary_login_password');?>',
'pre_replace' : {
'#enc_code#' : $('#temp-user-pwd').val(),
}
}
if (debugJavascript === true) console.log(data);
// Prepare form
$('#dialog-admin-change-user-password-info').html('<?php echo langHdl('sending_email_message');?>');
toastr.remove();
toastr.info(
'<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>'
);
// Launch action
$.post(
'sources/main.queries.php', {
type: 'mail_me',
type_category: 'action_mail',
data: prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
key: '<?php echo $_SESSION['key']; ?>'
},
function(data) {
data = prepareExchangedData(data, 'decode', '<?php echo $_SESSION['key']; ?>');
if (debugJavascript === true) console.log(data);
if (data.error !== false) {
// Show error
toastr.remove();
toastr.error(
data.message,
'', {
timeOut: 5000,
progressBar: true
}
);
} else {
// Fianlize UI
$('#dialog-admin-change-user-password-info').html('');
$('#dialog-admin-change-user-password-do, #dialog-admin-change-user-password-close').removeAttr('disabled');
// HIde
$('.content-header, .content').removeClass('hidden');
// SHow form
$('#dialog-admin-change-user-password').addClass('hidden');
store.set(
'teampassUser', {
admin_user_password: '',
admin_user_email: '',
}
);
// Inform user
toastr.remove();
toastr.success(
'<?php echo langHdl('done'); ?>',
'', {
timeOut: 1000
}
);
}
}
);
}
});
/**
* USER PROVIDES HIS TEMPORARY CODE TO
*/
$(document).on('click', '#dialog-user-temporary-code-do', function() {
// Perform a renecryption based upon a temporary code
console.log('Reencryption based upon users temporary code');
// Show progress
$('#dialog-user-temporary-code-progress').html('<b><?php echo langHdl('please_wait'); ?></b><i class="fas fa-spinner fa-pulse ml-3 text-primary"></i>');
toastr.remove();
toastr.info(
'<?php echo langHdl('in_progress'); ?><i class="fas fa-circle-notch fa-spin fa-2x ml-3"></i>'
);
// Disable buttons
$('#dialog-user-temporary-code-do, #dialog-user-temporary-code-close').attr('disabled', 'disabled');
// Start by testing if the temporary code is correct to decrypt an item
data = {
'user_id': store.get('teampassUser').user_id,
'password': $('#dialog-user-temporary-code-value').val(),
}
if (debugJavascript === true) console.log(data);
$.post(
'sources/main.queries.php', {
type: 'test_current_user_password_is_correct',
type_category: 'action_password',
data: prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
data = prepareExchangedData(data, 'decode', '<?php echo $_SESSION['key']; ?>');
if (debugJavascript === true) console.log(data);
if (data.error !== false) {
// Show error
toastr.remove();
toastr.error(
data.message,
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}
);
$("#dialog-user-temporary-code-progress").html('<?php echo langHdl('fill_in_fields_and_hit_launch'); ?>');
// Enable buttons
$('#dialog-user-temporary-code-do, #dialog-user-temporary-code-close').removeAttr('disabled');
} else {
// Change privatekey encryption with user-s password
data = {
'user_id': store.get('teampassUser').user_id,
'current_code': $('#dialog-user-temporary-code-current-password').val(),
'new_code': $('#dialog-user-temporary-code-value').val(),
'action_type' : 'encrypt_privkey_with_user_password',
}
if (debugJavascript === true) console.log(data);
$.post(
'sources/main.queries.php', {
type: 'change_private_key_encryption_password',
type_category: 'action_key',
data: prepareExchangedData(JSON.stringify(data), "encode", "<?php echo $_SESSION['key']; ?>"),
key: "<?php echo $_SESSION['key']; ?>"
},
function(data) {
data = prepareExchangedData(data, 'decode', '<?php echo $_SESSION['key']; ?>');
if (debugJavascript === true) console.log(data);
if (data.error !== false) {
// Show error
toastr.remove();
toastr.error(
data.message,
'<?php echo langHdl('caution'); ?>', {
timeOut: 5000,
progressBar: true
}