forked from pluginsGLPI/addressing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.php
296 lines (233 loc) · 10.5 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/*
* @version $Id$
-------------------------------------------------------------------------
addressing plugin for GLPI
Copyright (C) 2009-2016 by the addressing Development Team.
https://github.com/pluginsGLPI/addressing
-------------------------------------------------------------------------
LICENSE
This file is part of addressing.
addressing is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
addressing 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with addressing. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
function plugin_addressing_install() {
global $DB;
include_once (GLPI_ROOT."/plugins/addressing/inc/profile.class.php");
$update = false;
if (!$DB->tableExists("glpi_plugin_addressing_display")
&&!$DB->tableExists("glpi_plugin_addressing")
&& !$DB->tableExists("glpi_plugin_addressing_configs")) {
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/empty-2.5.0.sql");
} else {
if (!$DB->tableExists("glpi_plugin_addressing_profiles")
&& $DB->tableExists("glpi_plugin_addressing_display")
&& !$DB->fieldExists("glpi_plugin_addressing_display","ipconf1")) {//1.4
$update = true;
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-1.4.sql");
}
if (!$DB->tableExists("glpi_plugin_addressing")
&& $DB->tableExists("glpi_plugin_addressing_display")
&& $DB->fieldExists("glpi_plugin_addressing_display","ipconf1")) {
$update = true;
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-1.5.sql");
}
if ($DB->tableExists("glpi_plugin_addressing_display")
&& !$DB->fieldExists("glpi_plugin_addressing","ipdeb")) {
$update = true;
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-1.6.sql");
}
if ($DB->tableExists("glpi_plugin_addressing_profiles")
&& $DB->fieldExists("glpi_plugin_addressing_profiles","interface")) {
$update = true;
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-1.7.0.sql");
}
if (!$DB->tableExists("glpi_plugin_addressing_configs")) {
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-1.8.0.sql");
$update = true;
}
if ($DB->tableExists("glpi_plugin_addressing_profiles")
&& !$DB->fieldExists("glpi_plugin_addressing_profiles","use_ping_in_equipment")) {
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-1.9.0.sql");
$update = true;
}
//Version 2.4.0
if (!$DB->tableExists("glpi_plugin_addressing_filters")) {
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-2.4.0.sql");
}
//Version 2.5.0
if (!$DB->fieldExists("glpi_plugin_addressing_addressings", "locations_id") && !$DB->fieldExists("glpi_plugin_addressing_addressings", "fqdns_id")) {
$DB->runFile(GLPI_ROOT ."/plugins/addressing/sql/update-2.5.0.sql");
}
}
if ($update) {
$query_ = "SELECT *
FROM `glpi_plugin_addressing_profiles` ";
$result_ = $DB->query($query_);
if ($DB->numrows($result_)>0) {
while ($data=$DB->fetch_array($result_)) {
$query = "UPDATE `glpi_plugin_addressing_profiles`
SET `profiles_id` = '".$data["id"]."'
WHERE `id` = '".$data["id"]."'";
$result=$DB->query($query);
}
}
if ($DB->fieldExists("glpi_plugin_addressing_profiles", "name")) {
$query = "ALTER TABLE `glpi_plugin_addressing_profiles`
DROP `name` ";
$result = $DB->query($query);
}
Plugin::migrateItemType(array(5000 => 'PluginAddressingAddressing',
5001 => 'PluginAddressingReport'),
array("glpi_bookmarks", "glpi_bookmarks_users",
"glpi_displaypreferences", "glpi_documents_items",
"glpi_infocoms", "glpi_logs", "glpi_items_tickets"));
}
//0.85 : new profile system
PluginAddressingProfile::migrateProfiles();
//Add all rights for current user profile
PluginAddressingProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
//Drop old profile table : not used anymore
$migration = new Migration("2.5.0");
$migration->dropTable('glpi_plugin_addressing_profiles');
return true;
}
function plugin_addressing_uninstall() {
global $DB;
include_once (GLPI_ROOT."/plugins/addressing/inc/profile.class.php");
include_once (GLPI_ROOT."/plugins/addressing/inc/menu.class.php");
$migration = new Migration("2.5.0");
$tables = array("glpi_plugin_addressing_addressings",
"glpi_plugin_addressing_configs",
"glpi_plugin_addressing_filters");
foreach($tables as $table) {
$migration->dropTable($table);
}
$itemtypes = array('DisplayPreference', 'Bookmark');
foreach ($itemtypes as $itemtype) {
$item = new $itemtype;
$item->deleteByCriteria(array('itemtype' => 'PluginAddressingAddressing'));
}
//Delete rights associated with the plugin
$profileRight = new ProfileRight();
foreach (PluginAddressingProfile::getAllRights() as $right) {
$profileRight->deleteByCriteria(array('name' => $right['field']));
}
//Remove rigth from $_SESSION['glpiactiveprofile'] if exists
PluginAddressingProfile::removeRightsFromSession();
PluginAddressingMenu::removeRightsFromSession();
return true;
}
// Define database relations
function plugin_addressing_getDatabaseRelations() {
$plugin = new Plugin();
if ($plugin->isActivated("addressing")) {
return array("glpi_networks" => array("glpi_plugin_addressing_addressings" => "networks_id"),
"glpi_entities" => array("glpi_plugin_addressing_addressings" => "entities_id"));
}
return array();
}
////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
/*
function plugin_addressing_MassiveActions($type) {
switch ($type) {
case 'Profile' :
return array("plugin_addressing_allow" => PluginAddressingAddressing::getTypeName(2) . " - " .
__('Generate reports', 'addressing'));
}
return array();
}
function plugin_addressing_MassiveActionsDisplay($options=array()) {
switch ($options['itemtype']) {
case 'Profile' :
switch ($options['action']) {
case "plugin_addressing_allow" :
Profile::dropdownNoneReadWrite('use','');
echo " <input type='submit' name='massiveaction' class='submit' value=\"".
_sx('button','Post')."\" >";
break;
}
break;
}
return "";
}
function plugin_addressing_MassiveActionsProcess($data) {
$res = array('ok' => 0,
'ko' => 0,
'noright' => 0);
switch ($data['action']) {
case 'plugin_addressing_allow' :
if ($data['itemtype'] == 'Profile') {
$profglpi = new Profile();
$prof = new PluginAddressingProfile();
foreach ($data["item"] as $key => $val) {
if ($profglpi->getFromDB($key)
&& $profglpi->fields['interface']!='helpdesk') {
if ($prof->getFromDBByProfile($key)) {
if ($prof->update(array('id' => $prof->fields['id'],
'profiles_id' => $key,
'addressing' => $data['use']))) {
$res['ok']++;
} else {
$res['ko']++;
}
} else {
if ($prof->add(array('id' => $prof->fields['id'],
'profiles_id' => $key,
'addressing' => $data['use']))) {
$res['ok']++;
} else {
$res['ko']++;
}
}
} else {
$res['ko']++;
}
}
}
break;
}
return $res;
}
*/
// Do special actions for dynamic report
function plugin_addressing_dynamicReport($params) {
$PluginAddressingAddressing = new PluginAddressingAddressing();
if ($params["item_type"] == 'PluginAddressingReport'
&& isset($params["id"])
&& isset($params["display_type"])
&& $PluginAddressingAddressing->getFromDB($params["id"])) {
$PluginAddressingReport = new PluginAddressingReport();
$PluginAddressingAddressing->getFromDB($params['id']);
$addressingFilter = new PluginAddressingFilter();
if (isset($params['filter']) && $params['filter'] > 0) {
if ($addressingFilter->getFromDB($params['filter'])) {
$ipdeb = sprintf("%u", ip2long($addressingFilter->fields['begin_ip']));
$ipfin = sprintf("%u", ip2long($addressingFilter->fields['end_ip']));
$result = $PluginAddressingAddressing->compute($params["start"], array( 'ipdeb' => $ipdeb,
'ipfin' => $ipfin,
'entities_id' => $addressingFilter->fields['entities_id'],
'type_filter' => $addressingFilter->fields['type']));
}
} else {
$ipdeb = sprintf("%u", ip2long($PluginAddressingAddressing->fields["begin_ip"]));
$ipfin = sprintf("%u", ip2long($PluginAddressingAddressing->fields["end_ip"]));
$result = $PluginAddressingAddressing->compute($params["start"], array( 'ipdeb' => $ipdeb,
'ipfin' => $ipfin));
}
$PluginAddressingReport->displayReport($result, $PluginAddressingAddressing);
return true;
}
// Return false if no specific display is done, then use standard display
return false;
}
?>