Fixed #7211, #9197, #7864, [ch15504] - Added additional LDAP fields to sync (#9318)

* LDAP and Active Directory has plenty of other [ch15504]

* removed department id from ldap sync

* removed department id from ldap sync

* Update 2021_03_18_184102_adds_several_ldap_fields.php
This commit is contained in:
Godfrey Martinez 2021-04-05 19:26:04 -07:00 committed by GitHub
parent eb0ae74ef8
commit 5ea759f615
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 93 additions and 2 deletions

View file

@ -51,6 +51,9 @@ class LdapSync extends Command
$ldap_result_active_flag = Setting::getSettings()->ldap_active_flag_field;
$ldap_result_emp_num = Setting::getSettings()->ldap_emp_num;
$ldap_result_email = Setting::getSettings()->ldap_email;
$ldap_result_phone = Setting::getSettings()->ldap_phone_field;
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
$ldap_result_country = Setting::getSettings()->ldap_country;
try {
$ldapconn = Ldap::connectToLdap();
@ -175,6 +178,9 @@ class LdapSync extends Command
$item["email"] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : "" ;
$item["ldap_location_override"] = isset($results[$i]["ldap_location_override"]) ? $results[$i]["ldap_location_override"]:"";
$item["location_id"] = isset($results[$i]["location_id"]) ? $results[$i]["location_id"]:"";
$item["telephone"] = isset($results[$i][$ldap_result_phone][0]) ? $results[$i][$ldap_result_phone][0] : "";
$item["jobtitle"] = isset($results[$i][$ldap_result_jobtitle][0]) ? $results[$i][$ldap_result_jobtitle][0] : "";
$item["country"] = isset($results[$i][$ldap_result_country][0]) ? $results[$i][$ldap_result_country][0] : "";
$user = User::where('username', $item["username"])->first();
if ($user) {
@ -193,6 +199,9 @@ class LdapSync extends Command
$user->username = $item["username"];
$user->email = $item["email"];
$user->employee_num = e($item["employee_number"]);
$user->phone = $item["telephone"];
$user->jobtitle = $item["jobtitle"];
$user->country = $item["country"];
// Sync activated state for Active Directory.
if ( array_key_exists('useraccountcontrol', $results[$i]) ) {

View file

@ -943,6 +943,9 @@ class SettingsController extends Controller
$setting->ldap_tls = $request->input('ldap_tls', '0');
$setting->ldap_pw_sync = $request->input('ldap_pw_sync', '0');
$setting->custom_forgot_pass_url = $request->input('custom_forgot_pass_url');
$setting->ldap_phone_field = $request->input('ldap_phone');
$setting->ldap_jobtitle = $request->input('ldap_jobtitle');
$setting->ldap_country = $request->input('ldap_country');
}

View file

@ -169,7 +169,9 @@ class Ldap extends Model
$ldap_result_last_name = Setting::getSettings()->ldap_lname_field;
$ldap_result_first_name = Setting::getSettings()->ldap_fname_field;
$ldap_result_email = Setting::getSettings()->ldap_email;
$ldap_result_phone = Setting::getSettings()->ldap_phone;
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
$ldap_result_country = Setting::getSettings()->ldap_country;
// Get LDAP user data
$item = array();
$item["username"] = isset($ldapatttibutes[$ldap_result_username][0]) ? $ldapatttibutes[$ldap_result_username][0] : "";
@ -177,7 +179,9 @@ class Ldap extends Model
$item["lastname"] = isset($ldapatttibutes[$ldap_result_last_name][0]) ? $ldapatttibutes[$ldap_result_last_name][0] : "";
$item["firstname"] = isset($ldapatttibutes[$ldap_result_first_name][0]) ? $ldapatttibutes[$ldap_result_first_name][0] : "";
$item["email"] = isset($ldapatttibutes[$ldap_result_email][0]) ? $ldapatttibutes[$ldap_result_email][0] : "" ;
$item["telephone"] = isset($ldapatttibutes[$ldap_result_phone][0]) ?$ldapatttibutes[$ldap_result_phone][0] : "";
$item["jobtitle"] = isset($ldapatttibutes[$ldap_result_jobtitle][0]) ? $ldapatttibutes[$ldap_result_jobtitle][0] : "";
$item["country"] = isset($ldapatttibutes[$ldap_result_country][0]) ? $ldapatttibutes[$ldap_result_country][0] : "";
return $item;

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddsSeveralLdapFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->string('ldap_phone_field')->after('ldap_email')->nullable();
$table->string('ldap_jobtitle')->after('ldap_phone_field')->nullable();
$table->string('ldap_country')->after('ldap_jobtitle')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View file

@ -74,6 +74,9 @@ return array(
'ldap_tls' => 'Use TLS',
'ldap_tls_help' => 'This should be checked only if you are running STARTTLS on your LDAP server. ',
'ldap_uname' => 'LDAP Bind Username',
'ldap_phone' => 'LDAP Telephone Number',
'ldap_jobtitle' => 'LDAP Job Title',
'ldap_country' => 'LDAP Country',
'ldap_pword' => 'LDAP Bind Password',
'ldap_basedn' => 'Base Bind DN',
'ldap_filter' => 'LDAP Filter',

View file

@ -355,7 +355,47 @@
</div>
</div>
<!-- LDAP Phone -->
<div class="form-group {{ $errors->has('ldap_phone') ? 'error' : '' }}">
<div class="col-md-3">
{{ Form::label('ldap_phone', trans('admin/settings/general.ldap_phone')) }}
</div>
<div class="col-md-9">
{{ Form::text('ldap_phone', Request::old('ldap_phone', $setting->ldap_phone_field), ['class' => 'form-control','placeholder' => 'telephonenumber', $setting->demoMode]) }}
{!! $errors->first('ldap_phone', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
@if (config('app.lock_passwords')===true)
<p class="text-warning"><i class="fa fa-lock" aria-hidden="true"></i> {{ trans('general.feature_disabled') }}</p>
@endif
</div>
</div>
<!-- LDAP Job title -->
<div class="form-group {{ $errors->has('ldap_jobtitle') ? 'error' : '' }}">
<div class="col-md-3">
{{ Form::label('ldap_jobtitle', trans('admin/settings/general.ldap_jobtitle')) }}
</div>
<div class="col-md-9">
{{ Form::text('ldap_jobtitle', Request::old('ldap_jobtitle', $setting->ldap_jobtitle), ['class' => 'form-control','placeholder' => 'title', $setting->demoMode]) }}
{!! $errors->first('ldap_jobtitle', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
@if (config('app.lock_passwords')===true)
<p class="text-warning"><i class="fa fa-lock" aria-hidden="true"></i> {{ trans('general.feature_disabled') }}</p>
@endif
</div>
</div>
<!-- LDAP Country -->
<div class="form-group {{ $errors->has('ldap_country') ? 'error' : '' }}">
<div class="col-md-3">
{{ Form::label('ldap_country', trans('admin/settings/general.ldap_country')) }}
</div>
<div class="col-md-9">
{{ Form::text('ldap_country', Request::old('ldap_country', $setting->ldap_country), ['class' => 'form-control','placeholder' => 'c', $setting->demoMode]) }}
{!! $errors->first('ldap_country', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
@if (config('app.lock_passwords')===true)
<p class="text-warning"><i class="fa fa-lock" aria-hidden="true"></i> {{ trans('general.feature_disabled') }}</p>
@endif
</div>
</div>
@if ($setting->ldap_enabled)
<!-- LDAP test -->