Correction du fichier setup.php pour le plugin SOC

This commit is contained in:
tips-of-mine
2025-05-31 14:39:18 +02:00
committed by GitHub
parent 574f947467
commit bd6d72129c
2 changed files with 72 additions and 276 deletions

View File

@ -1,115 +0,0 @@
<?php
/*
* @version 1.0.0
* @license GPL-3.0+
* @brief GLPI SOC Case Management Plugin
* @copyright 2025 Tips-Of-Mine
*/
define('PLUGIN_SOC_VERSION', '1.0.0');
define('PLUGIN_SOC_MIN_GLPI', '10.0.0');
define('PLUGIN_SOC_MAX_GLPI', '10.1.0');
/**
* Plugin description
*
* @return boolean
*/
function plugin_version_soc() {
return [
'name' => 'SOC Case Management',
'version' => PLUGIN_SOC_VERSION,
'author' => 'Tips-Of-Mine',
'license' => 'GPL-3.0+',
'homepage' => 'https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management/',
'requirements' => [
'glpi' => [
'min' => PLUGIN_SOC_MIN_GLPI,
'max' => PLUGIN_SOC_MAX_GLPI,
],
'php' => [
'min' => '7.4.0',
]
]
];
}
/**
* Check plugin prerequisites before installation
*
* @return boolean
*/
function plugin_soc_check_prerequisites() {
if (version_compare(GLPI_VERSION, PLUGIN_SOC_MIN_GLPI, 'lt') || version_compare(GLPI_VERSION, PLUGIN_SOC_MAX_GLPI, 'gt')) {
echo "This plugin requires GLPI >= " . PLUGIN_SOC_MIN_GLPI . " and < " . PLUGIN_SOC_MAX_GLPI;
return false;
}
return true;
}
/**
* Check if plugin configuration is compatible with current GLPI status
*
* @return boolean
*/
function plugin_soc_check_config() {
return true;
}
/**
* Plugin initialization
*
* @global array $PLUGIN_HOOKS
* @return void
*/
function plugin_init_soc() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['soc'] = true;
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
$PLUGIN_HOOKS['javascript']['soc'] = ['/plugins/soc/js/soc.js'];
$PLUGIN_HOOKS['add_css']['soc'] = ['/plugins/soc/css/soc.css'];
// Initialize translations
$PLUGIN_HOOKS['init_translations']['soc'] = 'plugin_init_soc_translations';
if (Session::haveRight('plugin_soc_case', READ)) {
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
}
// Add a tab to Changes
if (Session::haveRight('change', READ)) {
Plugin::registerClass('PluginSocCase', [
'addtabtypes' => ['Change']
]);
}
// Add a tab to Tickets
if (Session::haveRight('ticket', READ)) {
Plugin::registerClass('PluginSocCase', [
'addtabtypes' => ['Ticket']
]);
}
// Add config page
if (Session::haveRight('config', UPDATE)) {
$PLUGIN_HOOKS['config_page']['soc'] = 'front/config.form.php';
}
}
/**
* Initialize plugin translations
*
* @return void
*/
function plugin_init_soc_translations() {
global $CFG_GLPI;
$domain = 'soc';
$locale_dir = GLPI_ROOT . '/plugins/soc/locales/';
if (file_exists($locale_dir)) {
// Load plugin translations
$GLOBALS['LANG']->addTranslationFile('gettext', $locale_dir, $domain, $_SESSION['glpilanguage']);
}
}

233
setup.php
View File

@ -1,133 +1,103 @@
<?php
/**
* Init the hooks of the SOC plugin
*/
use Glpi\Plugin\Hooks;
use GlpiPlugin\Soc\Computer;
use GlpiPlugin\Soc\Config;
use GlpiPlugin\Soc\Dropdown;
use GlpiPlugin\Soc\DeviceCamera;
use GlpiPlugin\Soc\Example;
use GlpiPlugin\Soc\Filters\ComputerModelFilter;
use GlpiPlugin\Soc\ItemForm;
use GlpiPlugin\Soc\RuleTestCollection;
use GlpiPlugin\Soc\Showtabitem;
define('PLUGIN_SOC_VERSION', '1.0.0');
define('PLUGIN_SOC_MIN_GLPI', '10.0.0');
define('PLUGIN_SOC_MAX_GLPI', '10.1.0');
/**
* Get plugin version information
* Plugin description
*
* @return array
*/
function plugin_version() {
$xml = simplexml_load_file(__DIR__ . '/plugin.xml');
if ($xml === false) {
// Handle error: plugin.xml not found or unreadable
return []; // Or throw an exception
}
$authors = [];
if (isset($xml->authors) && isset($xml->authors->author)) {
foreach ($xml->authors->author as $author) {
$authors[] = (string)$author->name . (isset($author->email) ? ' &lt;' . (string)$author->email . '&gt;' : '');
}
}
$versions = [];
if (isset($xml->versions) && isset($xml->versions->version)) {
foreach ($xml->versions->version as $version) {
$versions[] = [
'num' => (string)$version->num,
'minGlpiVersion' => (string)$version->compatibility, // GLPI expects minGlpiVersion
];
}
}
$langs = [];
if (isset($xml->langs) && isset($xml->langs->lang)) {
foreach ($xml->langs->lang as $lang) {
$langs[] = (string)$lang;
}
}
$tags = [];
if (isset($xml->tags)) {
foreach ($xml->tags->children() as $lang_code => $tag_list) {
$current_tags = [];
foreach ($tag_list->tag as $tag) {
$current_tags[] = (string)$tag;
}
$tags[$lang_code] = $current_tags;
}
}
return [
'name' => (string)$xml->name,
'key' => (string)$xml->key,
'state' => (string)$xml->state,
'logo' => (string)$xml->logo,
'shortdesc' => (string)$xml->description_short, // GLPI expects shortdesc
'longdesc' => (string)$xml->description_long, // GLPI expects longdesc
'homepage' => (string)$xml->homepage,
'download' => (string)$xml->download,
'issues_tracker' => (string)$xml->issues, // GLPI expects issues_tracker
'readme' => (string)$xml->readme,
'authors' => $authors,
'versions' => $versions,
'langs' => $langs,
'license' => (string)$xml->license,
'tags' => $tags,
'minGlpiVersion' => !empty($versions) ? $versions[count($versions)-1]['minGlpiVersion'] : '' // Default to last version's compatibility
];
function plugin_version_soc() {
return [
'name' => 'SOC Case Management',
'version' => PLUGIN_SOC_VERSION,
'author' => 'Tips-Of-Mine',
'license' => 'GPL-3.0+',
'homepage' => 'https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management/',
'requirements' => [
'glpi' => [
'min' => PLUGIN_SOC_MIN_GLPI,
'max' => PLUGIN_SOC_MAX_GLPI,
],
'php' => [
'min' => '7.4.0',
]
]
];
}
/**
* Initialize plugin options
*
* @return array
*/
function plugin_init_options() {
return [
'name' => __('SOC Case Management', 'soc'),
'key' => 'soc',
'tooltip' => __('SOC Case Management integration plugin for security teams.', 'soc'),
];
}
/**
* Check plugin prerequisites.
* Check plugin prerequisites before installation
*
* @return boolean
*/
function plugin_check_prerequisites() {
// For now, always return true
return true;
function plugin_soc_check_prerequisites() {
if (version_compare(GLPI_VERSION, PLUGIN_SOC_MIN_GLPI, 'lt') || version_compare(GLPI_VERSION, PLUGIN_SOC_MAX_GLPI, 'gt')) {
echo "This plugin requires GLPI >= " . PLUGIN_SOC_MIN_GLPI . " and < " . PLUGIN_SOC_MAX_GLPI;
return false;
}
return true;
}
/**
* Check plugin configuration.
*
* @param boolean $verbose Enable verbose mode (default false)
* Check if plugin configuration is compatible with current GLPI status
*
* @return boolean
*/
function plugin_check_config($verbose = false) {
// For now, always return true
return true;
function plugin_soc_check_config() {
return true;
}
/**
* Display plugin configuration page.
* Plugin initialization
*
* @global array $PLUGIN_HOOKS
* @return void
*/
function plugin_display_config() {
// Currently does nothing
function plugin_init_soc() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['soc'] = true;
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
$PLUGIN_HOOKS['javascript']['soc'] = ['plugins/soc/js/soc.js'];
$PLUGIN_HOOKS['add_css']['soc'] = ['plugins/soc/css/soc.css'];
// Initialize translations
Plugin::registerClass('PluginSocCase');
if (Session::haveRight('plugin_soc_case', READ)) {
$PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase'];
}
// Add a tab to Changes
if (Session::haveRight('change', READ)) {
Plugin::registerClass('PluginSocCase', [
'addtabtypes' => ['Change']
]);
}
// Add a tab to Tickets
if (Session::haveRight('ticket', READ)) {
Plugin::registerClass('PluginSocCase', [
'addtabtypes' => ['Ticket']
]);
}
// Add config page
if (Session::haveRight('config', UPDATE)) {
$PLUGIN_HOOKS['config_page']['soc'] = 'front/config.form.php';
}
}
/**
* Init the hooks of the plugin
* Install all necessary elements for the plugin
*
* @return void
* @return boolean
*/
function plugin_soc_install() {
global $DB;
@ -228,63 +198,4 @@ function plugin_soc_uninstall() {
PluginSocConfig::uninstall();
return true;
}
/**
* Define database relations
*/
function plugin_soc_getDatabaseRelations() {
return [
'glpi_entities' => [
'glpi_plugin_soc_cases' => 'entities_id'
],
'glpi_users' => [
'glpi_plugin_soc_cases' => 'users_id_tech'
],
'glpi_groups' => [
'glpi_plugin_soc_cases' => 'groups_id_tech'
],
'glpi_tickets' => [
'glpi_plugin_soc_case_tickets' => 'tickets_id'
],
'glpi_changes' => [
'glpi_plugin_soc_case_changes' => 'changes_id'
],
'glpi_plugin_soc_cases' => [
'glpi_plugin_soc_case_tickets' => 'plugin_soc_cases_id',
'glpi_plugin_soc_case_changes' => 'plugin_soc_cases_id'
]
];
}
/**
* Define display preferences
*/
function plugin_soc_getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
$tabs = [];
if ($item->getType() == 'Ticket' && Session::haveRight("plugin_soc_case", READ)) {
$tabs[1] = __('SOC Cases', 'soc');
}
if ($item->getType() == 'Change' && Session::haveRight("plugin_soc_case", READ)) {
$tabs[1] = __('SOC Cases', 'soc');
}
return $tabs;
}
/**
* Define right names
*/
function plugin_soc_getRights($itemtype = '') {
$rights = [
[
'itemtype' => 'PluginSocCase',
'label' => __('SOC Case', 'soc'),
'field' => 'plugin_soc_case'
]
];
return $rights;
}
}