PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 1.2.3
CloudSecure WP Security v1.2.3
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 / disable-xmlrpc.php
cloudsecure-wp-security / modules Last commit date
admin 2 years ago lib 2 years ago captcha.php 2 years ago cloudsecure-wp.php 2 years ago common.php 2 years ago config.php 2 years ago disable-author-query.php 2 years ago disable-login.php 2 years ago disable-restapi.php 2 years ago disable-xmlrpc.php 2 years ago htaccess.php 2 years ago login-log.php 2 years ago login-notification.php 2 years ago rename-login-page.php 2 years ago restrict-admin-page.php 2 years ago server-error-notification.php 2 years ago two-factor-authentication.php 2 years ago unify-messages.php 2 years ago update-notice.php 2 years ago
disable-xmlrpc.php
196 lines
1 <?php
2 class CloudSecureWP_Disable_XMLRPC extends CloudSecureWP_Common {
3 private const KEY_FEATURE = 'disable_xmlrpc';
4 private const KEY_TYPE = self::KEY_FEATURE . '_type';
5 private const TYPE_VALUE_PINGBACK = '1';
6 private const TYPE_VALUE_XMLRPC = '2';
7 private const TYPE_VALUES = array( self::TYPE_VALUE_PINGBACK, self::TYPE_VALUE_XMLRPC );
8 private $config;
9 private $htaccess;
10
11 function __construct( array $info, CloudSecureWP_Config $config, CloudSecureWP_Htaccess $htaccess ) {
12 parent::__construct( $info );
13 $this->config = $config;
14 $this->htaccess = $htaccess;
15 }
16
17 /**
18 * 機能毎のKEY取得
19 *
20 * @return string
21 */
22 public function get_feature_key(): string {
23 return self::KEY_FEATURE;
24 }
25
26 /**
27 * 有効無効判定
28 *
29 * @return bool
30 */
31 public function is_enabled(): bool {
32 return $this->config->get( $this->get_feature_key() ) === 't' ? true : false;
33 }
34
35 /**
36 * 初期設定値取得
37 *
38 * @return array
39 */
40 public function get_default(): array {
41 $ret = array(
42 self::KEY_FEATURE => $this->check_environment() ? 't' : 'f',
43 self::KEY_TYPE => self::TYPE_VALUES[0],
44 );
45 return $ret;
46 }
47
48 /**
49 * 設定値取得
50 */
51 public function get_settings(): array {
52 $settings = array();
53 $default = $this->get_default();
54
55 foreach ( $default as $key => $val ) {
56 $settings[ $key ] = $this->config->get( $key );
57 }
58
59 return $settings;
60 }
61
62 /**
63 * 設定値保存
64 *
65 * @param array $settings
66 * @return void
67 */
68 public function save_settings( $settings ): void {
69 $default = $this->get_default();
70
71 foreach ( $default as $key => $val ) {
72 $this->config->set( $key, $settings[ $key ] ?? '' );
73 }
74
75 $this->config->save();
76 }
77
78 /**
79 * 設定定義値取得
80 *
81 * @return array
82 */
83 public function get_constant_settings(): array {
84 return array( self::KEY_TYPE => self::TYPE_VALUES );
85 }
86
87 /**
88 * ピンバック無効化判定
89 *
90 * @return bool
91 */
92 public function is_pingback_disabled(): bool {
93 $settings = $this->get_settings();
94 if ( self::TYPE_VALUE_PINGBACK === $settings[ self::KEY_TYPE ] ) {
95 return true;
96 }
97 return false;
98 }
99
100 /**
101 * XMLRPC無効化判定
102 *
103 * @return bool
104 */
105 public function is_xmlrpc_disabled(): bool {
106 $settings = $this->get_settings();
107 if ( self::TYPE_VALUE_XMLRPC === $settings[ self::KEY_TYPE ] ) {
108 return true;
109 }
110 return false;
111 }
112
113 /**
114 * htaccessに書き出す設定を取得
115 *
116 * @return string
117 */
118 private function get_htaccess_settings(): string {
119
120 $setting = "<Files xmlrpc.php>" . "\n";
121 $setting .= " <IfModule authz_core_module>" . "\n";
122 $setting .= " Require all denied" . "\n";
123 $setting .= " </IfModule>" . "\n";
124 $setting .= " <IfModule !authz_core_module>" . "\n";
125 $setting .= " Order allow,deny" . "\n";
126 $setting .= " Deny from all" . "\n";
127 $setting .= " </IfModule>" . "\n";
128 $setting .= "</Files>" . "\n";
129
130 return $setting;
131 }
132
133 /**
134 * htaccessに書き出す設定を更新
135 *
136 * @return bool
137 */
138 public function update_htaccess(): bool {
139 $plugin_tag = $this->htaccess->get_plugin_settings_tag();
140 $tag = $this->get_feature_key();
141
142 if ( $this->htaccess->setting_tag_exists( $plugin_tag ) ) {
143 if ( $this->htaccess->setting_tag_exists( $tag ) ) {
144 if ( ! $this->remove_htaccess() ) {
145 return false;
146 }
147 }
148 } else {
149 $this->htaccess->add_plugin_settings_tag();
150 }
151
152 $setting = $this->get_htaccess_settings();
153 $ret = $this->htaccess->add_feature_setting( $tag, $setting );
154
155 return $ret;
156 }
157
158 /**
159 * htaccessから設定を削除
160 *
161 * @return bool
162 */
163 public function remove_htaccess(): bool {
164 return $this->htaccess->remove_settings( array( $this->get_feature_key() ) );
165 }
166
167 /**
168 * xmlrpc_methods
169 */
170 function xmlrpc_methods( $methods ) {
171 unset( $methods['pingback.ping'] );
172 unset( $methods['pingback.extensions.getPingbacks'] );
173 return $methods;
174 }
175
176 /**
177 * 有効化
178 *
179 * @return void
180 */
181 public function activate(): void {
182 $this->save_settings( $this->get_default() );
183 }
184
185 /**
186 * 無効化
187 *
188 * @return void
189 */
190 public function deactivate(): void {
191 $this->remove_htaccess();
192 $this->config->set( self::KEY_FEATURE, 'f' );
193 $this->config->save();
194 }
195 }
196