|
1
|
|
|
<?php |
|
2
|
|
|
// This is an extension to the LumenerController@index function |
|
3
|
|
|
|
|
4
|
|
|
global $lumener_controller; |
|
5
|
|
|
$lumener_controller = $this; |
|
6
|
|
|
function adminer_object() |
|
7
|
|
|
{ |
|
8
|
|
|
global $lumener_controller; |
|
9
|
|
|
function adminer_ob_flush() |
|
10
|
|
|
{ |
|
11
|
|
|
// Nothing to do |
|
12
|
|
|
} |
|
13
|
|
|
function adminer_ob_end_clean() |
|
14
|
|
|
{ |
|
15
|
|
|
// Nothing to do |
|
16
|
|
|
} |
|
17
|
|
|
$plugins = []; |
|
18
|
|
|
$plugin_file = $lumener_controller->getPluginsPath().'/plugin.php'; |
|
19
|
|
|
if (file_exists($plugin_file)) { |
|
20
|
|
|
// required to run any plugin |
|
21
|
|
|
include_once $plugin_file; |
|
22
|
|
|
|
|
23
|
|
|
// autoloader |
|
24
|
|
|
foreach (glob($lumener_controller->getPluginsPath()."/*.php") as $filename) { |
|
25
|
|
|
include_once $filename; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// specify enabled plugins here |
|
29
|
|
|
$enabled = config('lumener.adminer.plugins.enabled'); |
|
30
|
|
|
if ($enabled) { |
|
31
|
|
|
foreach ($enabled as $name => $arguments) { |
|
32
|
|
|
$reflector = new ReflectionClass($name); |
|
33
|
|
|
$plugins[] = $reflector->newInstanceArgs($arguments); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (empty($plugins)) { |
|
39
|
|
|
class_alias("Adminer", "ADMBase"); |
|
40
|
|
|
} else { |
|
41
|
|
|
class_alias("AdminerPlugin", "ADMBase"); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
class Lumener extends ADMBase |
|
45
|
|
|
{ |
|
46
|
|
|
public function name() |
|
47
|
|
|
{ |
|
48
|
|
|
// custom name in title and heading |
|
49
|
|
|
return config('lumener.name', 'Lumener'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function permanentLogin($j = false) |
|
53
|
|
|
{ |
|
54
|
|
|
// key used for permanent login |
|
55
|
|
|
$key = config('lumener.adminer_perma_key'); |
|
56
|
|
|
if ($key) { |
|
57
|
|
|
return $key; |
|
58
|
|
|
} |
|
59
|
|
|
return parent::permanentLogin($j); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function credentials() |
|
63
|
|
|
{ |
|
64
|
|
|
// server, username and password for connecting to database |
|
65
|
|
|
if (config('lumener.auto_login')) { |
|
66
|
|
|
$host = config('lumener.db.host', env("DB_HOST")); |
|
67
|
|
|
$port = config('lumener.db.port', env("DB_PORT")); |
|
68
|
|
|
$username = config('lumener.db.username', env("DB_USERNAME")); |
|
69
|
|
|
$password = config('lumener.db.password', env("DB_PASSWORD")); |
|
70
|
|
|
return array("{$host}:{$port}", $username, $password); |
|
71
|
|
|
} |
|
72
|
|
|
return parent::credentials(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function css() |
|
76
|
|
|
{ |
|
77
|
|
|
global $lumener_controller; |
|
78
|
|
|
$theme = LUMENER_STORAGE.'/adminer.css'; |
|
79
|
|
|
if (file_exists($theme)) { |
|
80
|
|
|
return [$lumener_controller->getRequest()->getPathInfo() |
|
81
|
|
|
.'/resources?file=adminer%2Ecss&type=text%2Fcss']; |
|
82
|
|
|
} |
|
83
|
|
|
return []; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function login($login, $password) |
|
87
|
|
|
{ |
|
88
|
|
|
$allowed_users = config('lumener.security.allowed_users'); |
|
89
|
|
|
$protected_users = config('lumener.security.protected_users'); |
|
90
|
|
|
if ( |
|
91
|
|
|
(!empty($allowed_users) && !in_array($login, $allowed_users)) |
|
92
|
|
|
||!empty($protected_users) && in_array($login, $protected_users) |
|
93
|
|
|
) { |
|
94
|
|
|
abort(403); |
|
95
|
|
|
} |
|
96
|
|
|
return config('lumener.auto_login') |
|
97
|
|
|
|| parent::login($login, $password); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function csp() |
|
101
|
|
|
{ |
|
102
|
|
|
if (defined("LUMENER_CSP")) { |
|
103
|
|
|
return LUMENER_CSP; |
|
104
|
|
|
} |
|
105
|
|
|
return parent::csp(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function database() |
|
109
|
|
|
{ |
|
110
|
|
|
// For Adminer Editor |
|
111
|
|
|
return config('lumener.db.database', env("DB_DATABASE")); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function tableName($tableStatus) |
|
115
|
|
|
{ |
|
116
|
|
|
$hidden = config('lumener.security.hidden_tables', []); |
|
117
|
|
|
$name = $tableStatus['Name']; |
|
118
|
|
|
if (!in_array($name, $hidden)) { |
|
119
|
|
|
return $name; |
|
120
|
|
|
} |
|
121
|
|
|
return ""; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
// User extensions |
|
126
|
|
|
$ext = config('lumener.adminer.extension_file'); |
|
127
|
|
|
if (file_exists($ext)) { |
|
128
|
|
|
return require($ext); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
if (empty($plugins)) { |
|
132
|
|
|
return new Lumener(); |
|
133
|
|
|
} |
|
134
|
|
|
return new Lumener($plugins); |
|
135
|
|
|
} |
|
136
|
|
|
|