-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_zone.php
More file actions
49 lines (40 loc) · 1.48 KB
/
get_zone.php
File metadata and controls
49 lines (40 loc) · 1.48 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
<?php
include 'config.php';
include 'functions.php';
require_once 'auth.php';
/** @var array $config */
header('Content-Type: application/json');
// 🔐 Start sesji i walidacja CSRF
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST' ||
!isset($_POST['csrf_token']) ||
$_POST['csrf_token'] !== ($_SESSION['csrf_token'] ?? '')
) {
http_response_code(403);
echo json_encode(['success' => false, 'error' => 'Nieprawidłowy token CSRF']);
exit;
}
$auth = login($config['username'], $config['password']);
if (!empty($auth['token'])) {
$userId = $_POST['user_id'] ?? '';
$udid = $_POST['udid'] ?? '';
$zoneId = (int) ($_POST['zone_id'] ?? 0);
if ($userId && $udid && $zoneId) {
$details = getModuleDetails($userId, $udid, $auth['token']);
foreach ($details['zones']['elements'] ?? [] as $zone) {
if (($zone['mode']['id'] ?? 0) == $zoneId) {
echo json_encode([
'success' => true,
'setTemperature' => number_format($zone['zone']['setTemperature'] / 10, 1, '.', ''),
'currentTemperature' => number_format($zone['zone']['currentTemperature'] / 10, 1, '.', ''),
'state' => $zone['zone']['zoneState'] ?? 'brak'
]);
exit;
}
}
}
}
http_response_code(400);
echo json_encode(['success' => false, 'error' => 'Nie udało się pobrać danych strefy']);