forked from munkireport/fan_temps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfan_temps_controller.php
205 lines (182 loc) · 5.93 KB
/
fan_temps_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
<?php
/**
* Fan_temps_controller class
*
* @package fan_temps
* @author tuxudo
**/
class Fan_temps_controller extends Module_controller
{
function __construct()
{
$this->module_path = dirname(__FILE__);
}
/**
* Default method
*
* @author AvB
**/
function index()
{
echo "You've loaded the fan_temps module!";
}
/**
* Retrieve GPU overtemp in json format
*
* @return void
* @author tuxudo
**/
public function get_gpu_overtemp()
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$queryobj = new Fan_temps_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `sght` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `sght` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve fans manually set in json format
*
* @return void
* @author tuxudo
**/
public function get_fan_manually()
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$queryobj = new Fan_temps_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `fnfd` = '2' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `fnfd` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve CPU hot in json format
*
* @return void
* @author tuxudo
**/
public function get_cpu_hot()
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$queryobj = new Fan_temps_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `spht` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `spht` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve disc inserted in json format
*
* @return void
* @author tuxudo
**/
public function get_odd_inserted()
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$queryobj = new Fan_temps_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `msdi` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `msdi` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve bad fans in json format
*
* @return void
* @author tuxudo
**/
public function get_bad_fans()
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$queryobj = new Fan_temps_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `mssf` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `mssf` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve data in json format for client tab
*
* @return void
* @author tuxudo
**/
public function get_tab_data($serial_number = '')
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$queryobj = new Fan_temps_model();
$sql = "SELECT json_info FROM fan_temps WHERE serial_number = '$serial_number'";
$fan_temps_tab = $queryobj->query($sql);
// Extract just the JSON string and make it an object
$data_json = json_decode(json_decode(json_encode($fan_temps_tab[0]),true)['json_info']);
if(!is_null($data_json)){
// Add the temperature type to the object for the client tab
if(!conf('temperature_unit')){
$data_json->TEMPERATURE_UNIT = "C";
} else {
$data_json->TEMPERATURE_UNIT = conf('temperature_unit');
}
}
$obj->view('json', array('msg' => current(array('msg' => $data_json))));
}
/**
* Retrieve data in json format
*
* @return void
* @author tuxudo
**/
public function get_data($serial_number = '')
{
$obj = new View();
if (! $this->authorized()) {
$obj->view('json', array('msg' => 'Not authorized'));
return;
}
$fan_temps = new Fan_temps_model;
$obj->view('json', array('msg' => $fan_temps->retrieve_records($serial_number)));
}
} // End class Fan_temps_controller