' : '').$langs->trans("ActualMailSPFRecordFound", $info['txt']);
+ }
+ }
+ }
if ($text) {
print info_admin($text);
}
diff --git a/htdocs/contact/ldap.php b/htdocs/contact/ldap.php
index 8babb849e7e..d29aab0386b 100644
--- a/htdocs/contact/ldap.php
+++ b/htdocs/contact/ldap.php
@@ -182,7 +182,6 @@ if ($result > 0) {
}
$ldap->unbind();
- $ldap->close();
} else {
setEventMessages($ldap->error, $ldap->errors, 'errors');
}
diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php
index 4e0c2bd83ca..07e9ba4f2b7 100644
--- a/htdocs/core/class/ldap.class.php
+++ b/htdocs/core/class/ldap.class.php
@@ -1,8 +1,8 @@
* Copyright (C) 2004 Benoit Mortier
- * Copyright (C) 2005-2017 Regis Houssin
- * Copyright (C) 2006-2015 Laurent Destailleur
+ * Copyright (C) 2005-2021 Regis Houssin
+ * Copyright (C) 2006-2021 Laurent Destailleur
*
* 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
@@ -48,6 +48,11 @@ class Ldap
*/
public $server = array();
+ /**
+ * Current connected server
+ */
+ public $connectedServer;
+
/**
* Base DN (e.g. "dc=foo,dc=com")
*/
@@ -132,35 +137,33 @@ class Ldap
if (!empty($conf->global->LDAP_SERVER_HOST_SLAVE)) {
$this->server[] = $conf->global->LDAP_SERVER_HOST_SLAVE;
}
- $this->serverPort = $conf->global->LDAP_SERVER_PORT;
- $this->ldapProtocolVersion = $conf->global->LDAP_SERVER_PROTOCOLVERSION;
- $this->dn = $conf->global->LDAP_SERVER_DN;
- $this->serverType = $conf->global->LDAP_SERVER_TYPE;
+ $this->serverPort = getDolGlobalInt('LDAP_SERVER_PORT', 389);
+ $this->ldapProtocolVersion = getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION');
+ $this->dn = getDolGlobalString('LDAP_SERVER_DN');
+ $this->serverType = getDolGlobalString('LDAP_SERVER_TYPE');
- $this->domain = $conf->global->LDAP_SERVER_DN;
- $this->searchUser = $conf->global->LDAP_ADMIN_DN;
- $this->searchPassword = $conf->global->LDAP_ADMIN_PASS;
- $this->people = $conf->global->LDAP_USER_DN;
- $this->groups = $conf->global->LDAP_GROUP_DN;
+ $this->domain = getDolGlobalString('LDAP_SERVER_DN');
+ $this->searchUser = getDolGlobalString('LDAP_ADMIN_DN');
+ $this->searchPassword = getDolGlobalString('LDAP_ADMIN_PASS');
+ $this->people = getDolGlobalString('LDAP_USER_DN');
+ $this->groups = getDolGlobalString('LDAP_GROUP_DN');
- $this->filter = $conf->global->LDAP_FILTER_CONNECTION; // Filter on user
- $this->filtergroup = $conf->global->LDAP_GROUP_FILTER; // Filter on groups
- $this->filtermember = $conf->global->LDAP_MEMBER_FILTER; // Filter on member
+ $this->filter = getDolGlobalString('LDAP_FILTER_CONNECTION'); // Filter on user
+ $this->filtergroup = getDolGlobalString('LDAP_GROUP_FILTER'); // Filter on groups
+ $this->filtermember = getDolGlobalString('LDAP_MEMBER_FILTER'); // Filter on member
// Users
- $this->attr_login = $conf->global->LDAP_FIELD_LOGIN; //unix
- $this->attr_sambalogin = $conf->global->LDAP_FIELD_LOGIN_SAMBA; //samba, activedirectory
- $this->attr_name = $conf->global->LDAP_FIELD_NAME;
- $this->attr_firstname = $conf->global->LDAP_FIELD_FIRSTNAME;
- $this->attr_mail = $conf->global->LDAP_FIELD_MAIL;
- $this->attr_phone = $conf->global->LDAP_FIELD_PHONE;
- $this->attr_skype = $conf->global->LDAP_FIELD_SKYPE;
- $this->attr_fax = $conf->global->LDAP_FIELD_FAX;
- $this->attr_mobile = $conf->global->LDAP_FIELD_MOBILE;
+ $this->attr_login = getDolGlobalString('LDAP_FIELD_LOGIN'); //unix
+ $this->attr_sambalogin = getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA'); //samba, activedirectory
+ $this->attr_name = getDolGlobalString('LDAP_FIELD_NAME');
+ $this->attr_firstname = getDolGlobalString('LDAP_FIELD_FIRSTNAME');
+ $this->attr_mail = getDolGlobalString('LDAP_FIELD_MAIL');
+ $this->attr_phone = getDolGlobalString('LDAP_FIELD_PHONE');
+ $this->attr_skype = getDolGlobalString('LDAP_FIELD_SKYPE');
+ $this->attr_fax = getDolGlobalString('LDAP_FIELD_FAX');
+ $this->attr_mobile = getDolGlobalString('LDAP_FIELD_MOBILE');
}
-
-
// Connection handling methods -------------------------------------------
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -288,6 +291,7 @@ class Ldap
$return = -1;
dol_syslog(get_class($this)."::connect_bind return=".$return.' - '.$this->error, LOG_WARNING);
}
+ $this->connectedServer = $host;
return $return;
}
@@ -297,6 +301,7 @@ class Ldap
* This method seems a duplicate/alias of unbind().
*
* @return boolean true or false
+ * @deprecated ldap_close is an alias of ldap_unbind
* @see unbind()
*/
public function close()
@@ -416,7 +421,7 @@ class Ldap
*/
public function add($dn, $info, $user)
{
- dol_syslog(get_class($this)."::add dn=".$dn." info=".join(',', $info));
+ dol_syslog(get_class($this)."::add dn=".$dn." info=".json_encode($info));
// Check parameters
if (!$this->connection) {
diff --git a/htdocs/core/lib/ldap.lib.php b/htdocs/core/lib/ldap.lib.php
index 9d6e0193108..56a8bcc4285 100644
--- a/htdocs/core/lib/ldap.lib.php
+++ b/htdocs/core/lib/ldap.lib.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2006-2017 Regis Houssin
+ * Copyright (C) 2006-2021 Regis Houssin
*
* 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
@@ -89,7 +89,6 @@ function ldap_prepare_head()
return $head;
}
-
/**
* Show button test LDAP synchro
*
@@ -119,7 +118,6 @@ function show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
print '
';
}
-
/**
* Show a LDAP array into an HTML output array.
*
@@ -153,7 +151,7 @@ function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount =
if ("$key" == "dn") {
continue;
}
- if ("$val" == "objectclass") {
+ if (!is_array($val) && "$val" == "objectclass") {
continue;
}
@@ -181,7 +179,7 @@ function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount =
}
print ' ';
}
- if ("$val" != $lastkey[$level] && !$subcount) {
+ if (!is_array($val) && "$val" != $lastkey[$level] && !$subcount) {
print '';
}
}
diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php
index b4aae4e5679..ede899d7761 100644
--- a/htdocs/core/lib/security.lib.php
+++ b/htdocs/core/lib/security.lib.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2008-2017 Regis Houssin
+/* Copyright (C) 2008-2021 Laurent Destailleur
+ * Copyright (C) 2008-2021 Regis Houssin
* Copyright (C) 2020 Ferran Marcet
*
* This program is free software; you can redistribute it and/or modify
@@ -91,7 +91,6 @@ function dol_decode($chain, $key = '1')
return $chain;
}
-
/**
* Returns a hash of a string.
* If constant MAIN_SECURITY_HASH_ALGO is defined, we use this function as hashing function (recommanded value is 'password_hash')
@@ -123,7 +122,7 @@ function dol_hash($chain, $type = '0')
} elseif ($type == '3' || $type == 'md5') {
return md5($chain);
} elseif ($type == '4' || $type == 'md5openldap') {
- return '{md5}'.base64_encode(mhash(MHASH_MD5, $chain)); // For OpenLdap with md5 (based on an unencrypted password in base)
+ return '{md5}'.base64_encode(pack("H*", md5($chain))); // For OpenLdap with md5 (based on an unencrypted password in base)
} elseif ($type == '5' || $type == 'sha256') {
return hash('sha256', $chain);
} elseif ($type == '6' || $type == 'password_hash') {
@@ -168,7 +167,6 @@ function dol_verifyHash($chain, $hash, $type = '0')
return dol_hash($chain, $type) == $hash;
}
-
/**
* Check permissions of a user to show a page and an object. Check read permission.
* If GETPOST('action','aZ09') defined, we also check write and delete permission.
diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php
index 6b11474995b..2d55ca2815b 100644
--- a/htdocs/core/login/functions_ldap.php
+++ b/htdocs/core/login/functions_ldap.php
@@ -120,7 +120,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest)
if ($ldapdebug) {
print "DEBUG: User ".$usertotest." must change password \n";
}
- $ldap->close();
+ $ldap->unbind();
sleep(1);
$langs->load('ldap');
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("YouMustChangePassNextLogon", $usertotest, $ldap->domainFQDN);
@@ -131,7 +131,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest)
print "DEBUG: ".$ldap->error." \n";
}
}
- $ldap->close();
+ $ldap->unbind();
}
// Forge LDAP user and password to test with them
@@ -166,14 +166,14 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest)
$now = dol_now();
if ($tmpuser->datestartvalidity && $db->jdate($tmpuser->datestartvalidity) >= $now) {
- $ldap->close();
+ $ldap->unbind();
// Load translation files required by the page
$langs->loadLangs(array('main', 'errors'));
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorLoginDateValidity");
return '--bad-login-validity--';
}
if ($tmpuser->dateendvalidity && $db->jdate($tmpuser->dateendvalidity) <= dol_get_first_hour($now)) {
- $ldap->close();
+ $ldap->unbind();
// Load translation files required by the page
$langs->loadLangs(array('main', 'errors'));
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorLoginDateValidity");
@@ -271,7 +271,7 @@ function check_user_password_ldap($usertotest, $passwordtotest, $entitytotest)
$_SESSION["dol_loginmesg"] = ($ldap->error ? $ldap->error : $langs->transnoentitiesnoconv("ErrorBadLoginPassword"));
}
- $ldap->close();
+ $ldap->unbind();
}
return $login;
diff --git a/htdocs/core/tpl/object_discounts.tpl.php b/htdocs/core/tpl/object_discounts.tpl.php
index df565aea6f9..38e1967c11b 100644
--- a/htdocs/core/tpl/object_discounts.tpl.php
+++ b/htdocs/core/tpl/object_discounts.tpl.php
@@ -1,5 +1,6 @@
+ * Copyright (C) 2021 Frédéric France
*
* 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
@@ -88,7 +89,7 @@ if ($absolute_discount > 0) {
// Is there credit notes availables ?
if ($absolute_creditnote > 0) {
// If validated, we show link "add credit note to payment"
- if ($cannotApplyDiscount || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
+ if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
$translationKey = !empty($discount_type) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote';
$text = $langs->trans($translationKey, price($absolute_creditnote), $langs->transnoentities("Currency".$conf->currency)).'.';
diff --git a/htdocs/knowledgemanagement/knowledgerecord_list.php b/htdocs/knowledgemanagement/knowledgerecord_list.php
index d4a702f26b8..aed45b1db26 100644
--- a/htdocs/knowledgemanagement/knowledgerecord_list.php
+++ b/htdocs/knowledgemanagement/knowledgerecord_list.php
@@ -1,6 +1,6 @@
- * Copyright (C) ---Put here your own copyright and developer email---
+ * Copyright (C) 2021 Frédéric France
*
* 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
@@ -104,7 +104,7 @@ foreach ($object->fields as $key => $val) {
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array();
foreach ($object->fields as $key => $val) {
- if ($val['searchall']) {
+ if (!empty($val['searchall'])) {
$fieldstosearchall['t.'.$key] = $val['label'];
}
}
@@ -444,6 +444,7 @@ print '
';
}
@@ -522,7 +523,7 @@ print ''."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0;
-if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
+if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
if (preg_match('/\$object/', $val)) {
$needToFetchEachLine++; // There is at least one compute field that use $object
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 508d56a46c5..7ffbe0328c1 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -501,6 +501,7 @@ WarningPHPMailC=- Using the SMTP server of your own Email Service Provider to se
WarningPHPMailD=Also, it is therefore recommended to change the sending method of e-mails to the value "SMTP". If you really want to keep the default "PHP" method to send emails, just ignore this warning, or remove it by setting the MAIN_HIDE_WARNING_TO_ENCOURAGE_SMTP_SETUP constant to 1 in Home - Setup - Other.
WarningPHPMail2=If your email SMTP provider need to restrict email client to some IP addresses (very rare), this is the IP address of the mail user agent (MUA) for your ERP CRM application: %s.
WarningPHPMailSPF=If the domain name in your sender email address is protected by a SPF record (ask your domain name registar), you must add the following IPs in the SPF record of the DNS of your domain: %s.
+ActualMailSPFRecordFound=Actual SPF record found : %s
ClickToShowDescription=Click to show description
DependsOn=This module needs the module(s)
RequiredBy=This module is required by module(s)
diff --git a/htdocs/user/card.php b/htdocs/user/card.php
index 79ae03cbe4f..e3a72384050 100644
--- a/htdocs/user/card.php
+++ b/htdocs/user/card.php
@@ -2774,7 +2774,7 @@ if ($action == 'create' || $action == 'adduserldap') {
}
if (!empty($conf->ldap->enabled) && !empty($object->ldap_sid)) {
- $ldap->close();
+ $ldap->unbind();
}
}
}
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index 1114aa826d5..d1aa62b25ee 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -2901,7 +2901,7 @@ class User extends CommonObject
}
}
foreach ($socialnetworks as $key => $value) {
- if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])})) {
+ if (!empty($this->socialnetworks[$value['label']]) && !empty($conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])})) {
$info[$conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']];
}
}
diff --git a/htdocs/user/group/ldap.php b/htdocs/user/group/ldap.php
index 710dab1ee22..d8d1995a847 100644
--- a/htdocs/user/group/ldap.php
+++ b/htdocs/user/group/ldap.php
@@ -192,7 +192,6 @@ if ($result > 0) {
print '