Merge commit 'gallery3-contrib/master'
Conflicts: modules/ldap/config/ldap.php Signed-off-by: rWatcher <rwatcher@australia.edu>
This commit is contained in:
commit
dc8cc9d26b
@ -49,9 +49,9 @@ $config["methods"] = array(
|
||||
"thumb_bottom" => t("Bottom of thumbnail"),
|
||||
"thumb_info" => t("Thumbnail information"),
|
||||
"thumb_top" => t("Top of thumbnail display")),
|
||||
"menu" => array("album" => t("Add an album menu element"),
|
||||
"photo" => t("Add an photo menu element")),
|
||||
"event" => array("batch_complete" => t("Batch completion"),
|
||||
"event" => array("admin_menu" => t("Add an admin menu element"),
|
||||
"album_menu" => t("Add an album menu element"),
|
||||
"batch_complete" => t("Batch completion"),
|
||||
"comment_add_form" => t("Comment add form creation"),
|
||||
"comment_created" => t("Comment created"),
|
||||
"comment_updated" => t("Comment updated"),
|
||||
@ -62,8 +62,9 @@ $config["methods"] = array(
|
||||
"item_related_update" => t("Photo meta data update"),
|
||||
"item_related_update_batch" => t("Photo meta data update"),
|
||||
"item_updated" => t("Album or photo update"),
|
||||
"photo_menu" => t("Add a photo menu element"),
|
||||
"site_menu" => t("Add a site menu element"),
|
||||
"user_before_delete" => t("Before user deletion"),
|
||||
"user_created" => t("User created"),
|
||||
"user_login" => t("User login"),
|
||||
"user_logout" => t("User logout")));
|
||||
|
@ -49,6 +49,7 @@ class Admin_Developer_Controller extends Admin_Controller {
|
||||
|
||||
$post = new Validation($_POST);
|
||||
$post->add_rules("name", "required");
|
||||
$post->add_rules("display_name", "required");
|
||||
$post->add_rules("description", "required");
|
||||
$post->add_callbacks("name", array($this, "_is_module_defined"));
|
||||
|
||||
@ -195,7 +196,8 @@ class Admin_Developer_Controller extends Admin_Controller {
|
||||
$data = "digraph G {\n";
|
||||
foreach ($items as $item) {
|
||||
$data .= " $item->parent_id -> $item->id\n";
|
||||
$data .= " $item->id [label=\"$item->id [$item->level] <$item->left, $item->right>\"]\n";
|
||||
$data .=
|
||||
" $item->id [label=\"$item->id [$item->level] <$item->left_ptr, $item->right_ptr>\"]\n";
|
||||
}
|
||||
$data .= "}\n";
|
||||
return $data;
|
||||
@ -215,7 +217,7 @@ class Admin_Developer_Controller extends Admin_Controller {
|
||||
}
|
||||
|
||||
private function _get_module_form() {
|
||||
$form = array("name" => "", "description" => "", "theme[]" => array(), "menu[]" => array(),
|
||||
$form = array("name" => "", "display_name" => "", "description" => "", "theme[]" => array(),
|
||||
"event[]" => array());
|
||||
$errors = array_fill_keys(array_keys($form), "");
|
||||
|
||||
@ -230,7 +232,6 @@ class Admin_Developer_Controller extends Admin_Controller {
|
||||
$v->hidden = array("csrf" => access::csrf_token());
|
||||
$v->theme = $config["theme"];
|
||||
$v->event = $config["event"];
|
||||
$v->menu = $config["menu"];
|
||||
$v->form = $form;
|
||||
$v->errors = $errors;
|
||||
return $v;
|
||||
|
@ -43,13 +43,13 @@ class developer_event_Core {
|
||||
$developer_menu->append(
|
||||
Menu::factory("link")
|
||||
->id("scaffold_profiler")
|
||||
->label("Profiling off")
|
||||
->label(t("Profiling off"))
|
||||
->url(url::site("admin/developer/session/profiler?value=0&csrf=$csrf")));
|
||||
} else {
|
||||
$developer_menu->append(
|
||||
Menu::factory("link")
|
||||
->id("scaffold_profiler")
|
||||
->label("Profiling on")
|
||||
->label(t("Profiling on"))
|
||||
->url(url::site("admin/developer/session/profiler?value=1&csrf=$csrf")));
|
||||
}
|
||||
|
||||
@ -57,13 +57,13 @@ class developer_event_Core {
|
||||
$developer_menu->append(
|
||||
Menu::factory("link")
|
||||
->id("scaffold_debugger")
|
||||
->label("Debugging off")
|
||||
->label(t("Debugging off"))
|
||||
->url(url::site("admin/developer/session/debug?value=0&csrf=$csrf")));
|
||||
} else {
|
||||
$developer_menu->append(
|
||||
Menu::factory("link")
|
||||
->id("scaffold_debugger")
|
||||
->label("Debugging on")
|
||||
->label(t("Debugging on"))
|
||||
->url(url::site("admin/developer/session/debug?value=1&csrf=$csrf")));
|
||||
}
|
||||
}
|
||||
|
@ -54,14 +54,10 @@ class developer_task_Core {
|
||||
$context["block"] = array();
|
||||
self::_render_helper_file($context, "block");
|
||||
break;
|
||||
case 4: // Generate menu helper
|
||||
$context["menu"] = !isset($context["menu"]) ? array() : $context["menu"];
|
||||
self::_render_helper_file($context, "menu");
|
||||
break;
|
||||
case 5: // Generate event helper
|
||||
case 4: // Generate event helper
|
||||
self::_render_helper_file($context, "event");
|
||||
break;
|
||||
case 6: // Generate admin controller
|
||||
case 5: // Generate admin controller
|
||||
$file = "{$context['module_path']}/controllers/admin_{$context['module']}.php";
|
||||
ob_start();
|
||||
$v = new View("admin_controller.txt");
|
||||
@ -72,7 +68,7 @@ class developer_task_Core {
|
||||
file_put_contents($file, ob_get_contents());
|
||||
ob_end_clean();
|
||||
break;
|
||||
case 7: // Generate admin form
|
||||
case 6: // Generate admin form
|
||||
$file = "{$context['module_path']}/views/admin_{$context['module']}.html.php";
|
||||
ob_start();
|
||||
$v = new View("admin_html.txt");
|
||||
@ -83,7 +79,7 @@ class developer_task_Core {
|
||||
file_put_contents($file, ob_get_contents());
|
||||
ob_end_clean();
|
||||
break;
|
||||
case 8: // Generate controller
|
||||
case 7: // Generate controller
|
||||
$file = "{$context['module_path']}/controllers/{$context['module']}.php";
|
||||
ob_start();
|
||||
$v = new View("controller.txt");
|
||||
@ -95,7 +91,7 @@ class developer_task_Core {
|
||||
file_put_contents($file, ob_get_contents());
|
||||
ob_end_clean();
|
||||
break;
|
||||
case 9: // Generate sidebar block view
|
||||
case 8: // Generate sidebar block view
|
||||
$file = "{$context['module_path']}/views/{$context['module']}_block.html.php";
|
||||
ob_start();
|
||||
$v = new View("block_html.txt");
|
||||
@ -107,11 +103,11 @@ class developer_task_Core {
|
||||
file_put_contents($file, ob_get_contents());
|
||||
ob_end_clean();
|
||||
break;
|
||||
case 10: // Generate module.info (do last)
|
||||
case 9: // Generate module.info (do last)
|
||||
$file = "{$context["module_path"]}/module.info";
|
||||
ob_start();
|
||||
$v = new View("module_info.txt");
|
||||
$v->module_name = $context["name"];
|
||||
$v->module_name = $context["display_name"];
|
||||
$v->module_description = $context["description"];
|
||||
print $v->render();
|
||||
file_put_contents($file, ob_get_contents());
|
||||
|
@ -13,6 +13,13 @@
|
||||
<p class="g-error"><?= t("Module is already implemented") ?></p>
|
||||
<? endif ?>
|
||||
</li>
|
||||
<li <? if (!empty($errors["display_name"])): ?> class="g-error"<? endif ?>>
|
||||
<?= form::label("display_name", t("Display name")) ?>
|
||||
<?= form::input("display_name", $form["display_name"]) ?>
|
||||
<? if (!empty($errors["display_name"]) && $errors["display_name"] == "required"): ?>
|
||||
<p class="g-error"><?= t("Module display_name is required")?></p>
|
||||
<? endif ?>
|
||||
</li>
|
||||
<li <? if (!empty($errors["description"])): ?> class="g-error"<? endif ?>>
|
||||
<?= form::label("description", t("Description")) ?>
|
||||
<?= form::input("description", $form["description"]) ?>
|
||||
@ -23,15 +30,11 @@
|
||||
<li>
|
||||
<ul>
|
||||
<li>
|
||||
<?= form::label("theme[]", t("Theme Callbacks")) ?>
|
||||
<?= form::label("theme[]", t("Theme callbacks")) ?>
|
||||
<?= form::dropdown(array("name" => "theme[]", "multiple" => true, "size" => 6), $theme, $form["theme[]"]) ?>
|
||||
</li>
|
||||
<li>
|
||||
<?= form::label("menu[]", t("Menu Callback")) ?>
|
||||
<?= form::dropdown(array("name" => "menu[]", "multiple" => true, "size" => 6), $menu, $form["menu[]"]) ?>
|
||||
</li>
|
||||
<li>
|
||||
<?= form::label("event[]", t("Gallery Event Handlers")) ?>
|
||||
<?= form::label("event[]", t("Gallery event handlers")) ?>
|
||||
<?= form::dropdown(array("name" => "event[]", "multiple" => true, "size" => 6), $event, $form["event[]"]) ?>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -19,75 +19,95 @@
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class <?= $module ?>_event {
|
||||
<? if (!empty($callbacks["admin_menu"])): ?>
|
||||
static function admin_menu($menu, $theme) {
|
||||
}
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["album_menu"])): ?>
|
||||
static function album_menu($menu, $theme) {
|
||||
}
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["batch_complete"])): ?>
|
||||
static function batch_complete() {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["comment_add_form"])): ?>
|
||||
static function comment_add_form($form) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["comment_created"])): ?>
|
||||
static function comment_created($theme, $args) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["comment_updated"])): ?>
|
||||
static function comment_updated($old, $new) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["group_before_delete"])): ?>
|
||||
static function group_before_delete($group) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["group_created"])): ?>
|
||||
static function group_created($group) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["item_before_delete"])): ?>
|
||||
static function item_before_delete($item) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["item_created"])): ?>
|
||||
static function item_created($item) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["item_related_update"])): ?>
|
||||
static function item_related_update($item) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["item_related_update_batch"])): ?>
|
||||
static function item_related_update_batch($sql) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["item_updated"])): ?>
|
||||
static function item_updated($old, $new) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["photo_menu"])): ?>
|
||||
static function photo_menu($menu, $theme) {
|
||||
}
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["site_menu"])): ?>
|
||||
static function site_menu($menu, $theme) {
|
||||
}
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["user_before_delete"])): ?>
|
||||
static function user_before_delete($user) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["user_created"])): ?>
|
||||
static function user_created($user) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["user_login"])): ?>
|
||||
static function user_login($user) {
|
||||
}
|
||||
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["user_logout"])): ?>
|
||||
static function user_logout($user) {
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<?= "<?php defined(\"SYSPATH\") or die(\"No direct script access.\");" ?>
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program 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 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class <?= $module ?>_menu {
|
||||
static function admin($menu, $theme) {
|
||||
$menu->get("settings_menu")
|
||||
->append(Menu::factory("link")
|
||||
->id("<?= $module ?>_menu")
|
||||
->label(t("<?= $module_name ?> Administration"))
|
||||
->url(url::site("admin/<?= $module ?>")));
|
||||
}
|
||||
|
||||
<? if (!empty($callbacks["album"])): ?>
|
||||
static function album($menu, $theme) {
|
||||
}
|
||||
|
||||
<? endif ?>
|
||||
<? if (!empty($callbacks["photo"])): ?>
|
||||
static function photo($menu, $theme) {
|
||||
}
|
||||
|
||||
<? endif ?>
|
||||
static function site($menu, $theme) {
|
||||
$item = $theme->item();
|
||||
|
||||
if ($item && access::can("edit", $item)) {
|
||||
$options_menu = $menu->get("options_menu")
|
||||
->append(Menu::factory("dialog")
|
||||
->id("<?= $module ?>")
|
||||
->label(t("Peform <?= $module_name ?> Processing"))
|
||||
->url(url::site("<?= $module ?>/index/$item->id")));
|
||||
}
|
||||
}
|
||||
}
|
74
modules/ldap/config/gallery.ldif
Normal file
74
modules/ldap/config/gallery.ldif
Normal file
@ -0,0 +1,74 @@
|
||||
dn: ou=people,dc=gallery,dc=local
|
||||
objectClass: organizationalUnit
|
||||
ou: people
|
||||
|
||||
dn: ou=groups,dc=gallery,dc=local
|
||||
objectClass: organizationalUnit
|
||||
ou: groups
|
||||
|
||||
dn: ou=systems,dc=gallery,dc=local
|
||||
objectClass: organizationalUnit
|
||||
ou: systems
|
||||
|
||||
dn: uid=jdoe,ou=people,dc=gallery,dc=local
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: posixAccount
|
||||
uid: jdoe
|
||||
sn: Doe
|
||||
givenname: John
|
||||
cn: John Doe
|
||||
userpassword: {SSHA}76qIsKTflGM6dj0f5c5olnD9ltKKXAFE
|
||||
displayName: John Doe
|
||||
homeDirectory: /home/jdoe
|
||||
uidnumber: 1000
|
||||
gidnumber: 10000
|
||||
mail: jdoe@gallery.local
|
||||
|
||||
dn: uid=hwallbanger,ou=people,dc=gallery,dc=local
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: posixAccount
|
||||
uid: hwallbanger
|
||||
sn: Wallbanger
|
||||
givenname: Harvey
|
||||
cn: Harvey Wallbanger
|
||||
userpassword: {SSHA}084H+FFr6s/anIoaIhI+O8OaH2u0MIBL
|
||||
displayName: Harvey Wallbanger
|
||||
homeDirectory: /home/hwallbanger
|
||||
uidnumber: 1001
|
||||
gidnumber: 10001
|
||||
mail: hwallbanger@gallery.local
|
||||
|
||||
dn: uid=rnail,ou=people,dc=gallery,dc=local
|
||||
objectClass: inetOrgPerson
|
||||
objectClass: posixAccount
|
||||
uid: rnail
|
||||
sn: Nail
|
||||
givenname: Rusty
|
||||
cn: Rusty Nail
|
||||
userpassword: {SSHA}wXVdpfbP6n9LwoLxrB+NvY2oDN1j/M2z
|
||||
displayName: Rusty Nail
|
||||
homeDirectory: /home/rnail
|
||||
uidnumber: 1002
|
||||
gidnumber: 10001
|
||||
mail: rnail@gallery.local
|
||||
|
||||
dn: cn=admins,ou=groups,dc=gallery,dc=local
|
||||
objectclass: posixGroup
|
||||
cn: admins
|
||||
gidnumber: 10000
|
||||
memberuid: jdoe
|
||||
|
||||
dn: cn=users,ou=groups,dc=gallery,dc=local
|
||||
objectclass: posixGroup
|
||||
cn: users
|
||||
gidnumber: 10001
|
||||
memberuid: jdoe
|
||||
memberuid: hwallbanger
|
||||
memberuid: rnail
|
||||
|
||||
dn: cn=guest,ou=groups,dc=gallery,dc=local
|
||||
objectclass: posixGroup
|
||||
cn: guest
|
||||
gidnumber: 10002
|
||||
|
||||
|
45
modules/ldap/config/identity.php
Normal file
45
modules/ldap/config/identity.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program 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 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
/*
|
||||
* @package Identity
|
||||
*
|
||||
* User settings, defined as arrays, or "groups". If no group name is
|
||||
* used when loading the cache library, the group named "default" will be used.
|
||||
*
|
||||
* Each group can be used independently, and multiple groups can be used at once.
|
||||
*
|
||||
* Group Options:
|
||||
* driver - User backend driver. Gallery comes with Gallery user driver.
|
||||
* allow_updates - Flag to indicate that the back end allows updates.
|
||||
* params - Driver parameters, specific to each driver.
|
||||
*/
|
||||
$config["ldap"] = array(
|
||||
"driver" => "ldap",
|
||||
"allow_updates" => false,
|
||||
"params" => array(
|
||||
"groups" => array("users", "guest"),
|
||||
"everybody_group" => "guest",
|
||||
"registered_users_group" => "users",
|
||||
"admins" => array("jdoe"),
|
||||
"url" => "ldap://127.0.0.1/",
|
||||
"group_domain" => "ou=groups,dc=gallery,dc=local",
|
||||
"user_domain" => "ou=people,dc=gallery,dc=local"
|
||||
)
|
||||
);
|
28
modules/ldap/config/ldap.php
Normal file
28
modules/ldap/config/ldap.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program 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 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
$config = array(
|
||||
"groups" => array("eng", "google", "prebuild", "guest"),
|
||||
"everybody_group" => "guest",
|
||||
"registered_users_group" => "google",
|
||||
"admins" => array("mediratta"),
|
||||
"url" => "ldaps://ldap.corp.google.com/",
|
||||
"group_domain" => "ou=Posix,ou=Groups,dc=google,dc=com",
|
||||
"user_domain" => "ou=People,dc=google,dc=com",
|
||||
);
|
40
modules/ldap/helpers/ldap_installer.php
Normal file
40
modules/ldap/helpers/ldap_installer.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program 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 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class ldap_installer {
|
||||
static function install() {
|
||||
module::set_version("ldap", 1);
|
||||
$root = item::root();
|
||||
foreach (identity::groups() as $group) {
|
||||
module::event("group_created", $group);
|
||||
access::allow($group, "view", $root);
|
||||
access::allow($group, "view_full", $root);
|
||||
}
|
||||
// Let the admin own everything
|
||||
$admin = identity::admin_user();
|
||||
Database::instance()->query("UPDATE {items} SET owner_id = {$admin->id}");
|
||||
}
|
||||
|
||||
static function uninstall() {
|
||||
// Delete all groups so that we give other modules an opportunity to clean up
|
||||
foreach (identity::groups() as $group) {
|
||||
module::event("group_deleted", $group);
|
||||
}
|
||||
}
|
||||
}
|
252
modules/ldap/libraries/drivers/IdentityProvider/Ldap.php
Normal file
252
modules/ldap/libraries/drivers/IdentityProvider/Ldap.php
Normal file
@ -0,0 +1,252 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* This program 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 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class IdentityProvider_Ldap_Driver implements IdentityProvider_Driver {
|
||||
static $_params;
|
||||
private static $_connection;
|
||||
private static $_guest_user;
|
||||
|
||||
/**
|
||||
* Initializes the LDAP Driver
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params) {
|
||||
self::$_params = $params;
|
||||
self::$_connection = ldap_connect(self::$_params["url"]);
|
||||
ldap_set_option(self::$_connection, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_bind(self::$_connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::guest.
|
||||
*/
|
||||
public function guest() {
|
||||
if (empty(self::$_guest_user)) {
|
||||
self::$_guest_user = new Ldap_User();
|
||||
self::$_guest_user->id = 0;
|
||||
self::$_guest_user->name = "Guest";
|
||||
self::$_guest_user->guest = true;
|
||||
self::$_guest_user->admin = false;
|
||||
self::$_guest_user->locale = null;
|
||||
self::$_guest_user->groups = array($this->everybody());
|
||||
}
|
||||
return self::$_guest_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::admin_user.
|
||||
*/
|
||||
public function admin_user() {
|
||||
return self::lookup_user_by_name(self::$_params["admins"][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::create_user.
|
||||
*/
|
||||
public function create_user($name, $full_name, $password) {
|
||||
throw new Exception("@todo INVALID OPERATION");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::is_correct_password.
|
||||
*/
|
||||
public function is_correct_password($user, $password) {
|
||||
$connection = ldap_connect(self::$_params["url"]);
|
||||
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
$lbind = ldap_bind($connection, $user->dn, $password);
|
||||
ldap_unbind($connection);
|
||||
|
||||
return ($lbind) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::lookup_user.
|
||||
*/
|
||||
public function lookup_user($id) {
|
||||
$result = ldap_search(self::$_connection, self::$_params["user_domain"], "uidNumber=$id");
|
||||
$entries = ldap_get_entries(self::$_connection, $result);
|
||||
if ($entries["count"] > 0) {
|
||||
$cn_entry = ldap_get_values(self::$_connection, $entry_id, "cn");
|
||||
return new Ldap_User($entries[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::lookup_user_by_name.
|
||||
*
|
||||
* Special processing: if the supplied name is admin then look up the first user
|
||||
* specified by the "admins" driver params
|
||||
*/
|
||||
public function lookup_user_by_name($name) {
|
||||
$result = ldap_search(self::$_connection, self::$_params["user_domain"], "uid=$name");
|
||||
$entries = ldap_get_entries(self::$_connection, $result);
|
||||
if ($entries["count"] > 0) {
|
||||
return new Ldap_User($entries[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::create_group.
|
||||
*/
|
||||
public function create_group($name) {
|
||||
throw new Exception("@todo INVALID OPERATION");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::everybody.
|
||||
*/
|
||||
public function everybody() {
|
||||
return $this->lookup_group_by_name(self::$_params["everybody_group"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::registered_users.
|
||||
*/
|
||||
public function registered_users() {
|
||||
return $this->lookup_group_by_name(self::$_params["registered_users_group"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::lookup_group.
|
||||
*/
|
||||
public function lookup_group($id) {
|
||||
$result = @ldap_search(self::$_connection, self::$_params["group_domain"], "gidNumber=$id");
|
||||
$entry_id = ldap_first_entry(self::$_connection, $result);
|
||||
|
||||
if ($entry_id !== false) {
|
||||
$cn_entry = ldap_get_values(self::$_connection, $entry_id, "cn");
|
||||
$gid_number_entry = ldap_get_values(self::$_connection, $entry_id, "gidNumber");
|
||||
return new Ldap_Group($gid_number_entry[0], $cn_entry[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up the group by name.
|
||||
* @param string $name the name of the group to locate
|
||||
* @return Group_Definition
|
||||
*/
|
||||
public function lookup_group_by_name($name) {
|
||||
$result = @ldap_search(self::$_connection, self::$_params["group_domain"], "cn=$name");
|
||||
$entry_id = ldap_first_entry(self::$_connection, $result);
|
||||
|
||||
if ($entry_id !== false) {
|
||||
$cn_entry = ldap_get_values(self::$_connection, $entry_id, "cn");
|
||||
$gid_number_entry = ldap_get_values(self::$_connection, $entry_id, "gidNumber");
|
||||
return new Ldap_Group($gid_number_entry[0], $cn_entry[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::get_user_list.
|
||||
*/
|
||||
public function get_user_list($ids) {
|
||||
$users = array();
|
||||
foreach ($ids as $id) {
|
||||
$users[] = $this->lookup_user($id);
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IdentityProvider_Driver::groups.
|
||||
*/
|
||||
public function groups() {
|
||||
$groups = array();
|
||||
foreach (self::$_params["groups"] as $group_name) {
|
||||
$root = item::root();
|
||||
$groups[] = $this->lookup_group_by_name($group_name);
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
static function groups_for($user) {
|
||||
$result = ldap_search(self::$_connection, self::$_params["group_domain"],
|
||||
"(memberUid=$user->name)");
|
||||
|
||||
$associated_groups = self::$_params["groups"];
|
||||
$groups = array();
|
||||
for ($entry_id = ldap_first_entry(self::$_connection, $result);
|
||||
$entry_id != false;
|
||||
$entry_id = ldap_next_entry(self::$_connection, $entry_id)) {
|
||||
$group_id = ldap_get_values(self::$_connection, $entry_id, "gidNumber");
|
||||
$group_name = ldap_get_values(self::$_connection, $entry_id, "cn");
|
||||
if (in_array($group_name[0], $associated_groups)) {
|
||||
$groups[] = new Ldap_Group($group_id[0], $group_name[0]);
|
||||
}
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
} // End Identity Gallery Driver
|
||||
|
||||
class Ldap_User implements User_Definition {
|
||||
private $ldap_entry;
|
||||
|
||||
public function __construct($ldap_entry=null) {
|
||||
$this->ldap_entry = $ldap_entry;
|
||||
}
|
||||
|
||||
public function display_name() {
|
||||
return $this->ldap_entry["displayname"][0];
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
switch($key) {
|
||||
case "name":
|
||||
return $this->ldap_entry["uid"][0];
|
||||
|
||||
case "guest":
|
||||
return false;
|
||||
|
||||
case "id":
|
||||
return $this->ldap_entry["uidnumber"][0];
|
||||
|
||||
case "groups":
|
||||
return IdentityProvider_Ldap_Driver::groups_for($this);
|
||||
|
||||
case "locale": // @todo
|
||||
return null;
|
||||
|
||||
case "admin":
|
||||
return in_array($this->ldap_entry["uid"][0],
|
||||
IdentityProvider_Ldap_Driver::$_params["admins"]);
|
||||
|
||||
case "dn":
|
||||
return $this->ldap_entry["dn"];
|
||||
|
||||
default:
|
||||
throw new Exception("@todo UNKNOWN_KEY ($key)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Ldap_Group implements Group_Definition {
|
||||
public $id;
|
||||
public $name;
|
||||
|
||||
public function __construct($id, $name) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->special = false;
|
||||
}
|
||||
}
|
6
modules/ldap/module.info
Normal file
6
modules/ldap/module.info
Normal file
@ -0,0 +1,6 @@
|
||||
name = "LDAP"
|
||||
description = "Use LDAP for authentication"
|
||||
version = 1
|
||||
|
||||
; Don't show this module on the module administration screen
|
||||
no_module_admin = 1
|
@ -1,4 +1,3 @@
|
||||
name = Tag Cloud
|
||||
name = "Tag Cloud"
|
||||
description = "3D tag cloud"
|
||||
|
||||
version = 1
|
||||
|
Reference in New Issue
Block a user