From ba25972b492605cc04684dab6054602edf4645b3 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 22 Jul 2016 15:09:49 -0700 Subject: [PATCH] Add LDAP port number option --- app/Http/Controllers/SettingsController.php | 1 + app/Models/Ldap.php | 6 ++-- ...07_22_143045_add_port_to_ldap_settings.php | 31 +++++++++++++++++++ resources/lang/en/admin/settings/general.php | 2 ++ resources/views/settings/edit.blade.php | 21 +++++++++++++ resources/views/settings/index.blade.php | 3 +- 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2016_07_22_143045_add_port_to_ldap_settings.php diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 2384a7ea4e..70f3846a24 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -400,6 +400,7 @@ class SettingsController extends Controller $setting->ldap_server = e(Input::get('ldap_server')); $setting->ldap_server_cert_ignore = e(Input::get('ldap_server_cert_ignore', false)); $setting->ldap_uname = e(Input::get('ldap_uname')); + $setting->ldap_port = e(Input::get('ldap_port')); if (Input::has('ldap_pword')) { $setting->ldap_pword = Crypt::encrypt(Input::get('ldap_pword')); } diff --git a/app/Models/Ldap.php b/app/Models/Ldap.php index f9f2e3f2da..b36655feda 100644 --- a/app/Models/Ldap.php +++ b/app/Models/Ldap.php @@ -24,6 +24,7 @@ class Ldap extends Model { $ldap_host = Setting::getSettings()->ldap_server; + $ldap_port = Setting::getSettings()->ldap_port; $ldap_version = Setting::getSettings()->ldap_version; $ldap_server_cert_ignore = Setting::getSettings()->ldap_server_cert_ignore; @@ -34,11 +35,10 @@ class Ldap extends Model putenv('LDAPTLS_REQCERT=never'); } - // Connecting to LDAP - $connection = @ldap_connect($ldap_host) or die("Could not connect to {$ldap_host}"); + $connection = @ldap_connect($ldap_host,$ldap_port); if (!$connection) { - throw new Exception('Could not connect to LDAP server at '.$ldap_host.': '.ldap_error($connection)); + throw new Exception('Could not connect to LDAP server at '.$ldap_host.' on port '.$ldap_port.'. Please check your LDAP server name and port number in your settings.'); } // Needed for AD diff --git a/database/migrations/2016_07_22_143045_add_port_to_ldap_settings.php b/database/migrations/2016_07_22_143045_add_port_to_ldap_settings.php new file mode 100644 index 0000000000..b0dd1a601c --- /dev/null +++ b/database/migrations/2016_07_22_143045_add_port_to_ldap_settings.php @@ -0,0 +1,31 @@ +string('ldap_port', 5)->default('389'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function ($table) { + $table->dropColumn('ldap_port'); + }); + } +} diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index c22fddcbfb..b7002c951d 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -47,6 +47,8 @@ return array( 'ldap_server_cert_help' => 'Select this checkbox if you are using a self signed SSL cert and would like to accept an invalid SSL certificate.', 'ldap_uname' => 'LDAP Bind Username', 'ldap_pword' => 'LDAP Bind Password', + 'ldap_port' => 'LDAP Port', + 'ldap_port_help' => 'This is usually 389 for ldap, 636 for ldaps.', 'ldap_basedn' => 'Base Bind DN', 'ldap_filter' => 'LDAP Filter', 'ldap_username_field' => 'Username Field', diff --git a/resources/views/settings/edit.blade.php b/resources/views/settings/edit.blade.php index f4c7ef3dfa..7ab69232d8 100755 --- a/resources/views/settings/edit.blade.php +++ b/resources/views/settings/edit.blade.php @@ -726,6 +726,27 @@ {!! $errors->first('ldap_server', ':message') !!} + + +
+
+ {{ Form::label('ldap_port', trans('admin/settings/general.ldap_port')) }} +
+
+ @if (config('app.lock_passwords')===true) + {{ Form::text('ldap_port', Input::old('ldap_port', $setting->ldap_port), array('class' => 'form-control', 'disabled'=>'disabled','placeholder' => '389')) }} + @else + {{ Form::text('ldap_port', Input::old('ldap_port', $setting->ldap_port), array('class' => 'form-control','placeholder' => '389')) }} + @endif +
+
+ +

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

+ {!! $errors->first('ldap_port', ':message') !!} +
+
+ +
{{ Form::label('ldap_server_cert_ignore', trans('admin/settings/general.ldap_server_cert')) }} diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php index 6a98fe005c..b1adc0f812 100755 --- a/resources/views/settings/index.blade.php +++ b/resources/views/settings/index.blade.php @@ -150,7 +150,8 @@ {{ trans('admin/settings/general.ldap_integration') }} @if ($setting->ldap_enabled == 1) - {{ trans('general.yes') }} + + {{ $setting->ldap_server }}:{{ $setting->ldap_port }} @if ($setting->is_ad == '1') (Active Directory) @endif