fix-proxmox-dashboard
This commit is contained in:
parent
fdad258386
commit
5c54b1916d
@ -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]);
|
||||
|
||||
@ -35,10 +35,41 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$uid = preg_replace('/[^0-9A-Fa-f]/', '', $_POST['uid'] ?? '');
|
||||
if (!$uid) { $msg = 'UID invalido.'; $msgOk = false; }
|
||||
else {
|
||||
$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] {$_POST['action']} OK"; }
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user