forked from 418sec/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kb.load.php
188 lines (177 loc) · 7.36 KB
/
kb.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
<?php
/**
* @package kb.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 || !isset($SETTINGS['enable_kb']) || $SETTINGS['enable_kb'] != 1) {
die('Hacking attempt...');
}
// Load config
if (file_exists('../includes/config/tp.config.php')) {
include_once '../includes/config/tp.config.php';
} elseif (file_exists('./includes/config/tp.config.php')) {
include_once './includes/config/tp.config.php';
} else {
throw new Exception("Error file '/includes/config/tp.config.php' not exists", 1);
}
?>
<script type="text/javascript">
//<![CDATA[
//Function opening
function openKB(id)
{
$.post(
"sources/kb.queries.php",
{
type : "open_kb",
id : id,
key : "<?php echo $_SESSION['key']; ?>"
},
function(data) {
data = $.parseJSON(data);
$("#kb_label").val(data.label);
$("#kb_category").val(data.category);
$("#kb_description").val(data.description);
$("#kb_id").val(id);
if (data.anyone_can_modify == 0) {
$("#modify_kb_no").prop("checked", true);
} else {
$("#modify_kb_yes").prop("checked", true);
}
for (var i=0; i < data.options.length; ++i) {
$("#kb_associated_to option[value="+data.options[i]+"]").prop("selected", true);
}
$("#kb_form").dialog("open");
}
);
}
//Function deleting
function deleteKB(id)
{
$("#kb_id").val(id);
$("#div_kb_delete").dialog("open");
}
$(function() {
//Launch the datatables pluggin
$("#t_kb").dataTable({
"aaSorting": [[ 1, "asc" ]],
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "<?php echo $SETTINGS['cpassman_url']; ?>/sources/datatable/datatable.kb.php?token=<?php echo $_SESSION["key"]; ?>",
"bJQueryUI": true,
"oLanguage": {
"sUrl": "<?php echo $SETTINGS['cpassman_url']; ?>/includes/language/datatables.<?php echo $_SESSION['user_language']; ?>.txt"
}
});
//Dialogbox for deleting KB
$("#div_kb_delete").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 300,
height: 150,
title: "<?php echo $LANG['item_menu_del_elem']; ?>",
buttons: {
"<?php echo $LANG['del_button']; ?>": function() {
$.post(
"sources/kb.queries.php",
{
type : "delete_kb",
id : $("#kb_id").val(),
key : "<?php echo $_SESSION['key']; ?>"
},
function(data) {
$("#div_kb_delete").dialog("close");
oTable = $("#t_kb").dataTable();
oTable.fnDraw();
}
)
},
"<?php echo $LANG['cancel_button']; ?>": function() {
$(this).dialog("close");
}
}
});
//Dialogbox for new KB
$("#kb_form").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 900,
height: 600,
title: "<?php echo $LANG['manage_entries_in_kb']; ?>",
buttons: {
"<?php echo $LANG['save_button']; ?>": function() {
if ($("#kb_label").val() == "") {
$("#kb_label").addClass("ui-state-error");
} else if ($("#kb_category").val() == "") {
$("#kb_category").addClass("ui-state-error");
} else if ($("#kb_description").val() == "") {
$("#kb_description").addClass("ui-state-error");
} else {
//selected items associated to KB
var itemsvalues = [];
$("#kb_associated_to :selected").each(function(i, selected) {
itemsvalues[i] = $(selected).val();
});
var data = '{"label":"'+sanitizeString($("#kb_label").val())+'","category":"'+sanitizeString($("#kb_category").val())+
'","anyone_can_modify":"'+$("input[name=modify_kb]:checked").val()+'","id":"'+$("#kb_id").val()+
'","kb_associated_to":"'+itemsvalues+'","description":"'+sanitizeString(CKEDITOR.instances["kb_description"].getData())+'"}';
$.post("sources/kb.queries.php",
{
type : "kb_in_db",
data : prepareExchangedData(data, "encode", "<?php echo $_SESSION['key']; ?>"),
key : "<?php echo $_SESSION['key']; ?>"
},
function(data) {
if (data[0].status == "done") {
oTable = $("#t_kb").dataTable();
oTable.fnDraw();
}
$("#kb_form").dialog("close");
},
"json"
);
}
},
"<?php echo $LANG['cancel_button']; ?>": function() {
$(this).dialog("close");
}
},
open:function(event, ui) {
$("#kb_label, #kb_description, #kb_category").removeClass("ui-state-error");
$("#kb_associated_to").multiselect();
var instance = CKEDITOR.instances["kb_description"];
if (instance) {
CKEDITOR.replace("kb_description",{toolbar:"Full", height: 250,language: "<?php echo $_SESSION['user_language_code']; ?>"});
} else {
$("#kb_description").ckeditor({toolbar:"Full", height: 250,language: "<?php echo $_SESSION['user_language_code']; ?>"});
}
},
close: function(event,ui) {
if (CKEDITOR.instances["kb_description"]) {
CKEDITOR.instances["kb_description"].destroy();
}
$("#kb_id,#kb_label, #kb_description, #kb_category, #full_list_items_associated").val("");
}
});
//category listing
$("#kb_category").autocomplete({
source: "sources/kb.queries.categories.php",
minLength: 1
}).focus(function() {
if (this.value == "")
$(this).trigger("keydown.autocomplete");
});
});
//]]>
</script>