PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

5 years ago
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT
  8. *
  9. * Further details on the project are available at https://github.com/postfixadmin/postfixadmin
  10. *
  11. * @version $Id$
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: editactive.php
  15. * Used to switch active status for admins, domains, mailboxes, aliases and aliasdomains, etc.
  16. *
  17. * Template File:
  18. * none - redirects to $formconf['listview']
  19. */
  20. require_once('common.php');
  21. if (safeget('token') != $_SESSION['PFA_token']) {
  22. die('Invalid token!');
  23. }
  24. $username = authentication_get_username(); # enforce login
  25. $id = safeget('id');
  26. $table = safeget('table');
  27. $field = safeget('field');
  28. $active = safeget('active');
  29. if ($field === '') {
  30. $field = 'active';
  31. }
  32. if (empty($table)) {
  33. die("Invalid table name given");
  34. }
  35. $handlerclass = ucfirst($table) . 'Handler';
  36. if (!preg_match('/^[a-z]+$/', $table) || !file_exists(dirname(__FILE__) . "/../model/$handlerclass.php")) { # validate $table
  37. die("Invalid table name given!");
  38. }
  39. $handler = new $handlerclass(0, $username);
  40. $formconf = $handler->webformConfig();
  41. authentication_require_role($formconf['required_role']);
  42. if ($handler->init($id)) { # errors will be displayed as last step anyway, no need for duplicated code ;-)
  43. if ($table == 'mailbox') {
  44. if ($field != 'active' && $field != 'smtp_active') {
  45. die(Config::Lang('invalid_parameter'));
  46. }
  47. } else {
  48. if ($field != 'active') {
  49. die(Config::Lang('invalid_parameter'));
  50. }
  51. }
  52. if ($active != '0' && $active != '1') {
  53. die(Config::Lang('invalid_parameter'));
  54. }
  55. if ($handler->set(array($field => $active))) {
  56. $handler->save();
  57. }
  58. }
  59. flash_error($handler->errormsg);
  60. flash_info($handler->infomsg);
  61. if ($formconf['listview'] == 'list-virtual.php') {
  62. $bits = [];
  63. $bits['domain'] = $_SESSION['list-virtual:domain'] ?? null;
  64. $bits['limit'] = $_SESSION['list-virtual:limit'] ?? null;
  65. header("Location: " . $formconf['listview'] . '?' . http_build_query(array_filter($bits)));
  66. exit(0);
  67. }
  68. header("Location: " . $formconf['listview']);
  69. exit;
  70. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */