PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 1.4.10
CloudSecure WP Security v1.4.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 / login-notification.php
cloudsecure-wp-security / modules Last commit date
admin 1 month ago cli 1 month ago lib 1 month ago captcha.php 3 months ago cloudsecure-wp.php 1 month ago common.php 2 months ago config.php 2 years ago disable-access-system-file.php 1 month ago disable-author-query.php 2 years ago disable-login.php 2 months ago disable-restapi.php 2 months ago disable-xmlrpc.php 1 year ago htaccess.php 3 months ago login-log.php 2 months ago login-notification.php 1 month ago rename-login-page.php 3 months ago restrict-admin-page.php 1 month ago server-error-notification.php 1 month ago two-factor-authentication.php 1 month ago unify-messages.php 2 years ago update-notice.php 7 months ago waf-engine.php 1 month ago waf.php 1 month ago
login-notification.php
176 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class CloudSecureWP_Login_Notification extends CloudSecureWP_Common {
8 private const KEY_FEATURE = 'login_notification';
9 private const KEY_SUBJECT = self::KEY_FEATURE . '_subject';
10 private const KEY_BODY = self::KEY_FEATURE . '_body';
11 private const KEY_ADMIN_ONLY = self::KEY_FEATURE . '_admin_only';
12 private $config;
13
14 function __construct( array $info, CloudSecureWP_Config $config ) {
15 parent::__construct( $info );
16 $this->config = $config;
17 }
18
19 /**
20 * 機能毎のKEY取得
21 *
22 * @return string
23 */
24 public function get_feature_key(): string {
25 return self::KEY_FEATURE;
26 }
27
28 /**
29 * 有効無効判定
30 *
31 * @return bool
32 */
33 public function is_enabled(): bool {
34 return $this->config->get( $this->get_feature_key() ) === 't' ? true : false;
35 }
36
37 /**
38 * 初期設定値取得
39 *
40 * @return array
41 */
42 public function get_default(): array {
43 $ret = array(
44 self::KEY_FEATURE => $this->check_environment() ? 't' : 'f',
45 self::KEY_SUBJECT => $this->get_default_subject(),
46 self::KEY_BODY => $this->get_default_body(),
47 self::KEY_ADMIN_ONLY => 't',
48 );
49 return $ret;
50 }
51
52 /**
53 * 設定値取得
54 */
55 public function get_settings(): array {
56 $settings = array();
57 $default = $this->get_default();
58
59 foreach ( $default as $key => $val ) {
60 $settings[ $key ] = $this->config->get( $key );
61 }
62
63 return $settings;
64 }
65
66 /**
67 * 設定値保存
68 *
69 * @param array $settings
70 * @return void
71 */
72 public function save_settings( $settings ): void {
73 $default = $this->get_default();
74
75 foreach ( $default as $key => $val ) {
76 $this->config->set( $key, $settings[ $key ] ?? '' );
77 }
78
79 $this->config->save();
80 }
81
82 /**
83 * メール件名デフォルト値取得
84 *
85 * @return string
86 */
87 private function get_default_subject(): string {
88 return 'ログイン通知';
89 }
90
91 /**
92 * メール本文デフォルト値取得
93 *
94 * @return string
95 */
96 private function get_default_body(): string {
97 $text = "{\$date} {\$time} に {\$user_name} がログインしました。" . "\n";
98 $text .= "" . "\n";
99 $text .= "【ログイン�
100 報】" . "\n";
101 $text .= "" . "\n";
102 $text .= "・日時:{\$date} {\$time}" . "\n";
103 $text .= "" . "\n";
104 $text .= "・ユーザー名:{\$user_name}" . "\n";
105 $text .= "" . "\n";
106 $text .= "・IPアドレス:{\$ip}" . "\n";
107 $text .= "" . "\n";
108 $text .= "・リファラー:{\$http_referer}" . "\n";
109 $text .= "" . "\n";
110 $text .= "・ユーザーエージェント:{\$http_user_agent}" . "\n";
111 $text .= "" . "\n";
112 $text .= "--" . "\n";
113 $text .= "CloudSecure WP Security" . "\n";
114
115 return $text;
116 }
117
118 /**
119 * 値割当て
120 *
121 * @param string $text
122 * @param array $values
123 * @return string
124 */
125 private function bind_values( string $text, array $values ): string {
126 foreach ( $values as $key => $val ) {
127 $text = str_replace( '{$' . $key . '}', $val, $text );
128 }
129 return $text;
130 }
131
132 /**
133 * 通知
134 */
135 public function notification( $user_name, $user ) {
136 if ( 't' === $this->config->get( self::KEY_ADMIN_ONLY ) && ! $user->has_cap( 'administrator' ) ) {
137 return;
138 }
139
140 $values = array(
141 'user_name' => $user_name,
142 'date' => $this->get_date(),
143 'time' => $this->get_time(),
144 'ip' => '' !== $this->get_client_ip() ? $this->get_client_ip() : '--',
145 'http_referer' => '' !== $this->get_http_referer() ? $this->get_http_referer() : '--',
146 'http_user_agent' => '' !== $this->get_http_user_agent() ? $this->get_http_user_agent() : '--',
147 );
148
149 $mail = $user->get( 'user_email' );
150 $subject = $this->bind_values( $this->config->get( self::KEY_SUBJECT ), $values );
151 $subject = preg_replace( '/[\r\n]/', '', $subject );
152 $body = $this->bind_values( $this->config->get( self::KEY_BODY ), $values );
153
154 $this->wp_send_mail( $mail, esc_html( $subject ), esc_html( $body ) );
155 }
156
157 /**
158 * 有効化
159 *
160 * @return void
161 */
162 public function activate(): void {
163 $this->save_settings( $this->get_default() );
164 }
165
166 /**
167 * 無効化
168 *
169 * @return void
170 */
171 public function deactivate(): void {
172 $this->config->set( $this->get_feature_key(), 'f' );
173 $this->config->save();
174 }
175 }
176