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.

172 lines
5.2 KiB

  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 :
  10. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  11. *
  12. * @version $Id$
  13. * @license GNU GPL v2 or later.
  14. *
  15. * File: list-virtual.php
  16. * List virtual users for a domain.
  17. *
  18. * Template File: list-virtual.tpl
  19. *
  20. * Template Variables:
  21. *
  22. * tMessage
  23. * tAlias
  24. * tMailbox
  25. *
  26. * Form POST \ GET Variables:
  27. *
  28. * fDomain
  29. * fDisplay
  30. */
  31. require_once('common.php');
  32. authentication_require_role('admin');
  33. if (authentication_has_role('global-admin')) {
  34. $list_domains = list_domains ();
  35. $is_superadmin = 1;
  36. } else {
  37. $list_domains = list_domains_for_admin(authentication_get_username());
  38. $is_superadmin = 0;
  39. }
  40. $tAlias = array();
  41. $tMailbox = array();
  42. $fDisplay = 0;
  43. $page_size = $CONF['page_size'];
  44. if ($_SERVER['REQUEST_METHOD'] == "GET")
  45. {
  46. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  47. if (isset ($_GET['limit'])) $fDisplay = intval ($_GET['limit']);
  48. }
  49. else
  50. {
  51. if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
  52. if (isset ($_POST['limit'])) $fDisplay = intval ($_POST['limit']);
  53. }
  54. if (count($list_domains) == 0) {
  55. # die("no domains");
  56. header("Location: list-domain.php"); # no domains (for this admin at least) - redirect to domain list
  57. }
  58. if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) if (empty ($fDomain)) $fDomain = $list_domains[0];
  59. if (!check_owner(authentication_get_username(), $fDomain)) {
  60. # die($PALANG['invalid_parameter']);
  61. header("Location: list-domain.php"); # domain not owned by this admin
  62. }
  63. $query = "SELECT $table_alias.address,$table_alias.goto,$table_alias.modified,$table_alias.active FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username WHERE $table_alias.domain='$fDomain' AND $table_mailbox.maildir IS NULL ORDER BY $table_alias.address LIMIT $fDisplay, $page_size";
  64. if ('pgsql'==$CONF['database_type'])
  65. {
  66. $query = "SELECT address,goto,extract(epoch from modified) as modified,active FROM $table_alias WHERE domain='$fDomain' AND NOT EXISTS(SELECT 1 FROM $table_mailbox WHERE username=$table_alias.address) ORDER BY address LIMIT $page_size OFFSET $fDisplay";
  67. }
  68. $result = db_query ($query);
  69. if ($result['rows'] > 0)
  70. {
  71. while ($row = db_array ($result['result']))
  72. {
  73. if ('pgsql'==$CONF['database_type'])
  74. {
  75. $row['modified']=gmstrftime('%c %Z',$row['modified']);
  76. $row['active']=('t'==$row['active']) ? 1 : 0;
  77. }
  78. $tAlias[] = $row;
  79. }
  80. }
  81. if ($CONF['vacation_control_admin'] == 'YES')
  82. {
  83. $query = "SELECT $table_mailbox.*, $table_vacation.active AS v_active FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email WHERE $table_mailbox.domain='$fDomain' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay";
  84. }
  85. else
  86. {
  87. $query = "SELECT * FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size";
  88. if ('pgsql'==$CONF['database_type'])
  89. {
  90. $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $page_size OFFSET $fDisplay";
  91. }
  92. }
  93. $result = db_query ($query);
  94. if ($result['rows'] > 0)
  95. {
  96. while ($row = db_array ($result['result']))
  97. {
  98. if ('pgsql'==$CONF['database_type'])
  99. {
  100. //var_dump($row);
  101. $row['created']=gmstrftime('%c %Z',strtotime($row['created']));
  102. $row['modified']=gmstrftime('%c %Z',strtotime($row['modified']));
  103. $row['active']=('t'==$row['active']) ? 1 : 0;
  104. if($row['v_active'] == NULL) {
  105. $row['v_active'] = 'f';
  106. }
  107. $row['v_active']=('t'==$row['v_active']) ? 1 : 0;
  108. }
  109. $tMailbox[] = $row;
  110. }
  111. }
  112. $tCanAddAlias = false;
  113. $tCanAddMailbox = false;
  114. $limit = get_domain_properties($fDomain);
  115. if (isset ($limit)) {
  116. if ($fDisplay >= $page_size) {
  117. $tDisplay_back_show = 1;
  118. $tDisplay_back = $fDisplay - $page_size;
  119. }
  120. if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) {
  121. $tDisplay_up_show = 1;
  122. }
  123. if ((($fDisplay + $page_size) < $limit['alias_count']) or
  124. (($fDisplay + $page_size) < $limit['mailbox_count']))
  125. {
  126. $tDisplay_next_show = 1;
  127. $tDisplay_next = $fDisplay + $page_size;
  128. }
  129. $active = $limit['active'];
  130. if($active == 't' || $active == 1) {
  131. $backup_mx = $limit['backupmx'];
  132. if($backup_mx == 'f' || $backup_mx == 0) {
  133. if($limit['aliases'] == 0) {
  134. $tCanAddAlias = true;
  135. }
  136. elseif($limit['alias_count'] < $limit['aliases']) {
  137. $tCanAddAlias = true;
  138. }
  139. if($limit['mailboxes'] == 0) {
  140. $tCanAddMailbox = true;
  141. }
  142. elseif($limit['mailbox_count'] < $limit['mailboxes']) {
  143. $tCanAddMailbox = true;
  144. }
  145. }
  146. }
  147. }
  148. include ("templates/header.tpl");
  149. include ("templates/menu.tpl");
  150. include ("templates/list-virtual.tpl");
  151. include ("templates/footer.tpl");
  152. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  153. ?>