57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../core/security.php';
|
|
$pdo = require __DIR__ . '/../core/db.php';
|
|
require_once __DIR__ . '/../models/Paste.php';
|
|
$config = require __DIR__ . '/../config/config.php';
|
|
|
|
$id = preg_replace('/[^a-f0-9]/i', '', $_GET['id'] ?? '');
|
|
|
|
if ($id === '') {
|
|
$errorCode = 404;
|
|
$errorMessage = 'Invalid paste ID.';
|
|
require __DIR__ . '/../../public/error.php';
|
|
exit;
|
|
}
|
|
|
|
$paste = new Paste($pdo);
|
|
$data = $paste->get($id);
|
|
|
|
if (!$data) {
|
|
$errorCode = 404;
|
|
$errorMessage = 'Paste not found.';
|
|
require __DIR__ . '/../../public/error.php';
|
|
exit;
|
|
}
|
|
|
|
if ($data['expire_time'] !== null && time() > (int)$data['expire_time']) {
|
|
$errorCode = 410;
|
|
$errorMessage = 'This paste has expired.';
|
|
require __DIR__ . '/../../public/error.php';
|
|
exit;
|
|
}
|
|
|
|
$needsPassword = (bool)$data['password_hash'];
|
|
$wrongPassword = false;
|
|
$decrypted = null;
|
|
|
|
if ($needsPassword) {
|
|
$submitted = $_POST['password'] ?? null;
|
|
if ($submitted !== null) {
|
|
if (password_verify($submitted, $data['password_hash'])) {
|
|
$needsPassword = false;
|
|
} else {
|
|
$wrongPassword = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$needsPassword) {
|
|
$decrypted = decryptText($data['encrypted_text'], $data['iv'], $config['app']['master_key']);
|
|
if ($decrypted === false) {
|
|
$errorCode = 500;
|
|
$errorMessage = 'Decryption failed. The paste may be corrupted.';
|
|
require __DIR__ . '/../../public/error.php';
|
|
exit;
|
|
}
|
|
}
|