101 lines
2.6 KiB
PHP
101 lines
2.6 KiB
PHP
<!doctype html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>AD User anlegen</title>
|
|
</head>
|
|
<body>
|
|
<h1>AD User anlegen</h1>
|
|
|
|
<form method="post" action="ad_create_user.php">
|
|
<p>
|
|
<label>Username (sAMAccountName)<br>
|
|
<input name="username" required maxlength="32">
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>Vorname<br>
|
|
<input name="vorname" required maxlength="64">
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>Nachname<br>
|
|
<input name="nachname" required maxlength="64">
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>Passwort<br>
|
|
<input name="passwort" type="password" required minlength="8" maxlength="128">
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>Benutzergruppe (Gruppenname / DN)<br>
|
|
<input name="gruppe" required maxlength="128" placeholder="z.B. 'IT-Users'">
|
|
</label>
|
|
</p>
|
|
|
|
<button type="submit">Anlegen</button>
|
|
</form>
|
|
</body>
|
|
</html>
|
|
|
|
<?php
|
|
declare(strict_types=1);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
require_once __DIR__ . '/../app/Services/PowerShellService.php';
|
|
|
|
// Minimal-Validation (zusätzlich zur PS-Validation)
|
|
$username = (string)($_POST['username'] ?? '');
|
|
$vorname = (string)($_POST['vorname'] ?? '');
|
|
$nachname = (string)($_POST['nachname'] ?? '');
|
|
$passwort = (string)($_POST['passwort'] ?? '');
|
|
$gruppe = (string)($_POST['gruppe'] ?? '');
|
|
|
|
if ($username === '' || $vorname === '' || $nachname === '' || $passwort === '' || $gruppe === '') {
|
|
http_response_code(400);
|
|
echo json_encode(['ok' => false, 'error' => 'Bitte alle Felder ausfüllen.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$ps = new PowerShellService();
|
|
|
|
$script = __DIR__ . '/../../scripts/powershell/New-AdUserFromPhp.ps1';
|
|
|
|
$res = $ps->runScript($script, [
|
|
'Username' => $username,
|
|
'Vorname' => $vorname,
|
|
'Nachname' => $nachname,
|
|
'Passwort' => $passwort,
|
|
'Benutzergruppe' => $gruppe,
|
|
], 60);
|
|
|
|
// PowerShell gibt JSON zurück
|
|
$json = $res['stdout'];
|
|
$data = json_decode($json, true);
|
|
|
|
if (!is_array($data)) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'ok' => false,
|
|
'error' => 'Ungültige Antwort von PowerShell.',
|
|
'stderr' => $res['stderr'],
|
|
'raw' => $json,
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
// Wenn PS exitCode != 0, trotzdem JSON ausgeben (enthält error)
|
|
if ($res['exitCode'] !== 0) {
|
|
http_response_code(400);
|
|
}
|
|
|
|
echo json_encode($data);
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['ok' => false, 'error' => $e->getMessage()]);
|
|
}
|