expressolivretools / app / Commons / Ldap.php @ ab2f5151
Histórico | Ver | Anotar | Baixar (1,8 KB)
1 | 68c328a2 | Alexandre Correia | <?php
|
---|---|---|---|
2 | |||
3 | namespace App\Commons; |
||
4 | |||
5 | use LdapRecord\Connection; |
||
6 | use Illuminate\Support\Facades\DB; |
||
7 | |||
8 | class Ldap |
||
9 | { |
||
10 | private $conn; |
||
11 | private $ldapBaseDn; |
||
12 | |||
13 | public function __construct() |
||
14 | { |
||
15 | $this->conn = ""; |
||
16 | |||
17 | $configEAdmin = DB::connection('pgsql-expresso')->table('phpgw_emailadmin') |
||
18 | ->where('description', env('KEY_EMAILADMIN_SOGO') ) |
||
19 | ->first(); |
||
20 | |||
21 | // Base DN
|
||
22 | $this->ldapBaseDn = $configEAdmin->smtpldapbasedn; |
||
23 | |||
24 | $this->conn = new Connection([ |
||
25 | 'hosts' => [ $configEAdmin->smtpldapserver ], |
||
26 | 'base_dn' => $configEAdmin->smtpldapbasedn, |
||
27 | 'username' => $configEAdmin->smtpldapadmindn, |
||
28 | 'password' => $configEAdmin->smtpldapadminpw, |
||
29 | ]); |
||
30 | |||
31 | } |
||
32 | |||
33 | public function getUidNumber( string $user ) |
||
34 | { |
||
35 | $query = $this->conn->query() |
||
36 | ->select('uidnumber')
|
||
37 | ->where('uid','=', $user) |
||
38 | ->get(); |
||
39 | |||
40 | return $query[0]['uidnumber'][0] ?? false ; |
||
41 | } |
||
42 | |||
43 | public function getUid( string $user ) |
||
44 | { |
||
45 | $query = $this->conn->query() |
||
46 | ->select('uid')
|
||
47 | ->where('uidnumber','=', $user) |
||
48 | ->get(); |
||
49 | |||
50 | return $query[0]['uid'][0] ?? false ; |
||
51 | } |
||
52 | |||
53 | public function getUsersOu( string $organization ) |
||
54 | { |
||
55 | $baseDn = "ou=".$organization.",".$this->ldapBaseDn; |
||
56 | |||
57 | $query = $this->conn->query() |
||
58 | ->setDn( $baseDn )
|
||
59 | ->select('cn', 'uid', 'uidnumber') |
||
60 | ->where([ |
||
61 | ['phpgwaccounttype', '=', 'u'], |
||
62 | ['phpgwaccountstatus', '=', 'A'] |
||
63 | ])->get(); |
||
64 | |||
65 | return $query; |
||
66 | } |
||
67 | } |