-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.php
More file actions
84 lines (78 loc) · 1.92 KB
/
bot.php
File metadata and controls
84 lines (78 loc) · 1.92 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require 'post.php';
$data = explode( ',', $data );
$lat = $data[0];
$lon = $data[1];
$alt = $data[2];
$Tin = $data[3];
$Tex = $data[4];
$alb = $data[5];
$gps = $data[6];
$chk = $data[7];
$text = 'New Iridium post received at ' . $transmit_time;
$attachments = array(
array(
'color' => '#3498DB',
'fields' => array(
array(
'title' => 'GPS position',
'value' => $lat . ", " . $lon,
'short' => true
),
array(
'title' => 'Altitude',
'value' => $alt . " m",
'short' => true
),
array(
'title' => 'Interior Temperature',
'value' => $Tin . " C",
'short' => true
),
array(
'title' => 'Exterior Temperature',
'value' => $Tex . " C",
'short' => true
),
array(
'title' => 'Barometric Altitude',
'value' => $alb . " m",
'short' => true
),
array(
'title' => 'Number of GPS satellites',
'value' => $gps,
'short' => true
),
array(
'title' => 'Check',
'value' => $chk,
'short' => true
)
)
),
array(
'color' => '#D00000',
'fields' => array(
array(
'title' => 'Follow live!',
'value' => "<https://dev.coderagora.com/iridium/|Iridium Live Tracking>\n<https://www.google.com/maps/place/" . $lat . "+" . $lon . "|Google Maps>"
)
)
)
);
$json_data = json_encode( array( 'text' => $text, 'attachments' => $attachments ) );
print_r( $json_data );
$urls = array( 'https://hooks.slack.com/services/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', 'https://hooks.slack.com/services/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' );
foreach ( $urls as $url ) {
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json_data );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen( $json_data )
));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_exec( $ch );
}