Tul xxx Tul
User / IP
:
216.73.216.217
Host / Server
:
45.84.207.204 / aircan.me
System
:
Linux lt-bnk-web1726.main-hosting.eu 5.14.0-611.36.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 3 11:23:52 EST 2026 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
u931257429
/
domains
/
aircan.me
/
public_html
/
francisco
/
Viewing: clientes.php
<?php require_once 'conexion.php'; header('Content-Type: application/json; charset=utf-8'); function respuesta($ok, $extra = []) { echo json_encode($ok ? array_merge(['success' => true], $extra) : array_merge(['success' => false], $extra)); exit; } function request_data() { $contentType = $_SERVER['CONTENT_TYPE'] ?? $_SERVER['HTTP_CONTENT_TYPE'] ?? ''; if (stripos($contentType, 'application/json') !== false) { $data = json_decode(file_get_contents('php://input'), true); return is_array($data) ? $data : []; } return $_POST; } function safe_unlink_if_exists($relativePath) { if (!$relativePath) return; $filePath = __DIR__ . DIRECTORY_SEPARATOR . str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $relativePath); if (file_exists($filePath)) { @unlink($filePath); } } $action = $_GET['action'] ?? ''; $hasDocumento = false; try { $stmt = $conn->prepare("SHOW COLUMNS FROM clientes LIKE 'documento'"); $stmt->execute(); $hasDocumento = (bool) $stmt->fetch(PDO::FETCH_ASSOC); } catch (Exception $e) { $hasDocumento = false; } $hasFoto = false; try { $stmt = $conn->prepare("SHOW COLUMNS FROM clientes LIKE 'foto'"); $stmt->execute(); $hasFoto = (bool) $stmt->fetch(PDO::FETCH_ASSOC); } catch (Exception $e) { $hasFoto = false; } // Ensure upload directory exists $uploadDir = __DIR__ . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'clientes_registrados' . DIRECTORY_SEPARATOR; if (!is_dir($uploadDir)) { @mkdir($uploadDir, 0777, true); } if ($action === 'list') { try { $sql = null; if ($hasDocumento && $hasFoto) { $sql = 'SELECT id, foto, nombre, telefono, documento, direccion, creado_en FROM clientes ORDER BY id DESC'; } elseif ($hasDocumento && !$hasFoto) { $sql = 'SELECT id, NULL AS foto, nombre, telefono, documento, direccion, creado_en FROM clientes ORDER BY id DESC'; } elseif (!$hasDocumento && $hasFoto) { $sql = 'SELECT id, foto, nombre, telefono, NULL AS documento, direccion, creado_en FROM clientes ORDER BY id DESC'; } else { $sql = 'SELECT id, NULL AS foto, nombre, telefono, NULL AS documento, direccion, creado_en FROM clientes ORDER BY id DESC'; } $res = $conn->query($sql); echo json_encode($res->fetchAll(PDO::FETCH_ASSOC)); exit; } catch (Exception $e) { respuesta(false, ['error' => 'Error al listar clientes.']); } } if ($action === 'count') { try { $res = $conn->query('SELECT COUNT(*) as total FROM clientes'); $row = $res->fetch(PDO::FETCH_ASSOC); echo json_encode(['total' => intval($row['total'] ?? 0)]); exit; } catch (Exception $e) { echo json_encode(['total' => 0]); exit; } } if ($action === 'add') { $data = request_data(); $nombre = trim($data['nombre'] ?? ''); $telefono = trim($data['telefono'] ?? ''); $documento = trim($data['documento'] ?? ''); $direccion = trim($data['direccion'] ?? ''); $fotoPath = null; if (!$nombre || !$telefono || !$direccion) { respuesta(false, ['error' => 'Nombre, teléfono y dirección son obligatorios.']); } try { if ($hasDocumento && $documento !== '') { $stmt = $conn->prepare('SELECT id FROM clientes WHERE documento = ?'); $stmt->execute([$documento]); if ($stmt->fetch()) { respuesta(false, ['error' => 'Ya existe un cliente con ese documento.']); } } if ($hasFoto && isset($_FILES['foto']) && $_FILES['foto']['error'] === UPLOAD_ERR_OK) { $ext = strtolower(pathinfo($_FILES['foto']['name'], PATHINFO_EXTENSION)); $allowed = ['png', 'jpg', 'jpeg', 'webp', 'gif', 'svg']; if (!in_array($ext, $allowed)) { respuesta(false, ['error' => 'Formato de imagen no permitido.']); } $fileName = uniqid('cli_') . '.' . $ext; $dest = $uploadDir . $fileName; if (move_uploaded_file($_FILES['foto']['tmp_name'], $dest)) { $fotoPath = 'uploads/clientes_registrados/' . $fileName; } } $cols = ['nombre', 'telefono', 'direccion']; $vals = [$nombre, $telefono, $direccion]; if ($hasDocumento) { $cols[] = 'documento'; $vals[] = ($documento === '' ? null : $documento); } if ($hasFoto) { $cols[] = 'foto'; $vals[] = $fotoPath; } $placeholders = implode(',', array_fill(0, count($cols), '?')); $sql = 'INSERT INTO clientes (' . implode(', ', $cols) . ') VALUES (' . $placeholders . ')'; $stmt = $conn->prepare($sql); $ok = $stmt->execute($vals); if ($ok) { respuesta(true); } respuesta(false, ['error' => 'Error al guardar en la base de datos.']); } catch (Exception $e) { respuesta(false, ['error' => 'Error al guardar en la base de datos.']); } } if ($action === 'delete') { $data = request_data(); $id = intval($data['id'] ?? 0); if (!$id) respuesta(false, ['error' => 'ID inválido.']); try { if ($hasFoto) { $stmt = $conn->prepare('SELECT foto FROM clientes WHERE id = ?'); $stmt->execute([$id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row && !empty($row['foto'])) { safe_unlink_if_exists($row['foto']); } } $stmt = $conn->prepare('DELETE FROM clientes WHERE id = ?'); if ($stmt->execute([$id])) { respuesta(true); } respuesta(false, ['error' => 'No se pudo eliminar.']); } catch (Exception $e) { respuesta(false, ['error' => 'No se pudo eliminar.']); } } if ($action === 'get') { $id = intval($_GET['id'] ?? 0); if (!$id) respuesta(false, ['error' => 'ID inválido.']); try { $sql = null; if ($hasDocumento && $hasFoto) { $sql = 'SELECT id, foto, nombre, telefono, documento, direccion, creado_en FROM clientes WHERE id = ?'; } elseif ($hasDocumento && !$hasFoto) { $sql = 'SELECT id, NULL AS foto, nombre, telefono, documento, direccion, creado_en FROM clientes WHERE id = ?'; } elseif (!$hasDocumento && $hasFoto) { $sql = 'SELECT id, foto, nombre, telefono, NULL AS documento, direccion, creado_en FROM clientes WHERE id = ?'; } else { $sql = 'SELECT id, NULL AS foto, nombre, telefono, NULL AS documento, direccion, creado_en FROM clientes WHERE id = ?'; } $stmt = $conn->prepare($sql); $stmt->execute([$id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row) { echo json_encode($row); exit; } respuesta(false, ['error' => 'Cliente no encontrado.']); } catch (Exception $e) { respuesta(false, ['error' => 'Cliente no encontrado.']); } } if ($action === 'edit') { $data = request_data(); $id = intval($data['id'] ?? 0); $nombre = trim($data['nombre'] ?? ''); $telefono = trim($data['telefono'] ?? ''); $documento = trim($data['documento'] ?? ''); $direccion = trim($data['direccion'] ?? ''); $newFotoPath = null; $hasNewFoto = false; if (!$id || !$nombre || !$telefono || !$direccion) { respuesta(false, ['error' => 'Todos los campos obligatorios deben estar completos.']); } try { $curr = null; if ($hasFoto) { $stmt = $conn->prepare('SELECT foto FROM clientes WHERE id = ?'); $stmt->execute([$id]); $curr = $stmt->fetch(PDO::FETCH_ASSOC); } if ($hasDocumento && $documento !== '') { $stmt = $conn->prepare('SELECT id FROM clientes WHERE documento = ? AND id != ?'); $stmt->execute([$documento, $id]); if ($stmt->fetch()) { respuesta(false, ['error' => 'Ya existe otro cliente con ese documento.']); } } if ($hasFoto && isset($_FILES['foto']) && $_FILES['foto']['error'] === UPLOAD_ERR_OK) { if ($curr && !empty($curr['foto'])) { safe_unlink_if_exists($curr['foto']); } $ext = strtolower(pathinfo($_FILES['foto']['name'], PATHINFO_EXTENSION)); $allowed = ['png', 'jpg', 'jpeg', 'webp', 'gif', 'svg']; if (!in_array($ext, $allowed)) { respuesta(false, ['error' => 'Formato de imagen no permitido.']); } $fileName = uniqid('cli_') . '.' . $ext; $dest = $uploadDir . $fileName; if (move_uploaded_file($_FILES['foto']['tmp_name'], $dest)) { $newFotoPath = 'uploads/clientes_registrados/' . $fileName; $hasNewFoto = true; } } $set = ['nombre = ?', 'telefono = ?', 'direccion = ?']; $params = [$nombre, $telefono, $direccion]; if ($hasDocumento) { $set[] = 'documento = ?'; $params[] = ($documento === '' ? null : $documento); } if ($hasFoto && $hasNewFoto) { $set[] = 'foto = ?'; $params[] = $newFotoPath; } $params[] = $id; $sql = 'UPDATE clientes SET ' . implode(', ', $set) . ' WHERE id = ?'; $stmt = $conn->prepare($sql); $ok = $stmt->execute($params); if ($ok) { respuesta(true); } respuesta(false, ['error' => 'Error al actualizar en la base de datos.']); } catch (Exception $e) { respuesta(false, ['error' => 'Error al actualizar en la base de datos.']); } } respuesta(false, ['error' => 'Acción no válida']);
Coded With 💗 by
0x6ick