mirror of
https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management.git
synced 2025-06-28 05:38:42 +02:00
![google-labs-jules[bot]](/assets/img/avatar_default.png)
Adds the following mandatory functions to setup.php to ensure the plugin can be correctly registered and identified by GLPI: - `plugin_version()`: Parses plugin.xml to provide metadata such as name, version, author, and compatibility to GLPI. - `plugin_init_options()`: Returns essential plugin identifiers like its key and display name. - Stub functions `plugin_check_prerequisites()`, `plugin_check_config()`, and `plugin_display_config()`: Added to prevent potential errors and serve as placeholders for future functionality. These changes address the issue of the plugin not appearing in the GLPI plugin installation interface.
279 lines
8.7 KiB
PHP
279 lines
8.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Get plugin version information
|
|
*
|
|
* @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) ? ' <' . (string)$author->email . '>' : '');
|
|
}
|
|
}
|
|
|
|
$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
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function plugin_check_prerequisites() {
|
|
// For now, always return true
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Check plugin configuration.
|
|
*
|
|
* @param boolean $verbose Enable verbose mode (default false)
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function plugin_check_config($verbose = false) {
|
|
// For now, always return true
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Display plugin configuration page.
|
|
*
|
|
* @return void
|
|
*/
|
|
function plugin_display_config() {
|
|
// Currently does nothing
|
|
}
|
|
|
|
/**
|
|
* Init the hooks of the plugin
|
|
*
|
|
* @return void
|
|
*/
|
|
function plugin_soc_install() {
|
|
global $DB;
|
|
|
|
if (!$DB->tableExists('glpi_plugin_soc_cases')) {
|
|
$query = "CREATE TABLE `glpi_plugin_soc_cases` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
`entities_id` int(11) NOT NULL DEFAULT '0',
|
|
`is_recursive` tinyint(1) NOT NULL DEFAULT '0',
|
|
`severity` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
`status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
|
|
`date_creation` timestamp NULL DEFAULT NULL,
|
|
`date_mod` timestamp NULL DEFAULT NULL,
|
|
`description` text COLLATE utf8_unicode_ci,
|
|
`users_id_tech` int(11) NOT NULL DEFAULT '0',
|
|
`groups_id_tech` int(11) NOT NULL DEFAULT '0',
|
|
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
|
|
PRIMARY KEY (`id`),
|
|
KEY `name` (`name`),
|
|
KEY `entities_id` (`entities_id`),
|
|
KEY `is_recursive` (`is_recursive`),
|
|
KEY `severity` (`severity`),
|
|
KEY `status` (`status`),
|
|
KEY `users_id_tech` (`users_id_tech`),
|
|
KEY `groups_id_tech` (`groups_id_tech`),
|
|
KEY `is_deleted` (`is_deleted`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
|
|
$DB->query($query) or die("Error creating glpi_plugin_soc_cases table " . $DB->error());
|
|
}
|
|
|
|
if (!$DB->tableExists('glpi_plugin_soc_case_tickets')) {
|
|
$query = "CREATE TABLE `glpi_plugin_soc_case_tickets` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`plugin_soc_cases_id` int(11) NOT NULL DEFAULT '0',
|
|
`tickets_id` int(11) NOT NULL DEFAULT '0',
|
|
`date_creation` timestamp NULL DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`tickets_id`),
|
|
KEY `tickets_id` (`tickets_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
|
|
$DB->query($query) or die("Error creating glpi_plugin_soc_case_tickets table" . $DB->error());
|
|
}
|
|
|
|
if (!$DB->tableExists('glpi_plugin_soc_case_changes')) {
|
|
$query = "CREATE TABLE `glpi_plugin_soc_case_changes` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`plugin_soc_cases_id` int(11) NOT NULL DEFAULT '0',
|
|
`changes_id` int(11) NOT NULL DEFAULT '0',
|
|
`date_creation` timestamp NULL DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `unicity` (`plugin_soc_cases_id`,`changes_id`),
|
|
KEY `changes_id` (`changes_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
|
|
$DB->query($query) or die("Error creating glpi_plugin_soc_case_changes table" . $DB->error());
|
|
}
|
|
|
|
// Create profiles rights
|
|
PluginSocProfile::initProfile();
|
|
PluginSocProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
|
|
|
|
// Initialize plugin configuration
|
|
PluginSocConfig::install();
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Uninstall the plugin
|
|
*
|
|
* @return boolean
|
|
*/
|
|
function plugin_soc_uninstall() {
|
|
global $DB;
|
|
|
|
// Delete plugin tables
|
|
$tables = [
|
|
'glpi_plugin_soc_cases',
|
|
'glpi_plugin_soc_case_tickets',
|
|
'glpi_plugin_soc_case_changes',
|
|
'glpi_plugin_soc_profiles'
|
|
];
|
|
|
|
foreach ($tables as $table) {
|
|
$query = "DROP TABLE IF EXISTS `$table`";
|
|
$DB->query($query) or die("Error dropping $table table");
|
|
}
|
|
|
|
// Delete plugin rights from profiles table
|
|
$query = "DELETE FROM `glpi_profilerights` WHERE `name` LIKE 'plugin_soc_%'";
|
|
$DB->query($query) or die("Error deleting plugin_soc rights");
|
|
|
|
// Delete plugin display preferences
|
|
$query = "DELETE FROM `glpi_displaypreferences` WHERE `itemtype` LIKE 'PluginSoc%'";
|
|
$DB->query($query) or die("Error deleting plugin_soc display preferences");
|
|
|
|
// Uninstall plugin configuration
|
|
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;
|
|
} |