mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Merge pull request #11408 from uberbrady/add_filter_option_to_ldap_sync
Add a new `--filter` option to Artisan ldap-sync command
This commit is contained in:
commit
d8d12d4590
|
@ -17,7 +17,7 @@ class LdapSync extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @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.
|
* The console command description.
|
||||||
|
@ -80,7 +80,11 @@ class LdapSync extends Command
|
||||||
} else {
|
} else {
|
||||||
$search_base = null;
|
$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) {
|
} catch (\Exception $e) {
|
||||||
if ($this->option('json_summary')) {
|
if ($this->option('json_summary')) {
|
||||||
$json_summary = ['error' => true, 'error_message' => $e->getMessage(), '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. */
|
/* 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)
|
// 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_locations = Location::where('ldap_ou', '!=', '')->get()->toArray();
|
||||||
$ldap_ou_lengths = [];
|
$ldap_ou_lengths = [];
|
||||||
|
|
|
@ -275,9 +275,10 @@ class Ldap extends Model
|
||||||
* @since [v3.0]
|
* @since [v3.0]
|
||||||
* @param $base_dn
|
* @param $base_dn
|
||||||
* @param $count
|
* @param $count
|
||||||
|
* @param $filter
|
||||||
* @return array|bool
|
* @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();
|
$ldapconn = self::connectToLdap();
|
||||||
self::bindAdminToLdap($ldapconn);
|
self::bindAdminToLdap($ldapconn);
|
||||||
|
@ -285,7 +286,9 @@ class Ldap extends Model
|
||||||
if (is_null($base_dn)) {
|
if (is_null($base_dn)) {
|
||||||
$base_dn = Setting::getSettings()->ldap_basedn;
|
$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
|
// Set up LDAP pagination for very large databases
|
||||||
$page_size = 500;
|
$page_size = 500;
|
||||||
|
|
Loading…
Reference in a new issue