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.

123 lines
3.7 KiB

5 years ago
  1. <?php
  2. # $Id$
  3. class AdminpasswordHandler extends PFAHandler
  4. {
  5. protected $db_table = 'admin';
  6. protected $id_field = 'username';
  7. # do not skip empty password fields
  8. protected $skip_empty_pass = false;
  9. protected function no_domain_field()
  10. {
  11. return true;
  12. }
  13. protected function validate_new_id()
  14. {
  15. return true;
  16. }
  17. # init $this->struct, $this->db_table and $this->id_field
  18. protected function initStruct()
  19. {
  20. # TODO: shorter PALANG labels ;-)
  21. $this->struct = array(
  22. # field name allow display in... type $PALANG label $PALANG description default / options / ...
  23. # editing? form list
  24. 'username' => self::pacol(0, 1, 1, 'text', 'admin' , ''),
  25. 'oldpass' => self::pacol(1, 1, 0, 'pass', 'pPassword_password_current' , '', '', array(),
  26. /*not_in_db*/ 1),
  27. 'password' => self::pacol(1, 1, 0, 'pass', 'pPassword_password' , ''),
  28. 'password2' => self::pacol(1, 1, 0, 'pass', 'pPassword_password2' , '' , '', array(),
  29. /*not_in_db*/ 0,
  30. /*dont_write_to_db*/ 1,
  31. /*select*/ 'password as password2'
  32. ),
  33. );
  34. }
  35. public function init(string $id): bool
  36. {
  37. # hardcode to logged in admin
  38. if ($this->admin_username == '') {
  39. die("No admin logged in");
  40. }
  41. $this->id = $this->admin_username;
  42. $this->values['username'] = $this->id;
  43. $this->struct['username']['default'] = $this->id;
  44. # hardcode to edit mode
  45. $this->new = 0;
  46. return parent::init($this->id);
  47. }
  48. public function initMsg()
  49. {
  50. $this->msg['error_already_exists'] = 'admin_already_exists'; # probably unused
  51. $this->msg['error_does_not_exist'] = 'admin_does_not_exist'; # probably unused
  52. $this->msg['confirm_delete'] = 'confirm_delete_admin'; # probably unused
  53. $this->msg['logname'] = 'edit_password';
  54. $this->msg['store_error'] = 'pPassword_result_error';
  55. $this->msg['successmessage'] = 'pPassword_result_success';
  56. }
  57. public function webformConfig()
  58. {
  59. return array(
  60. # $PALANG labels
  61. 'formtitle_create' => 'pPassword_welcome',
  62. 'formtitle_edit' => 'pPassword_welcome',
  63. 'create_button' => 'change_password',
  64. # various settings
  65. 'required_role' => 'admin',
  66. 'listview' => 'main.php',
  67. 'early_init' => 1,
  68. 'hardcoded_edit' => true,
  69. );
  70. }
  71. /**
  72. * check if old password is correct
  73. */
  74. protected function _validate_oldpass($field, $val)
  75. {
  76. $l = new Login('admin');
  77. if ($l->login($this->id, $val)) {
  78. return true;
  79. }
  80. $this->errormsg[$field] = Config::lang('pPassword_password_current_text_error');
  81. return false;
  82. }
  83. /**
  84. * skip default validation (check if password is good enough) for old password
  85. */
  86. protected function _inp_pass($field, $val)
  87. {
  88. if ($field == 'oldpass') {
  89. return true;
  90. }
  91. return parent::_inp_pass($field, $val);
  92. }
  93. /**
  94. * compare password / password2 field
  95. * error message will be displayed at the password2 field
  96. */
  97. protected function _validate_password2($field, $val)
  98. {
  99. return $this->compare_password_fields('password', 'password2');
  100. }
  101. }
  102. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */