From: Ben Klang Date: Fri, 8 Jul 2005 09:39:52 +0000 (+0000) Subject: More API changes, too tired to list X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b6c4f0493745e879de9e9560546cb05dec13d02b;p=horde.git More API changes, too tired to list git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@50 06cd67b6-e706-0410-b29e-9de616bca6e9 --- diff --git a/index.php b/index.php index 47ef0e3bf..1e2fb07ee 100644 --- a/index.php +++ b/index.php @@ -45,7 +45,7 @@ $tabs->preserve('context', $context); echo "
"; // if (!$section) { -// $section = +// $section = if (!$section) { $section = $tabs->_tabs[0]['tabname']; } @@ -55,6 +55,7 @@ switch ($section) { case "conference": case "dialplan": case "security": + case "system": case "users": case "moh": require "$section.php"; diff --git a/lib/Driver.php b/lib/Driver.php index 538c044a7..0f422b3c6 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -50,50 +50,10 @@ class Shout_Driver { */ function getContexts($filters = "all", $filterperms = null) { - # Initialize array to be returned - $retcontexts = array(); - - if ($filterperms == null) { - $filterperms = PERMS_SHOW|PERMS_READ; - } - - # Collect the master list of contexts from the backend - $contexts = $this->_getContexts($filters); - - - # Narrow down the list of contexts to those valid for this user. -// global $perms; -// -// $superadminPermName = "shout:superadmin"; -// if ($perms->exists($superadminPermName)) { -// $superadmin = $perms->getPermissions($superadminPermName) & -// ($filterperms); -// } else { -// $superadmin = 0; -// } -// -// foreach($contexts as $context) { -// $permName = "shout:contexts:".$context; -// if ($perms->exists($permName)) { -// $userperms = $perms->getPermissions($permName) & -// ($filterperms); -// } else { -// $userperms = 0; -// } -// -// if ((($userperms | $superadmin) ^ ($filterperms)) == 0) { -// $retcontexts[$context] = $context; -// } -// } - foreach ($contexts as $context) { - if (Shout::checkRights("shout:contexts:$context", $filterperms)) { - $retcontexts[] = $context; - } - } - return $retcontexts; + return PEAR::raiseError("This function is not implemented."); } // }}} - + // {{{ checkContextType /** * For the given context and type, make sure the context has the @@ -109,7 +69,7 @@ class Shout_Driver { */ function checkContextType($context, $type) { - return $this->_checkContextType($context, $type); + return PEAR::raiseError("This function is not implemented."); } //}}} @@ -124,10 +84,10 @@ class Shout_Driver { */ function getUsers($context) { - return $this->_getUsers($context); + return PEAR::raiseError("This function is not implemented."); } // }}} - + // {{{ getHomeContext method /** * Returns the name of the user's default context @@ -136,11 +96,25 @@ class Shout_Driver { */ function getHomeContext() { - return $this->_getHomeContext(); + return PEAR::raiseError("This function is not implemented."); } // }}} - - // {{{ getExtensions method + + // {{{ + /** + * Get a context's properties + * + * @param string $context Context to get properties for + * + * @return integer Bitfield of properties valid for this context + */ + function getContextProperties($context) + { + return PEAR::raiseError("This function is not implemented."); + } + // }}} + + // {{{ getExtensions method /** * Get a context's extensions and return as a multi-dimensional associative * array @@ -152,10 +126,10 @@ class Shout_Driver { */ function getDialplan($context) { - return $this->_getDialplan($context); + return PEAR::raiseError("This function is not implemented."); } // }}} - + // {{{ factory method /** * Attempts to return a concrete Shout_Driver instance based on diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php index f48a3fbbc..bde711962 100644 --- a/lib/Driver/ldap.php +++ b/lib/Driver/ldap.php @@ -42,39 +42,40 @@ class Shout_Driver_ldap extends Shout_Driver * * @access private */ - function _getContexts($filters = "all") + function getContexts($searchfilters = SHOUT_CONTEXT_ALL, + $filterperms = null) { + if ($filterperms == null) { + $filterperms = PERMS_SHOW|PERMS_READ; + } + # TODO Add caching mechanism here. Possibly cache results per # filter $this->contexts['customer'] and return either data # or possibly a reference to that data - if(!is_array($filters)) { - $tmp = $filters; - $filters = array(); - $filters[] = $tmp; - } - - $searchfilter = "(|"; - foreach ($filters as $filter) { - switch ($filter) { - case "customers": - $searchfilter.="(objectClass=vofficeCustomer)"; - break; - case "extensions": - $searchfilter.="(objectClass=asteriskExtensions)"; - break; - case "moh": - $searchfilter.="(objectClass=asteriskMusicOnHold)"; - break; - case "conference": - $searchfilter.="(objectClass=asteriskMeetMe)"; - break; - case "all": - default: - $searchfilter.="(objectClass=*)"; - break; + + # Determine which combination of contexts need to be returned + if ($searchfilters == SHOUT_CONTEXT_ALL) { + $searchfilter="(objectClass=*)"; + } else { + $searchfilter = "(|"; + if ($searchfilters & SHOUT_CONTEXT_CUSTOMERS) { + $searchfilter.="(objectClass=vofficeCustomer)"; + } + + if ($searchfilters & SHOUT_CONTEXT_EXTENSIONS) { + $searchfilter.="(objectClass=asteriskExtensions)"; + } + + if ($searchfilters & SHOUT_CONTEXT_MOH) { + $searchfilter.="(objectClass=asteriskMusicOnHold)"; + } + + if ($searchfilters & SHOUT_CONTEXT_CONFERENCE) { + $searchfilter.="(objectClass=asteriskMeetMe)"; } + $searchfilter .= ")"; } - $searchfilter .= ")"; + # Collect all the possible contexts from the backend $res = ldap_search($this->_LDAP, @@ -82,7 +83,7 @@ class Shout_Driver_ldap extends Shout_Driver "(&(objectClass=asteriskObject)$searchfilter)", array('context')); if (!$res) { - return PEAR::raiseError("Unable to locate any customers " . + return PEAR::raiseError("Unable to locate any contexts " . "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn'] . " matching those search filters"); } @@ -91,14 +92,17 @@ class Shout_Driver_ldap extends Shout_Driver $res = ldap_get_entries($this->_LDAP, $res); $i = 0; while ($i < $res['count']) { - $entries[] = $res[$i]['context'][0]; + $context = $res[$i]['context'][0]; + if (Shout::checkRights("shout:contexts:$context", $filterperms)) { + $entries[] = $context; + } $i++; } # return the array return $entries; } // }}} - + // {{{ _checkContextType method /** * For the given context and type, make sure the context has the @@ -112,7 +116,7 @@ class Shout_Driver_ldap extends Shout_Driver * * @access public */ - function _checkContextType($context, $type) { + function checkContextType($context, $type) { switch ($type) { case "users": $searchfilter = "(objectClass=vofficeCustomer)"; @@ -140,7 +144,7 @@ class Shout_Driver_ldap extends Shout_Driver return PEAR::raiseError("Unable to search directory for context type"); } - + $res = ldap_get_entries($this->_LDAP, $res); if (!$res) { return PEAR::raiseError("Unable to get results from LDAP query"); @@ -162,7 +166,7 @@ type"); * * @return array User information indexed by voice mailbox number */ - function _getUsers($context) + function getUsers($context) { $search = ldap_search($this->_LDAP, SHOUT_USERS_BRANCH.','.$this->_params['basedn'], @@ -211,14 +215,14 @@ type"); return $entries; } // }}} - + // {{{ _getHomeContext method /** * Returns the name of the user's default context * * @return string User's default context */ - function _getHomeContext() + function getHomeContext() { $res = ldap_search($this->_LDAP, SHOUT_USERS_BRANCH.','.$this->_params['basedn'], @@ -231,12 +235,62 @@ type"); } $res = ldap_get_entries($this->_LDAP, $res); - + # Assume the user only has one context. The schema encforces this return $res[0]['context'][0]; } // }}} - + + // {{{ + /** + * Get a context's properties + * + * @param string $context Context to get properties for + * + * @return integer Bitfield of properties valid for this context + */ + function getContextProperties($context) + { + + $res = ldap_search($this->_LDAP, + SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], + "(&(objectClass=asteriskObject)(context=$context))", + array('objectClass')); + if(!$res) { + return PEAR::raiseError(_("Unable to get properties for $context")); + } + + $res = ldap_get_entries($this->_LDAP, $res); + + $properties = 0; + if ($res['count'] != 1) { + return PEAR::raiseError(_("Incorrect number of properties found +for $context")); + } + + foreach ($res[0]['objectclass'] as $objectClass) { + switch ($objectClass) { + case "vofficeCustomer": + $properties = $properties | SHOUT_CONTEXT_CUSTOMERS; + break; + + case "asteriskExtensions": + $properties = $properties | SHOUT_CONTEXT_EXTENSIONS; + break; + + case "asteriskMusicOnHold": + $properties = $properties | SHOUT_CONTEXT_MOH; + break; + + case "asteriskMeetMe": + $properties = $properties | SHOUT_CONTEXT_CONFERENCE; + break; + } + } + return $properties; + } + // }}} + // {{{ _getDialplan method /** * Get a context's dialplan and return as a multi-dimensional associative @@ -247,7 +301,7 @@ type"); * @return array Multi-dimensional associative array of extensions data * */ - function _getDialplan($context) + function getDialplan($context) { $res = ldap_search($this->_LDAP, SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], @@ -270,18 +324,18 @@ type"); $j = 0; while ($j < $res[$i]['asteriskextensionline']['count']) { @$line = $res[$i]['asteriskextensionline'][$j]; - + # Basic sanity check for length. FIXME if (strlen($line) < 5) { break; } # Can't use strtok here because there may be ','s in the arg # string - + # Get the extension $token1 = strpos($line, ','); $token2 = strpos($line, ',', $token1 + 1); - + $extension = substr($line, 0, $token1); if (!isset($retdialplan[$extension])) { $retdialplan[$extension] = array(); @@ -291,16 +345,16 @@ type"); $priority = substr($line, $token1, $token2 - $token1); $retdialplan[$extension][$priority] = array(); $token2++; - + # Get Application and args $application = substr($line, $token2); - + # Merge all that data into the returning array $retdialplan['extensions'][$extension][$priority] = $application; $j++; } - + # Sort the extensions data foreach ($retdialplan['extensions'] as $extension) { ksort($extension); @@ -316,7 +370,7 @@ type"); $j++; } } - + # Handle ignorepat if (isset($res[$i]['asteriskignorepat'])) { $j = 0; @@ -335,7 +389,7 @@ type"); $j++; } } - + # Increment object $i++; } diff --git a/lib/Shout.php b/lib/Shout.php index 7088a11d6..6b46e2c3c 100644 --- a/lib/Shout.php +++ b/lib/Shout.php @@ -4,6 +4,12 @@ @define(SHOUT_USERS_BRANCH, "ou=Customers"); @define(SHOUT_USER_OBJECTCLASS, "asteriskUser"); +@define(SHOUT_CONTEXT_ALL, 0); +@define(SHOUT_CONTEXT_CUSTOMERS, 1 << 0); +@define(SHOUT_CONTEXT_EXTENSIONS, 1 << 1); +@define(SHOUT_CONTEXT_MOH, 1 << 2); +@define(SHOUT_CONTEXT_CONFERENCE, 1 << 3); + // {{{ Class Shout class Shout { @@ -70,36 +76,41 @@ null, $cellclass); if (!Auth::isAdmin("shout", PERMS_SHOW|PERMS_READ)) { return false; } - + $permprefix = "shout:contexts:$context"; $tabs = &new Horde_UI_Tabs('section', $vars); - + if (Shout::checkRights("$permprefix:users") && $shout->checkContextType($context, "users")) { $tabs->addTab(_("Users"), Horde::applicationUrl("index.php?context=$context"), 'users'); } - + if (Shout::checkRights("$permprefix:dialplan") && $shout->checkContextType($context, "dialplan")) { $tabs->addTab(_("Dial Plan"), Horde::applicationUrl('index.php'), 'dialplan'); } - + if (Shout::checkRights("$permprefix:conference") && $shout->checkContextType($context, "conference")) { $tabs->addTab(_("Conference Rooms"), Horde::applicationUrl('index.php'), 'conference'); } - + if (Shout::checkRights("$permprefix:moh") && $shout->checkContextType($context, "moh")) { $tabs->addTab(_("Music on Hold"), Horde::applicationUrl('index.php'), 'moh'); } - + + if (Auth::isAdmin("shout:system", PERMS_SHOW|PERMS_READ)) { + $tabs->addTab(_("System Settings"), + Horde::applicationUrl('index.php'), 'system'); + } + if (Auth::isAdmin("shout:superadmin", PERMS_SHOW|PERMS_READ)) { $tabs->addTab(_("Security"), Horde::applicationUrl('index.php'), 'security'); @@ -108,12 +119,12 @@ null, $cellclass); return $tabs; } - function checkRights($permname, $permmask = null) + function checkRights($permname, $permmask = null) { if ($permmask == null) { $permmask = PERMS_SHOW|PERMS_READ; } - + $superadmin = Auth::isAdmin("shout:superadmin", $permmask); $user = Auth::isAdmin($permname, $permmask); $test = $superadmin | $user; @@ -123,5 +134,43 @@ null, $cellclass); return FALSE; } } + + function getContextTypes() + { + return array(SHOUT_CONTEXT_CUSTOMERS => _("Customers"), + SHOUT_CONTEXT_EXTENSIONS => _("Dialplan"), + SHOUT_CONTEXT_MOH => _("Music On Hold"), + SHOUT_CONTEXT_CONFERENCE => _("Conference Calls")); + } + + /** + * Given an integer value of permissions returns an array + * representation of the integer. + * + * @param integer $int The integer representation of permissions. + */ + function integerToArray($int) + { + static $array = array(); + if (isset($array[$int])) { + return $array[$int]; + } + + $array[$int] = array(); + + /* Get the available perms array. */ + $types = Shout::getContextTypes(); + + /* Loop through each perm and check if its value is included in the + * integer representation. */ + foreach ($types as $val => $label) { + if ($int & $val) { + $array[$int][$val] = true; + } + } + + return $array[$int]; + } + } // }}} \ No newline at end of file diff --git a/shout.webprj b/shout.webprj index 873e62f64..12a188b33 100644 --- a/shout.webprj +++ b/shout.webprj @@ -9,42 +9,44 @@ - - - - + + + + - - + + - + - + - + + - + - + + - + - + - - + + - - + + @@ -65,7 +67,7 @@ -//w3c//dtd xhtml 1.0 strict//en - + Ben Klang ben@alkaloid.net Gubed @@ -76,17 +78,19 @@ - - - + + + - - + + - - - + + + + + diff --git a/templates/menu.inc b/templates/menu.inc index 8e15fa842..76ecabc6d 100644 --- a/templates/menu.inc +++ b/templates/menu.inc @@ -12,7 +12,7 @@ $menu_view = $prefs->getValue('menu_view');