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