connect_error) { die("Connection failed: " . $mysqli->connect_error); } // Diretório de upload $upload_dir = '/var/www/html/uploads/'; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } // Tipos de arquivos permitidos $allowed_types = ['image/jpeg', 'image/png', 'image/gif', 'application/pdf']; $max_file_size = 10 * 1024 * 1024; // 10MB if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_FILES['files'])) { $files = $_FILES['files']; $modification_times = isset($_POST['modification_times']) ? explode(',', $_POST['modification_times']) : []; // Capturar informações adicionais $user_agent = isset($_POST['user_agent']) ? $_POST['user_agent'] : 'Desconhecido'; $language = isset($_POST['language']) ? $_POST['language'] : 'Desconhecido'; $viewport_width = isset($_POST['viewport_width']) ? intval($_POST['viewport_width']) : 0; $viewport_height = isset($_POST['viewport_height']) ? intval($_POST['viewport_height']) : 0; $ip_address = $_SERVER['REMOTE_ADDR']; $host_name = gethostbyaddr($ip_address); $access_time = date("Y-m-d H:i:s"); // Formato padrão MySQL $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Desconhecido'; $request_method = $_SERVER['REQUEST_METHOD']; $server_software = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'Desconhecido'; $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'Desconhecido'; $connection = isset($_SERVER['HTTP_CONNECTION']) ? $_SERVER['HTTP_CONNECTION'] : 'Desconhecido'; $client_port = isset($_SERVER['REMOTE_PORT']) ? intval($_SERVER['REMOTE_PORT']) : 0; for ($i = 0; $i < count($files['name']); $i++) { $file_name = basename($files['name'][$i]); $file_tmp = $files['tmp_name'][$i]; $file_size = $files['size'][$i]; $file_type = $files['type'][$i]; $file_error = $files['error'][$i]; $file_path = $upload_dir . $file_name; // Validações if ($file_error !== UPLOAD_ERR_OK) { continue; } if ($file_size > $max_file_size) { continue; } if (!in_array($file_type, $allowed_types)) { continue; } // Movendo o arquivo if (move_uploaded_file($file_tmp, $file_path)) { // Ajustar a data de modificação usando touch() if (isset($modification_times[$i])) { $mod_time = intval($modification_times[$i] / 1000); // Convertendo de milissegundos para segundos touch($file_path, $mod_time); } // Gerar hash do arquivo para integridade $file_hash = hash_file('sha256', $file_path); // Preparar inserção na tabela queue $stmt = $mysqli->prepare("INSERT INTO queue (file_path, user_agent, ip_address, host_name, access_time, language, referer, request_method, server_software, protocol, connection, viewport_width, viewport_height, file_hash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); if (!$stmt) { unlink($file_path); continue; } $stmt->bind_param( "ssssssssssssss", $file_path, $user_agent, $ip_address, $host_name, $access_time, $language, $referer, $request_method, $server_software, $protocol, $connection, $viewport_width, $viewport_height, $file_hash ); if ($stmt->execute()) { $queue_id = $stmt->insert_id; } else { unlink($file_path); $stmt->close(); continue; } $stmt->close(); // Adicionar entrada na tabela client_ports $stmt_port = $mysqli->prepare("INSERT INTO client_ports (queue_id, port) VALUES (?, ?)"); if (!$stmt_port) { continue; } $stmt_port->bind_param("ii", $queue_id, $client_port); if ($stmt_port->execute()) { } else { } $stmt_port->close(); } else { } } } } $mysqli->close(); header("Location: /index.php?page=status"); exit(); ?>