diff --git a/public/index.php b/public/index.php index 38ae4ae..a5a36a2 100644 --- a/public/index.php +++ b/public/index.php @@ -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);