Change some variables to constants in config.

This commit is contained in:
Floorb 2021-07-26 17:41:54 -04:00
parent 98ce55886c
commit 49eaefd748
13 changed files with 33 additions and 57 deletions

View file

@ -2,6 +2,12 @@
if (!defined('IN_ADMIN')) { if (!defined('IN_ADMIN')) {
die(); die();
} }
$db_opts = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, /* throw a fatal exception on database errors */
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, /* Fetch rows as an associative array (hash table) by default */
PDO::ATTR_EMULATE_PREPARES => false
];
require_once('../includes/config.php'); require_once('../includes/config.php');

View file

@ -292,15 +292,7 @@ for ($loop = 0; $loop <= 6; $loop++) {
<div class="panel-title"> <div class="panel-title">
</div> </div>
<p style="height: auto;"> <p style="height: auto;">
<?php <br />You have the latest version
$latestversion = file_get_contents('https://raw.githubusercontent.com/jordansamuel/PASTE/releases/version');
echo "Latest version: " . $latestversion . "&mdash; Installed version: " . $currentversion;
if ($currentversion == $latestversion) {
echo '<br />You have the latest version';
} else {
echo '<br />Your Paste installation is outdated. Get the latest version from <a href="https://sourceforge.net/projects/phpaste/files/latest/download">SourceForge</a>';
}
?>
</p> </p>
</div> </div>

View file

@ -201,7 +201,7 @@ while ($row = mysqli_fetch_array($result)) {
$site_data = file_get_contents("../sitemap.xml"); $site_data = file_get_contents("../sitemap.xml");
$site_data = str_replace("</urlset>", "", $site_data); $site_data = str_replace("</urlset>", "", $site_data);
if ($mod_rewrite == "1") { if (PP_MOD_REWRITE) {
$server_name = $protocol . $_SERVER['SERVER_NAME'] . $levelup . "/" . $paste_id; $server_name = $protocol . $_SERVER['SERVER_NAME'] . $levelup . "/" . $paste_id;
} else { } else {
$server_name = $protocol . $_SERVER['SERVER_NAME'] . $levelup . "/paste.php?id=" . $paste_id; $server_name = $protocol . $_SERVER['SERVER_NAME'] . $levelup . "/paste.php?id=" . $paste_id;

View file

@ -10,9 +10,7 @@ require_once(__DIR__ . '/User.class.php');
/* View functions */ /* View functions */
function urlForPaste($paste_id) : string { function urlForPaste($paste_id) : string {
global $mod_rewrite; if (PP_MOD_REWRITE) {
if ($mod_rewrite === '1') {
return "/${paste_id}"; return "/${paste_id}";
} }
@ -20,9 +18,7 @@ function urlForPaste($paste_id) : string {
} }
function urlForMember(string $member_name) : string { function urlForMember(string $member_name) : string {
global $mod_rewrite; if (PP_MOD_REWRITE) {
if ($mod_rewrite === '1') {
return '/user/' . urlencode($member_name); return '/user/' . urlencode($member_name);
} }

View file

@ -17,17 +17,15 @@ if (gethostname() === 'thunderlane') {
ini_set('display_errors', 1); ini_set('display_errors', 1);
} }
$currentversion = 2.2; /* Maximum paste size in bytes */
const PP_PASTE_LIMIT_BYTES = 1048576;
// Max paste size in MB. This value should always be below the value of
// post_max_size in your PHP configuration settings (php.ini) or empty errors will occur.
// The value we got on installation of Paste was: post_max_size = 128M
// Otherwise, the maximum value that can be set is 4000 (4GB)
$pastelimit = "1"; // 0.5 = 512 kilobytes, 1 = 1MB
/* A long and random string used for additionally salting passwords. */ /* A long and random string used for additionally salting passwords. */
const PP_PASSWORD_PEPPER = 'd791b6c6-91f2-4e8f-ba80-74ea968e4931'; const PP_PASSWORD_PEPPER = 'd791b6c6-91f2-4e8f-ba80-74ea968e4931';
/* Whether to use friendly URLs that require mod_rewrite */
const PP_MOD_REWRITE = true;
$db_host = 'localhost'; $db_host = 'localhost';
$db_schema = 'p0nepast3s'; $db_schema = 'p0nepast3s';
$db_user = 'P0nedbAcc0unt'; $db_user = 'P0nedbAcc0unt';
@ -41,19 +39,12 @@ if (gethostname() === 'thunderlane') {
$db_pass = 'ponepaste'; $db_pass = 'ponepaste';
} }
$db_opts = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, /* throw a fatal exception on database errors */
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, /* Fetch rows as an associative array (hash table) by default */
PDO::ATTR_EMULATE_PREPARES => false
];
// Secret key for paste encryption // Secret key for paste encryption
//$sec_key = "8ac67343e7980b16b31e8311d4377bbb"; //$sec_key = "8ac67343e7980b16b31e8311d4377bbb";
$sec_key = ''; $sec_key = '';
define('SECRET', md5($sec_key));
// Set to 1 to enable Apache's mod_rewrite
$mod_rewrite = "1";
// Available GeSHi formats // Available GeSHi formats
$geshiformats = [ $geshiformats = [

View file

@ -437,7 +437,7 @@ function addToSitemap($paste_id, $priority, $changefreq, $mod_rewrite) {
// which protocol are we on // which protocol are we on
$protocol = paste_protocol(); $protocol = paste_protocol();
if ($mod_rewrite == "1") { if (PP_MOD_REWRITE) {
$server_name = $protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $paste_id; $server_name = $protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $paste_id;
} else { } else {
$server_name = $protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/paste.php?id=" . $paste_id; $server_name = $protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/paste.php?id=" . $paste_id;

View file

@ -91,7 +91,7 @@ function validatePasteFields() : string|null {
return $lang['notags']; return $lang['notags'];
} elseif (strlen($_POST["title"]) > 70) { /* Paste title too long */ } elseif (strlen($_POST["title"]) > 70) { /* Paste title too long */
return $lang['titlelen']; return $lang['titlelen'];
} elseif (mb_strlen($_POST["paste_data"], '8bit') > 1024 * 1024 * $pastelimit) { /* Paste size too big */ } elseif (mb_strlen($_POST["paste_data"], '8bit') > PP_PASTE_LIMIT_BYTES) { /* Paste size too big */
return $lang['large_paste']; return $lang['large_paste'];
} }

View file

@ -31,7 +31,7 @@ $lang['missing-input-secret'] = "The reCAPTCHA secret parameter is missing. Plea
$lang['missing-input-response'] = "The reCAPTCHA response parameter is invalid. Please try to complete the reCAPTCHA again."; $lang['missing-input-response'] = "The reCAPTCHA response parameter is invalid. Please try to complete the reCAPTCHA again.";
$lang['invalid-input-secret'] = "The reCAPTCHA secret parameter is invalid or malformed. Please double check your PASTE settings."; $lang['invalid-input-secret'] = "The reCAPTCHA secret parameter is invalid or malformed. Please double check your PASTE settings.";
$lang['empty_paste'] = "You cannot post an empty paste."; $lang['empty_paste'] = "You cannot post an empty paste.";
$lang['large_paste'] = "Your paste is too large. Max size is " . $pastelimit . "MB"; $lang['large_paste'] = "Your paste is too large. Max size is " . PP_PASTE_LIMIT_BYTES . " bytes";
$lang['paste_db_error'] = "Unable to post to database."; $lang['paste_db_error'] = "Unable to post to database.";
$lang['error'] = "Something went wrong."; $lang['error'] = "Something went wrong.";
$lang['archive'] = "Pastes Archive"; $lang['archive'] = "Pastes Archive";

View file

@ -199,26 +199,17 @@ if ($p_password == "NONE") {
// No password & diplay the paste // No password & diplay the paste
// Set download URL // Set download URL
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
$p_download = "download/$paste_id"; $p_download = "download/$paste_id";
} else {
$p_download = "paste.php?download&id=$paste_id";
}
// Set raw URL
if ($mod_rewrite == '1') {
$p_raw = "raw/$paste_id"; $p_raw = "raw/$paste_id";
} else {
$p_raw = "paste.php?raw&id=$paste_id";
}
// Set embed URL
if ($mod_rewrite == '1') {
$p_embed = "embed/$paste_id"; $p_embed = "embed/$paste_id";
} else { } else {
$p_download = "paste.php?download&id=$paste_id";
$p_raw = "paste.php?raw&id=$paste_id";
$p_embed = "paste.php?embed&id=$paste_id"; $p_embed = "paste.php?embed&id=$paste_id";
} }
// View counter // View counter
if ($_SESSION['not_unique'] !== $paste_id) { if ($_SESSION['not_unique'] !== $paste_id) {
$_SESSION['not_unique'] = $paste_id; $_SESSION['not_unique'] = $paste_id;

View file

@ -78,7 +78,7 @@ $start = $time;
<div class="navbar-item"> <div class="navbar-item">
<?php if ($current_user !== null) { <?php if ($current_user !== null) {
if (!isset($privatesite) || $privatesite !== "on") { if (!isset($privatesite) || $privatesite !== "on") {
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo ' <a class="button navbar-item mx-2" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/"> echo ' <a class="button navbar-item mx-2" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/">
<span class="icon has-text-info"> <span class="icon has-text-info">
<i class="fa fa-clipboard" aria-hidden="true"></i> <i class="fa fa-clipboard" aria-hidden="true"></i>
@ -125,7 +125,7 @@ $start = $time;
echo '<div class="navbar-item has-dropdown is-hoverable"> echo '<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" role="presentation">' . pp_html_escape($current_user->username) . '</a> <a class="navbar-link" role="presentation">' . pp_html_escape($current_user->username) . '</a>
<div class="navbar-dropdown">'; <div class="navbar-dropdown">';
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo '<a class="navbar-item" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/user/' . urlencode($current_user->username) . '">Pastes</a>'; echo '<a class="navbar-item" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/user/' . urlencode($current_user->username) . '">Pastes</a>';
echo '<a class="navbar-item" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/profile">Settings</a>'; echo '<a class="navbar-item" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/profile">Settings</a>';
} else { } else {
@ -141,7 +141,7 @@ $start = $time;
<div class="buttons"> <div class="buttons">
<?php <?php
if (!isset($privatesite) || $privatesite != "on") { if (!isset($privatesite) || $privatesite != "on") {
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo '<a class="button navbar-item mx-2" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/archive"> echo '<a class="button navbar-item mx-2" href="' . '//' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/archive">
<span class="icon has-text-info"> <span class="icon has-text-info">
<i class="fa fa-book" aria-hidden="true"></i> <i class="fa fa-book" aria-hidden="true"></i>

View file

@ -95,7 +95,7 @@
<p class="no-margin"> <p class="no-margin">
<?php <?php
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo '<header class="bd-category-header my-1"> echo '<header class="bd-category-header my-1">
<a data-tooltip="' . $titlehov . '" href="' . $p_id . '" title="' . $title . '">' . $title . ' </a> <a data-tooltip="' . $titlehov . '" href="' . $p_id . '" title="' . $title . '">' . $title . ' </a>
<a class="icon is-pulled-right has-tooltip-arrow has-tooltip-left-mobile has-tooltip-bottom-desktop has-tooltip-left-until-widescreen" data-tooltip="' . $p_time . '"> <a class="icon is-pulled-right has-tooltip-arrow has-tooltip-left-mobile has-tooltip-bottom-desktop has-tooltip-left-until-widescreen" data-tooltip="' . $p_time . '">
@ -137,7 +137,7 @@
<p class="no-margin"> <p class="no-margin">
<?php <?php
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo '<header class="bd-category-header my-1"> echo '<header class="bd-category-header my-1">
<a data-tooltip="' . $titlehov . '" href="' . $p_id . '" title="' . $title . '">' . $title . ' </a> <a data-tooltip="' . $titlehov . '" href="' . $p_id . '" title="' . $title . '">' . $title . ' </a>
<a class="icon is-pulled-right has-tooltip-arrow has-tooltip-left-mobile has-tooltip-bottom-desktop has-tooltip-left-until-widescreen" data-tooltip="' . $p_time . '"> <a class="icon is-pulled-right has-tooltip-arrow has-tooltip-left-mobile has-tooltip-bottom-desktop has-tooltip-left-until-widescreen" data-tooltip="' . $p_time . '">

View file

@ -189,9 +189,9 @@ $protocol = paste_protocol();
1 => $lang['unlisted'], 1 => $lang['unlisted'],
2 => $lang['private'] 2 => $lang['private']
}; };
$p_link = ($mod_rewrite == '1') ? "$p_id" : "paste.php?id=$p_id"; $p_link = urlForPaste($p_id);
$p_delete_link = ($mod_rewrite == '1') ? "user.php?del&user=$profile_username&id=$p_id" : "user.php?del&user=$profile_username&id=$p_id"; $p_delete_link = (PP_MOD_REWRITE) ? "user.php?del&user=$profile_username&id=$p_id" : "user.php?del&user=$profile_username&id=$p_id";
$p_tag_link = ($mod_rewrite == '1') ? "user.php?user=$profile_username&q=$p_tags" : "user.php?user=$profile_username&q=$tags"; $p_tag_link = (PP_MOD_REWRITE) ? "user.php?user=$profile_username&q=$p_tags" : "user.php?user=$profile_username&q=$tags";
$title = truncate($title, 20, 50); $title = truncate($title, 20, 50);
// Guests only see public pastes // Guests only see public pastes

View file

@ -206,7 +206,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
<div class="panel-embed my-5" style="display:none;"> <div class="panel-embed my-5" style="display:none;">
<input type="text" class="input has-background-white-ter has-text-grey" <input type="text" class="input has-background-white-ter has-text-grey"
value='<?php echo '<script src="' . $protocol . $baseurl . '/'; value='<?php echo '<script src="' . $protocol . $baseurl . '/';
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo 'embed/'; echo 'embed/';
} else { } else {
echo 'paste.php?embed&id='; echo 'paste.php?embed&id=';
@ -263,7 +263,7 @@ $selectedloader = "$bg[$i]"; // set variable equal to which random filename was
<p class="no-margin"> <p class="no-margin">
<?php <?php
if ($mod_rewrite == '1') { if (PP_MOD_REWRITE) {
echo '<header class="bd-category-header my-1"> echo '<header class="bd-category-header my-1">
<a href="' . $p_id . '" title="' . $long_title . '">' . $title . ' </a> <a href="' . $p_id . '" title="' . $long_title . '">' . $title . ' </a>
<p class="subtitle is-7">' . 'by ' . ' <p class="subtitle is-7">' . 'by ' . '