This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from nilsteampassnet/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 8
/
roles.load.php
393 lines (368 loc) · 13.1 KB
/
roles.load.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
<?php
/**
* @package roles.load.php
* @author Nils Laumaillé <[email protected]>
* @version 2.1.27
* @copyright 2009-2019 Nils Laumaillé
* @license GNU GPL-3.0
* @link https://www.teampass.net
*
* 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.
*/
if (!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1) {
die('Hacking attempt...');
}
?>
<script type="text/javascript">
//<![CDATA[
$(function() {
// manage delete
$("input[name=right_types_radio]").click(function(event) {
if ($("input[name=right_types_radio]:checked").attr("id").substring(6) == "write") {
$("#div_delete_option").show();
} else {
$("#div_delete_option").hide();
}
});
$("#add_new_role").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 400,
height: 280,
title: "<?php echo $LANG["give_function_title"]; ?>",
buttons: {
"<?php echo $LANG["save_button"]; ?>": function() {
$("#new_role_error").hide().html("");
if ($("#new_role_complexity").val() != "") {
$("#add_role_loader").show();
$.post(
"sources/roles.queries.php",
{
type : "add_new_role",
name : $("#new_function").val(),
complexity : $("#new_role_complexity").val()
},
function(data) {
if (data[0].error == "no") {
$("#new_function").val("");
$("#add_new_role").dialog("close");
refresh_roles_matrix("reload");
} else {
$("#new_role_error").show().html(data[0].message);
}
$("#add_role_loader").hide();
},
"json"
);
} else {
$("#new_role_error").show().html("<?php echo addslashes($LANG['error_role_complex_not_set']); ?>");
}
},
"<?php echo $LANG["cancel_button"]; ?>": function() {
$(this).dialog("close");
}
}
});
$("#delete_role").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 400,
height: 190,
title: "<?php echo $LANG["admin_action"]; ?>",
buttons: {
"<?php echo $LANG["ok"]; ?>": function() {
$("#delete_role_loader").show();
$.post(
"sources/roles.queries.php",
{
type : "delete_role",
id : $("#delete_role_id").val()
},
function(data) {
if (data[0].error == "no") {
$("#delete_role").dialog("close");
refresh_roles_matrix("reload");
}
$("#delete_role_loader").hide();
},
"json"
);
},
"<?php echo $LANG["cancel_button"]; ?>": function() {
$(this).dialog("close");
}
}
});
$("#edit_role").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 400,
height: 300,
title: "<?php echo $LANG["admin_action"]; ?>",
buttons: {
"<?php echo $LANG["ok"]; ?>": function() {
$("#edit_role_error").hide().html("");
$("#edit_role_loader").show();
$.post(
"sources/roles.queries.php",
{
type : "edit_role",
id : $("#edit_role_id").val(),
start : $('#role_start').val(),
title : $("#edit_role_title").val(),
complexity : $("#edit_role_complexity").val()
},
function(data) {
if (data[0].error == "yes") {
$("#edit_role_error").show().html(data[0].message);
} else {
$("#edit_role_title").val("");
$("#edit_role").dialog("close");
$("#div_loading").show();
refresh_roles_matrix("reload");
}
$("#edit_role_loader").hide();
},
"json"
);
},
"<?php echo $LANG["cancel_button"]; ?>": function() {
$("#edit_role_error").html("").hide();
$(this).dialog("close");
}
}
});
$("#type_of_rights").dialog({
bgiframe: false,
modal: false,
autoOpen: false,
width: 300,
height: 270,
title: "<?php echo $LANG["change_right_access"]; ?>",
buttons: {
"<?php echo $LANG["save_button"]; ?>": function() {
$("#edit_role_error").hide().html("");
$("#role_rights_loader").show();
// get write option
var accessoption = "";
if ($("input[name=right_types_radio]:checked").attr("id").substring(6) == "write") {
if ($("#right_nodelete").prop("checked") === true && $("#right_noedit").prop("checked") === true) {
accessoption = "nodelete_noedit";
} else if ($("#right_nodelete").prop("checked") === true) {
accessoption = "nodelete";
} else if ($("#right_noedit").prop("checked") === true) {
accessoption = "noedit";
}
}
// is several folders selected?
var multiselection = '',
tmp;
$(".multi_folders:checkbox:checked").each(function(){
tmp = $(this).attr('id').substring(9).split('_');
multiselection += tmp[0] + "-" + tmp[1] + ","; //folder_id-role_id
});
multiselection += $("#change_folder").val() + "-" + $('#change_role').val();
$.post(
"sources/roles.queries.php",
{
type : "change_role_via_tm",
access : $("input[name=right_types_radio]:checked").attr("id").substring(6),
accessoption : accessoption,
//folder : $("#change_folder").val(),
//role : $('#change_role').val(),
line : $("#change_line").val(),
multiselection: multiselection
},
function(data) {
$("#div_loading").show();
refresh_roles_matrix("reload");
$("#type_of_rights").dialog("close");
$("#role_rights_loader").hide();
},
"json"
);
},
"<?php echo $LANG["close"]; ?>": function() {
$(this).dialog("close");
}
},
open: function() {
$("#accordion").accordion({ autoHeight: false, navigation: true, collapsible: true, active: false });
}
});
refresh_roles_matrix();
});
//###########
//## FUNCTION : Change the actual right of the role other the select folder
//###########
function tm_change_role(role,folder,cell_id,allowed)
{
$("#div_loading").show();
$.post(
"sources/roles.queries.php",
{
type : "change_role_via_tm",
role : role,
folder : folder,
cell_id : cell_id,
allowed : allowed
},
function(data) {
refresh_roles_matrix("reload");
$("#div_loading").hide();
}
);
}
function delete_this_role(id,name)
{
$("#delete_role_id").val(id);
$("#delete_role_show").html(name);
$("#delete_role").dialog("open");
}
function edit_this_role(id,name,complexity)
{
$("#edit_role_id").val(id);
$("#edit_role_show").html(name);
$("#edit_role_title").val(name);
$("#edit_role_complexity").val(complexity);
$("#edit_role").dialog("open");
}
function allow_pw_change_for_role(id, value)
{
$("#div_loading").show();
//Send query
$.post(
"sources/roles.queries.php",
{
type : "allow_pw_change_for_role",
id : id,
value : value
},
function(data) {
if (value == 0)
$("#img_apcfr_"+id).attr("class","fa mi-red fa-2x fa-magic tip");
else
$("#img_apcfr_"+id).attr("class","fa mi-green fa-2x fa-magic tip");
$("#div_loading").hide();
refresh_roles_matrix("reload");
}
);
}
/**
*
* @access public
* @return void
**/
function refresh_roles_matrix(order)
{
$("#div_loading").show();
//clean up
$(".roles_next, .roles_previous").hide();
//manage start query
if (order == "next") {
var start = $('#next_role').val();
} else if (order == "previous") {
var start = $('#previous_role').val();
} else if (order == "reload") {
var start = $('#role_start').val();
} else {
var start = 0;
}
$('#role_start').val(start);
//send query
$.post(
"sources/roles.queries.php",
{
type : "refresh_roles_matrix",
start : start,
filter : $("#filter_roles").val()
},
function(data) {
//decrypt data
data = $.parseJSON(data);
$("#matrice_droits").html("");
if (data.new_table !== "") {
$("#matrice_droits").html(data.new_table);
if (data.next <= data.all && data.next >= 8) {
$(".roles_next").show();
}
if (data.next >= 8 && start > 0) {
$(".roles_previous").show();
}
//manage next & previous arrows
$('#next_role').val(data.next);
$('#previous_role').val(data.previous);
} else {
$("#matrice_droits").html(data.error);
}
// Prepare autocomplete for filterbox
$("#filter_roles")
.autocomplete({
source: data.list_of_roles,
focus: function() {
// prevent value inserted on focus
return false;
}
}
);
// Filter folders
$('#filter_folders').keypress(function(e) {
if (e.which === 13) {
var criteria = $(this).val().trim().toLowerCase();
$('.folder-name').each(function(i, obj) {
if ($(this).text().trim().toLowerCase().indexOf(criteria) > -1) {
$(this).closest('tr').removeClass('hidden');
} else {
$(this).closest('tr').addClass('hidden');
}
});
}
});
// Clear folders filter
$('.eraser').click(function() {
$('#filter_folders').val('');
refresh_roles_matrix("reload");
});
$("#div_loading").hide();
}
);
}
function openRightsDialog(role, folder, line, right)
{
if (right == "W") {
$("#right_write").prop("checked", true);
$("#right_nodelete, #right_noedit").prop("checked", false);
$("#div_delete_option").show();
} else if (right == "ND") {
$("#right_write").prop("checked", true);
$("#right_nodelete").prop("checked", true);
$("#right_noedit").prop("checked", false);
$("#div_delete_option").show();
} else if (right == "NE") {
$("#right_write").prop("checked", true);
$("#right_nodelete").prop("checked", false);
$("#right_noedit").prop("checked", true);
$("#div_delete_option").show();
} else if (right == "NDNE") {
$("#right_write").prop("checked", true);
$("#right_noedit, #right_nodelete").prop("checked", true);
$("#div_delete_option").show();
} else if (right == "R") {
$("#right_read").prop("checked", true);
$("#div_delete_option").hide();
} else {
$("#right_noaccess").prop("checked", true);
$("#div_delete_option").hide();
}
$("#change_role").val(role);
$("#change_folder").val(folder);
$("#change_line").val(line);
$("#type_of_rights").dialog("open");
}
//]]>
</script>