From afe6a9b3b1d9a61de92d0b8a62925dbd752a829f Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Wed, 20 Jul 2005 04:41:54 +0000 Subject: [PATCH] Added LDAP based limit support. Also will need new schema file currently on Marconi. Still no save support (coming soon...) git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@69 06cd67b6-e706-0410-b29e-9de616bca6e9 --- lib/Driver/ldap.php | 169 ++++++++++++++++++++++++++++++++++++++-------------- lib/User.php | 37 +++++++++--- shout.webprj | 22 +++---- users/edit.php | 3 +- users/save.php | 10 ++++ 5 files changed, 174 insertions(+), 67 deletions(-) diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index b9b3b1b67..dea475c89 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -270,7 +270,9 @@ type"); $res = ldap_get_entries($this->_LDAP, $res); - # Assume the user only has one context. The schema encforces this + # Assume the user only has one context. The schema enforces this + # FIXME: Handle cases where the managing user isn't a valid telephone + # system user return $res[0]['context'][0]; } // }}} @@ -436,60 +438,135 @@ for $context")); return $dialplans[$context]; } // }}} - - // {{{ getUserPhoneNumbers method + + // {{{ /** - * Get a list of phone numbers for the given user from the backend + * 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 string $extension Extension on which to search + * @param optional string $context Context to search * - * @param string $context Context for which this user is valid + * @param optional string $extension Extension/user to search * - * @return array Phone numbers for this user - * - * @access public + * @return array Array with elements indicating various limits */ - function getUserPhoneNumbers($extension, $context = null) + function &getLimits($context = null, $extension = null) { - $userfilter = "(".$this->userkey."=".$username.",". - $this->usersOU.",".$this->_params['basedn'].")"; - $searchfilter = "(&".$userfilter; - foreach ($prefs["searchfilters"]["phoneuser"] as $filter) { - $searchfilter .= "($filter)"; + + $limits = array('telephonenumbersmax', + 'voicemailboxesmax', + 'asteriskusers'); + + if(is_null($extension) && !is_null($context)) { + return PEAR::raiseError("Extension specified but no context " . + "given."); } - $searchfilter .= ")"; - - $res = ldap_search($this->_LDAP, $this->_params['basedn'], -$searchfilter, - array("userNumber")); - if (!res) { - return PEAR::raiseError("Unable to locate any LDAP entries for -$searchfilter under ".$this->_params['basedn']); + + if (!is_null($context) && array_key_exists($context, $limits)) { + if (!is_null($extension) && + array_key_exists($extension, $limits[$context])) { + 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] = -1; + } + } + + # 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."); } - // FIXME - } - // {{{ getUserVoicemailInfo method - /** - * Get the named user's voicemail particulars from LDAP - * - * @param string $extension Extension for which voicemail information should - * be returned - * @param optional string $context Context to which this extension belongs - * - * @return array Array containing voicemail options, user's name, email - * and pager addresses and PIN number - * - * @access public - */ - function getUserVoicemailInfo($extension, $context = null) - { - $userfilter = "(&(objectClass=asteriskVoiceMailbox)(context=$context))"; - $res = ldap_search($this->_LDAP, $this->_params['basedn'], -$userfilter, - array('asteriskVoiceMailboxOptions', 'mail', 'asteriskPager', - 'voiceMailboxPin', 'cn')); - return $res; + # 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]; + } } // }}} diff --git a/lib/User.php b/lib/User.php index b0f979e90..62604958e 100644 --- a/lib/User.php +++ b/lib/User.php @@ -9,6 +9,22 @@ * * @package Shout */ + +// {{{ Shout_User class +/** + * Class defining a single Asterisk user + * + * @package Shout + */ +class Shout_User { + var $_name; + var $_extension; + var $_email; + var $_pager; + var $_pin; +} + + // {{{ class UserDetailsForm extends Horde_Form { @@ -22,11 +38,13 @@ class UserDetailsForm extends Horde_Form { if (array_key_exists($extension, $users)) { # We must be editing an existing user $this->fillUserForm(&$vars, $users[$extension]); + $limits = &$shout->getLimits($context, $extension); $formtitle = "Edit User"; } else { + $limits = &$shout->getLimits($context); $formtitle = "Add User"; } - + parent::Horde_Form($vars, _("$formtitle - Context: $context")); $this->addHidden('', 'context', 'text', true); @@ -40,14 +58,15 @@ class UserDetailsForm extends Horde_Form { # TODO: Integrate with To-Be-Written user manager and possibly make this # TODO: new user also an email account. $this->addVariable(_("PIN"), 'pin', 'int', true); - $this->addVariable(_("Telephone Number 1:"), 'telephone1', 'text', - false); - $this->addVariable(_("Telephone Number 2:"), 'telephone2', 'text', - false); - $this->addVariable(_("Telephone Number 3:"), 'telephone3', 'text', - false); - $this->addVariable(_("Telephone Number 4:"), 'telephone4', 'text', - false); + + $t = 1; + while ($t <= $limits['telephonenumbersmax']) { + $this->addVariable(_("Telephone Number $t:"), "telephone$t", +'text', + false); + $t++; + } + $this->addVariable(_("Music on Hold while transferring"), 'moh', 'radio', true, false, null, array('values' => array(true => 'Yes', false => 'No'))); diff --git a/shout.webprj b/shout.webprj index 738ac88e5..5c115564d 100644 --- a/shout.webprj +++ b/shout.webprj @@ -9,7 +9,7 @@ - + @@ -28,12 +28,12 @@ - + - + @@ -71,9 +71,9 @@ - + - + @@ -118,16 +118,16 @@ - + - + - + @@ -135,9 +135,9 @@ - - - + + + diff --git a/users/edit.php b/users/edit.php index 35d317244..5ecc311bb 100644 --- a/users/edit.php +++ b/users/edit.php @@ -23,8 +23,9 @@ $UserDetailsForm = &Horde_Form::singleton('UserDetailsForm', $vars); $UserDetailsFormValid = $UserDetailsForm->validate($vars, true); $UserDetailsForm->open($RENDERER, $vars, 'users.php', 'post'); +$vars->set('section', $section); $UserDetailsForm->preserveVarByPost($vars, "section"); -$UserDetailsForm->preserve($vars); +// $UserDetailsForm->preserve($vars); require SHOUT_TEMPLATES . '/table-limiter-begin.inc'; $RENDERER->beginActive($UserDetailsForm->getTitle()); $RENDERER->renderFormActive($UserDetailsForm, $vars); diff --git a/users/save.php b/users/save.php index b2abc9786..e1813f32f 100644 --- a/users/save.php +++ b/users/save.php @@ -23,5 +23,15 @@ $UserDetailsForm = &Horde_Form::singleton('UserDetailsForm', $vars); $UserDetailsFormValid = $UserDetailsForm->validate($vars, true); if (!$UserDetailsFormValid) { # FIXME Handle invalid forms gracefully + echo "Invalid Form!"; } +$oldextension = Util::getFormData('oldextension'); +$extension = Util::getFormData('extension'); + +#$user = &new Shout_User(); + +#$user->define($context, $oldextension); +#$user->set('name', Util::getFormData('name')); +#$user->set('extension', Util::getFormData('extension')); +#$user->set('telephone' -- 2.11.0