X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=ldapauth%2Fldapauth.php;h=514fb1d1a89ade5565a827ce1292409e7cfec57e;hb=6bc8103ca2b341b4a7d15996a64502ac00d5c626;hp=63ccbe91598790d57f986ecfc6bdf771934456d2;hpb=cb9926c93a7fcf25028d19f47ef809ffcf002fd6;p=friendica-addons.git diff --git a/ldapauth/ldapauth.php b/ldapauth/ldapauth.php index 63ccbe91..514fb1d1 100644 --- a/ldapauth/ldapauth.php +++ b/ldapauth/ldapauth.php @@ -26,43 +26,52 @@ * Note when using with Windows Active Directory: you may need to set TLS_CACERT in your site * ldap.conf file to the signing cert for your LDAP server. * - * The configuration options for this module may be set in the .htconfig.php file + * The configuration options for this module may be set in the config/addon.ini.php file * e.g.: * - * // ldap hostname server - required - * $a->config['ldapauth']['ldap_server'] = 'host.example.com'; - * // dn to search users - required - * $a->config['ldapauth']['ldap_searchdn'] = 'ou=users,dc=example,dc=com'; - * // attribute to find username - required - * $a->config['ldapauth']['ldap_userattr'] = 'uid'; + * [ldapauth] + * ; ldap hostname server - required + * ldap_server = host.example.com + * ; dn to search users - required + * ldap_searchdn = ou=users,dc=example,dc=com + * ; attribute to find username - required + * ldap_userattr = uid * - * // admin dn - optional - only if ldap server dont have anonymous access - * $a->config['ldapauth']['ldap_binddn'] = 'cn=admin,dc=example,dc=com'; - * // admin password - optional - only if ldap server dont have anonymous access - * $a->config['ldapauth']['ldap_bindpw'] = 'password'; + * ; admin dn - optional - only if ldap server dont have anonymous access + * ldap_binddn = cn=admin,dc=example,dc=com + * ; admin password - optional - only if ldap server dont have anonymous access + * ldap_bindpw = password * - * // for create Friendica account if user exist in ldap - * // required an email and a simple (beautiful) nickname on user ldap object - * // active account creation - optional - default none - * $a->config['ldapauth']['ldap_autocreateaccount'] = 'true'; - * // attribute to get email - optional - default : 'mail' - * $a->config['ldapauth']['ldap_autocreateaccount_emailattribute'] = 'mail'; - * // attribute to get nickname - optional - default : 'givenName' - * $a->config['ldapauth']['ldap_autocreateaccount_nameattribute'] = 'cn'; + * ; for create Friendica account if user exist in ldap + * ; required an email and a simple (beautiful) nickname on user ldap object + * ; active account creation - optional - default none + * ldap_autocreateaccount = true + * ; attribute to get email - optional - default : 'mail' + * ldap_autocreateaccount_emailattribute = mail + * ; attribute to get nickname - optional - default : 'givenName' + * ldap_autocreateaccount_nameattribute = cn * * ...etc. */ +use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Model\User; function ldapauth_install() { - register_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate'); + Addon::registerHook('load_config', 'addon/ldapauth/ldapauth.php', 'ldapauth_load_config'); + Addon::registerHook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate'); } function ldapauth_uninstall() { - unregister_hook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate'); + Addon::unregisterHook('load_config', 'addon/ldapauth/ldapauth.php', 'ldapauth_load_config'); + Addon::unregisterHook('authenticate', 'addon/ldapauth/ldapauth.php', 'ldapauth_hook_authenticate'); +} + +function ldapauth_load_config(\Friendica\App $a) +{ + $a->loadConfigFile(__DIR__. '/config/ldapauth.ini.php'); } function ldapauth_hook_authenticate($a, &$b) @@ -176,7 +185,7 @@ function ldap_autocreateaccount($ldap_autocreateaccount, $username, $password, $ $results = get_existing_account($username); if (empty($results)) { if (strlen($email) > 0 && strlen($name) > 0) { - $arr = array('username' => $name, 'nickname' => $username, 'email' => $email, 'password' => $password, 'verified' => 1); + $arr = ['username' => $name, 'nickname' => $username, 'email' => $email, 'password' => $password, 'verified' => 1]; try { User::create($arr);