Add usernames and sudo_usernames fields to VM request form

- DB: add usernames/sudo_usernames columns to vm_requests table
- create.php: add form inputs for usernames and sudo_usernames
- send.php: capture, validate, and store both fields in DB
- netbox_integration/netbox_api.php: pass custom_fields to NetBox VM API
- requests.php: show usernames/sudo_usernames in request list
This commit is contained in:
alex
2026-05-09 23:57:36 +02:00
parent d629689473
commit 8c069ee82a
5 changed files with 59 additions and 3 deletions
+8 -2
View File
@@ -24,6 +24,8 @@ $vmName = trim((string) ($_POST['VM_Name'] ?? ''));
$size = trim((string) ($_POST['size'] ?? ''));
$domain = trim((string) ($_POST['domain'] ?? ''));
$description = trim((string) ($_POST['description'] ?? ''));
$usernames = trim((string) ($_POST['usernames'] ?? ''));
$sudoUsernames = trim((string) ($_POST['sudo_usernames'] ?? ''));
$errors = [];
if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9._-]{1,63}$/', $vmName)) {
@@ -45,9 +47,9 @@ $resources = $sizeMapping[$size];
try {
$stmt = db()->prepare(
'INSERT INTO vm_requests
(vm_name, domain_name, size, vcpus, ram_gb, disk_gb, requested_by, status, description)
(vm_name, domain_name, size, vcpus, ram_gb, disk_gb, requested_by, status, description, usernames, sudo_usernames)
VALUES
(:vm_name, :domain_name, :size, :vcpus, :ram_gb, :disk_gb, :requested_by, :status, :description)'
(:vm_name, :domain_name, :size, :vcpus, :ram_gb, :disk_gb, :requested_by, :status, :description, :usernames, :sudo_usernames)'
);
$stmt->execute([
'vm_name' => $vmName,
@@ -59,6 +61,8 @@ try {
'requested_by' => $_SESSION['user'] ?? 'unknown',
'status' => 'queued',
'description' => $description,
'usernames' => $usernames,
'sudo_usernames' => $sudoUsernames,
]);
// Get the inserted request ID
@@ -82,6 +86,8 @@ try {
'disk_gb' => $resources['disk_gb'],
'domain' => $domain,
'description' => $description ?: ('Requested by ' . ($_SESSION['user'] ?? 'unknown')),
'usernames' => $usernames,
'sudo_usernames' => $sudoUsernames,
]);
$netboxVmId = $vm['id'] ?? null;