PluginProbe ʕ •ᴥ•ʔ
SiteGuard WP Plugin / 1.8.7
SiteGuard WP Plugin v1.8.7
1.8.7 1.8.6 1.8.6-beta1 1.8.6-beta2 1.8.4 1.8.5 1.8.3 1.8.2 1.8.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.4.3 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.11 1.7.12 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.0-beta1 1.8.0-beta2 1.8.0-beta3 1.8.0-beta4
siteguard / admin / siteguard-login-history-table.php
siteguard / admin Last commit date
siteguard-login-history-table.php 1 month ago siteguard-menu-admin-filter.php 1 month ago siteguard-menu-author-query.php 2 weeks ago siteguard-menu-captcha.php 1 month ago siteguard-menu-dashboard.php 1 month ago siteguard-menu-fail-once.php 1 month ago siteguard-menu-init.php 1 month ago siteguard-menu-login-alert.php 1 month ago siteguard-menu-login-history.php 1 month ago siteguard-menu-login-lock.php 1 month ago siteguard-menu-protect-xmlrpc.php 1 month ago siteguard-menu-rename-login.php 2 weeks ago siteguard-menu-same-error.php 1 month ago siteguard-menu-updates-notify.php 1 month ago siteguard-menu-waf-tuning-support.php 1 month ago siteguard-waf-exclude-rule-table.php 1 month ago
siteguard-login-history-table.php
288 lines
1 <?php
2 if ( ! class_exists( 'WP_List_Table' ) ) {
3 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
4 }
5
6 class SiteGuard_LoginHistory_Table extends WP_List_Table {
7 protected $filter_operation;
8 protected $filter_type;
9 protected $filter_login_name;
10 protected $filter_ip_address;
11 protected $filter_login_name_not;
12 protected $filter_ip_address_not;
13
14 function __construct() {
15 global $status, $page;
16
17 // Set parent defaults
18 parent::__construct(
19 array(
20 'singular' => 'event', // singular name of the listed records
21 'plural' => 'events', // plural name of the listed records
22 'ajax' => false, // does this table support ajax?
23 )
24 );
25 $referer = wp_get_referer();
26 if ( false === strpos( $referer, 'siteguard_login_history' ) ) {
27 unset( $_COOKIE['siteguard_log_filter_operation'] );
28 unset( $_COOKIE['siteguard_log_filter_type'] );
29 unset( $_COOKIE['siteguard_log_filter_login_name'] );
30 unset( $_COOKIE['siteguard_log_filter_ip_address'] );
31 unset( $_COOKIE['siteguard_log_filter_login_name_not'] );
32 unset( $_COOKIE['siteguard_log_filter_ip_address_not'] );
33 }
34 if ( isset( $_POST['filter_reset'] ) ) {
35 $this->filter_operation = SITEGUARD_LOGIN_NOSELECT;
36 $this->filter_type = SITEGUARD_LOGIN_TYPE_NOSELECT;
37 $this->filter_login_name = '';
38 $this->filter_ip_address = '';
39 $this->filter_login_name_not = false;
40 $this->filter_ip_address_not = false;
41 } else {
42 $this->filter_operation = $this->get_filter_operation();
43 $this->filter_type = $this->get_filter_type();
44 $this->filter_login_name = $this->get_filter_login_name();
45 $this->filter_ip_address = $this->get_filter_ip_address();
46 $this->filter_login_name_not = $this->get_filter_login_name_not();
47 $this->filter_ip_address_not = $this->get_filter_ip_address_not();
48 }
49 if ( '' === $this->filter_login_name ) {
50 $this->filter_login_name_not = false;
51 }
52 if ( '' === $this->filter_ip_address ) {
53 $this->filter_ip_address_not = false;
54 }
55 }
56
57 function column_default( $item, $column_name ) {
58 switch ( $column_name ) {
59 case 'operation':
60 return SiteGuard_LoginHistory::convert_operation( $item[ $column_name ] );
61 case 'type':
62 return SiteGuard_LoginHistory::convert_type( $item[ $column_name ] );
63 case 'time':
64 case 'login_name':
65 case 'ip_address':
66 return $item[ $column_name ];
67 default:
68 return print_r( $item, true ); // Show the whole array for troubleshooting purposes
69 }
70 }
71
72 function get_columns() {
73 $columns = array(
74 // 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
75 'time' => esc_html__( 'Date/Time', 'siteguard' ),
76 'operation' => esc_html__( 'Operation', 'siteguard' ),
77 'login_name' => esc_html__( 'Username', 'siteguard' ),
78 'ip_address' => esc_html__( 'IP Address', 'siteguard' ),
79 'type' => esc_html__( 'Type', 'siteguard' ),
80 );
81 return $columns;
82 }
83
84 function get_sortable_columns() {
85 $sortable_columns = array(
86 'time' => array( 'id', true ), // true means it's already sorted
87 'operation' => array( 'operation', false ), // true means it's already sorted
88 'login_name' => array( 'login_name', false ),
89 'ip_address' => array( 'ip_address', false ),
90 'type' => array( 'type', false ),
91 );
92 return $sortable_columns;
93 }
94
95 function get_bulk_actions() {
96 // $actions = array(
97 // 'delete' => __( 'Delete' ),
98 // );
99 $actions = array();
100 return $actions;
101 }
102
103
104 function process_bulk_action() {
105 return;
106 }
107
108 function usort_reorder( $a, $b ) {
109 $orderby_values = array( 'id', 'operation', 'time', 'login_name', 'ip_address', 'type' );
110 $order_values = array( 'asc', 'desc' );
111 $orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? ( in_array( $_REQUEST['orderby'], $orderby_values ) ? sanitize_key( $_REQUEST['orderby'] ) : 'id' ) : 'id'; // If no sort, default to id
112 $order = ( ! empty( $_REQUEST['order'] ) ) ? ( in_array( $_REQUEST['order'], $order_values ) ? sanitize_key( $_REQUEST['order'] ) : 'desc' ) : 'desc'; // If no order, default to desc
113 if ( 'id' == $orderby ) {
114 $result = ( $a > $b ? 1 : ( $a < $b ? -1 : 0 ) );
115 } else {
116 $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); // Determine sort order
117 }
118 return ( 'asc' == $order ) ? $result : -$result; // Send final sort direction to usort
119 }
120 function get_filter_param_normal( $name, $default ) {
121 $result = $default;
122 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
123 if ( isset( $_POST['siteguard_filter_nonce'] ) && wp_verify_nonce( $_POST['siteguard_filter_nonce'], 'siteguard_login_history_filter' ) ) {
124 if ( isset( $_POST[ $name ] ) ) {
125 $result = sanitize_text_field( $_POST[ $name ] );
126 }
127 }
128 } else {
129 $cookie_name = 'siteguard_log_' . $name;
130 if ( isset( $_COOKIE[ $cookie_name ] ) ) {
131 $result = sanitize_text_field( $_COOKIE[ $cookie_name ] );
132 }
133 }
134 return $result;
135 }
136 function get_filter_param_operator( $name, $default ) {
137 $result = $default;
138 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
139 if ( isset( $_POST['siteguard_filter_nonce'] ) && wp_verify_nonce( $_POST['siteguard_filter_nonce'], 'siteguard_login_history_filter' ) ) {
140 if ( isset( $_POST['filter_action'] ) ) {
141 if ( isset( $_POST[ $name ] ) && 'not' === sanitize_text_field( $_POST[ $name ] ) ) {
142 $result = true;
143 } else {
144 $result = false;
145 }
146 }
147 }
148 } else {
149 $cookie_name = 'siteguard_log_' . $name;
150 if ( isset( $_COOKIE[ $cookie_name ] ) ) {
151 $result = ( 'not' === $_COOKIE[ $cookie_name ] );
152 } else {
153 $result = false;
154 }
155 }
156 return $result;
157 }
158 function get_filter_operation() {
159 global $siteguard_login_history;
160 $result = $this->get_filter_param_normal( 'filter_operation', SITEGUARD_LOGIN_NOSELECT );
161 if ( ! $siteguard_login_history->check_operation( $result ) ) {
162 $result = SITEGUARD_LOGIN_NOSELECT;
163 }
164 return $result;
165 }
166 function get_filter_type() {
167 global $siteguard_login_history;
168 $result = $this->get_filter_param_normal( 'filter_type', SITEGUARD_LOGIN_TYPE_NOSELECT );
169 if ( ! $siteguard_login_history->check_type( $result ) ) {
170 $result = SITEGUARD_LOGIN_TYPE_NOSELECT;
171 }
172 return $result;
173 }
174 function get_filter_login_name() {
175 return $this->get_filter_param_normal( 'filter_login_name', '' );
176 }
177 function get_filter_ip_address() {
178 return $this->get_filter_param_normal( 'filter_ip_address', '' );
179 }
180 function get_filter_login_name_not() {
181 return $this->get_filter_param_operator( 'filter_login_name_not', false );
182 }
183 function get_filter_ip_address_not() {
184 return $this->get_filter_param_operator( 'filter_ip_address_not', false );
185 }
186 function operation_dropdown() {
187 ?>
188 <select name="filter_operation" id="filter-by-operation">
189 <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_NOSELECT ); ?> value="<?php echo SITEGUARD_LOGIN_NOSELECT; ?>"><?php echo esc_html__( 'All Operations', 'siteguard' ); ?></option>
190 <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_SUCCESS ); ?> value="<?php echo SITEGUARD_LOGIN_SUCCESS; ?>"><?php echo esc_html__( 'Success', 'siteguard' ); ?></option>
191 <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_FAILED ); ?> value="<?php echo SITEGUARD_LOGIN_FAILED; ?>"><?php echo esc_html__( 'Failed', 'siteguard' ); ?></option>
192 <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_FAIL_ONCE ); ?> value="<?php echo SITEGUARD_LOGIN_FAIL_ONCE; ?>"><?php echo esc_html__( 'Fail Once', 'siteguard' ); ?></option>
193 <option <?php selected( $this->filter_operation, SITEGUARD_LOGIN_LOCKED ); ?> value="<?php echo SITEGUARD_LOGIN_LOCKED; ?>"><?php echo esc_html__( 'Locked', 'siteguard' ); ?></option>
194 </select>
195 <?php
196 }
197 function login_name_input() {
198 ?>
199 <select name="filter_login_name_not" id="filter-login-name-not">
200 <option <?php selected( $this->filter_login_name_not, false ); ?> value="is"><?php echo esc_html__( 'is', 'siteguard' ); ?></option>
201 <option <?php selected( $this->filter_login_name_not, true ); ?> value="not"><?php echo esc_html__( 'is not', 'siteguard' ); ?></option>
202 </select>
203 <input type="text" name="filter_login_name" id="filter-login-name" size="15" value="<?php echo esc_attr( $this->filter_login_name ); ?>">
204 <?php
205 }
206 function ip_address_input() {
207 ?>
208 <select name="filter_ip_address_not" id="filter-ip-address-not">
209 <option <?php selected( $this->filter_ip_address_not, false ); ?> value="is"><?php echo esc_html__( 'is', 'siteguard' ); ?></option>
210 <option <?php selected( $this->filter_ip_address_not, true ); ?> value="not"><?php echo esc_html__( 'is not', 'siteguard' ); ?></option>
211 </select>
212 <input type="text" name="filter_ip_address" id="filter-ip-address" size="15" value="<?php echo esc_attr( $this->filter_ip_address ); ?>">
213 <?php
214 }
215 function type_dropdown() {
216 ?>
217 <select name="filter_type" id="filter-type">
218 <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_NOSELECT ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_NOSELECT; ?>"><?php echo esc_html__( 'All Types', 'siteguard' ); ?></option>
219 <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_NORMAL ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_NORMAL; ?>"><?php echo esc_html__( 'Login Page', 'siteguard' ); ?></option>
220 <option <?php selected( $this->filter_type, SITEGUARD_LOGIN_TYPE_XMLRPC ); ?> value="<?php echo SITEGUARD_LOGIN_TYPE_XMLRPC; ?>"><?php echo esc_html__( 'XML-RPC', 'siteguard' ); ?></option>
221 </select>
222 <?php
223 }
224 function extra_tablenav( $witch ) {
225 if ( 'bottom' == $witch ) {
226 return;
227 }
228 ?>
229 <div class="alignleft actions bulkactions siteguard-login-history-filter">
230 <table class="siteguard-login-history-filter-table">
231 <tr>
232 <td><label for="filter-operation"><?php echo esc_html__( 'Operation', 'siteguard' ) . ':'; ?></label></td>
233 <td><?php $this->operation_dropdown(); ?></td>
234 <td width="30px"></td>
235 <td><label for="filter-login-name" ><?php echo esc_html__( 'Username', 'siteguard' ) . ':'; ?></label></td>
236 <td><?php $this->login_name_input(); ?></td>
237 </tr><tr>
238 <td><label for="filter-type" ><?php echo esc_html__( 'Type', 'siteguard' ) . ':'; ?></label></td>
239 <td><?php $this->type_dropdown(); ?></td>
240 <td></td>
241 <td><label for="filter-ip-address" ><?php echo esc_html__( 'IP Address', 'siteguard' ) . ':'; ?></label></td>
242 <td><?php $this->ip_address_input(); ?></td>
243 </tr>
244 </table>
245 <input type="submit" name="filter_action" id="post-query-submit" class="button" value="<?php echo esc_attr__( 'Filter' ); ?>">
246 <input type="submit" name="filter_reset" id="post-query-reset" class="button" value="<?php echo esc_attr__( 'All' ); ?>">
247 </div>
248 <?php
249 }
250
251 function prepare_items() {
252 global $siteguard_login_history;
253
254 $per_page = 10;
255
256 $columns = $this->get_columns();
257 $hidden = array();
258 $sortable = $this->get_sortable_columns();
259
260 $this->_column_headers = array( $columns, $hidden, $sortable );
261
262 $this->process_bulk_action();
263
264 $data = $siteguard_login_history->get_history( $this->filter_operation, $this->filter_login_name, $this->filter_ip_address, $this->filter_type, $this->filter_login_name_not, $this->filter_ip_address_not );
265
266 $total_items = count( $data );
267 $current_page = $this->get_pagenum();
268
269 if ( $total_items <= ( ( $current_page - 1 ) * $per_page ) ) {
270 $current_page = 1;
271 }
272 if ( $total_items > 0 ) {
273 usort( $data, array( $this, 'usort_reorder' ) );
274 $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
275 }
276
277 $this->items = $data;
278
279 $this->set_pagination_args(
280 array(
281 'total_items' => $total_items, // WE have to calculate the total number of items
282 'per_page' => $per_page, // WE have to determine how many items to show on a page
283 'total_pages' => ceil( $total_items / $per_page ), // WE have to calculate the total number of pages
284 )
285 );
286 }
287 }
288