PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/sources/admin/ManageBadBehavior.php

https://github.com/Arantor/Elkarte
PHP | 158 lines | 100 code | 22 blank | 36 comment | 15 complexity | d5711746d670dca64a46d9b44fbb49eb MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * @version 1.0 Alpha
  8. *
  9. */
  10. if (!defined('ELKARTE'))
  11. die('No access...');
  12. /**
  13. * View the forum's badbehavior log.
  14. * This function sets all the context up to show the badbehavior log for review.
  15. * It requires the maintain_forum permission.
  16. * It is accessed from ?action=admin;area=logs;sa=errorlog.
  17. *
  18. * @uses the BadBehavior template and badbehavior_log sub template.
  19. */
  20. function action_badbehaviorlog()
  21. {
  22. global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
  23. // Check for the administrative permission to do this.
  24. isAllowedTo('admin_forum');
  25. // Templates, etc...
  26. loadLanguage('BadBehaviorlog');
  27. loadTemplate('BadBehavior');
  28. // Functions we will need
  29. require_once(SUBSDIR . '/BadBehavior.subs.php');
  30. // You can filter by any of the following columns:
  31. $filters = array(
  32. 'id_member' => $txt['badbehaviorlog_username'],
  33. 'ip' => $txt['badbehaviorlog_ip'],
  34. 'session' => $txt['badbehaviorlog_session'],
  35. 'valid' => $txt['badbehaviorlog_key'],
  36. 'request_uri' => $txt['badbehaviorlog_request'],
  37. 'user_agent' => $txt['badbehaviorlog_agent'],
  38. );
  39. // Set up the filtering...
  40. $filter = array();
  41. if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
  42. {
  43. $filter = array(
  44. 'variable' => $_GET['filter'] == 'useragent' ? 'user_agent' : $_GET['filter'],
  45. 'value' => array(
  46. 'sql' => in_array($_GET['filter'], array('request_uri', 'user_agent')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
  47. ),
  48. 'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
  49. 'entity' => $filters[$_GET['filter']]
  50. );
  51. }
  52. elseif (isset($_GET['filter']) || isset($_GET['value']))
  53. {
  54. // Bad filter or something else going on, back to the start you go
  55. unset($_GET['filter'], $_GET['value']);
  56. redirectexit('action=admin;area=logs;sa=badbehaviorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
  57. }
  58. // Deleting or just doing a little weeding?
  59. if (isset($_POST['delall']) || isset($_POST['delete']))
  60. deleteBadBehavior($filter);
  61. // Just how many entries are there?
  62. $num_errors = getBadBehaviorLogEntryCount($filter);
  63. // If this filter turns up empty, just return
  64. if (empty($num_errors) && !empty($filter))
  65. redirectexit('action=admin;area=logs;sa=badbehaviorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
  66. // Clean up start.
  67. $start = (!isset($_GET['start']) || $_GET['start'] < 0) ? 0 : (int) $_GET['start'];
  68. // Do we want to reverse the listing?
  69. $sort = isset($_REQUEST['desc']) ? 'up' : 'down';
  70. // Set the page listing up.
  71. $context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=logs;sa=badbehaviorlog' . ($sort == 'down' ? ';desc' : '') . (!empty($filter) ? $filter['href'] : ''), $start, $num_errors, $modSettings['defaultMaxMessages']);
  72. // Find and sort out the log entries.
  73. getBadBehaviorLogEntries($start, $modSettings['defaultMaxMessages'], $sort, $members, $filter);
  74. // Load the member data so we have more information available
  75. if (!empty($members))
  76. {
  77. // Get some additional member info...
  78. $request = $smcFunc['db_query']('', '
  79. SELECT id_member, member_name, real_name
  80. FROM {db_prefix}members
  81. WHERE id_member IN ({array_int:member_list})
  82. LIMIT ' . count($members),
  83. array(
  84. 'member_list' => $members,
  85. )
  86. );
  87. while ($row = $smcFunc['db_fetch_assoc']($request))
  88. $members[$row['id_member']] = $row;
  89. $smcFunc['db_free_result']($request);
  90. // This is a spammer or a guest :D
  91. $members[0] = array(
  92. 'id_member' => 0,
  93. 'member_name' => '',
  94. 'real_name' => $txt['guest_title']
  95. );
  96. // Go through each entry and add the member data.
  97. foreach ($context['bb_entries'] as $id => $dummy)
  98. {
  99. $memID = $context['bb_entries'][$id]['member']['id'];
  100. $context['bb_entries'][$id]['member']['username'] = $members[$memID]['member_name'];
  101. $context['bb_entries'][$id]['member']['name'] = $members[$memID]['real_name'];
  102. $context['bb_entries'][$id]['member']['href'] = empty($memID) ? '' : $scripturl . '?action=profile;u=' . $memID;
  103. $context['bb_entries'][$id]['member']['link'] = empty($memID) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $memID . '">' . $context['bb_entries'][$id]['member']['name'] . '</a>';
  104. }
  105. }
  106. // Filtering?
  107. if (!empty($filter))
  108. {
  109. $context['filter'] = $filter;
  110. // Set the filtering context.
  111. if ($filter['variable'] === 'id_member')
  112. {
  113. $id = $filter['value']['sql'];
  114. loadMemberData($id, false, 'minimal');
  115. $context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
  116. }
  117. elseif ($filter['variable'] === 'url')
  118. {
  119. $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars((substr($filter['value']['sql'], 0, 1) === '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
  120. }
  121. elseif ($filter['variable'] === 'headers')
  122. {
  123. $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars($filter['value']['sql']), array("\n" => '<br />', '&lt;br /&gt;' => '<br />', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
  124. $context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
  125. }
  126. else
  127. $context['filter']['value']['html'] = $filter['value']['sql'];
  128. }
  129. // And the standard template goodies
  130. $context['page_title'] = $txt['badbehaviorlog_log'];
  131. $context['has_filter'] = !empty($filter);
  132. $context['sub_template'] = 'badbehavior_log';
  133. $context['sort_direction'] = $sort;
  134. $context['start'] = $start;
  135. createToken('admin-bbl');
  136. }