Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] -
## [unreleased] -

### Added

- Enrich computer inventory builder templates with all inventory schema fields (bios, operatingsystem, ...).

### Fixed

- Empty sections no longer fall back to the default template when the DB columns are null.
- Avoid multiple scrollbars on the builder mapping edition view.
53 changes: 53 additions & 0 deletions builder/computer/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Computer Builder Data Templates

These JSON files are the default templates used when creating a `ComputerBuilderMapping`.
Each file corresponds to a section of the GLPI Inventory Format schema.

Fields containing `{{ ldap.attributeName }}` are replaced at sync time with the value
of the corresponding LDAP attribute. Empty fields (`""`) are stripped from the final
inventory payload and can be filled in with an LDAP placeholder or a static value.

## bios.json

Reference: [inventory.schema.json — bios](https://github.com/glpi-project/inventory_format/blob/89f177aa93595bdff01c3f670e32edd11ace0524/inventory.schema.json#L166-L247)

| Field | Description | Notes |
|-------|-------------|-------|
| `ssn` | System serial number | |
| `smanufacturer` | System manufacturer | |
| `smodel` | System model | |
| `assettag` | Asset tag | |
| `bdate` | BIOS release date | Format: `dateordatetime` (e.g. `2023-10-15`) |
| `bmanufacturer` | BIOS manufacturer | |
| `bversion` | BIOS version | |
| `mmanufacturer` | Motherboard manufacturer | |
| `mmodel` | Motherboard model | |
| `msn` | Motherboard serial number | |
| `skunumber` | SKU number | |
| `biosserial` | BIOS serial number | |
| `enclosureserial` | Chassis serial number | |
| `secure_boot` | Secure boot status | Accepted values: `enabled`, `disabled`, `unsupported` |

## operatingsystem.json

Reference: [inventory.schema.json — operatingsystem](https://github.com/glpi-project/inventory_format/blob/89f177aa93595bdff01c3f670e32edd11ace0524/inventory.schema.json#L1312-L1436)

| Field | Description | Notes |
|-------|-------------|-------|
| `name` | OS distributor name | |
| `version` | OS release version | |
| `arch` | Processor architecture | e.g. `x86_64` |
| `boot_time` | Last boot timestamp | Format: `datetime` |
| `dns_domain` | DNS domain | |
| `fqdn` | Fully qualified domain name | |
| `full_name` | Full OS description | e.g. `Fedora release 25 (Twenty Five)` |
| `hostid` | Unique host identifier | |
| `install_date` | OS installation date | Format: `dateordatetime` |
| `kernel_name` | Kernel type | e.g. `linux` |
| `kernel_version` | Kernel version | e.g. `4.11.3-200.fc25.x86_64` |
| `ssh_key` | SSH public key | |
| `service_pack` | Service pack version | |

> **Note:** The `timezone` field (object with `name` and `offset`) is intentionally
> omitted from the default template. It can be added manually in the mapping if needed,
> but both `name` and `offset` must be set — a partial timezone object is invalid.
16 changes: 16 additions & 0 deletions builder/computer/data/bios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"ssn": "{{ ldap.serialNumber }}",
"smanufacturer": "",
"smodel": "",
"assettag": "",
"bdate": "",
"bmanufacturer": "",
"bversion": "",
"mmanufacturer": "",
"mmodel": "",
"msn": "",
"skunumber": "",
"biosserial": "",
"enclosureserial": "",
"secure_boot": ""
}
Comment thread
f2cmb marked this conversation as resolved.
15 changes: 15 additions & 0 deletions builder/computer/data/cpus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"core": "",
"description": "",
"familynumber": "",
"id": "",
"manufacturer": "",
"model": "",
"name": "",
"serial": "",
"speed": "",
"stepping": "",
"thread": ""
}
]
14 changes: 14 additions & 0 deletions builder/computer/data/drives.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"description": "",
"filesystem": "",
"free": "",
"label": "",
"letter": "",
"serial": "",
"systemdrive": "",
"total": "",
"type": "",
"volumn": ""
}
]
14 changes: 14 additions & 0 deletions builder/computer/data/memories.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"capacity": "",
"caption": "",
"description": "",
"manufacturer": "",
"memorycorrection": "",
"model": "",
"numslots": "",
"serialnumber": "",
"speed": "",
"type": ""
}
]
11 changes: 11 additions & 0 deletions builder/computer/data/networks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"description": "",
"mac": "{{ ldap.macAddress }}",
"pciid": "",
"pnpdeviceid": "",
"status": "",
"type": "",
"virtualdev": ""
}
]
15 changes: 15 additions & 0 deletions builder/computer/data/operatingsystem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "{{ ldap.operatingSystem }}",
"version": "{{ ldap.operatingSystemVersion }}",
"arch": "",
"boot_time": "",
"dns_domain": "",
"fqdn": "",
"full_name": "",
"hostid": "",
"install_date": "",
"kernel_name": "",
"kernel_version": "",
"ssh_key": "",
"service_pack": ""
}
Comment thread
f2cmb marked this conversation as resolved.
13 changes: 13 additions & 0 deletions builder/computer/data/storages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"description": "",
"disksize": "",
"firmware": "",
"interface": "",
"manufacturer": "",
"model": "",
"name": "",
"serial": "",
"type": ""
}
]
7 changes: 3 additions & 4 deletions front/authldapsyncfilter.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
$relation = new AuthLdapSyncFilter();

if (isset($_POST["add"])) {
/** @var array<string, mixed> $input ($_POST keys are always strings) */
$input = $_POST;
$relation->check(-1, CREATE, $input); // @phpstan-ignore argument.type ($_POST keys are always strings)
if ($input !== null) {
$relation->add($input);
}
$relation->check(-1, CREATE, $input);
$relation->add($input);
}

Html::back();
19 changes: 18 additions & 1 deletion src/ComputerBuilderMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected static function getTemplateBasePath(): string

public static function getSectionNames(): array
{
return ['main', 'hardware'];
return ['main', 'hardware', 'bios', 'operatingsystem', 'networks', 'cpus', 'memories', 'drives', 'storages'];
}

public static function install(Migration $migration): void
Expand All @@ -81,6 +81,13 @@ public static function install(Migration $migration): void
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
`main` text,
`hardware` text,
`bios` text,
`operatingsystem` text,
`networks` text,
`cpus` text,
`memories` text,
`drives` text,
`storages` text,
`date_creation` timestamp NULL DEFAULT NULL,
`date_mod` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
Expand All @@ -89,6 +96,16 @@ public static function install(Migration $migration): void
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC";

$DB->doQuery($query);
} else {
// Add new columns for existing installations
$migration->addField($table, 'bios', 'text', ['after' => 'hardware']);
$migration->addField($table, 'operatingsystem', 'text', ['after' => 'bios']);
$migration->addField($table, 'networks', 'text', ['after' => 'operatingsystem']);
$migration->addField($table, 'cpus', 'text', ['after' => 'networks']);
$migration->addField($table, 'memories', 'text', ['after' => 'cpus']);
$migration->addField($table, 'drives', 'text', ['after' => 'memories']);
$migration->addField($table, 'storages', 'text', ['after' => 'drives']);
$migration->executeMigration();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/SyncFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ public function showBuilderMappingTab(): void
}

$content = $builder->getSection($section_name);
if ($content === []) {
$content = $builder_itemtype::loadDefaultTemplate($section_name);
}

$sections[] = [
'name' => $section_name,
'content' => json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
Expand Down
22 changes: 18 additions & 4 deletions templates/builder_mapping.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
{{ __('Reset', 'advancedldap') }}
</button>
</div>
<div id="editor-{{ section.name }}" style="height: 300px;"></div>
<div id="editor-{{ section.name }}" style="min-height: 80px; border: 1px solid var(--tblr-border-color); border-radius: var(--tblr-border-radius);"></div>
<input type="hidden" name="sections[{{ section.name }}]" id="input-{{ section.name }}" value="{{ section.content|e('html_attr') }}">
</div>
{% endfor %}
Expand Down Expand Up @@ -111,13 +111,27 @@
window.GLPI.Monaco.createEditor(containerId, 'twig', section.content, completions).then((monaco) => {
editors[section.name] = monaco;

const container = document.getElementById(containerId);

monaco.editor.updateOptions({
scrollBeyondLastLine: false,
scrollbar: { vertical: 'hidden', alwaysConsumeMouseWheel: false },
automaticLayout: false,
});

const updateHeight = () => {
const height = monaco.editor.getContentHeight();
container.style.height = `${height}px`;
monaco.editor.layout({ width: container.offsetWidth, height });
};

monaco.editor.onDidContentSizeChange(updateHeight);
updateHeight();

// Update hidden input on change
monaco.editor.onDidChangeModelContent(() => {
document.getElementById(inputId).value = monaco.editor.getValue();
});

// Force layout after creation
monaco.editor.layout();
});
});
});
Expand Down
Loading