-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
40 lines (30 loc) · 1.23 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
//ini_set("display_errors", 1);
//ini_set("error_reporting", E_ALL);
$channels = require_once("channels.php");
$path = array_values(array_filter(explode("/", $_SERVER["REQUEST_URI"])));
$id = $path[0];
if (empty($channels[$id])) die;
$channels = $channels[$id];
$prefix = ""; // HACK TO PREVENT PING-PONG USING U+200F Right-To-Left Mark ‏ "" http://stackoverflow.com/questions/17978720/invisible-characters-ascii
// Only registered channels can broadcast.
if (empty($channels[$_POST["token"]])) die;
// Prevent reposting bot texts.
if (substr($_POST["text"], 0, strlen($prefix)) === $prefix) die;
foreach ($channels as $token => $url) {
// Skip the channel that is broadcasting.
if ($_POST["token"] === $token) continue;
// Post to all other channels.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
"payload" => json_encode([
"text" => "{$prefix}{$_POST['text']}",
"username" => "Fwd: {$_POST['user_name']} ({$_POST['team_domain']}#{$_POST['channel_name']})",
])
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
}