From 44e89f34e9adfbcc2f7bd6896485e68fac28f81d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 26 Apr 2022 10:44:47 +0300 Subject: [PATCH] Add file permissions to health check --- lib/data/models/health_check_model.dart | 8 +++- lib/data/models/health_check_model.g.dart | 45 ++++++++++++++++----- lib/data/web_client.dart | 2 +- lib/ui/app/dialogs/health_check_dialog.dart | 10 ++++- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/lib/data/models/health_check_model.dart b/lib/data/models/health_check_model.dart index fc3538bbd..c4f9504ef 100644 --- a/lib/data/models/health_check_model.dart +++ b/lib/data/models/health_check_model.dart @@ -37,6 +37,9 @@ abstract class HealthCheckResponse @BuiltValueField(wireName: 'open_basedir') bool get openBasedir; + @BuiltValueField(wireName: 'file_permissions') + String get filePermissions; + @BuiltValueField(wireName: 'exec') bool get execEnabled; @@ -55,8 +58,9 @@ abstract class HealthCheckResponse String get queue; // ignore: unused_element - static void _initializeBuilder(HealthCheckResponseBuilder builder) => - builder..trailingSlash = false; + static void _initializeBuilder(HealthCheckResponseBuilder builder) => builder + ..trailingSlash = false + ..filePermissions = ''; static Serializer get serializer => _$healthCheckResponseSerializer; diff --git a/lib/data/models/health_check_model.g.dart b/lib/data/models/health_check_model.g.dart index 286ff0d7c..5c8e3725a 100644 --- a/lib/data/models/health_check_model.g.dart +++ b/lib/data/models/health_check_model.g.dart @@ -47,6 +47,9 @@ class _$HealthCheckResponseSerializer 'open_basedir', serializers.serialize(object.openBasedir, specifiedType: const FullType(bool)), + 'file_permissions', + serializers.serialize(object.filePermissions, + specifiedType: const FullType(String)), 'exec', serializers.serialize(object.execEnabled, specifiedType: const FullType(bool)), @@ -111,6 +114,10 @@ class _$HealthCheckResponseSerializer result.openBasedir = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; break; + case 'file_permissions': + result.filePermissions = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; case 'exec': result.execEnabled = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -224,6 +231,8 @@ class _$HealthCheckResponse extends HealthCheckResponse { @override final bool openBasedir; @override + final String filePermissions; + @override final bool execEnabled; @override final String emailDriver; @@ -248,6 +257,7 @@ class _$HealthCheckResponse extends HealthCheckResponse { this.cacheEnabled, this.phantomEnabled, this.openBasedir, + this.filePermissions, this.execEnabled, this.emailDriver, this.pendingJobs, @@ -269,6 +279,8 @@ class _$HealthCheckResponse extends HealthCheckResponse { phantomEnabled, 'HealthCheckResponse', 'phantomEnabled'); BuiltValueNullFieldError.checkNotNull( openBasedir, 'HealthCheckResponse', 'openBasedir'); + BuiltValueNullFieldError.checkNotNull( + filePermissions, 'HealthCheckResponse', 'filePermissions'); BuiltValueNullFieldError.checkNotNull( execEnabled, 'HealthCheckResponse', 'execEnabled'); BuiltValueNullFieldError.checkNotNull( @@ -303,6 +315,7 @@ class _$HealthCheckResponse extends HealthCheckResponse { cacheEnabled == other.cacheEnabled && phantomEnabled == other.phantomEnabled && openBasedir == other.openBasedir && + filePermissions == other.filePermissions && execEnabled == other.execEnabled && emailDriver == other.emailDriver && pendingJobs == other.pendingJobs && @@ -326,14 +339,18 @@ class _$HealthCheckResponse extends HealthCheckResponse { $jc( $jc( $jc( - $jc(0, - systemHealth.hashCode), - phpVersion.hashCode), - envWritable.hashCode), - dbCheck.hashCode), - cacheEnabled.hashCode), - phantomEnabled.hashCode), - openBasedir.hashCode), + $jc( + $jc( + 0, + systemHealth + .hashCode), + phpVersion.hashCode), + envWritable.hashCode), + dbCheck.hashCode), + cacheEnabled.hashCode), + phantomEnabled.hashCode), + openBasedir.hashCode), + filePermissions.hashCode), execEnabled.hashCode), emailDriver.hashCode), pendingJobs.hashCode), @@ -352,6 +369,7 @@ class _$HealthCheckResponse extends HealthCheckResponse { ..add('cacheEnabled', cacheEnabled) ..add('phantomEnabled', phantomEnabled) ..add('openBasedir', openBasedir) + ..add('filePermissions', filePermissions) ..add('execEnabled', execEnabled) ..add('emailDriver', emailDriver) ..add('pendingJobs', pendingJobs) @@ -397,6 +415,11 @@ class HealthCheckResponseBuilder bool get openBasedir => _$this._openBasedir; set openBasedir(bool openBasedir) => _$this._openBasedir = openBasedir; + String _filePermissions; + String get filePermissions => _$this._filePermissions; + set filePermissions(String filePermissions) => + _$this._filePermissions = filePermissions; + bool _execEnabled; bool get execEnabled => _$this._execEnabled; set execEnabled(bool execEnabled) => _$this._execEnabled = execEnabled; @@ -436,6 +459,7 @@ class HealthCheckResponseBuilder _cacheEnabled = $v.cacheEnabled; _phantomEnabled = $v.phantomEnabled; _openBasedir = $v.openBasedir; + _filePermissions = $v.filePermissions; _execEnabled = $v.execEnabled; _emailDriver = $v.emailDriver; _pendingJobs = $v.pendingJobs; @@ -477,10 +501,11 @@ class HealthCheckResponseBuilder phantomEnabled, 'HealthCheckResponse', 'phantomEnabled'), openBasedir: BuiltValueNullFieldError.checkNotNull( openBasedir, 'HealthCheckResponse', 'openBasedir'), + filePermissions: BuiltValueNullFieldError.checkNotNull( + filePermissions, 'HealthCheckResponse', 'filePermissions'), execEnabled: BuiltValueNullFieldError.checkNotNull( execEnabled, 'HealthCheckResponse', 'execEnabled'), - emailDriver: BuiltValueNullFieldError.checkNotNull( - emailDriver, 'HealthCheckResponse', 'emailDriver'), + emailDriver: BuiltValueNullFieldError.checkNotNull(emailDriver, 'HealthCheckResponse', 'emailDriver'), pendingJobs: BuiltValueNullFieldError.checkNotNull(pendingJobs, 'HealthCheckResponse', 'pendingJobs'), pdfEngine: BuiltValueNullFieldError.checkNotNull(pdfEngine, 'HealthCheckResponse', 'pdfEngine'), trailingSlash: BuiltValueNullFieldError.checkNotNull(trailingSlash, 'HealthCheckResponse', 'trailingSlash'), diff --git a/lib/data/web_client.dart b/lib/data/web_client.dart index 034b4c448..649f769ee 100644 --- a/lib/data/web_client.dart +++ b/lib/data/web_client.dart @@ -32,7 +32,7 @@ class WebClient { url += '?'; } - if (!url.contains('per_page')) { + if (url.contains('/api/') && !url.contains('per_page')) { url += '&per_page=999999'; } diff --git a/lib/ui/app/dialogs/health_check_dialog.dart b/lib/ui/app/dialogs/health_check_dialog.dart index 3cc6fac30..60f8e3b01 100644 --- a/lib/ui/app/dialogs/health_check_dialog.dart +++ b/lib/ui/app/dialogs/health_check_dialog.dart @@ -43,7 +43,7 @@ class _HealthCheckDialogState extends State { final state = StoreProvider.of(context).state; try { - await webClient.get('${state.account.defaultUrl}/update', '', + await webClient.get('${state.account.defaultUrl}/update?secret=', '', rawResponse: true); } catch (e) { // do nothing @@ -145,6 +145,14 @@ class _HealthCheckDialogState extends State { isWarning: true, ), */ + if (_response.filePermissions != 'Ok') + _HealthListTile( + title: 'Invalid File Permissions', + isValid: false, + subtitle: _response.filePermissions, + url: + 'https://invoiceninja.github.io/docs/self-host-installation', + ), if (!state.account.isDocker) ...[ if (!_response.openBasedir) /*