PluginProbe
Easy Basic Authentication – Add basic auth to site or admin area / 2.2
Easy Basic Authentication – Add basic auth to site or admin area v2.2
trunk 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 1.8 1.8.1 1.9 All 50 releases
easy-basic-authentication / class / easy-basic-authentication-log-class.php

easy-basic-authentication-log-class.php in Easy Basic Authentication – Add basic auth to site or admin area 2.2, at class/easy-basic-authentication-log-class.php

82 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class easy_basic_authentication_log_class {
4
5 public function __construct()
6 {
7
8 }
9
10 public function is_enabled() {
11 return get_option( 'basic_auth_plugin_admin_log_enable' );
12 }
13
14 public function update_status($access) {
15 $logs = get_option('basic_auth_failure_logs', array());
16
17 $log_entry = array(
18 'id' => uniqid(),
19 'ip' => esc_attr($access['REMOTE_ADDR']),
20 'data' => current_time('mysql'),
21 'browser' => esc_attr($access['HTTP_USER_AGENT']),
22 'request_uri' => esc_attr($access["REQUEST_URI"]),
23 'viewed' => 0
24 );
25
26 $log_entry = apply_filters('basic_auth_single_log_entry', $log_entry);
27
28 $logs[] = $log_entry;
29
30 $logs = apply_filters('basic_auth_logs_entry', $logs);
31
32 update_option('basic_auth_failure_logs', $logs);
33 }
34
35 public function getMenu() {
36 $access_count = $this->basic_auth_count_not_viewed_log_failed_access();
37 add_submenu_page(
38 'basic-auth-plugin',
39 __('Log Page', 'easy-basic-authentication'),
40 __('Log Page', 'easy-basic-authentication'). '<span class="update-plugins count-' . $access_count . '"><span class="plugin-count">' . $access_count . '</span></span>',
41 'manage_options',
42 'basic-auth-login',
43 array($this, 'basic_auth_login_page')
44 );
45 }
46
47 public function basic_auth_not_viewed_log_failed_access() {
48 $return_not_viewed = array_filter($this->basic_auth_get_log_failed_access(), function ($entry) {
49 return isset($entry['viewed']) && $entry['viewed'] === 0;
50 });
51 return $return_not_viewed;
52 }
53
54 public function basic_auth_count_not_viewed_log_failed_access() {
55 return count($this->basic_auth_not_viewed_log_failed_access());
56 }
57
58 public function basic_auth_get_log_failed_access() {
59 return get_option('basic_auth_failure_logs', array());
60 }
61
62 public function basic_auth_count_log_failed_access() {
63 return count($this->basic_auth_get_log_failed_access());
64 }
65
66 public function basic_auth_login_page() {
67 if(array_key_exists('clear_mode',$_POST)) {
68 update_option('basic_auth_failure_logs', array());
69 }
70 $user_log_data = array_reverse($this->basic_auth_get_log_failed_access());
71 include plugin_dir_path( __FILE__ ) . '../template/log_page.php';
72 $this->update_view();
73 }
74
75 public function update_view() {
76 $logs = get_option('basic_auth_failure_logs', array());
77 foreach ($logs as &$entry) {
78 $entry['viewed'] = 1;
79 }
80 update_option('basic_auth_failure_logs', $logs);
81 }
82 }