-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmunkireportinfo_processor.php
executable file
·61 lines (51 loc) · 1.86 KB
/
munkireportinfo_processor.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
<?php
use CFPropertyList\CFPropertyList;
use munkireport\processors\Processor;
class Munkireportinfo_processor extends Processor
{
public function run($data)
{
if (! $data) {
throw new Exception(
"Error Processing Request: No property list found", 1
);
}
$parser = new CFPropertyList();
$parser->parse($data, CFPropertyList::FORMAT_XML);
$plist = $parser->toArray();
// Convert version to int
if (isset($plist['version'])) {
$digits = explode('.', $plist['version']);
$mult = 10000;
$plist['version'] = 0;
foreach ($digits as $digit) {
$plist['version'] += $digit * $mult;
$mult = $mult / 100;
}
}
// Set default version value
if(empty($plist['version'])){
$plist['version'] = null;
}
$infoData = [];
foreach (array('baseurl', 'passphrase', 'version', 'reportitems', 'start_time', 'end_time', 'log', 'log_warning', 'log_error', 'error_count', 'warning_count', 'upload_size', 'log_size', 'warning_log_size', 'error_log_size') as $item) {
if (isset($plist[$item])) {
if ($item == 'reportitems'){
$modulelist = array_keys($plist["reportitems"]);
sort($modulelist);
$modulelistproper = implode(", ",$modulelist);
$infoData[$item] = $modulelistproper;
} else {
$infoData[$item] = $plist[$item];
}
} else {
$infoData[$item] = null;
}
}
// Save the data. Save the lemurs!
Munkireportinfo_model::updateOrCreate(
['serial_number' => $this->serial_number],
$infoData
);
}
}