diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php new file mode 100644 index 00000000000..1751f57f503 --- /dev/null +++ b/apps/user_ldap/lib/helper.php @@ -0,0 +1,66 @@ +. + * + */ + +namespace OCA\user_ldap\lib; + +class Helper { + + /** + * @brief returns prefixes for each saved LDAP/AD server configuration. + * @return array with a list of the available prefixes + * + * Configuration prefixes are used to set up configurations for n LDAP or + * AD servers. Since configuration is stored in the database, table + * appconfig under appid user_ldap, the common identifiers in column + * 'configkey' have a prefix. The prefix for the very first server + * configuration is empty. + * Configkey Examples: + * Server 1: ldap_login_filtter + * Server 2: s1_ldap_login_filter + * Server 3: s2_ldap_login_filter + * + * The prefix needs to be passed to the constructor of Connection class, + * except the default (first) server shall be connected to. + * + */ + static public function getServerConfigurationPrefixes() { + $referenceConfigkey = 'ldap_login_filter'; + + $query = \OCP\DB::prepare(' + SELECT DISTINCT `configkey` + FROM `*PREFIX*appconfig` + WHERE `configkey` LIKE ? + '); + + $serverConfigs = $query->execute(array('%'.$referenceConfigkey))->fetchAll(); + $prefixes = array(); + + foreach($serverConfigs as $serverConfig) { + $len = strlen($serverConfig['configkey']) - strlen($referenceConfigkey); + $prefixes[] = substr($serverConfig['configkey'], 0, $len); + } + + return $prefixes; + } +} +