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-menu-login-history.php
113 lines
| 1 | <?php |
| 2 | |
| 3 | require_once 'siteguard-login-history-table.php'; |
| 4 | |
| 5 | class SiteGuard_Menu_Login_History extends SiteGuard_Base { |
| 6 | protected $wp_list_table; |
| 7 | function __construct() { |
| 8 | $this->wp_list_table = new SiteGuard_LoginHistory_Table(); |
| 9 | $this->wp_list_table->prepare_items(); |
| 10 | $this->render_page(); |
| 11 | } |
| 12 | function render_page() { |
| 13 | global $siteguard_config, $siteguard_login_history; |
| 14 | $img_path = SITEGUARD_URL_PATH . 'images/'; |
| 15 | echo '<div class="wrap">'; |
| 16 | echo '<img src="' . $img_path . 'sg_wp_plugin_logo_40.png" alt="SiteGuard Logo" />'; |
| 17 | echo '<h2>' . esc_html__( 'Login History', 'siteguard' ) . "</h2>\n"; |
| 18 | $documentation_link = '<a href="' . esc_url( __( 'https://www.jp-secure.com/siteguard_wp_plugin_en/howto/login_history/', 'siteguard' ) ) . '" target="_blank">' . esc_html__( 'online documentation', 'siteguard' ) . '</a>'; |
| 19 | echo '<div class="siteguard-description">' |
| 20 | . sprintf( |
| 21 | /* translators: %1$s: Link to the online documentation. */ |
| 22 | esc_html__( 'See the %1$s.', 'siteguard' ), |
| 23 | $documentation_link |
| 24 | ) |
| 25 | . '</div>'; |
| 26 | $error = siteguard_check_multisite(); |
| 27 | if ( is_wp_error( $error ) ) { |
| 28 | echo '<p class="description">'; |
| 29 | echo esc_html( $error->get_error_message() ); |
| 30 | echo '</p>'; |
| 31 | } |
| 32 | ?> |
| 33 | <form name="form1" class="siteguard-login-history-form" method="post" action=""> |
| 34 | <?php |
| 35 | wp_nonce_field( 'siteguard_login_history_filter', 'siteguard_filter_nonce' ); |
| 36 | $this->wp_list_table->display(); ?> |
| 37 | <div class="siteguard-description"> |
| 38 | <?php esc_html_e( 'View recent login activity and check for suspicious entries. Up to 10,000 records are stored; when the limit is exceeded, the oldest records are deleted first.', 'siteguard' ); ?> |
| 39 | </div> |
| 40 | <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>"> |
| 41 | </form> |
| 42 | </div> |
| 43 | <?php |
| 44 | } |
| 45 | private static function set_cookie_int( $name, $value, $expire ) { |
| 46 | $path = '/'; |
| 47 | $secure = is_ssl(); |
| 48 | $httponly = true; |
| 49 | $samesite = 'Lax'; |
| 50 | |
| 51 | if ( PHP_VERSION_ID >= 70300 ) { |
| 52 | setcookie( $name, $value, [ |
| 53 | 'expires' => $expire, |
| 54 | 'path' => $path, |
| 55 | 'secure' => $secure, |
| 56 | 'httponly' => $httponly, |
| 57 | 'samesite' => $samesite, |
| 58 | ]); |
| 59 | } else { |
| 60 | setcookie( $name, $value, $expire, $path . '; samesite=' . $samesite, '', $secure, $httponly ); |
| 61 | } |
| 62 | } |
| 63 | static function clear_cookie() { |
| 64 | $expire = time() - 1800; |
| 65 | self::set_cookie_int( 'siteguard_log_filter_operation', '', $expire ); |
| 66 | self::set_cookie_int( 'siteguard_log_filter_type', '', $expire ); |
| 67 | self::set_cookie_int( 'siteguard_log_filter_login_name', '', $expire ); |
| 68 | self::set_cookie_int( 'siteguard_log_filter_ip_address', '', $expire ); |
| 69 | self::set_cookie_int( 'siteguard_log_filter_login_name_not', '', $expire ); |
| 70 | self::set_cookie_int( 'siteguard_log_filter_ip_address_not', '', $expire ); |
| 71 | } |
| 72 | static function set_cookie() { |
| 73 | if ( ! isset( $_GET['page'] ) ) { |
| 74 | return; |
| 75 | } |
| 76 | if ( 'siteguard_login_history' !== $_GET['page'] ) { |
| 77 | return; |
| 78 | } |
| 79 | if ( ! current_user_can( 'manage_options' ) ) { |
| 80 | return; |
| 81 | } |
| 82 | if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
| 83 | $referer = wp_get_referer(); |
| 84 | if ( false === strpos( $referer, 'siteguard_login_history' ) ) { |
| 85 | self::clear_cookie(); |
| 86 | } |
| 87 | return; |
| 88 | } |
| 89 | if ( ! isset( $_POST['siteguard_filter_nonce'] ) || ! wp_verify_nonce( $_POST['siteguard_filter_nonce'], 'siteguard_login_history_filter' ) ) { |
| 90 | return; |
| 91 | } |
| 92 | if ( isset( $_POST['filter_reset'] ) ) { |
| 93 | self::clear_cookie(); |
| 94 | } else { |
| 95 | $expire = time() + 3600; |
| 96 | if ( isset( $_POST['filter_operation'] ) ) { |
| 97 | self::set_cookie_int( 'siteguard_log_filter_operation', sanitize_text_field( $_POST['filter_operation'] ), $expire ); |
| 98 | } |
| 99 | if ( isset( $_POST['filter_type'] ) ) { |
| 100 | self::set_cookie_int( 'siteguard_log_filter_type', sanitize_text_field( $_POST['filter_type'] ), $expire ); |
| 101 | } |
| 102 | if ( isset( $_POST['filter_login_name'] ) ) { |
| 103 | self::set_cookie_int( 'siteguard_log_filter_login_name', sanitize_text_field( $_POST['filter_login_name'] ), $expire ); |
| 104 | } |
| 105 | if ( isset( $_POST['filter_ip_address'] ) ) { |
| 106 | self::set_cookie_int( 'siteguard_log_filter_ip_address', sanitize_text_field( $_POST['filter_ip_address'] ), $expire ); |
| 107 | } |
| 108 | self::set_cookie_int( 'siteguard_log_filter_login_name_not', ( isset( $_POST['filter_login_name_not'] ) && 'not' === sanitize_text_field( $_POST['filter_login_name_not'] ) ) ? 'not' : 'is', $expire ); |
| 109 | self::set_cookie_int( 'siteguard_log_filter_ip_address_not', ( isset( $_POST['filter_ip_address_not'] ) && 'not' === sanitize_text_field( $_POST['filter_ip_address_not'] ) ) ? 'not' : 'is', $expire ); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 |