glpi / src / plugins / vigilo / plugin.php @ fa5253c9
History | View | Annotate | Download (5.23 KB)
1 | 166be9d2 | Francois POIROTTE | <?php
|
---|---|---|---|
2 | |||
3 | 22269799 | Francois POIROTTE | /* GLPI 9.1.2+ est nécessaire pour disposer du hook "post_show_item". */
|
4 | define('VIGILO_MIN_GLPI_VERSION', '9.1.2'); |
||
5 | 166be9d2 | Francois POIROTTE | |
6 | function plugin_init_vigilo() |
||
7 | { |
||
8 | global $PLUGIN_HOOKS; |
||
9 | global $DB; |
||
10 | |||
11 | $hooks =& $PLUGIN_HOOKS; |
||
12 | $p = "vigilo"; |
||
13 | $hookObj = new VigiloHooks(); |
||
14 | |||
15 | $hooks['csrf_compliant'][$p] = true; |
||
16 | |||
17 | foreach (array("Computer", "Printer", "NetworkEquipment") as $itemtype) { |
||
18 | $hooks['pre_item_update'][$p][$itemtype] = array($hookObj, "preItemUpdate"); |
||
19 | $hooks['item_add'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
||
20 | $hooks['item_update'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
||
21 | $hooks['item_restore'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
||
22 | $hooks['item_delete'][$p][$itemtype] = array($hookObj, "itemPurge"); |
||
23 | $hooks['item_purge'][$p][$itemtype] = array($hookObj, "itemPurge"); |
||
24 | } |
||
25 | |||
26 | $events = array('item_add', 'item_update', 'item_purge', 'item_delete', 'item_restore'); |
||
27 | foreach ($events as $event) { |
||
28 | $hooks[$event][$p] += array( |
||
29 | "IPAddress" => array($hookObj, "refreshAddress"), |
||
30 | "ComputerDisk" => array($hookObj, "refreshDisk"), |
||
31 | "NetworkPort" => array($hookObj, "refreshDevice"), |
||
32 | "DeviceProcessor" => array($hookObj, "refreshDevice"), |
||
33 | "DeviceMemory" => array($hookObj, "refreshDevice"), |
||
34 | "DeviceHardDrive" => array($hookObj, "refreshDevice"), |
||
35 | "DeviceControl" => array($hookObj, "refreshDevice"), |
||
36 | "DeviceSoundCard" => array($hookObj, "refreshDevice"), |
||
37 | "Software" => array($hookObj, "refreshSoftware"), |
||
38 | "Computer_SoftwareVersion" => array($hookObj, "refreshSoftwareVersion"), |
||
39 | "Location" => array($hookObj, "updateGroups"), |
||
40 | "Entity" => array($hookObj, "updateGroups"), |
||
41 | "Manufacturer" => array($hookObj, "updateGroups"), |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | $hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
||
46 | $hooks['config_page'][$p] = 'front/menu.php'; |
||
47 | $hooks['post_item_form'][$p] = array('PluginVigiloTemplate', 'showForm'); |
||
48 | } |
||
49 | |||
50 | function plugin_version_vigilo() |
||
51 | { |
||
52 | return array('name' => 'Vigilo monitoring', |
||
53 | 7ca31ee8 | Francois POIROTTE | 'version' => trim(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'VERSION.txt')), |
54 | 'author' => 'CSSI', |
||
55 | 'license' => 'GPLv2+', |
||
56 | 2fd8023e | Francois POIROTTE | 'homepage' => 'http://vigilo-nms.com', |
57 | 7ca31ee8 | Francois POIROTTE | 'minGlpiVersion' => VIGILO_MIN_GLPI_VERSION); |
58 | 166be9d2 | Francois POIROTTE | } |
59 | |||
60 | function plugin_vigilo_check_config($verbose = false) |
||
61 | { |
||
62 | if (version_compare(GLPI_VERSION, VIGILO_MIN_GLPI_VERSION, 'lt')) { |
||
63 | echo "This plugin requires GLPI >= " . VIGILO_MIN_GLPI_VERSION; |
||
64 | return false; |
||
65 | } |
||
66 | return true; |
||
67 | } |
||
68 | |||
69 | function plugin_vigilo_check_prerequisites() |
||
70 | { |
||
71 | return true; |
||
72 | } |
||
73 | |||
74 | function plugin_vigilo_install() |
||
75 | { |
||
76 | global $DB; |
||
77 | |||
78 | if (!TableExists('glpi_plugin_vigilo_template')) { |
||
79 | $query = <<<SQL |
||
80 | CREATE TABLE `glpi_plugin_vigilo_template` (
|
||
81 | cdde5484 | Francois POIROTTE | `id` int(11) NOT NULL default '0',
|
82 | 166be9d2 | Francois POIROTTE | `template` varchar(255) collate utf8_unicode_ci default NULL,
|
83 | cdde5484 | Francois POIROTTE | PRIMARY KEY (`id`)
|
84 | 166be9d2 | Francois POIROTTE | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
85 | SQL;
|
||
86 | $DB->query($query) or die($DB->error()); |
||
87 | } |
||
88 | |||
89 | if (!TableExists('glpi_plugin_vigilo_config')) { |
||
90 | $query = <<<SQL |
||
91 | CREATE TABLE `glpi_plugin_vigilo_config` (
|
||
92 | `key` varchar(255) collate utf8_unicode_ci NOT NULL,
|
||
93 | `value` varchar(255) collate utf8_unicode_ci NULL,
|
||
94 | PRIMARY KEY (`key`)
|
||
95 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||
96 | SQL;
|
||
97 | $DB->query($query) or die($DB->error()); |
||
98 | |||
99 | $query = "INSERT INTO `glpi_plugin_vigilo_config` VALUES('needs_deploy', 0);"; |
||
100 | $DB->query($query) or die($DB->error()); |
||
101 | } |
||
102 | |||
103 | return true; |
||
104 | } |
||
105 | |||
106 | function plugin_vigilo_uninstall() |
||
107 | { |
||
108 | global $DB; |
||
109 | |||
110 | foreach (array('template', 'deployment') as $table) { |
||
111 | $DB->query("DROP TABLE IF EXISTS `glpi_plugin_vigilo_$table`;"); |
||
112 | } |
||
113 | |||
114 | return true; |
||
115 | } |
||
116 | cdde5484 | Francois POIROTTE | |
117 | // @codingStandardsIgnoreStart
|
||
118 | function plugin_vigilo_getAddSearchOptions($itemtype) |
||
119 | { |
||
120 | // Le nom de la méthode est imposé par GLPI.
|
||
121 | // @codingStandardsIgnoreEnd
|
||
122 | $options = array(); |
||
123 | |||
124 | if (!in_array($itemtype, array('Computer', 'NetworkEquipment', 'Printer'))) { |
||
125 | return $options; |
||
126 | } |
||
127 | |||
128 | 14b31af4 | Francois POIROTTE | // @HACK: pour que les actions en masse fonctionnent,
|
129 | // on doit utiliser le nom réel du champ dans "linkfield",
|
||
130 | // alors que pour les actions sur un objet, il faut utiliser
|
||
131 | // le nom faisant le lien avec le type de l'objet.
|
||
132 | if (strpos($_SERVER["SCRIPT_FILENAME"], "/ajax/dropdownMassiveAction.php") !== false) { |
||
133 | $linkfield = 'vigilo_template'; |
||
134 | } else {
|
||
135 | $linkfield = 'id'; |
||
136 | } |
||
137 | |||
138 | cdde5484 | Francois POIROTTE | $options[7007]['table'] = 'glpi_plugin_vigilo_template'; |
139 | $options[7007]['field'] = 'template'; |
||
140 | 14b31af4 | Francois POIROTTE | $options[7007]['linkfield'] = $linkfield; |
141 | cdde5484 | Francois POIROTTE | $options[7007]['name'] = 'Template Vigilo'; |
142 | $options[7007]['massiveaction'] = true; |
||
143 | $options[7007]['datatype'] = 'dropdown'; |
||
144 | |||
145 | return $options; |
||
146 | } |