| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2025-03-14 17:45:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-23 11:26:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  | /* | 
					
						
							|  |  |  |  * ValidatesEnvironmentVariables.php | 
					
						
							| 
									
										
										
										
											2025-08-23 11:26:04 +02:00
										 |  |  |  * Copyright (c) 2025 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							| 
									
										
										
										
											2025-08-23 11:26:04 +02:00
										 |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-23 11:26:04 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  | namespace FireflyIII\Console\Commands\Integrity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Console\Commands\ShowsFriendlyMessages; | 
					
						
							|  |  |  | use Illuminate\Console\Command; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ValidatesEnvironmentVariables extends Command | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     use ShowsFriendlyMessages; | 
					
						
							| 
									
										
										
										
											2025-03-08 15:57:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-04 17:41:26 +02:00
										 |  |  |     protected $description = 'Makes sure you use the correct variables.'; | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  |     protected $signature   = 'integrity:validates-environment-variables'; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Execute the console command. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function handle(): int | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |         $result = $this->validateLanguage(); | 
					
						
							|  |  |  |         if (false === $result) { | 
					
						
							|  |  |  |             return Command::FAILURE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $result = $this->validateGuard(); | 
					
						
							|  |  |  |         if (false === $result) { | 
					
						
							|  |  |  |             return Command::FAILURE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $result = $this->validateStaticToken(); | 
					
						
							|  |  |  |         if (false === $result) { | 
					
						
							|  |  |  |             return Command::FAILURE; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-14 17:45:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |         return Command::SUCCESS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |     private function validateLanguage(): bool | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  |         $language  = config('firefly.default_language'); | 
					
						
							|  |  |  |         $locale    = config('firefly.default_locale'); | 
					
						
							|  |  |  |         $options   = array_keys(config('firefly.languages')); | 
					
						
							| 
									
										
										
										
											2025-03-08 15:57:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!in_array($language, $options, true)) { | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |             $this->friendlyError(sprintf('DEFAULT_LANGUAGE "%s" is not a valid language for Firefly III.', $language)); | 
					
						
							|  |  |  |             $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); | 
					
						
							|  |  |  |             $this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options))); | 
					
						
							| 
									
										
										
										
											2025-03-14 17:45:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         $options[] = 'equal'; | 
					
						
							| 
									
										
										
										
											2025-03-08 15:57:59 +01:00
										 |  |  |         if (!in_array($locale, $options, true)) { | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |             $this->friendlyError(sprintf('DEFAULT_LOCALE "%s" is not a valid local for Firefly III.', $locale)); | 
					
						
							|  |  |  |             $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); | 
					
						
							|  |  |  |             $this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options))); | 
					
						
							| 
									
										
										
										
											2025-03-14 17:45:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |     private function validateGuard(): bool | 
					
						
							| 
									
										
										
										
											2025-03-08 15:57:59 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-03-08 19:55:21 +01:00
										 |  |  |         $guard = config('auth.defaults.guard'); | 
					
						
							| 
									
										
										
										
											2025-03-08 15:57:59 +01:00
										 |  |  |         if ('web' !== $guard && 'remote_user_guard' !== $guard) { | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |             $this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard)); | 
					
						
							|  |  |  |             $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); | 
					
						
							|  |  |  |             $this->friendlyError('Valid guards are: web, remote_user_guard'); | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |     private function validateStaticToken(): bool | 
					
						
							| 
									
										
										
										
											2025-03-08 15:57:59 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |         $token = (string)config('firefly.static_cron_token'); | 
					
						
							| 
									
										
										
										
											2025-03-14 17:45:16 +01:00
										 |  |  |         if ('' !== $token && 32 !== strlen($token)) { | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |             $this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.'); | 
					
						
							|  |  |  |             $this->friendlyError('Please check your .env file and make sure you use a valid setting.'); | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-16 19:36:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-16 15:04:15 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2025-03-08 05:38:51 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |