Merge pull request #462 from MrPetovan/task/3942-move-user-to-src
Move include/user to srcpull/463/head
commit
82e8e64d88
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name: LDAP Authenticate
|
* Name: LDAP Authenticate
|
||||||
* Description: Authenticate a user against an LDAP directory
|
* Description: Authenticate a user against an LDAP directory
|
||||||
|
@ -51,23 +52,21 @@
|
||||||
*
|
*
|
||||||
* ...etc.
|
* ...etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once('include/user.php');
|
|
||||||
|
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Model\User;
|
||||||
|
|
||||||
|
function ldapauth_install()
|
||||||
function ldapauth_install() {
|
{
|
||||||
register_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
|
register_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ldapauth_uninstall()
|
||||||
function ldapauth_uninstall() {
|
{
|
||||||
unregister_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
|
unregister_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ldapauth_hook_authenticate($a, &$b)
|
||||||
function ldapauth_hook_authenticate($a,&$b) {
|
{
|
||||||
if (ldapauth_authenticate($b['username'], $b['password'])) {
|
if (ldapauth_authenticate($b['username'], $b['password'])) {
|
||||||
$results = get_existing_account($b['username']);
|
$results = get_existing_account($b['username']);
|
||||||
if (!empty($results)) {
|
if (!empty($results)) {
|
||||||
|
@ -78,8 +77,8 @@ function ldapauth_hook_authenticate($a,&$b) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ldapauth_authenticate($username,$password) {
|
function ldapauth_authenticate($username, $password)
|
||||||
|
{
|
||||||
$ldap_server = Config::get('ldapauth', 'ldap_server');
|
$ldap_server = Config::get('ldapauth', 'ldap_server');
|
||||||
$ldap_binddn = Config::get('ldapauth', 'ldap_binddn');
|
$ldap_binddn = Config::get('ldapauth', 'ldap_binddn');
|
||||||
$ldap_bindpw = Config::get('ldapauth', 'ldap_bindpw');
|
$ldap_bindpw = Config::get('ldapauth', 'ldap_bindpw');
|
||||||
|
@ -90,9 +89,7 @@ function ldapauth_authenticate($username,$password) {
|
||||||
$ldap_autocreateaccount_emailattribute = Config::get('ldapauth', 'ldap_autocreateaccount_emailattribute');
|
$ldap_autocreateaccount_emailattribute = Config::get('ldapauth', 'ldap_autocreateaccount_emailattribute');
|
||||||
$ldap_autocreateaccount_nameattribute = Config::get('ldapauth', 'ldap_autocreateaccount_nameattribute');
|
$ldap_autocreateaccount_nameattribute = Config::get('ldapauth', 'ldap_autocreateaccount_nameattribute');
|
||||||
|
|
||||||
if(! ((strlen($password))
|
if (!(strlen($password) && function_exists('ldap_connect') && strlen($ldap_server))) {
|
||||||
&& (function_exists('ldap_connect'))
|
|
||||||
&& (strlen($ldap_server)))) {
|
|
||||||
logger("ldapauth: not configured or missing php-ldap module");
|
logger("ldapauth: not configured or missing php-ldap module");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -126,16 +123,19 @@ function ldapauth_authenticate($username,$password) {
|
||||||
|
|
||||||
$dn = @ldap_get_dn($connect, $id);
|
$dn = @ldap_get_dn($connect, $id);
|
||||||
|
|
||||||
if(! @ldap_bind($connect,$dn,$password))
|
if (!@ldap_bind($connect, $dn, $password)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$emailarray = [];
|
$emailarray = [];
|
||||||
$namearray = [];
|
$namearray = [];
|
||||||
if ($ldap_autocreateaccount == "true") {
|
if ($ldap_autocreateaccount == "true") {
|
||||||
if(! strlen($ldap_autocreateaccount_emailattribute))
|
if (!strlen($ldap_autocreateaccount_emailattribute)) {
|
||||||
$ldap_autocreateaccount_emailattribute = "mail";
|
$ldap_autocreateaccount_emailattribute = "mail";
|
||||||
if(! strlen($ldap_autocreateaccount_nameattribute))
|
}
|
||||||
|
if (!strlen($ldap_autocreateaccount_nameattribute)) {
|
||||||
$ldap_autocreateaccount_nameattribute = "givenName";
|
$ldap_autocreateaccount_nameattribute = "givenName";
|
||||||
|
}
|
||||||
$emailarray = @ldap_get_values($connect, $id, $ldap_autocreateaccount_emailattribute);
|
$emailarray = @ldap_get_values($connect, $id, $ldap_autocreateaccount_emailattribute);
|
||||||
$namearray = @ldap_get_values($connect, $id, $ldap_autocreateaccount_nameattribute);
|
$namearray = @ldap_get_values($connect, $id, $ldap_autocreateaccount_nameattribute);
|
||||||
}
|
}
|
||||||
|
@ -154,17 +154,14 @@ function ldapauth_authenticate($username,$password) {
|
||||||
if ($eno === 32) {
|
if ($eno === 32) {
|
||||||
logger("ldapauth: access control group Does Not Exist");
|
logger("ldapauth: access control group Does Not Exist");
|
||||||
return false;
|
return false;
|
||||||
}
|
} elseif ($eno === 16) {
|
||||||
elseif ($eno === 16) {
|
|
||||||
logger('ldapauth: membership attribute does not exist in access control group');
|
logger('ldapauth: membership attribute does not exist in access control group');
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger('ldapauth: error: ' . $err);
|
logger('ldapauth: error: ' . $err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} elseif ($r === false) {
|
||||||
elseif ($r === false) {
|
|
||||||
@ldap_close($connect);
|
@ldap_close($connect);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -173,13 +170,14 @@ function ldapauth_authenticate($username,$password) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ldap_autocreateaccount($ldap_autocreateaccount,$username,$password,$email,$name) {
|
function ldap_autocreateaccount($ldap_autocreateaccount, $username, $password, $email, $name)
|
||||||
|
{
|
||||||
if ($ldap_autocreateaccount == "true") {
|
if ($ldap_autocreateaccount == "true") {
|
||||||
$results = get_existing_account($username);
|
$results = get_existing_account($username);
|
||||||
if (empty($results)) {
|
if (empty($results)) {
|
||||||
if (strlen($email) > 0 && strlen($name) > 0) {
|
if (strlen($email) > 0 && strlen($name) > 0) {
|
||||||
$arr = array('username' => $name, 'nickname' => $username, 'email' => $email, 'password' => $password, 'verified' => 1);
|
$arr = array('username' => $name, 'nickname' => $username, 'email' => $email, 'password' => $password, 'verified' => 1);
|
||||||
$result = create_user($arr);
|
$result = User::create($arr);
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
logger("ldapauth: account " . $username . " created");
|
logger("ldapauth: account " . $username . " created");
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,6 +190,7 @@ function ldap_autocreateaccount($ldap_autocreateaccount,$username,$password,$ema
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_existing_account($username){
|
function get_existing_account($username)
|
||||||
|
{
|
||||||
return q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1", $username);
|
return q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1", $username);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue