-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsmart_stats_controller.php
More file actions
113 lines (99 loc) · 3.72 KB
/
Copy pathsmart_stats_controller.php
File metadata and controls
113 lines (99 loc) · 3.72 KB
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
<?php
/**
* Smart_stats_controller class
*
* @package smart_stats
* @author tuxudo
**/
class Smart_stats_controller extends Module_controller
{
function __construct()
{
$this->module_path = dirname(__FILE__);
}
/**
* Default method
*
* @author AvB
**/
function index()
{
echo "You've loaded the smart_stats module!";
}
/**
* Get data for SSD Service Program widget
* https://www.apple.com/support/13-inch-macbook-pro-solid-state-drive-service-program/
* Research done by @eholtam/@poundbangbash
*
* @return void
* @author tuxudo
**/
public function ssd_service_check()
{
$sql = "SELECT COUNT(
CASE WHEN `firmware_version` = 'CXS4JA0Q' AND (SUBSTRING(`serial_number`, 4, 1) = 'V'
OR SUBSTRING(`serial_number`, 4, 1) = 'W')
THEN 1 END) AS 'unfixed',
COUNT(
CASE WHEN `firmware_version` = 'CXS4LA0Q' AND (SUBSTRING(`serial_number`, 4, 1) = 'V'
OR SUBSTRING(`serial_number`, 4, 1) = 'W')
THEN 1 END) AS 'fixed',
COUNT(
CASE WHEN (`firmware_version` = 'CXS4JA0Q' OR `firmware_version` = 'CXS4LA0Q') AND SUBSTRING(`serial_number`, 4, 1) <> 'V'
AND SUBSTRING(`serial_number`, 4, 1) <> 'W'
THEN 1 END) AS 'not_affected'
FROM smart_stats
LEFT JOIN reportdata USING (serial_number)
WHERE `model_number` = 'APPLE SSD SM0256L'
".get_machine_group_filter('AND');
$out = [];
$queryobj = new Smart_stats_model();
foreach($queryobj->query($sql)[0] as $label => $value){
$out[] = ['label' => $label, 'count' => $value];
}
jsonView($out);
}
/**
* Get SMART pass/fail/unknown for widget
*
* @return void
* @author tuxudo
**/
public function get_smart_stats()
{
$sql = "SELECT COUNT(CASE WHEN overall_health='PASSED' THEN 1 END) AS passed,
COUNT(CASE WHEN overall_health='UNKNOWN!' THEN 1 END) AS unknown,
COUNT(CASE WHEN overall_health='FAILED!' THEN 1 END) AS failed
FROM smart_stats
LEFT JOIN reportdata USING(serial_number)
".get_machine_group_filter();
$out = [];
$queryobj = new Smart_stats_model();
foreach($queryobj->query($sql)[0] as $label => $value){
$out[] = ['label' => $label, 'count' => $value];
}
jsonView($out);
}
/**
* Retrieve data in json format for client tab
*
* @return void
* @author tuxudo
**/
public function get_client_tab_data($serial_number = '')
{
// Remove non-serial number characters
$serial_number = preg_replace("/[^A-Za-z0-9_\-]]/", '', $serial_number);
$sql = "SELECT * FROM smart_stats WHERE serial_number = '$serial_number' ORDER BY disk_number";
$obj = new View();
$queryobj = new Smart_stats_model();
$smart_stats_tab = $queryobj->query($sql);
// Add the temperature type to the object for the client tab
$array_id = (count($smart_stats_tab) -1 );
while ($array_id > -1) {
$smart_stats_tab[$array_id]->temperature_unit = env('TEMPERATURE_UNIT', "C");
$array_id--;
}
$obj->view('json', array('msg' => current(array('msg' => $smart_stats_tab))));
}
} // END class Smart_stats_controller