-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
136 lines (118 loc) · 3.08 KB
/
index.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
<?php
/*
* Created on 24/09/2008
*
* Main call to CNML services
*/
// Common Bootstrap
if (file_exists('common/config.php'))
include_once("common/config.php");
else
include_once("common/config.php.template");
include_once("common/misc.php");
$VERSION = '0.2.3';
function call_service($service) {
if (file_exists('services/'.$service.'.php'))
include_once('services/'.$service.'.php');
else {
header("Content-Type: text/plain");
echo "ERROR: Service $service unknown\n";
getHelp();
exit;
}
if (isset($_GET['info'])) {
header("Content-Type: text/plain");
if (function_exists($service.'_info'))
call_user_func($service.'_info');
else
echo "No information available for $service\n";
exit;
}
if (function_exists($service.'_main'))
call_user_func($service.'_main');
else
echo "ERROR: No main hook for $service\n";
}
function getServerInfo() {
global $VERSION;
global $SNPGraphServerId;
global $rootZone;
global $rrdtool_version;
global $CNMLSource;
header("Content-Type: text/plain");
echo "CNML services version $VERSION at ";
echo exec('uname -a');
echo "\n";
echo "Server id: $SNPGraphServerId\n";
echo "Root zone: $rootZone\n";
echo "CNML source: $CNMLSource\n";
echo "php version: ";
echo system('php -v');
echo "\n";
echo "rrdtool version: ";
echo exec("rrdtool|head -1|cut -f 2 -d' '");
echo " set to: $rrdtool_version \n";
echo "\n";
}
function getHelp() {
global $VERSION;
echo "CNML services\n";
echo "Version: ".$VERSION."\n";
echo "USAGE:\n" .
"index.php?call=[service][¶meter[=value]]\n" .
"\n" .
"services: help version phpinfo serverinfo [service]\n" .
" help\n" .
" this message\n" .
" version\n" .
" gets version information\n" .
" phpinfo\n" .
" gets php version information\n" .
" serverinfo\n" .
" gets server information\n" .
" [service]\n" .
" name of the CNML service\n" .
" optional parameters:\n" .
" info\n" .
" obtain the parameters & information of the service\n" .
"\n";
echo "Available services:\n";
$fservices = glob('services/*.php');
foreach ($fservices as $fservice)
$services[] .= basename($fservice,'.php');
echo implode('|',$services);
echo "\n\nServices description:\n\n";
foreach ($services as $service)
if (file_exists('services/'.$service.'.php')) {
include_once('services/'.$service.'.php');
if (function_exists($service.'_info')) {
echo "--------------------------------------------------------------\n";
call_user_func($service.'_info');
}
}
}
if (!isset($_GET['call'])) {
header("Content-Type: text/plain");
echo "ERROR: No service specified\n";
getHelp();
exit;
} else
$service = $_GET['call'];
switch ($service) {
case 'version':
header("Content-Type: text/plain");
echo $VERSION;
exit;
case 'help':
header("Content-Type: text/plain");
getHelp();
break;
case 'phpinfo':
echo phpinfo();
break;
case 'serverinfo':
echo getServerInfo();
break; default:
call_service($service);
}
?>