31 lines
924 B
PHP
31 lines
924 B
PHP
<?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; |