ttrying to fix csv import and user creation per csv

This commit is contained in:
taarly 2025-12-13 15:34:55 +01:00
parent 2fd2bb3630
commit 9bc6b8d701
4 changed files with 71 additions and 1 deletions

View File

@ -102,6 +102,11 @@ Die grundlegende Funktionalität wurde mit folgenden Komponenten implementiert:
- `scripts/powershell/create_user.ps1`: PowerShell-Skript zum Erstellen eines einzelnen Benutzers. - `scripts/powershell/create_user.ps1`: PowerShell-Skript zum Erstellen eines einzelnen Benutzers.
- `scripts/powershell/create_users_csv.ps1`: PowerShell-Skript zum Erstellen mehrerer Benutzer aus CSV. - `scripts/powershell/create_users_csv.ps1`: PowerShell-Skript zum Erstellen mehrerer Benutzer aus CSV.
- `scripts/powershell/check_environment.ps1`: Prüft, ob `ActiveDirectory`-Modul vorhanden ist und zeigt die ausführende Identität an.
API endpoints:
- `public/api/powershell_check.php`: Ruft `check_environment.ps1` auf und gibt ein JSON-Objekt mit `actor`, `module_installed`, `can_new_aduser` zurück.
Bitte testen zuerst mit `powershell.dry_run = true` und prüfen sie die resultierenden Meldungen in UI. Bitte testen zuerst mit `powershell.dry_run = true` und prüfen sie die resultierenden Meldungen in UI.

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
session_start();
// Load config
$config = require __DIR__ . '/../../config/config.php';
// Simple login check (same as index.php)
$sessionKey = $config['security']['session_key_user'] ?? 'admin_user';
if (!isset($_SESSION[$sessionKey])) {
header('Content-Type: application/json');
echo json_encode(['success' => false, 'message' => 'Not authenticated']);
exit;
}
$scriptDir = $config['powershell']['script_dir'] ?? __DIR__ . '/../../scripts/powershell';
$script = $scriptDir . DIRECTORY_SEPARATOR . 'check_environment.ps1';
$exe = $config['powershell']['exe'] ?? 'powershell';
$executionPolicy = $config['powershell']['execution_policy'] ?? 'Bypass';
if (!file_exists($script)) {
header('Content-Type: application/json');
echo json_encode(['success' => false, 'message' => 'Script not found: ' . $script]);
exit;
}
$cmd = sprintf('%s -NoProfile -NonInteractive -ExecutionPolicy %s -File "%s"', $exe, $executionPolicy, $script);
$output = [];
$returnVar = null;
exec($cmd . ' 2>&1', $output, $returnVar);
$json = implode("\n", $output);
// Attempt to parse JSON
$decoded = json_decode($json, true);
if ($decoded === null) {
header('Content-Type: application/json');
echo json_encode(['success' => false, 'message' => 'Invalid JSON output', 'raw' => $json]);
exit;
}
header('Content-Type: application/json');
echo json_encode($decoded);
exit;

View File

@ -0,0 +1,17 @@
# Returns JSON with information about the environment and AD module availability
Try {
$actor = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
} Catch {
$actor = $null
}
# Does the ActiveDirectory module exist?
$module = Get-Module -ListAvailable -Name ActiveDirectory -ErrorAction SilentlyContinue
$hasModule = $module -ne $null
# Is New-ADUser available?
$canNewAdUser = (Get-Command New-ADUser -ErrorAction SilentlyContinue) -ne $null
$output = @{ success = $true; actor = $actor; module_installed = $hasModule; can_new_aduser = $canNewAdUser }
Write-Output ($output | ConvertTo-Json -Compress)
exit 0

View File

@ -13,7 +13,10 @@ try {
} }
$csvFile = [string]$meta.input_file $csvFile = [string]$meta.input_file
$delimiter = [string]($meta.delimiter ?? ',') # PowerShell 5.1 doesn't support the null-coalescing operator '??'.
# Use an explicit check here to set the default delimiter.
$delimiter = [string]$meta.delimiter
if ([string]::IsNullOrWhiteSpace($delimiter)) { $delimiter = ',' }
$hasHeader = [bool]($meta.has_header -as [bool]) $hasHeader = [bool]($meta.has_header -as [bool])
$dryRun = [bool]($meta.dry_run -as [bool]) $dryRun = [bool]($meta.dry_run -as [bool])