PHP code example of rgergo67 / openldap

1. Go to this page and download the library: Download rgergo67/openldap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rgergo67 / openldap example snippets


/*
 * Package Service Providers...
 */
 \Rgergo67\Openldap\OpenldapServiceProvider::class,
 php
/**
     * Gets the dn attribute.
     *
     * @return string The dn attribute.
     */
    public function getDnAttribute(){
        $baseUserDn = $this->isStudent()
            ? config('openldap.base_student_dn')
            : config('openldap.base_employee_dn');
        return config('openldap.login_attribute') . "=" . $this->uid . "," . $baseUserDn;
    }
 php
/**
 * Gets the ldap format attribute.
 *
 * @return     array  The ldap format attribute.
 */
public function getLdapFormatAttribute(){
    return [
        "objectClass" => config('openldap.user_object_class'),
        'cn' => $this->name,
        'sn' => $this->name,
        'mail' => $this->email,
        'gidNumber' => 1,
        'homeDirectory' => '/home/' . $this->username,
        'uid' => $this->uid,
        'uidNumber' => 67
    ];
}

if($user->isDirty('uid')){
    if(!$openldap->rename($user->oldDn, 'uid='.$user->uid, null))
        return false;
}

$openldap->updateUser($user);

public function getOldDnAttribute()
{
    return "uid={$this->getOriginal('uid')},{$this->baseEmployeeDn}";
}

// if all groups were deleted, return
if(!request('groups'))
    return true;

$this->openldap->deleteUserFromAllGroups($user);

foreach(request('groups') as $groupId){
    $group = Group::findOrFail($groupId);
    $this->openldap->addUserToGroup($user, $group->dn);
}

dump($this->openldap->search("ou=phonebook,ou=dev,dc=uni-pannon,dc=hu", "uid=ratting.gergo.mik-math"));

array:2 [▼
  "count" => 1
  0 => array:18 [▼
    "objectclass" => array:5 [▼
      "count" => 4
      0 => "top"
      1 => "person"
      2 => "organizationalPerson"
      3 => "inetOrgPerson"
    ]
    0 => "objectclass"
    "sn" => array:2 [▼
      "count" => 1
      0 => "Ratting"
    ]
    1 => "sn"
    "cn" => array:2 [▼
      "count" => 1
      0 => "Ratting Gergely"
    ]
    2 => "cn"
    "displayname" => array:2 [▼
      "count" => 1
      0 => "Ratting Gergely"
    ]
    3 => "displayname"
    "telephonenumber" => array:2 [▼
      "count" => 1
      0 => "4835"
    ]
    4 => "telephonenumber"
    "ou" => array:3 [▼
      "count" => 2
      0 => "MIK"
      1 => "MIK-MATH"
    ]
    5 => "ou"
    "roomnumber" => array:2 [▼
      "count" => 1
      0 => "B211"
    ]
    6 => "roomnumber"
    "uid" => array:2 [▼
      "count" => 1
      0 => "ratting.gergo.mik-math"
    ]
    7 => "uid"
    "count" => 8
    "dn" => "uid=ratting.gergo.mik-math,ou=phonebook,ou=dev,dc=uni-pannon,dc=hu"
  ]
]

dump($this->openldap->cleanUpEntry(
    $this->openldap->search("ou=phonebook,ou=dev,dc=uni-pannon,dc=hu", "uid=ratting.gergo.mik-math")
));

array:1 [▼
  "uid=ratting.gergo.mik-math,ou=phonebook,ou=dev,dc=uni-pannon,dc=hu" => array:8 [▼
    "objectclass" => array:4 [▼
      0 => "top"
      1 => "person"
      2 => "organizationalPerson"
      3 => "inetOrgPerson"
    ]
    "sn" => "Ratting"
    "cn" => "Ratting Gergely"
    "displayname" => "Ratting Gergely"
    "telephonenumber" => "4835"
    "ou" => array:2 [▼
      0 => "MIK"
      1 => "MIK-MATH"
    ]
    "roomnumber" => "B211"
    "uid" => "ratting.gergo.mik-math"
  ]
]