PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.11.1
JetBackup – Backup, Restore & Migrate v3.1.11.1
3.1.23.6 3.1.23.5 3.1.23.3 3.1.22.4 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 / Settings / General.php
backup / src / JetBackup / Settings Last commit date
.htaccess 1 year ago Automation.php 1 year ago General.php 1 year ago Integrations.php 1 year ago Logging.php 1 year ago Maintenance.php 1 year ago Notifications.php 1 year ago Performance.php 1 year ago Restore.php 1 year ago Security.php 1 year ago Settings.php 1 year ago Updates.php 1 year ago index.html 1 year ago web.config 1 year ago
General.php
172 lines
1 <?php
2
3 namespace JetBackup\Settings;
4
5 use Exception;
6 use JetBackup\Config\Config;
7 use JetBackup\Entities\Util;
8 use JetBackup\Exception\DBException;
9 use JetBackup\Exception\FieldsValidationException;
10 use JetBackup\Exception\JetBackupLinuxException;
11 use JetBackup\Factory;
12 use JetBackup\JetBackupLinux\JetBackupLinux;
13 use JetBackup\License\License;
14 use JetBackup\Wordpress\Wordpress;
15 use SleekDB\Exceptions\InvalidArgumentException;
16 use SleekDB\Exceptions\IOException;
17
18 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
19
20 class General extends Settings {
21
22 const SECTION = 'general';
23
24 const TIMEZONE = 'TIMEZONE';
25 const JETBACKUP_INTEGRATION = 'JETBACKUP_INTEGRATION';
26 const ADMIN_TOP_MENU_INTEGRATION = 'ADMIN_TOP_MENU_INTEGRATION';
27 const COMMUNITY_LANGUAGES = 'COMMUNITY_LANGUAGES';
28 const MANUAL_BACKUPS_RETENTION = 'MANUAL_BACKUPS_RETENTION';
29 const PHP_CLI_LOCATION = 'PHP_CLI_LOCATION';
30 const MYSQL_DEFAULT_PORT = 'MYSQL_DEFAULT_PORT';
31 const PHP_DEFAULT_BINARY = 'php';
32 const DEFAULT_TIMEZONE = 'UTC';
33 const WORDPRESS_TIMEZONE = 'WORDPRESS_TIMEZONE';
34 const LICENSE_STATUS = 'LICENSE_STATUS';
35
36 /**
37 * @throws InvalidArgumentException
38 * @throws DBException
39 * @throws IOException
40 */
41 public function __construct() {
42 parent::__construct(self::SECTION);
43 }
44
45 /**
46 * @return string
47 */
48 public function getTimeZone():string {
49 $timezone = $this->get(self::TIMEZONE, self::WORDPRESS_TIMEZONE);
50 if ($timezone == self::WORDPRESS_TIMEZONE) return Wordpress::getOption('timezone_string') ?: self::DEFAULT_TIMEZONE;
51 return $timezone;
52 }
53
54 private function getTimeZoneDisplay() {return $this->get(self::TIMEZONE, self::WORDPRESS_TIMEZONE);}
55 /**
56 * @param $value
57 *
58 * @return void
59 */
60 public function setTimeZone($value):void { $this->set(self::TIMEZONE, $value); }
61
62 /**
63 * @return bool
64 */
65 public function isJBIntegrationEnabled():bool { return (bool) $this->get(self::JETBACKUP_INTEGRATION, false); }
66 public function isAdminTopMenuIntegrationEnabled():bool { return (bool) $this->get(self::ADMIN_TOP_MENU_INTEGRATION, true); }
67
68 /**
69 * @param bool $value
70 *
71 * @return void
72 */
73 public function setJBIntegrationEnabled(bool $value):void { $this->set(self::JETBACKUP_INTEGRATION, $value); }
74 public function setAdminTopMenuIntegration(bool $value):void { $this->set(self::ADMIN_TOP_MENU_INTEGRATION, $value); }
75
76 /**
77 * @return bool
78 */
79 public function isCommunityLanguages():bool { return (bool) $this->get(self::COMMUNITY_LANGUAGES, true); }
80
81 /**
82 * @param bool $value
83 *
84 * @return void
85 */
86 public function setCommunityLanguages(bool $value):void { $this->set(self::COMMUNITY_LANGUAGES, $value); }
87
88 /**
89 * @return int
90 */
91 public function getManualBackupsRetention():int { return (int) $this->get(self::MANUAL_BACKUPS_RETENTION, 0); }
92
93 /**
94 * @param int $value
95 *
96 * @return void
97 */
98 public function setManualBackupsRetention(int $value):void { $this->set(self::MANUAL_BACKUPS_RETENTION, $value); }
99
100 /**
101 * @return string
102 */
103 public function getPHPCLILocation():string { return $this->get(self::PHP_CLI_LOCATION, self::PHP_DEFAULT_BINARY); }
104 public function getMysqlDefaultPort():int { return $this->get(self::MYSQL_DEFAULT_PORT, 3306); }
105
106 /**
107 * @param $value
108 *
109 * @return void
110 */
111 public function setPHPCLILocation($value):void { $this->set(self::PHP_CLI_LOCATION, $value); }
112 public function setMysqlDefaultPort($value):void { $this->set(self::MYSQL_DEFAULT_PORT, $value); }
113
114 /**
115 * @return array
116 * @throws Exception
117 */
118 public function getDisplay():array {
119
120 return [
121 Config::LICENSE_KEY => str_repeat('*', max(0, strlen(Factory::getConfig()->getLicenseKey()) - 6)) . substr(Factory::getConfig()->getLicenseKey(), -4),
122 self::LICENSE_STATUS => License::getLicenseStatus(),
123 self::TIMEZONE => $this->getTimeZoneDisplay(),
124 self::COMMUNITY_LANGUAGES => $this->isCommunityLanguages() ? 1 : 0,
125 self::JETBACKUP_INTEGRATION => $this->isJBIntegrationEnabled() ? 1 : 0,
126 self::ADMIN_TOP_MENU_INTEGRATION => $this->isAdminTopMenuIntegrationEnabled() ? 1 : 0,
127 self::MANUAL_BACKUPS_RETENTION => $this->getManualBackupsRetention(),
128 self::PHP_CLI_LOCATION => $this->getPHPCLILocation(),
129 self::MYSQL_DEFAULT_PORT => $this->getMySQLDefaultPort(),
130 ];
131 }
132
133 /**
134 * @return array
135 * @throws Exception
136 */
137 public function getDisplayCLI():array {
138
139 return [
140 'License Key' => str_repeat('*', max(0, strlen(Factory::getConfig()->getLicenseKey()) - 6)) . substr(Factory::getConfig()->getLicenseKey(), -4),
141 'License Status' => License::getLicenseStatus(),
142 'Timezone' => $this->getTimeZoneDisplay(),
143 'Community Languages' => $this->isCommunityLanguages() ? "Yes" : "No",
144 'JetBackup Integration' => $this->isJBIntegrationEnabled() ? "Yes" : "No",
145 'Admin bar top menu integration' => $this->isAdminTopMenuIntegrationEnabled() ? "Yes" : "No",
146 'Manual Backup Retain' => $this->getManualBackupsRetention(),
147 'PHP CLI Location' => $this->getPHPCLILocation(),
148 'MySQL Default Port' => $this->getMysqlDefaultPort(),
149 ];
150 }
151
152 /**
153 * @return void
154 * @throws FieldsValidationException
155 */
156 public function validateFields():void {
157
158 if((!$this->getTimeZone() || $this->getTimeZone() != (self::DEFAULT_TIMEZONE || self::WORDPRESS_TIMEZONE)) && !isset(Util::generateTimeZoneList()[$this->getTimeZone()]))
159 throw new FieldsValidationException("Timezone " . $this->getTimeZone(). " is not valid");
160
161 if((!$this->getPHPCLILocation() || strtolower($this->getPHPCLILocation()) != self::PHP_DEFAULT_BINARY) && !is_executable(trim($this->getPHPCLILocation())))
162 throw new FieldsValidationException("PHP CLI location ".$this->getPHPCLILocation()." is not executable");
163
164 if($this->isJBIntegrationEnabled()) {
165 try {
166 JetBackupLinux::checkRequirements();
167 } catch(JetBackupLinuxException $e) {
168 throw new FieldsValidationException($e->getMessage());
169 }
170 }
171 }
172 }