PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 1.1.1
CloudSecure WP Security v1.1.1
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 / common.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
common.php
225 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 require_once ABSPATH . 'wp-admin/includes/plugin.php';
8 require_once ABSPATH . 'wp-includes/pluggable.php';
9
10 class CloudSecureWP_Common {
11 public const MESSAGES = array(
12 'error_multisite' => 'WordPressマルチサイトには対応していません',
13 'error_htaccess_update' => '.htaccessファイルの更新に失敗しました',
14 'error_conflict_plugin' => '競合するプラグインが有効化されています',
15 );
16
17 public const CONFLICT_PLUGINS = array(
18 array(
19 'name' => 'SiteGuard WP Plugin',
20 'path' => 'siteguard/siteguard.php',
21 ),
22 );
23
24 public const PAGE_404 = 'cloudsecurewp_404';
25 protected const LOGIN_STATUS_SUCCESS = 1;
26 protected const LOGIN_STATUS_FAILED = 2;
27 protected const LOGIN_STATUS_DISABLED = 3;
28 protected const LOGIN_STATUS_DATAS = array(
29 self::LOGIN_STATUS_SUCCESS => '成功',
30 self::LOGIN_STATUS_FAILED => '失敗',
31 self::LOGIN_STATUS_DISABLED => '無効',
32 );
33 protected $info;
34
35 function __construct( array $info ) {
36 $this->info = $info;
37 }
38
39 /**
40 * エラーログ出力
41 *
42 * @param string $msg
43 * @param string $tag
44 * @return bool
45 */
46 protected function error_log( string $msg, string $tag = '' ): bool {
47 $file_path = $this->info['plugin_path'] . 'log/' . date_i18n( 'Ymd_' ) . 'error.log';
48
49 if ( '' != $tag ) {
50 $tag = '[' . $tag . '] ';
51 } else {
52 $tag = ' ';
53 }
54
55 if ( false === file_put_contents( $file_path, '[' . date_i18n( 'His' ) . ']' . $tag . $msg . "\n", FILE_APPEND | LOCK_EX ) ) {
56 return false;
57 }
58 return true;
59 }
60
61 /**
62 * WP cron 有効判定
63 *
64 * @return bool
65 */
66 protected function cron_enabled(): bool {
67 if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
68 return false;
69 }
70 return true;
71 }
72
73 /**
74 * WP mail 送信
75 *
76 * @param string $to
77 * @param string $subject
78 * @param string $body
79 * @return bool
80 */
81 public function wp_send_mail( string $to, string $subject, string $body ): bool {
82 $subject = '' . get_option( 'blogname' ) . '' . $subject;
83
84 if ( @wp_mail( $to, $subject, $body ) ) {
85 return true;
86 }
87 return false;
88 }
89
90 /**
91 * クライアントIP取得
92 *
93 * @return string
94 */
95 public function get_client_ip(): string {
96 return sanitize_text_field( $_SERVER['REMOTE_ADDR'] ?? '' );
97 }
98
99 /**
100 * 競合プラグイン有効判定
101 *
102 * @return string
103 */
104 protected function get_conflict_plugin_name(): string {
105 $plugins = self::CONFLICT_PLUGINS;
106 $ret = '';
107
108 foreach ( $plugins as $plugin_row ) {
109 if ( is_plugin_active( $plugin_row['path'] ) ) {
110 $ret = $plugin_row['name'];
111 break;
112 }
113 }
114
115 return $ret;
116 }
117
118 /**
119 * 管理�
120 のユーザー�
121 報�
122 �件取得
123 */
124 public function get_admin_users(): array {
125 $args = array(
126 'role' => 'administrator',
127 'fields' => 'all',
128 );
129
130 return get_users( $args );
131 }
132
133 /**
134 * �
135 �列からテキストに変換
136 *
137 * @param array $array
138 * @return string
139 */
140 public function array2Text( array $array ): string {
141 return implode( "\n", $array );
142 }
143
144 /**
145 * 動作環境チェック
146 *
147 * @return void
148 */
149 public function check_environment(): bool {
150 if ( ! is_multisite() ) {
151 if ( '' === $this->get_conflict_plugin_name() ) {
152 return true;
153 }
154 }
155
156 return false;
157 }
158
159 /**
160 * USERAGENT 取得
161 *
162 * @return string
163 */
164 public function get_http_user_agent(): string {
165 return sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ?? '' );
166 }
167
168 /**
169 * HTTP_REFERER 取得
170 *
171 * @return string
172 */
173 public function get_http_referer(): string {
174 return sanitize_url( $_SERVER['HTTP_REFERER'] ?? '' );
175 }
176
177 /**
178 * 年月日取得
179 *
180 * @param string $delimiter
181 * @return string
182 */
183 public function get_date( string $delimiter = '/' ): string {
184 return date_i18n( "Y{$delimiter}m{$delimiter}d" );
185 }
186
187 /**
188 * 時分秒取得
189 *
190 * @return string
191 */
192 public function get_time(): string {
193 return date_i18n( 'H:i:s' );
194 }
195
196 /**
197 * ログインステータス�
198 報取得
199 */
200 public function get_login_status_datas(): array {
201 return self::LOGIN_STATUS_DATAS;
202 }
203
204 /**
205 * 404
206 */
207 public function page404(): void {
208 $page = get_404_template();
209
210 if ( '' !== $page ) {
211 global $wp_query;
212
213 status_header( 404 );
214 nocache_headers();
215 $wp_query->set_404();
216 include $page;
217
218 } else {
219 wp_safe_redirect( home_url( self::PAGE_404 ) );
220 }
221
222 exit;
223 }
224 }
225