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