-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchdaemons_model.php
executable file
·100 lines (81 loc) · 3.48 KB
/
launchdaemons_model.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
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
<?php
use CFPropertyList\CFPropertyList;
class Launchdaemons_model extends \Model
{
public function __construct($serial = '')
{
parent::__construct('id', 'launchdaemons'); //primary key, tablename
$this->rs['id'] = '';
$this->rs['serial_number'] = $serial;
$this->rs['label'] = '';
$this->rs['path'] = '';
$this->rs['disabled'] = 0;
$this->rs['ondemand'] = 0;
$this->rs['runatload'] = 0;
$this->rs['program'] = '';
$this->rs['startonmount'] = 0;
$this->rs['startinterval'] = 0;
$this->rs['keepalive'] = 0;
$this->rs['daemon_json'] = '';
// Retrieve record for serial number
if ($serial) {
$this->retrieve_record($serial);
}
$this->serial = $serial;
// Add local config
configAppendFile(__DIR__ . '/config.php');
}
// ------------------------------------------------------------------------
/**
* Process data sent by postflight
*
* @param string data
*
**/
public function process($data)
{
// If data is empty, echo out error
if (! $data) {
echo ("Error Processing launchdaemons module: No data found");
} else {
// Delete previous entries
$this->deleteWhere('serial_number=?', $this->serial_number);
// List of labels to ignore
$label_ignorelist = is_array(conf('launchdaemon_ignorelist')) ? conf('launchdaemon_ignorelist') : array();
$regex = '/^'.implode('|', $label_ignorelist).'$/';
// Process incoming launchdaemons.plist
$parser = new CFPropertyList();
$parser->parse($data, CFPropertyList::FORMAT_XML);
$plist = $parser->toArray();
// Process each daemon in the plist
foreach ($plist as $daemon){
// Check if is a user daemon and if processing user daemons is allowed
if ( substr( $daemon['path'], 0, 7 ) === "/Users/" && !conf('user_agents')) {
continue;
}
// Check if we should skip this daemon
if (preg_match($regex, $daemon['label'])) {
continue;
}
// Make array of booleans for setting default
$booleans = array('disabled','ondemand','runatload','startonmount','keepalive');
// Process each field in the daemon
foreach (array('label','path','disabled','ondemand','runatload','program','startonmount','startinterval','keepalive','daemon_json') as $item) {
// If key does not exist and is boolean, set it to zero
if ( ! array_key_exists($item, $daemon) && in_array($item, $booleans)) {
$this->$item = 0;
// Else if key does not exist in $daemon, null it
} else if ( ! array_key_exists($item, $daemon) || $daemon[$item] == '') {
$this->$item = null;
// Set the db fields to be the same as those in the daemon
} else {
$this->$item = $daemon[$item];
}
}
// Save the lunch for dinner later because reheated pizza is amazeballs
$this->id = '';
$this->save();
}
}
}
}