Overview

Packages

  • None
  • Shout

Classes

  • AccountDetailsForm
  • ConferenceDetailsForm
  • DeviceDetailsForm
  • ExtensionDetailsForm
  • MenuForm
  • NumberDetailsForm
  • RecordingDetailsForm
  • Shout
  • Shout_Ajax_Application
  • Shout_Driver
  • Shout_Driver_Ldap
  • Shout_Driver_Sql
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Shout:: defines an set of utility methods for the Shout application.
  4:  *
  5:  * Copyright 2005-2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
  6:  *
  7:  * See the enclosed file COPYING for license information (BSD). If you
  8:  * did not receive this file, see
  9:  * http://www.opensource.org/licenses/bsd-license.php.
 10:  *
 11:  * @author  Ben Klang <ben@alkaloid.net>
 12:  * @package Shout
 13:  */
 14: class Shout
 15: {
 16:     /**
 17:      * @var string default menu, used for creating initial menu
 18:      */
 19:     const MAIN_MENU = 'Main Menu';
 20: 
 21:     /**
 22:      *
 23:      * @var string default recording, used for creating initial menu
 24:      */
 25:     const MAIN_RECORDING = 'main_menu';
 26: 
 27:     var $applist = array();
 28:     var $_applist_curapp = '';
 29:     var $_applist_curfield = '';
 30: 
 31:     /**
 32:      * Build Shout's list of menu items.
 33:      *
 34:      * @access public
 35:      */
 36:     static public function getMenu($returnType = 'object')
 37:     {
 38:         $mask = Horde_Menu::MASK_PROBLEM | Horde_Menu::MASK_LOGIN;
 39:         $menu = new Horde_Menu($mask);
 40: 
 41:         $menu->add(Horde::url('dialplan.php'), _("Call Menus"), "dialplan.png");
 42:         $menu->add(Horde::url('recordings.php'), _("Recordings"), "recordings.png");
 43:         $menu->add(Horde::url('extensions.php'), _("Extensions"), "extension.png");
 44:         $menu->add(Horde::url('devices.php'), _("Devices"), "shout.png");
 45:         $menu->add(Horde::url('conferences.php'), _("Conferences"), "conference.png");
 46: 
 47:         /* Administration. */
 48:         if ($GLOBALS['registry']->isAdmin(array('permission' => 'shout:admin'))) {
 49:             $menu->add(Horde::url('admin.php'), _("_Admin"), 'admin.png');
 50:         }
 51: 
 52:         if ($returnType == 'object') {
 53:             return $menu;
 54:         } else {
 55:             return $menu->render();
 56:         }
 57:     }
 58: 
 59:     /**
 60:      * Checks for the given permissions for the current user on the given
 61:      * permission.  Optionally check for higher-level permissions and ultimately
 62:      * test for superadmin priveleges.
 63:      *
 64:      * @param string $permname Name of the permission to check
 65:      *
 66:      * @param optional int $permmask Bitfield of permissions to check for
 67:      *
 68:      * @param options int $numparents Check for the same permissions this
 69:      *                                many levels up the tree
 70:      *
 71:      * @return boolean the effective permissions for the user.
 72:      */
 73:     static public function checkRights($permname, $permmask = null, $numparents = 0)
 74:     {
 75:         if ($GLOBALS['registry']->isAdmin()) {
 76:             return true;
 77:         }
 78: 
 79:         if ($permmask === null) {
 80:             $permmask = Horde_Perms::SHOW | Horde_Perms::READ;
 81:         }
 82: 
 83:         # Default deny all permissions
 84:         $user = 0;
 85:         $superadmin = 0;
 86: 
 87:         $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
 88:         $superadmin = $perms->hasPermission('shout:superadmin',
 89:             $GLOBALS['registry']->getAuth(), $permmask);
 90: 
 91:         while ($numparents >= 0) {
 92:             $tmpuser = $perms->hasPermission($permname,
 93:                 $GLOBALS['registry']->getAuth(), $permmask);
 94: 
 95:             $user = $user | $tmpuser;
 96:             if ($numparents > 0) {
 97:                 $pos = strrpos($permname, ':');
 98:                 if ($pos) {
 99:                     $permname = substr($permname, 0, $pos);
100:                 }
101:             }
102:             $numparents--;
103:         }
104:         $test = $superadmin | $user;
105: 
106:         return ($test & $permmask) == $permmask;
107:     }
108: 
109:     /**
110:      * Generate new device authentication tokens.
111:      *
112:      * This method is designed to generate random strings for the
113:      * authentication ID and password.  The result is intended to be used
114:      * for automatically generated device information.  The user is prevented
115:      * from specifying usernames and passwords for these reasons:
116:      * 1) If a username and/or password can be easily guessed, monetary loss
117:      *    is likely through the fraudulent placing of telephone calls.
118:      *    This has been observed in the wild far too many times already.
119:      *
120:      * 2) The username and password are only needed to be programmed into the
121:      *    device once, and then stored semi-permanently.  In some cases, the
122:      *    provisioning can be done automatically.  For these reasons, having
123:      *    user-friendly usernames and passswords is not terribly important.
124:      *
125:      * @param string $account  Account for this credential pair
126:      *
127:      * @return array  Array of (string $deviceID, string $devicePassword)
128:      */
129:     static public function genDeviceAuth($account)
130:     {
131:         $devid = $account . substr(uniqid(), 6);
132: 
133:         // This simple password generation algorithm inspired by Jon Haworth
134:         // http://www.laughing-buddha.net/jon/php/password/
135: 
136:         // define possible characters
137:         // Vowels excluded to avoid potential pronounceability
138:         $possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
139: 
140:         $password = "";
141:         $i = 0;
142:         while ($i < 12) {
143:             // pick a random character from the possible ones
144:             $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
145: 
146:             // we don't want this character if it's already in the password
147:             if (!strstr($password, $char)) {
148:               $password .= $char;
149:               $i++;
150:             }
151:         }
152: 
153:         return array($devid, $password);
154:     }
155: 
156:     static public function getMenuActions()
157:     {
158:         $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
159:         $account = $GLOBALS['session']->get('shout', 'curaccount_code');
160: 
161:         return array(
162:             'jump' => array(
163:                 'description' => _("Jump to menu"),
164:                 'args' => array (
165:                     'menuName' => array(
166:                         'name' => _("Menu"),
167:                         'type' => 'enum',
168:                         'required' => true,
169:                         'params' => array(self::getNames($shout->dialplan->getMenus($account)))
170:                     )
171:                 )
172:             ),
173:             'ringexten' => array(
174:                 'description' => _("Ring extension"),
175:                 'args' => array(
176:                     'exten' => array(
177:                         'name' => _("Extension"),
178:                         'type' => 'enum',
179:                         'required' => true,
180:                         'params' => array(self::getNames($shout->extensions->getExtensions($account)))
181:                     )
182:                 )
183:             ),
184:             'leave_message' => array(
185:                 'description' => _("Go to voicemail"),
186:                 'args' => array(
187:                     'exten' => array(
188:                         'name' => _("Mailbox"),
189:                         'type' => 'enum',
190:                         'required' => true,
191:                         'params' => array(self::getNames($shout->extensions->getExtensions($account)))
192:                     )
193:                 )
194:             ),
195:             'conference' => array(
196:                 'description' => _("Enter conference"),
197:                 'args' => array(
198:                     'roomno' => array(
199:                         'name' => _("Room Number (optional)"),
200:                         'type' => 'number',
201:                         'required' => false
202:                     )
203:                 )
204:             ),
205:             'directory' => array(
206:                 'description' => _("Company directory"),
207:                 'args' => array()
208:             ),
209:             'dial' => array(
210:                 'description' => _("Call out"),
211:                 'args' => array(
212:                     'numbers' => array(
213:                         'name' => _("Phone Number"),
214:                         'type' => 'phone',
215:                         'required' => true
216:                     )
217:                 )
218:             ),
219:             'rewind' => array(
220:                 'description' => _("Restart menu"),
221:                 'args' => array()
222:             ),
223:             'admin_login' => array(
224:                 'description' => _("Login to Admin Functions"),
225:                 'args' => array()
226:             ),
227:             'none' => array(
228:                 'description' => _("No action"),
229:                 'args' => array()
230:             )
231: 
232:             // TODO: Actions to implement: Queue, VoicemailLogin
233:         );
234:     }
235: 
236:     static public function getNames($array)
237:     {
238:         $res = array();
239:         foreach ($array as $id => $info) {
240:             $res[$id] = $info['name'];
241:         }
242:         return $res;
243:     }
244: 
245:     static public function getAdminTabs()
246:     {
247:         $tabname = Horde_Util::getFormData('view');
248:         $tabs = new Horde_Core_Ui_Tabs('view', Horde_Variables::getDefaultVariables());
249:         $tabs->addTab(_("Telephone Numbers"),
250:                       Horde::url('admin/numbers.php'),
251:                       array('view' => 'numbers', id => 'tabnumbers'));
252:         $tabs->addTab(_("Accounts"),
253:                       Horde::url('admin/accounts.php'),
254:                       array('view' => 'accounts', id => 'tabaccounts'));
255:         if ($view === null) {
256:             $view = 'numbers';
257:         }
258: 
259:         echo $tabs->render($view);
260:     }
261: 
262: }
263: 
API documentation generated by ApiGen