.htaccess
5 months ago
Automation.php
5 months ago
General.php
5 months ago
Integrations.php
5 months ago
Logging.php
5 months ago
Maintenance.php
5 months ago
Notifications.php
5 months ago
Performance.php
5 months ago
Restore.php
5 months ago
Security.php
5 months ago
Settings.php
5 months ago
Updates.php
5 months ago
index.html
5 months ago
web.config
5 months ago
Security.php
95 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 DAILY_CHECKSUM_CHECK = 'DAILY_CHECKSUM_CHECK'; |
| 24 | const DATADIR_SECURED = 'SECURITY_DATADIR_SECURED'; |
| 25 | const DATADIR_RECOMMENDED = 'SECURITY_DATADIR_RECOMMENDED'; |
| 26 | |
| 27 | /** |
| 28 | * @throws IOException |
| 29 | * @throws ReflectionException |
| 30 | */ |
| 31 | public function __construct() { |
| 32 | parent::__construct(self::SECTION); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @return bool |
| 37 | */ |
| 38 | public function isMFAEnabled():bool { return (bool) $this->get(self::MFA_ENABLED, false); } |
| 39 | public function isMFAAllowCLI():bool { return (bool) $this->get(self::MFA_ALLOW_CLI, false); } |
| 40 | |
| 41 | /** |
| 42 | * @param bool $value |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | public function setMFAEnabled(bool $value):void { $this->set(self::MFA_ENABLED,$value); } |
| 47 | public function setMFAAllowCLI(bool $value):void { $this->set(self::MFA_ALLOW_CLI,$value); } |
| 48 | |
| 49 | /** |
| 50 | * @return bool |
| 51 | */ |
| 52 | public function isValidateChecksumsEnabled():bool { return (bool) $this->get(self::DAILY_CHECKSUM_CHECK, false); } |
| 53 | |
| 54 | /** |
| 55 | * @param bool $value |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public function setValidateChecksumsEnabled(bool $value):void { $this->set(self::DAILY_CHECKSUM_CHECK, $value); } |
| 60 | |
| 61 | /** |
| 62 | * @return array |
| 63 | */ |
| 64 | public function getDisplay():array { |
| 65 | return [ |
| 66 | self::DATADIR_SECURED => System::isDataDirSecured() ? 1 : 0, |
| 67 | self::DATADIR_RECOMMENDED => System::getRecommendSecurePath(), |
| 68 | self::MFA_ENABLED => $this->isMFAEnabled() ? 1 : 0, |
| 69 | self::MFA_ALLOW_CLI => $this->isMFAAllowCLI() ? 1 : 0, |
| 70 | Config::ALTERNATE_DATA_FOLDER => Factory::getConfig()->getAlternateDataFolder(), |
| 71 | self::DAILY_CHECKSUM_CHECK => $this->isValidateChecksumsEnabled() ? 1 : 0, |
| 72 | ]; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return array |
| 77 | */ |
| 78 | public function getDisplayCLI():array { |
| 79 | return [ |
| 80 | 'MFA Enabled' => $this->isMFAEnabled() ? "Yes" : "No", |
| 81 | 'MFA Allow CLI' => $this->isMFAAllowCLI() ? "Yes" : "No", |
| 82 | 'Alternate Data Directory' => Factory::getConfig()->getAlternateDataFolder(), |
| 83 | 'Validate System Files Checksums' => $this->isValidateChecksumsEnabled() ? "Yes" : "No", |
| 84 | ]; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | */ |
| 89 | public function validateFields():void {} |
| 90 | |
| 91 | public function save(): void { |
| 92 | if (!$this->isMFAEnabled()) GoogleAuthenticator::clearCookie(); |
| 93 | parent::save(); |
| 94 | } |
| 95 | } |