Adjust PHP script 'Files/opcache_clear.php'.

This commit is contained in:
2025-07-18 12:04:29 +02:00
parent d9388f38d1
commit bca10b8c09
2 changed files with 103 additions and 4 deletions

View File

@ -43,6 +43,8 @@ if (isset($_GET['logout'])) {
h1 { font-size: 1.4em; }
input[type="text"], input[type="password"] { width: 100%; padding: 0.5em; margin-top: 0.3em; }
input[type="submit"] { padding: 0.6em 1.2em; margin-top: 1em; }
.button-block { margin-bottom: 1em; }
.separator { border-top: 1px solid #ccc; margin: 1.5em 0; }
.status { margin-top: 1em; padding: 1em; background: #eef; border-left: 4px solid #99f; }
.error { color: red; }
.logout { float: right; }
@ -63,10 +65,6 @@ if (isset($_GET['logout'])) {
<a href="?logout=1">Abmelden</a>
</div>
<h1>OPCache-Verwaltung</h1>
<form method="post">
<input type="submit" name="clear" value="OPCache jetzt leeren">
</form>
<div class="status">
<?php
if (function_exists('opcache_get_status') && function_exists('opcache_reset')) {
@ -75,7 +73,14 @@ if (isset($_GET['logout'])) {
echo " OPCache ist installiert, aber aktuell nicht aktiviert.";
} else {
echo "✅ OPCache ist aktiviert.<br>";
// Zeige Button nur wenn aktiv
echo '<form method="post" class="button-block">';
echo '<input type="submit" name="clear" value="OPCache jetzt leeren">';
echo '</form>';
if (isset($_POST['clear'])) {
echo '<div class="separator"></div>';
if (opcache_reset()) {
echo "✅ OPCache wurde erfolgreich geleert.";
} else {

View File

@ -0,0 +1,94 @@
<?php
// -------------------- KONFIGURATION --------------------
$valid_user = 'admin';
$valid_pass = 'supergeheim';
$allowed_ips = []; // z.B. ['127.0.0.1', '192.168.1.100']; leer = keine Prüfung
session_start();
// -------------------- IP-WHITELIST --------------------
$remote_ip = $_SERVER['REMOTE_ADDR'];
if (!empty($allowed_ips) && !in_array($remote_ip, $allowed_ips)) {
http_response_code(403);
exit("Zugriff verweigert für IP: $remote_ip");
}
// -------------------- LOGIN VERARBEITUNG --------------------
if (isset($_POST['username'], $_POST['password'])) {
if ($_POST['username'] === $valid_user && $_POST['password'] === $valid_pass) {
$_SESSION['authenticated'] = true;
} else {
$error = "Falscher Benutzername oder Passwort.";
}
}
// -------------------- LOGOUT --------------------
if (isset($_GET['logout'])) {
session_destroy();
header("Location: " . strtok($_SERVER["REQUEST_URI"], '?'));
exit;
}
// -------------------- HTML-AUSGABE --------------------
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>OPCache-Verwaltung</title>
<style>
body { font-family: sans-serif; background: #f4f4f4; padding: 2em; }
.box { background: white; padding: 1.5em; max-width: 500px; margin: auto; border-radius: 10px; box-shadow: 0 0 10px #ccc; }
h1 { font-size: 1.4em; }
input[type="text"], input[type="password"] { width: 100%; padding: 0.5em; margin-top: 0.3em; }
input[type="submit"] { padding: 0.6em 1.2em; margin-top: 1em; }
.status { margin-top: 1em; padding: 1em; background: #eef; border-left: 4px solid #99f; }
.error { color: red; }
.logout { float: right; }
</style>
</head>
<body>
<div class="box">
<?php if (!isset($_SESSION['authenticated'])): ?>
<h1>Login zur OPCache-Verwaltung</h1>
<?php if (!empty($error)): ?><p class="error"><?= htmlspecialchars($error) ?></p><?php endif; ?>
<form method="post">
<label>Benutzername:<br><input type="text" name="username" required></label><br><br>
<label>Passwort:<br><input type="password" name="password" required></label><br>
<input type="submit" value="Anmelden">
</form>
<?php else: ?>
<div class="logout">
<a href="?logout=1">Abmelden</a>
</div>
<h1>OPCache-Verwaltung</h1>
<form method="post">
<input type="submit" name="clear" value="OPCache jetzt leeren">
</form>
<div class="status">
<?php
if (function_exists('opcache_get_status') && function_exists('opcache_reset')) {
$status = @opcache_get_status(false);
if (!$status || empty($status['opcache_enabled'])) {
echo " OPCache ist installiert, aber aktuell nicht aktiviert.";
} else {
echo "✅ OPCache ist aktiviert.<br>";
if (isset($_POST['clear'])) {
if (opcache_reset()) {
echo "✅ OPCache wurde erfolgreich geleert.";
} else {
echo "⚠️ Fehler beim Leeren des OPCache.";
}
}
}
} else {
echo "❌ OPCache ist auf diesem Server nicht verfügbar.";
}
?>
</div>
<?php endif; ?>
</div>
</body>
</html>