1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dotclear2_ynh.git synced 2024-09-03 18:26:29 +02:00

Fix LDAP connection

This commit is contained in:
Kayou 2019-03-01 02:05:03 +01:00
parent 75d632ce5f
commit f751d455cd
No known key found for this signature in database
GPG key ID: 823A2CBE071D3126
3 changed files with 82 additions and 70 deletions

View file

@ -1,15 +1,15 @@
<?
<?php
class myDcAuth extends dcAuth
{
# L'utilisateur n'a pas le droit de changer son mot de passe
protected $allow_pass_change = false;
# La méthode de vérification du mot de passe
public function checkUser($user_id, $pwd=null, $user_key=null)
public function checkUser($user_id, $pwd=null, $user_key=null, $check_blog=true)
{
# Pas de mot de passe, on appelle la méthode parente.
if ($pwd == '') {
return parent::checkUser($user_id,null,$user_key);
return parent::checkUser($user_id, null, $user_key, $check_blog);
}
# On démarre une transaction et on ouvre un curseur sur la
@ -25,11 +25,10 @@ class myDcAuth extends dcAuth
$racine = "dc=yunohost,dc=org";
#connection au serveur ldap
$ds=@ldap_connect($server) or die("Could not connect to LDAP server.");
$ds=ldap_connect($server);
ldap_set_option ($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if (ldap_bind($ds,"uid=".$user_id.",ou=users,dc=yunohost,dc=org",$pwd))
{
# On définit le mot de passe, il est inséré dans tous les cas.
$cur->user_pwd = $pwd;
@ -45,18 +44,15 @@ class myDcAuth extends dcAuth
# au moins une permission "usage" sur le blog "default".
else
{
$sr=ldap_search($ds,$racine,"cn=$user_id",array( "dn", "cn", "sn", "mail", "givenName"));
$info = ldap_get_entries($ds, $sr);
#on recherche l'utilisateur dans le ldap pour recuperer toutes les informations
$sr=ldap_search($ds,$racine,"cn=$user_id",array( "dn", "cn", "sn", "mail", "givenName"));
$sr=ldap_search($ds,$racine,"uid=$user_id",array( "dn", "cn", "sn", "mail", "givenName"));
$info = ldap_get_entries($ds, $sr);
#si le ldap ne ramene qu'un seul utilisateur
if ($info["count"] ==1)
{
$cur->user_id = $info[0]['cn'][0];
$cur->user_id = $user_id;
$cur->user_email = $info[0]['mail'][0];
$cur->user_name = $info[0]['givenName'][0];
$cur->user_firstname = $info[0]['sn'][0];
@ -64,7 +60,7 @@ class myDcAuth extends dcAuth
$cur->user_tz = 'Europe/Paris';
$cur->user_default_blog = 'default';
$this->sudo(array($this->core,'addUser'),$cur);
$this->sudo(array($this->core,'setUserBlogPermissions'),$user_id,$user_id,array('admin'=>true));
$this->sudo(array($this->core,'setUserBlogPermissions'),$user_id,'default',array('admin'=>true));
$this->con->commit();
}
}
@ -72,7 +68,7 @@ class myDcAuth extends dcAuth
# Les opérations précédentes se sont déroulées sans erreur, nous
# pouvons maintenant appeler la méthode parente afin d'initialiser
# l'utilisateur dans l'object $core->auth
return parent::checkUser($user_id,$pwd);
return parent::checkUser($user_id, $pwd, $user_key, $check_blog);
}
# En cas d'erreur on annule la transaction et on renvoie "false"
$this->con->rollback();

View file

@ -105,6 +105,7 @@ email=$(yunohost user info $admin | grep mail: | cut -d' ' -f2 | tr -d '\n')
ynh_app_setting_set $app master_key $master_key
cp $php_config.in $php_config
cp ../conf/class.auth.ldap.php $final_path/inc/class.auth.ldap.php
admin_url=$(ynh_url_join $path_url admin/index.php)
@ -128,6 +129,13 @@ ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_c
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $php_config
ynh_replace_string "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config
# Adding LDAP login
cat << EOF >> $php_config
\$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
define('DC_AUTH_CLASS','myDcAuth');
EOF
ynh_store_file_checksum $php_config
#=================================================

View file

@ -125,6 +125,7 @@ ynh_add_fpm_config
#=================================================
cp $php_config.in $php_config
cp ../conf/class.auth.ldap.php $final_path/inc/class.auth.ldap.php
firstname=$(yunohost user info $admin | grep firstname: | cut -d' ' -f2 | tr -d '\n')
lastname=$(yunohost user info $admin | grep lastname: | cut -d' ' -f2 | tr -d '\n')
@ -151,6 +152,13 @@ ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_c
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $php_config
ynh_replace_string "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config
# Adding LDAP login
cat << EOF >> $php_config
\$__autoload['myDcAuth'] = dirname(__FILE__).'/class.auth.ldap.php';
define('DC_AUTH_CLASS','myDcAuth');
EOF
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$php_config"