class-cloudsecure-wp-cli-disable-restapi.php
8 months ago
class-cloudsecure-wp-cli-disable.php
8 months ago
class-cloudsecure-wp-cli-enable.php
8 months ago
class-cloudsecure-wp-cli-list.php
8 months ago
class-cloudsecure-wp-cli-status.php
8 months ago
class-cloudsecure-wp-cli-status.php
127 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CloudSecure WP Security Status Command |
| 4 | * 機能の設定値表示専用のコマンドクラス |
| 5 | * |
| 6 | * @package CloudSecure_WP_Security |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | if ( ! class_exists( 'WP_CLI' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // ベースクラスを読み込み |
| 18 | require_once dirname( __DIR__ ) . '/class-cloudsecure-wp-cli-base.php'; |
| 19 | |
| 20 | /** |
| 21 | * CloudSecure WP Security Status Command |
| 22 | * 機能の設定値表示専用のコマンドクラス |
| 23 | */ |
| 24 | class CloudSecureWP_CLI_Status extends CloudSecureWP_CLI_Base { |
| 25 | |
| 26 | /** |
| 27 | * 機能の設定値を表示する |
| 28 | * |
| 29 | * ## EXAMPLES |
| 30 | * wp cldsec-wp-security status disable-login |
| 31 | * wp cldsec-wp-security status login-notification |
| 32 | * |
| 33 | * ## OPTIONS |
| 34 | * <feature> : 設定値を確認する機能名(� |
| 35 | 須、単一の機能名のみ受付。複数指定はエラー) |
| 36 | * |
| 37 | * @param array $args 位置引数 |
| 38 | * @param array $assoc_args 関連� |
| 39 | �列引数 |
| 40 | */ |
| 41 | public function __invoke( $args = array(), $assoc_args = array() ) { |
| 42 | try { |
| 43 | // � |
| 44 | �通の機能検証処理 |
| 45 | $validation_result = $this->validate_feature_arguments( $args, true ); |
| 46 | if ( ! $validation_result['success'] ) { |
| 47 | $this->output_error_response( |
| 48 | array( |
| 49 | 'message' => $validation_result['error'], |
| 50 | ) |
| 51 | ); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | $feature_name = $validation_result['feature_name']; |
| 56 | $description = $validation_result['description']; |
| 57 | $feature_instance = $validation_result['feature_instance']; |
| 58 | |
| 59 | // 設定値を取得 |
| 60 | $settings = $feature_instance->get_settings(); |
| 61 | $feature_key = $feature_instance->get_feature_key(); |
| 62 | |
| 63 | // 機能の基本� |
| 64 | 報(設定値から直接取得) |
| 65 | $enabled = isset( $settings[ $feature_key ] ) && $settings[ $feature_key ] === 't'; |
| 66 | $status = $enabled ? 'enabled' : 'disabled'; |
| 67 | |
| 68 | // 設定値をフィルタリング(� |
| 69 | 部設定は除外) |
| 70 | $configuration = array(); |
| 71 | foreach ( $settings as $key => $value ) { |
| 72 | // 機能キー自体はスキップ(statusで既に表示済み) |
| 73 | if ( $key === $feature_key ) { |
| 74 | continue; |
| 75 | } |
| 76 | |
| 77 | // 設定キーから機能名プレフィックスを削除 |
| 78 | $display_key = str_replace( $feature_key . '_', '', $key ); |
| 79 | |
| 80 | // � |
| 81 | 部設定は除外 |
| 82 | if ( $this->is_internal_setting( $feature_name, $display_key ) ) { |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | // テキストエリア� |
| 87 | 容の改行コード変換 |
| 88 | if ( $this->is_textarea_setting( $feature_name, $display_key ) ) { |
| 89 | $value = $this->convert_textarea_to_placeholder( $value ); |
| 90 | } |
| 91 | |
| 92 | // � |
| 93 | �列設定の場合はキーを再インデックス(JSON出力の一貫性確保) |
| 94 | if ( $this->is_array_setting( $feature_name, $display_key ) && is_array( $value ) ) { |
| 95 | $value = array_values( $value ); |
| 96 | } |
| 97 | |
| 98 | // 表示用の値を正規化(boolean: t→1, f→0、ビットフラグ: 63→sql,xss,command,code,mail) |
| 99 | $value = $this->normalize_value_for_display( $feature_name, $display_key, $value ); |
| 100 | |
| 101 | $configuration[ $display_key ] = $value; |
| 102 | } |
| 103 | |
| 104 | // 特別な設定を追加(WordPressオプション) |
| 105 | $this->add_special_configuration_settings( $feature_name, $configuration ); |
| 106 | |
| 107 | $response_data = array( |
| 108 | 'result' => 'success', |
| 109 | 'data' => array( |
| 110 | 'name' => $feature_name, |
| 111 | 'description' => $description, |
| 112 | 'status' => $status, |
| 113 | 'configuration' => $configuration, |
| 114 | ), |
| 115 | ); |
| 116 | |
| 117 | $this->output_success_response( $response_data ); |
| 118 | } catch ( Exception $e ) { |
| 119 | $this->output_error_response( |
| 120 | array( |
| 121 | 'message' => $e->getMessage(), |
| 122 | ) |
| 123 | ); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 |