diff --git a/create.php b/create.php index becebae..7d2ec56 100644 --- a/create.php +++ b/create.php @@ -114,6 +114,34 @@ $error = $_GET['error'] ?? ''; > +
+ + Linux user accounts to create on this VM (e.g. jdoe, admin). + +
+ +
+ + Which users should have sudo access (e.g. admin). + +
+ diff --git a/netbox_integration/netbox_api.php b/netbox_integration/netbox_api.php index 7d9be59..0d9da78 100755 --- a/netbox_integration/netbox_api.php +++ b/netbox_integration/netbox_api.php @@ -119,6 +119,18 @@ class NetBoxClient { 'description' => $params['description'] ?? '', ]; + // Custom fields: usernames and sudo_usernames + $cf = []; + if (!empty($params['usernames'])) { + $cf['usernames'] = $params['usernames']; + } + if (!empty($params['sudo_usernames'])) { + $cf['sudo_usernames'] = $params['sudo_usernames']; + } + if (!empty($cf)) { + $payload['custom_fields'] = $cf; + } + // Tag lookup for domain — tags must be numeric IDs in the NetBox API if (!empty($params['domain'])) { $tag = $this->findTag($params['domain']); diff --git a/requests.php b/requests.php index 60ecc90..57bdc7d 100644 --- a/requests.php +++ b/requests.php @@ -13,7 +13,7 @@ $totalPages = max(1, (int) ceil($total / $perPage)); if ($page > $totalPages) $page = $totalPages; $stmt = db()->prepare( - 'SELECT id, vm_name, domain_name, size, vcpus, ram_gb, disk_gb, status, description, created_at, netbox_device_id + 'SELECT id, vm_name, domain_name, size, vcpus, ram_gb, disk_gb, status, description, usernames, sudo_usernames, created_at, netbox_device_id FROM vm_requests ORDER BY created_at DESC LIMIT :limit OFFSET :offset' @@ -88,6 +88,14 @@ $recentRequests = $stmt->fetchAll(); + +
+ Users: + + | sudo: + +
+ diff --git a/send.php b/send.php index faa6d12..2a84be4 100755 --- a/send.php +++ b/send.php @@ -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; diff --git a/setup_database.sql b/setup_database.sql index d68b63f..ab505c0 100755 --- a/setup_database.sql +++ b/setup_database.sql @@ -20,6 +20,8 @@ CREATE TABLE IF NOT EXISTS vm_requests ( requested_by VARCHAR(50) NOT NULL, status ENUM('queued', 'building', 'ready', 'failed', 'deployed_to_netbox', 'cancelled') NOT NULL DEFAULT 'queued', description VARCHAR(500) DEFAULT NULL, + usernames VARCHAR(500) DEFAULT NULL, + sudo_usernames VARCHAR(500) DEFAULT NULL, netbox_device_id INT UNSIGNED NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY vm_requests_vm_name_unique (vm_name),