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.

90 lines
2.4 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: viewlog.php
  16. * Shows entries from the log table to users.
  17. *
  18. * Template File: viewlog.tpl
  19. *
  20. * Template Variables:
  21. *
  22. * tMessage
  23. * tLog
  24. *
  25. * Form POST \ GET Variables:
  26. *
  27. * fDomain
  28. */
  29. require_once('common.php');
  30. authentication_require_role('admin');
  31. $SESSID_USERNAME = authentication_get_username();
  32. if(authentication_has_role('global-admin')) {
  33. $list_domains = list_domains ();
  34. }
  35. else {
  36. $list_domains = list_domains_for_admin ($SESSID_USERNAME);
  37. }
  38. if ($_SERVER['REQUEST_METHOD'] == "GET")
  39. {
  40. if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) $fDomain = $list_domains[0];
  41. } elseif ($_SERVER['REQUEST_METHOD'] == "POST") {
  42. if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
  43. } else {
  44. die('Unknown request method');
  45. }
  46. if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')))
  47. {
  48. $error = 1;
  49. $tMessage = $PALANG['pViewlog_result_error'];
  50. }
  51. // we need to initialize $tLog as an array!
  52. $tLog = array();
  53. if ($error != 1)
  54. {
  55. $query = "SELECT timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
  56. if ('pgsql'==$CONF['database_type'])
  57. {
  58. $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10";
  59. }
  60. $result=db_query($query);
  61. if ($result['rows'] > 0)
  62. {
  63. while ($row = db_array ($result['result']))
  64. {
  65. if ('pgsql'==$CONF['database_type'])
  66. {
  67. $row['timestamp']=gmstrftime('%c %Z',$row['timestamp']);
  68. }
  69. $tLog[] = $row;
  70. }
  71. }
  72. }
  73. for ($i = 0; $i < count ($tLog); $i++)
  74. $tLog[$i]['action'] = $PALANG ['pViewlog_action_'.$tLog [$i]['action']];
  75. $smarty->assign ('select_options', select_options ($list_domains, array ($fDomain)), false);
  76. $smarty->assign ('tLog', $tLog,false);
  77. $smarty->assign ('fDomain', $fDomain);
  78. $smarty->assign ('smarty_template', 'viewlog');
  79. $smarty->display ('index.tpl');
  80. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  81. ?>