2021-07-10 19:18:17 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Paste <https://github.com/jordansamuel/PASTE>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
2021-07-12 08:23:14 -04:00
|
|
|
*
|
2021-07-10 19:18:17 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License in GPL.txt for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$directory = 'install';
|
|
|
|
|
|
|
|
if (file_exists($directory)) {
|
|
|
|
header("Location: install");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Required functions
|
2021-07-10 17:54:43 -04:00
|
|
|
define('IN_PONEPASTE', 1);
|
|
|
|
require_once('includes/common.php');
|
2021-07-11 12:18:57 -04:00
|
|
|
require_once('includes/captcha.php');
|
|
|
|
require_once('includes/functions.php');
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-07-12 09:03:02 -04:00
|
|
|
function verifyCaptcha() : string|bool {
|
2021-07-12 08:23:14 -04:00
|
|
|
global $cap_e;
|
|
|
|
global $mode;
|
|
|
|
global $recaptcha_secretkey;
|
|
|
|
global $lang;
|
2021-07-17 18:17:29 -04:00
|
|
|
global $current_user;
|
2021-07-12 08:23:14 -04:00
|
|
|
|
2021-07-17 18:17:29 -04:00
|
|
|
if ($cap_e == "on" && !$current_user) {
|
2021-07-12 08:23:14 -04:00
|
|
|
if ($mode == "reCAPTCHA") {
|
2021-07-12 09:03:02 -04:00
|
|
|
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secretkey . "&response=" . $_POST['g-recaptcha-response']);
|
2021-07-12 08:23:14 -04:00
|
|
|
$response = json_decode($response, true);
|
|
|
|
if ($response["success"] == false) {
|
|
|
|
// reCAPTCHA Errors
|
|
|
|
return match ($response["error-codes"][0]) {
|
|
|
|
"missing-input-response" => $lang['missing-input-response'],
|
|
|
|
"missing-input-secret" => $lang['missing-input-secret'],
|
|
|
|
"invalid-input-secret" => $lang['invalid-input-secret'],
|
|
|
|
default => $lang['error']
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
2021-07-12 09:03:02 -04:00
|
|
|
$scode = strtolower(htmlentities(Trim($_POST['scode'])));
|
2021-07-12 08:23:14 -04:00
|
|
|
$cap_code = strtolower($_SESSION['captcha']['code']);
|
|
|
|
if ($cap_code !== $scode) {
|
|
|
|
return $lang['image_wrong']; // Wrong captcha.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the expiry of a paste based on user input.
|
|
|
|
*
|
|
|
|
* @param string $expiry Expiry time.
|
|
|
|
* SELF means to expire upon one view. +10M, +1H, +1D, +1W, +2W, +1M all do the obvious.
|
|
|
|
* Anything unhandled means to expire never.
|
|
|
|
* @return string|null Expiry time, or NULL if expires never.
|
|
|
|
*/
|
|
|
|
function calculatePasteExpiry(string $expiry) {
|
|
|
|
// used to use mktime
|
|
|
|
if ($expiry === 'self') {
|
|
|
|
return 'SELF'; // What does this do?
|
|
|
|
}
|
|
|
|
|
|
|
|
$valid_expiries = ['10M', '1H', '1D', '1W', '2W', '1M'];
|
|
|
|
|
|
|
|
return in_array($expiry, $valid_expiries)
|
|
|
|
? (new DateTime())->add(new DateInterval("P{$expiry}"))->format('U')
|
|
|
|
: null;
|
|
|
|
}
|
|
|
|
|
2021-07-12 09:03:02 -04:00
|
|
|
function validatePasteFields() : string|null {
|
2021-07-12 08:23:14 -04:00
|
|
|
global $lang;
|
|
|
|
global $pastelimit;
|
|
|
|
|
|
|
|
if (empty($_POST["paste_data"]) || trim($_POST['paste_data'] === '')) { /* Empty paste input */
|
|
|
|
return $lang['empty_paste'];
|
2021-07-12 09:03:02 -04:00
|
|
|
} elseif (!isset($_POST['title'])) { /* No paste title POSTed */
|
2021-07-12 08:23:14 -04:00
|
|
|
return $lang['error'];
|
|
|
|
} elseif (empty($_POST["tags"])) { /* No tags provided */
|
|
|
|
return $lang['notags'];
|
|
|
|
} elseif (strlen($_POST["title"]) > 70) { /* Paste title too long */
|
|
|
|
return $lang['titlelen'];
|
2021-07-26 17:41:54 -04:00
|
|
|
} elseif (mb_strlen($_POST["paste_data"], '8bit') > PP_PASTE_LIMIT_BYTES) { /* Paste size too big */
|
2021-07-12 08:23:14 -04:00
|
|
|
return $lang['large_paste'];
|
2021-07-10 17:54:43 -04:00
|
|
|
}
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-07-12 08:23:14 -04:00
|
|
|
return null;
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
|
|
|
|
2021-07-10 17:54:43 -04:00
|
|
|
// UTF-8
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
2021-07-10 19:18:17 +01:00
|
|
|
|
|
|
|
// Current date & user IP
|
2021-07-12 09:03:02 -04:00
|
|
|
$date = date('jS F Y');
|
|
|
|
$ip = $_SERVER['REMOTE_ADDR'];
|
2021-07-10 19:18:17 +01:00
|
|
|
|
|
|
|
// Sitemap
|
2021-07-12 08:23:14 -04:00
|
|
|
$site_sitemap_rows = $conn->query('SELECT * FROM sitemap_options LIMIT 1');
|
|
|
|
if ($row = $site_sitemap_rows->fetch()) {
|
2021-07-12 09:03:02 -04:00
|
|
|
$priority = $row['priority'];
|
2021-07-10 19:18:17 +01:00
|
|
|
$changefreq = $row['changefreq'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Captcha
|
2021-07-12 08:23:14 -04:00
|
|
|
$site_captcha_rows = $conn->query("SELECT * FROM captcha LIMIT 1");
|
|
|
|
if ($row = $site_captcha_rows->fetch()) {
|
2021-07-12 09:03:02 -04:00
|
|
|
$color = Trim($row['color']);
|
|
|
|
$mode = Trim($row['mode']);
|
|
|
|
$mul = Trim($row['mul']);
|
2021-07-10 19:18:17 +01:00
|
|
|
$allowed = Trim($row['allowed']);
|
2021-07-12 09:03:02 -04:00
|
|
|
$cap_e = Trim($row['cap_e']);
|
|
|
|
$recaptcha_sitekey = Trim($row['recaptcha_sitekey']);
|
|
|
|
$recaptcha_secretkey = Trim($row['recaptcha_secretkey']);
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
2021-07-12 08:23:14 -04:00
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
2021-07-10 19:18:17 +01:00
|
|
|
if ($cap_e == "on") {
|
|
|
|
if ($mode == "reCAPTCHA") {
|
|
|
|
$_SESSION['captcha_mode'] = "recaptcha";
|
|
|
|
$_SESSION['captcha'] = $recaptcha_sitekey;
|
|
|
|
} else {
|
|
|
|
$_SESSION['captcha_mode'] = "internal";
|
|
|
|
$_SESSION['captcha'] = captcha($color, $mode, $mul, $allowed);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$_SESSION['captcha_mode'] = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-10 17:54:43 -04:00
|
|
|
updatePageViews($conn);
|
2021-07-10 19:18:17 +01:00
|
|
|
|
|
|
|
// POST Handler
|
2021-07-14 18:02:39 -04:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
2021-07-12 08:23:14 -04:00
|
|
|
$error = validatePasteFields();
|
2021-07-10 19:18:17 +01:00
|
|
|
|
2021-07-12 08:23:14 -04:00
|
|
|
if ($error !== null) {
|
|
|
|
goto OutPut;
|
|
|
|
}
|
|
|
|
|
|
|
|
$captchaResponse = verifyCaptcha();
|
|
|
|
|
|
|
|
if ($captchaResponse !== true) {
|
|
|
|
$error = $captchaResponse;
|
|
|
|
goto OutPut;
|
|
|
|
}
|
|
|
|
|
|
|
|
$editing = isset($_POST['edit']);
|
|
|
|
|
2021-07-12 09:03:02 -04:00
|
|
|
$p_title = Trim(htmlspecialchars($_POST['title']));
|
2021-07-12 08:23:14 -04:00
|
|
|
|
|
|
|
if (empty($p_title)) {
|
|
|
|
$p_title = 'Untitled';
|
|
|
|
}
|
|
|
|
|
2021-07-12 09:03:02 -04:00
|
|
|
$p_content = htmlspecialchars($_POST['paste_data']);
|
|
|
|
$p_visible = Trim(htmlspecialchars($_POST['visibility']));
|
|
|
|
$p_code = Trim(htmlspecialchars($_POST['format']));
|
|
|
|
$p_expiry = Trim(htmlspecialchars($_POST['paste_expire_date']));
|
|
|
|
$p_tagsys = Trim(htmlspecialchars($_POST['tags']));
|
|
|
|
$p_tagsys = rtrim($p_tagsys, ',');
|
2021-07-12 08:23:14 -04:00
|
|
|
$p_password = $_POST['pass'];
|
|
|
|
if ($p_password == "" || $p_password == null) {
|
|
|
|
$p_password = "NONE";
|
|
|
|
} else {
|
|
|
|
$p_password = password_hash($p_password, PASSWORD_DEFAULT);
|
|
|
|
}
|
2021-07-14 14:20:43 -04:00
|
|
|
$p_encrypt = trim(htmlspecialchars($_POST['encrypted']));
|
2021-07-12 08:23:14 -04:00
|
|
|
|
|
|
|
if (empty($p_encrypt)) {
|
|
|
|
$p_encrypt = "0";
|
|
|
|
} else {
|
|
|
|
// Encrypt option
|
|
|
|
$p_encrypt = "1";
|
|
|
|
$p_content = encrypt($p_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set expiry time
|
|
|
|
$expires = calculatePasteExpiry($p_expiry);
|
|
|
|
|
|
|
|
// Edit existing paste or create new?
|
|
|
|
if ($editing) {
|
2021-07-14 14:20:43 -04:00
|
|
|
if ($current_user && $current_user['id'] === $paste_id) {
|
2021-07-12 08:23:14 -04:00
|
|
|
$paste_id = intval($_POST['paste_id']);
|
2021-07-10 17:54:43 -04:00
|
|
|
$statement = $conn->prepare(
|
2021-07-14 14:20:43 -04:00
|
|
|
"UPDATE pastes SET title = ?, content = ?, visible = ?, code = ?, expiry = ?, password = ?, encrypt = ?,ip = ?, tagsys = ?, updated_at = NOW()
|
2021-07-12 08:23:14 -04:00
|
|
|
WHERE id = ?"
|
2021-07-10 17:54:43 -04:00
|
|
|
);
|
|
|
|
|
2021-07-12 08:23:14 -04:00
|
|
|
$statement->execute([
|
2021-07-14 14:20:43 -04:00
|
|
|
$p_title, $p_content, $p_visible, $p_code, $expires, $p_password, $p_encrypt, $ip, $p_tagsys, $paste_id
|
2021-07-12 08:23:14 -04:00
|
|
|
]);
|
2021-07-10 19:18:17 +01:00
|
|
|
$success = $paste_id;
|
2021-07-12 08:23:14 -04:00
|
|
|
} else {
|
2021-07-12 23:33:54 +01:00
|
|
|
$error = $lang['loginwarning']; //"You must be logged in to do that."
|
2021-07-12 08:23:14 -04:00
|
|
|
}
|
2021-07-10 19:18:17 +01:00
|
|
|
} else {
|
2021-07-26 17:42:43 -04:00
|
|
|
if ($current_user['id'] == null) {
|
|
|
|
$paste_owner = "1";
|
|
|
|
} else {
|
|
|
|
$paste_owner = $current_user ? $current_user['id'] : null;
|
2021-07-17 22:31:21 +01:00
|
|
|
}
|
2021-07-12 08:23:14 -04:00
|
|
|
$statement = $conn->prepare(
|
2021-07-14 14:20:43 -04:00
|
|
|
"INSERT INTO pastes (title, content, visible, code, expiry, password, encrypt, user_id, created_at, ip, views, tagsys) VALUES
|
|
|
|
(?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, 0, ?)"
|
2021-07-12 08:23:14 -04:00
|
|
|
);
|
2021-07-14 14:20:43 -04:00
|
|
|
$statement->execute([$p_title, $p_content, $p_visible, $p_code, $expires, $p_password, $p_encrypt, $paste_owner, $ip, $p_tagsys]);
|
2021-07-12 08:23:14 -04:00
|
|
|
$paste_id = intval($conn->lastInsertId()); /* returns the last inserted ID as per the query above */
|
|
|
|
if ($p_visible == '0') {
|
|
|
|
addToSitemap($paste_id, $priority, $changefreq, $mod_rewrite);
|
|
|
|
}
|
|
|
|
$success = $paste_id;
|
2021-07-10 19:18:17 +01:00
|
|
|
}
|
2021-07-12 08:23:14 -04:00
|
|
|
|
|
|
|
// Redirect to paste on successful entry, or on successful edit redirect back to edited paste
|
|
|
|
if (isset($success)) {
|
2021-07-14 14:20:43 -04:00
|
|
|
$paste_url = urlForPaste($success);
|
2021-07-12 08:23:14 -04:00
|
|
|
header("Location: ${paste_url}");
|
|
|
|
die();
|
|
|
|
}
|
2021-07-10 19:18:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OutPut:
|
|
|
|
// Theme
|
|
|
|
require_once('theme/' . $default_theme . '/header.php');
|
|
|
|
require_once('theme/' . $default_theme . '/main.php');
|
|
|
|
require_once('theme/' . $default_theme . '/footer.php');
|