-
Notifications
You must be signed in to change notification settings - Fork 3
/
verisure.php
106 lines (89 loc) · 3.37 KB
/
verisure.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
header('Content-Type: application/json');
$email = $_GET['ma'];
$password = $_GET['pw'];
$doorCode = $_GET['dc'];
$intention = $_GET['int'];
$installationId = $_GET['ins'];
$deviceLabel = $_GET['dev'];
$baseURL = "https://e-api01.verisure.com/xbn/2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseURL . '/cookie');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "CPE/$email:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json;charset=UTF-8', 'Accept: application/json']);
$response = curl_exec($ch);
if (!$response)
{
echo 'Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch);
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
$cookie = json_decode($response);
$cookie = $cookie->cookie;
curl_close($ch);
if ($intention === "installid")
{
$urlEmail = urlencode($email);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseURL/webaccount/$urlEmail/installation");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: keep-alive', 'Accept: application/json, text/javascript, */*; q=0.01', 'Content-Type: application/json;charset=UTF-8', 'Cookie: vid=' . $cookie, ]);
$response = curl_exec($ch);
if (!$response)
{
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
echo $response;
curl_close($ch);
}
elseif ($intention === "lock" || $intention === "unlock")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseURL/installation/$installationId/device/$deviceLabel/$intention");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: keep-alive', 'Accept: application/json, text/javascript, */*; q=0.01', 'APPLICATION_ID: VS_APP_IPHONE', 'Content-Type: application/json;charset=UTF-8', "Cookie: vid=$cookie", ]);
// json body
$json_array = ['code' => $doorCode];
$body = json_encode($json_array);
// set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// send the request and save response to $response
$response = curl_exec($ch);
// stop if fails
if (!$response)
{
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
echo $response;
// close curl resource to free up system resources
curl_close($ch);
}
elseif ($intention === "status")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseURL/installation/$installationId/overview");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Cookie: vid=' . $cookie, 'Connection: keep-alive', 'Accept: application/json, text/javascript, */*; q=0.01', 'APPLICATION_ID: VS_APP_IPHONE', 'Content-Type: application/json;charset=UTF-8', ]);
$response = curl_exec($ch);
if (!$response)
{
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
echo 'Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch);
}
$response = json_decode($response);
$response = $response->doorLockStatusList;
$response = json_encode($response);
echo $response;
curl_close($ch);
}
else
{
echo 'No valid status in "int=" URL parameter. Valid parameters are installid, status, lock and unlock';
}
?>