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