Add -> add project
This commit is contained in:
31
app/controllers/SaveController.php
Normal file
31
app/controllers/SaveController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require __DIR__ . '/../core/security.php';
|
||||
$pdo = require __DIR__ . '/../core/db.php';
|
||||
require __DIR__ . '/../models/Paste.php';
|
||||
$config = require __DIR__ . '/../config/config.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: /index.php');
|
||||
exit;
|
||||
}
|
||||
$text = $_POST['text'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
$expire = isset($_POST['expire']) ? intval($_POST['expire']) : 0;
|
||||
if (trim($text) === '') {
|
||||
die('Text is required');
|
||||
}
|
||||
$id = generateId();
|
||||
$enc = encryptText($text, $config['master_key']);
|
||||
$password_hash = $password !== '' ? password_hash($password, PASSWORD_DEFAULT) : null;
|
||||
$expire_time = $expire > 0 ? time() + $expire : null;
|
||||
$paste = new Paste($pdo);
|
||||
|
||||
$paste->save($id, $enc['cipher'], $enc['iv'], $expire_time,$password_hash);
|
||||
|
||||
|
||||
$url = "http://" . $_SERVER['HTTP_HOST'] . "/view.php?id=" . $id;
|
||||
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"url" => $url
|
||||
]);
|
||||
exit;
|
||||
59
app/controllers/ViewController.php
Normal file
59
app/controllers/ViewController.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
require __DIR__ . '/../core/security.php';
|
||||
$pdo = require __DIR__ . '/../core/db.php';
|
||||
require __DIR__ . '/../models/Paste.php';
|
||||
$config = require __DIR__ . '/../config/config.php';
|
||||
|
||||
$id = $_GET['id'] ?? '';
|
||||
|
||||
$paste = new Paste($pdo);
|
||||
$data = $paste->get($id);
|
||||
|
||||
if (!$data) {
|
||||
die('Paste not found.');
|
||||
}
|
||||
|
||||
if ($data['expire_time'] !== null && time() > (int)$data['expire_time']) {
|
||||
die('Paste has expired.');
|
||||
}
|
||||
|
||||
if ($data['password_hash']) {
|
||||
if (!isset($_POST['password'])) {
|
||||
echo "<link rel='stylesheet' href='/assets/css/style.css'>";
|
||||
echo "<form method='post'>";
|
||||
echo "<input type='password' class='usepassword' name='password' placeholder='Password'>";
|
||||
echo "<button type='submit'>View</button>";
|
||||
echo "</form>";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!password_verify($_POST['password'], $data['password_hash'])) {
|
||||
die('Wrong password.');
|
||||
}
|
||||
}
|
||||
|
||||
$decrypted = decryptText($data['encrypted_text'], $data['iv'], $config['master_key']);
|
||||
|
||||
if ($decrypted === false) {
|
||||
die('Decryption failed.');
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>View Paste</title>
|
||||
<link rel="stylesheet" href="/assets/css/style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Your Paste</h1>
|
||||
<div class="paste-box">
|
||||
<button id="copyBtn">Copy</button>
|
||||
<pre id="pasteContent"><?= htmlspecialchars($decrypted) ?></pre>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user