Skip to content

A free open source IT asset/license management system

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

Godfrey Martinez5ea759f615c4
diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php
index 2928f38186..0a67cbe0f2 100755
--- a/app/Console/Commands/LdapSync.php
+++ b/app/Console/Commands/LdapSync.php
@@ -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]) ) {
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index e2f15bca80..0c5cfd6b8a 100755
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -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');
}
diff --git a/app/Models/Ldap.php b/app/Models/Ldap.php
index d4310fa6c5..e0ece7bb10 100644
--- a/app/Models/Ldap.php
+++ b/app/Models/Ldap.php
@@ -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;
diff --git a/database/migrations/2021_03_18_184102_adds_several_ldap_fields.php b/database/migrations/2021_03_18_184102_adds_several_ldap_fields.php
new file mode 100644
index 0000000000..9480062c65
--- /dev/null
+++ b/database/migrations/2021_03_18_184102_adds_several_ldap_fields.php
@@ -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()
+ {
+ //
+ }
+}
diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php
index 37a2d93e7d..84b519f13a 100644
--- a/resources/lang/en/admin/settings/general.php
+++ b/resources/lang/en/admin/settings/general.php
@@ -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',
diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php
index 1dd684ca31..f360005b04 100644
--- a/resources/views/settings/ldap.blade.php
+++ b/resources/views/settings/ldap.blade.php
@@ -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 -->