149 lines
6.5 KiB
PHP
149 lines
6.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 3) . '/src/App/bootstrap.php';
|
|
|
|
use App\ConfigLoader;
|
|
use App\LdapProvisioner;
|
|
|
|
$projectRoot = dirname(__DIR__, 3);
|
|
$config = ConfigLoader::load($projectRoot, 'registration');
|
|
$ldap = new LdapProvisioner($config);
|
|
$diagnostics = $ldap->diagnostics();
|
|
|
|
$serviceResult = $ldap->testServiceBind();
|
|
$messages = [];
|
|
$errors = [];
|
|
$form = ['username' => '', 'password' => '', 'new_password' => ''];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$action = (string) ($_POST['action'] ?? '');
|
|
$form['username'] = trim((string) ($_POST['username'] ?? ''));
|
|
$form['password'] = (string) ($_POST['password'] ?? '');
|
|
$form['new_password'] = (string) ($_POST['new_password'] ?? '');
|
|
|
|
if ($form['username'] === '') {
|
|
$errors[] = 'Benutzername ist erforderlich.';
|
|
}
|
|
|
|
if ($form['password'] === '') {
|
|
$errors[] = 'Passwort ist erforderlich.';
|
|
}
|
|
|
|
if ($action === 'change-password' && strlen($form['new_password']) < 12) {
|
|
$errors[] = 'Das neue Passwort muss mindestens 12 Zeichen lang sein.';
|
|
}
|
|
|
|
if ($errors === []) {
|
|
if ($action === 'test-login') {
|
|
$result = $ldap->testUserCredentials($form['username'], $form['password']);
|
|
|
|
if ($result['success'] ?? false) {
|
|
$messages[] = $result['message'] . ' DN: ' . (string) ($result['dn'] ?? '');
|
|
} else {
|
|
$errors[] = (string) ($result['message'] ?? 'LDAP-Login fehlgeschlagen.');
|
|
}
|
|
} elseif ($action === 'change-password') {
|
|
$loginCheck = $ldap->testUserCredentials($form['username'], $form['password']);
|
|
|
|
if (!(bool) ($loginCheck['success'] ?? false)) {
|
|
$errors[] = 'Der Login mit aktuellem Passwort ist fehlgeschlagen: ' . (string) ($loginCheck['message'] ?? '');
|
|
} else {
|
|
$result = $ldap->updateUserPassword($form['username'], $form['new_password']);
|
|
|
|
if ($result['success'] ?? false) {
|
|
$messages[] = $result['message'] . ' DN: ' . (string) ($result['dn'] ?? '');
|
|
$form['password'] = '';
|
|
$form['new_password'] = '';
|
|
} else {
|
|
$errors[] = (string) ($result['message'] ?? 'Passwortänderung fehlgeschlagen.');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?><!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>LDAP-Test</title>
|
|
<link rel="stylesheet" href="/assets/auth/login.css">
|
|
</head>
|
|
<body>
|
|
<main class="login-shell">
|
|
<section class="login-panel login-panel-wide">
|
|
<div class="login-panel-top">
|
|
<p class="login-kicker">Kusche.Berlin</p>
|
|
<h1>LDAP-Test</h1>
|
|
<p class="login-copy">Diese Testseite läuft unabhängig vom eigentlichen Desktop-Login. Hier kannst du nur LDAP-Login und Passwortänderung inklusive Samba-Feldern prüfen.</p>
|
|
</div>
|
|
|
|
<div class="login-notice <?= ($serviceResult['success'] ?? false) ? 'login-notice-success' : 'login-notice-error' ?>">
|
|
<strong>Service-Bind</strong>
|
|
<p><?= htmlspecialchars((string) ($serviceResult['message'] ?? ''), ENT_QUOTES) ?></p>
|
|
</div>
|
|
|
|
<div class="login-notice login-notice-info">
|
|
<strong>Verbindungsdaten</strong>
|
|
<ul class="login-list">
|
|
<li>Host: <?= htmlspecialchars((string) ($diagnostics['host'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>Port: <?= htmlspecialchars((string) ($diagnostics['port'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>Bind-DN: <?= htmlspecialchars((string) ($diagnostics['bind_dn'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>Users-DN: <?= htmlspecialchars((string) ($diagnostics['users_dn'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>StartTLS: <?= htmlspecialchars((string) ($diagnostics['starttls'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>Gruppenmodus: <?= htmlspecialchars((string) ($diagnostics['group_assignment_mode'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>Gruppenattribut: <?= htmlspecialchars((string) ($diagnostics['group_member_attribute'] ?? ''), ENT_QUOTES) ?></li>
|
|
<li>PHP LDAP-Erweiterung: <?= htmlspecialchars((string) ($diagnostics['ldap_extension'] ?? ''), ENT_QUOTES) ?></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<?php if ($messages !== []): ?>
|
|
<div class="login-notice login-notice-success">
|
|
<strong>Ergebnis</strong>
|
|
<ul class="login-list">
|
|
<?php foreach ($messages as $message): ?>
|
|
<li><?= htmlspecialchars($message, ENT_QUOTES) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($errors !== []): ?>
|
|
<div class="login-notice login-notice-error">
|
|
<strong>Bitte prüfen</strong>
|
|
<ul class="login-list">
|
|
<?php foreach ($errors as $error): ?>
|
|
<li><?= htmlspecialchars($error, ENT_QUOTES) ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form class="login-form" method="post" action="/admin/ldap-test">
|
|
<label class="login-field">
|
|
<span>Benutzername</span>
|
|
<input type="text" name="username" value="<?= htmlspecialchars($form['username'], ENT_QUOTES) ?>" required>
|
|
</label>
|
|
|
|
<label class="login-field">
|
|
<span>Passwort</span>
|
|
<input type="password" name="password" value="" required>
|
|
</label>
|
|
|
|
<label class="login-field">
|
|
<span>Neues Passwort</span>
|
|
<input type="password" name="new_password" value="" placeholder="Nur für Passwortänderung erforderlich">
|
|
</label>
|
|
|
|
<div class="login-actions">
|
|
<button class="login-button login-button-primary" type="submit" name="action" value="test-login">Login-Test</button>
|
|
<button class="login-button login-button-secondary" type="submit" name="action" value="change-password">Neues Passwort setzen</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
</main>
|
|
</body>
|
|
</html>
|