-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.php
85 lines (68 loc) · 2.29 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
<?php
// Redirect to HTTPS if HTTPS_REDIRECT is defined in environment variables
if (getenv('ADMINER_HTTPS_REDIRECT') === 'true' && (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off')) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
define('ASSETS_VERSION', '1');
if (empty($_GET['file'])) {
ob_start(function ($s) {
return preg_replace_callback('#(<(link|script)\s[^>]*(href|src)=")(adminer\.css|static/.+)(\?v=\d+)?"#U', function ($m) {
return $m[1] . '?file=' . urlencode($m[4]) . '&version=' . ASSETS_VERSION . '"';
}, $s);
}, 4096);
} elseif (preg_match('#^(default|adminer|static(/\w[\w.-]*)+)\.(\w+)\z#', $_GET['file'], $m)) {
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
header('HTTP/1.1 304 Not Modified');
exit;
}
header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('1 month')) . ' GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
$types = ['css' => 'text/css', 'js' => 'text/javascript', 'gif' => 'image/gif', 'png' => 'image/png'];
if (isset($types[$m[3]])) {
header('Content-Type: ' . $types[$m[3]]);
}
@readfile(__DIR__ . '/' . $_GET['file']);
exit;
}
function adminer_object()
{
$local = !isset($_SERVER['HTTP_X_FORWARDED_FOR'])
&& isset($_SERVER['REMOTE_ADDR'])
&& in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'], true);
include_once __DIR__ . '/plugins/plugin.php';
foreach (glob(__DIR__ . '/plugins/*.php') as $filename) {
include_once $filename;
}
$plugins = [
new AdminerDisableJush,
new AdminerAutocomplete,
new AdminerSaveMenuPos,
new AdminerRemoteColor,
new AdminerDumpJson,
new AdminerDumpPhpPrototype,
new AdminerTablesFilter,
];
if ($local) {
$plugins[] = new AdminerLoginWithoutCredentials;
}
if (getenv('ADMINER_SERVER') && getenv('ADMINER_USERNAME')) {
if (!isset($_GET['username'])) {
$_GET['username'] = '';
}
class AdminerCustomization extends AdminerPlugin
{
function credentials()
{
$server = getenv('ADMINER_SERVER');
$username = getenv('ADMINER_USERNAME');
$password = getenv('ADMINER_PASSWORD');
return [$server, $username, $password];
}
}
return new AdminerCustomization($plugins);
}
return new AdminerPlugin($plugins);
}
include __DIR__ . '/adminer.php';