forked from tariqbuilds/linux-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.php
90 lines (72 loc) · 2.05 KB
/
module.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
<?php
require 'libs/autoloader.php';
$available_modules = array(
'bandwidth',
'disk_partitions',
'dhcpleases',
'hostname',
'ip',
'issue',
'recent_account_logins',
'loadavg',
'current_ram',
'memcached',
'network_connections',
'numberofcores',
'logged_in_accounts',
'phpinfo',
'ping',
'ram_intensive_processes',
'cpu_intensive_processes',
'sabnzbd',
'internet_speed',
'swap',
'time',
'uptime',
'users',
'common_applications',
'arp_cache_table',
'redis_status',
'memory_info',
'cpu_info',
'io_stats',
);
/**
* Populate a module loader with our enabled modules
*/
$mods = new \ld\Modules\Loader;
$mods->defaultNamespace('\\Modules');
foreach($available_modules as $module) {
$mods->addModule($module);
}
/**
* If running on the terminal or via a script take the module name
* from the passed in arguments. Otherwise, take it from the HTTP request
*/
if (php_sapi_name() === 'cli') {
$requested_module = isset($argv[1]) ? $argv[1] : false;
} else {
$requested_module = isset($_GET['module']) ? $_GET['module'] : false;
}
// The default JSON object to return
$return = array(
'module' => $requested_module,
'data' => false,
'error' => false,
);
try {
if (!$requested_module || !$mods->moduleAvailable($requested_module)) {
throw new Exception('module_not_found');
}
$module = $mods->module($requested_module);
if (!$module) {
throw new Exception('error_loading_module');
}
$return['data'] = $module->getData($_GET);
unset($return['error']);
} catch (Exception $e) {
unset($return['data']);
$return['error'] = $e->getMessage();
}
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($return);