HEX
Server: Apache
System: Linux vps-4103104.goatdigital.com.br 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: wwgoat (1001)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: /home/wwgoat/public_html/www/ATUALIZAR_PAGAMENTO/painel.php
<?php
/**
 * Painel de Monitoramento de Acessos PRO v3.5
 * GARANTIDO o refresh automático a cada 30 segundos (exceto na pág. de config ).
 */
require_once 'config.php';

$logFile = 'dados_acesso.txt';
$blockFile = 'logs_bloqueios.txt';
$configFile = 'config.php';

// --- LÓGICA DE EXPORTAÇÃO CSV ---
if (isset($_GET['export']) && $_GET['export'] == 'csv') {
    if (file_exists($logFile)) {
        header('Content-Type: text/csv; charset=utf-8');
        header('Content-Disposition: attachment; filename=logs_acesso_' . date('Ymd_His') . '.csv');
        $output = fopen('php://output', 'w');
        fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF));
        fputcsv($output, ['Data/Hora', 'IP', 'Código', 'Cidade', 'Estado', 'País', 'Navegador'], ';');
        $lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        foreach (array_reverse($lines) as $line) {
            if (preg_match('/\[(.*?)\] IP: (.*?) \| Codigo: (.*?) \| Cidade: (.*?) \| Estado: (.*?) \| Pais: (.*?) \| Navegador: (.*)/', $line, $matches)) {
                fputcsv($output, array_slice($matches, 1), ';');
            }
        }
        fclose($output);
        exit;
    }
}

// Lógica para salvar novo Token
if (isset($_POST['save_token'])) {
    $newToken = trim($_POST['api_token']);
    $content = "<?php\n// Arquivo de configuração gerado automaticamente pelo Painel\n\$config_token = '{$newToken}';\n?>";
    file_put_contents($configFile, $content);
    header("Location: painel.php?view=config&status=updated");
    exit;
}

// Lógica para zerar arquivos
if (isset($_POST['zerar_logs'])) { file_put_contents($logFile, ""); header("Location: painel.php?status=zerado"); exit; }
if (isset($_POST['zerar_blocks'])) { file_put_contents($blockFile, ""); header("Location: painel.php?status=zerado"); exit; }

// --- CARREGAR LOGS ---
$logs = [];
if (file_exists($logFile)) {
    $lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach (array_reverse($lines) as $line) {
        if (preg_match('/\[(.*?)\] IP: (.*?) \| Codigo: (.*?) \| Cidade: (.*?) \| Estado: (.*?) \| Pais: (.*?) \| Navegador: (.*)/', $line, $matches)) {
            $logs[] = [
                'date' => $matches[1], 'ip' => $matches[2], 'code' => $matches[3],
                'city' => $matches[4], 'state' => $matches[5], 'country' => $matches[6],
                'browser' => $matches[7]
            ];
        }
    }
}

$blocks = [];
$ataque_recente = false;
if (file_exists($blockFile)) {
    $blines = file($blockFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach (array_reverse($blines) as $line) {
        if (preg_match('/\[(.*?)\] IP: (.*?) \| Motivo: (.*?) \| UA: (.*)/', $line, $matches)) {
            $blocks[] = ['date' => $matches[1], 'ip' => $matches[2], 'bot' => $matches[3], 'ua' => $matches[4]];
            if (strtotime($matches[1]) > (time() - 300)) $ataque_recente = true;
        }
    }
}

$total_acessos = count($logs);
$total_blocks = count($blocks);
$view = $_GET['view'] ?? 'dashboard';
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- LINHA RESPONSÁVEL PELA ATUALIZAÇÃO AUTOMÁTICA -->
    <?php if ($view !== 'config'): ?>
    <meta http-equiv="refresh" content="30">
    <?php endif; ?>
    
    <title>Painel de Controle | IP Monitor</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root { --primary: #4e73df; --success: #1cc88a; --info: #36b9cc; --warning: #f6c23e; --danger: #e74a3b; --dark: #5a5c69; --light: #f8f9fc; --sidebar-width: 280px; }
        * { box-sizing: border-box; }
        body { font-family: 'Nunito', sans-serif; background-color: #f4f6f9; margin: 0; color: #333; display: flex; min-height: 100vh; }
        .sidebar { width: var(--sidebar-width ); background: linear-gradient(180deg, #4e73df 10%, #224abe 100%); height: 100vh; position: fixed; left: 0; top: 0; color: white; padding: 25px; z-index: 1000; box-shadow: 4px 0 10px rgba(0,0,0,0.1); }
        .sidebar h3 { font-size: 1.5rem; margin-bottom: 30px; display: flex; align-items: center; gap: 10px; }
        .sidebar a { display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,0.8); text-decoration: none; padding: 15px; margin-bottom: 8px; border-radius: 8px; transition: all 0.3s; font-weight: 500; }
        .sidebar a:hover, .sidebar a.active { background: rgba(255,255,255,0.2); color: white; transform: translateX(5px); }
        .main-content { flex: 1; margin-left: var(--sidebar-width); padding: 40px; width: calc(100% - var(--sidebar-width)); }
        .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 35px; border-bottom: 1px solid #ddd; padding-bottom: 20px; }
        .header h1 { margin: 0; color: #2c3e50; font-size: 2rem; }
        .card-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 25px; margin-bottom: 40px; }
        .stat-box { background: white; padding: 25px; border-radius: 12px; box-shadow: 0 5px 15px rgba(0,0,0,0.05); border-left: 6px solid var(--primary); }
        .stat-label { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; color: var(--primary); margin-bottom: 10px; letter-spacing: 1px; }
        .stat-value { font-size: 2rem; font-weight: 800; color: #444; }
        .table-container { background: white; border-radius: 12px; box-shadow: 0 5px 15px rgba(0,0,0,0.05); overflow-x: auto; margin-bottom: 30px; }
        table { width: 100%; border-collapse: collapse; min-width: 900px; }
        th { background-color: #f8f9fc; color: #4e73df; text-align: left; padding: 18px; font-size: 0.9rem; font-weight: 700; border-bottom: 2px solid #e3e6f0; }
        td { padding: 18px; border-bottom: 1px solid #f0f0f0; font-size: 0.95rem; vertical-align: middle; }
        td.ua-cell { max-width: 250px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.85rem; color: #666; }
        .btn-danger { background: var(--danger); color: white; border: none; padding: 12px 20px; border-radius: 8px; cursor: pointer; font-weight: 700; transition: 0.3s; }
        .btn-success { background: var(--success); color: white; border: none; padding: 12px 20px; border-radius: 8px; cursor: pointer; font-weight: 700; text-decoration: none; display: inline-block; }
        input[type="text"] { width: 100%; padding: 15px; margin: 15px 0; border: 2px solid #e3e6f0; border-radius: 8px; font-size: 1rem; }
    </style>
</head>
<body>
    <div class="sidebar">
        <h3><i class="fas fa-shield-alt"></i> <span>IP Admin</span></h3>
        <hr style="opacity: 0.1; margin-bottom: 20px;">
        <a href="?view=dashboard" class="<?php echo $view == 'dashboard' ? 'active' : ''; ?>"><i class="fas fa-tachometer-alt"></i> <span>Dashboard</span></a>
        <a href="?view=logs" class="<?php echo $view == 'logs' ? 'active' : ''; ?>"><i class="fas fa-users"></i> <span>Logs de Acesso</span></a>
        <a href="?view=blocks" class="<?php echo $view == 'blocks' ? 'active' : ''; ?>"><i class="fas fa-robot"></i> <span>Bots Bloqueados</span></a>
        <a href="?view=config" class="<?php echo $view == 'config' ? 'active' : ''; ?>"><i class="fas fa-cog"></i> <span>Configurações</span></a>
    </div>

    <div class="main-content">
        <div class="header">
            <h1><?php echo ucfirst($view == 'logs' ? 'Logs de Acesso' : ($view == 'blocks' ? 'Bots Bloqueados' : $view)); ?></h1>
            <?php if ($view != 'config'): ?>
                <a href="?export=csv" class="btn-success"><i class="fas fa-file-export"></i> Exportar CSV</a>
            <?php endif; ?>
        </div>
        
        <?php if ($view == 'dashboard' || $view == 'logs' || $view == 'blocks'): ?>
            <div class="card-stats">
                <div class="stat-box">
                    <div class="stat-label">Visitantes Únicos</div>
                    <div class="stat-value"><?php echo $total_acessos; ?></div>
                </div>
                <div class="stat-box" style="border-left-color: var(--danger)">
                    <div class="stat-label">Bots Bloqueados</div>
                    <div class="stat-value"><?php echo $total_blocks; ?></div>
                </div>
                <div class="stat-box" style="border-left-color: var(--warning)">
                    <div class="stat-label">Limpar Dados</div>
                    <form method="POST" onsubmit="return confirm('Tem certeza que deseja apagar os logs selecionados?')">
                        <?php if($view == 'blocks'): ?>
                            <button type="submit" name="zerar_blocks" class="btn-danger"><i class="fas fa-robot"></i> Limpar Bots</button>
                        <?php else: ?>
                            <button type="submit" name="zerar_logs" class="btn-danger"><i class="fas fa-users"></i> Limpar Acessos</button>
                        <?php endif; ?>
                    </form>
                </div>
            </div>
        <?php endif; ?>

        <div class="table-container">
            <?php if ($view == 'dashboard' || $view == 'logs'): ?>
                <table>
                    <thead>
                        <tr><th>Data/Hora</th><th>IP</th><th>Localização</th><th>País</th><th>Navegador</th></tr>
                    </thead>
                    <tbody>
                        <?php if (empty($logs)): ?>
                            <tr><td colspan="5" style="text-align: center; padding: 60px;">Sem registros de acesso.</td></tr>
                        <?php else: foreach ($logs as $log): ?>
                            <tr>
                                <td><?php echo $log['date']; ?></td>
                                <td style="font-family: monospace; font-weight: 700; color: var(--primary);"><?php echo $log['ip']; ?></td>
                                <td><?php echo htmlspecialchars($log['city'] . ', ' . $log['state']); ?></td>
                                <td><?php echo htmlspecialchars($log['country']); ?></td>
                                <td class="ua-cell" title="<?php echo htmlspecialchars($log['browser']); ?>"><?php echo htmlspecialchars($log['browser']); ?></td>
                            </tr>
                        <?php endforeach; endif; ?>
                    </tbody>
                </table>
            <?php elseif ($view == 'blocks'): ?>
                <table>
                    <thead><tr><th>Data/Hora</th><th>IP do Bot</th><th>Motivo/Tipo</th><th>User-Agent</th></tr></thead>
                    <tbody>
                        <?php if (empty($blocks)): ?><tr><td colspan="4" style="text-align: center; padding: 60px;">Nenhum bot bloqueado ainda.</td></tr>
                        <?php else: foreach ($blocks as $block): ?>
                            <tr>
                                <td><?php echo $block['date']; ?></td>
                                <td style="font-family: monospace; font-weight: 700; color: var(--danger);"><?php echo $block['ip']; ?></td>
                                <td><span class="badge badge-bot"><?php echo strtoupper($block['bot']); ?></span></td>
                                <td class="ua-cell" title="<?php echo htmlspecialchars($block['ua']); ?>"><?php echo htmlspecialchars($block['ua']); ?></td>
                            </tr>
                        <?php endforeach; endif; ?>
                    </tbody>
                </table>
            <?php elseif ($view == 'config'): ?>
                <div class="table-container" style="padding: 40px;">
                    <h4><i class="fas fa-info-circle"></i> Configurações do Sistema</h4>
                    <p>Gerencie seu token da API ipinfo.io para obter os dados de geolocalização.</p>
                    <form method="POST">
                        <label>Token da API:</label>
                        <input type="text" name="api_token" value="<?php echo htmlspecialchars($config_token ?? ''); ?>" required>
                        <button type="submit" name="save_token" class="btn-success"><i class="fas fa-save"></i> Salvar Token</button>
                    </form>
                </div>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>