. * * ------------------------------------------------------------------------ * * This file is used to manage the checks before deploy a package. * * ------------------------------------------------------------------------ * * @package FusionInventory * @author Walid Nouh * @author David Durieux * @copyright Copyright (c) 2010-2016 FusionInventory team * @license AGPL License 3.0 or (at your option) any later version * http://www.gnu.org/licenses/agpl-3.0-standalone.html * @link http://www.fusioninventory.org/ * @link https://github.com/fusioninventory/fusioninventory-for-glpi * */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access directly to this file"); } /** * Manage the checks before deploy a package. */ class PluginFusioninventoryDeployCheck extends PluginFusioninventoryDeployPackageItem { public $shortname = 'checks'; public $json_name = 'checks'; /** * Get types of checks with name => description * * @return array */ function getTypes() { return [ __('Registry', 'fusioninventory') => [ 'winkeyExists' => __("Registry key exists", 'fusioninventory'), 'winvalueExists' => __("Registry value exists", 'fusioninventory'), 'winkeyMissing' => __("Registry key missing", 'fusioninventory'), 'winvalueMissing' => __("Registry value missing", 'fusioninventory'), 'winkeyEquals' => __("Registry value equals to", 'fusioninventory'), 'winkeyNotEquals' => __("Registry value not equals to", 'fusioninventory'), 'winvalueType' => __("Type of registry value equals to", 'fusioninventory') ], __('File') => [ 'fileExists' => __("File exists", 'fusioninventory'), 'fileMissing' => __("File is missing", 'fusioninventory'), 'fileSizeGreater' => __("File size is greater than", 'fusioninventory'), 'fileSizeEquals' => __("File size is equal to", 'fusioninventory'), 'fileSizeLower' => __("File size is lower than", 'fusioninventory'), 'fileSHA512' => __("SHA-512 hash value matches", 'fusioninventory'), 'fileSHA512mismatch' => __("SHA-512 hash value mismatch", 'fusioninventory'), ], __('Directory') => [ 'directoryExists' => __("Directory exists", 'fusioninventory'), 'directoryMissing' => __("Directory is missing", 'fusioninventory'), ], __('Other') => [ 'freespaceGreater' => __("Free space is greater than", 'fusioninventory') ] ]; } /** * Get label for a type * @param the type value * @return the type label */ function getLabelForAType($type) { $alltypes = []; foreach ($this->getTypes() as $label => $types) { $alltypes+= $types; } if (isset($alltypes[$type])) { return $alltypes[$type]; } else { return ''; } } /** * Get Unit name * * @return array */ function getUnitLabel() { return [ "B" => __('o'), "KB" => __('Kio'), "MB" => __('Mio'), "GB" => __('Gio') ]; } function getAuditDescription($type, $return) { $return_string = $this->getLabelForAType($type); //The skip case is a litte bit different. So we notice to the user //that if audit is successful, the the audit check process continue if ($return == 'skip') { $return_string.=' : '.__('continue', 'fusioninventory'); } else { $return_string.=' : '.__('passed', 'fusioninventory'); } $return_string.= ', '.__('otherwise', 'fusioninventory').' : '; $return_string.= $this->getValueForReturn($return); return $return_string; } /** * Get the number to multiply to have in B relative to the unit * * @param string $unit the unit of number * @return integer the number to multiply */ function getUnitSize($unit) { $units = [ "B" => 1, "KB" => 1024, "MB" => 1024 * 1024, "GB" => 1024 * 1024 * 1024 ]; if (array_key_exists($unit, $units)) { return $units[$unit]; } else { return 1; } } /** * Get all registry value types handled by the agent * * @since 9.2 * @return an array of registry values types */ function getRegistryTypes() { return [ 'REG_SZ' => 'REG_SZ', 'REG_DWORD' => 'REG_DWORD', 'REG_BINARY' => 'REG_BINARY', 'REG_EXPAND_SZ' => 'REG_EXPAND_SZ', 'REG_MULTI_SZ' => 'REG_MULTI_SZ', 'REG_LINK' => 'REG_LINK', 'REG_DWORD_BIG_ENDIAN' => 'REG_DWORD_BIG_ENDIAN', 'REG_NONE' => 'REG_NONE' ]; } function dropdownRegistryTypes($value = 'REG_SZ') { return Dropdown::showFromArray('value', $this->getRegistryTypes(), ['value' => $value]); } /** * Display list of checks * * @global array $CFG_GLPI * @param object $package PluginFusioninventoryDeployPackage instance * @param array $data array converted of 'json' field in DB where stored checks * @param string $rand unique element id used to identify/update an element */ function displayList(PluginFusioninventoryDeployPackage $package, $data, $rand) { global $CFG_GLPI; $checks_types = $this->getTypes(); $package_id = $package->getID(); $canedit = $package->canUpdateContent(); echo "
"; Html::showCheckbox(['name' => 'checks_entries['.$i.']']); echo " | "; } //Get the audit full description (with type and return value) //to be displayed in the UI $text = $this->getAuditDescription($check['type'], $check['return']); if (isset($check['name']) && !empty($check['name'])) { $check_label = $check['name'].' ('.$text.')'; } else { $check_label = $text; } echo "";
if ($canedit) {
echo "";
}
echo $check_label;
if ($canedit) {
echo "";
}
if ($check['return'] === 'startnow') {
echo " "; $warning = sprintf(__('Fusioninventory-Agent %1s or higher mandatory'), '2.4.2'); echo " "; $type_values = $this->getLabelsAndTypes($check['type'], false); if (isset($type_values['path_label'])) { echo $type_values['path_label'].': '.$check['path']; } if (!empty($check['value']) && $check['value'] != NOT_AVAILABLE) { echo " "; switch ($check['type']) { case 'freespaceGreater': case 'fileSizeGreater': echo ">"; break; case 'fileSizeLower': echo "<"; break; default: echo "="; break; } echo " "; echo $check['value']; } echo " | ";
if ($canedit) {
echo ""; } echo ""; $i++; } if ($canedit) { echo " | |
"; echo Html::getCheckAllAsCheckbox("checksList$rand", mt_rand()); echo " |
---|
".__('Audit label', 'fusioninventory')." | "; echo ""; echo " | {$values['path_label']} | "; echo "";
if ($values['path_comment']) {
echo " ".$values['path_comment'].""; } echo " | ";
echo "";
if ($values['value_label'] !== false) {
echo "|
---|---|---|---|---|
{$values['value_label']} | "; switch ($values['value_type']) { case "textarea": echo ""; break; case "input": echo " | "; break; case 'registry_type': echo " | "; $this->dropdownRegistryTypes($values['value']); echo " | "; break; case "input+unit": $value = $values['value']; // freespaceGreater check is saved as MiB if ($type == 'freespaceGreater') { $value = $value * 1024 * 1024; } $options['value'] = 'KB'; if ($mode === 'edit') { if ($value >= $this->getUnitSize('GB')) { $value = $value / ($this->getUnitSize('GB')); $options['value'] = 'GB'; } else if ($value >= ($this->getUnitSize('MB'))) { $value = $value/ ($this->getUnitSize('MB')); $options['value'] = 'MB'; } else if ($value >= ($this->getUnitSize('KB'))) { $value = $value/ ($this->getUnitSize('KB')); $options['value'] = 'KB'; } else { $options['value'] = 'B'; } } echo ""; echo ""; echo " | "; echo "
".__("Unit", 'fusioninventory')." | "; echo ""; $unit_labels = $this->getUnitLabel(); /* * The freespaceGreater check does not need to propose KiB or B * because its value is based on MiB according to REST API. * -- Kevin 'kiniou' Roy */ if ($type == 'freespaceGreater') { unset($unit_labels['KB']); unset($unit_labels['B']); } Dropdown::showFromArray('unit', $unit_labels, $options); echo " | "; break; } echo "|||
".__("If not successful", 'fusioninventory')." | "; echo ""; Dropdown::showFromArray('return', $this->getAllReturnValues(), ['value' => $values['return']]); echo " | "; echo "|||
"; echo " | ";
echo " | ";
echo "