-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsccm.class.php
More file actions
731 lines (575 loc) · 23.2 KB
/
sccm.class.php
File metadata and controls
731 lines (575 loc) · 23.2 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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
<?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");
}
use Glpi\Toolbox\Sanitizer;
class PluginSccmSccm
{
public $devices;
public static function getTypeName($nb = 0)
{
return __('SCCM', 'sccm');
}
public function showHome()
{
echo __('Please, read the documentation before using that.', 'footprints');
}
public function getSccmBuildNumber()
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "SELECT TOP 1 BuildNumber FROM dbo.Site;";
$result = $PluginSccmSccmdb->exec_query($query);
$version = null;
if ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$version = Sanitizer::sanitize($row['BuildNumber']);
}
return (int) $version;
}
public function getDevices($where = 0, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = self::getcomputerQuery();
if ($where != 0) {
$query .= " WHERE csd.MachineID = '" . $where . "'";
}
$result = $PluginSccmSccmdb->exec_query($query);
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tab['MD-SystemName'] = strtoupper($tab['MD-SystemName']);
$this->devices[] = $tab;
$i++;
}
$PluginSccmSccmdb->disconnect();
}
public function getDatas($type, $deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$datas = [];
if ($type == 'processors') {
$fields = ['Manufacturer00','Name00','NormSpeed00','AddressWidth00','CPUKey00','NumberOfCores00', 'NumberOfLogicalProcessors00'];
$table = 'Processor_DATA';
} else {
return [];
}
$query = "SELECT " . implode(',', $fields) . "\n";
$query .= " FROM " . $table . "\n";
$query .= " WHERE MachineID = '" . $deviceid . "'" . "\n";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getNetwork($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "SELECT NeDa.IPAddress00 as \"ND-IpAddress\",
NeDa.MACAddress00 as \"ND-MacAddress\",
NeDa.IPSubnet00 as \"ND-IpSubnet\",
NeDa.DefaultIPGateway00 as \"ND-IpGateway\",
NeDa.DHCPServer00 as \"ND-DHCPServer\",
NeDa.DNSDomain00 as \"ND-DomainName\",
net.Name0 as \"ND-Name\"
FROM Network_DATA NeDa
INNER JOIN v_R_System VrS ON VrS.ResourceID=NeDa.MachineID
INNER JOIN v_GS_NETWORK_ADAPTER net ON net.ResourceID=NeDa.MachineID AND NeDa.ServiceName00=net.ServiceName0
WHERE MACAddress00 is not null
AND NeDa.MachineID = '" . $deviceid . "'";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getSoftware($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "SELECT ArPd_64.DisplayName0 as \"ArPd-DisplayName\",
ArPd_64.InstallDate0 as \"ArPd-InstallDate\",
ArPd_64.Version0 as \"ArPd-Version\",
ArPd_64.Publisher0 as \"ArPd-Publisher\"
FROM v_GS_ADD_REMOVE_PROGRAMS_64 ArPd_64
INNER JOIN v_R_System VrS on VrS.ResourceID=ArPd_64.ResourceID
WHERE ArPd_64.ResourceID = $deviceid
AND (ArPd_64.DisplayName0 is not null and ArPd_64.DisplayName0 <> '')
UNION
SELECT ArPd.DisplayName0 as \"ArPd-DisplayName\",
ArPd.InstallDate0 as \"ArPd-InstallDate\",
ArPd.Version0 as \"ArPd-Version\",
ArPd.Publisher0 as \"ArPd-Publisher\"
FROM v_GS_ADD_REMOVE_PROGRAMS ArPd
INNER JOIN v_R_System VrS on VrS.ResourceID=ArPd.ResourceID
WHERE ArPd.ResourceID = $deviceid
AND (ArPd.DisplayName0 is not null and ArPd.DisplayName0 <> '')";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getMemories($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "SELECT
Capacity0 as \"Mem-Capacity\",
Caption0 as \"Mem-Caption\",
Description0 as \"Mem-Description\",
FormFactor0 as \"Mem-FormFactor\",
Manufacturer0 as \"Mem-Manufacturer\",
Removable0 as \"Mem-Removable\",
'' as \"Mem-Purpose\",
Speed0 as \"Mem-Speed\",
BankLabel0 as \"Mem-Type\",
GroupID as \"Mem-NumSlots\",
'' as \"Mem-SerialNumber\"
FROM v_GS_PHYSICAL_MEMORY
WHERE ResourceID = '" . $deviceid . "'
ORDER BY \"Mem-NumSlots\"";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getVideos($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "
SELECT
VideoProcessor0 as \"Vid-Chipset\",
AdapterRAM0/1024 as \"Vid-Memory\",
Name0 as \"Vid-Name\",
CONCAT(CurrentHorizontalResolution0, 'x', CurrentVerticalResolution0) as \"Vid-Resolution\",
GroupID as \"Vid-PciSlot\"
FROM v_GS_VIDEO_CONTROLLER
WHERE VideoProcessor0 is not null
AND ResourceID = '" . $deviceid . "'
ORDER BY GroupID";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getSounds($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "
SELECT distinct
Description0 as \"Snd-Description\",
Manufacturer0 as \"Snd-Manufacturer\",
Name0 as \"Snd-Name\"
FROM v_GS_SOUND_DEVICE
WHERE ResourceID = '" . $deviceid . "'";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getStorages($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "
SELECT
md.SystemName00,
gld.ResourceID as \"gld-ResourceID\",
gld.Description0 as \"gld-Description\",
gld.DeviceID0 as \"gld-Partition\",
gld.FileSystem0 as \"gld-FileSystem\",
gld.Size0 as \"gld-TotalSize\",
gld.FreeSpace0 as \"gld-FreeSpace\",
gld.VolumeName0 as \"gld-MountingPoint\",
gdi.Caption0 as \"gdi-Caption\"
FROM v_GS_LOGICAL_DISK as gld
INNER JOIN v_gs_Disk as gdi on gdi.ResourceID = gld.ResourceID
LEFT JOIN Motherboard_DATA as md on gld.ResourceID = md.MachineID
WHERE gld.GroupID = gdi.GroupID
AND gld.ResourceID = '" . $deviceid . "'";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public function getMedias($deviceid, $limit = 99999999)
{
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
if (!$res) {
die;
}
$query = "
SELECT distinct
Description0 as \"Med-Description\",
Manufacturer0 as \"Med-Manufacturer\",
Caption0 as \"Med-Model\",
Name0 as \"Med-Name\",
SCSITargetID0 as \"Med-SCSITargetId\",
MediaType0 as \"Med-Type\"
FROM v_GS_CDROM
WHERE ResourceID = '" . $deviceid . "'";
$result = $PluginSccmSccmdb->exec_query($query);
$data = [];
$i = 0;
$tab = [];
while (($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) and $i < $limit) {
$tmp = [];
foreach ($tab as $key => $value) {
$tmp[$key] = Sanitizer::sanitize($value);
}
$data[] = $tmp;
$i++;
}
$PluginSccmSccmdb->disconnect();
return $data;
}
public static function install()
{
$cronCollect = new CronTask();
if ($cronCollect->getFromDBbyName(__CLASS__, 'sccm')) {
$cronCollect->fields["name"] = "SCCMCollect";
$cronCollect->fields["hourmin"] = 4;
$cronCollect->fields["hourmax"] = 5;
$cronCollect->update($cronCollect->fields);
} elseif (!$cronCollect->getFromDBbyName(__CLASS__, 'SCCMCollect')) {
CronTask::register(
__CLASS__,
'SCCMCollect',
7 * DAY_TIMESTAMP,
['param' => 24, 'mode' => CronTask::MODE_EXTERNAL, 'hourmin' => 4, 'hourmax' => 5],
);
}
CronTask::register(
__CLASS__,
'SCCMPush',
7 * DAY_TIMESTAMP,
['param' => 24, 'mode' => CronTask::MODE_EXTERNAL, 'hourmin' => 6, 'hourmax' => 7],
);
}
public static function uninstall()
{
CronTask::unregister(__CLASS__);
}
public static function cronSCCMCollect($task)
{
return self::executeCollect($task);
}
public static function cronSCCMPush($task)
{
return self::executePush($task);
}
public static function cronInfo($name)
{
if ($name == "SCCMCollect") {
return ['description' => __("Interface - SCCMCollect", "sccm")];
}
if ($name == "SCCMPush") {
return ['description' => __("Interface - SCCMPush", "sccm")];
}
}
public static function executeCollect($task)
{
ini_set('max_execution_time', '0');
$retcode = -1;
$REP_XML = GLPI_PLUGIN_DOC_DIR . '/sccm/xml/';
$PluginSccmConfig = new PluginSccmConfig();
$PluginSccmConfig->getFromDB(1);
$PluginSccmSccm = new PluginSccmSccm();
if ($PluginSccmConfig->getField('active_sync') == 1) {
$PluginSccmSccm->getDevices();
Toolbox::logInFile('sccm', "getDevices OK \n", true);
Toolbox::logInFile('sccm', "Generate XML start : "
. count($PluginSccmSccm->devices) . " files\n", true);
foreach ($PluginSccmSccm->devices as $device_values) {
$PluginSccmSccmxml = new PluginSccmSccmxml($device_values);
$PluginSccmSccmxml->setAccessLog();
$PluginSccmSccmxml->setAccountInfos();
$PluginSccmSccmxml->setHardware();
$PluginSccmSccmxml->setOS();
$PluginSccmSccmxml->setBios();
$PluginSccmSccmxml->setProcessors();
$PluginSccmSccmxml->setSoftwares();
$PluginSccmSccmxml->setMemories();
$PluginSccmSccmxml->setVideos();
$PluginSccmSccmxml->setSounds();
$PluginSccmSccmxml->setUsers();
$PluginSccmSccmxml->setNetworks();
$PluginSccmSccmxml->setStorages();
$SXML = $PluginSccmSccmxml->sxml;
$SXML->asXML($REP_XML . $PluginSccmSccmxml->device_id . ".ocs");
Toolbox::logInFile('sccm', "Collect OK for device - " . $PluginSccmSccmxml->device_id . " \n", true);
$task->addVolume(1);
}
$retcode = 1;
Toolbox::logInFile('sccm', "Collect completed \n", true);
} else {
echo __("Collect is disabled by configuration.", "sccm");
}
return $retcode;
}
public static function getcomputerQuery()
{
return "SELECT csd.Description00 as \"CSD-Description\",
csd.Domain00 as \"CSD-Domain\",
csd.Manufacturer00 as \"CSD-Manufacturer\",
csd.Model00 as \"CSD-Model\",
csd.Roles00 as \"CSD-Roles\",
csd.SystemType00 as \"CSD-SystemType\",
csd.UserName00 as \"CSD-UserName\",
csd.MachineID as \"CSD-MachineID\",
csd.TimeKey as \"CSD-TimeKey\",
md.SystemName00 as \"MD-SystemName\",
osd.BuildNumber00 as \"OSD-BuildNumber\",
osd.Caption00 as \"OSD-Caption\",
osd.CSDVersion00 as \"OSD-CSDVersion\",
osd.BootDevice00 as \"OSD-BootDevice\",
osd.InstallDate00 as \"OSD-InstallDate\",
osd.LastBootUpTime00 as \"OSD-LastBootUpTime\",
osd.Manufacturer00 as \"OSD-Manufacturer\",
osd.Name00 as \"OSD-Name\",
osd.Organization00 as \"OSD-Organization\",
osd.RegisteredUser00 as \"OSD-RegisteredUser\",
osd.TotalVirtualMemorySize00 as \"OSD-TotalVirtualMemory\",
osd.TotalVisibleMemorySize00 as \"OSD-TotalVisibleMemory\",
osd.Version00 as \"OSD-Version\",
pbd.SerialNumber00 as \"PBD-SerialNumber\",
pbd.ReleaseDate00 as \"PBD-ReleaseDate\",
pbd.Name00 as \"PBD-Name\",
pbd.SMBIOSBIOSVersion00 as \"PBD-BiosVersion\",
pbd.Version00 as \"PBD-Version\",
pbd.Manufacturer00 as \"PBD-Manufacturer\",
sdi.User_Name0 as \"SDI-UserName\",
sd.SMSID0 as \"SD-UUID\",
sd.SystemRole0 as \"SD-SystemRole\",
VrS.User_Name0 as \"VrS-UserName\",
vWD.LastHWScan as \"vWD-LastScan\"
FROM Computer_System_DATA csd
LEFT JOIN Motherboard_DATA md ON csd.MachineID = md.MachineID
LEFT JOIN Operating_System_DATA osd ON csd.MachineID = osd.MachineID
LEFT JOIN v_GS_WORKSTATION_STATUS vWD ON csd.MachineID = vWD.ResourceID
LEFT JOIN PC_BIOS_DATA pbd ON csd.MachineID = pbd.MachineID
LEFT JOIN System_DISC sdi ON csd.MachineID = sdi.ItemKey
LEFT JOIN System_DATA sd ON csd.MachineID = sd.MachineID
INNER JOIN v_R_System VrS ON csd.MachineID = VrS.ResourceID
WHERE csd.MachineID is not null and csd.MachineID != ''";
}
public static function executePush($task)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
$PluginSccmSccmdb = new PluginSccmSccmdb();
$res = $PluginSccmSccmdb->connect();
$PluginSccmConfig = new PluginSccmConfig();
$PluginSccmConfig->getFromDB(1);
$retcode = -1;
if ($PluginSccmConfig->getField('active_sync') == 1) {
if ($res) {
$query = self::getcomputerQuery();
$result = $PluginSccmSccmdb->exec_query($query);
$tab = [];
while ($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$REP_XML = realpath(GLPI_PLUGIN_DOC_DIR . '/sccm/xml/' . $tab['CSD-MachineID'] . '.ocs');
if ($REP_XML === false) {
Toolbox::logInFile('sccm', "There is a problem with the path, realpath function return false.\nPath : " . $REP_XML . "\n", true);
continue;
}
$xmlFile = simplexml_load_file($REP_XML, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($xmlFile !== false) {
$ch = curl_init();
if ($PluginSccmConfig->getField('verify_ssl_cert') != "1") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
if ($PluginSccmConfig->getField('use_auth_ntlm') == "1") {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
}
if ($PluginSccmConfig->getField('unrestricted_auth') == "1") {
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
}
if ($PluginSccmConfig->getField('use_auth_info') == "1") {
curl_setopt($ch, CURLOPT_USERPWD, $PluginSccmConfig->getField('auth_info'));
}
$url = ($PluginSccmConfig->getField('inventory_server_url') ?: $CFG_GLPI['url_base']) . '/front/inventory.php';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/xml']);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlFile->asXML());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_REFERER, $CFG_GLPI['url_base']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch_result = curl_exec($ch);
if ($ch_result === false) {
Toolbox::logInFile('sccm', curl_error($ch) . "\n", true);
} else {
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode != 200) {
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$body = substr($ch_result, $header_size);
Toolbox::logInFile('sccm', "Push KO - " . $tab['CSD-MachineID'] . " -> STATUS CODE : " . $httpcode . " \n", true);
Toolbox::logInFile('sccm', "ERROR RETURNED : " . $body . " \n", true);
} else {
$task->addVolume(1);
if ($PluginSccmConfig->getField('use_lasthwscan') == 1) {
$agent = new Agent();
if ($agent->getFromDBByCrit(["name" => $tab['CSD-MachineID']])) {
$asset = new $agent->fields['itemtype']();
if ($asset->getFromDB($agent->fields['items_id'])) {
$asset->update([
"id" => $asset->fields['id'],
"last_inventory_update" => $tab['vWD-LastScan']->format('Y-m-d h:i'),
]);
}
}
}
Toolbox::logInFile('sccm', "Push OK - " . $tab['CSD-MachineID'] . " \n", true);
}
}
curl_close($ch);
} else {
$errors = "";
foreach (libxml_get_errors() as $error) {
$errors = $errors . $error->message . "\n";
}
Toolbox::logInFile('sccm', "Can't load the file with the path : " . $REP_XML . "\n\n" . $errors . "\n", true);
}
}
Toolbox::logInFile('sccm', "Push completed \n", true);
$PluginSccmSccmdb->disconnect();
$retcode = 1;
}
} else {
echo __("Push is disabled by configuration.", "sccm");
}
return $retcode;
}
}