-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser_extensions_processor.php
61 lines (47 loc) · 2.01 KB
/
browser_extensions_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 Browser_extensions_processor extends Processor
{
/**
* Process data sent by postflight
*
* @param string data
* @author abn290
**/
public function run($plist)
{
// Add local config
configAppendFile(__DIR__ . '/config.php');
// Check if we have data
if ( ! $plist){
throw new Exception("Error Processing Request: No property list found", 1);
}
// Delete previous set
Browser_extensions_model::where('serial_number', $this->serial_number)->delete();
// Build list of extension IDs to ignore
$extension_id_ignorelist = is_array(conf('browser_extension_id_ignorelist')) ? conf('browser_extension_id_ignorelist') : array();
$regex_id = '/^'.implode('|', $extension_id_ignorelist).'$/';
// Build list of extension names to ignore
$extension_name_ignorelist = is_array(conf('browser_extension_name_ignorelist')) ? conf('browser_extension_name_ignorelist') : array();
$regex_name = '/^'.implode('|', $extension_name_ignorelist).'$/';
$parser = new CFPropertyList();
$parser->parse($plist, CFPropertyList::FORMAT_XML);
// Get fillable items
$fillable = array_fill_keys((new Browser_extensions_model)->getFillable(), null);
$fillable['serial_number'] = $this->serial_number;
$save_list = [];
foreach ($parser->toArray() as $extension) {
// Check if we should skip this extension based on extension ID
if (preg_match($regex_id, $extension['extension_id'])) {
continue;
}
// Check if we should skip this extension based on extension name
if (preg_match($regex_name, $extension['name'])) {
continue;
}
$save_list[] = array_replace($fillable, array_intersect_key($extension, $fillable));
}
Browser_extensions_model::insertChunked($save_list);
}
}