-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest.php
More file actions
181 lines (147 loc) · 5.76 KB
/
test.php
File metadata and controls
181 lines (147 loc) · 5.76 KB
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
<?php
/**
* -------------------------------------------------------------------------
* SCCM plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of SCCM.
*
* SCCM 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 3 of the License, or
* (at your option) any later version.
*
* SCCM 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 SCCM. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @author François Legastelois
* @copyright Copyright (C) 2014-2023 by SCCM plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/sccm
* -------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
Session::haveRight("config", UPDATE);
Html::header(__('SCCM - TEST', 'sccm'),
$_SERVER["PHP_SELF"],
"plugins",
"sccm",
"Test");
echo "<div class='center spaced'>";
echo "<form method=\"POST\" action=\"".$_SERVER["PHP_SELF"]."?task=test\">";
echo '<input type="hidden" name="go_test" />';
echo "<table class='tab_cadrehov' style='width:20%;'>";
echo "<tr class='tab_bg_1'><td colspan='2' class='center b'>";
echo '<select name="type_test">';
echo '<option value="view">Voir HTML</option>';
echo '<option value="add">Injecter PC</option>';
echo '<option value="nbPcToInject">Nombre de PC à injecter</option>';
echo '<option value="viewList">Liste des PC à injecter</option>';
echo '</select>';
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td class='center b'>";
echo 'Limit : <input type="text" name="limit" size="10" />';
echo "</td>";
echo "<td class='center b'>";
echo 'Where : <input type="text" name="where" size="10" />';
echo "</td>";
echo "</tr>";
echo "<tr class='tab_bg_1'><td colspan='2' class='center b'>";
echo '<input type="submit" class="submit" value="Lancer le test" name="submit" />';
echo "</td></tr>";
echo "</table>";
Html::closeForm();
echo "</div>";
echo "<div class='center spaced'>";
echo "<table class='tab_glpi'>";
echo "<tr class='tab_bg_1'><td class='center b'>";
if (isset($_POST["go_test"])) {
$limit = isset($_POST['limit']) ? $_POST['limit'] : 99999999;
$where = isset($_POST['where']) ? $_POST['where'] : 0;
switch ($_POST["type_test"]) {
case 'view' : testViewHtml($limit, $where); break;
case 'add' : testAdd($where); break;
case 'nbPcToInject' : nbPcToInject(); break;
case 'viewList' : viewList(); break;
}
}
echo "</td></tr>";
echo "</table>";
echo "</div>";
Html::footer();
function viewList() {
global $PluginSccmSccm;
$PluginSccmSccm->getDevices("");
echo "<table class='tab_glpi'>";
foreach ($PluginSccmSccm->devices as $device_values) {
echo "<tr><td>".$device_values['MD-SystemName']."</td></tr>";
}
echo "</table>";
}
function nbPcToInject() {
global $PluginSccmSccm;
$PluginSccmSccm->getDevices("");
echo count($PluginSccmSccm->devices);
}
function testViewHtml($limit, $where) {
global $PluginSccmSccm;
$PluginSccmSccm->getDevices($where);
foreach ($PluginSccmSccm->devices as $device_values) {
$PluginSccmSccmxml = new PluginSccmSccmxml($PluginSccmSccm, $device_values);
$PluginSccmSccmxml->setAccessLog();
$PluginSccmSccmxml->setAccountInfos();
$PluginSccmSccmxml->setHardware();
$PluginSccmSccmxml->setOS();
$PluginSccmSccmxml->setBios();
$PluginSccmSccmxml->setProcessors();
$PluginSccmSccmxml->setSoftwares();
$PluginSccmSccmxml->setUsers();
$PluginSccmSccmxml->setNetworks();
$PluginSccmSccmxml->setStorages();
$SXML = $PluginSccmSccmxml->sxml;
Html::printCleanArray($PluginSccmSccmxml->object2array($SXML));
}
}
function testAdd($where) {
global $CFG_GLPI, $PluginSccmSccm, $PluginSccmConfig;
$PluginSccmSccm->getDevices($where);
$REP_XML = GLPI_PLUGIN_DOC_DIR.'/sccm/xml/';
foreach ($PluginSccmSccm->devices as $device_values) {
$PluginSccmSccmxml = new PluginSccmSccmxml($PluginSccmSccm, $device_values);
$PluginSccmSccmxml->setAccessLog();
$PluginSccmSccmxml->setAccountInfos();
$PluginSccmSccmxml->setHardware();
$PluginSccmSccmxml->setOS();
$PluginSccmSccmxml->setBios();
$PluginSccmSccmxml->setProcessors();
$PluginSccmSccmxml->setSoftwares();
$PluginSccmSccmxml->setUsers();
$PluginSccmSccmxml->setNetworks();
$PluginSccmSccmxml->setStorages();
$SXML = $PluginSccmSccmxml->sxml;
$SXML->asXML($REP_XML.$PluginSccmSccmxml->device_id.".ocs");
$url = ($PluginSccmConfig->getField('inventory_server_url') ?: $CFG_GLPI['url_base']) . '/front/inventory.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/xml']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $SXML->asXML());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, $CFG_GLPI['url_base']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
curl_close($ch);
echo "Ajout OK";
}
}