refactoring
This commit is contained in:
parent
a206e9fefe
commit
a55c337efd
|
@ -3,7 +3,7 @@
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
Copyright (C) 2003 - 2017 Roland Gruber
|
Copyright (C) 2003 - 2018 Roland Gruber
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -57,7 +57,7 @@ class Ldap{
|
||||||
*
|
*
|
||||||
* @param object $config an object of class Config
|
* @param object $config an object of class Config
|
||||||
*/
|
*/
|
||||||
function __construct($config) {
|
public function __construct($config) {
|
||||||
if (is_object($config)) {
|
if (is_object($config)) {
|
||||||
$this->conf = $config;
|
$this->conf = $config;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class Ldap{
|
||||||
* @param boolean $allowAnonymous specifies if anonymous binds are allowed
|
* @param boolean $allowAnonymous specifies if anonymous binds are allowed
|
||||||
* @return mixed if connect succeeds the 0 is returned, else false or error number
|
* @return mixed if connect succeeds the 0 is returned, else false or error number
|
||||||
*/
|
*/
|
||||||
function connect($user, $passwd, $allowAnonymous=false) {
|
public function connect($user, $passwd, $allowAnonymous=false) {
|
||||||
// close any prior connection
|
// close any prior connection
|
||||||
@$this->close();
|
@$this->close();
|
||||||
// do not allow anonymous bind
|
// do not allow anonymous bind
|
||||||
|
@ -105,7 +105,7 @@ class Ldap{
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Closes connection to server */
|
/** Closes connection to server */
|
||||||
function close() {
|
public function close() {
|
||||||
if ($this->server != null) {
|
if ($this->server != null) {
|
||||||
@ldap_close($this->server);
|
@ldap_close($this->server);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ class Ldap{
|
||||||
*
|
*
|
||||||
* @return object connection handle
|
* @return object connection handle
|
||||||
*/
|
*/
|
||||||
function server() {
|
public function server() {
|
||||||
if (!$this->is_connected) {
|
if (!$this->is_connected) {
|
||||||
$data = $this->decrypt_login();
|
$data = $this->decrypt_login();
|
||||||
$this->connect($data[0], $data[1]);
|
$this->connect($data[0], $data[1]);
|
||||||
|
@ -126,14 +126,14 @@ class Ldap{
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Closes connection to LDAP server before serialization */
|
/** Closes connection to LDAP server before serialization */
|
||||||
function __sleep() {
|
public function __sleep() {
|
||||||
$this->close();
|
$this->close();
|
||||||
// define which attributes to save
|
// define which attributes to save
|
||||||
return array("conf", "username", "password");
|
return array("conf", "username", "password");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reconnects to LDAP server when deserialized */
|
/** Reconnects to LDAP server when deserialized */
|
||||||
function __wakeup() {
|
public function __wakeup() {
|
||||||
$this->is_connected = false;
|
$this->is_connected = false;
|
||||||
// delete PDF files and images which are older than 15 min
|
// delete PDF files and images which are older than 15 min
|
||||||
$tmpDir = dirname(__FILE__) . '/../tmp/';
|
$tmpDir = dirname(__FILE__) . '/../tmp/';
|
||||||
|
@ -173,7 +173,7 @@ class Ldap{
|
||||||
* @param string $username LDAP user name
|
* @param string $username LDAP user name
|
||||||
* @param string $password LDAP password
|
* @param string $password LDAP password
|
||||||
*/
|
*/
|
||||||
function encrypt_login($username, $password) {
|
public function encrypt_login($username, $password) {
|
||||||
// encrypt username and password
|
// encrypt username and password
|
||||||
$this->username = base64_encode(lamEncrypt($username));
|
$this->username = base64_encode(lamEncrypt($username));
|
||||||
$this->password = base64_encode(lamEncrypt($password));
|
$this->password = base64_encode(lamEncrypt($password));
|
||||||
|
@ -184,7 +184,7 @@ class Ldap{
|
||||||
*
|
*
|
||||||
* @return array array(user name, password)
|
* @return array array(user name, password)
|
||||||
*/
|
*/
|
||||||
function decrypt_login() {
|
public function decrypt_login() {
|
||||||
// decrypt username and password
|
// decrypt username and password
|
||||||
$username = lamDecrypt(base64_decode($this->username));
|
$username = lamDecrypt(base64_decode($this->username));
|
||||||
$password = lamDecrypt(base64_decode($this->password));
|
$password = lamDecrypt(base64_decode($this->password));
|
||||||
|
@ -192,8 +192,26 @@ class Ldap{
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the LDAP user name.
|
||||||
|
*
|
||||||
|
* @return string user name
|
||||||
|
*/
|
||||||
|
public function getUserName() {
|
||||||
|
return lamDecrypt(base64_decode($this->username));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the LDAP password.
|
||||||
|
*
|
||||||
|
* @return string password
|
||||||
|
*/
|
||||||
|
public function getPassword() {
|
||||||
|
return lamDecrypt(base64_decode($this->password));
|
||||||
|
}
|
||||||
|
|
||||||
/** Closes connection to LDAP server and deletes encrypted username/password */
|
/** Closes connection to LDAP server and deletes encrypted username/password */
|
||||||
function destroy() {
|
public function destroy() {
|
||||||
$this->close();
|
$this->close();
|
||||||
$this->username="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
$this->username="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||||
$this->password="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
$this->password="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||||
|
|
Loading…
Reference in New Issue