-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
208 lines (187 loc) · 4.32 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
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
<?php
/** @noinspection NullCoalescingOperatorCanBeUsedInspection can't be used on PHP 5.6 */
namespace SpiroAB\Isimo;
if(!isset($config))
{
/** @var \PHPDoc\config $config */
$config = (object) [];
if(file_exists(__DIR__ . '/config.php'))
{
$config = require __DIR__ . '/config.php';
}
}
if(!isset($url_token))
{
/** @var string $url_token */
$url_token = preg_replace('#.*/#', '', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
}
if(!isset($config->token) || empty($url_token) || $url_token !== $config->token)
{
header('HTTP/1.1 404 Not found');
exit;
}
header('Content-type: application/json');
/** @var \PHPDoc\report $data */
$data = (object) [];
$data->report = [];
$data->time = time();
// TODO: Get this dynamically
$data->client = 'isimo-standalone v1.0.6';
// Place holders
$data->software = 'php';
$data->version = '0.0.0';
// PHP Info
ob_start();
phpinfo();
$data->phpinfo = ob_get_clean();
if(isset($config->software))
{
$data->software = (string) $config->software;
}
// mysql
if(isset($config->dbname))
{
$data->mysql = [];
/** @var string $dbname */
$dbname = $config->dbname;
/** @var string $dbuser */
$dbuser = isset($config->dbuser) ? $config->dbuser : 'root';
/** @var string $dbpass */
$dbpass = isset($config->dbpass) ? $config->dbpass : NULL;
/** @var string $dbhost */
$dbhost = isset($config->dbhost) ? $config->dbhost : 'localhost';
try
{
/** @noinspection PhpFullyQualifiedNameUsageInspection no include of root scope */
$db = new \mysqli($dbhost, $dbuser, $dbpass);
$db->select_db($dbname);
$result = $db->query('SHOW VARIABLES');
while($row = $result->fetch_row())
{
/** @var string[] $row */
$data->mysql[$row[0]] = $row[1];
}
$result->close();
}
/** @noinspection PhpFullyQualifiedNameUsageInspection no include of root scope */
catch(\Exception $e)
{
$data->error[] = $e->getMessage();
}
}
//<editor-fold desc="Git">
$data->gitsha = NULL;
/** @var string[] $git_dirs */
$git_dirs = [
'',
dirname(__DIR__) . '/.git',
$_SERVER['DOCUMENT_ROOT'] . '/.git',
];
if(isset($config->gitdir))
{
$git_dirs[0] = $config->gitdir;
}
$git_dirs = array_unique(array_filter($git_dirs));
foreach($git_dirs as $git_dir)
{
if(!is_dir($git_dir))
{
continue;
}
if(!is_file($git_dir . '/HEAD'))
{
continue;
}
/** @var string $git_head */
$git_head = file_get_contents($git_dir . '/HEAD');
if(!$git_head)
{
continue;
}
$git_head = trim(substr($git_head, 4));
if(!$git_head)
{
continue;
}
if(!is_file($git_dir . '/' . $git_head))
{
continue;
}
/** @var string $git_ref */
$git_ref = file_get_contents($git_dir . '/' . $git_head);
if(!$git_ref)
{
continue;
}
$git_ref = trim($git_ref);
if(!$git_ref)
{
continue;
}
$data->gitsha = $git_ref;
break;
}
//</editor-fold>
//<editor-fold desc="Composer">
/** @var string[] $composer_dirs */
$composer_dirs = [
'',
dirname(__DIR__) . '/.git',
$_SERVER['DOCUMENT_ROOT'] . '/.git',
];
if(isset($config->composerdir))
{
$composer_dirs[0] = $config->composerdir;
}
$composer_dirs = array_unique(array_filter($composer_dirs));
foreach($composer_dirs as $composer_dir)
{
if(!file_exists($composer_dir . '/composer.lock'))
{
continue;
}
$data->composer_lock = file_get_contents($composer_dir . '/composer.lock');
$data->composer_json = file_get_contents($composer_dir . '/composer.json');
if(empty($config->version_package_name))
{
break;
}
/** @var \PHPDoc\composerLock $composer_lock */
$composer_lock = json_decode($data->composer_lock);
if(empty($composer_lock->packages) || !is_array($composer_lock->packages))
{
break;
}
foreach($composer_lock->packages as $composer_package)
{
if(empty($composer_package->name))
{
continue;
}
if(empty($composer_package->version))
{
continue;
}
if($composer_package->name !== $config->version_package_name)
{
continue;
}
$data->version = $composer_package->version;
}
break;
}
//</editor-fold>
if(isset($version))
{
/** @var string version */
$data->version = $version;
}
else if(file_exists(__DIR__ . '/version.php'))
{
$data->version = require __DIR__ . '/version.php';
}
if($data->version === '0.0.0')
{
unset($data->version);
}
echo json_encode($data, 128), PHP_EOL;