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.

viewlog.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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$
  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. } else {
  33. $list_domains = list_domains_for_admin($SESSID_USERNAME);
  34. }
  35. $fDomain = '';
  36. $error = 0;
  37. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  38. if ((is_array($list_domains) and sizeof($list_domains) > 0)) {
  39. $fDomain = $list_domains[0];
  40. }
  41. } elseif ($_SERVER['REQUEST_METHOD'] == "POST") {
  42. if (isset($_POST['fDomain'])) {
  43. $fDomain = escape_string($_POST['fDomain']);
  44. }
  45. } else {
  46. die('Unknown request method');
  47. }
  48. if (! (check_owner($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))) {
  49. $error = 1;
  50. flash_error($PALANG['pViewlog_result_error']);
  51. }
  52. // we need to initialize $tLog as an array!
  53. $tLog = array();
  54. if ($error != 1) {
  55. $table_log = table_by_key('log');
  56. $page_size = isset($CONF['page_size']) ? intval($CONF['page_size']) : 35;
  57. $query = "SELECT timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT $page_size";
  58. if (db_pgsql()) {
  59. $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT $page_size";
  60. }
  61. $result=db_query($query);
  62. if ($result['rows'] > 0) {
  63. while ($row = db_assoc($result['result'])) {
  64. if (db_pgsql()) {
  65. $row['timestamp']=gmstrftime('%c %Z', $row['timestamp']);
  66. }
  67. $tLog[] = $row;
  68. }
  69. }
  70. }
  71. for ($i = 0; $i < count($tLog); $i++) {
  72. $tLog[$i]['action'] = $PALANG ['pViewlog_action_'.$tLog [$i]['action']];
  73. }
  74. $smarty->assign('domain_list', $list_domains);
  75. $smarty->assign('domain_selected', $fDomain);
  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: */