From b1b721d7dc8d729d1aa5886a5982316bda6722c7 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Wed, 29 Jun 2005 19:36:05 +0000 Subject: [PATCH] Initial revision git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@32 06cd67b6-e706-0410-b29e-9de616bca6e9 --- config/conf.php | 14 +++++ config/conf.xml | 45 ++++++++++++++ contexts.php | 19 ++++++ index.php | 21 +++++++ lib/Driver.php | 135 ++++++++++++++++++++++++++++++++++++++++ lib/Driver/ldap.php | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/Shout.php | 3 + lib/base.php | 45 ++++++++++++++ lib/defines.php | 7 +++ shout.webprj | 72 ++++++++++++++++++++++ templates/content_page | 8 +++ 11 files changed, 532 insertions(+) create mode 100644 config/conf.php create mode 100644 config/conf.xml create mode 100644 contexts.php create mode 100644 index.php create mode 100644 lib/Driver.php create mode 100644 lib/Driver/ldap.php create mode 100644 lib/Shout.php create mode 100644 lib/base.php create mode 100644 lib/defines.php create mode 100644 shout.webprj create mode 100644 templates/content_page diff --git a/config/conf.php b/config/conf.php new file mode 100644 index 000000000..4bcfc3814 --- /dev/null +++ b/config/conf.php @@ -0,0 +1,14 @@ + + + + + + Shout Storage + + + + + + localhost + + + + 3 + + 2 + 3 + + + + objectclass + + + + + + + + + + + + + + diff --git a/contexts.php b/contexts.php new file mode 100644 index 000000000..a95ff84bf --- /dev/null +++ b/contexts.php @@ -0,0 +1,19 @@ +getContexts(); +if (is_a($contexts, 'PEAR_Error')) { + $notification->push(_("Internal error viewing requested page"), + 'horde.error'); +} +# Print the contexts +foreach($contexts as $context) { + print "$context
\n"; +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 000000000..09361b6d5 --- /dev/null +++ b/index.php @@ -0,0 +1,21 @@ + + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + */ + +define('SHOUT_BASE', dirname(__FILE__)); +$shout_configured = (@is_readable(SHOUT_BASE . '/config/conf.php') && + @is_readable(SHOUT_BASE . '/config/prefs.php')); + +// if (!$shout_configured) { +// require SHOUT_BASE . '/../lib/Test.php'; +// Horde_Test::configFilesMissing('Shout', SHOUT_BASE, +// array('conf.php', 'prefs.php')); +// } + +require SHOUT_BASE . '/contexts.php'; \ No newline at end of file diff --git a/lib/Driver.php b/lib/Driver.php new file mode 100644 index 000000000..6933f065c --- /dev/null +++ b/lib/Driver.php @@ -0,0 +1,135 @@ + + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Ben Klang + * @version $Revision$ + * @since Shout 0.1 + * @package Shout + */ + +// {{{ Shout_Driver class +class Shout_Driver { + + // {{{ Class local variables + /** + * Hash containing connection parameters. + * + * @var array $_params + */ + var $_params = array(); + // }}} + + // {{{ Shout_Driver constructor + function Shout_Driver($params = array()) + { + $this->_params = $params; + } + // }}} + + // {{{ getContexts method + /** + * Get a list of contexts from the backend and filter for which contexts + * the current user can read/write + * + * @return array Contexts valid for this user + * + * @access public + */ + function getContexts() + { + return PEAR::raiseError(_("Not implemented.")); + } + // }}} + + // {{{ factory method + /** + * Attempts to return a concrete Shout_Driver instance based on + * $driver. + * + * @param string $driver The type of the concrete Shout_Driver subclass + * to return. The class name is based on the storage + * driver ($driver). The code is dynamically + * included. + * + * @param array $params (optional) A hash containing any additional + * configuration or connection parameters a + * subclass might need. + * + * @return mixed The newly created concrete Shout_Driver instance, or + * false on an error. + */ + function &factory($driver = null, $params = null) + { + if (is_null($driver)) { + $driver = $GLOBALS['conf']['storage']['driver']; + } + + $driver = basename($driver); + + if (is_null($params)) { + $params = Horde::getDriverConfig('storage', $driver); + } + + require_once dirname(__FILE__) . '/Driver/' . $driver . '.php'; + $class = 'Shout_Driver_' . $driver; + if (class_exists($class)) { + return $shout = &new $class($params); + } else { + return false; + } + } + // }}} + + // {{{ singleton method + /** + * Attempts to return a reference to a concrete Shout_Driver + * instance based on $driver. It will only create a new instance + * if no Shout_Driver instance with the same parameters currently + * exists. + * + * This method must be invoked as: $var = &Shout_Driver::singleton() + * + * @param string $driver The type of concrete Shout_Driver subclass + * to return. The is based on the storage + * driver ($driver). The code is dynamically + * included. + * @param array $params (optional) A hash containing any additional + * configuration or connection parameters a + * subclass might need. + * + * @return mixed The created concrete Shout_Driver instance, or false + * on error. + */ + function &singleton($driver = null, $params = null) + { + static $instances; + + if (is_null($driver)) { + $driver = $GLOBALS['conf']['storage']['driver']; + } + + if (is_null($params)) { + $params = Horde::getDriverConfig('storage', $driver); + } + + if (!isset($instances)) { + $instances = array(); + } + + $signature = serialize(array($driver, $params)); + if (!isset($instances[$signature])) { + $instances[$signature] = &Shout_Driver::factory($driver, $params); + } + + return $instances[$signature]; + } +} +// }}} \ No newline at end of file diff --git a/lib/Driver/ldap.php b/lib/Driver/ldap.php new file mode 100644 index 000000000..3895d7e03 --- /dev/null +++ b/lib/Driver/ldap.php @@ -0,0 +1,163 @@ +_connect(); + } + // }}} + + // {{{ getContexts method + /** + * Get a list of contexts from the backend and filter for which contexts + * the current user can read/write + * + * @return array Contexts valid for this user + * + * @access public + */ + function getContexts() + { + # Collect all the possible contexts from the backend + $res = ldap_search($this->_LDAP, + SHOUT_ASTERISK_BRANCH.','.$this->_params['basedn'], + '(&(objectClass=asteriskObject)(objectClass=vofficeCustomer))', + array('context')); + if (!$res) { + return PEAR::raiseError("Unable to locate any customers " . + "underneath ".SHOUT_ASTERISK_BRANCH.",".$this->_params['basedn']) . + "matching those search filters"; + } + # Get the list of valid contexts for this user + # Possibly create the idea of an Asterisk Global Admin in the + # permissions system where an arbitrary user has permissions in all + # contexts + + + $entries = array(); + $res = ldap_get_entries($this->_LDAP, $res); + $i = 0; + while ($i < $res['count']) { + $entries[] = $res[$i]['context'][0]; + $i++; + } + # return the array + return $entries; + } + // }}} + + + + // {{{ + function getUserPhoneNumbers($username, $context = null) + { + $userfilter = "(".$this->userkey."=".$username.",". + $this->usersOU.",".$this->_params['basedn'].")"; + $searchfilter = "(&".$userfilter; + foreach ($prefs["searchfilters"]["phoneuser"] as $filter) { + $searchfilter .= "($filter)"; + } + $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']); + } + // 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; + } + // }}} + + // {{{ _connect method + /** + * Attempts to open a connection to the LDAP server. + * + * @return boolean True on success; exits (Horde::fatal()) on error. + * + * @access private + */ + function _connect() + { + if (!$this->_connected) { + # FIXME What else is needed for this assert? + Horde::assertDriverConfig($this->_params, 'storage', + array('hostspec', 'basedn', 'binddn', 'password')); + + # FIXME Add other sane defaults here (mostly objectClass related) + if (!isset($this->_params['userObjectclass'])) { + $this->_params['userObjectclass'] = 'asteriskUser'; + } + + $this->_LDAP = ldap_connect($this->_params['hostspec'], 389); #FIXME + if (!$this->_LDAP) { + Horde::fatal("Unable to connect to LDAP server $hostname on +$port", __FILE__, __LINE__); #FIXME: $port + } + $res = ldap_set_option($this->_LDAP, LDAP_OPT_PROTOCOL_VERSION, +$this->_params['version']); + if (!$res) { + return PEAR::raiseError("Unable to set LDAP protocol version"); + } + $res = ldap_bind($this->_LDAP, $this->_params['binddn'], +$this->_params['password']); + if (!$res) { + return PEAR::raiseError("Unable to bind to the LDAP server. +Check authentication credentials."); + } + + $this->_connected = true; + } + return true; + } + // }}} +} \ No newline at end of file diff --git a/lib/Shout.php b/lib/Shout.php new file mode 100644 index 000000000..d43bdc1e0 --- /dev/null +++ b/lib/Shout.php @@ -0,0 +1,3 @@ +pushApp('shout', !defined('AUTH_HANDLER'))), +'PEAR_Error')) { + if ($pushed->getCode() == 'permission_denied') { + Horde::authenticationFailureRedirect(); + } + Horde::fatal($pushed, __FILE__, __LINE__, false); +} +$conf = &$GLOBALS['conf']; +@define('SHOUT_TEMPLATES', $registry->get('templates')); + +// Find the base file path of Shout. +@define('SHOUT_BASE', dirname(__FILE__) . '/..'); + +// Notification system. +$notification = &Notification::singleton(); +$notification->attach('status'); + +// Shout base libraries. +require_once SHOUT_BASE . '/lib/Shout.php'; +require_once SHOUT_BASE . '/lib/Driver.php'; + +$GLOBALS['shout'] = &Shout_Driver::singleton(); + +// Horde libraries. +require_once 'Horde/Help.php'; \ No newline at end of file diff --git a/lib/defines.php b/lib/defines.php new file mode 100644 index 000000000..79badd638 --- /dev/null +++ b/lib/defines.php @@ -0,0 +1,7 @@ + + + + + templates/ + toolbars/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 8026 + + + 0 + 8016 + http://localhost/Gubed/StartSession.php?gbdScript=/%rfpp + 0 + 0 + 0 + + + + -//w3c//dtd xhtml 1.0 strict//en + + + + + Ben Klang + ben@alkaloid.net + Gubed + *~;*.webprj;CVS; + + + + + + + + + + + diff --git a/templates/content_page b/templates/content_page new file mode 100644 index 000000000..66fd553b8 --- /dev/null +++ b/templates/content_page @@ -0,0 +1,8 @@ +