| [ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * Horde external API interface. 4 * 5 * This file defines Horde's external API interface. Other 6 * applications can interact with Horde through this API. 7 * 8 * $Horde: horde/lib/api.php,v 1.43.2.5 2006/05/04 13:27:28 jan Exp $ 9 * 10 * @package Horde 11 */ 12 13 /* Complex types. */ 14 $_types = array( 15 '{urn:horde}stringArray' => array(array('item' => 'string')), 16 'hashItem' => array('key' => 'string', 'value' => 'string'), 17 'hash' => array(array('item' => '{urn:horde}hashItem')), 18 'hashHashItem' => array('key' => 'string', 'value' => '{urn:horde}hash'), 19 'hashHash' => array(array('item' => '{urn:horde}hashHashItem'))); 20 21 /* Listings. */ 22 $_services['perms'] = array( 23 'args' => array(), 24 'type' => '{urn:horde}stringArray'); 25 26 $_services['admin_list'] = array(true); 27 28 $_services['listApps'] = array( 29 'args' => array('filter' => '{urn:horde}stringArray'), 30 'type' => '{urn:horde}stringArray' 31 ); 32 33 $_services['listAPIs'] = array( 34 'args' => array(), 35 'type' => '{urn:horde}stringArray' 36 ); 37 38 /* Blocks. */ 39 $_services['blockTitle'] = array( 40 'args' => array('app' => 'string', 'name' => 'string', 'params' => '{urn:horde}hash'), 41 'type' => 'string' 42 ); 43 44 $_services['blockContent'] = array( 45 'args' => array('app' => 'string', 'name' => 'string', 'params' => '{urn:horde}hash'), 46 'type' => 'string' 47 ); 48 49 $_services['blocks'] = array( 50 'args' => array(), 51 'type' => '{urn:horde}hash' 52 ); 53 54 /* User data. */ 55 $_services['getPreference'] = array( 56 'args' => array('app' => 'string', 'pref' => 'string'), 57 'type' => 'string' 58 ); 59 60 $_services['setPreference'] = array( 61 'args' => array('app' => 'string', 'pref' => 'string', 'value' => 'string'), 62 'type' => 'boolean' 63 ); 64 65 $_services['removeUserData'] = array( 66 'args' => array('user' => 'string'), 67 'type' => 'boolean' 68 ); 69 70 /* Groups. */ 71 $_services['addGroup'] = array( 72 'args' => array('name' => 'string', 'parent' => 'string'), 73 'type' => 'boolean' 74 ); 75 76 $_services['removeGroup'] = array( 77 'args' => array('name' => 'string'), 78 'type' => 'boolean' 79 ); 80 81 //$_services['getGroups']; ??? 82 83 $_services['addUserToGroup'] = array( 84 'args' => array('name' => 'string', 'user' => 'string'), 85 'type' => 'boolean' 86 ); 87 88 $_services['addUsersToGroup'] = array( 89 'args' => array('name' => 'string', 'users' => '{urn:horde}stringArray'), 90 'type' => 'boolean' 91 ); 92 93 $_services['removeUserFromGroup'] = array( 94 'args' => array('name' => 'string', 'user' => 'string'), 95 'type' => 'boolean' 96 ); 97 98 $_services['removeUsersFromGroup'] = array( 99 'args' => array('name' => 'string', 'users' => '{urn:horde}stringArray'), 100 'type' => 'boolean' 101 ); 102 103 $_services['listUsersOfGroup'] = array( 104 'args' => array('name' => 'string'), 105 'type' => '{urn:horde}stringArray' 106 ); 107 108 /* Shares. */ 109 $_services['addShare'] = array( 110 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'shareTitle' => 'string', 'userName' => 'string'), 111 'type' => 'boolean' 112 ); 113 114 $_services['removeShare'] = array( 115 'args' => array('shareRoot' => 'string', 'shareName' => 'string'), 116 'type' => 'boolean' 117 ); 118 119 $_services['listSharesOfOwner'] = array( 120 'args' => array('shareRoot' => 'string', 'userName' => 'string'), 121 'type' => '{urn:horde}stringArray' 122 ); 123 124 $_services['addUserPermissions'] = array( 125 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'userName' => 'string', 'permissions' => '{urn:horde}stringArray'), 126 'type' => 'boolean' 127 ); 128 129 $_services['addGroupPermissions'] = array( 130 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'groupName' => 'string', 'permissions' => '{urn:horde}stringArray'), 131 'type' => 'boolean' 132 ); 133 134 $_services['setUserPermissions'] = array( 135 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'userName' => 'string', 'permissions' => '{urn:horde}stringArray'), 136 'type' => 'boolean' 137 ); 138 139 $_services['setGroupPermissions'] = array( 140 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'groupName' => 'string', 'permissions' => '{urn:horde}stringArray'), 141 'type' => 'boolean' 142 ); 143 144 $_services['removeUserPermissions'] = array( 145 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'userName' => 'string'), 146 'type' => 'boolean' 147 ); 148 149 $_services['removeGroupPermissions'] = array( 150 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'groupName' => 'string'), 151 'type' => 'boolean' 152 ); 153 154 $_services['listUserPermissions'] = array( 155 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'userName' => 'string'), 156 'type' => '{urn:horde}stringArray' 157 ); 158 159 $_services['listGroupPermissions'] = array( 160 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'groupName' => 'string'), 161 'type' => '{urn:horde}stringArray' 162 ); 163 164 $_services['listUsersOfShare'] = array( 165 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'permissions' => '{urn:horde}stringArray'), 166 'type' => '{urn:horde}stringArray' 167 ); 168 169 $_services['listGroupsOfShare'] = array( 170 'args' => array('shareRoot' => 'string', 'shareName' => 'string', 'permissions' => '{urn:horde}stringArray'), 171 'type' => '{urn:horde}stringArray' 172 ); 173 174 175 /* Listings. */ 176 function _horde_perms() 177 { 178 $perms = array(); 179 180 $perms['tree']['horde']['max_blocks'] = false; 181 $perms['title']['horde:max_blocks'] = _("Maximum Number of Portal Blocks"); 182 $perms['type']['horde:max_blocks'] = 'int'; 183 184 return $perms; 185 } 186 187 function _horde_admin_list() 188 { 189 return array('configuration' => array( 190 'link' => '%application%/admin/setup/', 191 'name' => _("_Setup"), 192 'icon' => 'config.png'), 193 'users' => array( 194 'link' => '%application%/admin/user.php', 195 'name' => _("_Users"), 196 'icon' => 'user.png'), 197 'groups' => array( 198 'link' => '%application%/admin/groups.php', 199 'name' => _("_Groups"), 200 'icon' => 'group.png'), 201 'perms' => array( 202 'link' => '%application%/admin/perms/index.php', 203 'name' => _("_Permissions"), 204 'icon' => 'perms.png'), 205 'datatree' => array( 206 'link' => '%application%/admin/datatree.php', 207 'name' => _("_DataTree"), 208 'icon' => 'datatree.png'), 209 'sessions' => array( 210 'link' => '%application%/admin/sessions.php', 211 'name' => _("Sessions"), 212 'icon' => 'user.png'), 213 'phpshell' => array( 214 'link' => '%application%/admin/phpshell.php', 215 'name' => _("P_HP Shell"), 216 'icon' => 'mime/php.png'), 217 'sqlshell' => array( 218 'link' => '%application%/admin/sqlshell.php', 219 'name' => _("S_QL Shell"), 220 'icon' => 'sql.png'), 221 'cmdshell' => array( 222 'link' => '%application%/admin/cmdshell.php', 223 'name' => _("_CLI"), 224 'icon' => 'shell.png'), 225 ); 226 } 227 228 function _horde_listApps($filter = null) 229 { 230 return $GLOBALS['registry']->listApps($filter); 231 } 232 233 function _horde_listAPIs() 234 { 235 return $GLOBALS['registry']->listAPIs(); 236 } 237 238 /* Blocks. */ 239 function &_horde_block($app, $name, $params = array()) 240 { 241 global $registry; 242 243 require_once 'Horde/Block.php'; 244 require_once 'Horde/Block/Collection.php'; 245 246 $result = $registry->pushApp($app); 247 if (!is_a($result, 'PEAR_Error')) { 248 $result = Horde_Block_Collection::getBlock($app, $name, $params); 249 $registry->popApp($app); 250 } 251 return $result; 252 } 253 254 function _horde_blockTitle($app, $name, $params = array()) 255 { 256 $block = &_horde_block($app, $name, $params); 257 if (is_a($block, 'PEAR_Error')) { 258 return $block->getMessage(); 259 } 260 return $block->getTitle(); 261 } 262 263 function _horde_blockContent($app, $name, $params = array()) 264 { 265 $block = &_horde_block($app, $name, $params); 266 if (is_a($block, 'PEAR_Error')) { 267 return $block->getMessage(); 268 } 269 return $block->getContent(); 270 } 271 272 function _horde_blocks() 273 { 274 require_once 'Horde/Block/Collection.php'; 275 $collection = &Horde_Block_Collection::singleton(); 276 if (is_a($collection, 'PEAR_Error')) { 277 return $collection; 278 } else { 279 return $collection->getBlocksList(); 280 } 281 } 282 283 /* User data. */ 284 function _horde_getPreference($app, $pref) 285 { 286 $GLOBALS['registry']->loadPrefs($app); 287 return $GLOBALS['prefs']->getValue($pref); 288 } 289 290 function _horde_setPreference($app, $pref, $value) 291 { 292 $GLOBALS['registry']->loadPrefs($app); 293 return $GLOBALS['prefs']->setValue($pref, $value); 294 } 295 296 function _horde_removeUserData($user) 297 { 298 global $conf; 299 300 require_once 'Horde/Prefs.php'; 301 $prefs = &Prefs::singleton($conf['prefs']['driver'], null, $user); 302 if (is_a($result = $prefs->clear(), 'PEAR_Error')) { 303 return $result; 304 } 305 } 306 307 /* Groups. */ 308 309 /** 310 * Adds a group to the groups system. 311 * 312 * @param string $name The group's name. 313 * @param string $parent The group's parent's name. 314 */ 315 function _horde_addGroup($name, $parent = null) 316 { 317 if (empty($parent)) { 318 $parent = DATATREE_ROOT; 319 } 320 321 require_once 'Horde/Group.php'; 322 $groups = &Group::singleton(); 323 324 if (is_a($group = &$groups->newGroup($name, $parent), 'PEAR_Error')) { 325 return $group; 326 } 327 328 return $groups->addGroup($group); 329 } 330 331 /** 332 * Removes a group from the groups system. 333 * 334 * @param string $name The group's name. 335 */ 336 function _horde_removeGroup($name) 337 { 338 require_once 'Horde/Group.php'; 339 $groups = &Group::singleton(); 340 341 if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { 342 return $group; 343 } 344 345 return $groups->removeGroup($group, true); 346 } 347 348 /** 349 * Adds a user to a group. 350 * 351 * @param string $name The group's name. 352 * @param string $user The user to add. 353 */ 354 function _horde_addUserToGroup($name, $user) 355 { 356 require_once 'Horde/Group.php'; 357 $groups = &Group::singleton(); 358 359 if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { 360 return $group; 361 } 362 363 return $group->addUser($user); 364 } 365 366 /** 367 * Adds multiple users to a group. 368 * 369 * @param string $name The group's name. 370 * @param array $users The users to add. 371 */ 372 function _horde_addUsersToGroup($name, $users) 373 { 374 require_once 'Horde/Group.php'; 375 $groups = &Group::singleton(); 376 377 if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { 378 return $group; 379 } 380 381 foreach ($users as $user) { 382 $group->addUser($user, false); 383 } 384 385 return $group->save(); 386 } 387 388 /** 389 * Removes a user from a group. 390 * 391 * @param string $name The group's name. 392 * @param string $user The user to add. 393 */ 394 function _horde_removeUserFromGroup($name, $user) 395 { 396 require_once 'Horde/Group.php'; 397 $groups = &Group::singleton(); 398 399 if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { 400 return $group; 401 } 402 403 return $group->removeUser($user); 404 } 405 406 /** 407 * Removes multiple users from a group. 408 * 409 * @param string $name The group's name. 410 * @param array $users The users to add. 411 */ 412 function _horde_removeUsersFromGroup($name, $users) 413 { 414 require_once 'Horde/Group.php'; 415 $groups = &Group::singleton(); 416 417 if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { 418 return $group; 419 } 420 421 foreach ($users as $user) { 422 $group->removeUser($user, false); 423 } 424 425 return $group->save(); 426 } 427 428 /** 429 * Returns a list of users that are part of this group (and only this group) 430 * 431 * @return array The user list. 432 */ 433 function _horde_listUsersOfGroup($name) 434 { 435 require_once 'Horde/Group.php'; 436 $groups = &Group::singleton(); 437 438 if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { 439 return $group; 440 } 441 442 return $group->listUsers(); 443 } 444 445 /* Shares. */ 446 447 /** 448 * Adds a share to the shares system. 449 * 450 * @param string $shareRoot The name of the share root, e.g. the 451 * application that the share belongs to. 452 * @param string $shareName The share's name. 453 * @param string $shareTitle The share's human readable title. 454 * @param string $userName The share's owner. 455 */ 456 function _horde_addShare($shareRoot, $shareName, $shareTitle, $userName) 457 { 458 require_once 'Horde/Share.php'; 459 $shares = &Horde_Share::singleton($shareRoot); 460 461 if (is_a($share = &$shares->newShare($shareName), 'PEAR_Error')) { 462 return $share; 463 } 464 $share->set('owner', $userName); 465 $share->set('name', $shareTitle); 466 467 return $shares->addShare($share); 468 } 469 470 /** 471 * Removes a share from the shares system permanently. 472 * 473 * @param string $shareRoot The name of the share root, e.g. the 474 * application that the share belongs to. 475 * @param string $shareName The share's name. 476 */ 477 function _horde_removeShare($shareRoot, $shareName) 478 { 479 require_once 'Horde/Share.php'; 480 $shares = &Horde_Share::singleton($shareRoot); 481 482 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 483 return $share; 484 } 485 486 return $shares->removeShare($share); 487 } 488 489 /** 490 * Returns an array of all shares that $userName is the owner of. 491 * 492 * @param string $shareRoot The name of the share root, e.g. the 493 * application that the share belongs to. 494 * @param string $userName The share's owner. 495 * 496 * @return array The list of shares. 497 */ 498 function _horde_listSharesOfOwner($shareRoot, $userName) 499 { 500 require_once 'Horde/Share.php'; 501 $shares = &Horde_Share::singleton($shareRoot); 502 503 $share_list = &$shares->listShares($userName, PERMS_SHOW, $userName); 504 $myshares = array(); 505 foreach ($share_list as $share) { 506 $myshares[] = $share->getName(); 507 } 508 509 return $myshares; 510 } 511 512 /** 513 * Gives a user certain privileges for a share. 514 * 515 * @param string $shareRoot The name of the share root, e.g. the 516 * application that the share belongs to. 517 * @param string $shareName The share's name. 518 * @param string $userName The user's name. 519 * @param array $permissions A list of permissions (show, read, edit, delete). 520 */ 521 function _horde_addUserPermissions($shareRoot, $shareName, $userName, 522 $permissions) 523 { 524 require_once 'Horde/Share.php'; 525 $shares = &Horde_Share::singleton($shareRoot); 526 527 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 528 return $share; 529 } 530 531 $perm = &$share->getPermission(); 532 foreach ($permissions as $permission) { 533 $permission = String::upper($permission); 534 if (defined('PERMS_' . $permission)) { 535 $perm->addUserPermission($userName, constant('PERMS_' . $permission), false); 536 } 537 } 538 return $share->setPermission($perm); 539 } 540 541 /** 542 * Gives a group certain privileges for a share. 543 * 544 * @param string $shareRoot The name of the share root, e.g. the 545 * application that the share belongs to. 546 * @param string $shareName The share's name. 547 * @param string $groupName The group's name. 548 * @param array $permissions A list of permissions (show, read, edit, delete). 549 */ 550 function _horde_addGroupPermissions($shareRoot, $shareName, $groupName, 551 $permissions) 552 { 553 require_once 'Horde/Share.php'; 554 require_once 'Horde/Group.php'; 555 $shares = &Horde_Share::singleton($shareRoot); 556 $groups = &Group::singleton(); 557 558 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 559 return $share; 560 } 561 if (is_a($groupId = $groups->getGroupId($groupName), 'PEAR_Error')) { 562 return $groupId; 563 } 564 565 $perm = &$share->getPermission(); 566 foreach ($permissions as $permission) { 567 $permission = String::upper($permission); 568 if (defined('PERMS_' . $permission)) { 569 $perm->addGroupPermission($groupId, constant('PERMS_' . $permission), false); 570 } 571 } 572 return $share->setPermission($perm); 573 } 574 575 function _horde_setUserPermissions($shareRoot, $shareName, $userName, 576 $permissions) 577 { 578 } 579 580 function _horde_setGroupPermissions($shareRoot, $shareName, $groupName, 581 $permissions) 582 { 583 } 584 585 /** 586 * Removes a user from a share. 587 * 588 * @param string $shareRoot The name of the share root, e.g. the 589 * application that the share belongs to. 590 * @param string $shareName The share's name. 591 * @param string $userName The user's name. 592 */ 593 function _horde_removeUserPermissions($shareRoot, $shareName, $userName) 594 { 595 require_once 'Horde/Share.php'; 596 $shares = &Horde_Share::singleton($shareRoot); 597 598 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 599 return $share; 600 } 601 602 return $share->removeUser($userName); 603 } 604 605 /** 606 * Removes a group from a share. 607 * 608 * @param string $shareRoot The name of the share root, e.g. the 609 * application that the share belongs to. 610 * @param string $shareName The share's name. 611 * @param string $groupName The group's name. 612 */ 613 function _horde_removeGroupPermissions($shareRoot, $shareName, $groupName) 614 { 615 require_once 'Horde/Share.php'; 616 require_once 'Horde/Group.php'; 617 $shares = &Horde_Share::singleton($shareRoot); 618 $groups = &Group::singleton(); 619 620 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 621 return $share; 622 } 623 if (is_a($groupId = $groups->getGroupId($groupName), 'PEAR_Error')) { 624 return $groupId; 625 } 626 627 return $share->removeGroup($groupId); 628 } 629 630 /** 631 * Returns an array of all user permissions on a share. 632 * 633 * @param string $shareRoot The name of the share root, e.g. the 634 * application that the share belongs to. 635 * @param string $shareName The share's name. 636 * @param string $userName The user's name. 637 * 638 * @return array All user permissions for this share. 639 */ 640 function _horde_listUserPermissions($shareRoot, $shareName, $userName) 641 { 642 $perm_map = array(PERMS_SHOW => 'show', 643 PERMS_READ => 'read', 644 PERMS_EDIT => 'edit', 645 PERMS_DELETE => 'delete'); 646 647 require_once 'Horde/Share.php'; 648 $shares = &Horde_Share::singleton($shareRoot); 649 650 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 651 return $share; 652 } 653 654 $perm = &$share->getPermission(); 655 $permissions = $perm->getUserPermissions(); 656 if (empty($permissions[$userName])) { 657 return array(); 658 } 659 660 $user_permissions = array(); 661 foreach (array_keys(Perms::integerToArray($permissions[$userName])) as $permission) { 662 $user_permissions[] = $perm_map[$permission]; 663 } 664 665 return $user_permissions; 666 } 667 668 /** 669 * Returns an array of all group permissions on a share. 670 * 671 * @param string $shareRoot The name of the share root, e.g. the 672 * application that the share belongs to. 673 * @param string $shareName The share's name. 674 * @param string $groupName The group's name. 675 * 676 * @return array All group permissions for this share. 677 */ 678 function _horde_listGroupPermissions($shareRoot, $shareName, $groupName) 679 { 680 $perm_map = array(PERMS_SHOW => 'show', 681 PERMS_READ => 'read', 682 PERMS_EDIT => 'edit', 683 PERMS_DELETE => 'delete'); 684 685 require_once 'Horde/Share.php'; 686 $shares = &Horde_Share::singleton($shareRoot); 687 688 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 689 return $share; 690 } 691 692 $perm = &$share->getPermission(); 693 $permissions = $perm->getGroupPermissions(); 694 if (empty($permissions[$groupName])) { 695 return array(); 696 } 697 698 $group_permissions = array(); 699 foreach (array_keys(Perms::integerToArray($permissions[$groupName])) as $permission) { 700 $group_permissions[] = $perm_map[$permission]; 701 } 702 703 return $group_permissions; 704 } 705 706 /** 707 * Returns a list of users which have have certain permissions on a share. 708 * 709 * @param string $shareRoot The name of the share root, e.g. the 710 * application that the share belongs to. 711 * @param string $shareName The share's name. 712 * @param array $permissions A list of permissions (show, read, edit, delete). 713 * 714 * @return array List of users with the specified permissions. 715 */ 716 function _horde_listUsersOfShare($shareRoot, $shareName, $permissions) 717 { 718 require_once 'Horde/Share.php'; 719 $shares = &Horde_Share::singleton($shareRoot); 720 721 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 722 return $share; 723 } 724 725 $perm = 0; 726 foreach ($permissions as $permission) { 727 $permission = String::upper($permission); 728 if (defined('PERMS_' . $permission)) { 729 $perm &= constant('PERMS_' . $permission); 730 } 731 } 732 733 return $share->listUsers($perm); 734 } 735 736 /** 737 * Returns a list of groups which have have certain permissions on a share. 738 * 739 * @param string $shareRoot The name of the share root, e.g. the 740 * application that the share belongs to. 741 * @param string $shareName The share's name. 742 * @param array $permissions A list of permissions (show, read, edit, delete). 743 * 744 * @return array List of groups with the specified permissions. 745 */ 746 function _horde_listGroupsOfShare($shareRoot, $shareName, $permissions) 747 { 748 require_once 'Horde/Share.php'; 749 $shares = &Horde_Share::singleton($shareRoot); 750 751 if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { 752 return $share; 753 } 754 755 $perm = 0; 756 foreach ($permissions as $permission) { 757 $permission = String::upper($permission); 758 if (defined('PERMS_' . $permission)) { 759 $perm &= constant('PERMS_' . $permission); 760 } 761 } 762 763 return $share->listGroups($perm); 764 }
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 |