PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 1.3.10
CloudSecure WP Security v1.3.10
1.4.10 1.4.9 trunk 0.9.0 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.19 1.3.2 1.3.20 1.3.21 1.3.22 1.3.23 1.3.24 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8
cloudsecure-wp-security / modules / admin / login-log-table.php
cloudsecure-wp-security / modules / admin Last commit date
captcha.php 1 year ago common.php 1 year ago dashboard.php 1 year ago disable-access-system-file.php 1 year ago disable-author-query.php 1 year ago disable-login.php 1 year ago disable-restapi.php 1 year ago disable-xmlrpc.php 1 year ago login-log-table.php 1 year ago login-log.php 1 year ago login-notification.php 1 year ago rename-login-page.php 1 year ago restrict-admin-page.php 1 year ago server-error-notification.php 1 year ago server-error-table.php 1 year ago two-factor-authentication-registration.php 2 years ago two-factor-authentication.php 1 year ago unify-messages.php 1 year ago update-notice.php 1 year ago waf-table.php 1 year ago waf.php 1 year ago
login-log-table.php
280 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if ( ! class_exists( 'WP_List_Table' ) ) {
8 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9 }
10
11 class CloudSecureWP_Login_Log_Table extends WP_List_Table {
12 private $login_log;
13 private $per_page = 50;
14 private $conditions = array();
15 private $allowed_html;
16
17 function __construct( CloudSecureWP_Login_Log $login_log ) {
18 parent::__construct(
19 array(
20 'ajax' => false,
21 )
22 );
23 $this->login_log = $login_log;
24 }
25
26 /**
27 * 条件設定
28 *
29 * @param $conditions
30 * @return void
31 */
32 public function set_condition( array $conditions ): void {
33 $this->conditions = $conditions;
34 }
35
36 /**
37 * 絞込み条件保存
38 *
39 * @return void
40 */
41 public function save_conditions(): void {
42 $this->login_log->save_conditions( $this->conditions );
43 }
44
45 protected function pagination( $which ) {
46 if ( 'top' === $which ) {
47 return;
48 }
49 parent::pagination( 'top' );
50 }
51
52 protected function get_table_classes() {
53 $classes = parent::get_table_classes();
54 $classes[] = 'custom-table-class';
55 return $classes;
56 }
57
58 /**
59 * 条件取得
60 *
61 * @return array
62 */
63 public function get_conditions(): array {
64 $this->conditions = $this->login_log->get_conditions();
65 return $this->conditions;
66 }
67
68 function column_default( $item, $column ) {
69 $login_status_datas = $this->login_log->get_login_status_datas();
70 $methods = $this->login_log->get_methods();
71
72 switch ( $column ) {
73 case 'status':
74 return esc_html( $login_status_datas[ $item[ $column ] ] );
75 case 'method':
76 return esc_html( $methods[ $item[ $column ] ] );
77 case 'id':
78 case 'name':
79 case 'ip':
80 case 'login_at':
81 return esc_html( $item[ $column ] );
82 default:
83 return '';
84 }
85 }
86
87 function get_columns() {
88 $column_datas = $this->login_log->get_cloumns();
89
90 return array(
91 'login_at' => $column_datas['login_at'],
92 'status' => $column_datas['status'],
93 'ip' => $column_datas['ip'],
94 'method' => $column_datas['method'],
95 'name' => $column_datas['name'],
96 'id' => $column_datas['id'],
97 );
98 }
99
100 function get_hidden_columns() {
101 return array(
102 'id',
103 );
104 }
105
106 function get_sortable_columns() {
107 return array(
108 'login_at' => array( 'login_at', false ),
109 'status' => array( 'status', false ),
110 'ip' => array( 'ip', false ),
111 'method' => array( 'method', false ),
112 'name' => array( 'name', false ),
113 'id' => array( 'id', false ),
114 );
115 }
116
117 function usort_reorder( $a, $b ) {
118 $cloumns = $this->login_log->get_cloumns();
119 $orderby = 'login_at';
120
121 if ( array_key_exists( sanitize_text_field( $_GET['orderby'] ?? '' ), $cloumns ) ) {
122 $orderby = sanitize_text_field( $_GET['orderby'] );
123 }
124
125 $order = sanitize_text_field( $_GET['order'] ?? 'desc' );
126 if ( 'desc' !== $order ) {
127 $order = 'asc';
128 }
129
130 switch ( $orderby ) {
131 case 'id':
132 case 'status':
133 case 'method':
134 $result = ( (int) $a[ $orderby ] > (int) $b[ $orderby ] ? 1 : ( (int) $a[ $orderby ] < (int) $b[ $orderby ] ? -1 : 0 ) );
135 break;
136 case 'ip':
137 $a_ip = (int) sprintf( '%u', ip2long( $a[ $orderby ] ) );
138 $b_ip = (int) sprintf( '%u', ip2long( $b[ $orderby ] ) );
139 $result = ( $a_ip > $b_ip ? 1 : ( $a_ip < $b_ip ? -1 : 0 ) );
140 break;
141 default:
142 $result = strcmp( $a[ $orderby ], $b[ $orderby ] );
143 }
144
145 return ( $order === 'asc' ) ? $result : -$result;
146 }
147
148 function prepare_items() {
149 $columns = $this->get_columns();
150 $hidden = $this->get_hidden_columns();
151 $sortable = $this->get_sortable_columns();
152
153 $this->_column_headers = array( $columns, $hidden, $sortable );
154 $conditions = $this->get_conditions();
155
156 $login_log_rows = $this->login_log->get_login_history( $conditions );
157 $login_log_rows_count = count( $login_log_rows );
158
159 $current_page = $this->get_pagenum();
160 $max_page = (int) ceil( $login_log_rows_count / $this->per_page );
161
162 if ( $max_page < $current_page ) {
163 $current_page = $max_page;
164 }
165
166 $view_rows = array();
167 if ( 0 < $login_log_rows_count ) {
168 usort( $login_log_rows, array( &$this, 'usort_reorder' ) );
169 $view_rows = array_slice( $login_log_rows, ( ( $current_page - 1 ) * $this->per_page ), $this->per_page );
170 }
171 $this->items = $view_rows;
172
173 $this->set_pagination_args(
174 array(
175 'total_items' => $login_log_rows_count,
176 'per_page' => $this->per_page,
177 'total_pages' => ceil( $login_log_rows_count / $this->per_page ),
178 )
179 );
180 }
181
182 function extra_tablenav( $witch ) {
183 if ( 'top' === $witch ) {
184 $this->condition_view();
185 }
186 }
187
188
189 /**
190 * option 作成
191 *
192 * @param array $datas
193 * @param string $condition
194 * @return string
195 */
196 public function make_option( array $datas, string $condition ): string {
197 $options = '';
198 foreach ( $datas as $key => $val ) {
199
200 $selected = '';
201 if ( (string) $condition === (string) $key ) {
202 $selected = ' selected';
203 }
204 $options .= '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
205 }
206 return $options . "\n";
207 }
208
209 /**
210 * 絞込み条件
211 */
212 public function condition_view(): void {
213 $this->allowed_html = array(
214 'option' => array(
215 'value' => array(),
216 'selected' => array(),
217 ),
218 );
219
220 $login_status_datas = $this->login_log->get_login_status_datas();
221 $condition_status = $this->conditions['condition_status'] ?? '';
222 $status_options = $this->make_option( $login_status_datas, $condition_status );
223
224 $login_method_datas = $this->login_log->get_methods();
225 $condition_method = $this->conditions['condition_method'] ?? '';
226 $method_options = $this->make_option( $login_method_datas, $condition_method );
227
228 $condition_ip_other_than_t = '';
229 $condition_name_other_than_t = '';
230
231 $condition_ip = $this->conditions['condition_ip'] ?? '';
232 if ( '' !== $condition_ip ) {
233 $condition_ip_other_than = $this->conditions['condition_ip_other_than'] ?? '';
234 $condition_ip_other_than_t = $condition_ip_other_than === 't' ? 'checked' : '';
235 }
236
237 $condition_name = $this->conditions['condition_name'] ?? '';
238 if ( '' !== $condition_name ) {
239 $condition_name_other_than = $this->conditions['condition_name_other_than'] ?? '';
240 $condition_name_other_than_t = $condition_name_other_than === 't' ? 'checked' : '';
241 }
242 ?>
243 <div class="alignleft bulkactions login-log">
244 <div class="login-log-rows">
245 <div class="login-log-row">
246 <span>ログイン判定</span>
247 <select name="condition_status">
248 <option value="">--</option>
249 <?php echo wp_kses( $status_options, $this->allowed_html ); ?>
250 </select>
251 <div class="login-log-row-right">
252 <span>IPアドレス</span>
253 <input type="text" class="mr-12" name="condition_ip" placeholder="例)192.0.2.1" value="<?php echo esc_attr( $condition_ip ); ?>" maxlength="39"><br>
254 <input class="checkbox" id="condition_ip" type="checkbox" name="condition_ip_other_than" value="t" <?php echo esc_html( $condition_ip_other_than_t ); ?>><label for="condition_ip">を除く</label>
255 </div>
256 </div>
257 <div class="login-log-row">
258 <span>ログイン種別</span>
259 <select name="condition_method">
260 <option value="">--</option>
261 <?php echo wp_kses( $method_options, $this->allowed_html ); ?>
262 </select>
263 <div class="login-log-row-right">
264 <span>ユーザー名</span>
265 <input type="text" class="mr-12" name="condition_name" placeholder="例)user_name" value="<?php echo esc_attr( $condition_name ); ?>" maxlength="60"><br>
266 <input class="checkbox" id="condition_name" type="checkbox" name="condition_name_other_than" value="t" <?php echo esc_html( $condition_name_other_than_t ); ?>><label for="condition_name">を除く</label>
267 </div>
268 </div>
269 </div>
270 <div class="login-log-btns">
271 <?php wp_nonce_field( $this->login_log->get_feature_key() . '_csrf' ); ?>
272 <input type="submit" class="login-log-reset-btn" name="reset" value="クリア">
273 <input type="submit" class="login-log-done-btn" name="done" value="絞り込み">
274 </div>
275 </div>
276
277 <?php
278 }
279 }
280