A free open source IT asset/license management system
Moved pure env() calls into config files
snipe258813d87afb
diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.phpindex 0de38461b7..8730e9a9c9 100644--- a/app/Console/Commands/LdapSync.php+++ b/app/Console/Commands/LdapSync.php@@ -51,8 +51,8 @@ class LdapSync extends Commandexit();}- ini_set('max_execution_time', env('LDAP_TIME_LIM', 600)); // 600 seconds = 10 minutes- ini_set('memory_limit', env('LDAP_MEM_LIM', '500M'));+ ini_set('max_execution_time', config('app.ldap_time_limit')); // 600 seconds = 10 minutes+ ini_set('memory_limit', config('app.ldap_memory_limit'));// Single source of truth for internal-key => LDAP-attribute-name// lives on the Ldap model so parseAndMapLdapAttributes and thisdiff --git a/app/Console/Commands/MoveUploadsToNewDisk.php b/app/Console/Commands/MoveUploadsToNewDisk.phpindex 29f1f75532..461bd2f4e1 100644--- a/app/Console/Commands/MoveUploadsToNewDisk.php+++ b/app/Console/Commands/MoveUploadsToNewDisk.php@@ -89,7 +89,7 @@ class MoveUploadsToNewDisk extends Command$type_count++;$filename = basename($logo);Storage::disk('public')->put('uploads/'.$filename, file_get_contents($logo));- $this->info($type_count.'. LOGO: '.$filename.' was copied to '.env('PUBLIC_AWS_URL').'/uploads/'.$filename);+ $this->info($type_count.'. LOGO: '.$filename.' was copied to '.config('filesystems.disks.public_aws.url').'/uploads/'.$filename);}$private_uploads['assets'] = glob('storage/private_uploads/assets'.'/*.*');diff --git a/app/Console/Commands/ObjectImportCommand.php b/app/Console/Commands/ObjectImportCommand.phpindex 1319e6dbf4..7e2731face 100644--- a/app/Console/Commands/ObjectImportCommand.php+++ b/app/Console/Commands/ObjectImportCommand.php@@ -54,8 +54,8 @@ class ObjectImportCommand extends Command*/public function handle(){- ini_set('max_execution_time', env('IMPORT_TIME_LIMIT', 600)); // 600 seconds = 10 minutes- ini_set('memory_limit', env('IMPORT_MEMORY_LIMIT', '500M'));+ ini_set('max_execution_time', config('importer.time_limit')); // 600 seconds = 10 minutes+ ini_set('memory_limit', config('importer.memory_limit'));$this->progressIndicator = new ProgressIndicator($this->output);diff --git a/app/Console/Commands/SystemBackup.php b/app/Console/Commands/SystemBackup.phpindex ca2c9275c2..149e024b9f 100644--- a/app/Console/Commands/SystemBackup.php+++ b/app/Console/Commands/SystemBackup.php@@ -41,7 +41,7 @@ class SystemBackup extends Command*/public function handle(){- ini_set('max_execution_time', env('BACKUP_TIME_LIMIT', 600)); // 600 seconds = 10 minutes+ ini_set('max_execution_time', config('backup.time_limit')); // 600 seconds = 10 minutesif ($this->option('filename')) {$filename = $this->option('filename');diff --git a/app/Http/Controllers/Reports/CustomComponentReportController.php b/app/Http/Controllers/Reports/CustomComponentReportController.phpindex cda498cd8b..417c946812 100644--- a/app/Http/Controllers/Reports/CustomComponentReportController.php+++ b/app/Http/Controllers/Reports/CustomComponentReportController.php@@ -42,7 +42,7 @@ class CustomComponentReportController extends Controller{$this->authorize('reports.view');- ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); // 12000 seconds = 200 minutes+ ini_set('max_execution_time', config('app.report_time_limit')); // 12000 seconds = 200 minutes$this->disableDebugbar();diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.phpindex 08ba459b73..cb6e584af8 100644--- a/app/Http/Controllers/ReportsController.php+++ b/app/Http/Controllers/ReportsController.php@@ -501,7 +501,7 @@ class ReportsController extends Controller*/public function postCustom(CustomAssetReportRequest $request): StreamedResponse{- ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); // 12000 seconds = 200 minutes+ ini_set('max_execution_time', config('app.report_time_limit')); // 12000 seconds = 200 minutes$this->authorize('reports.view');$this->disableDebugbar();diff --git a/app/Http/Middleware/SecurityHeaders.php b/app/Http/Middleware/SecurityHeaders.phpindex 767d7fc1aa..1d014ef78f 100644--- a/app/Http/Middleware/SecurityHeaders.php+++ b/app/Http/Middleware/SecurityHeaders.php@@ -88,7 +88,7 @@ class SecurityHeaders$csp_policy[] = "connect-src 'self'";$csp_policy[] = "object-src 'none'";$csp_policy[] = "font-src 'self' data:";- $csp_policy[] = "img-src 'self' data: ".config('app.url').' '.config('app.additional_csp_urls').' '.env('PUBLIC_AWS_URL').' https://secure.gravatar.com http://gravatar.com maps.google.com maps.gstatic.com *.googleapis.com';+ $csp_policy[] = "img-src 'self' data: ".config('app.url').' '.config('app.additional_csp_urls').' '.config('filesystems.disks.public_aws.url').' https://secure.gravatar.com http://gravatar.com maps.google.com maps.gstatic.com *.googleapis.com';if (config('filesystems.disks.public.driver') == 's3') {$csp_policy[] = "img-src 'self' data: ".config('filesystems.disks.public.url');diff --git a/app/Http/Requests/ItemImportRequest.php b/app/Http/Requests/ItemImportRequest.phpindex bd0e9c7417..08b7ea584e 100644--- a/app/Http/Requests/ItemImportRequest.php+++ b/app/Http/Requests/ItemImportRequest.php@@ -32,8 +32,8 @@ class ItemImportRequest extends FormRequestpublic function import(Import $import){- ini_set('max_execution_time', env('IMPORT_TIME_LIMIT', 600)); // 600 seconds = 10 minutes- ini_set('memory_limit', env('IMPORT_MEMORY_LIMIT', '500M'));+ ini_set('max_execution_time', config('importer.time_limit')); // 600 seconds = 10 minutes+ ini_set('memory_limit', config('importer.memory_limit'));$filename = config('app.private_uploads').'/imports/'.$import->file_path;$import->import_type = $this->input('import-type');diff --git a/app/Models/Ldap.php b/app/Models/Ldap.phpindex 2b901e5cf7..66eb552cde 100644--- a/app/Models/Ldap.php+++ b/app/Models/Ldap.php@@ -73,8 +73,8 @@ class Ldap extends Modelself::ignoreCertificates((bool) $ldap_server_cert_ignore);// If the user specifies where CA Certs are, make sure to use them- if (env('LDAPTLS_CACERT')) {- putenv('LDAPTLS_CACERT='.env('LDAPTLS_CACERT'));+ if (config('app.ldap_tls_cacert')) {+ putenv('LDAPTLS_CACERT='.config('app.ldap_tls_cacert'));}// You _were_ allowed to do this *after* the ldap_connect() in some versions of PHP, but it's not how they want// you to anymore, and it seems to not work at all in later PHP versions.diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.phpindex eff02cb574..dfda63d247 100644--- a/app/Providers/AppServiceProvider.php+++ b/app/Providers/AppServiceProvider.php@@ -62,12 +62,11 @@ class AppServiceProvider extends ServiceProvider** We'll force the https scheme if the APP_URL starts with https://, or if APP_FORCE_TLS is set to true.*/- if ((strpos(env('APP_URL'), 'https://') === 0) || (env('APP_FORCE_TLS'))) {+ if ((str_starts_with(config('app.url'), 'https://')) || config('app.force_tls')) {$url->forceScheme('https');}- // TODO - isn't it somehow 'gauche' to check the environment directly; shouldn't we be using config() somehow?- if (! env('APP_ALLOW_INSECURE_HOSTS')) { // unless you set APP_ALLOW_INSECURE_HOSTS, you should PROHIBIT forging domain parts of URL via Host: headers+ if (! config('app.allow_insecure_hosts')) { // unless you set APP_ALLOW_INSECURE_HOSTS, you should PROHIBIT forging domain parts of URL via Host: headers$url_parts = parse_url(config('app.url'));if ($url_parts && array_key_exists('scheme', $url_parts) && array_key_exists('host', $url_parts)) { // check for the *required* parts of a bare-minimum URLURL::forceRootUrl(config('app.url'));diff --git a/config/app.php b/config/app.phpindex 7f86672f9c..cf6a6a914e 100755--- a/config/app.php+++ b/config/app.php@@ -626,4 +626,37 @@ return ['report_time_limit' => env('REPORT_TIME_LIMIT', 12000),+ /*+ |--------------------------------------------------------------------------+ | Force TLS / Allow Insecure Hosts+ |--------------------------------------------------------------------------+ | force_tls: forces the URL generator to emit https:// links regardless+ | of the incoming request scheme. Snipe-IT already forces https when+ | APP_URL starts with https, this flag covers reverse-proxy setups where+ | APP_URL is http but is actually TLS. allow_insecure_hosts skips+ | the URL::forceRootUrl() lockdown that otherwise rejects requests whose+ | Host header doesn't match APP_URL.+ */++ 'force_tls' => env('APP_FORCE_TLS', false),++ 'allow_insecure_hosts' => env('APP_ALLOW_INSECURE_HOSTS', false),++ /*+ |--------------------------------------------------------------------------+ | LDAP Execution Limits+ |--------------------------------------------------------------------------+ | Seconds and memory ceiling passed to ini_set() at the top of the+ | LDAP sync command so a large directory sync doesn't get killed by+ | PHP's shorter defaults. ldap_tls_cacert points at a custom CA+ | bundle to trust when running LDAPS against a self-signed or+ | private-CA-signed directory.+ */++ 'ldap_time_limit' => env('LDAP_TIME_LIM', 600),++ 'ldap_memory_limit' => env('LDAP_MEM_LIM', '500M'),++ 'ldap_tls_cacert' => env('LDAPTLS_CACERT'),+];diff --git a/config/backup.php b/config/backup.phpindex 3622638f2b..17fb4275b7 100644--- a/config/backup.php+++ b/config/backup.php@@ -253,4 +253,15 @@ return ['sanitize_by_default' => env('DB_SANITIZE_BY_DEFAULT', false),+ /*+ |--------------------------------------------------------------------------+ | Backup execution time limit+ |--------------------------------------------------------------------------+ | Seconds passed to ini_set('max_execution_time') at the top of the+ | snipeit:backup console command so a large-database dump doesn't get+ | killed by PHP's shorter default. Default 600 (10 minutes).+ */++ 'time_limit' => env('BACKUP_TIME_LIMIT', 600),+];diff --git a/config/importer.php b/config/importer.phpindex cbdb98d1d6..0fc1b46eaa 100644--- a/config/importer.php+++ b/config/importer.php@@ -26,4 +26,18 @@ return ['slice_size' => env('IMPORT_SLICE_SIZE', 500),+ /*+ |--------------------------------------------------------------------------+ | Importer execution knobs+ |--------------------------------------------------------------------------+ | Seconds and memory ceiling passed to ini_set() at the top of the+ | import processing path so a large CSV doesn't get killed by PHP's+ | shorter defaults. Applied both to the console ObjectImportCommand+ | and the API ItemImportRequest slice handler.+ */++ 'time_limit' => env('IMPORT_TIME_LIMIT', 600),++ 'memory_limit' => env('IMPORT_MEMORY_LIMIT', '500M'),+];diff --git a/phpstan-baseline.neon b/phpstan-baseline.neonindex c764d1f75f..744a624105 100644--- a/phpstan-baseline.neon+++ b/phpstan-baseline.neon@@ -336,12 +336,6 @@ parameters:count: 1path: app/Console/Commands/LdapSync.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 2- path: app/Console/Commands/LdapSync.php--message: '#^Property App\\Models\\User\:\:\$activated \(bool\) does not accept int\.$#'identifier: assign.propertyType@@ -414,12 +408,6 @@ parameters:count: 3path: app/Console/Commands/MergeUsersByUsername.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 1- path: app/Console/Commands/MoveUploadsToNewDisk.php--message: '#^Method Illuminate\\Filesystem\\FilesystemAdapter\:\:url\(\) invoked with 2 parameters, 1 required\.$#'identifier: arguments.count@@ -438,12 +426,6 @@ parameters:count: 1path: app/Console/Commands/NormalizeUserNames.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 2- path: app/Console/Commands/ObjectImportCommand.php--message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$display_name\.$#'identifier: property.notFound@@ -576,12 +558,6 @@ parameters:count: 1path: app/Console/Commands/SyncAssetLocations.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 1- path: app/Console/Commands/SystemBackup.php--message: '#^Method App\\Console\\Commands\\ToggleCustomfieldEncryption\:\:handle\(\) should return int but return statement is missing\.$#'identifier: return.missing@@ -3258,12 +3234,6 @@ parameters:count: 1path: app/Http/Controllers/Reports/CustomComponentReportController.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 1- path: app/Http/Controllers/Reports/CustomComponentReportController.php--message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Builder\:\:onlyTrashed\(\)\.$#'identifier: method.notFound@@ -3366,12 +3336,6 @@ parameters:count: 1path: app/Http/Controllers/ReportsController.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 1- path: app/Http/Controllers/ReportsController.php--message: '#^Method App\\Http\\Controllers\\ReportsController\:\:getAssetsCheckedOutRequiringAcceptance\(\) should return array but returns Illuminate\\Contracts\\View\\View\.$#'identifier: return.type@@ -3786,12 +3750,6 @@ parameters:count: 1path: app/Http/Middleware/PreventRequestsDuringMaintenance.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 1- path: app/Http/Middleware/SecurityHeaders.php--message: '#^PHPDoc type array of property App\\Http\\Middleware\\TrimStrings\:\:\$except is not covariant with PHPDoc type array\<int, string\> of overridden property Illuminate\\Foundation\\Http\\Middleware\\TrimStrings\:\:\$except\.$#'identifier: property.phpDocType@@ -3816,12 +3774,6 @@ parameters:count: 1path: app/Http/Requests/ItemImportRequest.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 2- path: app/Http/Requests/ItemImportRequest.php--message: '#^Call to static method flash\(\) on an unknown class Input\.$#'identifier: class.notFound@@ -7542,12 +7494,6 @@ parameters:count: 1path: app/Models/Ldap.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 2- path: app/Models/Ldap.php--message: '#^Method App\\Models\\Ldap\:\:bindAdminToLdap\(\) should return bool but return statement is missing\.$#'identifier: return.missing@@ -9750,12 +9696,6 @@ parameters:count: 1path: app/Presenters/UserPresenter.php- -- message: '#^Called ''env'' outside of the config directory which returns null when the config is cached, use ''config''\.$#'- identifier: larastan.noEnvCallsOutsideOfConfig- count: 3- path: app/Providers/AppServiceProvider.php--message: '#^PHPDoc type array of property App\\Providers\\AuthServiceProvider\:\:\$policies is not covariant with PHPDoc type array\<class\-string, class\-string\> of overridden property Illuminate\\Foundation\\Support\\Providers\\AuthServiceProvider\:\:\$policies\.$#'identifier: property.phpDocType