forked from 418sec/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.offline.php
276 lines (248 loc) · 10.1 KB
/
items.offline.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
<?php
/**
*
* @package index.php
* @author Nils Laumaillé <nils@teampass.net>
* @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();
}
include $SETTINGS['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'.php';
include $SETTINGS['cpassman_dir'].'/includes/config/settings.php';
header("Content-type: text/html; charset=utf-8");
header("Cache-Control: no-cache, no-store, must-revalidate");
require_once $SETTINGS['cpassman_dir'].'/sources/main.functions.php';
require_once $SETTINGS['cpassman_dir'].'/sources/SplClassLoader.php';
// 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="padding:10px;">
<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"> d</span>'.$LANG['offline_mode_warning'].'
</div>
<div style="margin:10px 0 10px 0;">
<label for="offline_mode_selected_folders" class="form_label">'.$LANG['select_folders'].' :</label>
<select id="offline_mode_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:10px 0 10px 0;">
<label for="pdf_password" class="">'.$LANG['admin_action_db_restore_key'].' :</label>
<input type="password" id="offline_password" name="offline_password" />
<div id="offline_pw_strength" style="margin:10px 0 0 130px;"></div>
<input type="hidden" id="offline_pw_strength_value" />
<input type="hidden" id="min_offline_pw_strength_value" value="'.$SETTINGS['offline_key_level'].'" />
</div>
<div style="text-align:center;margin-top:8px; display:none;" id="offline_information"></div>
<input type="hidden" id="offmode_number" />
<input type="hidden" id="offmode_list" />';
?>
<script type="text/javascript">
$(function() {
$("select").multiselect();
$("#offline_password").simplePassMeter({
"requirements": {},
"container": "#offline_pw_strength",
"defaultText" : "<?php echo $LANG['index_pw_level_txt']; ?>",
"ratings": [
{"minScore": 0,
"className": "meterFail",
"text": "<?php echo $LANG['complex_level0']; ?>"
},
{"minScore": 25,
"className": "meterWarn",
"text": "<?php echo $LANG['complex_level1']; ?>"
},
{"minScore": 50,
"className": "meterWarn",
"text": "<?php echo $LANG['complex_level2']; ?>"
},
{"minScore": 60,
"className": "meterGood",
"text": "<?php echo $LANG['complex_level3']; ?>"
},
{"minScore": 70,
"className": "meterGood",
"text": "<?php echo $LANG['complex_level4']; ?>"
},
{"minScore": 80,
"className": "meterExcel",
"text": "<?php echo $LANG['complex_level5']; ?>"
},
{"minScore": 90,
"className": "meterExcel",
"text": "<?php echo $LANG['complex_level6']; ?>"
}
]
});
$("#offline_password").bind({
"score.simplePassMeter" : function(jQEvent, score) {
$("#offline_pw_strength_value").val(score);
}
});
});
/*
* Export to Offline mode file - step 1
*/
function generateOfflineFile()
{
$("#offline_information").html('<i class="fa fa-cog fa-spin"></i> <?php echo $LANG['please_wait']; ?>').attr("class","").show();
//Get list of selected folders
var ids = "";
$("#offline_mode_selected_folders :selected").each(function(i, selected) {
if (ids == "") ids = $(selected).val();
else ids = ids + ";" + $(selected).val();
});
if (ids == "") {
$("#offline_information").show().html("<?php echo $LANG['error_no_selected_folder']; ?>").attr("class","ui-state-error");
setTimeout(function(){$("#offline_information").effect( "fade", "slow" );}, 1000);
return;
}
if ($("#offline_password").val() == "") {
$("#offline_information").show().html("<?php echo $LANG['pdf_password_warning']; ?>").attr("class","ui-state-error");
setTimeout(function(){$("#offline_information").effect( "fade", "slow" );}, 1000);
return;
}
if (parseInt($("#offline_pw_strength_value").val()) < parseInt($("#min_offline_pw_strength_value").val())) {
$("#offline_information").addClass("ui-state-error ui-corner-all").show().html("<?php echo $LANG['error_complex_not_enought']; ?>");
setTimeout(function(){$("#offline_information").effect( "fade", "slow" );}, 1000);
return;
}
pdf_password = sanitizeString($("#offline_password").val());
//Send query
$.post(
"sources/export.queries.php",
{
type : "export_to_html_format",
ids : ids,
pdf_password : sanitizeString($("#offline_password").val())
},
function(data) {
if (data[0].loop != null && data[0].loop == "true") {
exportHTMLLoop(ids, data[0].file, ids.split(';').length, 1, pdf_password, data[0].file_link);
}
$("#offline_information").html(data[0].text);
},
"json"
);
}
/*
* Loading Item details step 2
*/
function exportHTMLLoop(idsList, file, number, cpt, pdf_password, file_link)
{
// prpare list of ids to treat during this run
if (idsList != "") {
$("#offline_information").html('<i class="fa fa-cog fa-spin"></i> <?php echo $LANG['please_wait']; ?> - ' + Math.round((parseInt(cpt)*100)/parseInt(number)) + "%");
tab = idsList.split(';');
idTree = tab[0];
tab = tab.slice(1, tab.length);
idsList = tab.join(';');
cpt = parseInt(cpt) + 1;
$.post(
"sources/export.queries.php",
{
type : "export_to_html_format_loop",
idsList : idsList,
idTree : idTree,
file : file,
cpt : cpt,
number : number,
pdf_password : pdf_password,
file_link : file_link
},
function(data) {
// relaunch for next run
exportHTMLLoop (
data[0].idsList,
data[0].file,
number,
cpt,
pdf_password,
data[0].file_link
);
},
"json"
);
} else {
$.post(
"sources/export.queries.php",
{
type : "export_to_html_format_finalize",
file : file,
file_link : file_link,
pdf_password : pdf_password,
},
function(data) {
$("#offline_information").html('<i class="fa fa-download"></i> '+data[0].text);
},
"json"
);
}
};
</script>