Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2022-06-28 11:41:56 -07:00
commit 14c6879f06
2 changed files with 12 additions and 5 deletions

View file

@ -17,7 +17,7 @@ class LdapSync extends Command
*
* @var string
*/
protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=} {--base_dn=} {--summary} {--json_summary}';
protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=} {--base_dn=} {--filter=} {--summary} {--json_summary}';
/**
* The console command description.
@ -80,7 +80,11 @@ class LdapSync extends Command
} else {
$search_base = null;
}
$results = Ldap::findLdapUsers($search_base);
if ($this->option('filter') != '') {
$results = Ldap::findLdapUsers($search_base, -1, $this->option('filter'));
} else {
$results = Ldap::findLdapUsers($search_base);
}
} catch (\Exception $e) {
if ($this->option('json_summary')) {
$json_summary = ['error' => true, 'error_message' => $e->getMessage(), 'summary' => []];
@ -109,7 +113,7 @@ class LdapSync extends Command
}
/* Process locations with explicitly defined OUs, if doing a full import. */
if ($this->option('base_dn') == '') {
if ($this->option('base_dn') == '' && $this->option('filter') == '') {
// Retrieve locations with a mapped OU, and sort them from the shallowest to deepest OU (see #3993)
$ldap_ou_locations = Location::where('ldap_ou', '!=', '')->get()->toArray();
$ldap_ou_lengths = [];

View file

@ -275,9 +275,10 @@ class Ldap extends Model
* @since [v3.0]
* @param $base_dn
* @param $count
* @param $filter
* @return array|bool
*/
public static function findLdapUsers($base_dn = null, $count = -1)
public static function findLdapUsers($base_dn = null, $count = -1, $filter = null)
{
$ldapconn = self::connectToLdap();
self::bindAdminToLdap($ldapconn);
@ -285,7 +286,9 @@ class Ldap extends Model
if (is_null($base_dn)) {
$base_dn = Setting::getSettings()->ldap_basedn;
}
$filter = Setting::getSettings()->ldap_filter;
if($filter === null) {
$filter = Setting::getSettings()->ldap_filter;
}
// Set up LDAP pagination for very large databases
$page_size = 500;