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.

133 lines
4.0 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: search.php
  16. * Provides a method for searching for a user/mailbox
  17. * Template File: search.php
  18. *
  19. * Template Variables:
  20. *
  21. * tAlias
  22. * tMailbox
  23. *
  24. * Form POST \ GET Variables:
  25. *
  26. * fSearch
  27. * fGo
  28. * fDomain
  29. */
  30. require_once('common.php');
  31. authentication_require_role('admin');
  32. $SESSID_USERNAME = authentication_get_username();
  33. if(authentication_has_role('global-admin')) {
  34. $list_domains = list_domains ();
  35. }
  36. else {
  37. $list_domains = list_domains_for_admin ($SESSID_USERNAME);
  38. }
  39. $tAlias = array();
  40. $tMailbox = array();
  41. if ($_SERVER['REQUEST_METHOD'] == "GET")
  42. {
  43. if (isset ($_GET['search'])) $fSearch = escape_string ($_GET['search']);
  44. if (isset ($_GET['fGo'])) $fGo = escape_string ($_GET['fGo']);
  45. if (isset ($_GET['fDomain'])) $fDomain = escape_string ($_GET['domain']);
  46. }
  47. if ($_SERVER['REQUEST_METHOD'] == "POST")
  48. {
  49. if (isset ($_POST['search'])) $fSearch = escape_string ($_POST['search']);
  50. if (isset ($_POST['fGo'])) $fGo = escape_string ($_POST['fGo']);
  51. if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
  52. }
  53. if (empty ($fSearch) /* && !empty ($fGo) */)
  54. {
  55. header("Location: list-virtual.php?domain=" . $fDomain ) && exit;
  56. }
  57. if ($CONF['alias_control_admin'] == "YES")
  58. {
  59. $query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto,
  60. $table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active
  61. FROM $table_alias
  62. WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address";
  63. }
  64. else
  65. {
  66. // find all aliases which don't have a matching entry in table_mailbox
  67. $query = "SELECT $table_alias.address AS address, $table_alias.goto AS goto,
  68. $table_alias.modified AS modified, $table_alias.domain AS domain, $table_alias.active AS active
  69. FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username
  70. WHERE address LIKE '%$fSearch%' AND $table_mailbox.maildir IS NULL ORDER BY $table_alias.address";
  71. }
  72. $result = db_query ($query);
  73. if ($result['rows'] > 0)
  74. {
  75. while ($row = db_array ($result['result']))
  76. {
  77. if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
  78. {
  79. if ('pgsql'==$CONF['database_type'])
  80. {
  81. $row['modified']=gmstrftime('%c %Z',$row['modified']);
  82. $row['active']=('t'==$row['active']) ? 1 : 0;
  83. }
  84. $tAlias[] = $row;
  85. }
  86. }
  87. }
  88. if ($CONF['vacation_control_admin'] == 'YES' && $CONF['vacation'] == 'YES')
  89. {
  90. $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.username LIKE '%$fSearch%' OR $table_mailbox.name LIKE '%$fSearch%' ORDER BY $table_mailbox.username");
  91. }
  92. else
  93. {
  94. $query = "SELECT * FROM $table_mailbox WHERE username LIKE '%$fSearch%' OR name LIKE '%$fSearch%' ORDER BY username";
  95. }
  96. $result = db_query ($query);
  97. if ($result['rows'] > 0)
  98. {
  99. while ($row = db_array ($result['result']))
  100. {
  101. if (check_owner ($SESSID_USERNAME, $row['domain']) || authentication_has_role('global-admin'))
  102. {
  103. if ('pgsql'==$CONF['database_type'])
  104. {
  105. $row['created']=gmstrftime('%c %Z',strtotime($row['created']));
  106. $row['modified']=gmstrftime('%c %Z',strtotime($row['modified']));
  107. $row['active']=('t'==$row['active']) ? 1 : 0;
  108. }
  109. $tMailbox[] = $row;
  110. }
  111. }
  112. }
  113. include ("templates/header.php");
  114. include ("templates/menu.php");
  115. include ("templates/search.php");
  116. include ("templates/footer.php");
  117. // vim:ts=4:sw=4:et
  118. ?>