-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathciscospark.php
71 lines (54 loc) · 1.92 KB
/
ciscospark.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
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
<html>
<body>
<?php
/* Sample php script to be loaded on a web server and registered via as a webhook to the Spark API - it will receive a notification when a new message is posted and then call an external python script (sparkmess.py in this example) passing the messageid
CAREFUL on LOOPING - make sure to only post responses to rooms in response to messages your script didn't post or you could create a loop condition and overrun your room!!! In this example the loop prevention is in the python script, not here...
*/
$webhooksecretorig = "blalaberfasel"; # set NULL to disable check
$rawPost = NULL;
if ($webhooksecretorig !== NULL) {
if (!isset($_SERVER['HTTP_X_SPARK_SIGNATURE'])) {
throw new \Exception("HTTP header 'X-Spark-Signature' is missing.");
} elseif (!extension_loaded('hash')) {
throw new \Exception("Missing 'hash' extension to check the secret code validity.");
}
$hash = $_SERVER['HTTP_X_SPARK_SIGNATURE'];
$rawPost = file_get_contents('php://input');
if ($hash !== hash_hmac("SHA1", $rawPost, $webhooksecretorig)) {
throw new \Exception('Hook secret does not match.');
}
};
$json=json_decode($rawPost,true);
$txt = var_dump($json);
echo $txt;
$roomid = $json["data"]["roomId"];
echo "roomid";
echo $roomid;
$messid=$json["data"]["id"];
echo "messid";
echo $messid;
$pythonreturn = system ('python /usr/lib/cgi-bin/sparkmess.py '.$messid);
echo $pythonreturn;
/* This commented section can log to a MySQL database for tracking
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'YOURPASSWORD';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'INSERT INTO webhook '.
'(JSON) '.
'VALUES ( "'.$messid." at ".$roomid.'")';
mysql_select_db('Ciscospark');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
*/
?>
</body>
</html>