Skip to content
Draft
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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,33 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.17.0] - 2026-11-13

### Fixed

- Fix handling of additional information values in the injection form
- Fix model checks on the injection upload and the PDF report export
- Fix rights used by the model field dropdowns
- Fix CSV export of headers and of the model sample file
- Fix file name display in the PDF report header
- Fix temporary error file not being removed when its download fails
- Use the query builder for the remaining queries
- Fix models left in a deleted entity: declare their entity relation so it is checked and replaced on entity deletion, and move models already left in a deleted entity to the root entity

### Added

<<<<<<< HEAD
- Add Transifex translations link to README
- Inject generic assets, including their type, model, comment and custom fields
=======
- Make the plugin compatible with the Content Security Policy

## [2.15.13] - 2026-11-13

### Fixed

- Fix the uploaded file name being lost after the client injection upload step
- Fix models mapped to additional fields (Fields plugin) becoming inaccessible and their values being rejected on injection
- Fix entity injection failing when additional fields (Fields plugin) are mapped
>>>>>>> c784dc8 (Fix - Injection form checks and CSV exports (#717))
- Fix additional information sharing a field name across itemtypes (e.g. two device designations) overwriting each other, and show the itemtype next to each field
- Stop flagging a network port injection as partial when no connection to a network equipment port is requested
- Made several generic warnings more explicit. They explain why the mapping failed.
Expand Down
6 changes: 6 additions & 0 deletions ajax/dropdownChooseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@
Html::header_nocache();
}

<<<<<<< HEAD

Check failure on line 37 in ajax/dropdownChooseField.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_SL on line 37

Check failure on line 37 in ajax/dropdownChooseField.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_SL on line 37
Session::checkCentralAccess();
=======
Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ);
// Reads the session only: release it so that the calls of a tab run in parallel
Session::writeClose();
>>>>>>> c784dc8 (Fix - Injection form checks and CSV exports (#717))
PluginDatainjectionInjectionType::dropdownFields($_POST);
6 changes: 6 additions & 0 deletions ajax/dropdownMandatory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@
Html::header_nocache();
}

<<<<<<< HEAD
Session::checkCentralAccess();
=======
Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ);
// Reads the session only: release it so that the calls of a tab run in parallel
Session::writeClose();
>>>>>>> c784dc8 (Fix - Injection form checks and CSV exports (#717))
PluginDatainjectionInjectionType::showMandatoryCheckbox($_POST);
18 changes: 17 additions & 1 deletion front/clientinjection.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@
* -------------------------------------------------------------------------
*/

<<<<<<< HEAD

Check failure on line 31 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_SL on line 31

Check failure on line 31 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_SL on line 31
Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ);
=======
use Glpi\Exception\Http\AccessDeniedHttpException;
use Glpi\Exception\Http\BadRequestHttpException;

Session::checkRight("plugin_datainjection_use", READ);
>>>>>>> c784dc8 (Fix - Injection form checks and CSV exports (#717))

Html::header(
__('Data injection', 'datainjection'),
$_SERVER["PHP_SELF"],

Check failure on line 42 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected '"', expecting '-' or T_STRING or T_VARIABLE or T_NUM_STRING on line 42

Check failure on line 42 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected '"', expecting '-' or T_STRING or T_VARIABLE or T_NUM_STRING on line 42
"tools",
"plugindatainjectionmenu",
"client",
Expand All @@ -43,11 +50,20 @@
PluginDatainjectionClientInjection::showInjectionForm($model, $_SESSION['glpiactive_entity']);
} elseif (isset($_POST['upload'])) {
$model = new PluginDatainjectionModel();
$model->can($_POST['id'], READ);
$models_id = (int) ($_POST['id'] ?? 0);
if ($models_id <= 0) {
throw new BadRequestHttpException();
}

//Injection users may lack the model management right: only check the model itself is visible
if (!$model->getFromDB($models_id) || !$model->canViewItem()) {

Check failure on line 59 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 59

Check failure on line 59 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 59
throw new AccessDeniedHttpException();
}

$_SESSION['datainjection']['infos'] = ($_POST['info'] ?? []);

//If additional informations provided : check if mandatory infos are present
if (!$model->checkMandatoryFields($_SESSION['datainjection']['infos'])) {

Check failure on line 66 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 66

Check failure on line 66 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 66
Session::addMessageAfterRedirect(
__s('One mandatory field is not filled', 'datainjection'),
true,
Expand All @@ -69,8 +85,8 @@
'mode' => PluginDatainjectionModel::PROCESS,
'delete_file' => false,
];
$response = $model->processUploadedFile($options);

Check failure on line 88 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 88

Check failure on line 88 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 88
$model->cleanData();

Check failure on line 89 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 89

Check failure on line 89 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 89

if ($response) {
//File uploaded successfully and matches the given model : switch to the import tab
Expand Down Expand Up @@ -102,8 +118,8 @@
}

$clientInjection = new PluginDatainjectionClientInjection();
$clientInjection->title();

Check failure on line 121 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 121

Check failure on line 121 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 121
$clientInjection->showForm(0);

Check failure on line 122 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.3 - mysql:8.0 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 122

Check failure on line 122 in front/clientinjection.form.php

View workflow job for this annotation

GitHub Actions / GLPI 12.0.x - php:8.5 - mariadb:10.11 / Continuous integration

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 122
}

Html::footer();
16 changes: 15 additions & 1 deletion front/export.pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
* -------------------------------------------------------------------------
*/

use Glpi\Exception\Http\AccessDeniedHttpException;
use Glpi\Exception\Http\BadRequestHttpException;

Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ);

PluginDatainjectionModel::exportAsPDF($_GET['models_id']);
$models_id = (int) ($_GET['models_id'] ?? 0);
if ($models_id <= 0) {
throw new BadRequestHttpException();
}

//Injection users may lack the model management right: only check the model itself is visible
$model = new PluginDatainjectionModel();
if (!$model->getFromDB($models_id) || !$model->canViewItem()) {
throw new AccessDeniedHttpException();
}

PluginDatainjectionModel::exportAsPDF($models_id);
13 changes: 8 additions & 5 deletions inc/clientinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public static function showResultsForm(PluginDatainjectionModel $model)
TemplateRenderer::getInstance()->display('@datainjection/clientinjection_result.html.twig', $data);
}

private static function escapeCsvFormula(mixed $value): mixed
public static function escapeCsvFormula(mixed $value): mixed
{
if (is_string($value) && isset($value[0]) && in_array($value[0], ['=', '+', '-', '@'], true)) {
if (is_string($value) && isset($value[0]) && in_array($value[0], ['=', '+', '-', '@', "\t", "\r"], true)) {
return "'" . $value;
}

Expand All @@ -351,7 +351,7 @@ private static function writeErrorsCsv(string $dir, array $error_lines, array $h
$tmpfile = fopen($file, 'w');

if ($headers !== []) {
fputcsv($tmpfile, $headers, $delimiter);
fputcsv($tmpfile, array_map(self::escapeCsvFormula(...), $headers), $delimiter);
}

foreach ($error_lines as $line) {
Expand Down Expand Up @@ -422,8 +422,11 @@ public static function exportErrorsInCSV()
header('Pragma: no-cache');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
readfile($file);
unlink($file);
try {
readfile($file);
} finally {
unlink($file);
}
}
}
}
17 changes: 14 additions & 3 deletions inc/info.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ public static function showAdditionalInformation(
$value = ($option['default'] ?? '');
}

echo sprintf("<input type='text' name='%s' value='%s'", $name, $value);
echo sprintf("<input type='text' name='%s' value='%s'", htmlescape($name), htmlescape((string) $value));
if (isset($option['size'])) {
echo " size='" . $option['size'] . "'";
echo " size='" . (int) $option['size'] . "'";
}

echo ">";
Expand Down Expand Up @@ -406,7 +406,7 @@ public static function showAdditionalInformation(
break;

case 'multiline_text':
echo sprintf("<textarea cols='45' rows='5' name='%s'>%s</textarea>", $name, $value);
echo sprintf("<textarea cols='45' rows='5' name='%s'>%s</textarea>", htmlescape($name), htmlescape((string) $value));
break;

case 'dropdown_integer':
Expand Down Expand Up @@ -491,6 +491,7 @@ public static function dropdownTemplates($name, $table)

$values = [0 => Dropdown::EMPTY_VALUE];

<<<<<<< HEAD
$result = $DB->request([
'SELECT' => ['id', 'template_name'],
'FROM' => $table,
Expand All @@ -501,6 +502,16 @@ public static function dropdownTemplates($name, $table)
]);

foreach ($result as $data) {
=======
$iterator = $DB->request([
'SELECT' => ['id', 'template_name'],
'FROM' => $table,
'WHERE' => ['is_template' => 1] + getEntitiesRestrictCriteria($table),
'ORDER' => 'template_name',
]);

foreach ($iterator as $data) {
>>>>>>> c784dc8 (Fix - Injection form checks and CSV exports (#717))
$values[$data['id']] = $data['template_name'];
}

Expand Down
11 changes: 6 additions & 5 deletions inc/infocollection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ public function load($models_id)
/** @var DBmysql $DB */
global $DB;

$query = "SELECT *
FROM `glpi_plugin_datainjection_infos`
WHERE `models_id` = '" . $models_id . "'
ORDER BY `itemtype` ASC";
$iterator = $DB->request([
'FROM' => 'glpi_plugin_datainjection_infos',
'WHERE' => ['models_id' => (int) $models_id],
'ORDER' => 'itemtype ASC',
]);

foreach ($DB->doQuery($query) as $data) {
foreach ($iterator as $data) {
$infos = new PluginDatainjectionInfo();
$infos->fields = $data;
$this->infosCollection[] = $infos;
Expand Down
34 changes: 20 additions & 14 deletions inc/mapping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\QueryExpression;

use function Safe\ob_get_clean;
use function Safe\ob_start;
Expand Down Expand Up @@ -148,15 +149,18 @@ public static function getSeveralMappedField($models_id)
global $DB;

$several = [];
$query = "SELECT `value`,
COUNT(*) AS counter
FROM `glpi_plugin_datainjection_mappings`
WHERE `models_id` = '" . $models_id . "'
AND `value` NOT IN ('none')
GROUP BY `value`
HAVING `counter` > 1";

foreach ($DB->doQuery($query) as $mapping) {
$iterator = $DB->request([
'SELECT' => ['value', new QueryExpression('COUNT(*) AS counter')],
'FROM' => 'glpi_plugin_datainjection_mappings',
'WHERE' => [
'models_id' => (int) $models_id,
'NOT' => ['value' => 'none'],
],
'GROUPBY' => 'value',
'HAVING' => ['counter' => ['>', 1]],
]);

foreach ($iterator as $mapping) {
$several[] = $mapping['value'];
}

Expand All @@ -173,11 +177,13 @@ public static function getMappingsSortedByRank($models_id)
global $DB;

$mappings = [];
$query = "SELECT `name`
FROM `glpi_plugin_datainjection_mappings`
WHERE `models_id` = '" . $models_id . "'
ORDER BY `rank` ASC";
foreach ($DB->doQuery($query) as $data) {
$iterator = $DB->request([
'SELECT' => 'name',
'FROM' => 'glpi_plugin_datainjection_mappings',
'WHERE' => ['models_id' => (int) $models_id],
'ORDER' => 'rank ASC',
]);
foreach ($iterator as $data) {
$mappings[] = $data['name'];
}

Expand Down
11 changes: 6 additions & 5 deletions inc/mappingcollection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public function load($models_id)
/** @var DBmysql $DB */
global $DB;

$sql = "SELECT *
FROM `glpi_plugin_datainjection_mappings`
WHERE `models_id` = '{$models_id}'
ORDER BY `rank` ASC";
$iterator = $DB->request([
'FROM' => 'glpi_plugin_datainjection_mappings',
'WHERE' => ['models_id' => (int) $models_id],
'ORDER' => 'rank ASC',
]);

$this->mappingCollection = [];

foreach ($data = $DB->doQuery($sql) as $data) {
foreach ($iterator as $data) {
$mapping = new PluginDatainjectionMapping();
$mapping->fields = $data;
$this->mappingCollection[] = $mapping;
Expand Down
12 changes: 11 additions & 1 deletion inc/model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,13 @@ public function isFileCorrect()
),
);
$name_from_db = trim(mb_strtoupper((string) $mapping->getName(), 'UTF-8'));
// Sample and error files are exported with formula-escaped headers
$escaped_name_from_db = trim(mb_strtoupper(
(string) PluginDatainjectionClientInjection::escapeCsvFormula((string) $mapping->getName()),
'UTF-8',
));

if ($name_from_db !== $name_from_file) {
if ($name_from_db !== $name_from_file && $escaped_name_from_db !== $name_from_file) {
if ($error['error_message'] == '') {
$error['error_message'] = __('At least one column is incorrect', 'datainjection');
}
Expand Down Expand Up @@ -1496,8 +1501,13 @@ public static function exportAsPDF($models_id)
$pdf->setHeader(
sprintf(
__('%1$s (%2$s)'),
<<<<<<< HEAD
__('Data injection report', 'datainjection') . ' - <b>'
. PluginDatainjectionSession::getParam('file_name') . '</b>',
=======
__('Data injection report', 'datainjection') . ' - '
. PluginDatainjectionSession::getParam('file_name'),
>>>>>>> c784dc8 (Fix - Injection form checks and CSV exports (#717))
$model->getName(),
),
);
Expand Down
12 changes: 11 additions & 1 deletion inc/modelcsv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@

use Glpi\Application\View\TemplateRenderer;

use function Safe\fclose;
use function Safe\fopen;
use function Safe\fputcsv;
use function Safe\rewind;
use function Safe\stream_get_contents;

/**
* -------------------------------------------------------------------------
* DataInjection plugin for GLPI
Expand Down Expand Up @@ -118,7 +124,11 @@ public function showSample(PluginDatainjectionModel $model)
{

$headers = PluginDatainjectionMapping::getMappingsSortedByRank($model->fields['id']);
$sample = '"' . implode('"' . $this->getDelimiter() . '"', $headers) . "\"\n";
$handle = fopen('php://temp', 'r+');
fputcsv($handle, array_map(PluginDatainjectionClientInjection::escapeCsvFormula(...), $headers), $this->getDelimiter());
rewind($handle);
$sample = stream_get_contents($handle);
fclose($handle);

header(
'Content-disposition: attachment; filename="' . str_replace(
Expand Down
26 changes: 7 additions & 19 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ public static function getAllRights()
];
}

/**
* Clean profiles_id from plugin's profile table
*
* @param int $ID
**/
public function cleanProfiles($ID)
{
/** @var DBmysql $DB */
global $DB;
$query = "DELETE FROM `glpi_profiles`
WHERE `profiles_id`='{$ID}'
AND `name` LIKE '%plugin_datainjection%'";
$DB->doQuery($query);
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{

Expand Down Expand Up @@ -147,10 +132,13 @@ public static function migrateProfiles()

$profiles = getAllDataFromTable('glpi_plugin_datainjection_profiles');
foreach ($profiles as $id => $profile) {
$query = "SELECT `id` FROM `glpi_profiles` WHERE `name`='" . $profile['name'] . "'";
$result = $DB->doQuery($query);
if ($DB->numrows($result) == 1) {
$id = $DB->result($result, 0, 'id');
$iterator = $DB->request([
'SELECT' => 'id',
'FROM' => 'glpi_profiles',
'WHERE' => ['name' => $profile['name']],
]);
if (count($iterator) === 1) {
$id = $iterator->current()['id'];
switch ($profile['model']) {
case 'r':
$value = READ;
Expand Down
Loading
Loading