From 5c54b1916dde198cbd74db78022e9afbebc5a438 Mon Sep 17 00:00:00 2001 From: deploy Date: Sat, 27 Jun 2026 21:35:49 +0000 Subject: [PATCH] fix-proxmox-dashboard --- api/delete_device.php | 3 +-- esp_proxmox.php | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/api/delete_device.php b/api/delete_device.php index d5975e5..0027eec 100644 --- a/api/delete_device.php +++ b/api/delete_device.php @@ -11,7 +11,6 @@ if (!$data || !isset($data['uid'])) { $uid = $data['uid']; -$stmt = $db->prepare("DELETE FROM contadores WHERE uid=?"); -$stmt->execute([$uid]); +$pdo->prepare("DELETE FROM contadores WHERE uid=?")->execute([$uid]); echo json_encode(["ok"=>1]); diff --git a/esp_proxmox.php b/esp_proxmox.php index f3379f5..6910bad 100644 --- a/esp_proxmox.php +++ b/esp_proxmox.php @@ -35,9 +35,40 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $uid = preg_replace('/[^0-9A-Fa-f]/', '', $_POST['uid'] ?? ''); if (!$uid) { $msg = 'UID invalido.'; $msgOk = false; } else { - $res = pmx_post($_POST); - if (!empty($res['ok'])) { $msg = "[$uid] {$_POST['action']} OK"; } - else { $msg = $res['error'] ?? 'Erro'; $msgOk = false; } + $action = $_POST['action'] ?? ''; + try { + $pdo = new PDO('mysql:host=localhost;dbname=cagalhao;charset=utf8', + 'master', 'master', + [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]); + if ($action === 'approve') { + $pdo->prepare("UPDATE contadores SET blocked=0 WHERE uid=?")->execute([$uid]); + // sincronizar na VPS + $vps = ['http'=>['method'=>'POST','header'=>'Content-Type: application/x-www-form-urlencoded', + 'content'=>http_build_query(['action'=>'approve','uid'=>$uid]),'timeout'=>4]]; + @file_get_contents('https://web.xpto.ooguy.com/esp_api.php?key=esp_api_xupas_2025', false, stream_context_create($vps)); + $msg = "[$uid] aprovado OK"; $msgOk = true; + } elseif ($action === 'block') { + $pdo->prepare("UPDATE contadores SET blocked=1,online=0 WHERE uid=?")->execute([$uid]); + // sincronizar na VPS + $vps = ['http'=>['method'=>'POST','header'=>'Content-Type: application/x-www-form-urlencoded', + 'content'=>http_build_query(['action'=>'block','uid'=>$uid]),'timeout'=>4]]; + @file_get_contents('https://web.xpto.ooguy.com/esp_api.php?key=esp_api_xupas_2025', false, stream_context_create($vps)); + $msg = "[$uid] bloqueado OK"; $msgOk = true; + } elseif ($action === 'delete') { + // CT106 api.py: envia DELETE_CERT via MQTT + apaga CT106 SQLite + apaga VPS SQLite + pmx_post(['uid'=>$uid,'action'=>'delete']); + // apagar também do CT102 MySQL (esta BD) + $pdo->prepare("DELETE FROM contadores WHERE uid=?")->execute([$uid]); + $msg = "[$uid] eliminado OK"; $msgOk = true; + } else { + // cmd, switch_pair, brightness — envia via CT106 api.py (MQTT) + $res = pmx_post($_POST); + if (!empty($res['ok'])) { $msg = "[$uid] $action OK"; $msgOk = true; } + else { $msg = $res['error'] ?? 'Erro'; $msgOk = false; } + } + } catch (Throwable $e) { + $msg = 'Erro BD: '.$e->getMessage(); $msgOk = false; + } } $qs = $msg ? ($msgOk ? '?ok='.urlencode($msg) : '?err='.urlencode($msg)) : ''; header("Location: /esp_proxmox.php$qs"); exit;