|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin v6.0.0-beta.33 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Base controller class. |
|
13
|
|
|
* |
|
14
|
|
|
* @package PHPPgAdmin |
|
15
|
|
|
*/ |
|
16
|
|
|
class ServersController extends BaseController |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
use ServersTrait; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
public $controller_name = 'ServersController'; |
|
22
|
|
|
public $table_place = 'servers-servers'; |
|
23
|
|
|
public $section = 'servers'; |
|
24
|
|
|
public $query = ''; |
|
25
|
|
|
public $subject = ''; |
|
26
|
|
|
public $start_time; |
|
27
|
|
|
public $duration; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Default method to render the controller according to the action parameter. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function render() |
|
33
|
|
|
{ |
|
34
|
|
|
$lang = $this->lang; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$action = $this->action; |
|
37
|
|
|
|
|
38
|
|
|
if ('tree' == $action) { |
|
39
|
|
|
return $this->doTree(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$msg = $this->msg; |
|
43
|
|
|
|
|
44
|
|
|
$server_html = $this->printHeader($this->lang['strservers'], null, false); |
|
45
|
|
|
$server_html .= $this->printBody(false); |
|
46
|
|
|
$server_html .= $this->printTrail('root', false); |
|
47
|
|
|
|
|
48
|
|
|
ob_start(); |
|
49
|
|
|
switch ($action) { |
|
50
|
|
|
case 'logout': |
|
51
|
|
|
$this->doLogout(); |
|
52
|
|
|
|
|
53
|
|
|
break; |
|
54
|
|
|
default: |
|
55
|
|
|
$this->doDefault($msg); |
|
56
|
|
|
|
|
57
|
|
|
break; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$server_html .= ob_get_clean(); |
|
61
|
|
|
|
|
62
|
|
|
$server_html .= $this->printFooter(false); |
|
63
|
|
|
|
|
64
|
|
|
if (null === $this->container->requestobj->getAttribute('route')) { |
|
65
|
|
|
echo $server_html; |
|
66
|
|
|
} else { |
|
67
|
|
|
$body = $this->container->responseobj->getBody(); |
|
68
|
|
|
$body->write($server_html); |
|
69
|
|
|
|
|
70
|
|
|
return $this->container->responseobj; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function doDefault($msg = '') |
|
75
|
|
|
{ |
|
76
|
|
|
$lang = $this->lang; |
|
77
|
|
|
|
|
78
|
|
|
$this->printTabs('root', 'servers'); |
|
79
|
|
|
$this->printMsg($msg); |
|
80
|
|
|
$group = isset($_GET['group']) ? $_GET['group'] : false; |
|
81
|
|
|
|
|
82
|
|
|
$groups = $this->getServersGroups(true, $group); |
|
83
|
|
|
$columns = [ |
|
84
|
|
|
'group' => [ |
|
85
|
|
|
'title' => $lang['strgroup'], |
|
86
|
|
|
'field' => Decorator::field('desc'), |
|
87
|
|
|
'url' => 'servers?', |
|
88
|
|
|
'vars' => ['group' => 'id'], |
|
89
|
|
|
], |
|
90
|
|
|
]; |
|
91
|
|
|
$actions = []; |
|
92
|
|
|
if ( |
|
|
|
|
|
|
93
|
|
|
(false !== $group) && |
|
|
|
|
|
|
94
|
|
|
(isset($this->conf['srv_groups'][$group])) && |
|
|
|
|
|
|
95
|
|
|
($groups->recordCount() > 0) |
|
|
|
|
|
|
96
|
|
|
) { |
|
97
|
|
|
$this->printTitle(sprintf($lang['strgroupgroups'], htmlentities($this->conf['srv_groups'][$group]['desc'], ENT_QUOTES, 'UTF-8'))); |
|
98
|
|
|
echo $this->printTable($groups, $columns, $actions, $this->table_place); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$servers = $this->getServers(true, $group); |
|
102
|
|
|
|
|
103
|
|
|
$columns = [ |
|
104
|
|
|
'server' => [ |
|
105
|
|
|
'title' => $lang['strserver'], |
|
106
|
|
|
'field' => Decorator::field('desc'), |
|
107
|
|
|
'url' => \SUBFOLDER . '/redirect/server?', |
|
108
|
|
|
'vars' => ['server' => 'sha'], |
|
109
|
|
|
], |
|
110
|
|
|
'host' => [ |
|
111
|
|
|
'title' => $lang['strhost'], |
|
112
|
|
|
'field' => Decorator::field('host'), |
|
113
|
|
|
], |
|
114
|
|
|
'port' => [ |
|
115
|
|
|
'title' => $lang['strport'], |
|
116
|
|
|
'field' => Decorator::field('port'), |
|
117
|
|
|
], |
|
118
|
|
|
'username' => [ |
|
119
|
|
|
'title' => $lang['strusername'], |
|
120
|
|
|
'field' => Decorator::field('username'), |
|
121
|
|
|
], |
|
122
|
|
|
'actions' => [ |
|
123
|
|
|
'title' => $lang['stractions'], |
|
124
|
|
|
], |
|
125
|
|
|
]; |
|
126
|
|
|
|
|
127
|
|
|
$actions = [ |
|
128
|
|
|
'logout' => [ |
|
129
|
|
|
'content' => $lang['strlogout'], |
|
130
|
|
|
'attr' => [ |
|
131
|
|
|
'href' => [ |
|
132
|
|
|
'url' => 'servers', |
|
133
|
|
|
'urlvars' => [ |
|
134
|
|
|
'action' => 'logout', |
|
135
|
|
|
'logoutServer' => Decorator::field('id'), |
|
136
|
|
|
], |
|
137
|
|
|
], |
|
138
|
|
|
], |
|
139
|
|
|
], |
|
140
|
|
|
]; |
|
141
|
|
|
|
|
142
|
|
|
$svPre = function (&$rowdata) use ($actions) { |
|
143
|
|
|
$actions['logout']['disable'] = empty($rowdata->fields['username']); |
|
144
|
|
|
|
|
145
|
|
|
return $actions; |
|
146
|
|
|
}; |
|
147
|
|
|
|
|
148
|
|
|
if ( |
|
|
|
|
|
|
149
|
|
|
(false !== $group) && |
|
|
|
|
|
|
150
|
|
|
isset($this->conf['srv_groups'][$group]) |
|
|
|
|
|
|
151
|
|
|
) { |
|
152
|
|
|
$this->printTitle(sprintf($lang['strgroupservers'], htmlentities($this->conf['srv_groups'][$group]['desc'], ENT_QUOTES, 'UTF-8')), null); |
|
153
|
|
|
$actions['logout']['attr']['href']['urlvars']['group'] = $group; |
|
154
|
|
|
} |
|
155
|
|
|
echo $this->printTable($servers, $columns, $actions, $this->table_place, $lang['strnoobjects'], $svPre); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function doTree() |
|
159
|
|
|
{ |
|
160
|
|
|
$nodes = []; |
|
161
|
|
|
$group_id = isset($_GET['group']) ? $_GET['group'] : false; |
|
162
|
|
|
|
|
163
|
|
|
// root with srv_groups |
|
164
|
|
|
if (isset($this->conf['srv_groups']) and count($this->conf['srv_groups']) > 0 |
|
165
|
|
|
and false === $group_id) { |
|
|
|
|
|
|
166
|
|
|
$nodes = $this->getServersGroups(true); |
|
167
|
|
|
} elseif (isset($this->conf['srv_groups']) and false !== $group_id) { |
|
168
|
|
|
// group subtree |
|
169
|
|
|
if ('all' !== $group_id) { |
|
170
|
|
|
$nodes = $this->getServersGroups(false, $group_id); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
$nodes = array_merge($nodes, $this->getServers(false, $group_id)); |
|
|
|
|
|
|
174
|
|
|
$nodes = new \PHPPgAdmin\ArrayRecordSet($nodes); |
|
175
|
|
|
} else { |
|
176
|
|
|
// no srv_group |
|
177
|
|
|
$nodes = $this->getServers(true, false); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$reqvars = $this->misc->getRequestVars('server'); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
//$this->prtrace($reqvars); |
|
183
|
|
|
|
|
184
|
|
|
$attrs = [ |
|
185
|
|
|
'text' => Decorator::field('desc'), |
|
186
|
|
|
// Show different icons for logged in/out |
|
187
|
|
|
'icon' => Decorator::field('icon'), |
|
188
|
|
|
'toolTip' => Decorator::field('id'), |
|
189
|
|
|
'action' => Decorator::field('action'), |
|
190
|
|
|
// Only create a branch url if the user has |
|
191
|
|
|
// logged into the server. |
|
192
|
|
|
'branch' => Decorator::field('branch'), |
|
193
|
|
|
]; |
|
194
|
|
|
/*$this->prtrace([ |
|
195
|
|
|
'nodes' => $nodes, |
|
196
|
|
|
'attrs' => $attrs, |
|
197
|
|
|
'section' => $this->section, |
|
198
|
|
|
]);*/ |
|
199
|
|
|
return $this->printTree($nodes, $attrs, $this->section); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function doLogout() |
|
203
|
|
|
{ |
|
204
|
|
|
$plugin_manager = $this->plugin_manager; |
|
205
|
|
|
$lang = $this->lang; |
|
206
|
|
|
$this->misc = $this->misc; |
|
207
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
208
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
$plugin_manager->do_hook('logout', $_REQUEST['logoutServer']); |
|
211
|
|
|
|
|
212
|
|
|
$server_info = $this->misc->getServerInfo($_REQUEST['logoutServer']); |
|
213
|
|
|
$this->misc->setServerInfo(null, null, $_REQUEST['logoutServer']); |
|
214
|
|
|
|
|
215
|
|
|
unset($_SESSION['sharedUsername'], $_SESSION['sharedPassword']); |
|
216
|
|
|
|
|
217
|
|
|
$this->misc->setReloadBrowser(true); |
|
218
|
|
|
|
|
219
|
|
|
echo sprintf($lang['strlogoutmsg'], $server_info['desc']); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Get list of server groups. |
|
224
|
|
|
* |
|
225
|
|
|
* @param bool $recordset return as RecordSet suitable for HTMLTableController::printTable if true, otherwise just return an array |
|
226
|
|
|
* @param mixed $group_id a group name to filter the returned servers using $this->conf[srv_groups] |
|
227
|
|
|
* |
|
228
|
|
|
* @return array|\PHPPgAdmin\ArrayRecordSet either an array or a Recordset suitable for HTMLTableController::printTable |
|
229
|
|
|
*/ |
|
230
|
|
|
private function getServersGroups($recordset = false, $group_id = false) |
|
|
|
|
|
|
231
|
|
|
{ |
|
232
|
|
|
$lang = $this->lang; |
|
233
|
|
|
$grps = []; |
|
234
|
|
|
|
|
235
|
|
|
if (isset($this->conf['srv_groups'])) { |
|
236
|
|
|
foreach ($this->conf['srv_groups'] as $i => $group) { |
|
237
|
|
|
if ( |
|
|
|
|
|
|
238
|
|
|
(($group_id === false) and (!isset($group['parents']))) /* root */ |
|
|
|
|
|
|
239
|
|
|
or ( |
|
240
|
|
|
($group_id !== false) |
|
|
|
|
|
|
241
|
|
|
and isset($group['parents']) |
|
|
|
|
|
|
242
|
|
|
and in_array($group_id, explode( |
|
|
|
|
|
|
243
|
|
|
',', |
|
244
|
|
|
preg_replace('/\s/', '', $group['parents']) |
|
245
|
|
|
), true) |
|
|
|
|
|
|
246
|
|
|
) /* nested group */ |
|
|
|
|
|
|
247
|
|
|
) { |
|
248
|
|
|
$grps[$i] = [ |
|
249
|
|
|
'id' => $i, |
|
250
|
|
|
'desc' => $group['desc'], |
|
251
|
|
|
'icon' => 'Servers', |
|
252
|
|
|
'action' => Decorator::url( |
|
253
|
|
|
'servers', |
|
254
|
|
|
[ |
|
255
|
|
|
'group' => Decorator::field('id'), |
|
256
|
|
|
] |
|
257
|
|
|
), |
|
258
|
|
|
'branch' => Decorator::url( |
|
259
|
|
|
'servers', |
|
260
|
|
|
[ |
|
261
|
|
|
'action' => 'tree', |
|
262
|
|
|
'group' => $i, |
|
263
|
|
|
] |
|
264
|
|
|
), |
|
265
|
|
|
]; |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
if ($group_id === false) { |
|
270
|
|
|
$grps['all'] = [ |
|
271
|
|
|
'id' => 'all', |
|
272
|
|
|
'desc' => $lang['strallservers'], |
|
273
|
|
|
'icon' => 'Servers', |
|
274
|
|
|
'action' => Decorator::url( |
|
275
|
|
|
'servers', |
|
276
|
|
|
[ |
|
277
|
|
|
'group' => Decorator::field('id'), |
|
278
|
|
|
] |
|
279
|
|
|
), |
|
280
|
|
|
'branch' => Decorator::url( |
|
281
|
|
|
'servers', |
|
282
|
|
|
[ |
|
283
|
|
|
'action' => 'tree', |
|
284
|
|
|
'group' => 'all', |
|
285
|
|
|
] |
|
286
|
|
|
), |
|
287
|
|
|
]; |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
if ($recordset) { |
|
292
|
|
|
return new \PHPPgAdmin\ArrayRecordSet($grps); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
return $grps; |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
|