From: Ben Klang Date: Sat, 2 Jan 2010 18:24:06 +0000 (-0500) Subject: Shout: remove deprecated code X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=472c7e7e1c0af66d6270c2fcd2965601902fed20;p=horde.git Shout: remove deprecated code --- diff --git a/shout/lib/Driver/Ldap.php b/shout/lib/Driver/Ldap.php index 57763be6d..bef003c5f 100644 --- a/shout/lib/Driver/Ldap.php +++ b/shout/lib/Driver/Ldap.php @@ -28,43 +28,6 @@ class Shout_Driver_Ldap extends Shout_Driver { parent::__construct($params); $this->_connect(); - - /* These next lines will translate between indexes used in the - * application and LDAP. The rationale is that translation here will - * help make Congregation more driver-independant. The keys used to - * contruct user arrays should be more appropriate to human-legibility - * (name instead of 'cn' and email instead of 'mail'). This translation - * is only needed because LDAP indexes users based on an arbitrary - * attribute and the application indexes by extension/context. In my - * environment users are indexed by their 'mail' attribute and others - * may index based on 'cn' or 'uid'. Any time a new $prefs['uid'] needs - * to be supported, this function should be checked and possibly - * extended to handle that translation. - */ - switch($this->_params['uid']) { - case 'cn': - $this->_ldapKey = 'cn'; - $this->_appKey = 'name'; - break; - case 'mail': - $this->_ldapKey = 'mail'; - $this->_appKey = 'email'; - break; - case 'uid': - # FIXME Probably a better app key to map here - # There is no value that maps uid to LDAP so we can choose to use - # either extension or name, or anything really. I want to - # support it since it's a very common DN attribute. - # Since it's entirely administrator's preference, I'll - # set it to name for now - $this->_ldapKey = 'uid'; - $this->_appKey = 'name'; - break; - case 'voiceMailbox': - $this->_ldapKey = 'voiceMailbox'; - $this->_appKey = 'extension'; - break; - } } /** @@ -222,267 +185,6 @@ class Shout_Driver_Ldap extends Shout_Driver } /** - * Get a context's dialplan and return as a multi-dimensional associative - * array - * - * @param string $context Context to return extensions for - * - * @param boolean $preprocess Parse includes and barelines and add their - * information into the extensions array - * - * @return array Multi-dimensional associative array of extensions data - * - */ - public function getDialplan($context, $preprocess = false) - { - # FIXME Implement preprocess functionality. Don't forget to cache! - static $dialplans = array(); - if (isset($dialplans[$context])) { - return $dialplans[$context]; - } - - $res = @ldap_search($this->_LDAP, - SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], - "(&(objectClass=".SHOUT_CONTEXT_EXTENSIONS_OBJECTCLASS.")(context=$context))", - array(SHOUT_DIALPLAN_EXTENSIONLINE_ATTRIBUTE, SHOUT_DIALPLAN_INCLUDE_ATTRIBUTE, - SHOUT_DIALPLAN_IGNOREPAT_ATTRIBUTE, 'description', - SHOUT_DIALPLAN_BARELINE_ATTRIBUTE)); - if (!$res) { - return PEAR::raiseError("Unable to locate any extensions " . - "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn'] . - " matching those search filters"); - } - - $res = ldap_get_entries($this->_LDAP, $res); - $dialplans[$context] = array(); - $dialplans[$context]['name'] = $context; - $i = 0; - while ($i < $res['count']) { - # Handle extension lines - if (isset($res[$i][strtolower(SHOUT_DIALPLAN_EXTENSIONLINE_ATTRIBUTE)])) { - $j = 0; - while ($j < $res[$i][strtolower(SHOUT_DIALPLAN_EXTENSIONLINE_ATTRIBUTE)]['count']) { - @$line = $res[$i][strtolower(SHOUT_DIALPLAN_EXTENSIONLINE_ATTRIBUTE)][$j]; - - # Basic sanity check for length. FIXME - if (strlen($line) < 5) { - break; - } - # Can't use strtok here because there may be commass in the - # arg string - - # Get the extension - $token1 = strpos($line, ','); - $token2 = strpos($line, ',', $token1 + 1); - $token3 = strpos($line, '(', $token2 + 1); - - $extension = substr($line, 0, $token1); - if (!isset($dialplans[$context]['extensions'][$extension])) { - $dialplan[$context]['extensions'][$extension] = array(); - } - $token1++; - # Get the priority - $priority = substr($line, $token1, $token2 - $token1); - $dialplans[$context]['extensions'][$extension][$priority] = - array(); - $token2++; - - # Get Application and args - $application = substr($line, $token2, $token3 - $token2); - - if ($token3) { - $application = substr($line, $token2, $token3 - $token2); - $args = substr($line, $token3); - $args = preg_replace('/^\(/', '', $args); - $args = preg_replace('/\)$/', '', $args); - } else { - # This application must not have any args - $application = substr($line, $token2); - $args = ''; - } - - # Merge all that data into the returning array - $dialplans[$context]['extensions'][$extension][$priority]['application'] = - $application; - $dialplans[$context]['extensions'][$extension][$priority]['args'] = - $args; - $j++; - } - - # Sort the extensions data - foreach ($dialplans[$context]['extensions'] as - $extension => $data) { - ksort($dialplans[$context]['extensions'][$extension]); - } - uksort($dialplans[$context]['extensions'], - array(new Shout, "extensort")); - } - # Handle include lines - if (isset($res[$i]['asteriskincludeline'])) { - $j = 0; - while ($j < $res[$i]['asteriskincludeline']['count']) { - @$line = $res[$i]['asteriskincludeline'][$j]; - $dialplans[$context]['includes'][$j] = $line; - $j++; - } - } - - # Handle ignorepat - if (isset($res[$i]['asteriskignorepat'])) { - $j = 0; - while ($j < $res[$i]['asteriskignorepat']['count']) { - @$line = $res[$i]['asteriskignorepat'][$j]; - $dialplans[$context]['ignorepats'][$j] = $line; - $j++; - } - } - # Handle ignorepat - if (isset($res[$i]['asteriskextensionbareline'])) { - $j = 0; - while ($j < $res[$i]['asteriskextensionbareline']['count']) { - @$line = $res[$i]['asteriskextensionbareline'][$j]; - $dialplans[$context]['barelines'][$j] = $line; - $j++; - } - } - - # Increment object - $i++; - } - return $dialplans[$context]; - } - - /** - * Get the limits for the current user, the user's context, and global - * Return the most specific values in every case. Return default values - * where no data is found. If $extension is specified, $context must - * also be specified. - * - * @param optional string $context Context to search - * - * @param optional string $extension Extension/user to search - * - * @return array Array with elements indicating various limits - */ - # FIXME Figure out how this fits into Shout/Congregation better - public function getLimits($context = null, $extension = null) - { - - $limits = array('telephonenumbersmax', - 'voicemailboxesmax', - 'asteriskusersmax'); - - if(!is_null($extension) && is_null($context)) { - return PEAR::raiseError("Extension specified but no context " . - "given."); - } - - if (!is_null($context) && isset($limits[$context])) { - if (!is_null($extension) && - isset($limits[$context][$extension])) { - return $limits[$context][$extension]; - } - return $limits[$context]; - } - - # Set some default limits (to unlimited) - static $cachedlimits = array(); - # Initialize the limits with defaults - if (count($cachedlimits) < 1) { - foreach ($limits as $limit) { - $cachedlimits[$limit] = 99999; - } - } - - # Collect the global limits - $res = @ldap_search($this->_LDAP, - SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], - '(&(objectClass=asteriskLimits)(cn=globals))', - $limits); - - if (!$res) { - return PEAR::raiseError('Unable to search the LDAP server for ' . - 'global limits'); - } - - $res = ldap_get_entries($this->_LDAP, $res); - # There should only have been one object returned so we'll just take the - # first result returned - if ($res['count'] > 0) { - foreach ($limits as $limit) { - if (isset($res[0][$limit][0])) { - $cachedlimits[$limit] = $res[0][$limit][0]; - } - } - } else { - return PEAR::raiseError("No global object found."); - } - - # Get limits for the context, if provided - if (isset($context)) { - $res = ldap_search($this->_LDAP, - SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], - "(&(objectClass=asteriskLimits)(cn=$context))"); - - if (!$res) { - return PEAR::raiseError('Unable to search the LDAP server ' . - "for $context specific limits"); - } - - $cachedlimits[$context][$extension] = array(); - if ($res['count'] > 0) { - foreach ($limits as $limit) { - if (isset($res[0][$limit][0])) { - $cachedlimits[$context][$limit] = $res[0][$limit][0]; - } else { - # If no value is provided use the global limit - $cachedlimits[$context][$limit] = $cachedlimits[$limit]; - } - } - } else { - - foreach ($limits as $limit) { - $cachedlimits[$context][$limit] = - $cachedlimits[$limit]; - } - } - - if (isset($extension)) { - $res = @ldap_search($this->_LDAP, - SHOUT_USERS_BRANCH.','.$this->_params['basedn'], - "(&(objectClass=asteriskLimits)(voiceMailbox=$extension)". - "(context=$context))"); - - if (!$res) { - return PEAR::raiseError('Unable to search the LDAP server '. - "for Extension $extension, $context specific limits"); - } - - $cachedlimits[$context][$extension] = array(); - if ($res['count'] > 0) { - foreach ($limits as $limit) { - if (isset($res[0][$limit][0])) { - $cachedlimits[$context][$extension][$limit] = - $res[0][$limit][0]; - } else { - # If no value is provided use the context limit - $cachedlimits[$context][$extension][$limit] = - $cachedlimits[$context][$limit]; - } - } - } else { - foreach ($limits as $limit) { - $cachedlimits[$context][$extension][$limit] = - $cachedlimits[$context][$limit]; - } - } - return $cachedlimits[$context][$extension]; - } - return $cachedlimits[$context]; - } - } - - /** * Save an extension to the LDAP tree * * @param string $context Context to which the user should be added @@ -647,15 +349,6 @@ class Shout_Driver_Ldap extends Shout_Driver return $dn; } - /* Needed because uksort can't take a classed function as its callback arg */ - protected function _sortexten($e1, $e2) - { - print "$e1 and $e2\n"; - $ret = Shout::extensort($e1, $e2); - print "returning $ret"; - return $ret; - } - /** * Attempts to open a connection to the LDAP server. *