PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/better-wp-security/core/class-itsec-logger-all-logs.php

https://gitlab.com/najomie/fit-hippie
PHP | 260 lines | 117 code | 62 blank | 81 comment | 11 complexity | a3a4f82c5f8d28ef0e2ad48c0ae19b1d MD5 | raw file
  1. <?php
  2. /**
  3. * Log tables for Authentication Module
  4. *
  5. * @package iThemes-Security
  6. * @subpackage Authentication
  7. * @since 4.0
  8. */
  9. final class ITSEC_Logger_All_Logs extends ITSEC_WP_List_Table {
  10. function __construct() {
  11. parent::__construct(
  12. array(
  13. 'singular' => 'itsec_raw_log_item',
  14. 'plural' => 'itsec_raw_log_items',
  15. 'ajax' => true
  16. )
  17. );
  18. }
  19. /**
  20. * Define type column
  21. *
  22. * @param array $item array of row data
  23. *
  24. * @return string formatted output
  25. *
  26. **/
  27. function column_time( $item ) {
  28. return $item['time'];
  29. }
  30. /**
  31. * Define function column
  32. *
  33. * @param array $item array of row data
  34. *
  35. * @return string formatted output
  36. *
  37. **/
  38. function column_function( $item ) {
  39. return $item['function'];
  40. }
  41. /**
  42. * Define priority column
  43. *
  44. * @param array $item array of row data
  45. *
  46. * @return string formatted output
  47. *
  48. **/
  49. function column_priority( $item ) {
  50. return $item['priority'];
  51. }
  52. /**
  53. * Define host column
  54. *
  55. * @param array $item array of row data
  56. *
  57. * @return string formatted output
  58. *
  59. **/
  60. function column_host( $item ) {
  61. require_once( ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-ip-tools.php' );
  62. $r = array();
  63. if ( ! is_array( $item['host'] ) ) {
  64. $item['host'] = array( $item['host'] );
  65. }
  66. foreach ( $item['host'] as $host ) {
  67. if ( ITSEC_Lib_IP_Tools::validate( $host ) ) {
  68. $r[] = '<a href="' . esc_url( ITSEC_Lib::get_trace_ip_link( $host ) ) . '" target="_blank" rel="noopener noreferrer">' . esc_html( $host ) . '</a>';
  69. }
  70. }
  71. $return = implode( '<br />', $r );
  72. return $return;
  73. }
  74. /**
  75. * Define username column
  76. *
  77. * @param array $item array of row data
  78. *
  79. * @return string formatted output
  80. *
  81. **/
  82. function column_user( $item ) {
  83. if ( 0 != $item['user_id'] ) {
  84. return '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $item['user_id'] ) ) . '" target="_blank" rel="noopener noreferrer">' . $item['user'] . '</a>';
  85. } else {
  86. return $item['user'];
  87. }
  88. }
  89. /**
  90. * Define url column
  91. *
  92. * @param array $item array of row data
  93. *
  94. * @return string formatted output
  95. *
  96. **/
  97. function column_url( $item ) {
  98. return $item['url'];
  99. }
  100. /**
  101. * Define referrer column
  102. *
  103. * @param array $item array of row data
  104. *
  105. * @return string formatted output
  106. *
  107. **/
  108. function column_referrer( $item ) {
  109. return $item['referrer'];
  110. }
  111. /**
  112. * Define data column
  113. *
  114. * @param array $item array of row data
  115. *
  116. * @return string formatted output
  117. *
  118. **/
  119. function column_data( $item ) {
  120. global $itsec_logger;
  121. $raw_data = maybe_unserialize( $item['data'] );
  122. $data = apply_filters( "itsec_logger_filter_{$item['type']}_data_column_details", '', $raw_data );
  123. if ( empty( $data ) ) {
  124. if ( is_array( $raw_data ) && sizeof( $raw_data ) > 0 ) {
  125. $data = $itsec_logger->print_array( $raw_data, true );
  126. } elseif ( ! is_array( $raw_data ) ) {
  127. $data = sanitize_text_field( $raw_data );
  128. } else {
  129. $data = '';
  130. }
  131. }
  132. if ( strlen( $data ) > 1 ) {
  133. $content = '<div class="itsec-all-log-dialog" id="itsec-log-all-row-' . $item['id'] . '" style="display:none;">';
  134. $content .= $data;
  135. $content .= '</div>';
  136. $content .= '<a href="itsec-log-all-row-' . $item['id'] . '" class="dialog">' . __( 'Details', 'better-wp-security' ) . '</a>';
  137. return $content;
  138. } else {
  139. return '';
  140. }
  141. }
  142. /**
  143. * Define Columns
  144. *
  145. * @return array array of column titles
  146. */
  147. public function get_columns() {
  148. return array(
  149. 'function' => __( 'Function', 'better-wp-security' ),
  150. 'priority' => __( 'Priority', 'better-wp-security' ),
  151. 'time' => __( 'Time', 'better-wp-security' ),
  152. 'host' => __( 'Host', 'better-wp-security' ),
  153. 'user' => __( 'User', 'better-wp-security' ),
  154. 'url' => __( 'URL', 'better-wp-security' ),
  155. 'referrer' => __( 'Referrer', 'better-wp-security' ),
  156. 'data' => __( 'Data', 'better-wp-security' ),
  157. );
  158. }
  159. /**
  160. * Prepare data for table
  161. *
  162. * @return void
  163. */
  164. public function prepare_items() {
  165. global $itsec_logger, $wpdb;
  166. $columns = $this->get_columns();
  167. $hidden = array();
  168. $this->_column_headers = array( $columns, $hidden, false );
  169. $per_page = 20; //20 items per page
  170. $current_page = $this->get_pagenum();
  171. $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->base_prefix . "itsec_log`;" );
  172. $items = $itsec_logger->get_events( 'all', array(), $per_page, ( ( $current_page - 1 ) * $per_page ), 'log_date' );
  173. $table_data = array();
  174. $count = 0;
  175. foreach ( $items as $item ) { //loop through and group 404s
  176. $table_data[ $count ]['id'] = $count;
  177. $table_data[ $count ]['type'] = sanitize_text_field( $item['log_type'] );
  178. $table_data[ $count ]['function'] = sanitize_text_field( $item['log_function'] );
  179. $table_data[ $count ]['priority'] = sanitize_text_field( $item['log_priority'] );
  180. $table_data[ $count ]['time'] = sanitize_text_field( $item['log_date'] );
  181. $table_data[ $count ]['host'] = sanitize_text_field( $item['log_host'] );
  182. $table_data[ $count ]['user'] = sanitize_text_field( $item['log_username'] );
  183. $table_data[ $count ]['user_id'] = sanitize_text_field( $item['log_user'] );
  184. $table_data[ $count ]['url'] = sanitize_text_field( $item['log_url'] );
  185. $table_data[ $count ]['referrer'] = sanitize_text_field( $item['log_referrer'] );
  186. $table_data[ $count ]['data'] = $item['log_data'];
  187. $count ++;
  188. }
  189. $this->items = $table_data;
  190. $this->set_pagination_args(
  191. array(
  192. 'total_items' => $total_items,
  193. 'per_page' => $per_page,
  194. 'total_pages' => ceil( $total_items / $per_page )
  195. )
  196. );
  197. }
  198. }