forked from nilsteampassnet/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotv.php
114 lines (102 loc) · 4.11 KB
/
otv.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
<?php
/**
* @file otv.php
* @author Nils Laumaillé
* @version 2.1.22
* @copyright (c) 2009-2014 Nils Laumaillé
* @licensing GNU AFFERO GPL 3.0
* @link http://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/sessions.php');
@session_start();
if (!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1) {
die('Hacking attempt...');
}
$html = "";
if (
filter_var($_GET['code'], FILTER_SANITIZE_STRING) != ""
&& filter_var($_GET['item_id'], FILTER_SANITIZE_STRING) >= 0
&& filter_var($_GET['stamp'], FILTER_SANITIZE_STRING) >= 0
&& filter_var($_GET['otv_id'], FILTER_SANITIZE_STRING) >= 0
) {
//Include files
require_once $_SESSION['settings']['cpassman_dir'].'/includes/settings.php';
require_once $_SESSION['settings']['cpassman_dir'].'/includes/include.php';
require_once $_SESSION['settings']['cpassman_dir'].'/sources/SplClassLoader.php';
// connect to DB
require_once $_SESSION['settings']['cpassman_dir'].'/includes/libraries/Database/Meekrodb/db.class.php';
DB::$host = $server;
DB::$user = $user;
DB::$password = $pass;
DB::$dbName = $database;
DB::$port = $port;
DB::$error_handler = 'db_error_handler';
$link = mysqli_connect($server, $user, $pass, $database, $port);
// Include main functions used by TeamPass
require_once 'sources/main.functions.php';
// check session validity
$data = DB::queryfirstrow(
"SELECT timestamp, code, item_id FROM ".$pre."otv
WHERE id = %i",
intval($_GET['otv_id'])
);
if (
$data['timestamp'] == $_GET['stamp']
&& $data['code'] == $_GET['code']
&& $data['item_id'] == $_GET['item_id']
) {
// otv is too old
if ($data['timestamp'] < (time() - $_SESSION['settings']['otv_expiration_period'] * 86400) ) {
$html = "Link is too old!";
} else {
$dataItem = DB::queryfirstrow(
"SELECT *
FROM ".$pre."items as i
INNER JOIN ".$pre."log_items as l ON (l.id_item = i.id)
WHERE i.id = %i AND l.action = %s",
intval($_GET['item_id']),
'at_creation'
);
// get data
$pw = decrypt($dataItem['pw']);
// get key for original pw
$originalKey = DB::queryfirstrow(
"SELECT rand_key FROM `".$pre."keys`
WHERE `table` = %s AND `id` = %i",
'items',
intval($_GET['item_id'])
);
// unsalt previous pw
$pw = substr($pw, strlen($originalKey['rand_key']));
$label = $dataItem['label'];
$email = $dataItem['email'];
$url = $dataItem['url'];
$description = preg_replace('/(?<!\\r)\\n+(?!\\r)/', '', strip_tags($dataItem['description'], $k['allowedTags']));
$login = str_replace('"', '"', $dataItem['login']);
// display data
$html = "<div style='margin:30px;'>".
"<div style='font-size:20px;font-weight:bold;'>Welcome to One-Time item view page.</div>".
"<div style='font-style:italic;'>Here are the details of the Item that has been shared to you</div>".
"<div style='margin-top:10px;'><table>".
"<tr><td>Label:</td><td>" . $label . "</td</tr>".
"<tr><td>Password:</td><td>" . $pw . "</td</tr>".
"<tr><td>Description:</td><td>" . $description . "</td</tr>".
"<tr><td>login:</td><td>" . $login . "</td</tr>".
"<tr><td>URL:</td><td>" . $url ."</td</tr>".
"</table></div>".
"<div style='margin-top:30px;'>Copy carefully the data you need. This page is only visible once.</div>".
"</div>";
// delete entry
DB::delete($pre."otv", "id = %i", intval($_GET['otv_id']));
}
} else {
$html = "Not a valid page!";
}
} else {
$html = "Not a valid page!";
}
echo $html;