1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
|
<?php
/**
* Horde Hooks configuration file.
*
* THE HOOKS PROVIDED IN THIS FILE ARE EXAMPLES ONLY. DO NOT ENABLE THEM
* BLINDLY IF YOU DO NOT KNOW WHAT YOU ARE DOING. YOU HAVE TO CUSTOMIZE THEM
* TO MATCH YOUR SPECIFIC NEEDS AND SYSTEM ENVIRONMENT.
*
* This file is where you define any hooks, for preferences or general Horde
* use, that your installation uses. The functions in this file can vastly
* change how your installation behaves, so make sure to test out any changes
* here before doing them in a production environment.
*
* Hook function names are automatically determined. The format of the name
* is:
*
* _<type of hook>_hook_<name of hook>.
*
* Types of hooks that are defined in this file are 'prefs' (hooks to set the
* value of preferences), 'horde' (hooks for the Horde Framework scripts) and
* 'app' (where app is any Horde application name, like 'imp') hooks that are
* application specific.
*
* So, a hook to set the preference 'theme' would be named
* "_prefs_hook_theme".
*
* NOTE 1: Having a hook function in this file does NOT mean that the hook
* will automatically be used. YOU MUST enable the hook. For preferences, set
* 'hook' => true in that preferences attributes; for other hooks, there will
* be a configuration option in each application's conf.php file such as
* $conf['hooks']['hookname'] which must be set to true.
*
* NOTE 2: Preferences hooks are ONLY executed on login. Preferences are
* cached during a users session and, to avoid unnecessary overhead every time
* a preference is accessed, the results of hooks are cached as well. This
* leads to ...
*
* NOTE 3: Any preference that is NOT LOCKED, that is set by a hook, WILL BE
* SAVED WITH THAT VALUE. This means several things:
* 1) Users will get the results of the hook set for them in their
* preferences.
* 2) By virtue of this, the next time they log in and load their
* preferences, the hook will NOT be called, because in their last session,
* we saved the results of the hook for them. However, if the preference is
* locked, the result of the hook will never be saved.
*
* $Horde: horde/config/hooks.php.dist,v 1.73.6.13 2006/05/23 02:13:42 selsky Exp $
*/
// Example theme hook function. This shows how you can access things like the
// currently logged in user, global variables, server config, etc. It isn't,
// however, something you probably want to actually use in production, by
// virtue of demonstrating all those. :)
// if (!function_exists('_prefs_hook_theme')) {
// function _prefs_hook_theme($username = null)
// {
// if (Auth::getAuth() != 'chuck') {
// return 'mozilla';
// }
//
// global $registry;
// switch ($registry->getApp()) {
// case 'imp':
// return 'brown';
//
// case 'turba':
// return 'orange';
//
// case 'kronolith':
// return 'green';
//
// default:
// return '';
// }
// }
// }
// Example from_addr hook function. THIS FUNCTION ASSUMES THAT YOU ARE USING
// AN LDAP SERVER and that your /etc/ldap.conf or wherever it is correctly set
// to a valid host.
//
// You get passed NOTHING; you are responsible for bringing in to scope any
// information you need. You can "global" anything else you need. Return an
// address - either just the user@ side or a full address - and it will be
// used.
//
// If you want to use this code you will need to uncomment it below.
// if (!function_exists('_prefs_hook_from_addr')) {
// function _prefs_hook_from_addr($name = null)
// {
// if (is_null($name)) {
// $name = Auth::getAuth();
// }
// if (!empty($name)) {
// $base_context = 'o=myorg';
// $scope = 'sub';
//
// // You will probably need to replace cd= with uid=; this
// // syntax is for Netware 5.1 nldap.
// $cmd = '/usr/bin/ldapsearch -b ' . $base_context . ' -s ' . $scope . ' cn=';
// $cmd .= escapeShellCmd(Auth::getAuth());
// $cmd .= ' | /usr/bin/grep mail | /usr/bin/awk \'{print $2}\'';
// $mails = `$cmd`;
// $mail_array = explode("\n", $mails);
//
// // Send back the first email found, not the whole list.
// $mail = $mail_array['0'];
//
// // If no email address is found, then the login name will
// // be used.
// return (empty($mail) ? '' : $mail);
// }
//
// return '';
// }
// }
// Here is another way of doing the same thing.
// if (!function_exists('_prefs_hook_from_addr')) {
// function _prefs_hook_from_addr($user = null)
// {
// $ldapServer = '172.31.0.236';
// $ldapPort = '389';
// $searchBase = 'o=myorg';
//
// $ds = @ldap_connect($ldapServer, $ldapPort);
//
// if (is_null($user)) {
// $user = Auth::getAuth();
// }
//
// // You will probably need to replace cn= with uid=; this
// // syntax is for Netware 5.1 nldap.
// $searchResult = @ldap_search($ds, $searchBase, 'cn=' . $user);
// $information = @ldap_get_entries($ds, $searchResult);
// if ($information[0]['mail'][0] != '') {
// $name = $information[0]['mail'][0];
// } else {
// $name = $information[0]['cn'][0];
// }
//
// ldap_close($ds);
//
// return (empty($name) ? $user : $name);
// }
// }
// Here is an example fullname hook function to set the fullname from the GECOS
// information in the passwd file.
// if (!function_exists('_prefs_hook_fullname')) {
// function _prefs_hook_fullname($user = null)
// {
// if (is_null($user)) {
// $user = Auth::getBareAuth();
// }
// $array = posix_getpwnam($user);
// $gecos_array = explode(',', $array['gecos']);
// return (empty($gecos_array) ? $user : $gecos_array[0]);
// }
// }
// This is another example of how to get the user's full name, in this case
// from an ldap server. In this example we look if a Spanish name exists and
// return this or the standard 'cn' entry if not.
// if (!function_exists('_prefs_hook_fullname')) {
// function _prefs_hook_fullname($user = null)
// {
// $ldapServer = 'ldap.example.com';
// $ldapPort = '389';
// $searchBase = 'ou=people,o=example.com';
// $ldapcharset = 'utf-8';
// $outputcharset = NLS::getCharset();
//
// $ds = @ldap_connect($ldapServer, $ldapPort);
//
// if (is_null($user)) {
// $user = Auth::getAuth();
// }
// $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $user);
// $information = @ldap_get_entries($ds, $searchResult);
// if ($information[0]['cn;lang-es'][0] != '') {
// $name = $information[0]['cn;lang-es'][0];
// } else {
// $name = $information[0]['cn'][0];
// }
//
// ldap_close($ds);
//
// $name = String::convertCharset($name, $ldapcharset, $outputcharset);
// return (empty($name) ? $user : $name);
// }
// }
// Here is an example signature hook function to set the signature from the
// system taglines file; the string "%TAG%" (if present in a user's signature)
// will be replaced by the content of the file "/usr/share/tagline" (generated
// by the "TaRT" utility).
//
// Notice how we global in the $prefs array to get the user's current
// signature.
// if (!function_exists('_prefs_hook_signature')) {
// function _prefs_hook_signature($username = null)
// {
// $sig = $GLOBALS['prefs']->getValue('signature');
// if (preg_match('/%TAG%/', $sig)) {
// $tag = `cat /usr/share/tagline`;
// $sig = preg_replace('|%TAG%|', $tag, $sig);
// }
// return $sig;
// }
// }
// IE on Mac hangs when there are several icons to be loaded. At least on some
// systems. This hook disables the show_icons preference from Krononlith for
// these browsers.
// if (!function_exists('_prefs_hook_show_icons')) {
// function _prefs_hook_show_icons()
// {
// global $browser;
// if ($browser->getPlatform() == 'mac' &&
// $browser->getBrowser() == 'msie') {
// return false;
// } else {
// return true;
// }
// }
// }
// This hook is called when a user submits a signup request. It allows
// a chance to alter or validate the data submitted by a user before any
// attempts are made to add them to the system.
// if (!function_exists('_horde_hook_signup_preprocess')) {
// function _horde_hook_signup_preprocess($info) {
// $info['user_name'] = String::lower($info['user_name']);
// return $info;
// }
// }
// This hook is called when a signup is queued for administrative approval.
// This example sends a notification message to the web server
// administrator's e-mail address.
// if (!function_exists('_horde_hook_signup_queued')) {
// function _horde_hook_signup_queued_walkdata($fields, $data)
// {
// $msg = '';
// foreach ($data as $field => $value) {
// if ($field == 'password' || $field == 'url') {
// continue;
// }
//
// if (is_array($value)) {
// $msg .= _horde_hook_signup_queued_walkdata($fields, $value);
// } else {
// $field = isset($fields[$field]['label']) ?
// $fields[$field]['label'] : $field;
// $msg .= "$field: $value\n";
// }
// }
// return $msg;
// }
//
// function _horde_hook_signup_queued($userID, $data)
// {
// require_once 'Mail.php';
// global $conf, $registry;
//
// $headers = array(
// 'To' => $_SERVER['SERVER_ADMIN'],
// 'From' => $_SERVER['SERVER_ADMIN'],
// 'Subject' => 'New ' . $registry->get('name', 'horde') . ' Signup'
// );
//
// $extraFields = Horde::callHook('_horde_hook_signup_getextra');
//
// $msg = _("A new signup has been received and is awaiting your approval.");
// $msg .= "\n\n";
// $msg .= _horde_hook_signup_queued_walkdata($extraFields, $data);
// $msg .= "\n";
// $msg .= sprintf(_("You can approve this signup at %s"), Horde::applicationUrl('admin/user.php', true, -1));
//
// $mailer = Mail::factory($conf['mailer']['type'], $conf['mailer']['params']);
// return $mailer->send($_SERVER['SERVER_ADMIN'], $headers, $msg);
// }
// }
// Here is an example _horde_hook_signup_getextra function. It returns any
// extra fields which need to be filled in when a non registered user wishes
// to sign up.
// The example here takes the hypothetical case where we would want to store
// extra information about a user into a turba sql address book. All this
// function does then is to include the attributes.php file from the turba
// config directory and return the $attributes array.
// Otherwise any structure that would return an array with the following
// syntax would be valid:
// $somearray['somefieldname'] = array(...
// label - the text that the user will see attached to this field
// type - any allowed Horde_Form field type
// params - any allowed parameter to Horde_Form field types
// required - boolean, true or false whether this field is mandatory
// readonly - boolean, true or false whether this editable
// desc - any help text attached to the field
// NOTE: You DO NEED Turba to be correctly installed before you can use this
// example below.
// if (!function_exists('_horde_hook_signup_getextra')) {
// function _horde_hook_signup_getextra()
// {
// global $registry;
// require $registry->get('fileroot', 'turba') . '/config/attributes.php';
// return $attributes;
// }
// }
// Following on from the example in the above function, this is how a sample
// _horde_hook_signup_addextra function would look like.
// Here we connect to the database using the sql parameters configured in
// $conf and store the extra fields in turba_objects, using the $userId as the
// key for the object and values from the $extra array.
// You could create your own sql syntax or code to store this in whichever
// backend you require.
// NOTE: You DO NEED Turba to be correctly installed before you can use this
// example below. It also assumes that you are using an SQL backend.
// if (!function_exists('_horde_hook_signup_addextra')) {
// function _horde_hook_signup_addextra($userID, $extra)
// {
// global $conf;
//
// require_once 'DB.php';
// $_db = &DB::connect($conf['sql'], true);
//
// $fields = array();
// $values = array();
// foreach ($extra as $field => $value) {
// $fields[] = 'object_' . String::lower($field);
// $values[] = $_db->quote(String::convertCharset($value, NLS::getCharset(), $conf['sql']['charset']));
// }
// $fields[] = 'object_id';
// $values[] = $_db->quote($userID);
//
// $query = 'INSERT INTO turba_objects ( owner_id, ' . implode(', ', $fields) . ')';
// $query .= ' VALUES ( \'admin\', ' . implode(', ', $values) . ')';
// $result = $_db->query($query);
//
// return is_a($result, 'PEAR_Error') ? $result : true;
// }
// }
// Here is an example _horde_hook_preauthenticate that make Horde respect the
// Unix convention of not allowing login when a file named /etc/nologin exist.
// This function get passed the username, credential and realm information but
// they are not used in this example.
// if (!function_exists('_horde_hook_preauthenticate')) {
// function _horde_hook_preauthenticate($userID, $credential, $realm)
// {
// return !file_exists('/etc/nologin');
// }
// }
// Here is an example of validating the user's right to login to Horde by
// consulting group membership in an LDAP directory. That way, if your Horde
// installation is configured to authenticate against IMP which in turn
// authenticate via IMAP, it is still possible to limit access to Horde by
// group membership. The following example had been made with an MS Active
// Directory in mind. Note that if the LDAP directory is unavailable or some
// other error occur, authentication will fail.
// if (!function_exists('_horde_hook_postauthenticate')) {
// function _horde_hook_postauthenticate($userID, $credential, $realm)
// {
// $ldapServer = 'ad.example.com';
// $ldapPort = '389';
// // Note that credential is sent plain-text in this case, so don't use
// // privileged account here or setup SSL (by using port 636 above).
// $binddn = 'cn=WithoutPrivilege,dc=ulaval-dev,dc=ca';
// $bindpw = 'Remember this is sent in the clear unless SSL is used';
// $searchBase = 'ou=People,dc=example,dc=com';
// // Attribute to match $userID against in search
// $userAttr = 'sAMAccountName';
// // Group membership attribute, need to be all lowercase
// $groupAttr = 'memberof';
// // Attribute to check for right to use Horde
// $groupdn = 'cn=HordeUser,ou=People,dc=example,dc=com';
// $ret = true;
//
// $ds = @ldap_connect($ldapServer, $ldapPort);
//
// if (@ldap_bind($ds, $binddn, $bindpw)) {
// $searchResult = @ldap_search($ds, $searchBase, $userAttr . '=' . $userID, array($groupAttr), 0, 1, 5);
// if ($information = @ldap_get_entries($ds, $searchResult)) {
// // make pattern case-insensitive
// $pattern = '/' . $groupdn . '/i';
// foreach ($information[0][$groupAttr] as $group) {
// if (preg_match($pattern, $group)) {
// $ret = true;
// break;
// }
// }
// }
// }
//
// ldap_close($ds);
// return $ret;
// }
// }
// Here is an example of creating credentials needed by the LDAP Auth driver
// for adding/deleting/updating users.
// if (!function_exists('_horde_hook_authldap')) {
// function _horde_hook_authldap($userID, $credentials = null)
// {
// $entry['dn'] = 'uid=' . $userID . ',ou=People,dc=example.com';
// if (isset($credentials) && isset($credentials['user_fullname'])) {
// $entry['cn'] = $credentials['user_fullname'];
// } else {
// $entry['cn'] = $userID;
// }
// $entry['sn'] = $userID;
// $entry['objectclass'][0] = 'top';
// $entry['objectclass'][1] = 'person';
// $entry['objectclass'][2] = 'qmailuser';
// $entry['objectclass'][3] = 'CourierMailACcount';
// $entry['mailhost'] = 'mail.example.com';
// $entry['mailMessageStore'] = '/home/mail/' . $userID;
// $entry['homeDirectory'] = '/home/mail/' . $userID;
// $entry['mailbox'] = $entry['homeDirectory'] . '/Maildir';
// $entry['uid'] = $userID;
// $entry['accountStatus'] = 'active';
// $entry['mailQuota'] = '104857600S';
// $entry['mail'] = $userID;
// $entry['uidNumber'] = 501;
// $entry['gidNumber'] = 501;
//
// // need to check for new users (password) and edited users (user_pass_2)
// if (isset($credentials) && isset($credentials['password'])) {
// $entry['userPassword'] = '{MD5}' . base64_encode(mHash(MHASH_MD5, $credentials['password']));
// } elseif (isset($credentials) && isset($credentials['user_pass_2'])) {
// $entry['userPassword'] = '{MD5}' . base64_encode(mHash(MHASH_MD5, $credentials['user_pass_2']));
// }
// $entry['deliveryMode'] = 'nolocal';
// return $entry;
// }
// }
// This function is called when a Horde_Share object is created. It takes a
// reference to the Horde_Share object that is being created as well as th
// name of the application for which the Horde_Share object is being created as
// parameters. The return value is ignored.
// if (!function_exists('_horde_hook_share_init')) {
// function _horde_hook_share_init(&$share_object, $app)
// {
// if ($GLOBALS['conf']['kolab']['enabled']) {
// require_once 'Horde/Kolab.php';
// Kolab::synchroniseShares($share_object, $app);
// }
// }
// }
// The following three functions are examples of those that can be called when
// adding, modifying and removing shares, respectively. They are called with
// the share that is being added, modified or removed as their single
// parameter. If a PEAR_Error object is returned the respective share
// operation will fail with the error result.
// if (!function_exists('_horde_hook_share_add')) {
// function _horde_hook_share_add(&$share)
// {
// require_once 'Horde/Kolab.php';
// return Kolab::updateShare($share);
// }
// }
// if (!function_exists('_horde_hook_share_modify')) {
// function _horde_hook_share_modify(&$share)
// {
// require_once 'Horde/Kolab.php';
// return Kolab::updateShare($share);
// }
// }
//
// if (!function_exists('_horde_hook_share_remove')) {
// function _horde_hook_share_remove(&$share)
// {
// require_once 'Horde/Kolab.php';
// return Kolab::removeShare($share);
// }
// }
// This example is of a function that can be called when a share listing is
// requested. It takes a userid, a permissions level, an optional string
// containing a userid to restrict the owner of the shares returned, and the
// result of the corresponding Horde_Share::listShares() call as its
// parameters. As is the case in the previous three functions, if a PEAR_Error
// result is returned the Horde_Share::listShares() call that triggered this
// hook will fail with the returned result.
// if (!function_exists('_horde_hook_share_list')) {
// function _horde_hook_share_list($userid, $perm, $owner, &$share_list)
// {
// global $registry;
// //error_log('Number of ' . $GLOBALS['registry']->getApp() . ' shares' . ($owner ?
// // ' owned by ' . $owner : '') . ' available to ' . $userid . ' at perms level ' .
// // $perm . ': ' . count($share_list));
// return true;
// }
// }
// Here is an example _username_hook_frombackend function. It appends the
// virtual domain to the user name.
//
// ex. $HTTP_HOST = 'mail.mydomain.com', $userID = 'myname' returns:
// 'myname@mydomain.com'
// if (!function_exists('_username_hook_frombackend')) {
// function _username_hook_frombackend($userID)
// {
// $vdomain = getenv('HTTP_HOST');
// $vdomain = preg_replace('|^mail\.|i', '', $vdomain);
// $vdomain = String::lower($vdomain);
//
// return $userID . '@' . $vdomain;
// }
// }
// Here is an example _username_hook_tobackend function as a counterpart of the
// previous example. It strips the virtual domain from the user name.
//
// ex. $HTTP_HOST = 'mail.mydomain.com', $userID = 'myname' returns:
// 'myname@mydomain.com'
// if (!function_exists('_username_hook_tobackend')) {
// function _username_hook_tobackend($userID)
// {
// $vdomain = getenv('HTTP_HOST');
// $vdomain = preg_replace('|^mail\.|i', '', $vdomain);
// $vdomain = '@' . String::lower($vdomain);
//
// if (substr($userID, -strlen($vdomain)) == $vdomain) {
// $userID = substr($userID, 0, -strlen($vdomain));
// }
//
// return $userID;
// }
// }
// Here is an example _username_hook_frombackend function. It converts the user
// name to all lower case. This might be necessary if an authentication backend
// is case insensitive to take into account that Horde's preference system is
// case sensitive.
//
// ex. $userID = 'MyName' returns: 'myname'
// if (!function_exists('_username_hook_frombackend')) {
// function _username_hook_frombackend($userID)
// {
// return String::lower($userID);
// }
// }
// Here is an example _perms_hook_denied function. It is called if a user
// tries to make an action that is under permission control and that he
// doesn't have sufficient permissions for. It can be used to show the user a
// custom message including HTML code (you have to take care about HTML
// escaping on your own), or to interrupt the code flow and send the user to a
// different page for example.
// if (!function_exists('_perms_hook_denied')) {
// function _perms_hook_denied($permission)
// {
// if (($pos = strpos($permission, ':')) === false) {
// $app = $permission;
// } else {
// $app = substr($permission, 0, $pos);
// }
//
// return sprintf('Permission denied. Click <a href="http://www.example.com/upgrade.php?app=%s">HERE</a> to upgrade %s.',
// $app, $GLOBALS['registry']->get('name'));
// }
// }
// This is an example of a group hook. To use it you must set the group
// driver to hooks in conf.php. Then you must create a IT_department group
// (because that is how we know what hook to call). You can add users to the
// group as normal, and in addition this function will be called to
// dynamically include users in the group. In this example we will look up
// whether or not this user is part of the IT department using an external
// database.
// if (!function_exists('_group_hook_IT_department')) {
// function _group_hook_IT_department($userName)
// {
// global $conf;
//
// $dept = 'IT';
// include_once 'DB.php';
// $_db = &DB::connect($conf['sql'], true);
// $query = 'SELECT COUNT(*) FROM departments WHERE user_name = ? AND department = ?';
// $values = array($userName, $dept);
// $result = $_db->getOne($query, $values);
// if (!is_a($result, 'PEAR_Error') && $result > 0) {
// return true;
// } else {
// return false;
// }
// }
// }
// This is an example of a post-push hook; it is called right after an
// application is pushed successfully onto the app stack.
// if (!function_exists('_horde_hook_post_pushapp')) {
// function _horde_hook_post_pushapp($app)
// {
// if (in_array($app, array('kronolith', 'turba', 'horde', 'ingo')) ||
// strpos($_SERVER['PHP_SELF'], 'prefs.php') !== false) {
// require_once $GLOBALS['registry']->get('fileroot', 'dimp') . '/lib/Notification/Listener/statusOverride.php';
// $GLOBALS['notification'] = &Notification::singleton();
// $GLOBALS['notification']->attach('status', null, 'Notification_Listener_dimp_statusOverride');
// }
// }
// }
// Here is an example _imp_hook_trailer function to set the trailer from the
// system taglines file; the string "@@TAG@@" (if present in a trailer) will be
// replaced by the content of the file "/usr/share/tagline" (generated by the
// "TaRT" utility).
// if (!function_exists('_imp_hook_trailer')) {
// function _imp_hook_trailer($trailer)
// {
// if (preg_match('/@@TAG@@/', $trailer)) {
// $tag = `cat /usr/share/tagline`;
// $trailer = preg_replace('|@@TAG@@|', $tag, $trailer);
// }
// return $trailer;
// }
// }
// Here is an another example _imp_hook_trailer function to set the trailer
// from the LDAP directory for each domain. This function replaces the current
// trailer with the data it gets from ispmanDomainSignature.
// if (!function_exists('_imp_hook_trailer')) {
// function _imp_hook_trailer($trailer)
// {
// $vdomain = getenv('HTTP_HOST');
// $vdomain = preg_replace('|^.*?\.|i', '', $vdomain);
// $vdomain = String::lower($vdomain);
// $ldapServer = 'localhost';
// $ldapPort = '389';
// $searchBase = 'ispmanDomain=' . $vdomain . ",o=ispman";
//
// $ds = @ldap_connect($ldapServer, $ldapPort);
// $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $vdomain);
// $information = @ldap_get_entries($ds, $searchResult);
// $trailer= $information[0]['ispmandomainsignature'][0];
// ldap_close($ds);
//
// return $trailer;
// }
// }
// Here is an example _imp_hook_vinfo function. If $type == 'vdomain', this
// function returns the HTTP_HOST variable after removing the 'mail.'
// subdomain.
//
// If $type == 'username', this function returns a unique username composed of
// $_SESSION['imp']['user'] + vdomain.
//
// ex. $HTTP_HOST = 'mail.mydomain.com', $_SESSION['imp']['user'] = 'myname':
// $vdomain = 'mydomain.com'
// $username = 'myname_mydomain_com'
// if (!function_exists('_imp_hook_vinfo')) {
// function _imp_hook_vinfo($type = 'username')
// {
// $vdomain = getenv('HTTP_HOST');
// $vdomain = preg_replace('|^mail\.|i', '', $vdomain);
// $vdomain = String::lower($vdomain);
//
// if ($type == 'username') {
// return preg_replace('|\.|', '_', $_SESSION['imp']['user'] . '_' . $vdomain);
// } elseif ($type == 'vdomain') {
// return $vdomain;
// } else {
// return PEAR::raiseError('invalid type: ' . $type);
// }
// }
// }
// Here is an example of the _imp_hook_fetchmail_filter function to run
// SpamAssassin on email before it is written to the mailbox.
// Note: to use the spamassassin instead of spamd, change 'spamc' to
// 'spamassassin -P' and add any other important arguments, but realize spamc
// is MUCH faster than spamassassin.
// WARNING: Make sure to use the --noadd-from filter on spamd or spamassassin
// if (!function_exists('_imp_hook_fetchmail_filter')) {
// function _imp_hook_fetchmail_filter($message)
// {
// // Where does SpamAssassin live, and what username should we use
// // for preferences?
// $cmd = '/usr/local/bin/spamc';
// $username = Auth::getAuth();
// // If you use the _sam_hook_username() hook, uncomment the next line
// //$username = _sam_hook_username($username);
// $username = escapeshellarg($username);
//
// // Also, we remove the file ourselves; this hook may be called
// // hundreds of times per run depending on how many messages we fetch
// $file = Horde::getTempFile('horde', false);
//
// // Call SpamAssassin; pipe the new message to our tempfile
// $fp = popen("$cmd -u $username > $file", 'w');
// fwrite($fp, $message);
// pclose($fp);
//
// // Read the new message from the temporary file
// $message = file_get_contents($file);
// unlink($file);
// return $message;
// }
// }
// Here is an example signature hook function to set the signature from the
// system taglines file; the string "%TAG%" (if present in a user's signature)
// will be replaced by the content of the file "/usr/share/tagline" (generated
// by the "TaRT" utility).
// if (!function_exists('_imp_hook_signature')) {
// function _imp_hook_signature($sig)
// {
// if (preg_match('/%TAG%/', $sig)) {
// $tag = `cat /usr/share/tagline`;
// $sig = preg_replace('/%TAG%/', $tag, $sig);
// }
//
// return $sig;
// }
// }
// This is an example hook function for the IMP redirection scheme. This
// function is called when the user opens a mailbox in IMP, and allows the
// client to be redirected based on the mailbox name. The return value of this
// function should be a valid page within a horde application which will be
// placed in a "Location" header to redirect the client. The only parameter
// is the name of the mailbox which the user has opened. If an empty string
// is returned the user is not redirected.
// if (!function_exists('_imp_hook_mbox_redirect')) {
// function _imp_hook_mbox_redirect($mailbox)
// {
// require_once 'Horde/Kolab.php';
//
// if (strpos($mailbox, "INBOX/Calendar") !== false
// || preg_match("!^user/[^/]+/Calendar!", $mailbox)) {
// return $GLOBALS['registry']->get('webroot', 'kronolith');
// } elseif (strpos($mailbox, "INBOX/Tasks") !== false
// || preg_match("!^user/[^/]+/Tasks!", $mailbox)) {
// return $GLOBALS['registry']->get('webroot', 'nag');
// } elseif (strpos($mailbox, "INBOX/Notes") !== false
// || preg_match("!^user/[^/]+/Notes!", $mailbox)) {
// return $GLOBALS['registry']->get('webroot', 'mnemo');
// } elseif (strpos($mailbox, "INBOX/Contacts") !== false
// || preg_match("!^user/[^/]+/Contacts!", $mailbox)) {
// return $GLOBALS['registry']->get('webroot', 'turba');
// }
//
// return '';
// }
// }
// This is an example hook function for the IMP mailbox icon scheme. This
// function is called when the folder list is created and a "standard" folder
// is to be displayed - it allows custom folder icons to be specified.
// ("Standard" means all folders except the INBOX, sent-mail folders and
// trash folders.)
// If a mailbox name doesn't appear in the below list, the default mailbox
// icon is displayed.
// if (!function_exists('_imp_hook_mbox_icons')) {
// function _imp_hook_mbox_icons()
// {
// static $newmailboxes;
//
// if (!empty($newmailboxes)) {
// return $newmailboxes;
// }
//
// require_once 'Horde/Kolab.php';
//
// $kc = new Kolab_Cyrus($GLOBALS['conf']['kolab']['server']);
// $mailboxes = $kc->listMailBoxes();
// $newmailboxes = array();
//
// foreach ($mailboxes as $box) {
// $box = preg_replace("/^{[^}]+}/", "", $box);
// if (strpos($box, "INBOX/Calendar") !== false
// || preg_match("!^user/[^/]+/Calendar!", $box)) {
// $newmailboxes[$box] = Horde::img(
// $GLOBALS['registry']->get('icon', 'kronolith'),
// _("Calendar"),
// 'width="16" height="16" style="vertical-align:middle"',
// ''
// );
// } elseif (strpos($box, "INBOX/Tasks") !== false
// || preg_match("!^user/[^/]+/Tasks!", $box)) {
// $newmailboxes[$box] = Horde::img(
// $GLOBALS['registry']->get('icon', 'nag'),
// _("Tasks"),
// 'width="16" height="16" style="vertical-align:middle"',
// ''
// );
// } elseif (strpos($box, "INBOX/Notes") !== false
// || preg_match("!^user/[^/]+/Notes!", $box)) {
// $newmailboxes[$box] = Horde::img(
// $GLOBALS['registry']->get('icon', 'mnemo'),
// _("Notes"),
// 'width="16" height="16" style="vertical-align:middle"',
// ''
// );
// } elseif (strpos($box, "INBOX/Contacts") !== false
// || preg_match("!^user/[^/]+/Contacts!", $box)) {
// $newmailboxes[$box] = Horde::img(
// $GLOBALS['registry']->get('icon', 'turba'),
// _("Contacts"),
// 'width="16" height="16" style="vertical-align:middle"',
// ''
// );
// }
// }
//
// return $newmailboxes;
// }
// }
// This is an example hook function for the IMP spam reporting bouce option.
// This function is called when the message is about to be bounced - it
// will return the email address to bounce to. This is handy for spam
// reporting software (e.g. DSPAM) which has different e-mail aliases for
// spam reporting for each user.
// if (!function_exists('_imp_hook_spam_bounce')) {
// function _imp_hook_spam_bounce($action)
// {
// $prefix = ($action == 'spam') ? 'spam-' : 'fp-';
// return $prefix . Auth::getBareAuth() . '@example.com';
// }
// }
// Here an example _sam_hook_username function to set the username that
// SpamAssassin sees to one different from the Horde username.
// if (!function_exists('_sam_hook_username')) {
// function _sam_hook_username($horde_uid)
// {
// if (strstr($horde_uid, '@')) {
// $parts = explode('@', $horde_uid);
// return $parts[0];
// } else {
// return $horde_uid;
// }
// }
// }
// Here is an example _turba_hook_encode_password (and decode). encode is
// called when we store a value; decode when we display it. Passwords should
// be MD5 encoded, but not displayed.
//
// IMPORTANT: The last parameter in these examples (&$object) is only
// passed by Turba 2.1 and later. If you are using Turba 2.0, then you
// must remove the &$object parameter.
// if (!function_exists('_turba_hook_encode_password')) {
// function _turba_hook_encode_password($new_password, $old_password, &$contact)
// {
// if (is_null($new_password) || $new_password == '' ||
// $new_password == '[Not Displayed]') {
// return $old_password;
// } else {
// return md5($new_password);
// }
// }
// function _turba_hook_decode_password($password, &$contact)
// {
// if (strstr($_SERVER['PHP_SELF'], 'editobject')) {
// return null;
// } else {
// return '[Not Displayed]';
// }
// }
// }
// Here is an example _passwd_hook_username function to translate what the
// user enters, in the username box, into what the backend expects. If we want
// to add @example.com to the end of the username then enable the hook and use
// this function.
// if (!function_exists('_passwd_hook_username')) {
// function _passwd_hook_username($userid)
// {
// return $userid . '@example.com';
// }
// }
// Here is an example _passwd_hook_default_username function to set the
// username the passwd module sees when resetting passwords based on userid
// and realm. The default is to take a username of user@domain.tld and change
// it to user. If we want to leave it untouched, enable the hook and use this
// function.
// if (!function_exists('_passwd_hook_default_username')) {
// function _passwd_hook_default_username($userid)
// {
// return $userid;
// }
// }
// Here is an example _passwd_hook_userdn function that you can use to provide
// your ldap server with a userdn so that you do not have to perform anonymous
// binds. The function takes Auth::getAuth() as a parameter
// if (!function_exists('_passwd_hook_userdn')) {
// function _passwd_hook_userdn($auth)
// {
// return 'uid=' . $auth . ',o=example.com';
// }
// }
// This is an example of a hook to set custom tags to be included in a Giapeto
// page template. In this example a tag containing the current date is set to
// the $template object and which is then available in the page template as:
// <tag:date />
// if (!function_exists('_giapeto_hook_settags')) {
// function _giapeto_hook_settags(&$template)
// {
// $template->set('date', strftime('%a, %e %b %Y'));
// }
// }
// This is an example of a group hook. To use it you must set the group
// driver to hooks in conf.php. Then you must create a IT_department group
// (because that is how we know what hook to call). You can add users to the
// group as normal, and in addition this function will be called to
// dynamically include users in the group. In this example we will look up
// whether or not this user is part of the IT department using an external
// database.
// Default Kolab hooks:
if (!empty($GLOBALS['conf']['kolab']['enabled'])) {
require_once 'Horde/Kolab.php';
if (!function_exists('_horde_hook_share_init')) {
function _username_hook_frombackend($userID)
{
// Connect to the LDAP server.
$ds = ldap_connect(
$GLOBALS['conf']['kolab']['ldap']['server'],
$GLOBALS['conf']['kolab']['ldap']['port']
);
if (!$ds) {
return $userID;
}
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
// Bind anonymously.
$result = @ldap_bind($ds);
if (!$result) {
return $userID;
}
// Find the user's DN.
$result = ldap_search(
$ds,
$GLOBALS['conf']['kolab']['ldap']['basedn'],
'uid=' . $userID
);
$entry = ldap_first_entry($ds, $result);
if ($entry === false) {
// The user already authenticated with his email address.
return $userID;
}
$email = ldap_get_values($ds, $entry, 'mail');
return $email[0];
}
function _horde_hook_share_init(&$share_object, $app)
{
Kolab::synchroniseShares($share_object, $app);
}
function _horde_hook_share_add(&$share)
{
return Kolab::updateShare($share);
}
function _horde_hook_share_modify(&$share)
{
return Kolab::updateShare($share);
}
function _horde_hook_share_remove(&$share)
{
return Kolab::removeShare($share);
}
function _imp_hook_mbox_redirect($mailbox)
{
switch (Kolab::getMailboxType($mailbox)) {
case 'event':
return $GLOBALS['registry']->get('webroot', 'kronolith');
case 'task':
return $GLOBALS['registry']->get('webroot', 'nag');
case 'note':
return $GLOBALS['registry']->get('webroot', 'mnemo');
case 'contact':
return $GLOBALS['registry']->get('webroot', 'turba');
default:
return '';
}
}
function _imp_hook_mbox_icons()
{
static $icons;
if (!empty($icons)) {
return $icons;
}
$folders = Kolab::listFolders();
$icons = array();
foreach ($folders as $folder) {
$name = preg_replace('/^{[^}]+}/', '', $folder[0]);
switch ($folder[1]) {
case 'event':
$icons[$name] = Horde::img(
$GLOBALS['registry']->get('icon', 'kronolith'),
_("Calendar"),
'width="16" height="16" style="vertical-align:middle"',
''
);
break;
case 'task':
$icons[$name] = Horde::img(
$GLOBALS['registry']->get('icon', 'nag'),
_("Tasks"),
'width="16" height="16" style="vertical-align:middle"',
''
);
break;
case 'note':
$icons[$name] = Horde::img(
$GLOBALS['registry']->get('icon', 'mnemo'),
_("Notes"),
'width="16" height="16" style="vertical-align:middle"',
''
);
break;
case 'contact':
$icons[$name] = Horde::img(
$GLOBALS['registry']->get('icon', 'turba'),
_("Contacts"),
'width="16" height="16" style="vertical-align:middle"',
''
);
break;
}
}
return $icons;
}
}
}
|