/
getcustomproperties.php
executable file
·69 lines (60 loc) · 2.45 KB
/
getcustomproperties.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
<?php
/*
-------------------------------------------------------------------------
Archimap plugin for GLPI
Copyright (C) 2009-2018 by Eric Feron.
-------------------------------------------------------------------------
LICENSE
This file is part of Archimap.
Archimap 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.
Archimap 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 Archimap. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
include ('../../../inc/includes.php');
$forbidden_tables = ['glpi_users', 'glpi_authldaps', 'glpi_authmails', 'glpi_certificates'];
$DB = new DB;
$cells = file_get_contents('php://input');
//Toolbox::logInFile("getcustomproperties", $cells."\n");
if (isset($cells)) {
$cells = json_decode($cells);
} else {
die("No 'cells' contained in body of POST request 'getcustomproperties'");
}
$data = [];
foreach($cells as $id => $cell) {
$key = $DB->escape($cell->key);
$table = $DB->escape($cell->tablename);
if (isset($cell->jointtables)) {
$firstword = strtok($cell->jointtables, ' ');
$jointreservedword = array("LEFT", "INNER", "RIGHT", "JOIN", "NATURAL", "STRAIGHT_JOIN");
if ( in_array(strtoupper($firstword), $jointreservedword)
|| trim($cell->jointtables) == "") {
$jointtables = $DB->escape($cell->jointtables);
} else {
$jointtables = ", ".$DB->escape($cell->jointtables);
}
} else {
$jointtables = "";
}
$jointcolumns = (isset($cell->jointcolumns))? ", ".$DB->escape($cell->jointcolumns) : "";
$jointcriteria = (isset($cell->jointcriteria))? $DB->escape($cell->jointcriteria) : "";
if (!in_array(strtolower($table), $forbidden_tables)) {
$query = "SELECT $table.id as glpi_id $jointcolumns from $table $jointtables \nwhere $table.id = $id $jointcriteria";
//Toolbox::logInFile("getcustomproperties", $query."\n");
//var_dump($query);
if ($result=$DB->query($query)) {
$data[$key]=$DB->fetchAssoc($result);
}
}
}
//var_dump($data);
echo json_encode($data);
?>