| Total Complexity | 108 |
| Total Lines | 1125 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
Complex classes like RolesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RolesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class RolesController extends BaseController |
||
| 16 | { |
||
| 17 | public $controller_title = 'strroles'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Default method to render the controller according to the action parameter. |
||
| 21 | */ |
||
| 22 | public function render(): void |
||
| 23 | { |
||
| 24 | $this->printHeader(); |
||
| 25 | $this->printBody(); |
||
| 26 | |||
| 27 | switch ($this->action) { |
||
| 28 | case 'create': |
||
| 29 | $this->doCreate(); |
||
| 30 | |||
| 31 | break; |
||
| 32 | case 'save_create': |
||
| 33 | if (null !== $this->getPostParam('create')) { |
||
| 34 | $this->doSaveCreate(); |
||
| 35 | } else { |
||
| 36 | $this->doDefault(); |
||
| 37 | } |
||
| 38 | |||
| 39 | break; |
||
| 40 | case 'alter': |
||
| 41 | $this->doAlter(); |
||
| 42 | |||
| 43 | break; |
||
| 44 | case 'save_alter': |
||
| 45 | if (null !== $this->getPostParam('alter')) { |
||
| 46 | $this->doSaveAlter(); |
||
| 47 | } else { |
||
| 48 | $this->doDefault(); |
||
| 49 | } |
||
| 50 | |||
| 51 | break; |
||
| 52 | case 'confirm_drop': |
||
| 53 | $this->doDrop(true); |
||
| 54 | |||
| 55 | break; |
||
| 56 | case 'drop': |
||
| 57 | if (null !== $this->getPostParam('drop')) { |
||
| 58 | $this->doDrop(false); |
||
| 59 | } else { |
||
| 60 | $this->doDefault(); |
||
| 61 | } |
||
| 62 | |||
| 63 | break; |
||
| 64 | case 'properties': |
||
| 65 | $this->doProperties(); |
||
| 66 | |||
| 67 | break; |
||
| 68 | case 'confchangepassword': |
||
| 69 | $this->doChangePassword(true); |
||
| 70 | |||
| 71 | break; |
||
| 72 | case 'changepassword': |
||
| 73 | if (isset($_REQUEST['ok'])) { |
||
| 74 | $this->doChangePassword(false); |
||
| 75 | } else { |
||
| 76 | $this->doAccount(); |
||
| 77 | } |
||
| 78 | |||
| 79 | break; |
||
| 80 | case 'account': |
||
| 81 | $this->doAccount(); |
||
| 82 | |||
| 83 | break; |
||
| 84 | |||
| 85 | default: |
||
| 86 | $this->doDefault(); |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->printFooter(); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Show default list of roles in the database. |
||
| 94 | * |
||
| 95 | * @param mixed $msg |
||
| 96 | */ |
||
| 97 | public function doDefault($msg = ''): void |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Displays a screen for create a new role. |
||
| 220 | * |
||
| 221 | * @param mixed $msg |
||
| 222 | */ |
||
| 223 | public function doCreate($msg = ''): void |
||
| 224 | { |
||
| 225 | $data = $this->misc->getDatabaseAccessor(); |
||
| 226 | |||
| 227 | $this->coalesceArr($_POST, 'formRolename', ''); |
||
| 228 | |||
| 229 | $this->coalesceArr($_POST, 'formPassword', ''); |
||
| 230 | |||
| 231 | $this->coalesceArr($_POST, 'formConfirm', ''); |
||
| 232 | |||
| 233 | $this->coalesceArr($_POST, 'formConnLimit', ''); |
||
| 234 | |||
| 235 | $this->coalesceArr($_POST, 'formExpires', ''); |
||
| 236 | |||
| 237 | $this->coalesceArr($_POST, 'memberof', []); |
||
| 238 | |||
| 239 | $this->coalesceArr($_POST, 'members', []); |
||
| 240 | |||
| 241 | $this->coalesceArr($_POST, 'adminmembers', []); |
||
| 242 | |||
| 243 | $this->printTrail('role'); |
||
| 244 | $this->printTitle($this->lang['strcreaterole'], 'pg.role.create'); |
||
| 245 | $this->printMsg($msg); |
||
| 246 | |||
| 247 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
||
| 248 | echo '<table>' . \PHP_EOL; |
||
| 249 | echo \sprintf( |
||
| 250 | ' <tr> |
||
| 251 | <th class="data left required" style="width: 130px">%s</th>', |
||
| 252 | $this->lang['strname'] |
||
| 253 | ) . \PHP_EOL; |
||
| 254 | echo \sprintf( |
||
| 255 | ' <td class="data1"><input size="15" maxlength="%s" name="formRolename" value="', |
||
| 256 | $data->_maxNameLen |
||
| 257 | ), \htmlspecialchars($_POST['formRolename']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 258 | echo \sprintf( |
||
| 259 | ' <tr> |
||
| 260 | <th class="data left">%s</th>', |
||
| 261 | $this->lang['strpassword'] |
||
| 262 | ) . \PHP_EOL; |
||
| 263 | echo "\t\t<td class=\"data1\"><input size=\"15\" type=\"password\" name=\"formPassword\" value=\"", \htmlspecialchars($_POST['formPassword']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 264 | echo \sprintf( |
||
| 265 | ' <tr> |
||
| 266 | <th class="data left">%s</th>', |
||
| 267 | $this->lang['strconfirm'] |
||
| 268 | ) . \PHP_EOL; |
||
| 269 | echo "\t\t<td class=\"data1\"><input size=\"15\" type=\"password\" name=\"formConfirm\" value=\"", \htmlspecialchars($_POST['formConfirm']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 270 | echo \sprintf( |
||
| 271 | ' <tr> |
||
| 272 | <th class="data left"><label for="formSuper">%s</label></th>', |
||
| 273 | $this->lang['strsuper'] |
||
| 274 | ) . \PHP_EOL; |
||
| 275 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formSuper\" name=\"formSuper\"", |
||
| 276 | (isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 277 | echo \sprintf( |
||
| 278 | ' <tr> |
||
| 279 | <th class="data left"><label for="formCreateDB">%s</label></th>', |
||
| 280 | $this->lang['strcreatedb'] |
||
| 281 | ) . \PHP_EOL; |
||
| 282 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateDB\" name=\"formCreateDB\"", |
||
| 283 | (isset($_POST['formCreateDB'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 284 | echo \sprintf( |
||
| 285 | ' <tr> |
||
| 286 | <th class="data left"><label for="formCreateRole">%s</label></th>', |
||
| 287 | $this->lang['strcancreaterole'] |
||
| 288 | ) . \PHP_EOL; |
||
| 289 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateRole\" name=\"formCreateRole\"", |
||
| 290 | (isset($_POST['formCreateRole'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 291 | echo \sprintf( |
||
| 292 | ' <tr> |
||
| 293 | <th class="data left"><label for="formInherits">%s</label></th>', |
||
| 294 | $this->lang['strinheritsprivs'] |
||
| 295 | ) . \PHP_EOL; |
||
| 296 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formInherits\" name=\"formInherits\"", |
||
| 297 | (isset($_POST['formInherits'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 298 | echo \sprintf( |
||
| 299 | ' <tr> |
||
| 300 | <th class="data left"><label for="formCanLogin">%s</label></th>', |
||
| 301 | $this->lang['strcanlogin'] |
||
| 302 | ) . \PHP_EOL; |
||
| 303 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCanLogin\" name=\"formCanLogin\"", |
||
| 304 | (isset($_POST['formCanLogin'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 305 | echo \sprintf( |
||
| 306 | ' <tr> |
||
| 307 | <th class="data left">%s</th>', |
||
| 308 | $this->lang['strconnlimit'] |
||
| 309 | ) . \PHP_EOL; |
||
| 310 | echo "\t\t<td class=\"data1\"><input size=\"4\" name=\"formConnLimit\" value=\"", \htmlspecialchars($_POST['formConnLimit']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 311 | echo \sprintf( |
||
| 312 | ' <tr> |
||
| 313 | <th class="data left">%s</th>', |
||
| 314 | $this->lang['strexpires'] |
||
| 315 | ) . \PHP_EOL; |
||
| 316 | echo "\t\t<td class=\"data1\"><input size=\"23\" name=\"formExpires\" value=\"", \htmlspecialchars($_POST['formExpires']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 317 | |||
| 318 | $roles = $data->getRoles(); |
||
| 319 | |||
| 320 | if (0 < $roles->recordCount()) { |
||
| 321 | echo \sprintf( |
||
| 322 | ' <tr> |
||
| 323 | <th class="data left">%s</th>', |
||
| 324 | $this->lang['strmemberof'] |
||
| 325 | ) . \PHP_EOL; |
||
| 326 | echo "\t\t<td class=\"data\">" . \PHP_EOL; |
||
| 327 | echo "\t\t\t<select name=\"memberof[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
||
| 328 | |||
| 329 | while (!$roles->EOF) { |
||
| 330 | $rolename = $roles->fields['rolname']; |
||
| 331 | echo \sprintf( |
||
| 332 | ' <option value="%s"', |
||
| 333 | $rolename |
||
| 334 | ), |
||
| 335 | (\in_array($rolename, $_POST['memberof'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
||
| 336 | $roles->moveNext(); |
||
| 337 | } |
||
| 338 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 339 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 340 | |||
| 341 | $roles->moveFirst(); |
||
| 342 | echo \sprintf( |
||
| 343 | ' <tr> |
||
| 344 | <th class="data left">%s</th>', |
||
| 345 | $this->lang['strmembers'] |
||
| 346 | ) . \PHP_EOL; |
||
| 347 | echo "\t\t<td class=\"data\">" . \PHP_EOL; |
||
| 348 | echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
||
| 349 | |||
| 350 | while (!$roles->EOF) { |
||
| 351 | $rolename = $roles->fields['rolname']; |
||
| 352 | echo \sprintf( |
||
| 353 | ' <option value="%s"', |
||
| 354 | $rolename |
||
| 355 | ), |
||
| 356 | (\in_array($rolename, $_POST['members'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
||
| 357 | $roles->moveNext(); |
||
| 358 | } |
||
| 359 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 360 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 361 | |||
| 362 | $roles->moveFirst(); |
||
| 363 | echo \sprintf( |
||
| 364 | ' <tr> |
||
| 365 | <th class="data left">%s</th>', |
||
| 366 | $this->lang['stradminmembers'] |
||
| 367 | ) . \PHP_EOL; |
||
| 368 | echo "\t\t<td class=\"data\">" . \PHP_EOL; |
||
| 369 | echo "\t\t\t<select name=\"adminmembers[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
||
| 370 | |||
| 371 | while (!$roles->EOF) { |
||
| 372 | $rolename = $roles->fields['rolname']; |
||
| 373 | echo \sprintf( |
||
| 374 | ' <option value="%s"', |
||
| 375 | $rolename |
||
| 376 | ), |
||
| 377 | (\in_array($rolename, $_POST['adminmembers'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
||
| 378 | $roles->moveNext(); |
||
| 379 | } |
||
| 380 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 381 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 382 | } |
||
| 383 | |||
| 384 | echo '</table>' . \PHP_EOL; |
||
| 385 | echo '<p><input type="hidden" name="action" value="save_create" />' . \PHP_EOL; |
||
| 386 | echo $this->view->form; |
||
| 387 | echo \sprintf( |
||
| 388 | '<input type="submit" name="create" value="%s" />', |
||
| 389 | $this->lang['strcreate'] |
||
| 390 | ) . \PHP_EOL; |
||
| 391 | echo \sprintf( |
||
| 392 | '<input type="submit" name="cancel" value="%s" /></p>%s', |
||
| 393 | $this->lang['strcancel'], |
||
| 394 | \PHP_EOL |
||
| 395 | ); |
||
| 396 | echo '</form>' . \PHP_EOL; |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Actually creates the new role in the database. |
||
| 401 | */ |
||
| 402 | public function doSaveCreate(): void |
||
| 403 | { |
||
| 404 | $data = $this->misc->getDatabaseAccessor(); |
||
| 405 | |||
| 406 | $this->coalesceArr($_POST, 'memberof', []); |
||
| 407 | |||
| 408 | $this->coalesceArr($_POST, 'members', []); |
||
| 409 | |||
| 410 | $this->coalesceArr($_POST, 'adminmembers', []); |
||
| 411 | |||
| 412 | // Check data |
||
| 413 | if ('' === $_POST['formRolename']) { |
||
| 414 | $this->doCreate($this->lang['strroleneedsname']); |
||
| 415 | } elseif ($_POST['formPassword'] !== $_POST['formConfirm']) { |
||
| 416 | $this->doCreate($this->lang['strpasswordconfirm']); |
||
| 417 | } else { |
||
| 418 | $status = $data->createRole( |
||
| 419 | $_POST['formRolename'], |
||
| 420 | $_POST['formPassword'], |
||
| 421 | isset($_POST['formSuper']), |
||
| 422 | isset($_POST['formCreateDB']), |
||
| 423 | isset($_POST['formCreateRole']), |
||
| 424 | isset($_POST['formInherits']), |
||
| 425 | isset($_POST['formCanLogin']), |
||
| 426 | $_POST['formConnLimit'], |
||
| 427 | $_POST['formExpires'], |
||
| 428 | $_POST['memberof'], |
||
| 429 | $_POST['members'], |
||
| 430 | $_POST['adminmembers'] |
||
| 431 | ); |
||
| 432 | |||
| 433 | if (0 === $status) { |
||
| 434 | $this->doDefault($this->lang['strrolecreated']); |
||
| 435 | } else { |
||
| 436 | $this->doCreate($this->lang['strrolecreatedbad']); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Function to allow alter a role. |
||
| 443 | * |
||
| 444 | * @param mixed $msg |
||
| 445 | */ |
||
| 446 | public function doAlter($msg = ''): void |
||
| 447 | { |
||
| 448 | $data = $this->misc->getDatabaseAccessor(); |
||
| 449 | |||
| 450 | $this->printTrail('role'); |
||
| 451 | $this->printTitle($this->lang['stralter'], 'pg.role.alter'); |
||
| 452 | $this->printMsg($msg); |
||
| 453 | |||
| 454 | $roledata = $data->getRole($_REQUEST['rolename']); |
||
| 455 | |||
| 456 | if (0 >= $roledata->recordCount()) { |
||
| 457 | echo \sprintf( |
||
| 458 | '<p>%s</p>', |
||
| 459 | $this->lang['strnodata'] |
||
| 460 | ) . \PHP_EOL; |
||
| 461 | |||
| 462 | return; |
||
| 463 | } |
||
| 464 | $server_info = $this->misc->getServerInfo(); |
||
| 465 | $canRename = $data->hasUserRename() && ($_REQUEST['rolename'] !== $server_info['username']); |
||
| 466 | $roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
||
| 467 | $roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
||
| 468 | $roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
||
| 469 | $roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
||
| 470 | $roledata->fields['rolcanlogin'] = $data->phpBool($roledata->fields['rolcanlogin']); |
||
| 471 | |||
| 472 | $this->_adjustPostVars($roledata, $canRename); |
||
|
|
|||
| 473 | |||
| 474 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
||
| 475 | echo '<table>' . \PHP_EOL; |
||
| 476 | echo \sprintf( |
||
| 477 | ' <tr> |
||
| 478 | <th class="data left" style="width: 130px">%s</th>', |
||
| 479 | $this->lang['strname'] |
||
| 480 | ) . \PHP_EOL; |
||
| 481 | echo "\t\t<td class=\"data1\">", ($canRename ? \sprintf( |
||
| 482 | '<input name="formNewRoleName" size="15" maxlength="%s" value="', |
||
| 483 | $data->_maxNameLen |
||
| 484 | ) . \htmlspecialchars($_POST['formNewRoleName']) . '" />' : $this->misc->printVal($roledata->fields['rolname'])), "</td>\n\t</tr>" . \PHP_EOL; |
||
| 485 | echo \sprintf( |
||
| 486 | ' <tr> |
||
| 487 | <th class="data left">%s</th>', |
||
| 488 | $this->lang['strpassword'] |
||
| 489 | ) . \PHP_EOL; |
||
| 490 | echo "\t\t<td class=\"data1\"><input type=\"password\" size=\"15\" name=\"formPassword\" value=\"", \htmlspecialchars($_POST['formPassword']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 491 | echo \sprintf( |
||
| 492 | ' <tr> |
||
| 493 | <th class="data left">%s</th>', |
||
| 494 | $this->lang['strconfirm'] |
||
| 495 | ) . \PHP_EOL; |
||
| 496 | echo "\t\t<td class=\"data1\"><input type=\"password\" size=\"15\" name=\"formConfirm\" value=\"\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 497 | echo \sprintf( |
||
| 498 | ' <tr> |
||
| 499 | <th class="data left"><label for="formSuper">%s</label></th>', |
||
| 500 | $this->lang['strsuper'] |
||
| 501 | ) . \PHP_EOL; |
||
| 502 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formSuper\" name=\"formSuper\"", |
||
| 503 | (isset($_POST['formSuper'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 504 | echo \sprintf( |
||
| 505 | ' <tr> |
||
| 506 | <th class="data left"><label for="formCreateDB">%s</label></th>', |
||
| 507 | $this->lang['strcreatedb'] |
||
| 508 | ) . \PHP_EOL; |
||
| 509 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateDB\" name=\"formCreateDB\"", |
||
| 510 | (isset($_POST['formCreateDB'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 511 | echo \sprintf( |
||
| 512 | ' <tr> |
||
| 513 | <th class="data left"><label for="formCreateRole">%s</label></th>', |
||
| 514 | $this->lang['strcancreaterole'] |
||
| 515 | ) . \PHP_EOL; |
||
| 516 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCreateRole\" name=\"formCreateRole\"", |
||
| 517 | (isset($_POST['formCreateRole'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 518 | echo \sprintf( |
||
| 519 | ' <tr> |
||
| 520 | <th class="data left"><label for="formInherits">%s</label></th>', |
||
| 521 | $this->lang['strinheritsprivs'] |
||
| 522 | ) . \PHP_EOL; |
||
| 523 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formInherits\" name=\"formInherits\"", |
||
| 524 | (isset($_POST['formInherits'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 525 | echo \sprintf( |
||
| 526 | ' <tr> |
||
| 527 | <th class="data left"><label for="formCanLogin">%s</label></th>', |
||
| 528 | $this->lang['strcanlogin'] |
||
| 529 | ) . \PHP_EOL; |
||
| 530 | echo "\t\t<td class=\"data1\"><input type=\"checkbox\" id=\"formCanLogin\" name=\"formCanLogin\"", |
||
| 531 | (isset($_POST['formCanLogin'])) ? ' checked="checked"' : '', " /></td>\n\t</tr>" . \PHP_EOL; |
||
| 532 | echo \sprintf( |
||
| 533 | ' <tr> |
||
| 534 | <th class="data left">%s</th>', |
||
| 535 | $this->lang['strconnlimit'] |
||
| 536 | ) . \PHP_EOL; |
||
| 537 | echo "\t\t<td class=\"data1\"><input size=\"4\" name=\"formConnLimit\" value=\"", \htmlspecialchars($_POST['formConnLimit']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 538 | echo \sprintf( |
||
| 539 | ' <tr> |
||
| 540 | <th class="data left">%s</th>', |
||
| 541 | $this->lang['strexpires'] |
||
| 542 | ) . \PHP_EOL; |
||
| 543 | echo "\t\t<td class=\"data1\"><input size=\"23\" name=\"formExpires\" value=\"", \htmlspecialchars($_POST['formExpires']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 544 | |||
| 545 | $this->_populateMemberof($data); |
||
| 546 | $memberofold = \implode(',', $_POST['memberof']); |
||
| 547 | |||
| 548 | $this->_populateMembers($data); |
||
| 549 | $membersold = \implode(',', $_POST['members']); |
||
| 550 | |||
| 551 | $this->_populateAdminmembers($data); |
||
| 552 | $adminmembersold = \implode(',', $_POST['adminmembers']); |
||
| 553 | |||
| 554 | $roles = $data->getRoles($_REQUEST['rolename']); |
||
| 555 | |||
| 556 | if (0 < $roles->recordCount()) { |
||
| 557 | echo \sprintf( |
||
| 558 | ' <tr> |
||
| 559 | <th class="data left">%s</th>', |
||
| 560 | $this->lang['strmemberof'] |
||
| 561 | ) . \PHP_EOL; |
||
| 562 | echo "\t\t<td class=\"data\">" . \PHP_EOL; |
||
| 563 | echo "\t\t\t<select name=\"memberof[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
||
| 564 | |||
| 565 | while (!$roles->EOF) { |
||
| 566 | $rolename = $roles->fields['rolname']; |
||
| 567 | echo \sprintf( |
||
| 568 | ' <option value="%s"', |
||
| 569 | $rolename |
||
| 570 | ), |
||
| 571 | (\in_array($rolename, $_POST['memberof'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
||
| 572 | $roles->moveNext(); |
||
| 573 | } |
||
| 574 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 575 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 576 | |||
| 577 | $roles->moveFirst(); |
||
| 578 | echo \sprintf( |
||
| 579 | ' <tr> |
||
| 580 | <th class="data left">%s</th>', |
||
| 581 | $this->lang['strmembers'] |
||
| 582 | ) . \PHP_EOL; |
||
| 583 | echo "\t\t<td class=\"data\">" . \PHP_EOL; |
||
| 584 | echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
||
| 585 | |||
| 586 | while (!$roles->EOF) { |
||
| 587 | $rolename = $roles->fields['rolname']; |
||
| 588 | echo \sprintf( |
||
| 589 | ' <option value="%s"', |
||
| 590 | $rolename |
||
| 591 | ), |
||
| 592 | (\in_array($rolename, $_POST['members'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
||
| 593 | $roles->moveNext(); |
||
| 594 | } |
||
| 595 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 596 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 597 | |||
| 598 | $roles->moveFirst(); |
||
| 599 | echo \sprintf( |
||
| 600 | ' <tr> |
||
| 601 | <th class="data left">%s</th>', |
||
| 602 | $this->lang['stradminmembers'] |
||
| 603 | ) . \PHP_EOL; |
||
| 604 | echo "\t\t<td class=\"data\">" . \PHP_EOL; |
||
| 605 | echo "\t\t\t<select name=\"adminmembers[]\" multiple=\"multiple\" size=\"", \min(20, $roles->recordCount()), '">' . \PHP_EOL; |
||
| 606 | |||
| 607 | while (!$roles->EOF) { |
||
| 608 | $rolename = $roles->fields['rolname']; |
||
| 609 | echo \sprintf( |
||
| 610 | ' <option value="%s"', |
||
| 611 | $rolename |
||
| 612 | ), |
||
| 613 | (\in_array($rolename, $_POST['adminmembers'], true) ? ' selected="selected"' : ''), '>', $this->misc->printVal($rolename), '</option>' . \PHP_EOL; |
||
| 614 | $roles->moveNext(); |
||
| 615 | } |
||
| 616 | echo "\t\t\t</select>" . \PHP_EOL; |
||
| 617 | echo "\t\t</td>\n\t</tr>" . \PHP_EOL; |
||
| 618 | } |
||
| 619 | echo '</table>' . \PHP_EOL; |
||
| 620 | |||
| 621 | echo '<p><input type="hidden" name="action" value="save_alter" />' . \PHP_EOL; |
||
| 622 | echo '<input type="hidden" name="rolename" value="', \htmlspecialchars($_REQUEST['rolename']), '" />' . \PHP_EOL; |
||
| 623 | echo '<input type="hidden" name="memberofold" value="', $_POST['memberofold'] ?? \htmlspecialchars($memberofold), '" />' . \PHP_EOL; |
||
| 624 | echo '<input type="hidden" name="membersold" value="', $_POST['membersold'] ?? \htmlspecialchars($membersold), '" />' . \PHP_EOL; |
||
| 625 | echo '<input type="hidden" name="adminmembersold" value="', $_POST['adminmembersold'] ?? \htmlspecialchars($adminmembersold), '" />' . \PHP_EOL; |
||
| 626 | echo $this->view->form; |
||
| 627 | echo \sprintf( |
||
| 628 | '<input type="submit" name="alter" value="%s" />', |
||
| 629 | $this->lang['stralter'] |
||
| 630 | ) . \PHP_EOL; |
||
| 631 | echo \sprintf( |
||
| 632 | '<input type="submit" name="cancel" value="%s" /></p>%s', |
||
| 633 | $this->lang['strcancel'], |
||
| 634 | \PHP_EOL |
||
| 635 | ); |
||
| 636 | echo '</form>' . \PHP_EOL; |
||
| 637 | } |
||
| 638 | |||
| 639 | /** |
||
| 640 | * Function to save after editing a role. |
||
| 641 | */ |
||
| 642 | public function doSaveAlter(): void |
||
| 643 | { |
||
| 644 | $data = $this->misc->getDatabaseAccessor(); |
||
| 645 | |||
| 646 | $this->coalesceArr($_POST, 'memberof', []); |
||
| 647 | |||
| 648 | $this->coalesceArr($_POST, 'members', []); |
||
| 649 | |||
| 650 | $this->coalesceArr($_POST, 'adminmembers', []); |
||
| 651 | |||
| 652 | // Check name and password |
||
| 653 | if (isset($_POST['formNewRoleName']) && '' === $_POST['formNewRoleName']) { |
||
| 654 | $this->doAlter($this->lang['strroleneedsname']); |
||
| 655 | } elseif ($_POST['formPassword'] !== $_POST['formConfirm']) { |
||
| 656 | $this->doAlter($this->lang['strpasswordconfirm']); |
||
| 657 | } else { |
||
| 658 | if (isset($_POST['formNewRoleName'])) { |
||
| 659 | $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']); |
||
| 660 | } else { |
||
| 661 | $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']); |
||
| 662 | } |
||
| 663 | |||
| 664 | if (0 === $status) { |
||
| 665 | $this->doDefault($this->lang['strrolealtered']); |
||
| 666 | } else { |
||
| 667 | $this->doAlter($this->lang['strrolealteredbad']); |
||
| 668 | } |
||
| 669 | } |
||
| 670 | } |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Show confirmation of drop a role and perform actual drop. |
||
| 674 | * |
||
| 675 | * @param mixed $confirm |
||
| 676 | */ |
||
| 677 | public function doDrop($confirm): void |
||
| 678 | { |
||
| 679 | $data = $this->misc->getDatabaseAccessor(); |
||
| 680 | |||
| 681 | if ($confirm) { |
||
| 682 | $this->printTrail('role'); |
||
| 683 | $this->printTitle($this->lang['strdroprole'], 'pg.role.drop'); |
||
| 684 | |||
| 685 | echo '<p>', \sprintf( |
||
| 686 | $this->lang['strconfdroprole'], |
||
| 687 | $this->misc->printVal($_REQUEST['rolename']) |
||
| 688 | ), '</p>' . \PHP_EOL; |
||
| 689 | |||
| 690 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
||
| 691 | echo '<p><input type="hidden" name="action" value="drop" />' . \PHP_EOL; |
||
| 692 | echo '<input type="hidden" name="rolename" value="', \htmlspecialchars($_REQUEST['rolename']), '" />' . \PHP_EOL; |
||
| 693 | echo $this->view->form; |
||
| 694 | echo \sprintf( |
||
| 695 | '<input type="submit" name="drop" value="%s" />', |
||
| 696 | $this->lang['strdrop'] |
||
| 697 | ) . \PHP_EOL; |
||
| 698 | echo \sprintf( |
||
| 699 | '<input type="submit" name="cancel" value="%s" /></p>%s', |
||
| 700 | $this->lang['strcancel'], |
||
| 701 | \PHP_EOL |
||
| 702 | ); |
||
| 703 | echo '</form>' . \PHP_EOL; |
||
| 704 | } else { |
||
| 705 | $status = $data->dropRole($_REQUEST['rolename']); |
||
| 706 | |||
| 707 | if (0 === $status) { |
||
| 708 | $this->doDefault($this->lang['strroledropped']); |
||
| 709 | } else { |
||
| 710 | $this->doDefault($this->lang['strroledroppedbad']); |
||
| 711 | } |
||
| 712 | } |
||
| 713 | } |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Show the properties of a role. |
||
| 717 | * |
||
| 718 | * @param mixed $msg |
||
| 719 | */ |
||
| 720 | public function doProperties($msg = ''): void |
||
| 721 | { |
||
| 722 | $data = $this->misc->getDatabaseAccessor(); |
||
| 723 | |||
| 724 | $this->printTrail('role'); |
||
| 725 | $this->printTitle($this->lang['strproperties'], 'pg.role'); |
||
| 726 | $this->printMsg($msg); |
||
| 727 | |||
| 728 | $roledata = $data->getRole($_REQUEST['rolename']); |
||
| 729 | |||
| 730 | if (0 < $roledata->recordCount()) { |
||
| 731 | $roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
||
| 732 | $roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
||
| 733 | $roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
||
| 734 | $roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
||
| 735 | $roledata->fields['rolcanlogin'] = $data->phpBool($roledata->fields['rolcanlogin']); |
||
| 736 | |||
| 737 | echo '<table>' . \PHP_EOL; |
||
| 738 | echo "\t<tr>\n\t\t<th class=\"data\" style=\"width: 130px\">Description</th>" . \PHP_EOL; |
||
| 739 | echo "\t\t<th class=\"data\" style=\"width: 120\">Value</th>\n\t</tr>" . \PHP_EOL; |
||
| 740 | echo \sprintf( |
||
| 741 | ' <tr> |
||
| 742 | <td class="data1">%s</td>', |
||
| 743 | $this->lang['strname'] |
||
| 744 | ) . \PHP_EOL; |
||
| 745 | echo "\t\t<td class=\"data1\">", \htmlspecialchars($_REQUEST['rolename']), "</td>\n\t</tr>" . \PHP_EOL; |
||
| 746 | echo \sprintf( |
||
| 747 | ' <tr> |
||
| 748 | <td class="data2">%s</td>', |
||
| 749 | $this->lang['strsuper'] |
||
| 750 | ) . \PHP_EOL; |
||
| 751 | echo "\t\t<td class=\"data2\">", (($roledata->fields['rolsuper']) ? $this->lang['stryes'] : $this->lang['strno']), "</td>\n\t</tr>" . \PHP_EOL; |
||
| 752 | echo \sprintf( |
||
| 753 | ' <tr> |
||
| 754 | <td class="data1">%s</td>', |
||
| 755 | $this->lang['strcreatedb'] |
||
| 756 | ) . \PHP_EOL; |
||
| 757 | echo "\t\t<td class=\"data1\">", (($roledata->fields['rolcreatedb']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
||
| 758 | echo \sprintf( |
||
| 759 | ' <tr> |
||
| 760 | <td class="data2">%s</td>', |
||
| 761 | $this->lang['strcancreaterole'] |
||
| 762 | ) . \PHP_EOL; |
||
| 763 | echo "\t\t<td class=\"data2\">", (($roledata->fields['rolcreaterole']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
||
| 764 | echo \sprintf( |
||
| 765 | ' <tr> |
||
| 766 | <td class="data1">%s</td>', |
||
| 767 | $this->lang['strinheritsprivs'] |
||
| 768 | ) . \PHP_EOL; |
||
| 769 | echo "\t\t<td class=\"data1\">", (($roledata->fields['rolinherit']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
||
| 770 | echo \sprintf( |
||
| 771 | ' <tr> |
||
| 772 | <td class="data2">%s</td>', |
||
| 773 | $this->lang['strcanlogin'] |
||
| 774 | ) . \PHP_EOL; |
||
| 775 | echo "\t\t<td class=\"data2\">", (($roledata->fields['rolcanlogin']) ? $this->lang['stryes'] : $this->lang['strno']), '</td>' . \PHP_EOL; |
||
| 776 | echo \sprintf( |
||
| 777 | ' <tr> |
||
| 778 | <td class="data1">%s</td>', |
||
| 779 | $this->lang['strconnlimit'] |
||
| 780 | ) . \PHP_EOL; |
||
| 781 | echo "\t\t<td class=\"data1\">", ('-1' === $roledata->fields['rolconnlimit'] ? $this->lang['strnolimit'] : $this->misc->printVal($roledata->fields['rolconnlimit'])), '</td>' . \PHP_EOL; |
||
| 782 | echo \sprintf( |
||
| 783 | ' <tr> |
||
| 784 | <td class="data2">%s</td>', |
||
| 785 | $this->lang['strexpires'] |
||
| 786 | ) . \PHP_EOL; |
||
| 787 | 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; |
||
| 788 | echo \sprintf( |
||
| 789 | ' <tr> |
||
| 790 | <td class="data1">%s</td>', |
||
| 791 | $this->lang['strsessiondefaults'] |
||
| 792 | ) . \PHP_EOL; |
||
| 793 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolconfig']), '</td>' . \PHP_EOL; |
||
| 794 | echo \sprintf( |
||
| 795 | ' <tr> |
||
| 796 | <td class="data2">%s</td>', |
||
| 797 | $this->lang['strmemberof'] |
||
| 798 | ) . \PHP_EOL; |
||
| 799 | echo "\t\t<td class=\"data2\">"; |
||
| 800 | $memberof = $data->getMemberOf($_REQUEST['rolename']); |
||
| 801 | |||
| 802 | if (0 < $memberof->recordCount()) { |
||
| 803 | while (!$memberof->EOF) { |
||
| 804 | echo $this->misc->printVal($memberof->fields['rolname']), '<br />' . \PHP_EOL; |
||
| 805 | $memberof->moveNext(); |
||
| 806 | } |
||
| 807 | } |
||
| 808 | echo "</td>\n\t</tr>" . \PHP_EOL; |
||
| 809 | echo \sprintf( |
||
| 810 | ' <tr> |
||
| 811 | <td class="data1">%s</td>', |
||
| 812 | $this->lang['strmembers'] |
||
| 813 | ) . \PHP_EOL; |
||
| 814 | echo "\t\t<td class=\"data1\">"; |
||
| 815 | $members = $data->getMembers($_REQUEST['rolename']); |
||
| 816 | |||
| 817 | if (0 < $members->recordCount()) { |
||
| 818 | while (!$members->EOF) { |
||
| 819 | echo $this->misc->printVal($members->fields['rolname']), '<br />' . \PHP_EOL; |
||
| 820 | $members->moveNext(); |
||
| 821 | } |
||
| 822 | } |
||
| 823 | echo "</td>\n\t</tr>" . \PHP_EOL; |
||
| 824 | echo \sprintf( |
||
| 825 | ' <tr> |
||
| 826 | <td class="data2">%s</td>', |
||
| 827 | $this->lang['stradminmembers'] |
||
| 828 | ) . \PHP_EOL; |
||
| 829 | echo "\t\t<td class=\"data2\">"; |
||
| 830 | $adminmembers = $data->getMembers($_REQUEST['rolename'], 't'); |
||
| 831 | |||
| 832 | if (0 < $adminmembers->recordCount()) { |
||
| 833 | while (!$adminmembers->EOF) { |
||
| 834 | echo $this->misc->printVal($adminmembers->fields['rolname']), '<br />' . \PHP_EOL; |
||
| 835 | $adminmembers->moveNext(); |
||
| 836 | } |
||
| 837 | } |
||
| 838 | echo "</td>\n\t</tr>" . \PHP_EOL; |
||
| 839 | echo '</table>' . \PHP_EOL; |
||
| 840 | } else { |
||
| 841 | echo \sprintf( |
||
| 842 | '<p>%s</p>', |
||
| 843 | $this->lang['strnodata'] |
||
| 844 | ) . \PHP_EOL; |
||
| 845 | } |
||
| 846 | |||
| 847 | $navlinks = [ |
||
| 848 | 'showall' => [ |
||
| 849 | 'attr' => [ |
||
| 850 | 'href' => [ |
||
| 851 | 'url' => 'roles', |
||
| 852 | 'urlvars' => [ |
||
| 853 | 'server' => $_REQUEST['server'], |
||
| 854 | ], |
||
| 855 | ], |
||
| 856 | ], |
||
| 857 | 'content' => $this->lang['strshowallroles'], |
||
| 858 | ], |
||
| 859 | 'alter' => [ |
||
| 860 | 'attr' => [ |
||
| 861 | 'href' => [ |
||
| 862 | 'url' => 'roles', |
||
| 863 | 'urlvars' => [ |
||
| 864 | 'action' => 'alter', |
||
| 865 | 'server' => $_REQUEST['server'], |
||
| 866 | 'rolename' => $_REQUEST['rolename'], |
||
| 867 | ], |
||
| 868 | ], |
||
| 869 | ], |
||
| 870 | 'content' => $this->lang['stralter'], |
||
| 871 | ], |
||
| 872 | 'drop' => [ |
||
| 873 | 'attr' => [ |
||
| 874 | 'href' => [ |
||
| 875 | 'url' => 'roles', |
||
| 876 | 'urlvars' => [ |
||
| 877 | 'action' => 'confirm_drop', |
||
| 878 | 'server' => $_REQUEST['server'], |
||
| 879 | 'rolename' => $_REQUEST['rolename'], |
||
| 880 | ], |
||
| 881 | ], |
||
| 882 | ], |
||
| 883 | 'content' => $this->lang['strdrop'], |
||
| 884 | ], |
||
| 885 | ]; |
||
| 886 | |||
| 887 | $this->printNavLinks($navlinks, 'roles-properties', \get_defined_vars()); |
||
| 888 | } |
||
| 889 | |||
| 890 | /** |
||
| 891 | * If a role is not a superuser role, then we have an 'account management' |
||
| 892 | * page for change his password, etc. We don't prevent them from |
||
| 893 | * messing with the URL to gain access to other role admin stuff, because |
||
| 894 | * the PostgreSQL permissions will prevent them changing anything anyway. |
||
| 895 | * |
||
| 896 | * @param mixed $msg |
||
| 897 | */ |
||
| 898 | public function doAccount($msg = ''): void |
||
| 899 | { |
||
| 900 | $data = $this->misc->getDatabaseAccessor(); |
||
| 901 | |||
| 902 | $server_info = $this->misc->getServerInfo(); |
||
| 903 | |||
| 904 | $roledata = $data->getRole($server_info['username']); |
||
| 905 | $_REQUEST['rolename'] = $server_info['username']; |
||
| 906 | |||
| 907 | $this->printTrail('role'); |
||
| 908 | $this->printTabs('server', 'account'); |
||
| 909 | $this->printMsg($msg); |
||
| 910 | |||
| 911 | if (0 < $roledata->recordCount()) { |
||
| 912 | $roledata->fields['rolsuper'] = $data->phpBool($roledata->fields['rolsuper']); |
||
| 913 | $roledata->fields['rolcreatedb'] = $data->phpBool($roledata->fields['rolcreatedb']); |
||
| 914 | $roledata->fields['rolcreaterole'] = $data->phpBool($roledata->fields['rolcreaterole']); |
||
| 915 | $roledata->fields['rolinherit'] = $data->phpBool($roledata->fields['rolinherit']); |
||
| 916 | echo '<table>' . \PHP_EOL; |
||
| 917 | echo \sprintf( |
||
| 918 | ' <tr> |
||
| 919 | <th class="data">%s</th>', |
||
| 920 | $this->lang['strname'] |
||
| 921 | ) . \PHP_EOL; |
||
| 922 | echo \sprintf( |
||
| 923 | ' <th class="data">%s</th>', |
||
| 924 | $this->lang['strsuper'] |
||
| 925 | ) . \PHP_EOL; |
||
| 926 | echo \sprintf( |
||
| 927 | ' <th class="data">%s</th>', |
||
| 928 | $this->lang['strcreatedb'] |
||
| 929 | ) . \PHP_EOL; |
||
| 930 | echo \sprintf( |
||
| 931 | ' <th class="data">%s</th>', |
||
| 932 | $this->lang['strcancreaterole'] |
||
| 933 | ) . \PHP_EOL; |
||
| 934 | echo \sprintf( |
||
| 935 | ' <th class="data">%s</th>', |
||
| 936 | $this->lang['strinheritsprivs'] |
||
| 937 | ) . \PHP_EOL; |
||
| 938 | echo \sprintf( |
||
| 939 | ' <th class="data">%s</th>', |
||
| 940 | $this->lang['strconnlimit'] |
||
| 941 | ) . \PHP_EOL; |
||
| 942 | echo \sprintf( |
||
| 943 | ' <th class="data">%s</th>', |
||
| 944 | $this->lang['strexpires'] |
||
| 945 | ) . \PHP_EOL; |
||
| 946 | echo \sprintf( |
||
| 947 | ' <th class="data">%s</th>', |
||
| 948 | $this->lang['strsessiondefaults'] |
||
| 949 | ) . \PHP_EOL; |
||
| 950 | echo "\t</tr>" . \PHP_EOL; |
||
| 951 | echo "\t<tr>\n\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolname']), '</td>' . \PHP_EOL; |
||
| 952 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolsuper'], 'yesno'), '</td>' . \PHP_EOL; |
||
| 953 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolcreatedb'], 'yesno'), '</td>' . \PHP_EOL; |
||
| 954 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolcreaterole'], 'yesno'), '</td>' . \PHP_EOL; |
||
| 955 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolinherit'], 'yesno'), '</td>' . \PHP_EOL; |
||
| 956 | echo "\t\t<td class=\"data1\">", ('-1' === $roledata->fields['rolconnlimit'] ? $this->lang['strnolimit'] : $this->misc->printVal($roledata->fields['rolconnlimit'])), '</td>' . \PHP_EOL; |
||
| 957 | 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; |
||
| 958 | echo "\t\t<td class=\"data1\">", $this->misc->printVal($roledata->fields['rolconfig']), '</td>' . \PHP_EOL; |
||
| 959 | echo "\t</tr>\n</table>" . \PHP_EOL; |
||
| 960 | } else { |
||
| 961 | echo \sprintf( |
||
| 962 | '<p>%s</p>', |
||
| 963 | $this->lang['strnodata'] |
||
| 964 | ) . \PHP_EOL; |
||
| 965 | } |
||
| 966 | |||
| 967 | $this->printNavLinks(['changepassword' => [ |
||
| 968 | 'attr' => [ |
||
| 969 | 'href' => [ |
||
| 970 | 'url' => 'roles', |
||
| 971 | 'urlvars' => [ |
||
| 972 | 'action' => 'confchangepassword', |
||
| 973 | 'server' => $_REQUEST['server'], |
||
| 974 | ], |
||
| 975 | ], |
||
| 976 | ], |
||
| 977 | 'content' => $this->lang['strchangepassword'], |
||
| 978 | ]], 'roles-account', \get_defined_vars()); |
||
| 979 | } |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Show confirmation of change password and actually change password. |
||
| 983 | * |
||
| 984 | * @param mixed $confirm |
||
| 985 | * @param mixed $msg |
||
| 986 | */ |
||
| 987 | public function doChangePassword($confirm, $msg = ''): void |
||
| 988 | { |
||
| 989 | $data = $this->misc->getDatabaseAccessor(); |
||
| 990 | |||
| 991 | $server_info = $this->misc->getServerInfo(); |
||
| 992 | |||
| 993 | if ($confirm) { |
||
| 994 | $_REQUEST['rolename'] = $server_info['username']; |
||
| 995 | $this->printTrail('role'); |
||
| 996 | $this->printTitle($this->lang['strchangepassword'], 'pg.role.alter'); |
||
| 997 | $this->printMsg($msg); |
||
| 998 | |||
| 999 | $this->coalesceArr($_POST, 'password', ''); |
||
| 1000 | |||
| 1001 | $this->coalesceArr($_POST, 'confirm', ''); |
||
| 1002 | |||
| 1003 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/roles" method="post">' . \PHP_EOL; |
||
| 1004 | echo '<table>' . \PHP_EOL; |
||
| 1005 | echo \sprintf( |
||
| 1006 | ' <tr> |
||
| 1007 | <th class="data left required">%s</th>', |
||
| 1008 | $this->lang['strpassword'] |
||
| 1009 | ) . \PHP_EOL; |
||
| 1010 | echo "\t\t<td><input type=\"password\" name=\"password\" size=\"32\" value=\"", |
||
| 1011 | \htmlspecialchars($_POST['password']), "\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 1012 | echo \sprintf( |
||
| 1013 | ' <tr> |
||
| 1014 | <th class="data left required">%s</th>', |
||
| 1015 | $this->lang['strconfirm'] |
||
| 1016 | ) . \PHP_EOL; |
||
| 1017 | echo "\t\t<td><input type=\"password\" name=\"confirm\" size=\"32\" value=\"\" /></td>\n\t</tr>" . \PHP_EOL; |
||
| 1018 | echo '</table>' . \PHP_EOL; |
||
| 1019 | echo '<p><input type="hidden" name="action" value="changepassword" />' . \PHP_EOL; |
||
| 1020 | echo $this->view->form; |
||
| 1021 | echo \sprintf( |
||
| 1022 | '<input type="submit" name="ok" value="%s" />', |
||
| 1023 | $this->lang['strok'] |
||
| 1024 | ) . \PHP_EOL; |
||
| 1025 | echo \sprintf( |
||
| 1026 | '<input type="submit" name="cancel" value="%s" />', |
||
| 1027 | $this->lang['strcancel'] |
||
| 1028 | ) . \PHP_EOL; |
||
| 1029 | echo '</p></form>' . \PHP_EOL; |
||
| 1030 | } else { |
||
| 1031 | // Check that password is minimum length |
||
| 1032 | if (\mb_strlen($_POST['password']) < $this->conf['min_password_length']) { |
||
| 1033 | $this->doChangePassword(true, $this->lang['strpasswordshort']); |
||
| 1034 | } elseif ($_POST['password'] !== $_POST['confirm']) { |
||
| 1035 | // Check that password matches confirmation password |
||
| 1036 | $this->doChangePassword(true, $this->lang['strpasswordconfirm']); |
||
| 1037 | } else { |
||
| 1038 | $status = $data->changePassword($server_info['username'], $_POST['password']); |
||
| 1039 | |||
| 1040 | if (0 === $status) { |
||
| 1041 | $this->doAccount($this->lang['strpasswordchanged']); |
||
| 1042 | } else { |
||
| 1043 | $this->doAccount($this->lang['strpasswordchangedbad']); |
||
| 1044 | } |
||
| 1045 | } |
||
| 1046 | } |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Adjusts the content of the $_POST superglobal according to role data. |
||
| 1051 | * |
||
| 1052 | * @param ADORecordSet $roledata The roledata |
||
| 1053 | * @param bool $canRename Indicates if role can be renamed |
||
| 1054 | */ |
||
| 1055 | private function _adjustPostVars($roledata, $canRename): void |
||
| 1056 | { |
||
| 1057 | if (isset($_POST['formExpires'])) { |
||
| 1058 | return; |
||
| 1059 | } |
||
| 1060 | |||
| 1061 | if ($canRename) { |
||
| 1062 | $_POST['formNewRoleName'] = $roledata->fields['rolname']; |
||
| 1063 | } |
||
| 1064 | |||
| 1065 | if ($roledata->fields['rolsuper']) { |
||
| 1066 | $_POST['formSuper'] = ''; |
||
| 1067 | } |
||
| 1068 | |||
| 1069 | if ($roledata->fields['rolcreatedb']) { |
||
| 1070 | $_POST['formCreateDB'] = ''; |
||
| 1071 | } |
||
| 1072 | |||
| 1073 | if ($roledata->fields['rolcreaterole']) { |
||
| 1074 | $_POST['formCreateRole'] = ''; |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | if ($roledata->fields['rolinherit']) { |
||
| 1078 | $_POST['formInherits'] = ''; |
||
| 1079 | } |
||
| 1080 | |||
| 1081 | if ($roledata->fields['rolcanlogin']) { |
||
| 1082 | $_POST['formCanLogin'] = ''; |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | $_POST['formConnLimit'] = '-1' === $roledata->fields['rolconnlimit'] ? '' : $roledata->fields['rolconnlimit']; |
||
| 1086 | $_POST['formExpires'] = 'infinity' === $roledata->fields['rolvaliduntil'] ? '' : $roledata->fields['rolvaliduntil']; |
||
| 1087 | $_POST['formPassword'] = ''; |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | private function _populateMemberof($data): void |
||
| 1091 | { |
||
| 1092 | if (!isset($_POST['memberof'])) { |
||
| 1093 | $memberof = $data->getMemberOf($_REQUEST['rolename']); |
||
| 1094 | |||
| 1095 | if (0 < $memberof->recordCount()) { |
||
| 1096 | $i = 0; |
||
| 1097 | |||
| 1098 | while (!$memberof->EOF) { |
||
| 1099 | $_POST['memberof'][$i++] = $memberof->fields['rolname']; |
||
| 1100 | $memberof->moveNext(); |
||
| 1101 | } |
||
| 1102 | } else { |
||
| 1103 | $_POST['memberof'] = []; |
||
| 1104 | } |
||
| 1105 | } |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | private function _populateMembers($data): void |
||
| 1122 | } |
||
| 1123 | } |
||
| 1124 | } |
||
| 1125 | |||
| 1126 | private function _populateAdminmembers($data): void |
||
| 1140 | } |
||
| 1141 | } |
||
| 1142 | } |
||
| 1143 | } |
||
| 1144 |