-
Notifications
You must be signed in to change notification settings - Fork 8
/
oneclick-login.php
92 lines (82 loc) · 2.71 KB
/
oneclick-login.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
<?php
/**
* Display a list of predefined database servers to login with just one click.
* Don't use this in production enviroment unless the access is restricted
*
* @link https://www.adminer.org/plugins/#use
* @author Gio Freitas, https://www.github.com/giofreitas
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
class OneClickLogin {
/** @access protected */
var $servers, $driver;
/**
*
* Set supported servers
* @param array $servers
* @param string $driver
*/
function __construct($servers, $driver = "server") {
$this->servers = $servers;
$this->driver = $driver;
}
function login($login, $password) {
// check if server is allowed
return isset($this->servers[SERVER]);
}
function databaseValues($server){
$databases = $server['databases'];
if(is_array($databases))
foreach($databases as $database => $name){
if(is_string($database))
continue;
unset($databases[$database]);
if(!isset($databases[$name]))
$databases[$name] = $name;
}
return $databases;
}
function loginForm() {
?>
</form>
<table>
<tr>
<th><?php echo lang('Server') ?></th>
<th><?php echo lang('User') ?></th>
<th><?php echo lang('Database') ?></th>
</tr>
<?php
foreach($this->servers as $host => $server):
$databases = isset($server['databases']) ? $server['databases'] : "";
if (!is_array($databases))
$databases = array($databases => $databases);
foreach(array_keys($databases) as $i => $database):
?>
<tr>
<?php if( $i === 0): ?>
<td style="vertical-align:middle" rowspan="<?php echo count($databases) ?>"><?php echo isset($server['label']) ? "{$server['label']} ($host)" : $host; ?></td>
<td style="vertical-align:middle" rowspan="<?php echo count($databases) ?>"><?php echo $server['username'] ?></td>
<?php endif; ?>
<td style="vertical-align:middle"><?php echo $databases[$database] ?></td>
<td>
<form action="" method="post">
<input type="hidden" name="auth[driver]" value="<?php echo $this->driver; ?>">
<input type="hidden" name="auth[server]" value="<?php echo $host; ?>">
<input type="hidden" name="auth[username]" value="<?php echo h($server["username"]); ?>">
<input type="hidden" name="auth[password]" value="<?php echo h($server["pass"]); ?>">
<input type='hidden' name="auth[db]" value="<?php echo h($database); ?>"/>
<input type='hidden' name="auth[permanent]" value="1"/>
<input type="submit" value="<?php echo lang('Enter'); ?>">
</form>
</td>
</tr>
<?php
endforeach;
endforeach;
?>
</table>
<form action="" method="post">
<?php
return true;
}
}