PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 1.3.20
CloudSecure WP Security v1.3.20
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 / cloudsecure-wp.php
cloudsecure-wp-security / modules Last commit date
admin 7 months ago cli 8 months ago lib 11 months ago captcha.php 2 years ago cloudsecure-wp.php 8 months ago common.php 1 year ago config.php 2 years ago disable-access-system-file.php 1 year ago disable-author-query.php 2 years ago disable-login.php 1 year ago disable-restapi.php 7 months ago disable-xmlrpc.php 1 year ago htaccess.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 10 months ago server-error-notification.php 1 year ago two-factor-authentication.php 10 months ago unify-messages.php 2 years ago update-notice.php 7 months ago waf-engine.php 7 months ago waf.php 1 year ago
cloudsecure-wp.php
681 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 require_once __DIR__ . '/common.php';
8 require_once __DIR__ . '/config.php';
9 require_once __DIR__ . '/htaccess.php';
10 require_once __DIR__ . '/login-notification.php';
11 require_once __DIR__ . '/disable-login.php';
12 require_once __DIR__ . '/rename-login-page.php';
13 require_once __DIR__ . '/unify-messages.php';
14 require_once __DIR__ . '/restrict-admin-page.php';
15 require_once __DIR__ . '/disable-xmlrpc.php';
16 require_once __DIR__ . '/disable-author-query.php';
17 require_once __DIR__ . '/disable-restapi.php';
18 require_once __DIR__ . '/update-notice.php';
19 require_once __DIR__ . '/captcha.php';
20 require_once __DIR__ . '/../really-simple-captcha/really-simple-captcha.php';
21 require_once __DIR__ . '/lib/class-time-based-one-time-password.php';
22 require_once __DIR__ . '/login-log.php';
23 require_once __DIR__ . '/two-factor-authentication.php';
24 require_once __DIR__ . '/server-error-notification.php';
25 require_once __DIR__ . '/lib/class-waf-rules.php';
26 require_once __DIR__ . '/waf-engine.php';
27 require_once __DIR__ . '/waf.php';
28 require_once __DIR__ . '/disable-access-system-file.php';
29 require_once __DIR__ . '/lib/class-disable-access-system-file-rules.php';
30
31 class CloudSecureWP extends CloudSecureWP_Common {
32 private $config;
33 private $htaccess;
34 private $login_notification;
35 private $disable_login;
36 private $rename_login_page;
37 private $unify_messages;
38 private $restrict_admin_page;
39 private $disable_xmlrpc;
40 private $disable_author_query;
41 private $disable_restapi;
42 private $update_notice;
43 private $captcha;
44 private $login_log;
45 private $two_factor_authentication;
46 private $server_error_notification;
47 private $waf;
48 private $disable_access_system_file;
49
50 function __construct( array $info ) {
51 parent::__construct( $info );
52 $this->config = new CloudSecureWP_Config( $info );
53 $this->htaccess = new CloudSecureWP_Htaccess( $info );
54 $this->login_notification = new CloudSecureWP_Login_Notification( $info, $this->config );
55 $this->disable_login = new CloudSecureWP_Disable_Login( $info, $this->config );
56 $this->rename_login_page = new CloudSecureWP_Rename_Login_Page( $info, $this->config, $this->htaccess );
57 $this->unify_messages = new CloudSecureWP_Unify_Messages( $info, $this->config, $this->disable_login );
58 $this->restrict_admin_page = new CloudSecureWP_Restrict_Admin_Page( $info, $this->config, $this->htaccess, $this->disable_login );
59 $this->disable_xmlrpc = new CloudSecureWP_Disable_XMLRPC( $info, $this->config, $this->htaccess );
60 $this->disable_author_query = new CloudSecureWP_Disable_Author_Query( $info, $this->config );
61 $this->disable_restapi = new CloudSecureWP_Disable_RESTAPI( $info, $this->config );
62 $this->update_notice = new CloudSecureWP_Update_Notice( $info, $this->config );
63 $this->captcha = new CloudSecureWP_CAPTCHA( $info, $this->config );
64 $this->login_log = new CloudSecureWP_Login_Log( $info, $this->config, $this->disable_login );
65 $this->two_factor_authentication = new CloudSecureWP_Two_Factor_Authentication( $info, $this->config, $this->disable_login );
66 $this->server_error_notification = new CloudSecureWP_Server_Error_Notification( $info, $this->config );
67 $this->waf = new CloudSecureWP_Waf( $info, $this->config );
68 $this->disable_access_system_file = new CloudSecureWP_Disable_Access_System_File( $info, $this->config );
69 }
70
71 /**
72 * プラグイン実行
73 *
74 * @return void
75 */
76 public function run() {
77 if ( ! $this->check_environment() ) {
78 if ( $this->login_notification->is_enabled() ) {
79 $this->login_notification->deactivate();
80 }
81
82 if ( $this->disable_login->is_enabled() ) {
83 $this->disable_login->deactivate();
84 }
85
86 if ( $this->rename_login_page->is_enabled() ) {
87 $this->rename_login_page->deactivate();
88 }
89
90 if ( $this->unify_messages->is_enabled() ) {
91 $this->unify_messages->deactivate();
92 }
93
94 if ( $this->restrict_admin_page->is_enabled() ) {
95 $this->restrict_admin_page->deactivate();
96 }
97
98 if ( $this->disable_xmlrpc->is_enabled() ) {
99 $this->disable_xmlrpc->deactivate();
100 }
101
102 if ( $this->disable_author_query->is_enabled() ) {
103 $this->disable_author_query->deactivate();
104 }
105
106 if ( $this->disable_restapi->is_enabled() ) {
107 $this->disable_restapi->deactivate();
108 }
109
110 if ( $this->update_notice->is_enabled() ) {
111 $this->update_notice->deactivate();
112 }
113
114 if ( $this->captcha->is_enabled() ) {
115 $this->captcha->deactivate();
116 }
117
118 if ( $this->two_factor_authentication->is_enabled() ) {
119 $this->two_factor_authentication->deactivate();
120 }
121
122 if ( $this->server_error_notification->is_enabled() ) {
123 $this->server_error_notification->deactivate();
124 }
125
126 if ( $this->waf->is_enabled() ) {
127 $this->waf->deactivate();
128 }
129
130 if ( $this->disable_access_system_file->is_enabled() ) {
131 $this->disable_access_system_file->deactivate();
132 }
133 } else {
134 if ( $this->waf->is_enabled() ) {
135 add_action( 'plugins_loaded', array( $this->waf, 'waf' ), 10 );
136 }
137
138 if ( $this->server_error_notification->is_enabled() ) {
139 add_filter( 'wp_php_error_args', array( $this->server_error_notification, 'notification' ), 10, 2 );
140 }
141
142 if ( $this->disable_access_system_file->is_enabled() ) {
143 add_action( 'plugins_loaded', array( $this->disable_access_system_file, 'init' ), 10 );
144 }
145
146 add_action( 'wp_login', array( $this->login_log, 'wp_login' ), 1, 1 );
147 add_action( 'xmlrpc_call', array( $this->login_log, 'xmlrpc_call' ), 10 );
148 add_action( 'wp_login_failed', array( $this->login_log, 'wp_login_failed' ), 20, 1 );
149
150 if ( $this->login_notification->is_enabled() ) {
151 add_action( 'wp_login', array( $this->login_notification, 'notification' ), 10, 2 );
152 }
153
154 if ( $this->disable_login->is_enabled() ) {
155 add_filter( 'shake_error_codes', array( $this->disable_login, 'shake_error_codes' ) );
156 add_filter( 'authenticate', array( $this->disable_login, 'authenticate' ), 99, 3 );
157 add_action( 'wp_login_failed', array( $this->disable_login, 'wp_login_failed' ), 10, 1 );
158 }
159
160 if ( $this->rename_login_page->is_enabled() ) {
161 if ( $this->htaccess->setting_tag_exists( $this->rename_login_page->get_feature_key() ) ) {
162 remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
163 add_action( 'plugins_loaded', array( $this->rename_login_page, 'wp_register_404' ), 10 );
164 add_filter( 'login_init', array( $this->rename_login_page, 'login_init' ), 10, 2 );
165 add_filter( 'site_url', array( $this->rename_login_page, 'site_url' ), 10, 4 );
166 add_filter( 'network_site_url', array( $this->rename_login_page, 'network_site_url' ), 10, 3 );
167 add_filter( 'register', array( $this->rename_login_page, 'register' ), 10, 1 );
168 add_filter( 'wp_redirect', array( $this->rename_login_page, 'wp_redirect' ), 10, 2 );
169 add_filter( 'auth_redirect_scheme', array( $this->rename_login_page, 'auth_redirect_scheme' ), 99, 1 );
170
171 } else {
172 add_action( 'admin_notices', array( $this->rename_login_page, 'admin_notices' ), 10, 0 );
173 $this->rename_login_page->deactivate();
174 }
175 } else {
176 if ( $this->htaccess->setting_tag_exists( $this->rename_login_page->get_feature_key() ) ) {
177 $this->rename_login_page->deactivate();
178 }
179 }
180
181 if ( $this->unify_messages->is_enabled() ) {
182 add_filter( 'login_errors', array( $this->unify_messages, 'login_errors' ), 10, 1 );
183 }
184
185 if ( $this->restrict_admin_page->is_enabled() ) {
186 if ( $this->htaccess->setting_tag_exists( $this->restrict_admin_page->get_feature_key() ) ) {
187 add_action( 'wp_login', array( $this->restrict_admin_page, 'update' ), 1, 2 );
188
189 } else {
190 add_action( 'admin_notices', array( $this->restrict_admin_page, 'admin_notices' ), 10, 0 );
191 $this->restrict_admin_page->deactivate();
192 }
193 } else {
194 if ( $this->htaccess->setting_tag_exists( $this->restrict_admin_page->get_feature_key() ) ) {
195 $this->restrict_admin_page->deactivate();
196 }
197 }
198
199 if ( $this->disable_xmlrpc->is_enabled() ) {
200 if ( $this->disable_xmlrpc->is_pingback_disabled() ) {
201 if ( $this->htaccess->setting_tag_exists( $this->disable_xmlrpc->get_feature_key() ) ) {
202 add_action( 'admin_notices', array( $this->disable_xmlrpc, 'admin_notices' ), 10, 0 );
203 $this->disable_xmlrpc->deactivate();
204 } else {
205 add_filter( 'xmlrpc_methods', array( $this->disable_xmlrpc, 'xmlrpc_methods' ) );
206 }
207 }
208
209 if ( $this->disable_xmlrpc->is_xmlrpc_disabled() ) {
210 if ( ! $this->htaccess->setting_tag_exists( $this->disable_xmlrpc->get_feature_key() ) ) {
211 add_action( 'admin_notices', array( $this->disable_xmlrpc, 'admin_notices' ), 10, 0 );
212 $this->disable_xmlrpc->deactivate();
213 }
214 }
215 } else {
216 if ( $this->htaccess->setting_tag_exists( $this->disable_xmlrpc->get_feature_key() ) ) {
217 $this->disable_xmlrpc->deactivate();
218 }
219 }
220
221 if ( $this->disable_author_query->is_enabled() ) {
222 add_action( 'init', array( $this->disable_author_query, 'init' ) );
223 }
224
225 if ( $this->disable_restapi->is_enabled() ) {
226 add_filter( 'rest_pre_dispatch', array( $this->disable_restapi, 'rest_pre_dispatch' ), 10, 3 );
227 }
228
229 if ( $this->update_notice->is_enabled() ) {
230 $this->update_notice->set_cron();
231 add_action( $this->update_notice->get_cron_key(), array( $this->update_notice, 'update_notice' ) );
232 }
233
234 if ( $this->captcha->is_enabled() && 'xmlrpc.php' !== basename( sanitize_text_field( $_SERVER['SCRIPT_NAME'] ) ) && ! is_admin() ) {
235 add_filter( 'shake_error_codes', array( $this->captcha, 'shake_error_codes' ) );
236
237 if ( $this->captcha->is_login_form_enabled() ) {
238 add_filter( 'login_form', array( $this->captcha, 'login_form' ) );
239 add_action( 'wp_authenticate_user', array( $this->captcha, 'wp_authenticate_user' ), 10, 2 );
240 }
241
242 if ( $this->captcha->is_comment_form_enabled() ) {
243 add_action( 'comment_form_logged_in_after', array( $this->captcha, 'comment_form_default_fields' ), 1 );
244 add_action( 'comment_form_after_fields', array( $this->captcha, 'comment_form_default_fields' ) );
245 add_filter( 'preprocess_comment', array( $this->captcha, 'preprocess_comment' ) );
246 }
247
248 if ( $this->captcha->is_lost_password_form_enabled() ) {
249 add_filter( 'lostpassword_form', array( $this->captcha, 'lostpassword_form' ) );
250 add_filter( 'allow_password_reset', array( $this->captcha, 'allow_password_reset' ), 10, 2 );
251 }
252
253 if ( $this->captcha->is_register_form_enabled() ) {
254 add_action( 'register_form', array( $this->captcha, 'register_form' ) );
255 add_action( 'register_post', array( $this->captcha, 'register_post' ), 10, 3 );
256 }
257 }
258
259 if ( $this->two_factor_authentication->is_enabled() && 'xmlrpc.php' !== basename( $_SERVER['SCRIPT_NAME'] ) && ! is_admin() ) {
260 add_filter( 'authenticate', array( $this->two_factor_authentication, 'decode_base64_credentials' ), 0, 3 );
261 add_action( 'wp_login', array( $this->two_factor_authentication, 'wp_login' ), 0, 2 );
262 add_action( 'wp_login', array( $this->two_factor_authentication, 'redirect_if_not_two_factor_authentication_registered' ), 10, 2 );
263 }
264
265 if ( $this->two_factor_authentication->is_enabled() && is_admin() && current_user_can( 'administrator' ) ) {
266 add_filter( 'manage_users_columns', array( $this->two_factor_authentication, 'add_2factor_state_2user_list' ) );
267 add_action( 'manage_users_custom_column', array( $this->two_factor_authentication, 'show_2factor_state_2user_list' ), 10, 3 );
268 }
269 }
270
271 if ( is_admin() ) {
272 if ( 'cloudsecurewp_rename_login_page' === sanitize_text_field( $_GET['page'] ?? '' ) ) {
273 ob_start();
274 }
275
276 $this->update();
277
278 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
279 }
280 }
281
282 /**
283 * プラグイン有効化
284 */
285 public function activate(): void {
286 $this->config->rm();
287 $this->config->set( 'version', $this->info['version'] );
288 $this->config->save();
289
290 $this->login_notification->activate();
291 $this->disable_login->activate();
292 $this->rename_login_page->activate();
293 $this->unify_messages->activate();
294 $this->restrict_admin_page->activate();
295 $this->disable_xmlrpc->activate();
296 $this->disable_author_query->activate();
297 $this->disable_restapi->activate();
298 $this->update_notice->activate();
299 $this->captcha->activate();
300 $this->login_log->activate();
301 $this->two_factor_authentication->activate();
302 $this->server_error_notification->activate();
303 $this->waf->activate();
304 $this->disable_access_system_file->activate();
305 }
306
307 /**
308 * プラグイン無効化
309 */
310 public function deactivate(): void {
311 $this->config->load_option();
312 $this->login_notification->deactivate();
313 $this->disable_login->deactivate();
314 $this->rename_login_page->deactivate();
315 $this->unify_messages->deactivate();
316 $this->restrict_admin_page->deactivate();
317 $this->disable_xmlrpc->deactivate();
318 $this->disable_author_query->deactivate();
319 $this->disable_restapi->deactivate();
320 $this->update_notice->deactivate();
321 $this->captcha->deactivate();
322 $this->two_factor_authentication->deactivate();
323 $this->server_error_notification->deactivate();
324 $this->waf->deactivate();
325 $this->disable_access_system_file->deactivate();
326 }
327
328 /**
329 * admin menuを追加
330 */
331 public function admin_menu(): void {
332 require_once __DIR__ . '/admin/common.php';
333
334 wp_enqueue_style( 'cloudsecurewp', $this->info['plugin_url'] . 'assets/css/style.css', array(), $this->info['version'] );
335
336 $slug = 'cloudsecurewp';
337 add_menu_page( $this->info['plugin_name'], $this->info['plugin_name'], 'manage_options', $slug, array( $this, 'dashboard' ), $this->info['plugin_url'] . 'assets/images/plugin-icon.png?v=2' );
338 add_submenu_page( $slug, 'ダッシュボード', 'ダッシュボード', 'manage_options', $slug, array( $this, 'dashboard' ) );
339 add_submenu_page( $slug, 'ログイン無効化', 'ログイン無効化', 'manage_options', $slug . '_disable_login', array( $this, 'm_disable_login' ) );
340 add_submenu_page( $slug, 'ログインURL変更', 'ログインURL変更', 'manage_options', $slug . '_rename_login_page', array( $this, 'm_rename_login_page' ) );
341 add_submenu_page( $slug, 'ログインエラーメッセージ統一', 'ログインエラーメッセージ統一', 'manage_options', $slug . '_unify_messages', array( $this, 'm_unify_messages' ) );
342 add_submenu_page( $slug, '2段階認証', '2段階認証', 'manage_options', $slug . '_two_factor_authentication', array( $this, 'm_two_factor_authentication' ) );
343 add_submenu_page( $slug, '画像認証追加', '画像認証追加', 'manage_options', $slug . '_captcha', array( $this, 'm_captcha' ) );
344 add_submenu_page( $slug, '管理画面アクセス制限', '管理画面アクセス制限', 'manage_options', $slug . '_restrict_admin_page', array( $this, 'm_restrict_admin_page' ) );
345 add_submenu_page( $slug, '設定ファイルアクセス防止', '設定ファイルアクセス防止', 'manage_options', $slug . '_disable_access_system_file', array( $this, 'm_disable_access_system_file' ) );
346 add_submenu_page( $slug, 'ユーザー名漏えい防止', 'ユーザー名漏えい防止', 'manage_options', $slug . '_disable_author_query', array( $this, 'm_disable_author_query' ) );
347 add_submenu_page( $slug, 'XML-RPC無効化', 'XML-RPC無効化', 'manage_options', $slug . '_disable_xmlrpc', array( $this, 'm_disable_xmlrpc' ) );
348 add_submenu_page( $slug, 'REST API無効化', 'REST API無効化', 'manage_options', $slug . '_disable_restapi', array( $this, 'm_disable_restapi' ) );
349 add_submenu_page( $slug, 'シンプルWAF', 'シンプルWAF', 'manage_options', $slug . '_waf', array( $this, 'm_waf' ) );
350 add_submenu_page( $slug, 'ログイン通知', 'ログイン通知', 'manage_options', $slug . '_login_notification', array( $this, 'm_login_notification' ) );
351 add_submenu_page( $slug, 'アップデート通知', 'アップデート通知', 'manage_options', $slug . '_update_notification', array( $this, 'm_update_notice' ) );
352 add_submenu_page( $slug, 'サーバーエラー通知', 'サーバーエラー通知', 'manage_options', $slug . '_server_error_notification', array( $this, 'm_server_error_notification' ) );
353 add_submenu_page( $slug, 'ログイン履歴', 'ログイン履歴', 'manage_options', $slug . '_login_log', array( $this, 'm_login_log' ) );
354
355 if ( $this->two_factor_authentication->is_enabled_on_screen() ) {
356 add_menu_page( 'デバイス登録', '2段階認証', 'read', $slug . '_two_factor_authentication_registration', array( $this, 'm_two_factor_authentication_registration' ), 'dashicons-lock', 72 );
357 }
358 }
359
360 /**
361 * ダッシュボードページ
362 *
363 * @return void
364 */
365 public function dashboard(): void {
366 require_once 'admin/dashboard.php';
367
368 $datas = array(
369 $this->login_notification->get_feature_key() => $this->config->get( $this->login_notification->get_feature_key() ),
370 $this->disable_login->get_feature_key() => $this->config->get( $this->disable_login->get_feature_key() ),
371 $this->rename_login_page->get_feature_key() => $this->config->get( $this->rename_login_page->get_feature_key() ),
372 $this->unify_messages->get_feature_key() => $this->config->get( $this->unify_messages->get_feature_key() ),
373 $this->restrict_admin_page->get_feature_key() => $this->config->get( $this->restrict_admin_page->get_feature_key() ),
374 $this->disable_xmlrpc->get_feature_key() => $this->config->get( $this->disable_xmlrpc->get_feature_key() ),
375 $this->disable_author_query->get_feature_key() => $this->config->get( $this->disable_author_query->get_feature_key() ),
376 $this->disable_restapi->get_feature_key() => $this->config->get( $this->disable_restapi->get_feature_key() ),
377 $this->update_notice->get_feature_key() => $this->config->get( $this->update_notice->get_feature_key() ),
378 $this->server_error_notification->get_feature_key() => $this->config->get( $this->server_error_notification->get_feature_key() ),
379 $this->captcha->get_feature_key() => $this->config->get( $this->captcha->get_feature_key() ),
380 $this->two_factor_authentication->get_feature_key() => $this->config->get( $this->two_factor_authentication->get_feature_key() ),
381 $this->waf->get_feature_key() => $this->config->get( $this->waf->get_feature_key() ),
382 $this->disable_access_system_file->get_feature_key() => $this->config->get( $this->disable_access_system_file->get_feature_key() ),
383 );
384
385 new CloudSecureWP_Admin_Dashboard( $this->info, $datas );
386 }
387
388 /**
389 * ログイン通知ページ
390 *
391 * @return void
392 */
393 public function m_login_notification(): void {
394 require_once 'admin/login-notification.php';
395 new CloudSecureWP_Admin_Login_Notification( $this->info, $this->login_notification );
396 }
397
398 /**
399 * ログイン無効化ページ
400 *
401 * @return void
402 */
403 public function m_disable_login(): void {
404 require_once 'admin/disable-login.php';
405 new CloudSecureWP_Admin_Disable_Login( $this->info, $this->disable_login );
406 }
407
408 /**
409 * ログインURL変更
410 *
411 * @return void
412 */
413 public function m_rename_login_page(): void {
414 require_once 'admin/rename-login-page.php';
415 new CloudSecureWP_Admin_Rename_Login_Page( $this->info, $this->rename_login_page );
416 }
417
418 /**
419 * エラーメッセージ単一化機能
420 *
421 * @return void
422 */
423 public function m_unify_messages(): void {
424 require_once 'admin/unify-messages.php';
425 new CloudSecureWP_Admin_Unify_Messages( $this->info, $this->unify_messages );
426 }
427
428 /**
429 * 管理画面アクセス制限
430 *
431 * @return void
432 */
433 public function m_restrict_admin_page(): void {
434 require_once 'admin/restrict-admin-page.php';
435 new CloudSecureWP_Admin_Restrict_Admin_Page( $this->info, $this->restrict_admin_page );
436 }
437
438 /**
439 * XMLRPC無効化
440 *
441 * @return void
442 */
443 public function m_disable_xmlrpc(): void {
444 require_once 'admin/disable-xmlrpc.php';
445 new CloudSecureWP_Admin_Disable_XMLRPC( $this->info, $this->disable_xmlrpc );
446 }
447
448 /**
449 * ユーザー名漏えい防止
450 *
451 * @return void
452 */
453 public function m_disable_author_query(): void {
454 require_once 'admin/disable-author-query.php';
455 new CloudSecureWP_Admin_Disable_Author_Query( $this->info, $this->disable_author_query );
456 }
457
458 /**
459 * REST API無効化
460 *
461 * @return void
462 */
463 public function m_disable_restapi(): void {
464 require_once 'admin/disable-restapi.php';
465 new CloudSecureWP_Admin_Disable_RESTAPI( $this->info, $this->disable_restapi );
466 }
467
468 /**
469 * アップデート通知
470 *
471 * @return void
472 */
473 public function m_update_notice(): void {
474 require_once 'admin/update-notice.php';
475 new CloudSecureWP_Admin_Update_Notice( $this->info, $this->update_notice );
476 }
477
478 /**
479 * 画像認証追加
480 *
481 * @return void
482 */
483 public function m_captcha(): void {
484 require_once 'admin/captcha.php';
485 new CloudSecureWP_Admin_CAPTCHA( $this->info, $this->captcha );
486 }
487
488 /**
489 * ログイン履歴
490 *
491 * @return void
492 */
493 public function m_login_log(): void {
494 require_once 'admin/login-log.php';
495 require_once 'admin/login-log-table.php';
496 new CloudSecureWP_Admin_Login_Log( $this->info, $this->login_log );
497 }
498
499 /**
500 * 2段階認証
501 *
502 * @return void
503 */
504 public function m_two_factor_authentication(): void {
505 require_once 'admin/two-factor-authentication.php';
506 new CloudSecureWP_Admin_Two_Factor_Authentication( $this->info, $this->two_factor_authentication );
507 }
508
509 /**
510 * 2段階認証のデバイス登録
511 *
512 * @return void
513 */
514 public function m_two_factor_authentication_registration(): void {
515 require_once 'admin/two-factor-authentication-registration.php';
516 new CloudSecureWP_Admin_Two_Factor_Authentication_Registration( $this->info, $this->two_factor_authentication );
517 }
518
519 /**
520 * サーバーエラー通知
521 *
522 * @return void
523 */
524 public function m_server_error_notification(): void {
525 require_once 'admin/server-error-notification.php';
526 require_once 'admin/server-error-table.php';
527 new CloudSecureWP_Admin_Server_Error_Notification( $this->info, $this->server_error_notification );
528 }
529
530 /**
531 * シンプルWAF
532 *
533 * @return void
534 */
535 public function m_waf(): void {
536 require_once 'admin/waf.php';
537 require_once 'admin/waf-table.php';
538 new CloudSecureWP_Admin_Waf( $this->info, $this->waf );
539 }
540
541 /**
542 * 設定ファイルアクセス防止
543 *
544 * @return void
545 */
546 public function m_disable_access_system_file(): void {
547 require_once 'admin/disable-access-system-file.php';
548 new CloudSecureWP_Admin_Disable_Access_System_File( $this->info, $this->disable_access_system_file );
549 }
550
551 /**
552 * CLI用のgetterメソッド群
553 * 注意: これらのメソッドはWP-CLI環境でのみ使用されることを想定しています
554 */
555 private function validate_cli_access() {
556 // WP-CLI環境チェック
557 if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
558 wp_die( 'Unauthorized access: CLI only' );
559 }
560 }
561
562 public function get_config() {
563 $this->validate_cli_access();
564 return $this->config;
565 }
566
567 public function get_htaccess() {
568 $this->validate_cli_access();
569 return $this->htaccess;
570 }
571
572 public function get_login_notification() {
573 $this->validate_cli_access();
574 return $this->login_notification;
575 }
576
577 public function get_disable_login() {
578 $this->validate_cli_access();
579 return $this->disable_login;
580 }
581
582 public function get_rename_login_page() {
583 $this->validate_cli_access();
584 return $this->rename_login_page;
585 }
586
587 public function get_unify_messages() {
588 $this->validate_cli_access();
589 return $this->unify_messages;
590 }
591
592 public function get_restrict_admin_page() {
593 $this->validate_cli_access();
594 return $this->restrict_admin_page;
595 }
596
597 public function get_disable_xmlrpc() {
598 $this->validate_cli_access();
599 return $this->disable_xmlrpc;
600 }
601
602 public function get_disable_author_query() {
603 $this->validate_cli_access();
604 return $this->disable_author_query;
605 }
606
607 public function get_disable_restapi() {
608 $this->validate_cli_access();
609 return $this->disable_restapi;
610 }
611
612 public function get_update_notice() {
613 $this->validate_cli_access();
614 return $this->update_notice;
615 }
616
617 public function get_captcha() {
618 $this->validate_cli_access();
619 return $this->captcha;
620 }
621
622 public function get_login_log() {
623 $this->validate_cli_access();
624 return $this->login_log;
625 }
626
627 public function get_two_factor_authentication() {
628 $this->validate_cli_access();
629 return $this->two_factor_authentication;
630 }
631
632 public function get_server_error_notification() {
633 $this->validate_cli_access();
634 return $this->server_error_notification;
635 }
636
637 public function get_waf() {
638 $this->validate_cli_access();
639 return $this->waf;
640 }
641
642 public function get_disable_access_system_file() {
643 $this->validate_cli_access();
644 return $this->disable_access_system_file;
645 }
646
647 /**
648 * プラグイン更新時の処理
649 */
650 private function update(): void {
651 $old_version = $this->config->get( 'version' );
652 $now_version = $this->info['version'];
653
654 if ( empty( $old_version ) ) {
655 $old_version = '1.0.0';
656 }
657
658 if ( 0 <= version_compare( $old_version, $now_version ) ) {
659 return;
660 }
661
662 if ( version_compare( $old_version, '1.1.0' ) < 0 ) {
663 $this->two_factor_authentication->activate();
664 $this->server_error_notification->activate();
665 }
666
667 if ( version_compare( $old_version, '1.3.0' ) < 0 ) {
668 $this->waf->activate();
669 $this->disable_access_system_file->activate();
670 }
671
672 if ( version_compare( $old_version, '1.3.7' ) < 0 ) {
673 $this->waf->activate();
674 $this->server_error_notification->activate();
675 }
676
677 $this->config->set( 'version', $now_version );
678 $this->config->save();
679 }
680 }
681