PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.9.2
JetBackup – Backup, Restore & Migrate v3.1.9.2
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Config / System.php
backup / src / JetBackup / Config Last commit date
.htaccess 1 year ago Config.php 1 year ago Locations.php 1 year ago System.php 1 year ago index.html 1 year ago web.config 1 year ago
System.php
166 lines
1 <?php
2
3 namespace JetBackup\Config;
4
5 use DateTime;
6 use DateTimeZone;
7 use JetBackup\Cron\Cron;
8 use JetBackup\Entities\Util;
9 use JetBackup\Exception\IOException;
10 use JetBackup\Factory;
11 use JetBackup\IO\Execute;
12 use JetBackup\JetBackup;
13 use JetBackup\JetBackupLinux\JetBackupLinux;
14 use JetBackup\Wordpress\Wordpress;
15 use JetBackup\Wordpress\Helper;
16
17 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
18
19 class System {
20
21 const NO_VALUE_STRING = "Cannot get value";
22 const PHP_MIN_POST_MAX_SIZE = (8 * 1024 * 1024);
23
24 public static function isWindowsOS(): bool {
25 // Check if PHP_OS_FAMILY is available (PHP 7.2+)
26 if(defined('PHP_OS_FAMILY')) return PHP_OS_FAMILY === 'Windows';
27
28 // Fallback to using PHP_OS for older versions
29 return str_starts_with(strtoupper(PHP_OS), 'WIN');
30 }
31
32 public static function getLastCron (): int {
33 $cron_last = Factory::getLocations()->getDataDir() . JetBackup::SEP . Cron::LAST_FILE;
34 if(!file_exists($cron_last)) return 0;
35 $_start_time = filemtime($cron_last);
36 $timeDifference = microtime(true) - $_start_time;
37 return (int) $timeDifference;
38 }
39
40 public static function getRecommendSecurePath(): ?string {
41 // Check if the open_basedir directive is enabled
42 if (ini_get('open_basedir')) {
43 return '(Open basedir is enabled, cannot set secure path)';
44 }
45
46 // Attempt to fetch the user's home directory
47 $userHomeDir = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH');
48
49 // Validate the user's home directory
50 if ($userHomeDir && is_dir($userHomeDir)) {
51 // Construct the secure path within the user's home directory
52 return $userHomeDir . JetBackup::SEP . Factory::getConfig()->getDataDirectory();
53 }
54
55 // If home directory is not valid, fallback to the previous solution
56 $_base_path = dirname(Factory::getWPHelper()->getWordPressHomedir());
57
58 // Check if this is nested inside another WordPress installation
59 if (file_exists($_base_path . JetBackup::SEP . 'wp-config.php')) {
60 return null;
61 }
62
63 // Return the secure path based on the parent directory of the WordPress home directory
64 return $_base_path . JetBackup::SEP . Factory::getConfig()->getDataDirectory();
65 }
66
67 private static function getFreeDiskSpace(): string {
68 try {
69 return function_exists('disk_free_space') ? Util::bytesToHumanReadable(disk_free_space( Factory::getWPHelper()->getWordPressHomedir())) : self::NO_VALUE_STRING;
70 } catch (\Exception $e) {
71 throw new IOException($e->getMessage());
72 }
73 }
74
75 private static function getOpenFilesLimit (): ?string {
76 return function_exists('posix_getrlimit') ? posix_getrlimit()['hard openfiles'] : self::NO_VALUE_STRING;
77 }
78
79 private static function getPHPCliVersion () {
80 try {
81
82 if(!Execute::run((Factory::getSettingsGeneral()->getPHPCLILocation() ?: 'php') . " -r 'print_r(phpversion());'", $output))
83 return $output[0];
84
85 return self::NO_VALUE_STRING;
86
87 } catch (\Exception $e) {
88 throw new IOException($e->getMessage());
89 }
90 }
91
92 private static function getPHPVersion (): string {
93 return defined('PHP_VERSION') ? PHP_VERSION : self::NO_VALUE_STRING;
94 }
95
96 /**
97 * @throws IOException
98 */
99 public static function isPHPVersionCompatible() {
100
101 if (($php_web_version = self::getPHPVersion()) && ($php_cli_version = self::getPHPCliVersion()) != self::NO_VALUE_STRING) {
102 return version_compare($php_web_version, $php_cli_version, '=');
103 }
104
105 return true;
106 }
107
108 public static function isDataDirSecured(): bool {
109 $homedir = Factory::getWPHelper()->getWordPressHomedir();
110 $datadir = Factory::getLocations()->getDataDir();
111 return !str_starts_with($datadir, $homedir);
112 }
113
114 public static function isAlternateFolderSecured(?string $datadir): bool {
115 if (!$datadir) return false;
116 $homedir = Helper::getUserHomedir();
117 if(!$homedir) $homedir = dirname(ABSPATH);
118 return str_starts_with($datadir, $homedir);
119 }
120
121 private static function getAvailableCli (): string {
122 if (!($list = Execute::getAvailable())) return self::NO_VALUE_STRING;
123 return implode(',', array_values($list));
124 }
125
126 public static function getSystemInfo(): array {
127
128 $dateTime = new DateTime('now', new DateTimeZone(Factory::getSettingsGeneral()->getTimeZone()));
129
130 return [
131 'timezone' => Factory::getSettingsGeneral()->getTimeZone(),
132 'show_time' => $dateTime->format('H:i:s'),
133 'loaded_language' => Wordpress::getLocale(),
134 'open_files_limit' => self::getOpenFilesLimit(),
135 'memory_limit' => ini_get('memory_limit'),
136 'max_execution_time' => ini_get('max_execution_time'),
137 'post_max_size' => ini_get('post_max_size'),
138 'upload_max_filesize' => ini_get('upload_max_filesize'),
139 'wordpress_path' => Factory::getWPHelper()->getWordPressHomedir(),
140 'jetbackup_data_dir' => Factory::getLocations()->getDataDir(),
141 'free_disk_space' => self::getFreeDiskSpace(),
142 'php_version' => self::getPHPVersion(),
143 'php_cli' => self::getPHPCliVersion(),
144 'available_cli' => self::getAvailableCli(),
145 ];
146 }
147
148 /**
149 * @throws IOException
150 */
151 public static function getTotalAlerts(): int {
152 $alerts = 0;
153 if(!self::isDataDirSecured()) $alerts++;
154 if(ini_get('post_max_size') !== false && Util::humanReadableToBytes(ini_get('post_max_size')) < self::PHP_MIN_POST_MAX_SIZE) $alerts++;
155 if(!self::isPHPVersionCompatible()) $alerts++;
156 if(self::getLastCron() > 600) $alerts++;
157 if(!Factory::getSettingsAutomation()->isHeartbeatEnabled()) $alerts++;
158 if(!Factory::getSettingsAutomation()->isCronsEnabled()) $alerts++;
159 if(JetBackupLinux::isInstalled() && !Factory::getSettingsGeneral()->isJBIntegrationEnabled()) $alerts++;
160 return $alerts;
161 }
162
163 public static function getServerExecutionTime() {
164 return ini_get('max_execution_time') ?: 60;
165 }
166 }