Browse Source

ReportNotifier Slack notification support

pull/40/head
Benjamin Southall 8 years ago
parent
commit
d09953da07
  1. 6
      inc/config.php
  2. 38
      post.php

6
inc/config.php

@ -1669,3 +1669,9 @@
'<a href="https://youtu.be/$2" target="_blank" class="file">'. '<a href="https://youtu.be/$2" target="_blank" class="file">'.
'<img style="width:360px;height:270px;" src="//img.youtube.com/vi/$2/0.jpg" class="post-image"/>'. '<img style="width:360px;height:270px;" src="//img.youtube.com/vi/$2/0.jpg" class="post-image"/>'.
'</a></div>'; '</a></div>';
// Slack Report Notification
$config['slack'] = true;
$config['slack_channel'] = "reports";
$config['slack_incoming_webhook_endpoint'] = "https://hooks.slack.com/services/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";

38
post.php

@ -141,15 +141,15 @@ if (isset($_POST['delete'])) {
markup($reason); markup($reason);
foreach ($report as &$id) { foreach ($report as &$id) {
$query = prepare(sprintf("SELECT `thread` FROM ``posts_%s`` WHERE `id` = :id", $board['uri'])); $query = prepare(sprintf("SELECT `thread` , `body_nomarkup` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
$query->bindValue(':id', $id, PDO::PARAM_INT); $query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
$thread = $query->fetchColumn(); $thread = $query->fetch(PDO::FETCH_ASSOC);
if ($config['syslog']) if ($config['syslog'])
_syslog(LOG_INFO, 'Reported post: ' . _syslog(LOG_INFO, 'Reported post: ' .
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread ? '#' . $id : '') . '/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread['thread'] ? '#' . $id : '') .
' for "' . $reason . '"' ' 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)");
@ -159,6 +159,38 @@ if (isset($_POST['delete'])) {
$query->bindValue(':post', $id, PDO::PARAM_INT); $query->bindValue(':post', $id, PDO::PARAM_INT);
$query->bindValue(':reason', $reason, PDO::PARAM_STR); $query->bindValue(':reason', $reason, PDO::PARAM_STR);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if ($config['slack'])
{
function slack($message, $room = "reports", $icon = ":no_entry_sign:")
{
$room = ($room) ? $room : "reports";
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"text" => urlencode($message),
"icon_emoji" => $icon
));
// You can get your webhook endpoint from your Slack settings
// For some reason using the configuration key doesn't work
//$ch = curl_init($config['slack_incoming_webhook_endpoint']);
$ch = curl_init("https://hooks.slack.com/services/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");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_';
$slackmessage = 'Post: <' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n Post Content: ' . $postcontent . '\n Reason: ' . $reason . '\n';
$slackresult = slack($slackmessage, $config['slack_channel']);
}
} }
$is_mod = isset($_POST['mod']) && $_POST['mod']; $is_mod = isset($_POST['mod']) && $_POST['mod'];

Loading…
Cancel
Save