summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2016-09-23 22:44:48 +0900
committerBenjamin Southall <applemansigloo@gmail.com>2016-09-23 22:44:48 +0900
commitd09953da0750347f965dcdebd7a769fed98945ee (patch)
treea4fcaa725a52a14d39c7b3a36c74456f4488e35b
parentdf4c402f1add7547d472f94934c5137faf23aef4 (diff)
ReportNotifier Slack notification support
-rw-r--r--inc/config.php6
-rw-r--r--post.php38
2 files changed, 41 insertions, 3 deletions
diff --git a/inc/config.php b/inc/config.php
index 69b4bd3a..86ddd5aa 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -1669,3 +1669,9 @@
'<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"/>'.
'</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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";
+
diff --git a/post.php b/post.php
index 99ef4850..f2ed509f 100644
--- a/post.php
+++ b/post.php
@@ -141,15 +141,15 @@ if (isset($_POST['delete'])) {
markup($reason);
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->execute() or error(db_error($query));
- $thread = $query->fetchColumn();
+ $thread = $query->fetch(PDO::FETCH_ASSOC);
if ($config['syslog'])
_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 . '"'
);
$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(':reason', $reason, PDO::PARAM_STR);
$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'];