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
/
items.export.php
245 lines (219 loc) · 9.43 KB
/
items.export.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
<?php
/**
*
* @package items.export.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.
*/
require_once './sources/SecureHandler.php';
session_start();
if ((!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1 ||
!isset($_SESSION['user_id']) || empty($_SESSION['user_id']) ||
!isset($_SESSION['key']) || empty($_SESSION['key'])) &&
$_GET['key'] != $_SESSION['key']
) {
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);
}
/* do checks */
require_once $SETTINGS['cpassman_dir'].'/includes/config/include.php';
require_once $SETTINGS['cpassman_dir'].'/sources/checks.php';
if (!checkUser($_SESSION['user_id'], $_SESSION['key'], "home")) {
$_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
include $SETTINGS['cpassman_dir'].'/error.php';
exit();
}
require $SETTINGS['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'.php';
require $SETTINGS['cpassman_dir'].'/includes/config/settings.php';
header("Content-type: text/html; charset=utf-8");
header("Cache-Control: no-cache, no-store, must-revalidate");
// connect to the server
require_once $SETTINGS['cpassman_dir'].'/includes/libraries/Database/Meekrodb/db.class.php';
$pass = defuse_return_decrypted($pass);
DB::$host = $server;
DB::$user = $user;
DB::$password = $pass;
DB::$dbName = $database;
DB::$port = $port;
DB::$encoding = $encoding;
DB::$error_handler = true;
$link = mysqli_connect($server, $user, $pass, $database, $port);
$link->set_charset($encoding);
echo '
<div class="ui-state-highlight ui-corner-all" style="margin:10px;padding:10px;">
<i class="fa fa-bullhorn"></i> '.$LANG['print_out_warning'].'
</div>
<div>
<label for="export_selected_folders" class="form_label">'.$LANG['select_folders'].' :</label>
<select id="export_selected_folders" multiple class="text ui-widget-content ui-corner-all" style="padding:10px;">
';
//Load Tree
$tree = new SplClassLoader('Tree\NestedTree', './includes/libraries');
$tree->register();
$tree = new Tree\NestedTree\NestedTree($pre.'nested_tree', 'id', 'parent_id', 'title');
$folders = $tree->getDescendants();
// show list of all folders
foreach ($folders as $f) {
// Be sure that user can only see folders he/she is allowed to
if (!in_array($f->id, $_SESSION['forbiden_pfs'])) {
$displayThisNode = false;
// Check if any allowed folder is part of the descendants of this node
$nodeDescendants = $tree->getDescendants($f->id, true, false, true);
foreach ($nodeDescendants as $node) {
if (in_array($node, $_SESSION['groupes_visibles'])) {
$displayThisNode = true;
break;
}
}
if ($displayThisNode === true) {
if ($f->title == $_SESSION['user_id'] && $f->nlevel == 1) {
$f->title = $_SESSION['login'];
}
echo "<option value='".$f->id."'>".$f->title."</option>";
}
}
}
echo '
</select>
</div>
<div style="margin-top:5px;">
<label class="form_label">'.$LANG['select_file_format'].':</label>
<div class="export_radio_buttonset">
<input type="radio" id="export_format_pdf" name="export_format" value="pdf" /><label for="export_format_pdf">'.$LANG['pdf'].'</label>
<input type="radio" id="export_format_csv" name="export_format" value="csv" /><label for="export_format_csv">'.$LANG['csv'].'</label>
</div>
</div>
<div style="margin-top:5px; display:none;" id="div_export_pdf_password">
<label for="export_pdf_password" class="form_label">'.$LANG['file_protection_password'].':</label>
<input type="password" id="export_pdf_password" />
</div>
<div style="text-align:center;margin-top:10px; display:none;" id="export_information"></div>';
?>
<script type="text/javascript">
$(function() {
$("select").multiselect();
//$(".radio_buttonset").buttonset();
$(".export_radio_buttonset").click(function(){
$("#export_information").html('');
if ($("input[name='export_format']:checked").val() == "pdf"){
$("#div_export_pdf_password").show();
} else {
$("#export_pdf_password").val("");
$("#div_export_pdf_password").hide();
}
})
});
function pollExport(export_format, remainingIds, currentID, nb)
{
$.ajax({
url: "sources/export.queries.php",
type : 'POST',
dataType : "json",
data : {
type : export_format,
id : currentID,
ids : remainingIds
},
complete : function(data, statut){
var aIds = remainingIds.split(",");
var currentID = aIds[0];
aIds.shift();
var nb2 = aIds.length;
aIds = aIds.toString();
$("#export_progress").html(Math.floor(((nb-nb2) / nb) * 100)+"%");
//console.log(remainingIds+" ; "+currentID+" ; "+aIds+" ; "+nb+" ; "+nb2);
if (currentID != "") {
pollExport(export_format, aIds, currentID, nb);
} else {
//Send query
$.post(
"sources/export.queries.php",
{
type : "finalize_export_pdf",
pdf_password : $("#export_pdf_password").val()
},
function(data) {
$("#export_information").html("<span class='fa fa-file-code-o'></span> <a href='"+data[0].href+"'><?php echo $LANG['pdf_download']; ?></a>").show();
},
"json"
);
}
}
})
};
function exportItemsToFile()
{
$("#export_information").html('<i class="fa fa-cog fa-spin"></i> <?php echo $LANG['please_wait']; ?> ... <span id="export_progress">0%</span>').attr("class","").show();
//Get list of selected folders
var ids = "";
$("#export_selected_folders :selected").each(function(i, selected) {
if (ids == "") ids = $(selected).val();
else ids = ids + ";" + $(selected).val();
});
if (ids == "") {
$("#export_information").show().html("<i class='fa fa-exclamation-circle'></i> <?php echo $LANG['error_no_selected_folder']; ?>").attr("class","ui-state-error");
setTimeout(function(){$("#export_information").effect( "fade", "slow" );}, 1000);
return;
}
if ($("input[name='export_format']:checked").length == 0) {
$("#export_information").show().html("<i class='fa fa-exclamation-circle'></i> <?php echo $LANG['error_export_format_not_selected']; ?>").attr("class","ui-state-error");
setTimeout(function(){$("#export_information").effect( "fade", "slow" );}, 1000);
return;
}
// Get PDF encryption password and make sure it is set
if (($("#export_pdf_password").val() == "") && ($("input[name='export_format']:checked").val() == "pdf")) {
$("#export_information").show().html("<i class='fa fa-exclamation-circle'></i> <?php echo $LANG['pdf_password_warning']; ?>").attr("class","ui-state-error");
setTimeout(function(){$("#export_information").effect( "fade", "slow" );}, 1000);
return;
}
// export format?
var export_format = "";
if ($("input[name='export_format']:checked").val() == "pdf") export_format = "export_to_pdf_format";
else if ($("input[name='export_format']:checked").val() == "csv") export_format = "export_to_csv_format";
if (export_format == "export_to_pdf_format") {
$.post(
"sources/export.queries.php",
{
type : "initialize_export_table"
},
function(data) {
// launch export by building content of export table
var aIds = ids.split(";");
var currentID = aIds[0];
aIds.shift();
var nb = aIds.length+1;
aIds = aIds.toString();
pollExport(export_format, aIds, currentID, nb);
}
);
} else {
//Send query
$.post(
"sources/export.queries.php",
{
type : export_format,
ids : ids,
pdf_password : $("#pdf_password").val()
},
function(data) {
$("#export_information").html("<span class='fa fa-file-code-o'></span> <a href='"+data[0].href+"'><?php echo $LANG['pdf_download']; ?></a>").show();
},
"json"
);
}
}
</script>