post.php: use logger

This commit is contained in:
Zankaria 2024-04-03 23:51:02 +02:00
parent 55cb6bc400
commit 710f6aa6c2

View File

@ -7,6 +7,7 @@ require_once 'inc/bootstrap.php';
use Vichan\AppContext; use Vichan\AppContext;
use Vichan\Driver\HttpDriver; use Vichan\Driver\HttpDriver;
use Vichan\Driver\Log;
use Vichan\Service\{RemoteCaptchaQuery, NativeCaptchaQuery}; use Vichan\Service\{RemoteCaptchaQuery, NativeCaptchaQuery};
/** /**
@ -250,7 +251,7 @@ if (isset($_GET['Newsgroups']) && $config['nntpchan']['enabled']) {
$content = file_get_contents("php://input"); $content = file_get_contents("php://input");
} }
elseif ($ct == 'multipart/mixed' || $ct == 'multipart/form-data') { elseif ($ct == 'multipart/mixed' || $ct == 'multipart/form-data') {
_syslog(LOG_INFO, "MM: Files: ".print_r($GLOBALS, true)); // Debug $context->getLog()->log(Log::DEBUG, 'MM: Files: ' . print_r($GLOBALS, true));
$content = ''; $content = '';
@ -415,8 +416,9 @@ if (isset($_POST['delete'])) {
modLog("User at $ip deleted their own post #$id"); modLog("User at $ip deleted their own post #$id");
} }
_syslog(LOG_INFO, 'Deleted post: ' . $context->getLog()->log(
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '') Log::INFO,
'Deleted post: /' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '')
); );
} }
} }
@ -491,9 +493,7 @@ if (isset($_POST['delete'])) {
error($config['error']['captcha']); error($config['error']['captcha']);
} }
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
if ($config['syslog']) { $context->getLog()->log(Log::ERROR, "Native captcha IO exception: {$e->getMessage()}");
_syslog(LOG_ERR, "Native captcha IO exception: {$e->getMessage()}");
}
error($config['error']['local_io_error']); error($config['error']['local_io_error']);
} }
} }
@ -512,9 +512,7 @@ if (isset($_POST['delete'])) {
$post = $query->fetch(PDO::FETCH_ASSOC); $post = $query->fetch(PDO::FETCH_ASSOC);
if ($post === false) { if ($post === false) {
if ($config['syslog']) { $context->getLog()->log(Log::INFO, "Failed to report non-existing post #{$id} in {$board['dir']}");
_syslog(LOG_INFO, "Failed to report non-existing post #{$id} in {$board['dir']}");
}
error($config['error']['nopost']); error($config['error']['nopost']);
} }
@ -523,11 +521,12 @@ if (isset($_POST['delete'])) {
error($error); error($error);
} }
if ($config['syslog']) $context->getLog()->log(
_syslog(LOG_INFO, 'Reported post: ' . Log::INFO,
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '') . 'Reported post: /'
' for "' . $reason . '"' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($post['thread'] ? '#' . $id : '')
); . " for \"$reason\""
);
$query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)"); $query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)");
$query->bindValue(':time', time(), PDO::PARAM_INT); $query->bindValue(':time', time(), PDO::PARAM_INT);
$query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
@ -637,14 +636,10 @@ if (isset($_POST['delete'])) {
} }
} }
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
if ($config['syslog']) { $context->getLog()->log(Log::ERROR, "Captcha IO exception: {$e->getMessage()}");
_syslog(LOG_ERR, "Captcha IO exception: {$e->getMessage()}");
}
error($config['error']['remote_io_error']); error($config['error']['remote_io_error']);
} catch (JsonException $e) { } catch (JsonException $e) {
if ($config['syslog']) { $context->getLog()->log(Log::ERROR, "Bad JSON reply to captcha: {$e->getMessage()}");
_syslog(LOG_ERR, "Bad JSON reply to captcha: {$e->getMessage()}");
}
error($config['error']['remote_io_error']); error($config['error']['remote_io_error']);
} }
@ -1128,11 +1123,9 @@ if (isset($_POST['delete'])) {
try { try {
$file['size'] = strip_image_metadata($file['tmp_name']); $file['size'] = strip_image_metadata($file['tmp_name']);
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
if ($config['syslog']) { $context->getLog()->log(Log::ERROR, "Could not strip image metadata: {$e->getMessage()}");
_syslog(LOG_ERR, "Could not strip image metadata: {$e->getMessage()}"); // Since EXIF metadata can countain sensible info, fail the request.
// Since EXIF metadata can countain sensible info, fail the request. error(_('Could not strip EXIF metadata!'), null, $error);
error(_('Could not strip EXIF metadata!'), null, $error);
}
} }
} else { } else {
$image->to($file['file']); $image->to($file['file']);
@ -1168,9 +1161,7 @@ if (isset($_POST['delete'])) {
$post['body_nomarkup'] .= "<tinyboard ocr image $key>" . htmlspecialchars($value) . "</tinyboard>"; $post['body_nomarkup'] .= "<tinyboard ocr image $key>" . htmlspecialchars($value) . "</tinyboard>";
} }
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
if ($config['syslog']) { $context->getLog()->log(Log::ERROR, "Could not OCR image: {$e->getMessage()}");
_syslog(LOG_ERR, "Could not OCR image: {$e->getMessage()}");
}
} }
} }
} }
@ -1360,9 +1351,10 @@ if (isset($_POST['delete'])) {
buildThread($post['op'] ? $id : $post['thread']); buildThread($post['op'] ? $id : $post['thread']);
if ($config['syslog']) $context->getLog()->log(
_syslog(LOG_INFO, 'New post: /' . $board['dir'] . $config['dir']['res'] . Log::INFO,
link_for($post) . (!$post['op'] ? '#' . $id : '')); 'New post: /' . $board['dir'] . $config['dir']['res'] . link_for($post) . (!$post['op'] ? '#' . $id : '')
);
if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"'); if (!$post['mod']) header('X-Associated-Content: "' . $redirect . '"');