Merge vichan PHP8 fixes, configure composer, fix outstanding incompatibilities

This commit is contained in:
discomrade 2021-06-29 23:10:12 -02:00
parent c9ef4e80ac
commit 2605a6ff5d
252 changed files with 279 additions and 28498 deletions

View file

@ -9,31 +9,10 @@ if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
exit;
}
define('TINYBOARD', null);
$microtime_start = microtime(true);
require_once 'inc/error.php';
require_once 'inc/cache.php';
require_once 'inc/display.php';
require_once 'inc/template.php';
require_once 'inc/database.php';
require_once 'inc/events.php';
require_once 'inc/api.php';
require_once 'inc/mod/auth.php';
require_once 'inc/lock.php';
require_once 'inc/queue.php';
require_once 'inc/polyfill.php';
require_once 'inc/lib/IP/Lifo/IP/IP.php';
@include_once 'inc/lib/parsedown/Parsedown.php'; // fail silently, this isn't a critical piece of code
require_once 'inc/anti-bot.php'; // DELETE ME THIS IS FOR print_err function only!
use Lifo\IP\IP; // for expanding IPv6 address in DNSBL()
if (!extension_loaded('gettext')) {
require_once 'inc/lib/gettext/gettext.inc';
}
// the user is not currently logged in as a moderator
$mod = false;
@ -1611,6 +1590,70 @@ function checkMute() {
}
}
function checkSpam(array $extra_salt = array()) {
global $config, $pdo;
if (!isset($_POST['hash']))
return true;
$hash = $_POST['hash'];
if (!empty($extra_salt)) {
// create a salted hash of the "extra salt"
$extra_salt = implode(':', $extra_salt);
} else {
$extra_salt = '';
}
// Reconsturct the $inputs array
$inputs = array();
foreach ($_POST as $name => $value) {
if (in_array($name, $config['spam']['valid_inputs']))
continue;
$inputs[$name] = $value;
}
// Sort the inputs in alphabetical order (A-Z)
ksort($inputs);
$_hash = '';
// Iterate through each input
foreach ($inputs as $name => $value) {
print_err("-> " . $name . ' : ' . $value);
$_hash .= $name . '=' . $value;
}
// Add a salt to the hash
$_hash .= $config['cookies']['salt'];
// Use SHA1 for the hash
$_hash = sha1($_hash . $extra_salt);
if ($hash != $_hash) {
print_err("Hash mismatch");
return true;
}
$query = prepare('SELECT `passed` FROM ``antispam`` WHERE `hash` = :hash');
$query->bindValue(':hash', $hash);
$query->execute() or error(db_error($query));
if ((($passed = $query->fetchColumn(0)) === false) || ($passed > $config['spam']['hidden_inputs_max_pass'])) {
// there was no database entry for this hash. most likely expired.
return true;
}
return $hash;
}
function incrementSpamHash($hash) {
$query = prepare('UPDATE ``antispam`` SET `passed` = `passed` + 1 WHERE `hash` = :hash');
$query->bindValue(':hash', $hash);
$query->execute() or error(db_error($query));
}
function buildIndex($global_api = "yes") {
global $board, $config, $build_pages;
@ -1746,7 +1789,6 @@ function buildJavascript() {
}
if ($config['minify_js']) {
require_once 'inc/lib/minify/JSMin.php';
$script = JSMin::minify($script);
}