<?php
session_start();

include '../config.php';


$password = $Passwort_fuer_Login_Bereich;


$error_message = "";


if (isset($_POST['password'])) {
    
    if ($_POST['password'] === $password) {
        $_SESSION['loggedin'] = true;
    } else {
        
        $error_message = '<div style="font-family: Verdana; color: red; border: 1px solid red; padding: 10px; border-radius: 5px; margin: 0 auto 20px auto; text-align: center; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); max-width: 90%; width: 300px;line-height:23px;">Falsches Passwort. Bitte versuchen Sie es erneut.</div>';
    }
}


if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
    
    $logFile = 'log/ip_log.txt';

    
    if (file_exists($logFile)) {
        
        $logData = file_get_contents($logFile);
        
       
        if (trim($logData) === "") {
            echo '<div style="font-family: Verdana; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin: 20px auto; text-align: center; border: 1px solid #ccc; background-color: #f9f9f9; max-width: 90%; width: 300px;">Keine Eintr&auml;ge vorhanden.</div>';
        } else {
            
            echo '<div style="font-family: Verdana; font-size:15px; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin: 20px auto; text-align: center; border: 1px solid #ccc; background-color: #f9f9f9; max-width: 90%; width: 80%;"><pre>' . htmlspecialchars($logData) . '</pre></div>';
        }
    } else {
        
        echo '<div style="font-family: Verdana; color: red; border: 1px solid red; padding: 10px; border-radius: 5px; margin: 20px auto; text-align: center; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); max-width: 90%; width: 300px;">Die Logdatei existiert nicht.</div>';
    }

   
    echo '<style> a:link, a:visited {
color: #00598D;
text-decoration: none;
font-weight: bold;
}

a:hover {
text-decoration: underline;
} </style>';
    

$file = 'log/ip_log.txt'; 


if (file_exists($file)) {
    
    $fileSize = filesize($file);
    
    
    
    $fileSizeKB = $fileSize / 1024;
    
   
    $fileSizeMB = $fileSize / (1024 * 1024);
    
   
    
    
    
} else {
    
    echo '';
}
    echo '<br /><p style="font-family: Verdana; font-size:19px; padding: 10px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin: 20px auto; text-align: center; border: 1px solid #ccc; max-width: 90%; width: 200px;">
        <a href="delete_logfile.php" style="color: #007BFF; transition: text-decoration 0.3s; display: inline-block; text-align: center;">Log-Datei leeren</a><br /><span style="font-size:14px;line-height:30px;">Dateigr&ouml;&szlig;e: ' . $fileSize . ' Bytes</span>
    </p><br />';
    


    
    
    echo '<p style="font-family: Verdana; padding: 10px; background-color: #4CAF50; color: white; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin: 20px auto; text-align: center; border: none; max-width: 90%; width: 100px;">
        <a href="logout.php" style="color: white; text-decoration: none;">Ausloggen</a>
    </p>';
} else {
   
    passwordForm($error_message);
}


function passwordForm($error_message) {
    echo '<div style="font-family: Verdana; display: flex; justify-content: center; align-items: center; height: 90vh; flex-direction: column; padding: 0 20px;">';
    
    
    if (!empty($error_message)) {
        echo $error_message;
    }
    
    echo '<form method="post" style="background-color: #f2f2f2; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; max-width: 100%; width: 300px;">';
    echo '<h2 style="margin-bottom: 20px;">Log-Datei &ouml;ffnen</h2>';
    echo '<label for="password" style="display: block; font-weight: bold; margin-bottom: 10px;">Passwort:</label>';
    
    
    echo '<div style="position: relative; display: flex; align-items: center; justify-content: center;">';
    echo '<input type="password" name="password" id="password" style="padding: 10px; width: calc(100% - 40px); margin-bottom: 20px; border: 1px solid #ccc; border-radius: 5px;" required>';
    
    echo '</div>';
    
    echo '<input type="submit" value="Anmelden" style="padding: 10px 20px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 16px;">';
    echo '</form>';
    
    echo '<!-- Dieser Copyrighthinweis darf NICHT entfernt werden. -->

<div style="display: flex;justify-content: center;align-items: center;padding-right:5%;padding-left:5%;margin-top:20px;">

<div style="border: 1px solid #ccc; margin: 0;box-sizing: border-box;display: inline-block;line-height: 0.3;vertical-align: top;padding-bottom:7.5px;padding-right:5px;padding-left:5px;">
						<br /><br /><a href="https://www.kontaktformular.com" title="kontaktformular.com" style="text-decoration: none;color:#000000;font-size:13.5px;line-height: 20px;" target="_blank">&copy; kontaktformular.com</a>
</div>
</div>
<!-- Dieser Copyrighthinweis darf NICHT entfernt werden. -->'; 
echo '</div>';
    
}
?><!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    
</head>


</html>