From aa55fa6ff496d279ca271b4614a5f778e73ae808 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 18:16:34 +0100 Subject: [PATCH 01/25] Switch to form requests for settings Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 38 ++++++----------- app/Http/Requests/StoreLabelSettings.php | 41 +++++++++++++++++++ app/Http/Requests/StoreLdapSettings.php | 40 ++++++++++++++++++ .../Requests/StoreLocalizationSettings.php | 30 ++++++++++++++ .../Requests/StoreNotificationSettings.php | 36 ++++++++++++++++ app/Http/Requests/StoreSecuritySettings.php | 35 ++++++++++++++++ app/Models/Setting.php | 29 ------------- resources/views/settings/alerts.blade.php | 15 +++---- resources/views/settings/general.blade.php | 2 +- resources/views/settings/ldap.blade.php | 7 +++- resources/views/settings/security.blade.php | 5 ++- 11 files changed, 208 insertions(+), 70 deletions(-) create mode 100644 app/Http/Requests/StoreLabelSettings.php create mode 100644 app/Http/Requests/StoreLdapSettings.php create mode 100644 app/Http/Requests/StoreLocalizationSettings.php create mode 100644 app/Http/Requests/StoreNotificationSettings.php create mode 100644 app/Http/Requests/StoreSecuritySettings.php diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index b9026aaece..dda951377d 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -7,6 +7,11 @@ use App\Helpers\StorageHelper; use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\SettingsSamlRequest; use App\Http\Requests\SetupUserRequest; +use App\Http\Requests\StoreLdapSettings; +use App\Http\Requests\StoreLocalizationSettings; +use App\Http\Requests\StoreNotificationSettings; +use App\Http\Requests\StoreLabelSettings; +use App\Http\Requests\StoreSecuritySettings; use App\Models\CustomField; use App\Models\Group; use App\Models\Setting; @@ -486,7 +491,7 @@ class SettingsController extends Controller * * @since [v1.0] */ - public function postSecurity(Request $request) : RedirectResponse + public function postSecurity(StoreSecuritySettings $request) : RedirectResponse { $this->validate($request, [ 'pwd_secure_complexity' => 'array', @@ -556,7 +561,7 @@ class SettingsController extends Controller * * @since [v1.0] */ - public function postLocalization(Request $request) : RedirectResponse + public function postLocalization(StoreLocalizationSettings $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -599,7 +604,7 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * @since [v1.0] */ - public function postAlerts(Request $request) : RedirectResponse + public function postAlerts(StoreNotificationSettings $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -780,7 +785,7 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * @since [v4.0] */ - public function postLabels(Request $request) : RedirectResponse + public function postLabels(StoreLabelSettings $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); @@ -855,30 +860,11 @@ class SettingsController extends Controller * * @since [v4.0] */ - public function getLdapSettings() : View + public function getLdapSettings(StoreLdapSettings $request) : View { $setting = Setting::getSettings(); $groups = Group::pluck('name', 'id'); - - - /** - * This validator is only temporary (famous last words.) - @snipe - */ - $messages = [ - 'ldap_username_field.not_in' => 'sAMAccountName (mixed case) will likely not work. You should use samaccountname (lowercase) instead. ', - 'ldap_auth_filter_query.not_in' => 'uid=samaccountname is probably not a valid auth filter. You probably want uid= ', - 'ldap_filter.regex' => 'This value should probably not be wrapped in parentheses.', - ]; - - $validator = Validator::make($setting->toArray(), [ - 'ldap_username_field' => 'not_in:sAMAccountName', - 'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1', - 'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1', - ], $messages); - - - - return view('settings.ldap', compact('setting', 'groups'))->withErrors($validator); + return view('settings.ldap', compact('setting', 'groups'))->withErrors($setting->getErrors()); } /** @@ -887,7 +873,7 @@ class SettingsController extends Controller * @author [A. Gianotto] [] * @since [v4.0] */ - public function postLdapSettings(Request $request) : RedirectResponse + public function postLdapSettings(StoreLdapSettings $request) : RedirectResponse { if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); diff --git a/app/Http/Requests/StoreLabelSettings.php b/app/Http/Requests/StoreLabelSettings.php new file mode 100644 index 0000000000..a203d2702d --- /dev/null +++ b/app/Http/Requests/StoreLabelSettings.php @@ -0,0 +1,41 @@ +|string> + */ + public function rules(): array + { + return [ + 'labels_per_page' => 'numeric', + 'labels_width' => 'numeric', + 'labels_height' => 'numeric', + 'labels_pmargin_left' => 'numeric|nullable', + 'labels_pmargin_right' => 'numeric|nullable', + 'labels_pmargin_top' => 'numeric|nullable', + 'labels_pmargin_bottom' => 'numeric|nullable', + 'labels_display_bgutter' => 'numeric|nullable', + 'labels_display_sgutter' => 'numeric|nullable', + 'labels_fontsize' => 'numeric|min:5', + 'labels_pagewidth' => 'numeric|nullable', + 'labels_pageheight' => 'numeric|nullable', + 'qr_text' => 'max:31|nullable', + ]; + } +} diff --git a/app/Http/Requests/StoreLdapSettings.php b/app/Http/Requests/StoreLdapSettings.php new file mode 100644 index 0000000000..50a066f134 --- /dev/null +++ b/app/Http/Requests/StoreLdapSettings.php @@ -0,0 +1,40 @@ +|string> + */ + public function rules(): array + { + return [ + 'ldap_username_field' => 'not_in:sAMAccountName', + 'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1', + 'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1', + ]; + } + + public function messages() : array + { + return [ + 'ldap_username_field.not_in' => 'sAMAccountName (mixed case) will likely not work. You should use samaccountname (lowercase) instead. ', + 'ldap_auth_filter_query.not_in' => 'uid=samaccountname is probably not a valid auth filter. You probably want uid= ', + 'ldap_filter.regex' => 'This value should probably not be wrapped in parentheses.', + ]; + } +} diff --git a/app/Http/Requests/StoreLocalizationSettings.php b/app/Http/Requests/StoreLocalizationSettings.php new file mode 100644 index 0000000000..4cea8826e8 --- /dev/null +++ b/app/Http/Requests/StoreLocalizationSettings.php @@ -0,0 +1,30 @@ +|string> + */ + public function rules(): array + { + return [ + 'default_currency' => 'required', + 'locale' => 'required', + ]; + } +} diff --git a/app/Http/Requests/StoreNotificationSettings.php b/app/Http/Requests/StoreNotificationSettings.php new file mode 100644 index 0000000000..37034732f8 --- /dev/null +++ b/app/Http/Requests/StoreNotificationSettings.php @@ -0,0 +1,36 @@ +|string> + */ + public function rules(): array + { + return [ + 'alert_email' => 'email_array|nullable', + 'admin_cc_email' => 'email|nullable', + 'alert_threshold' => 'numeric|nullable', + 'alert_interval' => 'numeric|nullable', + 'audit_warning_days' => 'numeric|nullable', + 'due_checkin_days' => 'numeric|nullable', + 'audit_interval' => 'numeric|nullable', + ]; + } +} diff --git a/app/Http/Requests/StoreSecuritySettings.php b/app/Http/Requests/StoreSecuritySettings.php new file mode 100644 index 0000000000..42a529aa57 --- /dev/null +++ b/app/Http/Requests/StoreSecuritySettings.php @@ -0,0 +1,35 @@ +|string> + */ + public function rules(): array + { + return [ + 'pwd_secure_min' => 'numeric|required|min:8', + 'custom_forgot_pass_url' => 'url|nullable', + 'privacy_policy_link' => 'nullable|url', + 'login_remote_user_enabled' => 'numeric|nullable', + 'login_common_disabled' => 'numeric|nullable', + 'login_remote_user_custom_logout_url' => 'string|nullable', + 'login_remote_user_header_name' => 'string|nullable', + ]; + } +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php index d775be81c5..6f585b95f8 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -51,36 +51,7 @@ class Setting extends Model */ protected $rules = [ 'brand' => 'required|min:1|numeric', - 'qr_text' => 'max:31|nullable', - 'alert_email' => 'email_array|nullable', - 'admin_cc_email' => 'email|nullable', - 'default_currency' => 'required', - 'locale' => 'required', - 'labels_per_page' => 'numeric', - 'labels_width' => 'numeric', - 'labels_height' => 'numeric', - 'labels_pmargin_left' => 'numeric|nullable', - 'labels_pmargin_right' => 'numeric|nullable', - 'labels_pmargin_top' => 'numeric|nullable', - 'labels_pmargin_bottom' => 'numeric|nullable', - 'labels_display_bgutter' => 'numeric|nullable', - 'labels_display_sgutter' => 'numeric|nullable', - 'labels_fontsize' => 'numeric|min:5', - 'labels_pagewidth' => 'numeric|nullable', - 'labels_pageheight' => 'numeric|nullable', - 'login_remote_user_enabled' => 'numeric|nullable', - 'login_common_disabled' => 'numeric|nullable', - 'login_remote_user_custom_logout_url' => 'string|nullable', - 'login_remote_user_header_name' => 'string|nullable', 'thumbnail_max_h' => 'numeric|max:500|min:25', - 'pwd_secure_min' => 'numeric|required|min:8', - 'alert_threshold' => 'numeric|nullable', - 'alert_interval' => 'numeric|nullable', - 'audit_warning_days' => 'numeric|nullable', - 'due_checkin_days' => 'numeric|nullable', - 'audit_interval' => 'numeric|nullable', - 'custom_forgot_pass_url' => 'url|nullable', - 'privacy_policy_link' => 'nullable|url', 'google_client_id' => 'nullable|ends_with:apps.googleusercontent.com' ]; diff --git a/resources/views/settings/alerts.blade.php b/resources/views/settings/alerts.blade.php index edbf1be839..8a76d5b315 100644 --- a/resources/views/settings/alerts.blade.php +++ b/resources/views/settings/alerts.blade.php @@ -21,9 +21,10 @@ - {{ Form::open(['method' => 'POST', 'files' => false, 'autocomplete' => 'off', 'class' => 'form-horizontal', 'role' => 'form' ]) }} +
+ - {{csrf_field()}} + {{ csrf_field() }}
@@ -68,12 +69,10 @@ {{ Form::label('alert_email', trans('admin/settings/general.alert_email')) }}
- {{ Form::text('alert_email', old('alert_email', $setting->alert_email), array('class' => 'form-control','placeholder' => 'admin@yourcompany.com')) }} + {!! $errors->first('alert_email', '
') !!} -

{{ trans('admin/settings/general.alert_email_help') }}

-
@@ -84,7 +83,7 @@ {{ Form::label('admin_cc_email', trans('admin/settings/general.admin_cc_email')) }}
- {{ Form::text('admin_cc_email', old('admin_cc_email', $setting->admin_cc_email), array('class' => 'form-control','placeholder' => 'admin@yourcompany.com')) }} + {!! $errors->first('admin_cc_email', '
') !!}

{{ trans('admin/settings/general.admin_cc_email_help') }}

@@ -154,10 +153,6 @@
{{ Form::text('due_checkin_days', old('due_checkin_days', $setting->due_checkin_days), array('class' => 'form-control','placeholder' => '14', 'maxlength'=>'3', 'style'=>'width: 60px;')) }} {{ trans('general.days') }} - - - -
{!! $errors->first('due_checkin_days', '') !!} diff --git a/resources/views/settings/general.blade.php b/resources/views/settings/general.blade.php index c800b26ac9..17c0a8ec81 100644 --- a/resources/views/settings/general.blade.php +++ b/resources/views/settings/general.blade.php @@ -18,7 +18,7 @@ - {{ Form::open(['method' => 'POST', 'files' => false, 'autocomplete' => 'off', 'class' => 'form-horizontal', 'role' => 'form' ]) }} + {{csrf_field()}} diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index 0c9faf8c2e..30f928ed7c 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -43,7 +43,7 @@ @endif - {{ Form::open(['method' => 'POST', 'files' => false, 'autocomplete' => 'off', 'class' => 'form-horizontal', 'role' => 'form']) }} + {{csrf_field()}} @@ -314,7 +314,10 @@ {{ Form::text('ldap_lname_field', old('ldap_lname_field', $setting->ldap_lname_field), ['class' => 'form-control','placeholder' => trans('general.example') .'sn', $setting->demoMode]) }} {!! $errors->first('ldap_lname_field', '') !!} @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
diff --git a/resources/views/settings/security.blade.php b/resources/views/settings/security.blade.php index 1b04f7d58a..a51c86fccb 100644 --- a/resources/views/settings/security.blade.php +++ b/resources/views/settings/security.blade.php @@ -16,9 +16,10 @@ - {{ Form::open(['method' => 'POST', 'files' => false, 'autocomplete' => 'off', 'class' => 'form-horizontal', 'role' => 'form' ]) }} + + - {{csrf_field()}} + {{ csrf_field() }}
From 41b94e7128c68af71f53e95ddd8bfbc242cde198 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 18:19:26 +0100 Subject: [PATCH 02/25] Fixed form input group Signed-off-by: snipe --- resources/views/settings/alerts.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/settings/alerts.blade.php b/resources/views/settings/alerts.blade.php index 8a76d5b315..9cf2312f78 100644 --- a/resources/views/settings/alerts.blade.php +++ b/resources/views/settings/alerts.blade.php @@ -21,7 +21,7 @@ - + {{ csrf_field() }} @@ -121,7 +121,7 @@ {{ Form::label('audit_interval', trans('admin/settings/general.audit_interval')) }}
- {{ Form::text('audit_interval', old('audit_interval', $setting->audit_interval), array('class' => 'form-control','placeholder' => '12', 'maxlength'=>'3', 'style'=>'width: 60px;')) }} + {{ Form::text('audit_interval', old('audit_interval', $setting->audit_interval), array('class' => 'form-control','placeholder' => '12', 'maxlength'=>'3')) }} {{ trans('general.months') }}
@@ -136,7 +136,7 @@ {{ Form::label('audit_warning_days', trans('admin/settings/general.audit_warning_days')) }}
- {{ Form::text('audit_warning_days', old('audit_warning_days', $setting->audit_warning_days), array('class' => 'form-control','placeholder' => '14', 'maxlength'=>'3', 'style'=>'width: 60px;')) }} + {{ Form::text('audit_warning_days', old('audit_warning_days', $setting->audit_warning_days), array('class' => 'form-control','placeholder' => '14', 'maxlength'=>'3')) }} {{ trans('general.days') }}
@@ -151,7 +151,7 @@ {{ Form::label('due_checkin_days', trans('admin/settings/general.due_checkin_days')) }}
- {{ Form::text('due_checkin_days', old('due_checkin_days', $setting->due_checkin_days), array('class' => 'form-control','placeholder' => '14', 'maxlength'=>'3', 'style'=>'width: 60px;')) }} + {{ Form::text('due_checkin_days', old('due_checkin_days', $setting->due_checkin_days), array('class' => 'form-control','placeholder' => '14', 'maxlength'=>'3')) }} {{ trans('general.days') }}
From 5cda7cce4830626f594de8cb4d4291c161916351 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 18:21:40 +0100 Subject: [PATCH 03/25] Only accept a positive number for thresholds Signed-off-by: snipe --- app/Http/Requests/StoreNotificationSettings.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/StoreNotificationSettings.php b/app/Http/Requests/StoreNotificationSettings.php index 37034732f8..b365b00c9d 100644 --- a/app/Http/Requests/StoreNotificationSettings.php +++ b/app/Http/Requests/StoreNotificationSettings.php @@ -26,11 +26,11 @@ class StoreNotificationSettings extends FormRequest return [ 'alert_email' => 'email_array|nullable', 'admin_cc_email' => 'email|nullable', - 'alert_threshold' => 'numeric|nullable', - 'alert_interval' => 'numeric|nullable', - 'audit_warning_days' => 'numeric|nullable', - 'due_checkin_days' => 'numeric|nullable', - 'audit_interval' => 'numeric|nullable', + 'alert_threshold' => 'numeric|nullable|gt:0', + 'alert_interval' => 'numeric|nullable|gt:0', + 'audit_warning_days' => 'numeric|nullable|gt:0', + 'due_checkin_days' => 'numeric|nullable|gt:0', + 'audit_interval' => 'numeric|nullable|gt:0', ]; } } From 4f957bcf7191ce17bbc33b958a5b60968fb3264f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 18:34:53 +0100 Subject: [PATCH 04/25] Required flag Signed-off-by: snipe --- app/Http/Requests/StoreLdapSettings.php | 11 ++++++----- resources/lang/en-US/validation.php | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/StoreLdapSettings.php b/app/Http/Requests/StoreLdapSettings.php index 50a066f134..48979b01a5 100644 --- a/app/Http/Requests/StoreLdapSettings.php +++ b/app/Http/Requests/StoreLdapSettings.php @@ -23,18 +23,19 @@ class StoreLdapSettings extends FormRequest public function rules(): array { return [ - 'ldap_username_field' => 'not_in:sAMAccountName', + 'ldap_username_field' => 'not_in:sAMAccountName|required_if:ldap_enabled,1', 'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1', 'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1', ]; } - public function messages() : array + public function messages(): array { return [ - 'ldap_username_field.not_in' => 'sAMAccountName (mixed case) will likely not work. You should use samaccountname (lowercase) instead. ', - 'ldap_auth_filter_query.not_in' => 'uid=samaccountname is probably not a valid auth filter. You probably want uid= ', - 'ldap_filter.regex' => 'This value should probably not be wrapped in parentheses.', + 'ldap_username_field' => trans('validation.custom.ldap_username_field.not_in'), + 'ldap_auth_filter_query' => trans('validation.custom.ldap_auth_filter_query.not_in'), + 'ldap_filter' => trans('validation.custom.ldap_filter.regex'), ]; } + } diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 6341707914..2b025d5db2 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -173,6 +173,7 @@ return [ 'ulid' => 'The :attribute field must be a valid ULID.', 'uuid' => 'The :attribute field must be a valid UUID.', + /* |-------------------------------------------------------------------------- | Custom Validation Language Lines @@ -206,6 +207,11 @@ return [ 'checkboxes' => ':attribute contains invalid options.', 'radio_buttons' => ':attribute is invalid.', 'invalid_value_in_field' => 'Invalid value included in this field', + + 'ldap_username_field.not_in' => 'sAMAccountName (mixed case) will likely not work. You should use samaccountname (lowercase) instead. ', + 'ldap_auth_filter_query.not_in' => 'uid=samaccountname is probably not a valid auth filter. You probably want uid= ', + 'ldap_filter.regex' => 'This value should probably not be wrapped in parentheses.', + ], /* |-------------------------------------------------------------------------- From 69c43c610c87babcf3919a8bac8ac73f6533330b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:30:00 +0100 Subject: [PATCH 05/25] Fixed typo Signed-off-by: snipe --- resources/lang/en-US/validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 2b025d5db2..52f1b43bf9 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -195,7 +195,7 @@ return [ 'custom_field_not_found_on_model' => 'This field seems to exist, but is not available on this Asset Model\'s fieldset.', // date_format validation with slightly less stupid messages. It duplicates a lot, but it gets the job done :( - // We use this because the default error message for date_format is reflects php Y-m-d, which non-PHP + // We use this because the default error message for date_format reflects php Y-m-d, which non-PHP // people won't know how to format. 'purchase_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD format', 'last_audit_date.date_format' => 'The :attribute must be a valid date in YYYY-MM-DD hh:mm:ss format', From d9be2b5a5e5cff6266c0ee54b5d2261885459f69 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:30:25 +0100 Subject: [PATCH 06/25] Trying to use the email_array translation Signed-off-by: snipe --- app/Providers/ValidationServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 1f3abca8a6..76ba1b629a 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -31,6 +31,7 @@ class ValidationServiceProvider extends ServiceProvider Validator::extend('email_array', function ($attribute, $value, $parameters, $validator) { $value = str_replace(' ', '', $value); $array = explode(',', $value); + $email_to_validate = []; foreach ($array as $email) { //loop over values $email_to_validate['alert_email'][] = $email; @@ -38,7 +39,7 @@ class ValidationServiceProvider extends ServiceProvider $rules = ['alert_email.*'=>'email']; $messages = [ - 'alert_email.*'=>trans('validation.email_array'), + 'alert_email.*' => trans('validation.custom.email_array'), ]; $validator = Validator::make($email_to_validate, $rules, $messages); From 3a77b83e9c71bf60f52e4900670047764b453e62 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:30:34 +0100 Subject: [PATCH 07/25] Added space Signed-off-by: snipe --- app/Http/Requests/StoreNotificationSettings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Requests/StoreNotificationSettings.php b/app/Http/Requests/StoreNotificationSettings.php index b365b00c9d..db7e8a0fe2 100644 --- a/app/Http/Requests/StoreNotificationSettings.php +++ b/app/Http/Requests/StoreNotificationSettings.php @@ -33,4 +33,5 @@ class StoreNotificationSettings extends FormRequest 'audit_interval' => 'numeric|nullable|gt:0', ]; } + } From 9c4191ae0ac4c4d338f77cb6bd3ea71c66f0844d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:30:42 +0100 Subject: [PATCH 08/25] Basic tests Signed-off-by: snipe --- tests/Feature/Settings/LabelSettingTest.php | 22 +++++++++++++ tests/Feature/Settings/LdapSettingsTests.php | 33 +++++++++++++++++++ .../Feature/Settings/SecuritySettingTest.php | 22 +++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 tests/Feature/Settings/LabelSettingTest.php create mode 100644 tests/Feature/Settings/LdapSettingsTests.php create mode 100644 tests/Feature/Settings/SecuritySettingTest.php diff --git a/tests/Feature/Settings/LabelSettingTest.php b/tests/Feature/Settings/LabelSettingTest.php new file mode 100644 index 0000000000..276e49866a --- /dev/null +++ b/tests/Feature/Settings/LabelSettingTest.php @@ -0,0 +1,22 @@ +actingAs(User::factory()->create()) + ->get(route('settings.labels.index')) + ->assertForbidden(); + } + +} diff --git a/tests/Feature/Settings/LdapSettingsTests.php b/tests/Feature/Settings/LdapSettingsTests.php new file mode 100644 index 0000000000..33adfc4b43 --- /dev/null +++ b/tests/Feature/Settings/LdapSettingsTests.php @@ -0,0 +1,33 @@ +actingAs(User::factory()->create()) + ->get(route('settings.ldap.index')) + ->assertForbidden(); + } + + public function testLdapSettingsCanBeSaved() + { + $response = $this->actingAs(User::factory()->superuser()->create()) + ->post(route('settings.alerts.save', ['ldap_enabled' => 1])) + ->assertStatus(302) + ->assertValid('alert_email') + ->assertRedirect(route('settings.index')) + ->assertSessionHasNoErrors(); + $this->followRedirects($response)->assertSee('alert-success'); + } + +} diff --git a/tests/Feature/Settings/SecuritySettingTest.php b/tests/Feature/Settings/SecuritySettingTest.php new file mode 100644 index 0000000000..d81df5599e --- /dev/null +++ b/tests/Feature/Settings/SecuritySettingTest.php @@ -0,0 +1,22 @@ +actingAs(User::factory()->create()) + ->get(route('settings.security.index')) + ->assertForbidden(); + } + +} From 2883e791938812a54ad2e4865cfcabd40bbb5589 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:30:55 +0100 Subject: [PATCH 09/25] Removed unecessary assets creation Signed-off-by: snipe --- tests/Feature/Settings/AlertsSettingTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Settings/AlertsSettingTest.php b/tests/Feature/Settings/AlertsSettingTest.php index 87e7c0286a..bb837981a8 100644 --- a/tests/Feature/Settings/AlertsSettingTest.php +++ b/tests/Feature/Settings/AlertsSettingTest.php @@ -14,10 +14,20 @@ class AlertsSettingTest extends TestCase { public function testPermissionRequiredToViewAlertSettings() { - $asset = Asset::factory()->create(); $this->actingAs(User::factory()->create()) ->get(route('settings.alerts.index')) ->assertForbidden(); } + public function testAdminCCEmailArrayCanBeSaved() + { + $response = $this->actingAs(User::factory()->superuser()->create()) + ->post(route('settings.alerts.save', ['alert_email' => 'me@example.com,you@example.com'])) + ->assertStatus(302) + ->assertValid('alert_email') + ->assertRedirect(route('settings.index')) + ->assertSessionHasNoErrors(); + $this->followRedirects($response)->assertSee('alert-success'); + } + } From a7f7e4938ffb99217f9cbbc70cdf08a4a9bbf9cd Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:31:56 +0100 Subject: [PATCH 10/25] Added form action Signed-off-by: snipe --- resources/views/settings/alerts.blade.php | 2 +- resources/views/settings/ldap.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/settings/alerts.blade.php b/resources/views/settings/alerts.blade.php index 9cf2312f78..ddca5c8158 100644 --- a/resources/views/settings/alerts.blade.php +++ b/resources/views/settings/alerts.blade.php @@ -21,7 +21,7 @@ - + {{ csrf_field() }} diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index 30f928ed7c..f26cf3a121 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -43,7 +43,7 @@ @endif - + {{csrf_field()}} From 185bc966e6c699e9ff4930a254c5c79405c0b836 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:46:47 +0100 Subject: [PATCH 11/25] Cleaned up use statements in tests Signed-off-by: snipe --- tests/Feature/Settings/AlertsSettingTest.php | 4 ---- tests/Feature/Settings/BrandingSettingsTest.php | 1 - tests/Feature/Settings/LabelSettingTest.php | 4 ---- tests/Feature/Settings/LdapSettingsTests.php | 6 +----- tests/Feature/Settings/SecuritySettingTest.php | 4 ---- 5 files changed, 1 insertion(+), 18 deletions(-) diff --git a/tests/Feature/Settings/AlertsSettingTest.php b/tests/Feature/Settings/AlertsSettingTest.php index bb837981a8..d79bd1cf21 100644 --- a/tests/Feature/Settings/AlertsSettingTest.php +++ b/tests/Feature/Settings/AlertsSettingTest.php @@ -2,12 +2,8 @@ namespace Tests\Feature\Settings; -use App\Models\Asset; use Tests\TestCase; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use App\Models\User; -use App\Models\Setting; class AlertsSettingTest extends TestCase diff --git a/tests/Feature/Settings/BrandingSettingsTest.php b/tests/Feature/Settings/BrandingSettingsTest.php index 03e2b013f6..d751a1ab47 100644 --- a/tests/Feature/Settings/BrandingSettingsTest.php +++ b/tests/Feature/Settings/BrandingSettingsTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Settings; -use App\Models\Asset; use Tests\TestCase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; diff --git a/tests/Feature/Settings/LabelSettingTest.php b/tests/Feature/Settings/LabelSettingTest.php index 276e49866a..e96c684a89 100644 --- a/tests/Feature/Settings/LabelSettingTest.php +++ b/tests/Feature/Settings/LabelSettingTest.php @@ -2,12 +2,8 @@ namespace Tests\Feature\Settings; -use App\Models\Asset; use Tests\TestCase; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use App\Models\User; -use App\Models\Setting; class LabelSettingTest extends TestCase diff --git a/tests/Feature/Settings/LdapSettingsTests.php b/tests/Feature/Settings/LdapSettingsTests.php index 33adfc4b43..2cda521da1 100644 --- a/tests/Feature/Settings/LdapSettingsTests.php +++ b/tests/Feature/Settings/LdapSettingsTests.php @@ -2,12 +2,8 @@ namespace Tests\Feature\Settings; -use App\Models\Asset; use Tests\TestCase; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use App\Models\User; -use App\Models\Setting; class LdapSettingsTests extends TestCase @@ -22,7 +18,7 @@ class LdapSettingsTests extends TestCase public function testLdapSettingsCanBeSaved() { $response = $this->actingAs(User::factory()->superuser()->create()) - ->post(route('settings.alerts.save', ['ldap_enabled' => 1])) + ->post(route('settings.ldap.save', ['ldap_enabled' => 1])) ->assertStatus(302) ->assertValid('alert_email') ->assertRedirect(route('settings.index')) diff --git a/tests/Feature/Settings/SecuritySettingTest.php b/tests/Feature/Settings/SecuritySettingTest.php index d81df5599e..6edeee673b 100644 --- a/tests/Feature/Settings/SecuritySettingTest.php +++ b/tests/Feature/Settings/SecuritySettingTest.php @@ -2,12 +2,8 @@ namespace Tests\Feature\Settings; -use App\Models\Asset; use Tests\TestCase; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; use App\Models\User; -use App\Models\Setting; class SecuritySettingTest extends TestCase From 2cb9ac26cd4b5b79fc9c813a76a8a0043ef2fa6c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 19:57:04 +0100 Subject: [PATCH 12/25] Renamed test Signed-off-by: snipe --- tests/Feature/Settings/LdapSettingsTest.php | 48 ++++++++++++++++++++ tests/Feature/Settings/LdapSettingsTests.php | 29 ------------ 2 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 tests/Feature/Settings/LdapSettingsTest.php delete mode 100644 tests/Feature/Settings/LdapSettingsTests.php diff --git a/tests/Feature/Settings/LdapSettingsTest.php b/tests/Feature/Settings/LdapSettingsTest.php new file mode 100644 index 0000000000..49189c33c9 --- /dev/null +++ b/tests/Feature/Settings/LdapSettingsTest.php @@ -0,0 +1,48 @@ +actingAs(User::factory()->create()) + ->get(route('settings.ldap.index')) + ->assertForbidden(); + } + + public function testLdapSettingsCanBeSaved() + { + $response = $this->actingAs(User::factory()->superuser()->create()) + ->post(route('settings.ldap.save', [ + 'ldap_enabled' => 1, + 'ldap_username_field' => 'samaccountName', + 'ldap_filter' => 'uid=', + ])) + ->assertStatus(302) + ->assertValid('ldap_enabled') + ->assertRedirect(route('settings.index')) + ->assertSessionHasNoErrors(); + $this->followRedirects($response)->assertSee('alert-success'); + } + + public function testLdapSettingsAreValidate() + { + $response = $this->actingAs(User::factory()->superuser()->create()) + ->from(route('settings.ldap.index')) + ->post(route('settings.ldap.save', [ + 'ldap_enabled' => 1, + 'ldap_username_field' => 'sAMAccountName', + 'ldap_filter' => '', + ])) + ->assertStatus(302) + ->assertRedirect(route('settings.ldap.index')) + ->assertSessionHasErrors(); + $this->followRedirects($response)->assertSee('alert-danger'); + } + +} diff --git a/tests/Feature/Settings/LdapSettingsTests.php b/tests/Feature/Settings/LdapSettingsTests.php deleted file mode 100644 index 2cda521da1..0000000000 --- a/tests/Feature/Settings/LdapSettingsTests.php +++ /dev/null @@ -1,29 +0,0 @@ -actingAs(User::factory()->create()) - ->get(route('settings.ldap.index')) - ->assertForbidden(); - } - - public function testLdapSettingsCanBeSaved() - { - $response = $this->actingAs(User::factory()->superuser()->create()) - ->post(route('settings.ldap.save', ['ldap_enabled' => 1])) - ->assertStatus(302) - ->assertValid('alert_email') - ->assertRedirect(route('settings.index')) - ->assertSessionHasNoErrors(); - $this->followRedirects($response)->assertSee('alert-success'); - } - -} From d9fbf330e5302355b4c59d14fec7311e2375fb24 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 20:33:15 +0100 Subject: [PATCH 13/25] Fixed translations Signed-off-by: snipe --- app/Http/Requests/StoreLdapSettings.php | 10 +--------- resources/lang/en-US/validation.php | 8 +++++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/Http/Requests/StoreLdapSettings.php b/app/Http/Requests/StoreLdapSettings.php index 48979b01a5..c707fc3bd4 100644 --- a/app/Http/Requests/StoreLdapSettings.php +++ b/app/Http/Requests/StoreLdapSettings.php @@ -22,6 +22,7 @@ class StoreLdapSettings extends FormRequest */ public function rules(): array { + \Log::error('boop'); return [ 'ldap_username_field' => 'not_in:sAMAccountName|required_if:ldap_enabled,1', 'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1', @@ -29,13 +30,4 @@ class StoreLdapSettings extends FormRequest ]; } - public function messages(): array - { - return [ - 'ldap_username_field' => trans('validation.custom.ldap_username_field.not_in'), - 'ldap_auth_filter_query' => trans('validation.custom.ldap_auth_filter_query.not_in'), - 'ldap_filter' => trans('validation.custom.ldap_filter.regex'), - ]; - } - } diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 52f1b43bf9..7d7840eb42 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -208,9 +208,11 @@ return [ 'radio_buttons' => ':attribute is invalid.', 'invalid_value_in_field' => 'Invalid value included in this field', - 'ldap_username_field.not_in' => 'sAMAccountName (mixed case) will likely not work. You should use samaccountname (lowercase) instead. ', - 'ldap_auth_filter_query.not_in' => 'uid=samaccountname is probably not a valid auth filter. You probably want uid= ', - 'ldap_filter.regex' => 'This value should probably not be wrapped in parentheses.', + 'ldap_username_field' => [ + 'not_in' => 'sAMAccountName (mixed case) will likely not work. You should use samaccountname (lowercase) instead.' + ], + 'ldap_auth_filter_query' => ['not_in' => 'uid=samaccountname is probably not a valid auth filter. You probably want uid= '], + 'ldap_filter' => ['regex' => 'This value should probably not be wrapped in parentheses.'], ], /* From ded79469c1cdfe7ce8421b872da9945cf9ff569d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 20:33:29 +0100 Subject: [PATCH 14/25] Remove unused controller method Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index dda951377d..3d3cabd486 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -278,20 +278,6 @@ class SettingsController extends Controller return view('settings/index', compact('settings')); } - /** - * Return the admin settings page. - * - * @author [A. Gianotto] [] - * - * @since [v1.0] - */ - public function getEdit() : View - - { - $setting = Setting::getSettings(); - - return view('settings/general', compact('setting')); - } /** * Return a form to allow a super admin to update settings. @@ -875,6 +861,7 @@ class SettingsController extends Controller */ public function postLdapSettings(StoreLdapSettings $request) : RedirectResponse { + \Log::error('Controller loaded'); if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } From 242fe33f973131463c5ebb297b4d05aa50974c3c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 20:33:42 +0100 Subject: [PATCH 15/25] Switch to regular HTML input Signed-off-by: snipe --- resources/views/settings/ldap.blade.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index f26cf3a121..ef6aad2566 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -342,7 +342,8 @@ {{ Form::label('ldap_auth_filter_query', trans('admin/settings/general.ldap_auth_filter_query')) }}
- {{ Form::text('ldap_auth_filter_query', old('ldap_auth_filter_query', $setting->ldap_auth_filter_query), ['class' => 'form-control','placeholder' => trans('general.example') .'uid=', $setting->demoMode]) }} + + demoMode }}> {!! $errors->first('ldap_auth_filter_query', '') !!} @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

From 707bdad192416c9bd6be3fd221913df282601d55 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 20:33:56 +0100 Subject: [PATCH 16/25] Updated test Signed-off-by: snipe --- tests/Feature/Settings/LdapSettingsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Settings/LdapSettingsTest.php b/tests/Feature/Settings/LdapSettingsTest.php index 49189c33c9..14eb727003 100644 --- a/tests/Feature/Settings/LdapSettingsTest.php +++ b/tests/Feature/Settings/LdapSettingsTest.php @@ -20,7 +20,7 @@ class LdapSettingsTest extends TestCase $response = $this->actingAs(User::factory()->superuser()->create()) ->post(route('settings.ldap.save', [ 'ldap_enabled' => 1, - 'ldap_username_field' => 'samaccountName', + 'ldap_username_field' => 'samaccountname', 'ldap_filter' => 'uid=', ])) ->assertStatus(302) @@ -30,14 +30,14 @@ class LdapSettingsTest extends TestCase $this->followRedirects($response)->assertSee('alert-success'); } - public function testLdapSettingsAreValidate() + public function testLdapSettingsAreValidatedCorrectly() { $response = $this->actingAs(User::factory()->superuser()->create()) ->from(route('settings.ldap.index')) ->post(route('settings.ldap.save', [ 'ldap_enabled' => 1, 'ldap_username_field' => 'sAMAccountName', - 'ldap_filter' => '', + 'ldap_filter' => 'uid=', ])) ->assertStatus(302) ->assertRedirect(route('settings.ldap.index')) From 3705b914399054e29d4964371ca638524a427bed Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 20:51:34 +0100 Subject: [PATCH 17/25] Added more validation Signed-off-by: snipe --- app/Http/Requests/StoreLdapSettings.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Requests/StoreLdapSettings.php b/app/Http/Requests/StoreLdapSettings.php index c707fc3bd4..d1fe3bb8fc 100644 --- a/app/Http/Requests/StoreLdapSettings.php +++ b/app/Http/Requests/StoreLdapSettings.php @@ -27,6 +27,11 @@ class StoreLdapSettings extends FormRequest 'ldap_username_field' => 'not_in:sAMAccountName|required_if:ldap_enabled,1', 'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1', 'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1', + 'ldap_server' => 'nullable|required_if:ldap_enabled,1', + 'ldap_uname' => 'nullable|required_if:ldap_enabled,1', + 'ldap_pword' => 'nullable|required_if:ldap_enabled,1', + 'ldap_basedn' => 'nullable|required_if:ldap_enabled,1', + 'ldap_fname_field' => 'nullable|required_if:ldap_enabled,1', ]; } From 710e738e8ef0d39f0ead49f8dd0604d201a11936 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 22:15:16 +0100 Subject: [PATCH 18/25] Fixed tests Signed-off-by: snipe --- tests/Feature/Settings/LdapSettingsTest.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Settings/LdapSettingsTest.php b/tests/Feature/Settings/LdapSettingsTest.php index 14eb727003..317ccb42df 100644 --- a/tests/Feature/Settings/LdapSettingsTest.php +++ b/tests/Feature/Settings/LdapSettingsTest.php @@ -22,10 +22,16 @@ class LdapSettingsTest extends TestCase 'ldap_enabled' => 1, 'ldap_username_field' => 'samaccountname', 'ldap_filter' => 'uid=', + 'ldap_auth_filter_query' => 'uid=', + 'ldap_uname' => 'SomeUserField', + 'ldap_pword' => 'MyAwesomePassword', + 'ldap_basedn' => 'uid=', + 'ldap_fname_field' => 'SomeFirstnameField', + 'ldap_server' => 'ldaps://ldap.example.com', ])) ->assertStatus(302) ->assertValid('ldap_enabled') - ->assertRedirect(route('settings.index')) + ->assertRedirect(route('settings.ldap.index')) ->assertSessionHasNoErrors(); $this->followRedirects($response)->assertSee('alert-success'); } @@ -37,11 +43,19 @@ class LdapSettingsTest extends TestCase ->post(route('settings.ldap.save', [ 'ldap_enabled' => 1, 'ldap_username_field' => 'sAMAccountName', - 'ldap_filter' => 'uid=', + 'ldap_filter' => '(uid=)', ])) ->assertStatus(302) ->assertRedirect(route('settings.ldap.index')) - ->assertSessionHasErrors(); + ->assertSessionHasErrors([ + 'ldap_username_field', + 'ldap_auth_filter_query', + 'ldap_uname', + 'ldap_pword', + 'ldap_basedn', + 'ldap_fname_field', + 'ldap_server', + ]); $this->followRedirects($response)->assertSee('alert-danger'); } From aa8048ac15fc931825083070099b0ceee550f281 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 22:15:25 +0100 Subject: [PATCH 19/25] Blade changes for ldap Signed-off-by: snipe --- resources/views/settings/ldap.blade.php | 176 ++++++++++++++++-------- 1 file changed, 118 insertions(+), 58 deletions(-) diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index ef6aad2566..794e9b7492 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') - Update LDAP/AD Settings + {{ trans('admin/settings/general.ldap_ad') }} @parent @stop @@ -76,7 +76,7 @@
@if (config('app.lock_passwords')===true) @@ -93,10 +93,12 @@
- {!! $errors->first('is_ad', '') !!} + @error('is_ad') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@@ -116,7 +118,9 @@

{{ trans('admin/settings/general.ldap_pw_sync_help') }}

- {!! $errors->first('ldap_pw_sync_help', '') !!} + @error('ldap_pw_sync') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -132,29 +136,15 @@
{{ Form::text('ad_domain', old('ad_domain', $setting->ad_domain), ['class' => 'form-control','placeholder' => trans('general.example') .'example.com', $setting->demoMode]) }}

{{ trans('admin/settings/general.ad_domain_help') }}

- {!! $errors->first('ad_domain', '') !!} + @error('ad_domain') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif
- {{-- NOTICE - this was a feature for AdLdap2-based LDAP syncing, and is already handled in 'classic' LDAP, so we now hide the checkbox (but haven't deleted the field) -
-
- {{ Form::label('ad_append_domain', trans('admin/settings/general.ad_append_domain_label')) }} -
-
- {{ Form::checkbox('ad_append_domain', '1', old('ad_append_domain', $setting->ad_append_domain),['class' => 'minimal '. $setting->demoMode, $setting->demoMode]) }} - {{ trans('admin/settings/general.ad_append_domain') }} -

{{ trans('admin/settings/general.ad_append_domain_help') }}

- {!! $errors->first('ad_append_domain', ':message') !!} - @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

- @endif -
-
--}} -
@@ -163,7 +153,9 @@
{{ Form::textarea('ldap_client_tls_key', old('ldap_client_tls_key', $setting->ldap_client_tls_key), ['class' => 'form-control','placeholder' => trans('general.example') .'-----BEGIN RSA PRIVATE KEY-----'."\r\n1234567890\r\n-----END RSA PRIVATE KEY----- ", $setting->demoMode]) }} - {!! $errors->first('ldap_client_tls_key', '') !!} + @error('ldap_client_tls_key') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -178,7 +170,9 @@
{{ Form::textarea('ldap_client_tls_cert', old('ldap_client_tls_cert', $setting->ldap_client_tls_cert), ['class' => 'form-control','placeholder' => trans('general.example') .'-----BEGIN CERTIFICATE-----'."\r\n1234567890\r\n-----END CERTIFICATE-----", $setting->demoMode]) }}

{{ trans('admin/settings/general.ldap_client_tls_cert_help') }}

- {!! $errors->first('ldap_client_tls_cert', '') !!} + @error('ldap_client_tls_cert') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -192,8 +186,10 @@
{{ Form::text('ldap_server', old('ldap_server', $setting->ldap_server), ['class' => 'form-control','placeholder' => trans('general.example') .'ldap://ldap.example.com', $setting->demoMode]) }} + @error('ldap_server') + + @enderror

{{ trans('admin/settings/general.ldap_server_help') }}

- {!! $errors->first('ldap_server', '') !!} @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -210,7 +206,9 @@ {{ Form::checkbox('ldap_tls', '1', old('ldap_tls', $setting->ldap_tls),['class' => 'minimal '. $setting->demoMode, $setting->demoMode]) }} {{ trans('admin/settings/general.ldap_tls_help') }} - {!! $errors->first('ldap_tls', '') !!} + @error('ldap_tls') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -224,10 +222,12 @@
- {!! $errors->first('ldap_server_cert_ignore', '') !!} + @error('ldap_server_cert_ignore') + + @enderror

{{ trans('admin/settings/general.ldap_server_cert_help') }}

@if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@@ -242,8 +242,9 @@
{{ Form::text('ldap_uname', old('ldap_uname', $setting->ldap_uname), ['class' => 'form-control','autocomplete' => 'off', 'placeholder' => trans('general.example') .'binduser@example.com', $setting->demoMode]) }} - {!! $errors->first('ldap_uname', '') !!} - @if (config('app.lock_passwords')===true) + @error('ldap_uname') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif
@@ -256,7 +257,9 @@
{{ Form::password('ldap_pword', ['class' => 'form-control', 'autocomplete' => 'off', 'onfocus' => "this.removeAttribute('readonly');", $setting->demoMode, ' readonly']) }} - {!! $errors->first('ldap_pword', '') !!} + @error('ldap_pword') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -270,7 +273,9 @@
{{ Form::text('ldap_basedn', old('ldap_basedn', $setting->ldap_basedn), ['class' => 'form-control', 'placeholder' => trans('general.example') .'cn=users/authorized,dc=example,dc=com', $setting->demoMode]) }} - {!! $errors->first('ldap_basedn', '') !!} + @error('ldap_basedn') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -283,8 +288,10 @@ {{ Form::label('ldap_filter', trans('admin/settings/general.ldap_filter')) }}
- {{ Form::text('ldap_filter', old('ldap_filter', $setting->ldap_filter), ['class' => 'form-control','placeholder' => trans('general.example') .'&(cn=*)', $setting->demoMode]) }} - {!! $errors->first('ldap_filter', '') !!} + + @error('ldap_filter') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -297,8 +304,10 @@ {{ Form::label('ldap_username_field', trans('admin/settings/general.ldap_username_field')) }}
- {{ Form::text('ldap_username_field', old('ldap_username_field', $setting->ldap_username_field), ['class' => 'form-control','placeholder' => trans('general.example') .'samaccountname', $setting->demoMode]) }} - {!! $errors->first('ldap_username_field', '') !!} + + @error('ldap_username_field') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -311,8 +320,10 @@ {{ Form::label('ldap_lname_field', trans('admin/settings/general.ldap_lname_field')) }}
- {{ Form::text('ldap_lname_field', old('ldap_lname_field', $setting->ldap_lname_field), ['class' => 'form-control','placeholder' => trans('general.example') .'sn', $setting->demoMode]) }} - {!! $errors->first('ldap_lname_field', '') !!} + + @error('ldap_lname_field') + + @enderror @if (config('app.lock_passwords')===true)

@@ -328,7 +339,7 @@ {{ Form::label('ldap_fname_field', trans('admin/settings/general.ldap_fname_field')) }}

- {{ Form::text('ldap_fname_field', old('ldap_fname_field', $setting->ldap_fname_field), ['class' => 'form-control', 'placeholder' => trans('general.example') .'givenname', $setting->demoMode]) }} + demoMode }}> {!! $errors->first('ldap_fname_field', '') !!} @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@@ -339,7 +350,7 @@
- {{ Form::label('ldap_auth_filter_query', trans('admin/settings/general.ldap_auth_filter_query')) }} +
@@ -368,7 +379,6 @@ @endforeach - {{ trans('admin/users/general.group_memberships_helpblock') }} @else
@@ -387,7 +397,7 @@
@endif @else -

No groups have been created yet. Visit Admin Settings > Permission Groups to add one.

+

{!! trans('admin/settings/general.no_groups') !!}

@endif
@@ -399,11 +409,12 @@ {{ Form::label('ldap_active_flag', trans('admin/settings/general.ldap_active_flag')) }}
- {{ Form::text('ldap_active_flag', old('ldap_active_flag', $setting->ldap_active_flag), ['class' => 'form-control', $setting->demoMode]) }} - + demoMode }}>

{!! trans('admin/settings/general.ldap_activated_flag_help') !!}

- {!! $errors->first('ldap_active_flag', '') !!} + @error('ldap_active_flag') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -417,7 +428,9 @@
{{ Form::text('ldap_emp_num', old('ldap_emp_num', $setting->ldap_emp_num), ['class' => 'form-control','placeholder' => trans('general.example') .'employeenumber/employeeid', $setting->demoMode]) }} - {!! $errors->first('ldap_emp_num', '') !!} + @error('ldap_emp_num') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -430,7 +443,9 @@
{{ Form::text('ldap_dept', old('ldap_dept', $setting->ldap_dept), ['class' => 'form-control','placeholder' => trans('general.example') .'department', $setting->demoMode]) }} - {!! $errors->first('ldap_dept', '') !!} + @error('ldap_dept') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -443,7 +458,9 @@
{{ Form::text('ldap_manager', old('ldap_manager', $setting->ldap_manager), ['class' => 'form-control','placeholder' => trans('general.example') .'manager', $setting->demoMode]) }} - {!! $errors->first('ldap_manager', '') !!} + @error('ldap_manager') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -457,7 +474,9 @@
{{ Form::text('ldap_email', old('ldap_email', $setting->ldap_email), ['class' => 'form-control','placeholder' => trans('general.example') .'mail', $setting->demoMode]) }} - {!! $errors->first('ldap_email', '') !!} + @error('ldap_email') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -471,7 +490,9 @@
{{ Form::text('ldap_phone', old('ldap_phone', $setting->ldap_phone_field), ['class' => 'form-control','placeholder' => trans('general.example') .'telephonenumber', $setting->demoMode]) }} - {!! $errors->first('ldap_phone', '') !!} + @error('ldap_phone') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -485,8 +506,9 @@
{{ Form::text('ldap_jobtitle', old('ldap_jobtitle', $setting->ldap_jobtitle), ['class' => 'form-control','placeholder' => trans('general.example') .'title', $setting->demoMode]) }} - {!! $errors->first('ldap_jobtitle', '') !!} - @if (config('app.lock_passwords')===true) + @error('ldap_jobtitle') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif
@@ -499,8 +521,9 @@
{{ Form::text('ldap_country', old('ldap_country', $setting->ldap_country), ['class' => 'form-control','placeholder' => trans('general.example') .'c', $setting->demoMode]) }} - {!! $errors->first('ldap_country', '') !!} - @if (config('app.lock_passwords')===true) + @error('ldap_country') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif
@@ -513,7 +536,9 @@
{{ Form::text('ldap_location', old('ldap_location', $setting->ldap_location), ['class' => 'form-control','placeholder' => trans('general.example') .'physicaldeliveryofficename', $setting->demoMode]) }}

{!! trans('admin/settings/general.ldap_location_help') !!}

- {!! $errors->first('ldap_location', '') !!} + @error('ldap_location') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -584,7 +609,9 @@
{{ Form::text('custom_forgot_pass_url', old('custom_forgot_pass_url', $setting->custom_forgot_pass_url), ['class' => 'form-control','placeholder' => trans('general.example') .'https://my.ldapserver-forgotpass.com', $setting->demoMode]) }}

{{ trans('admin/settings/general.custom_forgot_pass_url_help') }}

- {!! $errors->first('custom_forgot_pass_url', '') !!} + @error('custom_forgot_pass_url') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -624,9 +651,41 @@ $(function() { if( $('#is_ad').prop('checked') === false) { $('#ad_domain').prop('disabled', 'disabled'); - } else { - //$('#ldap_server').prop('disabled', 'disabled'); + $("#ad_domain").prop('required',false); } + + + // Mark fields as required if LDAP is enabled + if ($('#ldap_enabled').prop('checked') === false) { + $("#ldap_server").prop('required',false); + $("#ldap_auth_filter_query").prop('required',false); + $("#ldap_filter").prop('required',false); + $("#ldap_uname").prop('required',false); + $("#ldap_pword").prop('required',false); + $("#ldap_basedn").prop('required',false); + $("#ldap_fname_field").prop('required',false); + } + + $("#ldap_enabled").change(function() { + + if (this.checked) { + $("#ldap_server").prop('required',true); + $("#ldap_auth_filter_query").prop('required',true); + $("#ldap_filter").prop('required',true); + $("#ldap_uname").prop('required',true); + $("#ldap_pword").prop('required',true); + $("#ldap_basedn").prop('required',true); + } else { + $("#ldap_server").prop('required',false); + $("#ldap_auth_filter_query").prop('required',false); + $("#ldap_filter").prop('required',false); + $("#ldap_uname").prop('required',false); + $("#ldap_pword").prop('required',false); + $("#ldap_basedn").prop('required',false); + $("#ldap_fname_field").prop('required',false); + } + + }); }); $("#is_ad").change(function() { @@ -742,6 +801,7 @@ return body; } + $("#ldaptestlogin").click(function(){ $("#ldaptestloginrow").removeClass('text-success'); $("#ldaptestloginrow").removeClass('text-danger'); From 4361a108183b8b1ed473be8bfe8b7c27eda7a84c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 22:15:30 +0100 Subject: [PATCH 20/25] Added string Signed-off-by: snipe --- resources/lang/en-US/admin/settings/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php index 9a81886ae8..d656391edd 100644 --- a/resources/lang/en-US/admin/settings/general.php +++ b/resources/lang/en-US/admin/settings/general.php @@ -385,5 +385,6 @@ return [ 'restore_default_avatar_help' => '', 'due_checkin_days' => 'Due For Checkin Warning', 'due_checkin_days_help' => 'How many days before the expected checkin of an asset should it be listed in the "Due for checkin" page?', + 'no_groups' => 'No groups have been created yet. Visit Admin Settings > Permission Groups to add one.', ]; From 130e0c6242e2590cb44d60437d8b7c0f4e3c7f67 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 22:15:37 +0100 Subject: [PATCH 21/25] More validation Signed-off-by: snipe --- app/Http/Requests/StoreLdapSettings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/StoreLdapSettings.php b/app/Http/Requests/StoreLdapSettings.php index d1fe3bb8fc..65668bb4e3 100644 --- a/app/Http/Requests/StoreLdapSettings.php +++ b/app/Http/Requests/StoreLdapSettings.php @@ -27,11 +27,12 @@ class StoreLdapSettings extends FormRequest 'ldap_username_field' => 'not_in:sAMAccountName|required_if:ldap_enabled,1', 'ldap_auth_filter_query' => 'not_in:uid=samaccountname|required_if:ldap_enabled,1', 'ldap_filter' => 'nullable|regex:"^[^(]"|required_if:ldap_enabled,1', - 'ldap_server' => 'nullable|required_if:ldap_enabled,1', + 'ldap_server' => 'nullable|required_if:ldap_enabled,1|starts_with:ldap://,ldaps://', 'ldap_uname' => 'nullable|required_if:ldap_enabled,1', 'ldap_pword' => 'nullable|required_if:ldap_enabled,1', 'ldap_basedn' => 'nullable|required_if:ldap_enabled,1', 'ldap_fname_field' => 'nullable|required_if:ldap_enabled,1', + 'custom_forgot_pass_url' => 'nullable|url', ]; } From 3886da8941b01af7d4f7c63a141ea2bde49854c3 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 22:15:49 +0100 Subject: [PATCH 22/25] Remove form request from get LDAP method Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 3d3cabd486..aa773d9eea 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -846,11 +846,11 @@ class SettingsController extends Controller * * @since [v4.0] */ - public function getLdapSettings(StoreLdapSettings $request) : View + public function getLdapSettings() : View { $setting = Setting::getSettings(); $groups = Group::pluck('name', 'id'); - return view('settings.ldap', compact('setting', 'groups'))->withErrors($setting->getErrors()); + return view('settings.ldap', compact('setting', 'groups')); } /** @@ -861,7 +861,6 @@ class SettingsController extends Controller */ public function postLdapSettings(StoreLdapSettings $request) : RedirectResponse { - \Log::error('Controller loaded'); if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } From 90be2a4498a71d55080663875e29ebd67cfdc433 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 22:26:30 +0100 Subject: [PATCH 23/25] Use newer naming convention for errors Signed-off-by: snipe --- resources/views/settings/ldap.blade.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index 794e9b7492..1cfdad555c 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -340,7 +340,11 @@
demoMode }}> - {!! $errors->first('ldap_fname_field', '') !!} + @error('ldap_fname_field') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif @@ -355,7 +359,11 @@
demoMode }}> - {!! $errors->first('ldap_auth_filter_query', '') !!} + @error('ldap_auth_filter_query') + + @enderror @if (config('app.lock_passwords')===true)

{{ trans('general.feature_disabled') }}

@endif From d9432baf7ad497e6b7104990401a4074b1d6fe80 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 9 Oct 2024 23:51:20 +0100 Subject: [PATCH 24/25] Mlore ldap style improvements Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 10 +- resources/views/settings/ldap.blade.php | 389 ++++++++++++++++------ 2 files changed, 298 insertions(+), 101 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 163bcee284..81440136f3 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -189,14 +189,14 @@ dir="{{ Helper::determineLanguageDirection() }}"> action="{{ route('findbytag/hardware') }}" method="get">
- - + +
- diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index 1cfdad555c..86e5869132 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -42,7 +42,6 @@ @endif - {{csrf_field()}} @@ -62,7 +61,7 @@

{{ trans('admin/settings/general.ldap_ad') }} -

+
@@ -76,11 +75,15 @@
+ @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -93,15 +96,21 @@
@error('is_ad') - + + + {{ $message }} + @enderror @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -113,16 +122,23 @@

{{ trans('admin/settings/general.ldap_pw_sync_help') }}

@error('ldap_pw_sync') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -134,13 +150,20 @@ {{ Form::label('ad_domain', trans('admin/settings/general.ad_domain')) }}
- {{ Form::text('ad_domain', old('ad_domain', $setting->ad_domain), ['class' => 'form-control','placeholder' => trans('general.example') .'example.com', $setting->demoMode]) }} + {{ Form::text('ad_domain', old('ad_domain', $setting->ad_domain), ['class' => 'form-control','placeholder' => trans('general.example') .'example.com']) }}

{{ trans('admin/settings/general.ad_domain_help') }}

@error('ad_domain') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -151,13 +174,19 @@ {{ Form::label('ldap_client_tls_key', trans('admin/settings/general.ldap_client_tls_key')) }}
- {{ Form::textarea('ldap_client_tls_key', old('ldap_client_tls_key', $setting->ldap_client_tls_key), ['class' => 'form-control','placeholder' => trans('general.example') .'-----BEGIN RSA PRIVATE KEY-----'."\r\n1234567890\r\n-----END RSA PRIVATE KEY----- -", $setting->demoMode]) }} + {{ Form::textarea('ldap_client_tls_key', old('ldap_client_tls_key', $setting->ldap_client_tls_key), ['class' => 'form-control','placeholder' => trans('general.example') .'-----BEGIN RSA PRIVATE KEY-----'."\r\n1234567890\r\n-----END RSA PRIVATE KEY-----"]) }} @error('ldap_client_tls_key') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -168,13 +197,20 @@ {{ Form::label('ldap_client_tls_cert', trans('admin/settings/general.ldap_client_tls_cert')) }}
- {{ Form::textarea('ldap_client_tls_cert', old('ldap_client_tls_cert', $setting->ldap_client_tls_cert), ['class' => 'form-control','placeholder' => trans('general.example') .'-----BEGIN CERTIFICATE-----'."\r\n1234567890\r\n-----END CERTIFICATE-----", $setting->demoMode]) }} + {{ Form::textarea('ldap_client_tls_cert', old('ldap_client_tls_cert', $setting->ldap_client_tls_cert), ['class' => 'form-control','placeholder' => trans('general.example') .'-----BEGIN CERTIFICATE-----'."\r\n1234567890\r\n-----END CERTIFICATE-----"]) }}

{{ trans('admin/settings/general.ldap_client_tls_cert_help') }}

@error('ldap_client_tls_cert') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -185,13 +221,21 @@ {{ Form::label('ldap_server', trans('admin/settings/general.ldap_server')) }}
- {{ Form::text('ldap_server', old('ldap_server', $setting->ldap_server), ['class' => 'form-control','placeholder' => trans('general.example') .'ldap://ldap.example.com', $setting->demoMode]) }} + {{ Form::text('ldap_server', old('ldap_server', $setting->ldap_server), ['class' => 'form-control','placeholder' => trans('general.example') .'ldap://ldap.example.com']) }} @error('ldap_server') - + + + {{ $message }} + @enderror +

{{ trans('admin/settings/general.ldap_server_help') }}

+ @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -203,14 +247,21 @@
@error('ldap_tls') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -222,15 +273,24 @@
@error('ldap_server_cert_ignore') - + + + {{ $message }} + @enderror -

{{ trans('admin/settings/general.ldap_server_cert_help') }}

+ +

+ {{ trans('admin/settings/general.ldap_server_cert_help') }} +

@if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -241,11 +301,19 @@ {{ Form::label('ldap_uname', trans('admin/settings/general.ldap_uname')) }}
- {{ Form::text('ldap_uname', old('ldap_uname', $setting->ldap_uname), ['class' => 'form-control','autocomplete' => 'off', 'placeholder' => trans('general.example') .'binduser@example.com', $setting->demoMode]) }} + {{ Form::text('ldap_uname', old('ldap_uname', $setting->ldap_uname), ['class' => 'form-control','autocomplete' => 'off', 'placeholder' => trans('general.example') .'binduser@example.com']) }} @error('ldap_uname') - - @enderror @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+ + + {{ $message }} + + @enderror + + @if (config('app.lock_passwords')===true) +

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -256,12 +324,19 @@ {{ Form::label('ldap_pword', trans('admin/settings/general.ldap_pword')) }}
- {{ Form::password('ldap_pword', ['class' => 'form-control', 'autocomplete' => 'off', 'onfocus' => "this.removeAttribute('readonly');", $setting->demoMode, ' readonly']) }} + {{ Form::password('ldap_pword', ['class' => 'form-control', 'autocomplete' => 'off', 'onfocus' => "this.removeAttribute('readonly');", ' readonly']) }} @error('ldap_pword') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -272,12 +347,19 @@ {{ Form::label('ldap_basedn', trans('admin/settings/general.ldap_basedn')) }}
- {{ Form::text('ldap_basedn', old('ldap_basedn', $setting->ldap_basedn), ['class' => 'form-control', 'placeholder' => trans('general.example') .'cn=users/authorized,dc=example,dc=com', $setting->demoMode]) }} + {{ Form::text('ldap_basedn', old('ldap_basedn', $setting->ldap_basedn), ['class' => 'form-control', 'placeholder' => trans('general.example') .'cn=users/authorized,dc=example,dc=com']) }} @error('ldap_basedn') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -290,10 +372,17 @@
@error('ldap_filter') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -306,10 +395,17 @@
@error('ldap_username_field') - + + + {!! $message !!} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -322,11 +418,15 @@
@error('ldap_lname_field') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true)

- + {{ trans('general.feature_disabled') }}

@endif @@ -339,14 +439,19 @@ {{ Form::label('ldap_fname_field', trans('admin/settings/general.ldap_fname_field')) }}
- demoMode }}> + @error('ldap_fname_field') -
@@ -358,14 +463,19 @@
- demoMode }}> + @error('ldap_auth_filter_query') -
@@ -417,14 +527,21 @@ {{ Form::label('ldap_active_flag', trans('admin/settings/general.ldap_active_flag')) }}
- demoMode }}> +

{!! trans('admin/settings/general.ldap_activated_flag_help') !!}

@error('ldap_active_flag') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -435,12 +552,19 @@ {{ Form::label('ldap_emp_num', trans('admin/settings/general.ldap_emp_num')) }}
- {{ Form::text('ldap_emp_num', old('ldap_emp_num', $setting->ldap_emp_num), ['class' => 'form-control','placeholder' => trans('general.example') .'employeenumber/employeeid', $setting->demoMode]) }} + {{ Form::text('ldap_emp_num', old('ldap_emp_num', $setting->ldap_emp_num), ['class' => 'form-control','placeholder' => trans('general.example') .'employeenumber/employeeid']) }} @error('ldap_emp_num') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -450,12 +574,20 @@ {{ Form::label('ldap_dept', trans('admin/settings/general.ldap_dept')) }}
- {{ Form::text('ldap_dept', old('ldap_dept', $setting->ldap_dept), ['class' => 'form-control','placeholder' => trans('general.example') .'department', $setting->demoMode]) }} + {{ Form::text('ldap_dept', old('ldap_dept', $setting->ldap_dept), ['class' => 'form-control','placeholder' => trans('general.example') .'department']) }} + @error('ldap_dept') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -465,12 +597,19 @@ {{ Form::label('ldap_dept', trans('admin/settings/general.ldap_manager')) }}
- {{ Form::text('ldap_manager', old('ldap_manager', $setting->ldap_manager), ['class' => 'form-control','placeholder' => trans('general.example') .'manager', $setting->demoMode]) }} + {{ Form::text('ldap_manager', old('ldap_manager', $setting->ldap_manager), ['class' => 'form-control','placeholder' => trans('general.example') .'manager']) }} @error('ldap_manager') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -481,12 +620,19 @@ {{ Form::label('ldap_email', trans('admin/settings/general.ldap_email')) }}
- {{ Form::text('ldap_email', old('ldap_email', $setting->ldap_email), ['class' => 'form-control','placeholder' => trans('general.example') .'mail', $setting->demoMode]) }} + {{ Form::text('ldap_email', old('ldap_email', $setting->ldap_email), ['class' => 'form-control','placeholder' => trans('general.example') .'mail']) }} @error('ldap_email') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -497,12 +643,19 @@ {{ Form::label('ldap_phone', trans('admin/settings/general.ldap_phone')) }}
- {{ Form::text('ldap_phone', old('ldap_phone', $setting->ldap_phone_field), ['class' => 'form-control','placeholder' => trans('general.example') .'telephonenumber', $setting->demoMode]) }} + {{ Form::text('ldap_phone', old('ldap_phone', $setting->ldap_phone_field), ['class' => 'form-control','placeholder' => trans('general.example') .'telephonenumber']) }} @error('ldap_phone') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -513,11 +666,19 @@ {{ Form::label('ldap_jobtitle', trans('admin/settings/general.ldap_jobtitle')) }}
- {{ Form::text('ldap_jobtitle', old('ldap_jobtitle', $setting->ldap_jobtitle), ['class' => 'form-control','placeholder' => trans('general.example') .'title', $setting->demoMode]) }} + {{ Form::text('ldap_jobtitle', old('ldap_jobtitle', $setting->ldap_jobtitle), ['class' => 'form-control','placeholder' => trans('general.example') .'title']) }} @error('ldap_jobtitle') - - @enderror @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+ + + {{ $message }} + + @enderror + + @if (config('app.lock_passwords')===true) +

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -528,11 +689,19 @@ {{ Form::label('ldap_country', trans('admin/settings/general.ldap_country')) }}
- {{ Form::text('ldap_country', old('ldap_country', $setting->ldap_country), ['class' => 'form-control','placeholder' => trans('general.example') .'c', $setting->demoMode]) }} + {{ Form::text('ldap_country', old('ldap_country', $setting->ldap_country), ['class' => 'form-control','placeholder' => trans('general.example') .'c']) }} @error('ldap_country') - - @enderror @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+ + + {{ $message }} + + @enderror + + @if (config('app.lock_passwords')===true) +

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -542,13 +711,20 @@ {{ Form::label('ldap_location', trans('admin/settings/general.ldap_location')) }}
- {{ Form::text('ldap_location', old('ldap_location', $setting->ldap_location), ['class' => 'form-control','placeholder' => trans('general.example') .'physicaldeliveryofficename', $setting->demoMode]) }} + {{ Form::text('ldap_location', old('ldap_location', $setting->ldap_location), ['class' => 'form-control','placeholder' => trans('general.example') .'physicaldeliveryofficename']) }}

{!! trans('admin/settings/general.ldap_location_help') !!}

@error('ldap_location') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -560,7 +736,7 @@ {{ Form::label('test_ldap_sync', 'Test LDAP Sync') }}

@@ -569,7 +745,10 @@

{{ trans('admin/settings/general.ldap_login_sync_help') }}

@if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -615,13 +794,20 @@ {{ Form::label('custom_forgot_pass_url', trans('admin/settings/general.custom_forgot_pass_url')) }}
- {{ Form::text('custom_forgot_pass_url', old('custom_forgot_pass_url', $setting->custom_forgot_pass_url), ['class' => 'form-control','placeholder' => trans('general.example') .'https://my.ldapserver-forgotpass.com', $setting->demoMode]) }} + {{ Form::text('custom_forgot_pass_url', old('custom_forgot_pass_url', $setting->custom_forgot_pass_url), ['class' => 'form-control','placeholder' => trans('general.example') .'https://my.ldapserver-forgotpass.com']) }}

{{ trans('admin/settings/general.custom_forgot_pass_url_help') }}

@error('custom_forgot_pass_url') - + + + {{ $message }} + @enderror + @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

+

+ + {{ trans('general.feature_disabled') }} +

@endif
@@ -646,9 +832,10 @@ {{Form::close()}} -@stop +@endsection @push('js') + From b5b93fdd3a75bf72712b927b5c59c1e249c47f16 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Oct 2024 00:27:00 +0100 Subject: [PATCH 25/25] Make ldap username required Signed-off-by: snipe --- resources/views/settings/ldap.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php index 86e5869132..5b483f48a2 100644 --- a/resources/views/settings/ldap.blade.php +++ b/resources/views/settings/ldap.blade.php @@ -868,6 +868,7 @@ $("#ldap_server").prop('required',false); $("#ldap_auth_filter_query").prop('required',false); $("#ldap_filter").prop('required',false); + $("#ldap_username_field").prop('required',false); $("#ldap_uname").prop('required',false); $("#ldap_pword").prop('required',false); $("#ldap_basedn").prop('required',false); @@ -881,13 +882,14 @@ $("#ldap_auth_filter_query").prop('required',true); $("#ldap_filter").prop('required',true); $("#ldap_uname").prop('required',true); + $("#ldap_username_field").prop('required',true); $("#ldap_pword").prop('required',true); $("#ldap_basedn").prop('required',true); } else { $("#ldap_server").prop('required',false); $("#ldap_auth_filter_query").prop('required',false); $("#ldap_filter").prop('required',false); - $("#ldap_uname").prop('required',false); + $("#ldap_username_field").prop('required',false); $("#ldap_pword").prop('required',false); $("#ldap_basedn").prop('required',false); $("#ldap_fname_field").prop('required',false);