Skip to content
Snippets Groups Projects

update docs

Merged Hahn Axel (hahn) requested to merge update-docs into master
4 files
+ 94
47
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 26
44
@@ -14,7 +14,7 @@ As an example I create a hash named $aConfig and save it as "inc_config.php".
@@ -14,7 +14,7 @@ As an example I create a hash named $aConfig and save it as "inc_config.php".
return [
return [
...
...
'ldap' => [
'ldap-master' => [
'server' => 'ldaps://ldap.example.com',
'server' => 'ldaps://ldap.example.com',
'DnLdapUser' => 'cn=Lookup,ou=Service,dc=some,dc=example.com',
'DnLdapUser' => 'cn=Lookup,ou=Service,dc=some,dc=example.com',
'PwLdapUser' => 'PasswordOfLookupUser',
'PwLdapUser' => 'PasswordOfLookupUser',
@@ -31,34 +31,49 @@ return [
@@ -31,34 +31,49 @@ return [
];
];
```
```
## initialize connection
## Initialize connection
```php
```php
$aConfig = require_once('inc_config.php');
$aConfig = require_once('inc_config.php');
require_once '[APPROOT]/classes/ldap.class.php';
require_once '[APPROOT]/classes/ldap.class.php';
$oLdap=new imlldap($aConfig['ldap']);
$oLdap=new imlldap($aConfig['ldap-maser']);
```
```
## Methods
## Methods
 
### LDAP Connection
 
 
You can reconfigure the connetction data of a current ldap object:
 
 
* setConfig(array $aConfig = []): void<br>Set new connection values.
 
 
These methods are used internally - it is not a must to use them:
 
 
* connect(): void<br>Connect to host and port
 
* bind(string $sUser = '', string $sPw = ''): bool<br>with bind a user and password to access ldap data
 
* unbind(): void
 
### Object handling
### Object handling
* objAdd(string $sDn, array $aItem): bool
* DnExists(string $sDn): bool<br>Check if a DN exists
* objGet(string $sDn, string $sSearchFilter = '(objectclass=*)', array $aAttributesToGet = ["*"]): bool|array
* objAdd(string $sDn, array $aItem): bool<br>Create a new object
* objUpdate(string $sDn, array $aItem): bool
* objGet(string $sDn, string $sSearchFilter = '(objectclass=*)', array $aAttributesToGet = ["*"]): bool|array<br>Get object data of a given DN
* objDelete(string $sDn): bool
* objUpdate(string $sDn, array $aItem): bool<br>Update values of a given object
 
* objDelete(string $sDn): bool<br>Delete an object
### Attributes
### Attributes
* objAddAttr(string $sDn, array $aItem): bool
* objAddAttr(string $sDn, array $aItem): bool
* objDeleteAttr(string $sDn, array $aItem): bool
* objDeleteAttr(string $sDn, array $aItem): bool
* objectAttributeExists(string $sDn, string $sAttribute): bool
* objectAttributeExists(string $sDn, string $sAttribute): bool<br>Check if an attribute exists
* objectAttributeAndValueExist(string $sDn, string $sAttribute, string $sAttrValue): bool - check only
* objectAttributeAndValueExist(string $sDn, string $sAttribute, string $sAttrValue): bool<br>Check if an attribute exists and has a given value
* objectAttributeAndValueMustExist(string $sDn, string $sAttribute, string $sAttrValue): bool - force the existence of attribute and value
* objectAttributeAndValueMustExist(string $sDn, string $sAttribute, string $sAttrValue): bool<br>Force the existence of an attribute that must have a given value
### User functions
### User functions
 
You need to set `$aConfig['DnUserNode']` to a base DN where are the user objects.
 
* userAdd(array $aItem, string $sDn = "")
* userAdd(array $aItem, string $sDn = "")
* getUserInfo(string $sUser, array $aAttributesToGet = ["*"]): bool|array
* getUserInfo(string $sUser, array $aAttributesToGet = ["*"]): bool|array
* userDelete(string $sUserDn)
* userDelete(string $sUserDn)
@@ -68,40 +83,7 @@ $oLdap=new imlldap($aConfig['ldap']);
@@ -68,40 +83,7 @@ $oLdap=new imlldap($aConfig['ldap']);
### Debugging
### Debugging
Turn debugging on or off
Turn debugging on or off.
* debugOff()
* debugOff()
* debugOn()
* debugOn()
## Examples
### read user attributes
Use the username or an email address to get user data. The 2nd parameter defines the attributes to fetch (`["*"]` is default).
```php
$aUser = $oLdap->getUserInfo("john@example.com", []);
$aUser = $oLdap->getUserInfo("john@example.com", ["memberof", "uid"]);
// simplify result array:
print_r($oLdap->normalizeSearchentry($aUser));
```
### Verify user and password for login
```php
// set values from $_FORM or $_POST data of your login form here
// The variable $bAuthenticated is true if authentication of the user was successful.
$bAuthenticated=oLdap->verifyPassword($sUser, $sPassword);
```
### Example: search
When using special chars in search then you can sanitize the search string.
```php
$sCn = 'John Smith (john)';
$sSearchFilter = '(cn='.$oLdap->sanitizeFilter($sCn).')';
$aResults = $oLdap->searchDn("<DN here>", $sSearchFilter, ["*"]);
$oLdap->close();
```
Loading