fix: better fix for encryption issue

This commit is contained in:
Floorb 2023-06-14 03:00:04 -04:00
parent ca28f037f7
commit 8969eb4071

View file

@ -126,17 +126,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$paste_password = password_hash($paste_password, PASSWORD_DEFAULT);
}
// If it's a new paste or the existing paste is encrypted, encrypt the paste
// This is to prevent legacy pastes from getting weird
if ($editing && !$paste->encrypt) {
$paste_content = $_POST['paste_data'];
} else {
$paste_content = openssl_encrypt(
$_POST['paste_data'],
PP_ENCRYPTION_ALGO,
PP_ENCRYPTION_KEY
);
}
$paste_content = openssl_encrypt(
$_POST['paste_data'],
PP_ENCRYPTION_ALGO,
PP_ENCRYPTION_KEY
);
// Set expiry time
$expires = calculatePasteExpiry($p_expiry);
@ -145,6 +139,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($editing) {
$paste = Paste::find($_POST['paste_id']);
if (can('edit', $paste)) {
$paste_content = $paste->encrypt ? $paste_content : $_POST['paste_data'];
$paste->update([
'title' => $paste_title,
'content' => $paste_content,
@ -153,7 +148,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'expiry' => $expires,
'password' => $paste_password,
'updated_at' => date_create(),
'ip' => $ip
'ip' => $ip,
'encrypt' => true
]);
$paste->replaceTags($tags);