PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.22.3
JetBackup – Backup, Restore & Migrate v3.1.22.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 / Ajax / Calls / ManageSettingsGeneral.php
backup / src / JetBackup / Ajax / Calls Last commit date
.htaccess 1 year ago AbortQueueItem.php 1 year ago AddToQueue.php 3 months ago ClearAlerts.php 1 year ago ClearCompletedQueueItems.php 1 year ago CreateSupportUser.php 1 year ago DeleteBackupJob.php 1 year ago DeleteDestination.php 1 year ago DeleteDownload.php 1 year ago DeleteSchedule.php 1 year ago DeleteSnapshot.php 1 year ago DestinationSetExportConfig.php 1 year ago DuplicateBackupJob.php 1 year ago EditBackupNotes.php 1 year ago EnableBackupJob.php 1 year ago EnableDestination.php 1 year ago ExecuteCron.php 1 year ago FileManager.php 10 months ago GetBackup.php 1 year ago GetBackupJob.php 1 year ago GetDashboard.php 1 year ago GetDatabaseTables.php 1 year ago GetDestination.php 1 year ago GetLog.php 1 year ago GetQRCode.php 1 year ago GetQueueItem.php 1 year ago GetSchedule.php 1 year ago GetSettingsAutomation.php 1 year ago GetSettingsGeneral.php 1 year ago GetSettingsIntegrations.php 1 year ago GetSettingsLogging.php 1 year ago GetSettingsMaintenance.php 1 year ago GetSettingsNotifications.php 1 year ago GetSettingsPerformance.php 1 year ago GetSettingsRestore.php 1 year ago GetSettingsSecurity.php 1 year ago GetSettingsUpdates.php 1 year ago GetSystemInfo.php 11 months ago ListAlerts.php 1 year ago ListBackupJobs.php 1 year ago ListBackups.php 1 year ago ListDatabaseTables.php 1 year ago ListDestinations.php 1 year ago ListDownloads.php 1 year ago ListQueueItems.php 4 months ago ListSchedules.php 1 year ago LockSnapshot.php 1 year ago ManageBackupJob.php 1 year ago ManageDestination.php 1 year ago ManageSchedule.php 3 months ago ManageSettingsAutomation.php 10 months ago ManageSettingsGeneral.php 4 months ago ManageSettingsIntegrations.php 1 year ago ManageSettingsLogging.php 1 year ago ManageSettingsMaintenance.php 1 year ago ManageSettingsNotifications.php 1 year ago ManageSettingsPerformance.php 1 year ago ManageSettingsRestore.php 1 year ago ManageSettingsSecurity.php 2 weeks ago ManageSettingsUpdates.php 1 year ago ManageShowcase.php 1 year ago PanelPreload.php 1 year ago SendTestEmail.php 1 year ago StartOverQueueItem.php 1 year ago ValidateDestination.php 1 year ago ValidateMFA.php 1 year ago index.html 1 year ago web.config 1 year ago
ManageSettingsGeneral.php
160 lines
1 <?php
2
3 namespace JetBackup\Ajax\Calls;
4
5 use Exception;
6 use JetBackup\Ajax\aAjax;
7 use JetBackup\Config\Config;
8 use JetBackup\Exception\AjaxException;
9 use JetBackup\Exception\DBException;
10 use JetBackup\Exception\FieldsValidationException;
11 use JetBackup\Exception\IOException;
12 use JetBackup\Exception\JetBackupLinuxException;
13 use JetBackup\Exception\LicenseException;
14 use JetBackup\Exception\QueueException;
15 use JetBackup\Factory;
16 use JetBackup\JetBackupLinux\JetBackupLinux;
17 use JetBackup\License\License;
18 use JetBackup\License\LicenseLocalKey;
19 use JetBackup\Settings\General;
20 use JetBackup\UserInput\UserInput;
21 use SleekDB\Exceptions\InvalidArgumentException;
22
23 class ManageSettingsGeneral extends aAjax {
24
25 /**
26 * @return string
27 * @throws AjaxException
28 */
29 private function _getLicenseKey(): string { return $this->getUserInput(Config::LICENSE_KEY, '', UserInput::STRING); }
30
31 /**
32 * @return string
33 * @throws AjaxException
34 */
35 private function _getTimeZone(): string { return $this->getUserInput(General::TIMEZONE, 'UTC', UserInput::STRING); }
36
37 /**
38 * @return bool
39 * @throws AjaxException
40 */
41 private function _getJetBackupIntegration():bool { return $this->getUserInput(General::JETBACKUP_INTEGRATION, false, UserInput::BOOL); }
42
43 /**
44 * @return bool
45 * @throws AjaxException
46 */
47 private function _getAdminTopMenuIntegration():bool { return $this->getUserInput(General::ADMIN_TOP_MENU_INTEGRATION, true, UserInput::BOOL); }
48
49 /**
50 * @throws AjaxException
51 */
52 private function _getDisplayLocalDiskSpace():bool { return $this->getUserInput(General::DISPLAY_LOCAL_FREE_DISK_SPACE, false, UserInput::BOOL); }
53
54 /**
55 * @return bool
56 * @throws AjaxException
57 */
58 private function _getCommunityLanguages():bool { return $this->getUserInput(General::COMMUNITY_LANGUAGES, false, UserInput::BOOL); }
59
60 /**
61 * @return int
62 * @throws AjaxException
63 */
64 private function _getManualBackupsRetention(): int { return $this->getUserInput(General::MANUAL_BACKUPS_RETENTION, 0, UserInput::UINT); }
65
66 /**
67 * @return int
68 * @throws AjaxException
69 */
70 private function _getImportedBackupsRetention(): int { return $this->getUserInput(General::IMPORTED_BACKUPS_RETENTION, 10, UserInput::UINT); }
71
72 /**
73 * @return string
74 * @throws AjaxException
75 */
76 private function _getPHPCLILocation(): string { return $this->getUserInput(General::PHP_CLI_LOCATION, 'php', UserInput::STRING); }
77 private function _getAlternateWpConfigLocation(): string { return $this->getUserInput(General::ALTERNATE_WP_CONFIG_LOCATION, '', UserInput::STRING); }
78
79 /**
80 * @return int
81 * @throws AjaxException
82 */
83 private function _getMysqlDefaultPort(): int { return $this->getUserInput(General::MYSQL_DEFAULT_PORT, '3306', UserInput::UINT); }
84
85 /**
86 * @return void
87 * @throws AjaxException
88 * @throws DBException
89 * @throws FieldsValidationException
90 * @throws IOException
91 * @throws InvalidArgumentException
92 * @throws JetBackupLinuxException
93 * @throws QueueException
94 * @throws \SleekDB\Exceptions\IOException
95 * @throws Exception
96 */
97 public function execute(): void {
98
99 $settings = Factory::getSettingsGeneral();
100 $jb_integration_set = $this->isset(General::JETBACKUP_INTEGRATION);
101 $jb_integration_old_value = $jb_integration_set ? $settings->isJBIntegrationEnabled() : null;
102
103 if($this->isset(General::TIMEZONE)) $settings->setTimeZone($this->_getTimeZone());
104 if($jb_integration_set) $settings->setJBIntegrationEnabled($this->_getJetBackupIntegration());
105 if($this->isset(General::COMMUNITY_LANGUAGES)) $settings->setCommunityLanguages($this->_getCommunityLanguages());
106 if($this->isset(General::ADMIN_TOP_MENU_INTEGRATION)) $settings->setAdminTopMenuIntegration($this->_getAdminTopMenuIntegration());
107 if($this->isset(General::DISPLAY_LOCAL_FREE_DISK_SPACE)) $settings->setDisplayLocalDiskSpace($this->_getDisplayLocalDiskSpace());
108 if($this->isset(General::MANUAL_BACKUPS_RETENTION)) $settings->setManualBackupsRetention($this->_getManualBackupsRetention());
109 if($this->isset(General::IMPORTED_BACKUPS_RETENTION)) $settings->setImportedBackupsRetention($this->_getImportedBackupsRetention());
110 if($this->isset(General::PHP_CLI_LOCATION)) $settings->setPHPCLILocation($this->_getPHPCLILocation());
111 if($this->isset(General::ALTERNATE_WP_CONFIG_LOCATION)) $settings->setAlternateWpConfigLocation($this->_getAlternateWpConfigLocation());
112 if($this->isset(General::MYSQL_DEFAULT_PORT)) $settings->setMysqlDefaultPort($this->_getMysqlDefaultPort());
113
114 $settings->validateFields();
115
116 if($this->isset(Config::LICENSE_KEY) && !str_starts_with($this->_getLicenseKey(), '*')) {
117 $config = Factory::getConfig();
118
119 $new_license = $this->_getLicenseKey();
120 $old_license = $config->getLicenseKey();
121
122 if($old_license != $new_license) {
123
124 $config->setLicenseKey($new_license);
125
126 if($new_license) {
127
128 try {
129 $config->validateLicense();
130 $localKey = new LicenseLocalKey();
131 if($localKey->getStatus() != License::STATUS_ACTIVE) throw new LicenseException($localKey->getDescription());
132 } catch (LicenseException $e) {
133
134 $config->setLicenseKey($old_license);
135 $config->save();
136
137 throw new FieldsValidationException($e->getMessage());
138 }
139
140 } else {
141 $config->setLicenseLocalKey('');
142 }
143
144 $config->save();
145 }
146 }
147
148 $settings->save();
149
150 if($jb_integration_set) {
151 if ($jb_integration_old_value != $settings->isJBIntegrationEnabled()) {
152 if($settings->isJBIntegrationEnabled() == 0) JetBackupLinux::deleteSnapshots();
153 if($settings->isJBIntegrationEnabled() == 1) JetBackupLinux::addToQueue();
154 }
155 }
156
157 $this->setResponseMessage('Saved Successfully');
158 $this->setResponseData($this->isCLI() ? $settings->getDisplayCLI() : $settings->getDisplay());
159 }
160 }