.htaccess
1 year ago
Automation.php
10 months ago
General.php
3 months ago
Integrations.php
4 months ago
Logging.php
4 months ago
Maintenance.php
4 months ago
Notifications.php
4 months ago
Performance.php
3 months ago
Restore.php
1 year ago
Security.php
23 hours ago
Settings.php
4 months ago
Updates.php
4 months ago
index.html
1 year ago
web.config
1 year ago
Security.php
105 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Settings; |
| 4 | |
| 5 | use JetBackup\Config\Config; |
| 6 | use JetBackup\Config\System; |
| 7 | use JetBackup\Exception\AjaxException; |
| 8 | use JetBackup\Exception\FieldsValidationException; |
| 9 | use JetBackup\Exception\IOException; |
| 10 | use JetBackup\Factory; |
| 11 | use JetBackup\MFA\GoogleAuthenticator; |
| 12 | use JetBackup\Wordpress\UI; |
| 13 | use ReflectionException; |
| 14 | |
| 15 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 16 | |
| 17 | class Security extends Settings { |
| 18 | |
| 19 | const SECTION = 'security'; |
| 20 | |
| 21 | const MFA_ENABLED = 'MFA_ENABLED'; |
| 22 | const MFA_ALLOW_CLI = 'MFA_ALLOW_CLI'; |
| 23 | const ABILITIES_ENABLED = 'ABILITIES_ENABLED'; |
| 24 | const MFA_ALLOW_ABILITIES = 'MFA_ALLOW_ABILITIES'; |
| 25 | const DAILY_CHECKSUM_CHECK = 'DAILY_CHECKSUM_CHECK'; |
| 26 | const DATADIR_SECURED = 'SECURITY_DATADIR_SECURED'; |
| 27 | const DATADIR_RECOMMENDED = 'SECURITY_DATADIR_RECOMMENDED'; |
| 28 | |
| 29 | /** |
| 30 | * @throws IOException |
| 31 | * @throws ReflectionException |
| 32 | */ |
| 33 | public function __construct() { |
| 34 | parent::__construct(self::SECTION); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return bool |
| 39 | */ |
| 40 | public function isMFAEnabled():bool { return (bool) $this->get(self::MFA_ENABLED, false); } |
| 41 | public function isMFAAllowCLI():bool { return (bool) $this->get(self::MFA_ALLOW_CLI, false); } |
| 42 | public function isAbilitiesEnabled():bool { return (bool) $this->get(self::ABILITIES_ENABLED, false); } |
| 43 | public function isMFAAllowAbilities():bool { return (bool) $this->get(self::MFA_ALLOW_ABILITIES, false); } |
| 44 | |
| 45 | /** |
| 46 | * @param bool $value |
| 47 | * |
| 48 | * @return void |
| 49 | */ |
| 50 | public function setMFAEnabled(bool $value):void { $this->set(self::MFA_ENABLED,$value); } |
| 51 | public function setMFAAllowCLI(bool $value):void { $this->set(self::MFA_ALLOW_CLI,$value); } |
| 52 | public function setAbilitiesEnabled(bool $value):void { $this->set(self::ABILITIES_ENABLED,$value); } |
| 53 | public function setMFAAllowAbilities(bool $value):void { $this->set(self::MFA_ALLOW_ABILITIES,$value); } |
| 54 | |
| 55 | /** |
| 56 | * @return bool |
| 57 | */ |
| 58 | public function isValidateChecksumsEnabled():bool { return (bool) $this->get(self::DAILY_CHECKSUM_CHECK, false); } |
| 59 | |
| 60 | /** |
| 61 | * @param bool $value |
| 62 | * |
| 63 | * @return void |
| 64 | */ |
| 65 | public function setValidateChecksumsEnabled(bool $value):void { $this->set(self::DAILY_CHECKSUM_CHECK, $value); } |
| 66 | |
| 67 | /** |
| 68 | * @return array |
| 69 | */ |
| 70 | public function getDisplay():array { |
| 71 | return [ |
| 72 | self::DATADIR_SECURED => System::isDataDirSecured() ? 1 : 0, |
| 73 | self::DATADIR_RECOMMENDED => System::getRecommendSecurePath(), |
| 74 | self::MFA_ENABLED => $this->isMFAEnabled() ? 1 : 0, |
| 75 | self::MFA_ALLOW_CLI => $this->isMFAAllowCLI() ? 1 : 0, |
| 76 | self::ABILITIES_ENABLED => $this->isAbilitiesEnabled() ? 1 : 0, |
| 77 | self::MFA_ALLOW_ABILITIES => $this->isMFAAllowAbilities() ? 1 : 0, |
| 78 | Config::ALTERNATE_DATA_FOLDER => Factory::getConfig()->getAlternateDataFolder(), |
| 79 | self::DAILY_CHECKSUM_CHECK => $this->isValidateChecksumsEnabled() ? 1 : 0, |
| 80 | ]; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return array |
| 85 | */ |
| 86 | public function getDisplayCLI():array { |
| 87 | return [ |
| 88 | 'MFA Enabled' => $this->isMFAEnabled() ? "Yes" : "No", |
| 89 | 'MFA Allow CLI' => $this->isMFAAllowCLI() ? "Yes" : "No", |
| 90 | 'Abilities API Enabled' => $this->isAbilitiesEnabled() ? "Yes" : "No", |
| 91 | 'MFA Allow Abilities API' => $this->isMFAAllowAbilities() ? "Yes" : "No", |
| 92 | 'Alternate Data Directory' => Factory::getConfig()->getAlternateDataFolder(), |
| 93 | 'Validate System Files Checksums' => $this->isValidateChecksumsEnabled() ? "Yes" : "No", |
| 94 | ]; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | */ |
| 99 | public function validateFields():void {} |
| 100 | |
| 101 | public function save(): void { |
| 102 | if (!$this->isMFAEnabled()) GoogleAuthenticator::clearCookie(); |
| 103 | parent::save(); |
| 104 | } |
| 105 | } |