forked from munkireport/sophos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsophos_controller.php
229 lines (188 loc) · 6.07 KB
/
sophos_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
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
<?php
/**
* Sophos module class
*
* @package munkireport
* @author rickheil
**/
class Sophos_controller extends Module_controller
{
/*** Protect methods with auth! ****/
public function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);
}
/**
* Default method
*
* @author AvB
**/
public function index()
{
echo "You've loaded the Sophos module!";
}
/**
* Get Sophos for serial_number
*
* @param string $serial serial number
**/
public function get_data($serial = '')
{
$out = [];
if (! $this->authorized()) {
$out['error'] = 'Not authorized';
} else {
$prm = new Sophos_model;
foreach ($prm->retrieve_records($serial) as $sophos) {
$out = $sophos->rs;
}
}
$obj = new View();
$obj->view('json', array('msg' => $out));
}
/**
* Get installation stats
*
* @return void
* @author rickheil
**/
public function get_sophos_install_stats()
{
$obj = new View();
if(! $this->authorized()) {
$obj->view('json', array('msg' => array('error' => 'Not authenticated')));
return;
}
$sophos_install_stats = new Sophos_model();
$out = [];
$out['stats'] = $sophos_install_stats->get_sophos_install_stats();
$obj->view('json', array('msg' => $out));
}
/**
* Get running stats
*
* @return void
* @author rickheil
**/
public function get_sophos_running_stats()
{
$obj = new View();
if(! $this->authorized()) {
$obj->view('json', array('msg' => array('error' => 'Not authenticated')));
return;
}
$sophos_running_stats = new Sophos_model();
$out = [];
$out['stats'] = $sophos_running_stats->get_sophos_running_stats();
$obj->view('json', array('msg' => $out));
}
/**
* Get product version stats
*
* @return void
* @author rickheil
**/
public function get_sophos_product_version_stats()
{
if(! $this->authorized()) {
$obj->view('json', array('msg' => array('error' => 'Not authenticated')));
return;
}
$sophos_product_version_stats = new Sophos_model();
$sql = "SELECT count(1) as count, product_version
FROM sophos
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY product_version
ORDER BY product_version DESC";
$out = [];
foreach ($sophos_product_version_stats->query($sql) as $obj) {
$obj->product_version = $obj->product_version ? $obj->product_version : '0';
$out[] = array('label' => $obj->product_version, 'count' => intval($obj->count));
}
$obj = new View();
$obj->view('json', array('msg' => $out));
}
/**
* Get engine version stats
*
* @return void
* @author rickheil
**/
public function get_sophos_engine_version_stats()
{
if(! $this->authorized()) {
$obj->view('json', array('msg' => array('error' => 'Not authenticated')));
return;
}
$sophos_engine_version_stats = new Sophos_model();
$sql = "SELECT count(1) as count, engine_version
FROM sophos
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY engine_version
ORDER BY engine_version DESC";
$out = [];
foreach ($sophos_engine_version_stats->query($sql) as $obj) {
$obj->engine_version = $obj->engine_version ? $obj->engine_version : '0';
$out[] = array('label' => $obj->engine_version, 'count' => intval($obj->count));
}
$obj = new View();
$obj->view('json', array('msg' => $out));
}
/**
* Get virus data version stats
*
* @return void
* @author rickheil
**/
public function get_sophos_virus_data_version_stats()
{
if(! $this->authorized()) {
$obj->view('json', array('msg' => array('error' => 'Not authenticated')));
return;
}
$sophos_virus_data_version_stats = new Sophos_model();
$sql = "SELECT count(1) as count, virus_data_version
FROM sophos
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY virus_data_version
ORDER BY virus_data_version DESC";
$out = [];
foreach ($sophos_virus_data_version_stats->query($sql) as $obj) {
$obj->virus_data_version = $obj->virus_data_version ? $obj->virus_data_version : '0';
$out[] = array('label' => $obj->virus_data_version, 'count' => intval($obj->count));
}
$obj = new View();
$obj->view('json', array('msg' => $out));
}
/**
* Get user interface version stats
*
* @return void
* @author rickheil
**/
public function get_sophos_user_interface_version_stats()
{
if(! $this->authorized()) {
$obj->view('json', array('msg' => array('error' => 'Not authenticated')));
return;
}
$sophos_user_interface_version_stats = new Sophos_model();
$sql = "SELECT count(1) as count, user_interface_version
FROM sophos
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
GROUP BY user_interface_version
ORDER BY user_interface_version DESC";
$out = [];
foreach ($sophos_user_interface_version_stats->query($sql) as $obj) {
$obj->user_interface_version = $obj->user_interface_version ? $obj->user_interface_version : '0';
$out[] = array('label' => $obj->user_interface_version, 'count' => intval($obj->count));
}
$obj = new View();
$obj->view('json', array('msg' => $out));
}
}