1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin 6.1.3 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
8
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base controller class. |
13
|
|
|
*/ |
14
|
|
|
class RolesController extends BaseController |
15
|
|
|
{ |
16
|
|
|
public $controller_title = 'strroles'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Default method to render the controller according to the action parameter. |
20
|
|
|
*/ |
21
|
|
|
public function render(): void |
22
|
|
|
{ |
23
|
|
|
$this->printHeader(); |
24
|
|
|
$this->printBody(); |
25
|
|
|
|
26
|
|
|
switch ($this->action) { |
27
|
|
|
case 'create': |
28
|
|
|
$this->doCreate(); |
29
|
|
|
|
30
|
|
|
break; |
31
|
|
|
case 'save_create': |
32
|
|
|
if (null !== $this->getPostParam('create')) { |
33
|
|
|
$this->doSaveCreate(); |
34
|
|
|
} else { |
35
|
|
|
$this->doDefault(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
break; |
39
|
|
|
case 'alter': |
40
|
|
|
$this->doAlter(); |
41
|
|
|
|
42
|
|
|
break; |
43
|
|
|
case 'save_alter': |
44
|
|
|
if (null !== $this->getPostParam('alter')) { |
45
|
|
|
$this->doSaveAlter(); |
46
|
|
|
} else { |
47
|
|
|
$this->doDefault(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
break; |
51
|
|
|
case 'confirm_drop': |
52
|
|
|
$this->doDrop(true); |
53
|
|
|
|
54
|
|
|
break; |
55
|
|
|
case 'drop': |
56
|
|
|
if (null !== $this->getPostParam('drop')) { |
57
|
|
|
$this->doDrop(false); |
58
|
|
|
} else { |
59
|
|
|
$this->doDefault(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
break; |
63
|
|
|
case 'properties': |
64
|
|
|
$this->doProperties(); |
65
|
|
|
|
66
|
|
|
break; |
67
|
|
|
case 'confchangepassword': |
68
|
|
|
$this->doChangePassword(true); |
69
|
|
|
|
70
|
|
|
break; |
71
|
|
|
case 'changepassword': |
72
|
|
|
if (isset($_REQUEST['ok'])) { |
73
|
|
|
$this->doChangePassword(false); |
74
|
|
|
} else { |
75
|
|
|
$this->doAccount(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
break; |
79
|
|
|
case 'account': |
80
|
|
|
$this->doAccount(); |
81
|
|
|
|
82
|
|
|
break; |
83
|
|
|
|
84
|
|
|
default: |
85
|
|
|
$this->doDefault(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->printFooter(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Show default list of roles in the database. |
93
|
|
|
* |
94
|
|
|
* @param mixed $msg |
95
|
|
|
*/ |
96
|
|
|
public function doDefault($msg = ''): void |
97
|
|
|
{ |
98
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
99
|
|
|
|
100
|
|
|
$lang = $this->lang; |
101
|
|
|
$renderRoleConnLimit = static function ($val) use ($lang) { |
102
|
|
|
return '-1' === $val ? $lang['strnolimit'] : \htmlspecialchars($val); |
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
$renderRoleExpires = static function ($val) use ($lang) { |
106
|
|
|
return 'infinity' === $val ? $lang['strnever'] : \htmlspecialchars($val); |
107
|
|
|
}; |
108
|
|
|
|
109
|
|
|
$this->printTrail('server'); |
110
|
|
|
$this->printTabs('server', 'roles'); |
111
|
|
|
$this->printMsg($msg); |
112
|
|
|
|
113
|
|
|
$roles = $data->getRoles(); |
114
|
|
|
|
115
|
|
|
$columns = [ |
116
|
|
|
'role' => [ |
117
|
|
|
'title' => $this->lang['strrole'], |
118
|
|
|
'field' => Decorator::field('rolname'), |
119
|
|
|
'url' => \containerInstance()->subFolder . "/redirect/role?action=properties&{$this->misc->href}&", |
120
|
|
|
'vars' => ['rolename' => 'rolname'], |
121
|
|
|
], |
122
|
|
|
'group' => [ |
123
|
|
|
'title' => $this->lang['strgroup'], |
124
|
|
|
'field' => Decorator::field('group'), |
125
|
|
|
], |
126
|
|
|
'superuser' => [ |
127
|
|
|
'title' => $this->lang['strsuper'], |
128
|
|
|
'field' => Decorator::field('rolsuper'), |
129
|
|
|
'type' => 'yesno', |
130
|
|
|
], |
131
|
|
|
'createdb' => [ |
132
|
|
|
'title' => $this->lang['strcreatedb'], |
133
|
|
|
'field' => Decorator::field('rolcreatedb'), |
134
|
|
|
'type' => 'yesno', |
135
|
|
|
], |
136
|
|
|
'createrole' => [ |
137
|
|
|
'title' => $this->lang['strcancreaterole'], |
138
|
|
|
'field' => Decorator::field('rolcreaterole'), |
139
|
|
|
'type' => 'yesno', |
140
|
|
|
], |
141
|
|
|
'inherits' => [ |
142
|
|
|
'title' => $this->lang['strinheritsprivs'], |
143
|
|
|
'field' => Decorator::field('rolinherit'), |
144
|
|
|
'type' => 'yesno', |
145
|
|
|
], |
146
|
|
|
'canloging' => [ |
147
|
|
|
'title' => $this->lang['strcanlogin'], |
148
|
|
|
'field' => Decorator::field('rolcanlogin'), |
149
|
|
|
'type' => 'yesno', |
150
|
|
|
], |
151
|
|
|
'connlimit' => [ |
152
|
|
|
'title' => $this->lang['strconnlimit'], |
153
|
|
|
'field' => Decorator::field('rolconnlimit'), |
154
|
|
|
'type' => 'callback', |
155
|
|
|
'params' => ['function' => $renderRoleConnLimit], |
156
|
|
|
], |
157
|
|
|
'expires' => [ |
158
|
|
|
'title' => $this->lang['strexpires'], |
159
|
|
|
'field' => Decorator::field('rolvaliduntil'), |
160
|
|
|
'type' => 'callback', |
161
|
|
|
'params' => ['function' => $renderRoleExpires, 'null' => $this->lang['strnever']], |
162
|
|
|
], |
163
|
|
|
'actions' => [ |
164
|
|
|
'title' => $this->lang['stractions'], |
165
|
|
|
], |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
$actions = [ |
169
|
|
|
'alter' => [ |
170
|
|
|
'content' => $this->lang['stralter'], |
171
|
|
|
'attr' => [ |
172
|
|
|
'href' => [ |
173
|
|
|
'url' => 'roles', |
174
|
|
|
'urlvars' => [ |
175
|
|
|
'action' => 'alter', |
176
|
|
|
'rolename' => Decorator::field('rolname'), |
177
|
|
|
], |
178
|
|
|
], |
179
|
|
|
], |
180
|
|
|
], |
181
|
|
|
'drop' => [ |
182
|
|
|
'content' => $this->lang['strdrop'], |
183
|
|
|
'attr' => [ |
184
|
|
|
'href' => [ |
185
|
|
|
'url' => 'roles', |
186
|
|
|
'urlvars' => [ |
187
|
|
|
'action' => 'confirm_drop', |
188
|
|
|
'rolename' => Decorator::field('rolname'), |
189
|
|
|
], |
190
|
|
|
], |
191
|
|
|
], |
192
|
|
|
], |
193
|
|
|
]; |
194
|
|
|
|
195
|
|
|
echo $this->printTable($roles, $columns, $actions, 'roles-roles', $this->lang['strnoroles']); |
196
|
|
|
|
197
|
|
|
$navlinks = [ |
198
|
|
|
'create' => [ |
199
|
|
|
'attr' => [ |
200
|
|
|
'href' => [ |
201
|
|
|
'url' => 'roles', |
202
|
|
|
'urlvars' => [ |
203
|
|
|
'action' => 'create', |
204
|
|
|
'server' => $_REQUEST['server'], |
205
|
|
|
], |
206
|
|
|
], |
207
|
|
|
], |
208
|
|
|
'content' => $this->lang['strcreaterole'], |
209
|
|
|
], |
210
|
|
|
]; |
211
|
|
|
$this->printNavLinks($navlinks, 'roles-roles', \get_defined_vars()); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Displays a screen for create a new role. |
216
|
|
|
* |
217
|
|
|
* @param mixed $msg |
218
|
|
|
*/ |
219
|
|
|
public function doCreate($msg = ''): void |
220
|
|
|
{ |
221
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
222
|
|
|
|
223
|
|
|
$this->coalesceArr($_POST, 'formRolename', ''); |
224
|
|
|
|
225
|
|
|
$this->coalesceArr($_POST, 'formPassword', ''); |
226
|
|
|
|
227
|
|
|
$this->coalesceArr($_POST, 'formConfirm', ''); |
228
|
|
|
|
229
|
|
|
$this->coalesceArr($_POST, 'formConnLimit', ''); |
230
|
|
|
|
231
|
|
|
$this->coalesceArr($_POST, 'formExpires', ''); |
232
|
|
|
|
233
|
|
|
$this->coalesceArr($_POST, 'memberof', []); |
234
|
|
|
|
235
|
|
|
$this->coalesceArr($_POST, 'members', []); |
236
|
|
|
|
237
|
|
|
$this->coalesceArr($_POST, 'adminmembers', []); |
238
|
|
|
|
239
|
|
|
$this->printTrail('role'); |
240
|
|
|
$this->printTitle($this->lang['strcreaterole'], 'pg.role.create'); |
241
|
|
|
$this->printMsg($msg); |
242
|
|
|
|
243
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
244
|
|
|
echo '<table>' . \PHP_EOL; |
245
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\" style=\"width: 130px\">{$this->lang['strname']}</th>" . \PHP_EOL; |
246
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"15\" maxlength=\"{$data->_maxNameLen}\" name=\"formRolename\" value=\"", \htmlspecialchars($_POST['formRolename']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
|
|
|
|
247
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strpassword']}</th>" . \PHP_EOL; |
248
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"15\" type=\"password\" name=\"formPassword\" value=\"", \htmlspecialchars($_POST['formPassword']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
249
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strconfirm']}</th>" . \PHP_EOL; |
250
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"15\" type=\"password\" name=\"formConfirm\" value=\"", \htmlspecialchars($_POST['formConfirm']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
251
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formSuper\">{$this->lang['strsuper']}</label></th>" . \PHP_EOL; |
252
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formSuper\" name=\"formSuper\"", |
253
|
|
|
(isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
254
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateDB\">{$this->lang['strcreatedb']}</label></th>" . \PHP_EOL; |
255
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateDB\" name=\"formCreateDB\"", |
256
|
|
|
(isset($_POST['formCreateDB'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
257
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateRole\">{$this->lang['strcancreaterole']}</label></th>" . \PHP_EOL; |
258
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateRole\" name=\"formCreateRole\"", |
259
|
|
|
(isset($_POST['formCreateRole'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
260
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formInherits\">{$this->lang['strinheritsprivs']}</label></th>" . \PHP_EOL; |
261
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formInherits\" name=\"formInherits\"", |
262
|
|
|
(isset($_POST['formInherits'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
263
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCanLogin\">{$this->lang['strcanlogin']}</label></th>" . \PHP_EOL; |
264
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCanLogin\" name=\"formCanLogin\"", |
265
|
|
|
(isset($_POST['formCanLogin'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
266
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strconnlimit']}</th>" . \PHP_EOL; |
267
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"4\" name=\"formConnLimit\" value=\"", \htmlspecialchars($_POST['formConnLimit']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
268
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strexpires']}</th>" . \PHP_EOL; |
269
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"23\" name=\"formExpires\" value=\"", \htmlspecialchars($_POST['formExpires']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
270
|
|
|
|
271
|
|
|
$roles = $data->getRoles(); |
272
|
|
|
|
273
|
|
|
if (0 < $roles->recordCount()) { |
274
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strmemberof']}</th>" . \PHP_EOL; |
275
|
|
|
echo "\t\t<td class=\"data\">" . \PHP_EOL; |
276
|
|
|
echo "\t\t\t<select name=\"memberof[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
277
|
|
|
|
278
|
|
|
while (!$roles->EOF) { |
279
|
|
|
$rolename = $roles->fields['rolname']; |
280
|
|
|
echo "\t\t\t\t<option value=\"{$rolename}\"", |
281
|
|
|
(\in_array($rolename, $_POST['memberof'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
282
|
|
|
$roles->moveNext(); |
283
|
|
|
} |
284
|
|
|
echo "\t\t\t</select>" . \PHP_EOL; |
285
|
|
|
echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
286
|
|
|
|
287
|
|
|
$roles->moveFirst(); |
288
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strmembers']}</th>" . \PHP_EOL; |
289
|
|
|
echo "\t\t<td class=\"data\">" . \PHP_EOL; |
290
|
|
|
echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
291
|
|
|
|
292
|
|
|
while (!$roles->EOF) { |
293
|
|
|
$rolename = $roles->fields['rolname']; |
294
|
|
|
echo "\t\t\t\t<option value=\"{$rolename}\"", |
295
|
|
|
(\in_array($rolename, $_POST['members'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
296
|
|
|
$roles->moveNext(); |
297
|
|
|
} |
298
|
|
|
echo "\t\t\t</select>" . \PHP_EOL; |
299
|
|
|
echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
300
|
|
|
|
301
|
|
|
$roles->moveFirst(); |
302
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['stradminmembers']}</th>" . \PHP_EOL; |
303
|
|
|
echo "\t\t<td class=\"data\">" . \PHP_EOL; |
304
|
|
|
echo "\t\t\t<select name=\"adminmembers[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
305
|
|
|
|
306
|
|
|
while (!$roles->EOF) { |
307
|
|
|
$rolename = $roles->fields['rolname']; |
308
|
|
|
echo "\t\t\t\t<option value=\"{$rolename}\"", |
309
|
|
|
(\in_array($rolename, $_POST['adminmembers'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
310
|
|
|
$roles->moveNext(); |
311
|
|
|
} |
312
|
|
|
echo "\t\t\t</select>" . \PHP_EOL; |
313
|
|
|
echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
echo '</table>' . \PHP_EOL; |
317
|
|
|
echo '<p><input type="hidden" name="action" value="save_create" />' . \PHP_EOL; |
318
|
|
|
echo $this->view->form; |
319
|
|
|
echo "<input type=\"submit\" name=\"create\" value=\"{$this->lang['strcreate']}\" />" . \PHP_EOL; |
320
|
|
|
echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
321
|
|
|
echo '</form>' . \PHP_EOL; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Actually creates the new role in the database. |
326
|
|
|
*/ |
327
|
|
|
public function doSaveCreate(): void |
328
|
|
|
{ |
329
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
330
|
|
|
|
331
|
|
|
$this->coalesceArr($_POST, 'memberof', []); |
332
|
|
|
|
333
|
|
|
$this->coalesceArr($_POST, 'members', []); |
334
|
|
|
|
335
|
|
|
$this->coalesceArr($_POST, 'adminmembers', []); |
336
|
|
|
|
337
|
|
|
// Check data |
338
|
|
|
if ('' === $_POST['formRolename']) { |
339
|
|
|
$this->doCreate($this->lang['strroleneedsname']); |
340
|
|
|
} elseif ($_POST['formPassword'] !== $_POST['formConfirm']) { |
341
|
|
|
$this->doCreate($this->lang['strpasswordconfirm']); |
342
|
|
|
} else { |
343
|
|
|
$status = $data->createRole( |
344
|
|
|
$_POST['formRolename'], |
345
|
|
|
$_POST['formPassword'], |
346
|
|
|
isset($_POST['formSuper']), |
347
|
|
|
isset($_POST['formCreateDB']), |
348
|
|
|
isset($_POST['formCreateRole']), |
349
|
|
|
isset($_POST['formInherits']), |
350
|
|
|
isset($_POST['formCanLogin']), |
351
|
|
|
$_POST['formConnLimit'], |
352
|
|
|
$_POST['formExpires'], |
353
|
|
|
$_POST['memberof'], |
354
|
|
|
$_POST['members'], |
355
|
|
|
$_POST['adminmembers'] |
356
|
|
|
); |
357
|
|
|
|
358
|
|
|
if (0 === $status) { |
359
|
|
|
$this->doDefault($this->lang['strrolecreated']); |
360
|
|
|
} else { |
361
|
|
|
$this->doCreate($this->lang['strrolecreatedbad']); |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Function to allow alter a role. |
368
|
|
|
* |
369
|
|
|
* @param mixed $msg |
370
|
|
|
*/ |
371
|
|
|
public function doAlter($msg = ''): void |
372
|
|
|
{ |
373
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
374
|
|
|
|
375
|
|
|
$this->printTrail('role'); |
376
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.role.alter'); |
377
|
|
|
$this->printMsg($msg); |
378
|
|
|
|
379
|
|
|
$roledata = $data->getRole($_REQUEST['rolename']); |
380
|
|
|
|
381
|
|
|
if (0 >= $roledata->recordCount()) { |
382
|
|
|
echo "<p>{$this->lang['strnodata']}</p>" . \PHP_EOL; |
383
|
|
|
|
384
|
|
|
return; |
385
|
|
|
} |
386
|
|
|
$server_info = $this->misc->getServerInfo(); |
387
|
|
|
$canRename = $data->hasUserRename() && ($_REQUEST['rolename'] !== $server_info['username']); |
388
|
|
|
$roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
389
|
|
|
$roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
390
|
|
|
$roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
391
|
|
|
$roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
392
|
|
|
$roledata->fields['rolcanlogin'] = $data->phpBool($roledata->fields['rolcanlogin']); |
393
|
|
|
|
394
|
|
|
$this->_adjustPostVars($roledata, $canRename); |
|
|
|
|
395
|
|
|
|
396
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
397
|
|
|
echo '<table>' . \PHP_EOL; |
398
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\" style=\"width: 130px\">{$this->lang['strname']}</th>" . \PHP_EOL; |
399
|
|
|
echo "\t\t<td class=\"data1\">", ($canRename ? "<input name=\"formNewRoleName\" size=\"15\" maxlength=\"{$data->_maxNameLen}\" value=\"" . \htmlspecialchars($_POST['formNewRoleName']) . '" />' : $this->misc->printVal($roledata->fields['rolname'])), "</td>\n\t</tr>" . \PHP_EOL; |
|
|
|
|
400
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strpassword']}</th>" . \PHP_EOL; |
401
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"password\" size=\"15\" name=\"formPassword\" value=\"", \htmlspecialchars($_POST['formPassword']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
402
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strconfirm']}</th>" . \PHP_EOL; |
403
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"password\" size=\"15\" name=\"formConfirm\" value=\"\" /></td>\n\t</tr>" . \PHP_EOL; |
404
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formSuper\">{$this->lang['strsuper']}</label></th>" . \PHP_EOL; |
405
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formSuper\" name=\"formSuper\"", |
406
|
|
|
(isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
407
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateDB\">{$this->lang['strcreatedb']}</label></th>" . \PHP_EOL; |
408
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateDB\" name=\"formCreateDB\"", |
409
|
|
|
(isset($_POST['formCreateDB'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
410
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCreateRole\">{$this->lang['strcancreaterole']}</label></th>" . \PHP_EOL; |
411
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateRole\" name=\"formCreateRole\"", |
412
|
|
|
(isset($_POST['formCreateRole'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
413
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formInherits\">{$this->lang['strinheritsprivs']}</label></th>" . \PHP_EOL; |
414
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formInherits\" name=\"formInherits\"", |
415
|
|
|
(isset($_POST['formInherits'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
416
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\"><label for=\"formCanLogin\">{$this->lang['strcanlogin']}</label></th>" . \PHP_EOL; |
417
|
|
|
echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCanLogin\" name=\"formCanLogin\"", |
418
|
|
|
(isset($_POST['formCanLogin'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
419
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strconnlimit']}</th>" . \PHP_EOL; |
420
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"4\" name=\"formConnLimit\" value=\"", \htmlspecialchars($_POST['formConnLimit']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
421
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strexpires']}</th>" . \PHP_EOL; |
422
|
|
|
echo "\t\t<td class=\"data1\"><input size=\"23\" name=\"formExpires\" value=\"", \htmlspecialchars($_POST['formExpires']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
423
|
|
|
|
424
|
|
|
$this->_populateMemberof($data); |
425
|
|
|
$memberofold = \implode(',', $_POST['memberof']); |
426
|
|
|
|
427
|
|
|
$this->_populateMembers($data); |
428
|
|
|
$membersold = \implode(',', $_POST['members']); |
429
|
|
|
|
430
|
|
|
$this->_populateAdminmembers($data); |
431
|
|
|
$adminmembersold = \implode(',', $_POST['adminmembers']); |
432
|
|
|
|
433
|
|
|
$roles = $data->getRoles($_REQUEST['rolename']); |
434
|
|
|
|
435
|
|
|
if (0 < $roles->recordCount()) { |
436
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strmemberof']}</th>" . \PHP_EOL; |
437
|
|
|
echo "\t\t<td class=\"data\">" . \PHP_EOL; |
438
|
|
|
echo "\t\t\t<select name=\"memberof[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
439
|
|
|
|
440
|
|
|
while (!$roles->EOF) { |
441
|
|
|
$rolename = $roles->fields['rolname']; |
442
|
|
|
echo "\t\t\t\t<option value=\"{$rolename}\"", |
443
|
|
|
(\in_array($rolename, $_POST['memberof'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
444
|
|
|
$roles->moveNext(); |
445
|
|
|
} |
446
|
|
|
echo "\t\t\t</select>" . \PHP_EOL; |
447
|
|
|
echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
448
|
|
|
|
449
|
|
|
$roles->moveFirst(); |
450
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strmembers']}</th>" . \PHP_EOL; |
451
|
|
|
echo "\t\t<td class=\"data\">" . \PHP_EOL; |
452
|
|
|
echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
453
|
|
|
|
454
|
|
|
while (!$roles->EOF) { |
455
|
|
|
$rolename = $roles->fields['rolname']; |
456
|
|
|
echo "\t\t\t\t<option value=\"{$rolename}\"", |
457
|
|
|
(\in_array($rolename, $_POST['members'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
458
|
|
|
$roles->moveNext(); |
459
|
|
|
} |
460
|
|
|
echo "\t\t\t</select>" . \PHP_EOL; |
461
|
|
|
echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
462
|
|
|
|
463
|
|
|
$roles->moveFirst(); |
464
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['stradminmembers']}</th>" . \PHP_EOL; |
465
|
|
|
echo "\t\t<td class=\"data\">" . \PHP_EOL; |
466
|
|
|
echo "\t\t\t<select name=\"adminmembers[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
467
|
|
|
|
468
|
|
|
while (!$roles->EOF) { |
469
|
|
|
$rolename = $roles->fields['rolname']; |
470
|
|
|
echo "\t\t\t\t<option value=\"{$rolename}\"", |
471
|
|
|
(\in_array($rolename, $_POST['adminmembers'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
472
|
|
|
$roles->moveNext(); |
473
|
|
|
} |
474
|
|
|
echo "\t\t\t</select>" . \PHP_EOL; |
475
|
|
|
echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
476
|
|
|
} |
477
|
|
|
echo '</table>' . \PHP_EOL; |
478
|
|
|
|
479
|
|
|
echo '<p><input type="hidden" name="action" value="save_alter" />' . \PHP_EOL; |
480
|
|
|
echo '<input type="hidden" name="rolename" value="', \htmlspecialchars($_REQUEST['rolename']), '" />' . \PHP_EOL; |
481
|
|
|
echo '<input type="hidden" name="memberofold" value="', $_POST['memberofold'] ?? \htmlspecialchars($memberofold), '" />' . \PHP_EOL; |
482
|
|
|
echo '<input type="hidden" name="membersold" value="', $_POST['membersold'] ?? \htmlspecialchars($membersold), '" />' . \PHP_EOL; |
483
|
|
|
echo '<input type="hidden" name="adminmembersold" value="', $_POST['adminmembersold'] ?? \htmlspecialchars($adminmembersold), '" />' . \PHP_EOL; |
484
|
|
|
echo $this->view->form; |
485
|
|
|
echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />" . \PHP_EOL; |
486
|
|
|
echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
487
|
|
|
echo '</form>' . \PHP_EOL; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Function to save after editing a role. |
492
|
|
|
*/ |
493
|
|
|
public function doSaveAlter(): void |
494
|
|
|
{ |
495
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
496
|
|
|
|
497
|
|
|
$this->coalesceArr($_POST, 'memberof', []); |
498
|
|
|
|
499
|
|
|
$this->coalesceArr($_POST, 'members', []); |
500
|
|
|
|
501
|
|
|
$this->coalesceArr($_POST, 'adminmembers', []); |
502
|
|
|
|
503
|
|
|
// Check name and password |
504
|
|
|
if (isset($_POST['formNewRoleName']) && '' === $_POST['formNewRoleName']) { |
505
|
|
|
$this->doAlter($this->lang['strroleneedsname']); |
506
|
|
|
} elseif ($_POST['formPassword'] !== $_POST['formConfirm']) { |
507
|
|
|
$this->doAlter($this->lang['strpasswordconfirm']); |
508
|
|
|
} else { |
509
|
|
|
if (isset($_POST['formNewRoleName'])) { |
510
|
|
|
$status = $data->setRenameRole($_POST['rolename'], $_POST['formPassword'], isset($_POST['formSuper']), isset($_POST['formCreateDB']), isset($_POST['formCreateRole']), isset($_POST['formInherits']), isset($_POST['formCanLogin']), $_POST['formConnLimit'], $_POST['formExpires'], $_POST['memberof'], $_POST['members'], $_POST['adminmembers'], $_POST['memberofold'], $_POST['membersold'], $_POST['adminmembersold'], $_POST['formNewRoleName']); |
|
|
|
|
511
|
|
|
} else { |
512
|
|
|
$status = $data->setRole($_POST['rolename'], $_POST['formPassword'], isset($_POST['formSuper']), isset($_POST['formCreateDB']), isset($_POST['formCreateRole']), isset($_POST['formInherits']), isset($_POST['formCanLogin']), $_POST['formConnLimit'], $_POST['formExpires'], $_POST['memberof'], $_POST['members'], $_POST['adminmembers'], $_POST['memberofold'], $_POST['membersold'], $_POST['adminmembersold']); |
|
|
|
|
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
if (0 === $status) { |
516
|
|
|
$this->doDefault($this->lang['strrolealtered']); |
517
|
|
|
} else { |
518
|
|
|
$this->doAlter($this->lang['strrolealteredbad']); |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Show confirmation of drop a role and perform actual drop. |
525
|
|
|
* |
526
|
|
|
* @param mixed $confirm |
527
|
|
|
*/ |
528
|
|
|
public function doDrop($confirm): void |
529
|
|
|
{ |
530
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
531
|
|
|
|
532
|
|
|
if ($confirm) { |
533
|
|
|
$this->printTrail('role'); |
534
|
|
|
$this->printTitle($this->lang['strdroprole'], 'pg.role.drop'); |
535
|
|
|
|
536
|
|
|
echo '<p>', \sprintf($this->lang['strconfdroprole'], $this->misc->printVal($_REQUEST['rolename'])), '</p>' . \PHP_EOL; |
537
|
|
|
|
538
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
539
|
|
|
echo '<p><input type="hidden" name="action" value="drop" />' . \PHP_EOL; |
540
|
|
|
echo '<input type="hidden" name="rolename" value="', \htmlspecialchars($_REQUEST['rolename']), '" />' . \PHP_EOL; |
541
|
|
|
echo $this->view->form; |
542
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />" . \PHP_EOL; |
543
|
|
|
echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
544
|
|
|
echo '</form>' . \PHP_EOL; |
545
|
|
|
} else { |
546
|
|
|
$status = $data->dropRole($_REQUEST['rolename']); |
547
|
|
|
|
548
|
|
|
if (0 === $status) { |
549
|
|
|
$this->doDefault($this->lang['strroledropped']); |
550
|
|
|
} else { |
551
|
|
|
$this->doDefault($this->lang['strroledroppedbad']); |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Show the properties of a role. |
558
|
|
|
* |
559
|
|
|
* @param mixed $msg |
560
|
|
|
*/ |
561
|
|
|
public function doProperties($msg = ''): void |
562
|
|
|
{ |
563
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
564
|
|
|
|
565
|
|
|
$this->printTrail('role'); |
566
|
|
|
$this->printTitle($this->lang['strproperties'], 'pg.role'); |
567
|
|
|
$this->printMsg($msg); |
568
|
|
|
|
569
|
|
|
$roledata = $data->getRole($_REQUEST['rolename']); |
570
|
|
|
|
571
|
|
|
if (0 < $roledata->recordCount()) { |
572
|
|
|
$roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
573
|
|
|
$roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
574
|
|
|
$roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
575
|
|
|
$roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
576
|
|
|
$roledata->fields['rolcanlogin'] = $data->phpBool($roledata->fields['rolcanlogin']); |
577
|
|
|
|
578
|
|
|
echo '<table>' . \PHP_EOL; |
579
|
|
|
echo "\t<tr>\n\t\t<th class=\"data\" style=\"width: 130px\">Description</th>" . \PHP_EOL; |
580
|
|
|
echo "\t\t<th class=\"data\" style=\"width: 120\">Value</th>\n\t</tr>" . \PHP_EOL; |
581
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">{$this->lang['strname']}</td>" . \PHP_EOL; |
582
|
|
|
echo "\t\t<td class=\"data1\">", \htmlspecialchars($_REQUEST['rolename']), "</td>\n\t</tr>" . \PHP_EOL; |
583
|
|
|
echo "\t<tr>\n\t\t<td class=\"data2\">{$this->lang['strsuper']}</td>" . \PHP_EOL; |
584
|
|
|
echo "\t\t<td class=\"data2\">", (($roledata->fields['rolsuper']) ? $this->lang['stryes'] : $this->lang['strno']), "</td>\n\t</tr>" . \PHP_EOL; |
585
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">{$this->lang['strcreatedb']}</td>" . \PHP_EOL; |
586
|
|
|
echo "\t\t<td class=\"data1\">", (($roledata->fields['rolcreatedb']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
587
|
|
|
echo "\t<tr>\n\t\t<td class=\"data2\">{$this->lang['strcancreaterole']}</td>" . \PHP_EOL; |
588
|
|
|
echo "\t\t<td class=\"data2\">", (($roledata->fields['rolcreaterole']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
589
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">{$this->lang['strinheritsprivs']}</td>" . \PHP_EOL; |
590
|
|
|
echo "\t\t<td class=\"data1\">", (($roledata->fields['rolinherit']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
591
|
|
|
echo "\t<tr>\n\t\t<td class=\"data2\">{$this->lang['strcanlogin']}</td>" . \PHP_EOL; |
592
|
|
|
echo "\t\t<td class=\"data2\">", (($roledata->fields['rolcanlogin']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
593
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">{$this->lang['strconnlimit']}</td>" . \PHP_EOL; |
594
|
|
|
echo "\t\t<td class=\"data1\">", ('-1' === $roledata->fields['rolconnlimit'] ? $this->lang['strnolimit'] : $this->misc->printVal($roledata->fields['rolconnlimit'])), '</td>' . \PHP_EOL; |
|
|
|
|
595
|
|
|
echo "\t<tr>\n\t\t<td class=\"data2\">{$this->lang['strexpires']}</td>" . \PHP_EOL; |
596
|
|
|
echo "\t\t<td class=\"data2\">", ('infinity' === $roledata->fields['rolvaliduntil'] || null === $roledata->fields['rolvaliduntil'] ? $this->lang['strnever'] : $this->misc->printVal($roledata->fields['rolvaliduntil'])), '</td>' . \PHP_EOL; |
|
|
|
|
597
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">{$this->lang['strsessiondefaults']}</td>" . \PHP_EOL; |
598
|
|
|
echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolconfig']), '</td>' . \PHP_EOL; |
599
|
|
|
echo "\t<tr>\n\t\t<td class=\"data2\">{$this->lang['strmemberof']}</td>" . \PHP_EOL; |
600
|
|
|
echo "\t\t<td class=\"data2\">"; |
601
|
|
|
$memberof = $data->getMemberOf($_REQUEST['rolename']); |
602
|
|
|
|
603
|
|
|
if (0 < $memberof->recordCount()) { |
604
|
|
|
while (!$memberof->EOF) { |
605
|
|
|
echo $this->misc->printVal($memberof->fields['rolname']), '<br />' . \PHP_EOL; |
606
|
|
|
$memberof->moveNext(); |
607
|
|
|
} |
608
|
|
|
} |
609
|
|
|
echo "</td>\n\t</tr>" . \PHP_EOL; |
610
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">{$this->lang['strmembers']}</td>" . \PHP_EOL; |
611
|
|
|
echo "\t\t<td class=\"data1\">"; |
612
|
|
|
$members = $data->getMembers($_REQUEST['rolename']); |
613
|
|
|
|
614
|
|
|
if (0 < $members->recordCount()) { |
615
|
|
|
while (!$members->EOF) { |
616
|
|
|
echo $this->misc->printVal($members->fields['rolname']), '<br />' . \PHP_EOL; |
617
|
|
|
$members->moveNext(); |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
echo "</td>\n\t</tr>" . \PHP_EOL; |
621
|
|
|
echo "\t<tr>\n\t\t<td class=\"data2\">{$this->lang['stradminmembers']}</td>" . \PHP_EOL; |
622
|
|
|
echo "\t\t<td class=\"data2\">"; |
623
|
|
|
$adminmembers = $data->getMembers($_REQUEST['rolename'], 't'); |
624
|
|
|
|
625
|
|
|
if (0 < $adminmembers->recordCount()) { |
626
|
|
|
while (!$adminmembers->EOF) { |
627
|
|
|
echo $this->misc->printVal($adminmembers->fields['rolname']), '<br />' . \PHP_EOL; |
628
|
|
|
$adminmembers->moveNext(); |
629
|
|
|
} |
630
|
|
|
} |
631
|
|
|
echo "</td>\n\t</tr>" . \PHP_EOL; |
632
|
|
|
echo '</table>' . \PHP_EOL; |
633
|
|
|
} else { |
634
|
|
|
echo "<p>{$this->lang['strnodata']}</p>" . \PHP_EOL; |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
$navlinks = [ |
638
|
|
|
'showall' => [ |
639
|
|
|
'attr' => [ |
640
|
|
|
'href' => [ |
641
|
|
|
'url' => 'roles', |
642
|
|
|
'urlvars' => [ |
643
|
|
|
'server' => $_REQUEST['server'], |
644
|
|
|
], |
645
|
|
|
], |
646
|
|
|
], |
647
|
|
|
'content' => $this->lang['strshowallroles'], |
648
|
|
|
], |
649
|
|
|
'alter' => [ |
650
|
|
|
'attr' => [ |
651
|
|
|
'href' => [ |
652
|
|
|
'url' => 'roles', |
653
|
|
|
'urlvars' => [ |
654
|
|
|
'action' => 'alter', |
655
|
|
|
'server' => $_REQUEST['server'], |
656
|
|
|
'rolename' => $_REQUEST['rolename'], |
657
|
|
|
], |
658
|
|
|
], |
659
|
|
|
], |
660
|
|
|
'content' => $this->lang['stralter'], |
661
|
|
|
], |
662
|
|
|
'drop' => [ |
663
|
|
|
'attr' => [ |
664
|
|
|
'href' => [ |
665
|
|
|
'url' => 'roles', |
666
|
|
|
'urlvars' => [ |
667
|
|
|
'action' => 'confirm_drop', |
668
|
|
|
'server' => $_REQUEST['server'], |
669
|
|
|
'rolename' => $_REQUEST['rolename'], |
670
|
|
|
], |
671
|
|
|
], |
672
|
|
|
], |
673
|
|
|
'content' => $this->lang['strdrop'], |
674
|
|
|
], |
675
|
|
|
]; |
676
|
|
|
|
677
|
|
|
$this->printNavLinks($navlinks, 'roles-properties', \get_defined_vars()); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* If a role is not a superuser role, then we have an 'account management' |
682
|
|
|
* page for change his password, etc. We don't prevent them from |
683
|
|
|
* messing with the URL to gain access to other role admin stuff, because |
684
|
|
|
* the PostgreSQL permissions will prevent them changing anything anyway. |
685
|
|
|
* |
686
|
|
|
* @param mixed $msg |
687
|
|
|
*/ |
688
|
|
|
public function doAccount($msg = ''): void |
689
|
|
|
{ |
690
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
691
|
|
|
|
692
|
|
|
$server_info = $this->misc->getServerInfo(); |
693
|
|
|
|
694
|
|
|
$roledata = $data->getRole($server_info['username']); |
695
|
|
|
$_REQUEST['rolename'] = $server_info['username']; |
696
|
|
|
|
697
|
|
|
$this->printTrail('role'); |
698
|
|
|
$this->printTabs('server', 'account'); |
699
|
|
|
$this->printMsg($msg); |
700
|
|
|
|
701
|
|
|
if (0 < $roledata->recordCount()) { |
702
|
|
|
$roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
703
|
|
|
$roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
704
|
|
|
$roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
705
|
|
|
$roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
706
|
|
|
echo '<table>' . \PHP_EOL; |
707
|
|
|
echo "\t<tr>\n\t\t<th class=\"data\">{$this->lang['strname']}</th>" . \PHP_EOL; |
708
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strsuper']}</th>" . \PHP_EOL; |
709
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strcreatedb']}</th>" . \PHP_EOL; |
710
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strcancreaterole']}</th>" . \PHP_EOL; |
711
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strinheritsprivs']}</th>" . \PHP_EOL; |
712
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strconnlimit']}</th>" . \PHP_EOL; |
713
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strexpires']}</th>" . \PHP_EOL; |
714
|
|
|
echo "\t\t<th class=\"data\">{$this->lang['strsessiondefaults']}</th>" . \PHP_EOL; |
715
|
|
|
echo "\t</tr>" . \PHP_EOL; |
716
|
|
|
echo "\t<tr>\n\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolname']), '</td>' . \PHP_EOL; |
717
|
|
|
echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolsuper'], 'yesno'), '</td>' . \PHP_EOL; |
718
|
|
|
echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolcreatedb'], 'yesno'), '</td>' . \PHP_EOL; |
719
|
|
|
echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolcreaterole'], 'yesno'), '</td>' . \PHP_EOL; |
720
|
|
|
echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolinherit'], 'yesno'), '</td>' . \PHP_EOL; |
721
|
|
|
echo "\t\t<td class=\"data1\">", ('-1' === $roledata->fields['rolconnlimit'] ? $this->lang['strnolimit'] : $this->misc->printVal($roledata->fields['rolconnlimit'])), '</td>' . \PHP_EOL; |
|
|
|
|
722
|
|
|
echo "\t\t<td class=\"data1\">", ('infinity' === $roledata->fields['rolvaliduntil'] || null === $roledata->fields['rolvaliduntil'] ? $this->lang['strnever'] : $this->misc->printVal($roledata->fields['rolvaliduntil'])), '</td>' . \PHP_EOL; |
|
|
|
|
723
|
|
|
echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolconfig']), '</td>' . \PHP_EOL; |
724
|
|
|
echo "\t</tr>\n</table>" . \PHP_EOL; |
725
|
|
|
} else { |
726
|
|
|
echo "<p>{$this->lang['strnodata']}</p>" . \PHP_EOL; |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
$this->printNavLinks(['changepassword' => [ |
730
|
|
|
'attr' => [ |
731
|
|
|
'href' => [ |
732
|
|
|
'url' => 'roles', |
733
|
|
|
'urlvars' => [ |
734
|
|
|
'action' => 'confchangepassword', |
735
|
|
|
'server' => $_REQUEST['server'], |
736
|
|
|
], |
737
|
|
|
], |
738
|
|
|
], |
739
|
|
|
'content' => $this->lang['strchangepassword'], |
740
|
|
|
]], 'roles-account', \get_defined_vars()); |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
/** |
744
|
|
|
* Show confirmation of change password and actually change password. |
745
|
|
|
* |
746
|
|
|
* @param mixed $confirm |
747
|
|
|
* @param mixed $msg |
748
|
|
|
*/ |
749
|
|
|
public function doChangePassword($confirm, $msg = ''): void |
750
|
|
|
{ |
751
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
752
|
|
|
|
753
|
|
|
$server_info = $this->misc->getServerInfo(); |
754
|
|
|
|
755
|
|
|
if ($confirm) { |
756
|
|
|
$_REQUEST['rolename'] = $server_info['username']; |
757
|
|
|
$this->printTrail('role'); |
758
|
|
|
$this->printTitle($this->lang['strchangepassword'], 'pg.role.alter'); |
759
|
|
|
$this->printMsg($msg); |
760
|
|
|
|
761
|
|
|
$this->coalesceArr($_POST, 'password', ''); |
762
|
|
|
|
763
|
|
|
$this->coalesceArr($_POST, 'confirm', ''); |
764
|
|
|
|
765
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
766
|
|
|
echo '<table>' . \PHP_EOL; |
767
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strpassword']}</th>" . \PHP_EOL; |
768
|
|
|
echo "\t\t<td><input type=\"password\" name=\"password\" size=\"32\" value=\"", |
769
|
|
|
\htmlspecialchars($_POST['password']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
770
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strconfirm']}</th>" . \PHP_EOL; |
771
|
|
|
echo "\t\t<td><input type=\"password\" name=\"confirm\" size=\"32\" value=\"\" /></td>\n\t</tr>" . \PHP_EOL; |
772
|
|
|
echo '</table>' . \PHP_EOL; |
773
|
|
|
echo '<p><input type="hidden" name="action" value="changepassword" />' . \PHP_EOL; |
774
|
|
|
echo $this->view->form; |
775
|
|
|
echo "<input type=\"submit\" name=\"ok\" value=\"{$this->lang['strok']}\" />" . \PHP_EOL; |
776
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />" . \PHP_EOL; |
777
|
|
|
echo '</p></form>' . \PHP_EOL; |
778
|
|
|
} else { |
779
|
|
|
// Check that password is minimum length |
780
|
|
|
if (\mb_strlen($_POST['password']) < $this->conf['min_password_length']) { |
781
|
|
|
$this->doChangePassword(true, $this->lang['strpasswordshort']); |
782
|
|
|
} elseif ($_POST['password'] !== $_POST['confirm']) { |
783
|
|
|
// Check that password matches confirmation password |
784
|
|
|
$this->doChangePassword(true, $this->lang['strpasswordconfirm']); |
785
|
|
|
} else { |
786
|
|
|
$status = $data->changePassword($server_info['username'], $_POST['password']); |
787
|
|
|
|
788
|
|
|
if (0 === $status) { |
789
|
|
|
$this->doAccount($this->lang['strpasswordchanged']); |
790
|
|
|
} else { |
791
|
|
|
$this->doAccount($this->lang['strpasswordchangedbad']); |
792
|
|
|
} |
793
|
|
|
} |
794
|
|
|
} |
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
/** |
798
|
|
|
* Adjusts the content of the $_POST superglobal according to role data. |
799
|
|
|
* |
800
|
|
|
* @param \ADORecordSet $roledata The roledata |
801
|
|
|
* @param bool $canRename Indicates if role can be renamed |
802
|
|
|
*/ |
803
|
|
|
private function _adjustPostVars($roledata, $canRename): void |
804
|
|
|
{ |
805
|
|
|
if (isset($_POST['formExpires'])) { |
806
|
|
|
return; |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
if ($canRename) { |
810
|
|
|
$_POST['formNewRoleName'] = $roledata->fields['rolname']; |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
if ($roledata->fields['rolsuper']) { |
814
|
|
|
$_POST['formSuper'] = ''; |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
if ($roledata->fields['rolcreatedb']) { |
818
|
|
|
$_POST['formCreateDB'] = ''; |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
if ($roledata->fields['rolcreaterole']) { |
822
|
|
|
$_POST['formCreateRole'] = ''; |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
if ($roledata->fields['rolinherit']) { |
826
|
|
|
$_POST['formInherits'] = ''; |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
if ($roledata->fields['rolcanlogin']) { |
830
|
|
|
$_POST['formCanLogin'] = ''; |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
$_POST['formConnLimit'] = '-1' === $roledata->fields['rolconnlimit'] ? '' : $roledata->fields['rolconnlimit']; |
834
|
|
|
$_POST['formExpires'] = 'infinity' === $roledata->fields['rolvaliduntil'] ? '' : $roledata->fields['rolvaliduntil']; |
835
|
|
|
$_POST['formPassword'] = ''; |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
private function _populateMemberof($data): void |
839
|
|
|
{ |
840
|
|
|
if (!isset($_POST['memberof'])) { |
841
|
|
|
$memberof = $data->getMemberOf($_REQUEST['rolename']); |
842
|
|
|
|
843
|
|
|
if (0 < $memberof->recordCount()) { |
844
|
|
|
$i = 0; |
845
|
|
|
|
846
|
|
|
while (!$memberof->EOF) { |
847
|
|
|
$_POST['memberof'][$i++] = $memberof->fields['rolname']; |
848
|
|
|
$memberof->moveNext(); |
849
|
|
|
} |
850
|
|
|
} else { |
851
|
|
|
$_POST['memberof'] = []; |
852
|
|
|
} |
853
|
|
|
} |
854
|
|
|
} |
855
|
|
|
|
856
|
|
|
private function _populateMembers($data): void |
857
|
|
|
{ |
858
|
|
|
if (!isset($_POST['members'])) { |
859
|
|
|
$members = $data->getMembers($_REQUEST['rolename']); |
860
|
|
|
|
861
|
|
|
if (0 < $members->recordCount()) { |
862
|
|
|
$i = 0; |
863
|
|
|
|
864
|
|
|
while (!$members->EOF) { |
865
|
|
|
$_POST['members'][$i++] = $members->fields['rolname']; |
866
|
|
|
$members->moveNext(); |
867
|
|
|
} |
868
|
|
|
} else { |
869
|
|
|
$_POST['members'] = []; |
870
|
|
|
} |
871
|
|
|
} |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
private function _populateAdminmembers($data): void |
875
|
|
|
{ |
876
|
|
|
if (!isset($_POST['adminmembers'])) { |
877
|
|
|
$adminmembers = $data->getMembers($_REQUEST['rolename'], 't'); |
878
|
|
|
|
879
|
|
|
if (0 < $adminmembers->recordCount()) { |
880
|
|
|
$i = 0; |
881
|
|
|
|
882
|
|
|
while (!$adminmembers->EOF) { |
883
|
|
|
$_POST['adminmembers'][$i++] = $adminmembers->fields['rolname']; |
884
|
|
|
$adminmembers->moveNext(); |
885
|
|
|
} |
886
|
|
|
} else { |
887
|
|
|
$_POST['adminmembers'] = []; |
888
|
|
|
} |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
} |
892
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.