Make spamnoticer aware of users deleting their own posts
This commit is contained in:
parent
29b45e7a11
commit
39e5960369
|
@ -35,10 +35,6 @@ function getStackTraceAsString() {
|
|||
return $traceString;
|
||||
}
|
||||
|
||||
function print_err2($s) {
|
||||
print_err($s);
|
||||
}
|
||||
|
||||
print_err("\n\nSTART\n\n");
|
||||
|
||||
class AntiBot {
|
||||
|
|
|
@ -517,6 +517,8 @@
|
|||
|
||||
// Allow users to delete their own posts?
|
||||
$config['allow_delete'] = true;
|
||||
// Allow users to delete their own threads?
|
||||
$config['allow_thread_deletion'] = false;
|
||||
// How long after posting should you have to wait before being able to delete that post? (In seconds.)
|
||||
$config['delete_time'] = 10;
|
||||
// Reply limit (stops bumping thread when this is reached).
|
||||
|
|
|
@ -23,6 +23,7 @@ require_once 'inc/mod/auth.php';
|
|||
require_once 'inc/lock.php';
|
||||
require_once 'inc/queue.php';
|
||||
require_once 'inc/polyfill.php';
|
||||
require_once 'inc/spamnoticer.php';
|
||||
@include_once 'inc/lib/parsedown/Parsedown.php'; // fail silently, this isn't a critical piece of code
|
||||
|
||||
if (!extension_loaded('gettext')) {
|
||||
|
@ -1116,7 +1117,7 @@ function bumpThread($id) {
|
|||
function deleteFile($id, $remove_entirely_if_already=true, $file=null, $alert_spamnoticer=false) {
|
||||
global $board, $config;
|
||||
|
||||
$query = prepare(sprintf("SELECT `thread`, `files`, `num_files` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1", $board['uri']));
|
||||
$query = prepare(sprintf("SELECT `thread`, `files`, `num_files`, `delete_token` FROM ``posts_%s`` WHERE `id` = :id LIMIT 1", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
if (!$post = $query->fetch(PDO::FETCH_ASSOC))
|
||||
|
@ -1154,6 +1155,16 @@ function deleteFile($id, $remove_entirely_if_already=true, $file=null, $alert_sp
|
|||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if ($alert_spamnoticer) {
|
||||
$delete_tokens = array();
|
||||
|
||||
if ($post['delete_token']) {
|
||||
$delete_tokens[] = $post['delete_token'];
|
||||
}
|
||||
|
||||
removeRecentPostFromSpamnoticer($config, $delete_tokens, true);
|
||||
}
|
||||
|
||||
if ($post['thread'])
|
||||
buildThread($post['thread']);
|
||||
else
|
||||
|
@ -1192,7 +1203,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true, $aler
|
|||
global $board, $config;
|
||||
|
||||
// Select post and replies (if thread) in one query
|
||||
$query = prepare(sprintf("SELECT `id`,`thread`,`files`,`slug` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query = prepare(sprintf("SELECT `id`,`thread`,`files`,`slug`, `delete_token` FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
|
@ -1206,6 +1217,7 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true, $aler
|
|||
}
|
||||
|
||||
$ids = array();
|
||||
$delete_tokens = array();
|
||||
|
||||
// Delete posts and maybe replies
|
||||
while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
@ -1238,14 +1250,22 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true, $aler
|
|||
}
|
||||
}
|
||||
|
||||
$ids[] = (int)$post['id'];
|
||||
$ids[] = (int) $post['id'];
|
||||
|
||||
if ($post['delete_token']) {
|
||||
$delete_tokens[] = $post['delete_token'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$query = prepare(sprintf("DELETE FROM ``posts_%s`` WHERE `id` = :id OR `thread` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
if ($alert_spamnoticer) {
|
||||
removeRecentPostFromSpamnoticer($config, $delete_tokens);
|
||||
}
|
||||
|
||||
$query = prepare("SELECT `board`, `post` FROM ``cites`` WHERE `target_board` = :board AND (`target` = " . implode(' OR `target` = ', $ids) . ") ORDER BY `board`");
|
||||
$query->bindValue(':board', $board['uri']);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
|
|
@ -211,3 +211,36 @@ function checkWithSpamNoticer($config, $post, $boardname) {
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function removeRecentPostFromSpamnoticer($config, $delete_tokens, $files_only = false) {
|
||||
if (!$delete_tokens) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client = _createClient($config);
|
||||
|
||||
$promise = $client->postAsync('/undo_recent_post', [
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => [
|
||||
'delete_tokens' => $delete_tokens,
|
||||
'files_only' => $files_only,
|
||||
]
|
||||
]);
|
||||
|
||||
$promise->then(
|
||||
function ($response) use ($config) {
|
||||
// This callback is executed when the request is successful
|
||||
if ($config['debug']) {
|
||||
print_err("POST to SpamNoticer /undo_recent_post sent successfully!");
|
||||
}
|
||||
},
|
||||
function (RequestException $exception) {
|
||||
print_err("ERROR sending POST to SpamNoticer /undo_recent_post:\n$exception");
|
||||
}
|
||||
);
|
||||
|
||||
// This will initiate the asynchronous request, but we won't wait for the response.
|
||||
$promise->wait(false); // Set to false for asynchronous behavior
|
||||
}
|
||||
|
|
14
install.php
14
install.php
|
@ -9,7 +9,6 @@ if (fopen('inc/instance-config.php' , 'a') === false) {
|
|||
}
|
||||
|
||||
require 'inc/functions.php';
|
||||
require_once 'inc/anti-bot.php'; // DELETE ME THIS IS FOR print_err function only!
|
||||
|
||||
loadConfig();
|
||||
|
||||
|
@ -25,27 +24,17 @@ $page = array(
|
|||
$config['minify_html'] = false;
|
||||
|
||||
function checkMd5Exec(bool $can_exec) {
|
||||
print_err2("checkMd5Exec");
|
||||
print_err2($can_exec);
|
||||
$shell_out = shell_exec("pwd");
|
||||
print_err2("shell out: " . $shell_out);
|
||||
$shell_out = shell_exec('echo "vichan" | md5sum');
|
||||
print_err2("shell out: " . $shell_out);
|
||||
$shell_ok = $shell_out == "141225c362da02b5c359c45b665168de -\n";
|
||||
print_err2("shell ok: " . strval($shell_ok));
|
||||
$result = $can_exec && $shell_ok;
|
||||
print_err2($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function checkGifsicle() {
|
||||
print_err2("checkGifsicle");
|
||||
$shell_out = shell_exec('echo $PATH');
|
||||
print_err2("shell out: " . $shell_out);
|
||||
$shell_out = shell_exec('gifsicle --help');
|
||||
print_err2("shell out: " . $shell_out);
|
||||
$shell_out = shell_exec('which gifsicle');
|
||||
print_err2("shell out (which gifsicle): " . $shell_out);
|
||||
return $shell_out;
|
||||
}
|
||||
|
||||
|
@ -673,7 +662,6 @@ if ($step == 0) {
|
|||
|
||||
echo Element('page.html', $page);
|
||||
} elseif ($step == 1) {
|
||||
print_err2("Hello World install.php");
|
||||
$page['title'] = 'Pre-installation test';
|
||||
|
||||
$can_exec = true;
|
||||
|
@ -691,8 +679,6 @@ if ($step == 0) {
|
|||
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
|
||||
}
|
||||
|
||||
print_err2("Can exec: " . strval($can_exec));
|
||||
|
||||
// Required extensions
|
||||
$extensions = array(
|
||||
'PDO' => array(
|
||||
|
|
11
post.php
11
post.php
|
@ -172,7 +172,7 @@ function handle_nntpchan() {
|
|||
|
||||
}
|
||||
|
||||
function handle_delete(){
|
||||
function handle_delete() {
|
||||
// Delete
|
||||
global $config, $board, $mod;
|
||||
if (!isset($_POST['board'], $_POST['password']))
|
||||
|
@ -278,9 +278,10 @@ function handle_delete(){
|
|||
echo json_encode(array('success' => true));
|
||||
}
|
||||
|
||||
// We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI)
|
||||
if (function_exists('fastcgi_finish_request'))
|
||||
@fastcgi_finish_request();
|
||||
// We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI)
|
||||
if (function_exists('fastcgi_finish_request')) {
|
||||
@fastcgi_finish_request();
|
||||
}
|
||||
|
||||
rebuildThemes('post-delete', $board['uri']);
|
||||
|
||||
|
@ -988,8 +989,6 @@ function handle_post(){
|
|||
} else {
|
||||
print_err($spam_noticer_result->reason);
|
||||
}
|
||||
} else {
|
||||
print_err("spam_noticer off!");
|
||||
}
|
||||
|
||||
if (!hasPermission($config['mod']['bypass_filters'], $board['uri']) && !$dropped_post) {
|
||||
|
|
Loading…
Reference in New Issue