diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71714cd4..bb9ed47c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+### Added
+
+- Make the plugin compatible with the Content Security Policy
+
### Fixed
- Fix the uploaded file name being lost after the client injection upload step
diff --git a/inc/info.class.php b/inc/info.class.php
index 899eb3dc..7d034649 100644
--- a/inc/info.class.php
+++ b/inc/info.class.php
@@ -206,10 +206,10 @@ public static function showFormInfos(PluginDatainjectionModel $model)
echo "
";
echo sprintf(" ", $arrow);
echo "";
- echo sprintf("", $formname) . __s('Check all') . " ";
+ echo sprintf("", htmlescape($formname)) . __s('Check all') . " ";
echo "/ ";
echo "";
- echo sprintf("", $formname) . __s('Uncheck all') . " ";
+ echo sprintf("", htmlescape($formname)) . __s('Uncheck all') . " ";
echo "";
echo " ";
- echo "" . __s('Close') . " ";
+ echo "" . __s('Close') . " ";
echo "";
}
diff --git a/public/js/clientinjection.js b/public/js/clientinjection.js
new file mode 100644
index 00000000..8858d50d
--- /dev/null
+++ b/public/js/clientinjection.js
@@ -0,0 +1,57 @@
+/**
+ * -------------------------------------------------------------------------
+ * DataInjection plugin for GLPI
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of DataInjection.
+ *
+ * DataInjection is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DataInjection is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DataInjection. If not, see .
+ * -------------------------------------------------------------------------
+ * @copyright Copyright (C) 2007-2023 by DataInjection plugin team.
+ * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
+ * @link https://github.com/pluginsGLPI/datainjection
+ * -------------------------------------------------------------------------
+ */
+
+$(function() {
+ document.querySelectorAll('[data-datainjection-model-form]:not([data-datainjection-model-form-ready])').forEach((span) => {
+ span.setAttribute('data-datainjection-model-form-ready', '');
+
+ const rand = span.dataset.rand;
+ const uploadUrl = span.dataset.uploadUrl;
+ const resultUrl = span.dataset.resultUrl;
+ const modelId = Number(span.dataset.modelsId);
+ const step = Number(span.dataset.step);
+ const resultStep = Number(span.dataset.resultStep);
+
+ function loadFormForModel(modelId) {
+ if (modelId > 0) {
+ const url = (step === resultStep) ? resultUrl : uploadUrl;
+ $('#span_injection').load(url, { models_id: modelId });
+ }
+ }
+
+ // On model change
+ $('#clientinjection_form' + rand + ' select[name="dropdown_models"]').on('change select2:select', function() {
+ loadFormForModel($(this).val());
+ });
+
+ // Initial load
+ if (modelId > 0) {
+ loadFormForModel(modelId);
+ }
+ });
+});
diff --git a/public/js/datainjection.js b/public/js/datainjection.js
index 15893c8a..a6778dad 100644
--- a/public/js/datainjection.js
+++ b/public/js/datainjection.js
@@ -39,3 +39,54 @@ function show_log(num) {
document.getElementById('log'+num+'_table').style.display = 'none';
}
}
+
+document.addEventListener('click', (e) => {
+ const confirmButton = e.target.closest('[data-datainjection-confirm]');
+ if (confirmButton !== null && !window.confirm(confirmButton.dataset.datainjectionConfirm)) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ }
+}, true);
+
+document.addEventListener('click', (e) => {
+ const markLink = e.target.closest('[data-datainjection-mark-checkboxes]');
+ if (markLink !== null) {
+ if (markCheckboxes(markLink.dataset.datainjectionMarkCheckboxes)) {
+ e.preventDefault();
+ }
+ return;
+ }
+
+ const unmarkLink = e.target.closest('[data-datainjection-unmark-checkboxes]');
+ if (unmarkLink !== null) {
+ if (unMarkCheckboxes(unmarkLink.dataset.datainjectionUnmarkCheckboxes)) {
+ e.preventDefault();
+ }
+ return;
+ }
+
+ const popupLink = e.target.closest('[data-datainjection-popup]');
+ if (popupLink !== null) {
+ const popup = window.open(
+ popupLink.dataset.datainjectionPopup,
+ 'glpipopup',
+ popupLink.dataset.datainjectionPopupFeatures
+ );
+ popup.focus();
+ if ('datainjectionPopupPrevent' in popupLink.dataset) {
+ e.preventDefault();
+ }
+ return;
+ }
+
+ const locationLink = e.target.closest('[data-datainjection-location]');
+ if (locationLink !== null) {
+ location.href = locationLink.dataset.datainjectionLocation;
+ return;
+ }
+
+ if (e.target.closest('[data-datainjection-close-window]') !== null) {
+ e.preventDefault();
+ window.close();
+ }
+});
diff --git a/public/js/injection_progress.js b/public/js/injection_progress.js
index 51659c5e..44afdbbc 100644
--- a/public/js/injection_progress.js
+++ b/public/js/injection_progress.js
@@ -99,3 +99,10 @@ function startBatchInjection(container) {
processBatch();
}
+
+$(function() {
+ document.querySelectorAll('[data-datainjection-injection]:not([data-datainjection-injection-ready])').forEach((container) => {
+ container.setAttribute('data-datainjection-injection-ready', '');
+ startBatchInjection(container);
+ });
+});
diff --git a/setup.php b/setup.php
index b411fa92..43b028d6 100644
--- a/setup.php
+++ b/setup.php
@@ -98,6 +98,7 @@ function plugin_version_datainjection()
'homepage' => 'https://github.com/pluginsGLPI/datainjection',
'license' => 'GPLv2+',
'version' => PLUGIN_DATAINJECTION_VERSION,
+ 'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_DATAINJECTION_MIN_GLPI,
diff --git a/templates/clientinjection.html.twig b/templates/clientinjection.html.twig
index 590b9cae..be277441 100644
--- a/templates/clientinjection.html.twig
+++ b/templates/clientinjection.html.twig
@@ -64,37 +64,17 @@
-
+
+ {{ call('Html::script', ['/plugins/datainjection/js/clientinjection.js', {'version': constant('PLUGIN_DATAINJECTION_VERSION')}, false])|raw }}
-
-
\ No newline at end of file
diff --git a/templates/clientinjection_injection.html.twig b/templates/clientinjection_injection.html.twig
index e230d433..be0a711b 100644
--- a/templates/clientinjection_injection.html.twig
+++ b/templates/clientinjection_injection.html.twig
@@ -36,6 +36,7 @@
-
-
\ No newline at end of file
+{{ call('Html::script', ['/plugins/datainjection/js/injection_progress.js', {'version': constant('PLUGIN_DATAINJECTION_VERSION')}, false])|raw }}
\ No newline at end of file
diff --git a/templates/clientinjection_result.html.twig b/templates/clientinjection_result.html.twig
index 15ca3f22..fabf3638 100644
--- a/templates/clientinjection_result.html.twig
+++ b/templates/clientinjection_result.html.twig
@@ -44,18 +44,18 @@
\ No newline at end of file
diff --git a/templates/mappings_form.html.twig b/templates/mappings_form.html.twig
index 1063f0e0..15a77dba 100644
--- a/templates/mappings_form.html.twig
+++ b/templates/mappings_form.html.twig
@@ -32,7 +32,7 @@