-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
executable file
·218 lines (209 loc) · 8.66 KB
/
view.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
<?php
// Define secure access constant
define('SECURE_ACCESS', true);
session_start();
require_once 'lang.php';
require_once 'env.inc.php';
require_once 'header_warning.php';
require_once 'checkenv.inc.php';
require_once 'db.inc.php';
if (!isset($_GET['id'])) {
header('Location: index.php');
exit();
}
$id = $_GET['id'];
$current_time = time();
$table = DBTABLE_PREFIX . DBTABLE_NAME;
$stmt = $pdo->prepare("SELECT * FROM {$table} WHERE id = ? AND (expires_at > ? OR expires_at = 9223372036854775807)");
$stmt->execute([$id, $current_time]);
$row = $stmt->fetch();
if (!$row) {
$error = __('link_expired');
} elseif ($row['view_limit'] > 0 && $row['view_count'] >= $row['view_limit']) {
$error = __('max_views_reached');
} else {
$stmt = $pdo->prepare("UPDATE {$table} SET view_count = view_count + 1 WHERE id = ?");
$stmt->execute([$id]);
$row['view_count']++;
}
?>
<!DOCTYPE html>
<html lang="<?= $_SESSION['lang']; ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= __('shared_password'); ?></title>
<link rel="stylesheet" href="chota.min.css">
<style>
body {
padding: 1rem;
background: var(--bg-secondary);
}
.container {
margin: 0 auto;
}
.card {
background: white;
padding: 2rem;
border-radius: 4px;
}
.text-right {
text-align: right;
}
.password-display {
background: var(--bg-secondary);
padding: 1rem;
border-radius: 4px;
border: 1px solid var(--color-primary);
font-family: monospace;
position: relative;
}
.blur {
filter: blur(5px);
transition: filter 0.3s ease;
}
.error {
color: var(--color-error);
}
.button-group {
display: flex;
gap: 1rem;
margin-top: 1rem;
}
.button.error {
background: var(--color-error);
border-color: var(--color-error);
}
.button.error:hover {
background: var(--color-error);
filter: brightness(90%);
}
.visibility-toggle {
position: absolute;
right: 1rem;
top: 50%;
transform: translateY(-50%);
background: var(--color-primary);
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
z-index: 1;
}
.visibility-toggle:hover {
opacity: 0.9;
}
</style>
<script>
function copyToClipboard() {
const passwordText = document.getElementById('password-text').textContent;
navigator.clipboard.writeText(passwordText).then(() => {
const copyBtn = document.getElementById('copy-btn');
copyBtn.textContent = '<?= __('copied'); ?>';
setTimeout(() => {
copyBtn.textContent = '<?= __('copy_clipboard'); ?>';
}, 2000);
});
}
function destroyPassword() {
if (confirm('<?= __('confirm_destroy'); ?>')) {
fetch('destroy.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'id=<?= urlencode($id); ?>'
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('<?= __('password_destroyed'); ?>');
window.location.href = 'index.php';
} else {
alert('<?= __('destroy_error'); ?>');
}
})
.catch(() => alert('<?= __('destroy_error'); ?>'));
}
}
function toggleVisibility() {
const passwordText = document.getElementById('password-text');
const toggleBtn = document.getElementById('visibility-toggle');
if (passwordText.classList.contains('blur')) {
passwordText.classList.remove('blur');
toggleBtn.textContent = '<?= __('hide_text'); ?>';
} else {
passwordText.classList.add('blur');
toggleBtn.textContent = '<?= __('show_text'); ?>';
}
}
</script>
</head>
<body>
<?php showHeader(); ?>
<div class="container">
<?php showInstallWarning(); ?>
<?php if (isset($_SESSION['success_message'])): ?>
<div class="success-message" style="background: #d4edda; border: 1px solid #c3e6cb; color: #155724; padding: 1rem; margin-bottom: 2rem; border-radius: 4px;">
<?php
echo htmlspecialchars($_SESSION['success_message']);
unset($_SESSION['success_message']);
?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['error_message'])): ?>
<div class="error-message" style="background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; padding: 1rem; margin-bottom: 2rem; border-radius: 4px;">
<?php
echo htmlspecialchars($_SESSION['error_message']);
unset($_SESSION['error_message']);
?>
</div>
<?php endif; ?>
<div class="card">
<?php if (isset($error)): ?>
<p class="error text-center"><?= htmlspecialchars($error); ?></p>
<?php else: ?>
<h3 class="text-center"><?= __('shared_password'); ?></h3>
<div class="row">
<div class="col">
<label><?= __('password'); ?></label>
<div class="password-display">
<?php require_once 'crypt.inc.php';
$enc = new Encryption();
?>
<span id="password-text" class="blur" onclick="this.classList.remove('blur');"><?= nl2br(htmlspecialchars($enc->decrypt($row['data']))); ?></span>
<button id="visibility-toggle" class="visibility-toggle" onclick="toggleVisibility();"><?= __('show_text'); ?></button>
</div><br />
<button id="copy-btn" onclick="copyToClipboard()" class="button primary"><?= __('copy_clipboard'); ?></button>
</div>
</div>
<div class="row">
<div class="col">
<small>
<?php if ($row['expires_at'] !== 9223372036854775807): ?>
<p><?= __('expires'); ?> <?= date(__('date_format'), $row['expires_at']); ?></p>
<?php else: ?>
<p><?= __('no_expiration'); ?></p>
<?php endif; ?>
<?php if ($row['view_limit'] > 0): ?>
<p><?= __('views_remaining'); ?> <?= $row['view_limit'] - $row['view_count']; ?> <?= __('of'); ?> <?= $row['view_limit']; ?></p>
<?php endif; ?>
</small>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col">
<div class="button-group">
<a href="index.php" class="button primary"><?= __('share_another'); ?></a>
<?php if (!isset($error)): ?>
<button onclick="destroyPassword()" class="button error"><?= __('destroy_password'); ?></button>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>