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.

105 lines
3.7 KiB

  1. <?php
  2. # $Id$
  3. /**
  4. * Handlers User level alias actions - e.g. add alias, get aliases, update etc.
  5. */
  6. class DomainHandler {
  7. private $username = null; # actually it's the domain - variable name kept for consistence with the other classes
  8. public $errormsg = array();
  9. /**
  10. * @param string $username
  11. */
  12. public function __construct($username) {
  13. $this->username = $username;
  14. }
  15. public function getTransports() {
  16. return Config::read('transport_options');
  17. }
  18. public function getTransport($id) {
  19. $transports = Config::read('transport_options');
  20. return $transports[$id-1];
  21. }
  22. public function add($desc, $a, $m, $t, $q, $default, $backup) {
  23. ($backup == true) ? $backup = db_get_boolean(true) : $backup = db_get_boolean(false);
  24. $arr = array(
  25. 'domain' => $this->username,
  26. 'description' => $desc,
  27. 'aliases' => $a,
  28. 'mailboxes' => $m,
  29. 'maxquota' => $q,
  30. 'transport' => $this->getTransport($t),
  31. 'backupmx' => $backup,
  32. );
  33. $result = db_insert('domain', $arr);
  34. if ($result != 1) {
  35. $this->errormsg[] = Lang::read('pAdminCreate_domain_result_error') . "\n($domain)\n";
  36. return false;
  37. } else {
  38. if ($default) {
  39. foreach (Config::read('default_aliases') as $address=>$goto) {
  40. $address = $address . "@" . $domain;
  41. # TODO: use AliasHandler->add instead of writing directly to the alias table
  42. $arr = array(
  43. 'address' => $address,
  44. 'goto' => $goto,
  45. 'domain' => $domain,
  46. );
  47. $result = db_insert ('alias', $arr);
  48. }
  49. }
  50. $tMessage = Lang::read('pAdminCreate_domain_result_success') . "<br />($domain)</br />";
  51. }
  52. if (!domain_postcreation($domain)) {
  53. $tMessage = Lang::read('pAdminCreate_domain_error');
  54. }
  55. db_log ($domain, 'create_domain', "");
  56. return true;
  57. }
  58. public function view () {
  59. $table_domain = table_by_key('domain');
  60. $E_domain = escape_string($this->username);
  61. $result = db_query("SELECT domain, description, aliases, mailboxes, maxquota, quota, transport, backupmx, DATE_FORMAT(created, '%d.%m.%y') AS created, DATE_FORMAT(modified, '%d.%m.%y') AS modified, active FROM $table_domain WHERE domain='$E_domain'");
  62. if ($result['rows'] != 0) {
  63. $this->return = db_array($result['result']);
  64. return true;
  65. }
  66. $this->errormsg = $result['error'];
  67. return false;
  68. }
  69. /**
  70. * @return true on success false on failure
  71. */
  72. public function delete(){
  73. if( ! $this->view() ) {
  74. $this->errormsg[] = 'A domain with that name does not exist.'; # TODO: make translatable
  75. return false;
  76. }
  77. $this->errormsg[] = '*** Domain deletion not implemented yet ***';
  78. return false; # XXX function aborts here until TODO below is implemented! XXX
  79. # TODO: recursively delete mailboxes, aliases, alias_domains, fetchmail entries etc. before deleting the domain
  80. # TODO: move the needed code from delete.php here
  81. $result = db_delete('domain', 'domain', $this->username);
  82. if( $result == 1 ) {
  83. list(/*NULL*/,$domain) = explode('@', $this->username);
  84. db_log ($domain, 'delete_domain', $this->username); # TODO delete_domain is not a valid db_log keyword yet because we don't yet log add/delete domain
  85. return true;
  86. }
  87. }
  88. }
  89. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */