-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmunkiinfo_controller.php
103 lines (92 loc) · 2.77 KB
/
munkiinfo_controller.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
101
102
103
<?php
/**
* munkiinfo status module class
*
* @package munkireport
* @author
**/
class munkiinfo_controller extends Module_controller
{
protected $module_path;
protected $view_path;
/*** Protect methods with auth! ****/
public function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);
$this->view_path = dirname(__FILE__) . '/views/';
}
/**
* Default method
*
* @author
**/
public function index()
{
echo "You've loaded the munkiinfo module!";
}
/**
* undocumented function summary
*
* Undocumented function long description
*
* @param type var Description
* @return {11:return type}
*/
public function listing($value = '')
{
if (! $this->authorized()) {
redirect('auth/login');
}
$data['page'] = 'clients';
$data['scripts'] = array("clients/client_list.js");
$obj = new View();
$obj->view('munkiprotocol_listing', $data, $this->view_path);
}
/**
* Get Munki Protocol Statistics
*
* @author erikng
**/
public function get_protocol_stats()
{
if (! $this->authorized()) {
// die('Authenticate first.'); // Todo: return json
$out['error'] = 'Not authorized';
}
$queryobj = new munkiinfo_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'http' THEN 1 END) AS http,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'https' THEN 1 END) AS https,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'localrepo' THEN 1 END) AS localrepo
FROM munkiinfo
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$obj = new View();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Get munki preferences for serial_number
*
* @param string $serial serial number
* @author clburlison
**/
public function get_data($serial = '')
{
$out = array();
$temp = array();
if (! $this->authorized()) {
$out['error'] = 'Not authorized';
} else {
$munkiinfo = new munkiinfo_model;
foreach ($munkiinfo->retrieve_records($serial) as $prefs) {
$temp[] = $prefs->rs;
}
foreach ($temp as $value) {
$out[$value['munkiinfo_key']] = $value['munkiinfo_value'];
}
}
$obj = new View();
$obj->view('json', array('msg' => $out));
}
} // END class default_module