Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
feat(agent): collect inventory data for debug
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry authored and DIOHz0r committed Mar 22, 2018
1 parent fe5666c commit 98a2e95
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
10 changes: 8 additions & 2 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,10 +1022,11 @@ protected function enrollByInvitationToken($input) {

$input = [];

$config = Config::getConfigurationValues("flyvemdm", [
$config = Config::getConfigurationValues('flyvemdm', [
'mqtt_tls_for_clients',
'mqtt_use_client_cert',
'debug_noexpire',
'debug_save_inventory',
'computertypes_id',
'agentusercategories_id',
'agent_profiles_id',
Expand Down Expand Up @@ -1177,9 +1178,14 @@ protected function enrollByInvitationToken($input) {
}

// Create the device
if ($config['debug_save_inventory'] != '0') {
if (!is_dir(FLYVEMDM_INVENTORY_PATH)) {
@mkdir(FLYVEMDM_INVENTORY_PATH, 0770, true);
}
file_put_contents(FLYVEMDM_INVENTORY_PATH . "/$invitationToken.xml", $inventory);
}
$pfCommunication = new PluginFusioninventoryCommunication();
$pfAgent = new PluginFusioninventoryAgent();
//var_dump($_SESSION['glpi_plugin_fusioninventory']);
$_SESSION['glpi_fusionionventory_nolock'] = true;
ob_start();
if (!key_exists('glpi_plugin_fusioninventory', $_SESSION) || !key_exists('xmltags',
Expand Down
6 changes: 6 additions & 0 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ public function showFormDebug() {
-1,
['display' => false]
);
$fields['debug_save_inventory'] = Dropdown::showYesNo(
'debug_save_inventory',
$fields['debug_save_inventory'],
-1,
['display' => false]
);
$fields['show_wizard'] = Dropdown::showYesNo(
'show_wizard',
$fields['show_wizard'],
Expand Down
2 changes: 1 addition & 1 deletion inc/package.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PluginFlyvemdmPackage extends CommonDBTM {
* @return string
*/
public static function getTypeName($nb = 0) {
return _n('Package', 'Packages', $nb, "flyvemdm");
return _n('Package', 'Packages', $nb, 'flyvemdm');
}

/**
Expand Down
1 change: 1 addition & 0 deletions install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ protected function createInitialConfig() {
'service_profiles_id' => '',
'debug_enrolment' => '0',
'debug_noexpire' => '0',
'debug_save_inventory' => '0',
'ssl_cert_url' => '',
'default_device_limit' => '0',
'default_agent_url' => PLUGIN_FLYVEMDM_AGENT_DOWNLOAD_URL,
Expand Down
7 changes: 4 additions & 3 deletions install/upgrade/update_to_dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ function plugin_flyvemdm_update_to_dev(Migration $migration) {
$profileRight->updateProfileRights($profiles_id, $newRights);

Config::setConfigurationValues('flyvemdm', [
'default_agent_url' => PLUGIN_FLYVEMDM_AGENT_DOWNLOAD_URL,
'show_wizard' => '0',
'default_agent_url' => PLUGIN_FLYVEMDM_AGENT_DOWNLOAD_URL,
'show_wizard' => '0',
'debug_save_inventory' => '0',
]);

// Update configuration
Expand Down Expand Up @@ -235,7 +236,7 @@ function plugin_flyvemdm_update_to_dev(Migration $migration) {
$result->rewind();
$row = $result->current();
if (strpos($row['filename'], 'flyvemdm/package/') !== 0) {
// It there is at least one package and the path does st arts with the new prefix, then update all the table
// If there is at least one package and the path does starts with the new prefix, then update all the table
$migration->addPostQuery("UPDATE `$table` SET `filename` = CONCAT('flyvemdm/package/', `filename`)");
}
}
Expand Down
4 changes: 4 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
define('FLYVEMDM_FILE_PATH', GLPI_PLUGIN_DOC_DIR . '/flyvemdm/file');
}

if (!defined('FLYVEMDM_INVENTORY_PATH')) {
define('FLYVEMDM_INVENTORY_PATH', GLPI_PLUGIN_DOC_DIR . '/flyvemdm/inventory');
}

if (!defined('FLYVEMDM_TEMPLATE_CACHE_PATH')) {
define('FLYVEMDM_TEMPLATE_CACHE_PATH', GLPI_PLUGIN_DOC_DIR . '/flyvemdm/cache');
}
Expand Down
12 changes: 12 additions & 0 deletions tests/suite-integration/PluginFlyvemdmAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ public function testEnrollAgent() {
$agent = $this->agentFromInvitation($user, $guestEmail, $serial, $invitationToken, 'apple');

$this->boolean($agent->isNewItem())->isTrue();

// Check save inventory feature (debug setting)
\Config::setConfigurationValues('flyvemdm', ['debug_save_inventory' => '1']);

list($user, $serial, $guestEmail, $invitation) = $this->createUserInvitation(\User::getForeignKeyField());
$invitationToken = $invitation->getField('invitation_token');
$inviationId = $invitation->getID();
$agent = $this->agentFromInvitation($user, $guestEmail, $serial, $invitationToken, 'android');
\Config::setConfigurationValues('flyvemdm', ['debug_save_inventory' => '0']);

$inventoryExists = file_exists(FLYVEMDM_INVENTORY_PATH . "/$invitationToken.xml");
$this->boolean($inventoryExists)->isTrue();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tpl/config-debug.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<td>{{ config.debug_noexpire|raw }}</td>
<td></td>
</tr>
<tr class="tab_bg_1">
<td>{{ __('Save initial inventory in file', 'flyvemdm') }}</td>
<td>{{ config.debug_save_inventory|raw }}</td>
<td></td>
</tr>
<tr>
<th colspan="3" class="">{{ __('Bug collector', 'flyvemdm') }}</th>
</tr>
Expand Down

0 comments on commit 98a2e95

Please sign in to comment.