Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/viewlogs.php

<?php
session_start();

// Load passcode
$passcode = require('/usr/home/beeson/MathXpert/logs/passcode.php');

// Authentication check
if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) {
    if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["passcode"])) {
        if ($_POST["passcode"] === $passcode) {
            $_SESSION['authenticated'] = true;
            header("Location: viewlogs.php"); // Reload to remove passcode from URL
            exit;
        } else {
            echo "Invalid passcode!";
        }
    }
    ?>
    <form method="POST">
        <input type="password" name="passcode" placeholder="Enter passcode">
        <button type="submit">Login</button>
    </form>
    <?php
    exit;
}

// Database connection
$dbFile = "/usr/home/beeson/MathXpert/logs/userlog.db";
try {
    $pdo = new PDO("sqlite:$dbFile");
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Fetch logs
    $stmt = $pdo->query("SELECT ip_address, first_use, last_active, country, region, city, isp FROM UserLogs ORDER BY last_active DESC");
    $logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}

// Display logs
echo "<h2>User Access Logs</h2>";
echo "<table border='1'>";
echo "<tr><th>IP Address</th><th>First Use</th><th>Last Active</th><th>Country</th><th>Region</th><th>City</th><th>ISP</th></tr>";

foreach ($logs as $log) {
    echo "<tr>";
    echo "<td>{$log['ip_address']}</td>";
    echo "<td>{$log['first_use']}</td>";
    echo "<td>{$log['last_active']}</td>";
    echo "<td>{$log['country']}</td>";
    echo "<td>{$log['region']}</td>";
    echo "<td>{$log['city']}</td>";
    echo "<td>{$log['isp']}</td>";
    echo "</tr>";
}
echo "</table>";
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists