forked from flyve-mdm/glpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
221 lines (196 loc) · 6.3 KB
/
hook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* LICENSE
*
* Copyright © 2016-2018 Teclib'
* Copyright © 2010-2018 by the FusionInventory Development Team.
*
* This file is part of Flyve MDM Plugin for GLPI.
*
* Flyve MDM Plugin for GLPI is a subproject of Flyve MDM. Flyve MDM is a mobile
* device management software.
*
* Flyve MDM Plugin for GLPI is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Flyve MDM Plugin for GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with Flyve MDM Plugin for GLPI. If not, see http://www.gnu.org/licenses/.
* ------------------------------------------------------------------------------
* @copyright Copyright © 2018 Teclib
* @license https://www.gnu.org/licenses/agpl.txt AGPLv3+
* @link https://github.com/flyve-mdm/glpi-plugin
* @link https://flyve-mdm.com/
* ------------------------------------------------------------------------------
*/
/**
* Entry point for installation process
*/
function plugin_flyvemdm_install() {
$version = plugin_version_flyvemdm();
$migration = new Migration($version['version']);
require_once(PLUGIN_FLYVEMDM_ROOT . "/install/install.class.php");
spl_autoload_register([PluginFlyvemdmInstall::class, 'autoload']);
$install = new PluginFlyvemdmInstall();
if (!$install->isPluginInstalled()) {
return $install->install($migration);
}
return $install->upgrade($migration);
}
/**
* Uninstalls the plugin
* @return boolean True if success
*/
function plugin_flyvemdm_uninstall() {
require_once(PLUGIN_FLYVEMDM_ROOT . "/install/install.class.php");
$install = new PluginFlyvemdmInstall();
return $install->uninstall();
}
/**
* Second pass of initialization after all other initiaization of other plugins
* Also force inclusion of this file
*/
function plugin_flyvemdm_postinit() {
$plugin = new Plugin();
if ($plugin->isActivated('orion')) {
try {
PluginOrionReport::registerItemtype(PluginFlyvemdmPackage::class);
} catch (Exception $e) {
Toolbox::logInFile('php-errors', $e->getMessage());
}
}
}
/**
* @param string $type
* @return array
*/
function plugin_flyvemdm_MassiveActions($type) {
switch ($type) {
case 'User':
return [PluginFlyvemdmInvitation::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'InviteUser' =>
__("Invite to enroll a device", 'flyvemdm')];
}
return [];
}
/**
* Actions done when a profile_user is being purged
* @param CommonDBTM $item
*/
function plugin_flyvemdm_hook_pre_profileuser_purge(CommonDBTM $item) {
$config = Config::getConfigurationValues('flyvemdm', ['guest_profiles_id', 'registered_profiles_id']);
$guestProfileId = $config['guest_profiles_id'];
if ($item->getField('profiles_id') == $guestProfileId) {
$invitation = new PluginFlyvemdmInvitation();
if (!$invitation->deleteByCriteria(['users_id' => $item->getField('users_id')])) {
$item->input = false;
}
}
}
/**
* Define Dropdown tables to be managed in GLPI
* @return array
*/
function plugin_flyvemdm_getDropdown() {
$plugin = new Plugin();
if ($plugin->isActivated('flyvemdm')) {
// Table => Name
return [
PluginFlyvemdmWellknownpath::class => __('Well known Android\'s FS paths', 'flyvemdm'),
PluginFlyvemdmPolicyCategory::class => __('Policy Categories', 'flyvemdm')
];
} else {
return [];
}
}
/**
* @param string $itemtype
* @return string
*/
function plugin_flyvemdm_addDefaultSelect($itemtype) {
$selected = '';
return $selected;
}
/**
* Add a default WHERE in SELECT queries on itemtypes
* @param string $itemtype Itemtype
* @return string
*/
function plugin_Flyvemdm_addDefaultJoin($itemtype, $ref_table, $already_link_tables) {
switch ($itemtype) {
case PluginFlyvemdmGeolocation::class:
return PluginFlyvemdmGeolocation::addDefaultJoin($ref_table, $already_link_tables);
case PluginFlyvemdmAgent::class:
return PluginFlyvemdmAgent::addDefaultJoin($ref_table, $already_link_tables);
}
}
/**
* Add a default WHERE in SELECT queries on itemtypes
* @param string $itemtype Itemtype
* @return string
*/
function plugin_Flyvemdm_addDefaultWhere($itemtype) {
switch ($itemtype) {
case PluginFlyvemdmGeolocation::class:
return PluginFlyvemdmGeolocation::addDefaultWhere();
case PluginFlyvemdmAgent::class:
return PluginFlyvemdmAgent::addDefaultWhere();
}
}
/**
* @return array
*/
function plugin_flyvemdm_getDatabaseRelations() {
return [
];
}
/**
* @param CommonDBTM $item
*/
function plugin_flyvemdm_hook_entity_add(CommonDBTM $item) {
if ($item instanceof Entity) {
$entityConfig = new PluginFlyvemdmEntityConfig();
$entityConfig->hook_entity_add($item);
$fleet = new PluginFlyvemdmFleet();
$fleet->hook_entity_add($item);
}
}
/**
* @param CommonDBTM $item
*/
function plugin_flyvemdm_hook_entity_purge(CommonDBTM $item) {
if ($item instanceof Entity) {
$itemtypes = [
PluginFlyvemdmEntityConfig::class,
PluginFlyvemdmInvitation::class,
PluginFlyvemdmAgent::class,
PluginFlyvemdmFleet::class,
PluginFlyvemdmPackage::class,
PluginFlyvemdmFile::class,
];
foreach ($itemtypes as $itemtype) {
$itemToPurge = new $itemtype();
$itemToPurge->hook_entity_purge($item);
}
}
}
/**
* hook when a computer is being purged
*
* @param CommonDBTM $item
*/
function plugin_flyvemdm_hook_computer_purge(CommonDBTM $item) {
$geolocation = new PluginFlyvemdmGeolocation();
$geolocation->hook_computer_purge($item);
$agent = new PluginFlyvemdmAgent();
$agent->hook_computer_purge($item);
}
function plugin_flyvemdm_hook_pre_invitation_purge(CommonDBTM $item) {
$success = true;
$invitation = new PluginFlyvemdmInvitation();
$success = $success && $invitation->hook_pre_invitation_purge($item);
return $success;
}