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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Jamf Plugin for GLPI Changelog

## [Unreleased]

### Changed

- Make the plugin compatible with the Content Security Policy

## [3.2.4] - 2026-11-05

### Fixed
Expand Down
29 changes: 8 additions & 21 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public static function getTypeName($nb = 1)
*/
public static function showForItem(array $params)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$item = $params['item'];

if (!self::canView() || $item::getType() !== 'Computer') {
Expand All @@ -74,22 +71,13 @@ public static function showForItem(array $params)
$match = $jamf_item->fields;
$match = array_merge($match, $jamf_item->getJamfDeviceData());

$js = '';
$sync_attributes = [];
if ($item->canUpdate()) {
$ajax_url = $CFG_GLPI['root_doc'] . '/plugins/jamf/ajax/sync.php';
$js = <<<JAVASCRIPT
function syncDevice(itemtype, items_id) {
$.ajax({
type: "POST",
url: "{$ajax_url}",
data: {"itemtype": itemtype, "items_id": items_id},
contentType: 'application/json',
success: function() {
location.reload();
}
});
}
JAVASCRIPT;
$sync_attributes = [
'data-jamf-sync' => '',
'data-jamf-sync-itemtype' => $item::getType(),
'data-jamf-sync-items-id' => $item->getID(),
];
}

$info = [
Expand Down Expand Up @@ -135,11 +123,10 @@ function syncDevice(itemtype, items_id) {
'url' => self::getJamfDeviceURL($match['jamf_items_id']),
],
'sync' => [
'caption' => _x('action', 'Sync now', 'jamf'),
'on_click' => sprintf('syncDevice("%s", %s); return false;', $item::getType(), $item->getID()),
'caption' => _x('action', 'Sync now', 'jamf'),
'attributes' => $sync_attributes,
],
],
'extra_js' => $js,
],
];

Expand Down
37 changes: 13 additions & 24 deletions inc/mobiledevice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ public static function cardSupervisedProvider($params = [])

public static function showForItem(array $params)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

/** @var CommonDBTM $item */
$item = $params['item'];

Expand All @@ -286,22 +283,13 @@ public static function showForItem(array $params)
$match = $jamf_item->fields;
$match = array_merge($match, $jamf_item->getJamfDeviceData());

$js = '';
$sync_attributes = [];
if ($item->canUpdate()) {
$ajax_url = $CFG_GLPI['root_doc'] . '/plugins/jamf/ajax/sync.php';
$js = <<<JAVASCRIPT
function syncDevice(itemtype, items_id) {
$.ajax({
type: "POST",
url: "{$ajax_url}",
data: {"itemtype": itemtype, "items_id": items_id},
contentType: 'application/json',
success: function() {
location.reload();
}
});
}
JAVASCRIPT;
$sync_attributes = [
'data-jamf-sync' => '',
'data-jamf-sync-itemtype' => $item::getType(),
'data-jamf-sync-items-id' => $item->getID(),
];
}

$info = [
Expand Down Expand Up @@ -355,11 +343,10 @@ function syncDevice(itemtype, items_id) {
'url' => self::getJamfDeviceURL($match['jamf_items_id']),
],
'sync' => [
'caption' => _x('action', 'Sync now', 'jamf'),
'on_click' => sprintf('syncDevice("%s", %d); return false;', $item::getType(), $item->getID()),
'caption' => _x('action', 'Sync now', 'jamf'),
'attributes' => $sync_attributes,
],
],
'extra_js' => $js,
],
'lost_mode' => [
'caption' => _x('form_section', 'Jamf Lost Mode Information', 'jamf'),
Expand Down Expand Up @@ -401,9 +388,11 @@ function syncDevice(itemtype, items_id) {
],
'lost_location' => [
'caption' => _x('field', 'GPS', 'jamf'),
'value' => Html::link(sprintf('%s, %s', $lat, $long), sprintf('https://www.google.com/maps/place/%s,%s', $lat, $long), [
'display' => false,
]),
'value' => sprintf(
'<a href="%s">%s</a>',
htmlescape(sprintf('https://www.google.com/maps/place/%s,%s', $lat, $long)),
htmlescape(sprintf('%s, %s', $lat, $long)),
),
],
'lost_location_altitude' => [
'caption' => _x('field', 'Altitude', 'jamf'),
Expand Down
167 changes: 167 additions & 0 deletions public/js/jamf.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,170 @@
};
};
})();

(function () {
/**
* Replace the button content by a spinner and a label, and disable it.
* The label comes from the button's data-jamf-busy-label attribute.
*/
const setBusy = (button, spinner_class, text_prefix) => {
button.prop('disabled', true).empty()
.append($('<span>', {
class: `spinner-border spinner-border-sm ${spinner_class}`,
role: 'status',
'aria-hidden': 'true'
}))
.append(document.createTextNode(text_prefix + button.data('jamfBusyLabel')));
};

const importDevices = () => {
const import_ids = $(':checkbox:checked').filter(':not([name^="_checkall"])').map(function () {
return this.name.replace("import", "").substring(1).split('_');
}).toArray();

$.ajax({
type: "POST",
url: `${CFG_GLPI.root_doc}/plugins/jamf/ajax/import.php`,
data: {
action: "import",
import_ids: import_ids
},
contentType: 'application/json',
beforeSend: () => {
setBusy($('[data-jamf-action="import"]'), 'me-2', '');
$('[data-jamf-action="discover"]').prop('disabled', true);
$('[data-jamf-action="clear"]').prop('disabled', true);
},
complete: () => {
window.location.reload();
}
});
};

const discoverNow = () => {
$.ajax({
type: "POST",
url: `${CFG_GLPI.root_doc}/plugins/jamf/ajax/cron.php`,
data: { crontask: "importJamf" },
contentType: 'application/json',
beforeSend: () => {
$('[data-jamf-action="import"]').prop('disabled', true);
setBusy($('[data-jamf-action="discover"]'), 'me-2', '');
$('[data-jamf-action="clear"]').prop('disabled', true);
},
complete: () => {
window.location.reload();
}
});
};

const clearPendingImports = () => {
$.ajax({
type: "POST",
url: `${CFG_GLPI.root_doc}/plugins/jamf/ajax/import.php`,
data: {
action: "clear"
},
contentType: 'application/json',
beforeSend: () => {
$('[data-jamf-action="import"]').prop('disabled', true);
$('[data-jamf-action="discover"]').prop('disabled', true);
setBusy($('[data-jamf-action="clear"]'), 'me-2', '');
},
complete: () => {
window.location.reload();
}
});
};

const mergeDevices = () => {
const post_data = {};
const table = $("#merge_table")[0];
const row_count = table.rows.length;
for (let i = 1; i < row_count; i++) {
const row = table.rows[i];
const jamf_id = row.cells[0].innerText;
const itemtype = row.cells[2].innerText;
const jamf_type = row.cells[3].innerText;
const glpi_sel = $(row.cells[6]).find('select')[0];
const glpi_id = glpi_sel.value;
if (glpi_id && glpi_id > 0) {
post_data[glpi_id] = {'itemtype': itemtype, 'jamf_id': jamf_id, 'jamf_type': jamf_type};
}
}
$.ajax({
type: "POST",
url: `${CFG_GLPI.root_doc}/plugins/jamf/ajax/merge.php`,
data: {action: "merge", item_ids: post_data},
contentType: 'application/json',
beforeSend: () => {
setBusy($('[data-jamf-action="merge"]'), '', ' ');
},
complete: () => {
location.reload();
}
});
};

$(document).on('click', '[data-jamf-action="import"]', () => importDevices());
$(document).on('click', '[data-jamf-action="discover"]', () => discoverNow());
$(document).on('click', '[data-jamf-action="clear"]', () => clearPendingImports());
$(document).on('click', '[data-jamf-action="merge"]', () => mergeDevices());

$(document).on('click', '[data-jamf-action="reset-password"]', (e) => {
const password_input = $('input[name="jsspassword"]');
$(e.currentTarget).closest('div.form-field').hide();
password_input.val('');
password_input.closest('div.form-field').attr('hidden', null);
});

$(document).on('click', '[data-jamf-sync]', function () {
$.ajax({
type: "POST",
url: `${CFG_GLPI.root_doc}/plugins/jamf/ajax/sync.php`,
data: {"itemtype": this.dataset.jamfSyncItemtype, "items_id": this.dataset.jamfSyncItemsId},
contentType: 'application/json',
success: () => {
location.reload();
}
});
});

const initMdmCommands = () => {
$('[data-jamf-mdm-commands]:not([data-jamf-mdm-ready])').each(function () {
$(this).attr('data-jamf-mdm-ready', '');
window.jamfPlugin = new window.JamfPlugin();
window.jamfPlugin.init({
commands: JSON.parse(this.dataset.jamfMdmCommands),
jamf_id: this.dataset.jamfId,
itemtype: this.dataset.jamfItemtype,
items_id: this.dataset.jamfItemsId,
});
});
};

$(document).on('click', '[data-jamf-mdm-command]', (e) => {
window.jamfPlugin.onMDMCommandButtonClick(e.currentTarget.dataset.jamfMdmCommand, e);
});

const initInventoryInfo = () => {
const markers = $('[data-jamf-inventory-info]:not([data-jamf-inventory-info-ready])');
if (markers.length === 0) {
return;
}
markers.attr('data-jamf-inventory-info-ready', '');
// Assets are marked dynamic by this plugin, so the native inventory section is removed
const card_title_icon = $('form[name="asset_form"]').next('.card').find('.card-header .ribbon i');
if (card_title_icon.length > 0 && card_title_icon.eq(0).hasClass('fa-cloud-download-alt')) {
card_title_icon.closest('.card').remove();
}
};

const initPluginMarkup = () => {
initMdmCommands();
initInventoryInfo();
};

$(initPluginMarkup);
$(document).on('glpi.tab.loaded', initPluginMarkup);
})();
1 change: 1 addition & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function plugin_version_jamf()
'author' => "<a href=\"mailto:contact@teclib.com\">Teclib'</a> & Curtis Conard",
'license' => 'GPLv2',
'homepage' => 'https://github.com/pluginsGLPI/jamf',
'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_JAMF_MIN_GLPI,
Expand Down
10 changes: 1 addition & 9 deletions templates/config.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,14 @@
{% set password_set = config.jsspassword is defined and config.jsspassword|length > 0 %}
{% if password_set %}
{% set field_value %}
<button name="reset_password" type="button" class="btn btn-outline-secondary btn-sm">
<button name="reset_password" type="button" class="btn btn-outline-secondary btn-sm" data-jamf-action="reset-password">
<i class="ti ti-key"></i>
{{ _x('button', 'Reset password', 'jamf') }}
</button>
{% endset %}
{{ fields.field('password_reset_btn', field_value, _x('config', 'JSS Password', 'jamf'), {
add_field_class: 'align-items-center',
}) }}
<script>
$('button[name="reset_password"]').on('click', (e) => {
const password_input = $('input[name="jsspassword"]');
$(e.currentTarget).closest('div.form-field').hide();
password_input.val('');
password_input.closest('div.form-field').attr('hidden', null);
});
</script>
{% endif %}
{{ fields.passwordField('jsspassword', config.jsspassword|default(null), _x('config', 'JSS Password', 'jamf'), {
add_field_attribs: password_set ? {'hidden': 'hidden'} : {},
Expand Down
Loading