PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.0
Backup Migration v1.3.0
2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 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.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / includes / check / system_info.php
backup-backup / includes / check Last commit date
checker.php 2 years ago system_info.php 2 years ago
system_info.php
502 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin\Checker;
5
6 // Use
7 use BMI\Plugin\Backup_Migration_Plugin as BMP;
8 use BMI\Plugin\BMI_Logger as Logger;
9
10 /**
11 * Class System_Info
12 */
13 class System_Info {
14 /**
15 * Get the available memory
16 *
17 * @var float|int // flot|int
18 */
19 protected $memory_available;
20
21 /**
22 * Get the PHP version
23 *
24 * @var float // Version
25 */
26 protected $php_version;
27
28 /**
29 * Get the MySQL version
30 *
31 * @var float // MySQL version
32 */
33 protected $mysql_version;
34
35 /**
36 * Get the webserver
37 *
38 * @var String // webserver used.
39 */
40 protected $webserver;
41
42 /**
43 * Get the Operating Server
44 *
45 * @var String // OS used.
46 */
47 protected $os;
48 /**
49 * Get the Free Space After Backup
50 *
51 * @var false|float|int
52 */
53 protected $free_space_after_backup;
54
55 public function is_enabled($func) {
56
57 $disabled = explode(',', ini_get('disable_functions'));
58 $isDisabled = in_array($func, $disabled);
59 if (!$isDisabled && function_exists($func)) return true;
60 else return false;
61
62 }
63
64 /**
65 * Get the timezone from WordPress details.
66 *
67 * @return String // timezone
68 */
69 public function get_timezone() {
70 if (! isset($this->timezone)) {
71 if (function_exists('wp_timezone')) {
72 $this->timezone = wp_timezone()->getName();
73 } else {
74 $date = new \DateTime();
75 $time_zone = $date->getTimezone();
76 $this->timezone = $time_zone->getName();
77 }
78 }
79
80 return $this->timezone;
81 }
82
83 /**
84 * Get the Webserver by executing shell details.
85 *
86 * @return String // webserver name
87 */
88 public function get_webserver() {
89 if (! isset($this->webserver)) {
90 if (isset($_SERVER['SERVER_SOFTWARE'])) {
91 $this->webserver = sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE']));
92 }
93 }
94
95 return $this->webserver;
96 }
97
98 /**
99 * Get the Webserver from phpinfo details.
100 *
101 * @return String // os fingureprint
102 */
103 public function get_os() {
104 if ($this->is_enabled('php_uname')) {
105 if (! isset($this->os)) {
106 $this->os = strtolower(php_uname('s'));
107 }
108
109 return $this->os;
110 } else {
111 return __('Blocked by hosting', 'backup-backup');
112 }
113 }
114
115 /**
116 * Get the homeurl from WordPress details.
117 *
118 * @return String // os
119 */
120 public function get_operating_system() {
121 if ($this->is_enabled('php_uname')) {
122 if (! isset($this->operating_system)) {
123 $this->operating_system = php_uname('s') . ' ' . php_uname('v');
124 }
125
126 return $this->operating_system;
127 } else {
128 return __('Blocked by hosting', 'backup-backup');
129 }
130 }
131
132 /**
133 * Get the upload directory url from WordPress details.
134 *
135 * @return String // upload directory url
136 */
137 public function get_upload_dir_url() {
138 if (! isset($this->upload_dir_url)) {
139 $upload_dir_url = wp_get_upload_dir();
140 $this->upload_dir_url = $upload_dir_url['baseurl'];
141 }
142
143 return $this->upload_dir_url;
144 }
145
146 /**
147 * Get the content directory
148 *
149 * @return String // content directory
150 */
151 public function get_content_dir() {
152 if (! isset($this->content_dir)) {
153 $content_dir = plugin_dir_path(WP_CONTENT_DIR . '/' . 'plugins/');
154 $this->content_dir = $content_dir;
155 }
156
157 return $this->content_dir;
158 }
159
160 /**
161 * Get the plugin directory from WordPress details.
162 *
163 * @return String // plugin directory
164 */
165 public function get_plugin_dir() {
166 if (! isset($this->plugin_dir)) {
167 $plugin_dir = plugin_dir_path(WP_CONTENT_DIR . '/plugins/plugin-folder');
168 $this->plugin_dir = $plugin_dir;
169 }
170
171 return $this->plugin_dir;
172 }
173
174 /**
175 * Get the active plugins.
176 *
177 * @return String // active plugins
178 */
179 public function get_active_plugins_info() {
180 if (! isset($this->active_plugins)) {
181 $active_plugins = get_option('active_plugins', false);
182
183 $arr_active_plugins = [];
184
185 foreach ($active_plugins as $path) {
186 $arr_data = [];
187 if (! function_exists('get_plugin_data')) {
188 require_once ABSPATH . 'wp-admin/includes/plugin.php';
189 }
190 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $path);
191 if (
192 isset($plugin_data['Name']) && ! empty($plugin_data['Name'])
193 && isset($plugin_data['Version']) && ! empty($plugin_data['Version'])
194 ) {
195 $arr_data['name'] = $plugin_data['Name'];
196 $arr_data['version'] = $plugin_data['Version'];
197 $arr_data['slug'] = $plugin_data['TextDomain'];
198
199 array_push($arr_active_plugins, $arr_data);
200 unset($arr_data);
201 }
202 }
203 $this->active_plugins = $arr_active_plugins;
204 }
205
206 return $this->active_plugins;
207 }
208
209 /**
210 * Get the check multisite.
211 *
212 * @return bool // check multisite
213 */
214 public function check_multisite() {
215 if (! isset($this->is_multisite)) {
216 $this->is_multisite = is_multisite();
217 }
218
219 return $this->is_multisite;
220 }
221
222 /**
223 * Get the disk free space
224 *
225 * @return float // disk free space
226 */
227 public function get_disk_free_space() {
228 if ($this->is_enabled('disk_free_space')) {
229 if (!isset($this->disk_free_space)) {
230 $this->disk_free_space = \disk_free_space(ABSPATH);
231 }
232
233 return $this->disk_free_space;
234 } else {
235 return __('Blocked by hosting', 'backup-backup');
236 }
237 }
238
239 /**
240 * Get the php version
241 *
242 * @return String // php version
243 */
244 public function get_php_version() {
245 if (! isset($this->php_version)) {
246 $this->php_version = explode(' ', phpversion())[0];
247 }
248
249 return $this->php_version;
250 }
251
252 /**
253 * Get the php loaded extensions
254 *
255 * @return String // php loaded extensions
256 */
257 public function get_php_loaded_extensions() {
258 if (! isset($this->php_loaded_extensions)) {
259 $this->php_loaded_extensions = get_loaded_extensions();
260 }
261
262 return $this->php_loaded_extensions;
263 }
264
265 /**
266 * Get the disable functions
267 *
268 * @return String // disable functions
269 */
270 public function get_php_disable_functions() {
271 if (! isset($this->disable_functions)) {
272 $this->disable_functions = explode(',', ini_get('disable_functions'));
273 }
274
275 return $this->disable_functions;
276 }
277
278 /**
279 * Get the backtrack limit
280 *
281 * @return String // backtrack limit
282 */
283 public function get_backtrack_limit() {
284 if (! isset($this->backtrack_limit)) {
285 $this->backtrack_limit = (int) ini_get('pcre.backtrack_limit');
286 }
287
288 return $this->backtrack_limit;
289 }
290
291 /**
292 * Get the is mysql character set
293 *
294 * @return String // mysql character set
295 */
296 public function get_mysql_character_set() {
297 global $wpdb;
298 if (! isset($this->get_mysql_character_set)) {
299 $charset_query = $wpdb->get_charset_collate();
300 $matches = [];
301 preg_match('/SET\s+(\w+)/', $charset_query, $matches);
302 if (count($matches) > 1) {
303 return $matches[1];
304 }
305 }
306
307 return '';
308 }
309
310 /**
311 * Get the is get active_themes_info
312 *
313 * @return String // active_themes_info
314 */
315 public function get_active_themes_info() {
316 if (! isset($this->wp_active_themes_info)) {
317 $arr_active_themes = [];
318 $theme = wp_get_theme();
319 $theme_name = $theme->get('TextDomain');
320 $theme_version = $theme->get('TextDomain');
321 if (
322 isset($theme_name) && ! empty($theme_name)
323 && isset($theme_version) && ! empty($theme_version)
324 ) {
325 $arr_data['name'] = $theme->get('Name');
326 $arr_data['version'] = $theme->get('Version');
327 $arr_data['slug'] = $theme->get('TextDomain');
328
329 array_push($arr_active_themes, $arr_data);
330 unset($arr_data);
331 }
332 $this->wp_active_themes_info = $arr_active_themes;
333 }
334
335 return $this->wp_active_themes_info;
336 }
337
338 /**
339 * Get the is get php_version_primary()
340 *
341 * @return String // php_version_primary()
342 */
343 public function get_php_version_primary() {
344 if (! isset($this->php_version_primary)) {
345 $this->php_version_primary = explode('.', $this->get_php_version());
346
347 return $this->php_version_primary[0];
348 }
349 }
350
351 /**
352 * Get the is get php_version_secondary()
353 *
354 * @return String // php_version_secondary()
355 */
356 public function get_php_version_secondary() {
357 if (! isset($this->php_version_secondary)) {
358 $this->php_version_secondary = explode('.', $this->get_php_version());
359
360 return $this->php_version_secondary[1];
361 }
362 }
363
364 /**
365 * Get the is get php_version_minor()
366 *
367 * @return String // php_version_minor()
368 */
369 public function get_php_version_minor() {
370 if (! isset($this->php_version_minor)) {
371 $this->php_version_minor = explode('.', $this->get_php_version());
372
373 return $this->php_version_minor[2];
374 }
375 }
376
377 /**
378 * Get changes human redeable sizes to numbers()
379 *
380 * @param String $num // readble size to be converted to byte
381 *
382 * @return number // readble_size_to_bytes()
383 */
384 public function readble_size_to_bytes($num) {
385 $num_split = str_split(strval(strtolower($num)));
386 $num_split_temp = $num_split;
387 $num_end = end($num_split);
388 array_pop($num_split);
389 $num_join = implode('', $num_split);
390 if ('m' === $num_end) {
391 $num = doubleval($num_join) * 1048576;
392 } elseif ('k' === $num_end) {
393 $num = doubleval($num_join) * 1024;
394 } elseif ('g' === $num_end) {
395 $num = doubleval($num_join) * 1073741824;
396 }
397
398 return $num;
399 }
400
401 /**
402 * List of system information.
403 *
404 * @return array // List of system information
405 */
406 public function to_array() {
407 global $wpdb;
408 if (function_exists('curl_version')) {
409 $curl_version = curl_version();
410 } else {
411 $curl_version = [];
412 }
413
414 return [
415 // WP related.
416 'wp_version' => get_bloginfo('version'),
417 'wp_site_url' => \site_url(),
418 'wp_timezone' => $this->get_timezone(),
419 'wp_blog_time' => time(),
420 'wp_root_dir' => ABSPATH,
421 'wp_language' => get_bloginfo('language'),
422 'wp_cache' => defined('WP_CACHE') ? WP_CACHE : null,
423 'wp_fs_method' => defined('FS_METHOD') ? FS_METHOD : null,
424 'wp_db_charset' => defined('DB_CHARSET') ? DB_CHARSET : null,
425 'wp_db_collate' => defined('DB_COLLATE') ? DB_COLLATE : null,
426 'wp_debug' => defined('WP_DEBUG') ? WP_DEBUG : null,
427 'wp_debug_log' => defined('WP_DEBUG_LOG') ? WP_DEBUG_LOG : null,
428 'wp_debug_display' => defined('WP_DEBUG_DISPLAY') ? WP_DEBUG_DISPLAY : null,
429 'wp_script_debug' => defined('SCRIPT_DEBUG') ? SCRIPT_DEBUG : null,
430 // 'wp_content_dir' => File_System::normalize_path( $this->get_content_dir() ),
431 // 'wp_plugin_dir' => ( new File_System() )->get_plugin_root_directory(),
432 // 'wp_theme_dir' => ( new File_System() )->get_theme_root_directory(),
433 // 'wp_upload_dir' => ( new File_System() )->get_upload_directory(),
434 'wp_upload_dir_url' => $this->get_upload_dir_url(),
435 'wp_multisite_enabled' => $this->check_multisite(),
436 'wp_memory_limit_readable' => defined('WP_MEMORY_LIMIT') ? WP_MEMORY_LIMIT : null,
437 'wp_memory_limit_bytes' => defined('WP_MEMORY_LIMIT') ? $this->readble_size_to_bytes(WP_MEMORY_LIMIT) : null,
438 'wp_max_memory_limit_readble' => defined('WP_MAX_MEMORY_LIMIT') ? WP_MAX_MEMORY_LIMIT : null,
439 'wp_max_memory_limit_bytes' => defined('WP_MAX_MEMORY_LIMIT') ? $this->readble_size_to_bytes(WP_MAX_MEMORY_LIMIT) : null,
440 'wp_active_plugins_info' => $this->get_active_plugins_info(),
441 'wp_alternative_cron_enabled' => defined('ALTERNATE_WP_CRON') ? ALTERNATE_WP_CRON : null,
442 'wp_cron_enabled' => defined('DISABLE_WP_CRON') ? false : true,
443 'wp_cron_lock_timeout' => defined('WP_CRON_LOCK_TIMEOUT') ? WP_CRON_LOCK_TIMEOUT : null,
444 'wp_cron_job_running' => defined('DOING_CRON') ? DOING_CRON : false,
445 'wp_http_block_external' => defined('WP_HTTP_BLOCK_EXTERNAL') ? true : false,
446 'wp_automatic_update_disable' => defined('AUTOMATIC_UPDATER_DISABLED') ? true : false,
447 'wp_active_themes_info' => $this->get_active_themes_info(),
448
449 // Webserver related information.
450 'web_server_name' => $this->get_webserver(),
451 'operating_system_short_name' => $this->get_os(),
452 'operating_system_full' => $this->get_operating_system(),
453 'server_ip' => isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : null,
454 'temp_folder' => get_temp_dir(),
455
456 // PHP Library related info.
457
458 // Disk & storage related info.
459 'disk_free_space_bytes' => $this->get_disk_free_space(),
460
461 'disk_free_space_readable' => (($this->is_enabled('disk_total_space')) ? BMP::humanSize($this->get_disk_free_space()) : __('Blocked by hosting', 'backup-backup')),
462 'dir_disk_space_bytes' => (($this->is_enabled('disk_total_space')) ? disk_total_space(ABSPATH) : __('Blocked by hosting', 'backup-backup')),
463 'dir_disk_space_readable' => (($this->is_enabled('disk_total_space')) ? BMP::humanSize(disk_total_space(ABSPATH)) : __('Blocked by hosting', 'backup-backup')),
464
465 // PHP Configuration information.
466 'php_memory_limit_bytes' => $this->readble_size_to_bytes(ini_get('memory_limit')),
467 'php_memory_limit_readable' => ini_get('memory_limit'),
468 'php_max_execution_time' => ini_get('max_execution_time'),
469 'php_upload_max_filesize_bytes' => $this->readble_size_to_bytes(ini_get('upload_max_filesize')),
470 'php_upload_max_filesize_readable' => ini_get('upload_max_filesize'),
471 'php_max_input_vars' => (int) ini_get('max_input_vars'),
472 'php_post_max_size_bytes' => $this->readble_size_to_bytes(ini_get('post_max_size')),
473 'php_post_max_size_readable' => ini_get('post_max_size'),
474
475 'php_version_primary' => $this->get_php_version_primary(),
476 'php_version_secondary' => $this->get_php_version_secondary(),
477 'php_version_minor' => $this->get_php_version_minor(),
478 'php_version_full' => $this->get_php_version(),
479
480 'php_sapi' => php_sapi_name(),
481 'php_allow_url_fopen' => ini_get('allow_url_fopen') === 1 ? true : false,
482 'php_loaded_extensions' => $this->get_php_loaded_extensions(),
483 'php_disable_functions' => $this->get_php_disable_functions(),
484 'php_xml_support' => extension_loaded('xml'),
485 'php_backtrack_limit' => $this->get_backtrack_limit(),
486 'php_fast_cgi' => strpos(php_sapi_name(), 'fcgi') !== false, // for some it was coming fpm-fcgi and on some cgi-fcgi so changed to account for both.
487 'php_zip_archive_class_exists' => class_exists('ZipArchive'),
488 'php_mcrypt_exists' => extension_loaded('mcrypt'),
489
490 // MySql Configuration information.
491 'mysql_version' => $wpdb->db_version(),
492 'mysql_character_set' => $this->get_mysql_character_set(),
493
494 'curl_version' => isset($curl_version['version']) ? $curl_version['version'] : null,
495 'curl_ssl_enabled' => isset($curl_version['features']) ? (bool) ($curl_version['features'] & 4) : false,
496 'php_open_ssl_version_text' => isset($curl_version['ssl_version']) ? $curl_version['ssl_version'] : null,
497 'php_open_ssl_version_number' => isset($curl_version['ssl_version_number']) ? $curl_version['ssl_version_number'] : null,
498 'plugin_compile_method' => defined('BMI_REV') ? BMI_REV : 'unknown'
499 ];
500 }
501 }
502