via: 8b7b83f0a42fc7cce5deaacd1c3a56f76c392175 (commit)
from: 7f89d85adb464f103abda4c3cee75a10f9515921 (commit)
= COMMIT LOG ===========================================================
committer: Mathieu Parent
comments:
MediaBrotha: adding LDAP backend
diff --git a/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
new file mode 100644
index 0000000..d275ff1
--- /dev/null
+++ b/sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
@@ -0,0 +1,88 @@
+<?php
+/*
+Copyright 2011 Mathieu Parent <math.parent@gmail.com>
+
+This file is part of MediaBrotha.
+
+ MediaBrotha is free software: you can
+ redistribute it and/or modify it under the terms of the GNU General
+ Public License as published by the Free Software Foundation, either
+ version 3 of the License, or (at your option) any later version.
+
+ MediaBrotha is distributed in the hope that it
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with MediaBrotha. If not, see
+ <http://www.gnu.org/licenses/>.
+
+*/
+
+require_once('Net/LDAP2.php');
+/**
+ * @author Mathieu Parent
+ */
+
+class MediaBrotha_Backend_LDAP extends MediaBrotha_Backend {
+ private $_ldap;
+ public function __construct(array $args = Array()) {
+ parent::__construct($args);
+ $this->_ldap = Net_LDAP2::connect($this->getMetadata('ldap_connect_config'));
+ if (Net_LDAP2::isError($this->_ldap)) {
+ die('Could not fetch entry: '.$this->_ldap->getMessage());
+ }
+ }
+ public function register() {
+ parent::register();
+ MediaBrotha_Core::registerMimeType($this, 'text/directory');
+ }
+
+ public function capabilities($uri = NULL, $mime_type = NULL, $mime_encoding = NULL) {
+ return Array(
+ 'browse',
+ );
+ }
+
+ public function isURISafe($uri) {
+ return true;
+ }
+
+
+ public static function parseLDAPURI($uri, $component = NULL) {
+ $uri = preg_replace('@^ldap:///@', 'ldap://fake_host/', $uri);
+ $components = parse_url($uri, $component);
+ if (is_array($components) && ($components['host'] === 'fake_host')) {
+ $components['host'] = NULL;
+ }
+ return $components;
+ }
+
+ // Capability browse
+ public function fetch($uri) {
+ if (($this::parseLDAPURI($uri, PHP_URL_SCHEME) != 'ldap') || !$this->isURISafe($uri)) {
+ $ldap_connect_config = $this->getMetadata('ldap_connect_config');
+ $uri = 'ldap:///'.$ldap_connect_config['basedn'];
+ }
+ $basedn = $this::parseLDAPURI($uri, PHP_URL_PATH);
+ if ($basedn && ($basedn{0} = '/')) {
+ $basedn = substr($basedn, 1);
+ }
+ $this->_buffer = $this->_ldap->search($basedn, NULL,
+ Array());
+ return true;
+ }
+ protected function _mediaFromBufferItem($entry) {
+ if ($entry) {
+ $media = new MediaBrotha_Media(Array(
+ 'uri' => 'ldap:///'.$entry->dn(),
+ 'name' => $entry->dn(), //$entry->getValue('sn', 'single'),
+ ));
+ $media->setMimeType('text/directory');
+ // $media->setMimeEncoding($finfo->file($file->getPathname(), FILEINFO_MIME_ENCODING));
+ return $media;
+ }
+ }
+}
+
Summary of changes: sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php | 88 ++++++++++++++++++++ 1 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 sathieu/cisco-xml/lib/MediaBrotha/Backend/LDAP.php
this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email
For more info, see http://blog.chomperstomp.com/?p=630
--
FreeSWITCH user-contributed scripts, etc