More API changes, too tired to list
authorBen Klang <ben@alkaloid.net>
Fri, 8 Jul 2005 09:39:52 +0000 (09:39 +0000)
committerBen Klang <ben@alkaloid.net>
Fri, 8 Jul 2005 09:39:52 +0000 (09:39 +0000)
git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@50 06cd67b6-e706-0410-b29e-9de616bca6e9

index.php
lib/Driver.php
lib/Driver/ldap.php
lib/Shout.php
shout.webprj
templates/menu.inc

index 47ef0e3..1e2fb07 100644 (file)
--- a/index.php
+++ b/index.php
@@ -45,7 +45,7 @@ $tabs->preserve('context', $context);
 
 echo "<br />";
 // 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";
index 538c044..0f422b3 100644 (file)
@@ -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
index f48a3fb..bde7119 100644 (file)
@@ -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++;
         }
index 7088a11..6b46e2c 100644 (file)
@@ -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
index 873e62f..12a188b 100644 (file)
@@ -9,42 +9,44 @@
     <item url="templates/" uploadstatus="2" />
     <item url="lib/" uploadstatus="2" />
     <item url="lib/Driver/" uploadstatus="2" />
-    <item modified_time="1120357513" url="lib/Driver/ldap.php" uploadstatus="2" />
-    <item modified_time="1120589135" url="lib/base.php" uploadstatus="2" />
-    <item modified_time="1120456298" url="lib/Driver.php" uploadstatus="2" />
-    <item modified_time="1120585169" url="index.php" uploadstatus="2" />
+    <item modified_time="1120808744" url="lib/Driver/ldap.php" uploadstatus="2" />
+    <item modified_time="1120792108" url="lib/base.php" uploadstatus="2" />
+    <item modified_time="1120799748" url="lib/Driver.php" uploadstatus="2" />
+    <item modified_time="1120793382" url="index.php" uploadstatus="2" />
     <uploadprofiles showtreeviews="true" defaultProfile="Shout" >
       <profile remote_host="picasso.v-office.biz" remote_port="" remote_path="/srv/vhost/users/aklang/sites/intranet.v-office.biz/shout" remote_protocol="sftp" user="aklang" name="Shout" >
         <uploadeditem upload_time="0" url="config/" />
         <uploadeditem upload_time="1120073766" url="config/conf.xml" />
         <uploadeditem upload_time="1120183942" url="contexts.php" />
-        <uploadeditem upload_time="1120355053" url="dialplan.php" />
-        <uploadeditem upload_time="1120585169" url="index.php" />
+        <uploadeditem upload_time="1120648621" url="dialplan.php" />
+        <uploadeditem upload_time="1120793382" url="index.php" />
         <uploadeditem upload_time="1120021874" url="index.php~" />
         <uploadeditem upload_time="0" url="lib/" />
-        <uploadeditem upload_time="1120456298" url="lib/Driver.php" />
+        <uploadeditem upload_time="1120799748" url="lib/Driver.php" />
         <uploadeditem upload_time="1120022560" url="lib/Driver.php~" />
         <uploadeditem upload_time="0" url="lib/Driver/" />
-        <uploadeditem upload_time="1120357513" url="lib/Driver/ldap.php" />
+        <uploadeditem upload_time="1120808744" url="lib/Driver/ldap.php" />
         <uploadeditem upload_time="1120026921" url="lib/Driver/ldap.php~" />
         <uploadeditem upload_time="1120288491" url="lib/SelectContext.php" />
-        <uploadeditem upload_time="1120357628" url="lib/Shout.php" />
+        <uploadeditem upload_time="1120812478" url="lib/Shout.php" />
+        <uploadeditem upload_time="1120812245" url="lib/System.php" />
         <uploadeditem upload_time="1120279975" url="lib/Users.php" />
-        <uploadeditem upload_time="1120589135" url="lib/base.php" />
+        <uploadeditem upload_time="1120792108" url="lib/base.php" />
         <uploadeditem upload_time="1120073766" url="lib/defines.php" />
-        <uploadeditem upload_time="1120287842" url="moh.php" />
+        <uploadeditem upload_time="1120296517" url="moh.php" />
         <uploadeditem upload_time="1120027019" url="shout.webprj" />
+        <uploadeditem upload_time="1120811068" url="system.php" />
         <uploadeditem upload_time="0" url="templates/" />
-        <uploadeditem upload_time="1120174958" url="templates/common-header.inc" />
+        <uploadeditem upload_time="1120158044" url="templates/common-header.inc" />
         <uploadeditem upload_time="1120073766" url="templates/content_page" />
         <uploadeditem upload_time="0" url="templates/context/" />
-        <uploadeditem upload_time="1120175005" url="templates/context/contextline.inc" />
+        <uploadeditem upload_time="1120169761" url="templates/context/contextline.inc" />
         <uploadeditem upload_time="0" url="templates/dialplan/" />
-        <uploadeditem upload_time="1120377494" url="templates/dialplan/dialplanlist.inc" />
-        <uploadeditem upload_time="1120357382" url="templates/menu.inc" />
+        <uploadeditem upload_time="1120648933" url="templates/dialplan/dialplanlist.inc" />
+        <uploadeditem upload_time="1120798154" url="templates/menu.inc" />
         <uploadeditem upload_time="0" url="templates/users/" />
-        <uploadeditem upload_time="1120378861" url="templates/users/userlist.inc" />
-        <uploadeditem upload_time="1120456715" url="users.php" />
+        <uploadeditem upload_time="1120648933" url="templates/users/userlist.inc" />
+        <uploadeditem upload_time="1120792108" url="users.php" />
       </profile>
     </uploadprofiles>
     <debuggers>
@@ -65,7 +67,7 @@
     <defaultDTD>-//w3c//dtd xhtml 1.0 strict//en</defaultDTD>
     <item modified_time="1120073766" url="config/conf.xml" uploadstatus="1" />
     <item url="config/" uploadstatus="1" />
-    <item modified_time="1120357628" url="lib/Shout.php" uploadstatus="1" />
+    <item modified_time="1120812478" url="lib/Shout.php" uploadstatus="1" />
     <author>Ben Klang</author>
     <email>ben@alkaloid.net</email>
     <debuggerclient>Gubed</debuggerclient>
       <mailinglist address="" />
     </teamdata>
     <events/>
-    <item modified_time="1120174958" url="templates/common-header.inc" uploadstatus="1" />
-    <item modified_time="1120357382" url="templates/menu.inc" uploadstatus="1" />
-    <item modified_time="1120456715" url="users.php" uploadstatus="1" />
+    <item modified_time="1120158044" url="templates/common-header.inc" uploadstatus="1" />
+    <item modified_time="1120798154" url="templates/menu.inc" uploadstatus="1" />
+    <item modified_time="1120792108" url="users.php" uploadstatus="1" />
     <item url="templates/context/" uploadstatus="1" />
-    <item modified_time="1120175005" url="templates/context/contextline.inc" uploadstatus="1" />
-    <item modified_time="1120287842" url="moh.php" uploadstatus="1" />
+    <item modified_time="1120169761" url="templates/context/contextline.inc" uploadstatus="1" />
+    <item modified_time="1120296517" url="moh.php" uploadstatus="1" />
     <item url="templates/users/" uploadstatus="1" />
-    <item modified_time="1120378861" url="templates/users/userlist.inc" uploadstatus="1" />
-    <item modified_time="1120355053" url="dialplan.php" uploadstatus="1" />
-    <item modified_time="1120377494" url="templates/dialplan/dialplanlist.inc" uploadstatus="1" />
+    <item modified_time="1120648933" url="templates/users/userlist.inc" uploadstatus="1" />
+    <item modified_time="1120648621" url="dialplan.php" uploadstatus="1" />
+    <item modified_time="1120648933" url="templates/dialplan/dialplanlist.inc" uploadstatus="1" />
     <item url="templates/dialplan/" uploadstatus="1" />
+    <item modified_time="1120811068" url="system.php" />
+    <item modified_time="1120812245" url="lib/System.php" />
     <treestatus>
       <openfolder url="config" />
       <openfolder url="lib" />
index 8e15fa8..76ecabc 100644 (file)
@@ -12,7 +12,7 @@ $menu_view = $prefs->getValue('menu_view');
    <label for="context" accesskey="<?php echo $accesskey ?>">
     <select id="context" name="context" onchange="contextSubmit()">
      <?php
-        foreach ($shout->getContexts("customers") as $item) {
+        foreach ($shout->getContexts(SHOUT_CONTEXT_CUSTOMERS) as $item) {
             print "<option name=\"$item\"";
             if ($item == $context) {
                 print " selected";