From 741b8a48682890ee68e3f650510fec9a4d47d5b0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 14 Feb 2014 13:57:50 +0100 Subject: Show a domain dropdown when multiple AD domains are configured This integrates the functionality of the now outdated addomain plugin directly into the authad plugin and makes multi-domain setups usable without SSO. See also https://github.com/cosmocode/dokuwiki-plugin-addomain --- lib/plugins/authad/action.php | 91 ++++++++++++++++++++++++++++++++++++++ lib/plugins/authad/auth.php | 25 +++++++++++ lib/plugins/authad/plugin.info.txt | 2 +- 3 files changed, 117 insertions(+), 1 deletion(-) (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/action.php b/lib/plugins/authad/action.php index e69de29bb..97be9897e 100644 --- a/lib/plugins/authad/action.php +++ b/lib/plugins/authad/action.php @@ -0,0 +1,91 @@ + + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +/** + * Class action_plugin_addomain + */ +class action_plugin_authad extends DokuWiki_Action_Plugin { + + /** + * Registers a callback function for a given event + */ + public function register(Doku_Event_Handler &$controller) { + + $controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE', $this, 'handle_auth_login_check'); + $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_html_loginform_output'); + + } + + /** + * Adds the selected domain as user postfix when attempting a login + * + * @param Doku_Event $event + * @param array $param + */ + public function handle_auth_login_check(Doku_Event &$event, $param) { + global $INPUT; + + /** @var auth_plugin_authad $auth */ + global $auth; + if(!is_a($auth, 'auth_plugin_authad')) return; // AD not even used + + if($INPUT->str('dom')) { + $usr = $auth->cleanUser($event->data['user']); + $dom = $auth->_userDomain($usr); + if(!$dom) { + $usr = "$usr@".$INPUT->str('dom'); + } + $INPUT->post->set('u', $usr); + $event->data['user'] = $usr; + } + } + + /** + * Shows a domain selection in the login form when more than one domain is configured + * + * @param Doku_Event $event + * @param array $param + */ + public function handle_html_loginform_output(Doku_Event &$event, $param) { + global $INPUT; + /** @var auth_plugin_authad $auth */ + global $auth; + if(!is_a($auth, 'auth_plugin_authad')) return; // AD not even used + $domains = $auth->_getConfiguredDomains(); + if(count($domains) <= 1) return; // no choice at all + + /** @var Doku_Form $form */ + $form =& $event->data; + + // any default? + $dom = ''; + if($INPUT->has('u')) { + $usr = $auth->cleanUser($INPUT->str('u')); + $dom = $auth->_userDomain($usr); + + // update user field value + if($dom) { + $usr = $auth->_userName($usr); + $pos = $form->findElementByAttribute('name', 'u'); + $ele =& $form->getElementAt($pos); + $ele['value'] = $usr; + } + } + + // add select box + $element = form_makeListboxField('dom', $domains, $dom, $this->getLang('domain'), '', 'block'); + $pos = $form->findElementByAttribute('name', 'p'); + $form->insertElement($pos + 1, $element); + } + +} + +// vim:ts=4:sw=4:et: \ No newline at end of file diff --git a/lib/plugins/authad/auth.php b/lib/plugins/authad/auth.php index e1d758fb8..db9b179a6 100644 --- a/lib/plugins/authad/auth.php +++ b/lib/plugins/authad/auth.php @@ -511,6 +511,31 @@ class auth_plugin_authad extends DokuWiki_Auth_Plugin { return $opts; } + /** + * Returns a list of configured domains + * + * The default domain has an empty string as key + * + * @return array associative array(key => domain) + */ + public function _getConfiguredDomains() { + $domains = array(); + if(empty($this->conf['account_suffix'])) return $domains; // not configured yet + + // add default domain, using the name from account suffix + $domains[''] = ltrim($this->conf['account_suffix'], '@'); + + // find additional domains + foreach($this->conf as $key => $val) { + if(is_array($val) && isset($val['account_suffix'])) { + $domains[$key] = ltrim($val['account_suffix'], '@'); + } + } + ksort($domains); + + return $domains; + } + /** * Check provided user and userinfo for matching patterns * diff --git a/lib/plugins/authad/plugin.info.txt b/lib/plugins/authad/plugin.info.txt index 3af1ddfbe..8774fcf3c 100644 --- a/lib/plugins/authad/plugin.info.txt +++ b/lib/plugins/authad/plugin.info.txt @@ -1,7 +1,7 @@ base authad author Andreas Gohr email andi@splitbrain.org -date 2013-04-25 +date 2014-02-14 name Active Directory Auth Plugin desc Provides user authentication against a Microsoft Active Directory url http://www.dokuwiki.org/plugin:authad -- cgit v1.2.3 From e30b0f289638b91494ea96d307fd82e1458d6dcf Mon Sep 17 00:00:00 2001 From: Wild Date: Sat, 22 Feb 2014 12:47:47 +0100 Subject: translation update --- lib/plugins/authad/lang/fr/settings.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/lang/fr/settings.php b/lib/plugins/authad/lang/fr/settings.php index 84e0d00d9..d05390efc 100644 --- a/lib/plugins/authad/lang/fr/settings.php +++ b/lib/plugins/authad/lang/fr/settings.php @@ -4,7 +4,6 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * * @author Bruno Veilleux - * @author Momo50 */ $lang['account_suffix'] = 'Le suffixe de votre compte. Ex.: @mon.domaine.org'; $lang['base_dn'] = 'Votre nom de domaine de base. DC=mon,DC=domaine,DC=org'; @@ -12,7 +11,6 @@ $lang['domain_controllers'] = 'Une liste de contrôleurs de domaine séparés $lang['admin_username'] = 'Un utilisateur Active Directory avec accès aux données de tous les autres utilisateurs. Facultatif, mais nécessaire pour certaines actions telles que l\'envoi de courriels d\'abonnement.'; $lang['admin_password'] = 'Le mot de passe de l\'utilisateur ci-dessus.'; $lang['sso'] = 'Est-ce que la connexion unique (Single-Sign-On) par Kerberos ou NTLM doit être utilisée?'; -$lang['sso_charset'] = 'Le jeu de caractères de votre serveur web va passer le nom d\'utilisateur Kerberos ou NTLM. Vide pour UTF-8 ou latin-1. Nécessite l\'extension iconv.'; $lang['real_primarygroup'] = 'Est-ce que le véritable groupe principal doit être résolu au lieu de présumer "Domain Users" (plus lent)?'; $lang['use_ssl'] = 'Utiliser une connexion SSL? Si utilisée, n\'activez pas TLS ci-dessous.'; $lang['use_tls'] = 'Utiliser une connexion TLS? Si utilisée, n\'activez pas SSL ci-dessus.'; -- cgit v1.2.3 From 176279377b99c01aa3ca08bd1a25b134fe7f97b0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 28 Feb 2014 11:20:26 +0100 Subject: fixed merge error --- lib/plugins/authad/lang/fr/settings.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/lang/fr/settings.php b/lib/plugins/authad/lang/fr/settings.php index d05390efc..84e0d00d9 100644 --- a/lib/plugins/authad/lang/fr/settings.php +++ b/lib/plugins/authad/lang/fr/settings.php @@ -4,6 +4,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * * @author Bruno Veilleux + * @author Momo50 */ $lang['account_suffix'] = 'Le suffixe de votre compte. Ex.: @mon.domaine.org'; $lang['base_dn'] = 'Votre nom de domaine de base. DC=mon,DC=domaine,DC=org'; @@ -11,6 +12,7 @@ $lang['domain_controllers'] = 'Une liste de contrôleurs de domaine séparés $lang['admin_username'] = 'Un utilisateur Active Directory avec accès aux données de tous les autres utilisateurs. Facultatif, mais nécessaire pour certaines actions telles que l\'envoi de courriels d\'abonnement.'; $lang['admin_password'] = 'Le mot de passe de l\'utilisateur ci-dessus.'; $lang['sso'] = 'Est-ce que la connexion unique (Single-Sign-On) par Kerberos ou NTLM doit être utilisée?'; +$lang['sso_charset'] = 'Le jeu de caractères de votre serveur web va passer le nom d\'utilisateur Kerberos ou NTLM. Vide pour UTF-8 ou latin-1. Nécessite l\'extension iconv.'; $lang['real_primarygroup'] = 'Est-ce que le véritable groupe principal doit être résolu au lieu de présumer "Domain Users" (plus lent)?'; $lang['use_ssl'] = 'Utiliser une connexion SSL? Si utilisée, n\'activez pas TLS ci-dessous.'; $lang['use_tls'] = 'Utiliser une connexion TLS? Si utilisée, n\'activez pas SSL ci-dessus.'; -- cgit v1.2.3 From 85db969ec27b3f6e656d04a114174a630be90d4c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 28 Feb 2014 11:23:43 +0100 Subject: added missing language strings --- lib/plugins/authad/lang/de/lang.php | 10 ++++++++++ lib/plugins/authad/lang/en/lang.php | 10 ++++++++++ lib/plugins/authad/lang/ko/lang.php | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 lib/plugins/authad/lang/de/lang.php create mode 100644 lib/plugins/authad/lang/en/lang.php create mode 100644 lib/plugins/authad/lang/ko/lang.php (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/lang/de/lang.php b/lib/plugins/authad/lang/de/lang.php new file mode 100644 index 000000000..3f275750c --- /dev/null +++ b/lib/plugins/authad/lang/de/lang.php @@ -0,0 +1,10 @@ + + */ + +$lang['domain'] = 'Anmelde-Domäne'; + +//Setup VIM: ex: et ts=4 : diff --git a/lib/plugins/authad/lang/en/lang.php b/lib/plugins/authad/lang/en/lang.php new file mode 100644 index 000000000..e2967d662 --- /dev/null +++ b/lib/plugins/authad/lang/en/lang.php @@ -0,0 +1,10 @@ + + */ + +$lang['domain'] = 'Logon Domain'; + +//Setup VIM: ex: et ts=4 : diff --git a/lib/plugins/authad/lang/ko/lang.php b/lib/plugins/authad/lang/ko/lang.php new file mode 100644 index 000000000..1aa436708 --- /dev/null +++ b/lib/plugins/authad/lang/ko/lang.php @@ -0,0 +1,10 @@ + + */ + +$lang['domain'] = '로그온 도메인'; + +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From a854a9a897ade35800abd440c29787ec8429c678 Mon Sep 17 00:00:00 2001 From: Joerg Date: Thu, 6 Mar 2014 10:46:06 +0100 Subject: translation update --- lib/plugins/authad/lang/de/lang.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/lang/de/lang.php b/lib/plugins/authad/lang/de/lang.php index 3f275750c..eea511d1b 100644 --- a/lib/plugins/authad/lang/de/lang.php +++ b/lib/plugins/authad/lang/de/lang.php @@ -1,10 +1,8 @@ */ - -$lang['domain'] = 'Anmelde-Domäne'; - -//Setup VIM: ex: et ts=4 : +$lang['domain'] = 'Anmelde-Domäne'; -- cgit v1.2.3 From 99327e8e4c6bc07af2ebfc62bffee62f35c34025 Mon Sep 17 00:00:00 2001 From: Juan De La Cruz Date: Thu, 6 Mar 2014 15:10:56 +0100 Subject: translation update --- lib/plugins/authad/lang/es/lang.php | 8 ++++++++ lib/plugins/authad/lang/es/settings.php | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 lib/plugins/authad/lang/es/lang.php (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/lang/es/lang.php b/lib/plugins/authad/lang/es/lang.php new file mode 100644 index 000000000..c5b242cba --- /dev/null +++ b/lib/plugins/authad/lang/es/lang.php @@ -0,0 +1,8 @@ + + */ +$lang['domain'] = 'Dominio de inicio'; diff --git a/lib/plugins/authad/lang/es/settings.php b/lib/plugins/authad/lang/es/settings.php index 98b78056b..9dbd44be8 100644 --- a/lib/plugins/authad/lang/es/settings.php +++ b/lib/plugins/authad/lang/es/settings.php @@ -5,6 +5,7 @@ * * @author monica * @author Antonio Bueno + * @author Juan De La Cruz */ $lang['account_suffix'] = 'Su cuenta, sufijo. Ejem. @ my.domain.org '; $lang['base_dn'] = 'Su base DN. Ejem. DC=my,DC=dominio,DC=org'; @@ -13,3 +14,4 @@ $lang['admin_username'] = 'Un usuario con privilegios de Active Directory $lang['admin_password'] = 'La contraseña del usuario anterior.'; $lang['sso'] = 'En caso de inicio de sesión usará ¿Kerberos o NTLM?'; $lang['sso_charset'] = 'La codificación con que tu servidor web pasará el nombre de usuario Kerberos o NTLM. Si es UTF-8 o latin-1 dejar en blanco. Requiere la extensión iconv.'; +$lang['debug'] = 'Mostrar información adicional de depuración sobre los errores?'; -- cgit v1.2.3 From 68321121b4d24c7489400c950afdbe6eba0f417d Mon Sep 17 00:00:00 2001 From: Aleksandr Selivanov Date: Tue, 11 Mar 2014 18:06:07 +0100 Subject: translation update --- lib/plugins/authad/lang/ru/lang.php | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 lib/plugins/authad/lang/ru/lang.php (limited to 'lib/plugins/authad') diff --git a/lib/plugins/authad/lang/ru/lang.php b/lib/plugins/authad/lang/ru/lang.php new file mode 100644 index 000000000..6f3c03e39 --- /dev/null +++ b/lib/plugins/authad/lang/ru/lang.php @@ -0,0 +1,8 @@ + + */ +$lang['domain'] = 'Домен'; -- cgit v1.2.3