viewlog.php 2.4 KB

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