.htaccess
9 months ago
AbortQueueItem.php
9 months ago
AddToQueue.php
9 months ago
ClearAlerts.php
9 months ago
ClearCompletedQueueItems.php
9 months ago
CreateSupportUser.php
9 months ago
DeleteBackupJob.php
9 months ago
DeleteDestination.php
9 months ago
DeleteDownload.php
9 months ago
DeleteSchedule.php
9 months ago
DeleteSnapshot.php
9 months ago
DestinationSetExportConfig.php
9 months ago
DuplicateBackupJob.php
9 months ago
EditBackupNotes.php
9 months ago
EnableBackupJob.php
9 months ago
EnableDestination.php
9 months ago
ExecuteCron.php
9 months ago
FileManager.php
9 months ago
GetBackup.php
9 months ago
GetBackupJob.php
9 months ago
GetDashboard.php
9 months ago
GetDatabaseTables.php
9 months ago
GetDestination.php
9 months ago
GetLog.php
9 months ago
GetQRCode.php
9 months ago
GetQueueItem.php
9 months ago
GetSchedule.php
9 months ago
GetSettingsAutomation.php
9 months ago
GetSettingsGeneral.php
9 months ago
GetSettingsIntegrations.php
9 months ago
GetSettingsLogging.php
9 months ago
GetSettingsMaintenance.php
9 months ago
GetSettingsNotifications.php
9 months ago
GetSettingsPerformance.php
9 months ago
GetSettingsRestore.php
9 months ago
GetSettingsSecurity.php
9 months ago
GetSettingsUpdates.php
9 months ago
GetSystemInfo.php
9 months ago
ListAlerts.php
9 months ago
ListBackupJobs.php
9 months ago
ListBackups.php
9 months ago
ListDatabaseTables.php
9 months ago
ListDestinations.php
9 months ago
ListDownloads.php
9 months ago
ListQueueItems.php
9 months ago
ListSchedules.php
9 months ago
LockSnapshot.php
9 months ago
ManageBackupJob.php
9 months ago
ManageDestination.php
9 months ago
ManageSchedule.php
9 months ago
ManageSettingsAutomation.php
9 months ago
ManageSettingsGeneral.php
9 months ago
ManageSettingsIntegrations.php
9 months ago
ManageSettingsLogging.php
9 months ago
ManageSettingsMaintenance.php
9 months ago
ManageSettingsNotifications.php
9 months ago
ManageSettingsPerformance.php
9 months ago
ManageSettingsRestore.php
9 months ago
ManageSettingsSecurity.php
9 months ago
ManageSettingsUpdates.php
9 months ago
ManageShowcase.php
9 months ago
PanelPreload.php
9 months ago
SendTestEmail.php
9 months ago
StartOverQueueItem.php
9 months ago
ValidateDestination.php
9 months ago
ValidateMFA.php
9 months ago
index.html
9 months ago
web.config
9 months ago
ManageSettingsGeneral.php
145 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 | * @return bool |
| 51 | * @throws AjaxException |
| 52 | */ |
| 53 | private function _getCommunityLanguages():bool { return $this->getUserInput(General::COMMUNITY_LANGUAGES, false, UserInput::BOOL); } |
| 54 | |
| 55 | /** |
| 56 | * @return int |
| 57 | * @throws AjaxException |
| 58 | */ |
| 59 | private function _getManualBackupsRetention(): int { return $this->getUserInput(General::MANUAL_BACKUPS_RETENTION, 0, UserInput::UINT); } |
| 60 | |
| 61 | /** |
| 62 | * @return string |
| 63 | * @throws AjaxException |
| 64 | */ |
| 65 | private function _getPHPCLILocation(): string { return $this->getUserInput(General::PHP_CLI_LOCATION, 'php', UserInput::STRING); } |
| 66 | |
| 67 | /** |
| 68 | * @return int |
| 69 | * @throws AjaxException |
| 70 | */ |
| 71 | private function _getMysqlDefaultPort(): int { return $this->getUserInput(General::MYSQL_DEFAULT_PORT, '3306', UserInput::UINT); } |
| 72 | |
| 73 | /** |
| 74 | * @return void |
| 75 | * @throws AjaxException |
| 76 | * @throws DBException |
| 77 | * @throws FieldsValidationException |
| 78 | * @throws IOException |
| 79 | * @throws InvalidArgumentException |
| 80 | * @throws JetBackupLinuxException |
| 81 | * @throws QueueException |
| 82 | * @throws \SleekDB\Exceptions\IOException |
| 83 | * @throws Exception |
| 84 | */ |
| 85 | public function execute(): void { |
| 86 | |
| 87 | $settings = Factory::getSettingsGeneral(); |
| 88 | $jb_integration_set = $this->isset(General::JETBACKUP_INTEGRATION); |
| 89 | $jb_integration_old_value = $jb_integration_set ? $settings->isJBIntegrationEnabled() : null; |
| 90 | |
| 91 | if($this->isset(General::TIMEZONE)) $settings->setTimeZone($this->_getTimeZone()); |
| 92 | if($jb_integration_set) $settings->setJBIntegrationEnabled($this->_getJetBackupIntegration()); |
| 93 | if($this->isset(General::COMMUNITY_LANGUAGES)) $settings->setCommunityLanguages($this->_getCommunityLanguages()); |
| 94 | if($this->isset(General::ADMIN_TOP_MENU_INTEGRATION)) $settings->setAdminTopMenuIntegration($this->_getAdminTopMenuIntegration()); |
| 95 | if($this->isset(General::MANUAL_BACKUPS_RETENTION)) $settings->setManualBackupsRetention($this->_getManualBackupsRetention()); |
| 96 | if($this->isset(General::PHP_CLI_LOCATION)) $settings->setPHPCLILocation($this->_getPHPCLILocation()); |
| 97 | if($this->isset(General::MYSQL_DEFAULT_PORT)) $settings->setMysqlDefaultPort($this->_getMysqlDefaultPort()); |
| 98 | |
| 99 | $settings->validateFields(); |
| 100 | |
| 101 | if($this->isset(Config::LICENSE_KEY) && !str_starts_with($this->_getLicenseKey(), '*')) { |
| 102 | $config = Factory::getConfig(); |
| 103 | |
| 104 | $new_license = $this->_getLicenseKey(); |
| 105 | $old_license = $config->getLicenseKey(); |
| 106 | |
| 107 | if($old_license != $new_license) { |
| 108 | |
| 109 | $config->setLicenseKey($new_license); |
| 110 | |
| 111 | if($new_license) { |
| 112 | |
| 113 | try { |
| 114 | $config->validateLicense(); |
| 115 | $localKey = new LicenseLocalKey(); |
| 116 | if($localKey->getStatus() != License::STATUS_ACTIVE) throw new LicenseException($localKey->getDescription()); |
| 117 | } catch (LicenseException $e) { |
| 118 | |
| 119 | $config->setLicenseKey($old_license); |
| 120 | $config->save(); |
| 121 | |
| 122 | throw new FieldsValidationException($e->getMessage()); |
| 123 | } |
| 124 | |
| 125 | } else { |
| 126 | $config->setLicenseLocalKey(''); |
| 127 | } |
| 128 | |
| 129 | $config->save(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | $settings->save(); |
| 134 | |
| 135 | if($jb_integration_set) { |
| 136 | if ($jb_integration_old_value != $settings->isJBIntegrationEnabled()) { |
| 137 | if($settings->isJBIntegrationEnabled() == 0) JetBackupLinux::deleteSnapshots(); |
| 138 | if($settings->isJBIntegrationEnabled() == 1) JetBackupLinux::addToQueue(); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | $this->setResponseMessage('Saved Successfully'); |
| 143 | $this->setResponseData($this->isCLI() ? $settings->getDisplayCLI() : $settings->getDisplay()); |
| 144 | } |
| 145 | } |