1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: class Horde_Api extends Horde_Registry_Api
11: {
12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: public function admin_list()
23: {
24: $admin = array(
25: 'configuration' => array(
26: 'link' => '%application%/admin/config/',
27: 'name' => _("_Configuration"),
28: 'icon' => Horde_Themes::img('config.png')
29: ),
30: 'users' => array(
31: 'link' => '%application%/admin/user.php',
32: 'name' => _("_Users"),
33: 'icon' => Horde_Themes::img('user.png')
34: ),
35: 'groups' => array(
36: 'link' => '%application%/admin/groups.php',
37: 'name' => _("_Groups"),
38: 'icon' => Horde_Themes::img('group.png')
39: ),
40: 'perms' => array(
41: 'link' => '%application%/admin/perms/index.php',
42: 'name' => _("_Permissions"),
43: 'icon' => Horde_Themes::img('perms.png')
44: ),
45: 'locks' => array(
46: 'link' => '%application%/admin/locks.php',
47: 'name' => _("_Locks"),
48: 'icon' => Horde_Themes::img('locked.png')
49: ),
50: 'alarms' => array(
51: 'link' => '%application%/admin/alarms.php',
52: 'name' => _("_Alarms"),
53: 'icon' => Horde_Themes::img('alerts/alarm.png')
54: ),
55: 'datatree' => array(
56: 'link' => '%application%/admin/datatree.php',
57: 'name' => _("_DataTree"),
58: 'icon' => Horde_Themes::img('datatree.png')
59: ),
60: 'sessions' => array(
61: 'link' => '%application%/admin/sessions.php',
62: 'name' => _("Sessions"),
63: 'icon' => Horde_Themes::img('user.png')
64: ),
65: 'phpshell' => array(
66: 'link' => '%application%/admin/phpshell.php',
67: 'name' => _("P_HP Shell"),
68: 'icon' => Horde_Themes::img('mime/php.png')
69: ),
70: 'sqlshell' => array(
71: 'link' => '%application%/admin/sqlshell.php',
72: 'name' => _("S_QL Shell"),
73: 'icon' => Horde_Themes::img('sql.png')
74: ),
75: 'cmdshell' => array(
76: 'link' => '%application%/admin/cmdshell.php',
77: 'name' => _("_CLI"),
78: 'icon' => Horde_Themes::img('shell.png')
79: )
80: );
81:
82: if (!empty($GLOBALS['conf']['activesync']['enabled'])) {
83: $admin['activesync'] = array(
84: 'link' => '%application%/admin/activesync.php',
85: 'name' => _("ActiveSync Devices"),
86: 'icon' => Horde_Themes::img('mobile.png')
87: );
88: }
89:
90: if (empty($GLOBALS['conf']['datatree']['driver']) ||
91: $GLOBALS['conf']['datatree']['driver'] == 'null') {
92: unset($admin['datatree']);
93: }
94:
95: return $admin;
96: }
97:
98: 99: 100: 101: 102: 103: 104: 105: 106:
107: public function listApps($filter = null)
108: {
109: return $GLOBALS['registry']->listApps($filter);
110: }
111:
112: 113: 114: 115: 116:
117: public function listAPIs()
118: {
119: return $GLOBALS['registry']->listAPIs();
120: }
121:
122:
123:
124: 125: 126: 127: 128: 129: 130: 131: 132:
133: public function blockTitle($app, $name, $params = array())
134: {
135: $class = $app . '_Block_' . basename($name);
136: try {
137: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlock($app, $class, $params)->getTitle();
138: } catch (Horde_Exception $e) {
139: return $e->getMessage();
140: }
141: }
142:
143: 144: 145: 146: 147: 148: 149: 150: 151:
152: public function blockContent($app, $name, $params = array())
153: {
154: $class = $app . '_Block_' . basename($name);
155: try {
156: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlock($app, $class, $params)->getContent();
157: } catch (Horde_Exception $e) {
158: return $e->getMessage();
159: }
160: }
161:
162: 163: 164: 165: 166: 167:
168: public function blocks()
169: {
170: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create()->getBlocksList();
171: }
172:
173:
174:
175: 176: 177: 178: 179: 180: 181: 182:
183: public function getPreference($app, $pref)
184: {
185: $pushed = $GLOBALS['registry']->pushApp($app);
186: $GLOBALS['registry']->loadPrefs($app);
187: $value = $GLOBALS['prefs']->getValue($pref);
188: if ($pushed) {
189: $GLOBALS['registry']->popApp();
190: }
191:
192: return $value;
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202:
203: public function setPreference($app, $pref, $value)
204: {
205: $pushed = $GLOBALS['registry']->pushApp($app);
206: $GLOBALS['registry']->loadPrefs($app);
207: $value = $GLOBALS['prefs']->setValue($pref, $value);
208: if ($pushed) {
209: $GLOBALS['registry']->popApp();
210: }
211: }
212:
213: 214: 215: 216: 217: 218: 219: 220: 221: 222:
223: public function removeUserData($user, $app = false)
224: {
225: if ($app === true) {
226: $app = null;
227: } elseif ($app === false || !strlen($app)) {
228: $app = false;
229: }
230:
231: $GLOBALS['registry']->removeUserData($user, $app);
232: }
233:
234:
235:
236: 237: 238: 239: 240: 241: 242: 243: 244:
245: public function addGroup($name, $parent = null)
246: {
247: if (!$GLOBALS['registry']->isAdmin()) {
248: throw new Horde_Exception(_("You are not allowed to add groups."));
249: }
250:
251: try {
252: return $GLOBALS['injector']
253: ->getInstance('Horde_Group')
254: ->create($name);
255: } catch (Horde_Group_Exception $e) {
256: throw new Horde_Exception($e);
257: }
258: }
259:
260: 261: 262: 263: 264: 265: 266:
267: public function removeGroup($group)
268: {
269: if (!$GLOBALS['registry']->isAdmin()) {
270: throw new Horde_Exception(_("You are not allowed to delete groups."));
271: }
272:
273: try {
274: $GLOBALS['injector']->getInstance('Horde_Group')->remove($group);
275: } catch (Horde_Group_Exception $e) {
276: throw new Horde_Exception($e);
277: }
278: }
279:
280: 281: 282: 283: 284: 285: 286: 287:
288: public function addUserToGroup($group, $user)
289: {
290: if (!$GLOBALS['registry']->isAdmin()) {
291: throw new Horde_Exception(_("You are not allowed to change groups."));
292: }
293:
294: try {
295: $GLOBALS['injector']
296: ->getInstance('Horde_Group')
297: ->addUser($group, $user);
298: } catch (Horde_Group_Exception $e) {
299: throw new Horde_Exception($e);
300: }
301: }
302:
303: 304: 305: 306: 307: 308: 309: 310:
311: public function removeUserFromGroup($group, $user)
312: {
313: if (!$GLOBALS['registry']->isAdmin()) {
314: throw new Horde_Exception(_("You are not allowed to change groups."));
315: }
316:
317: try {
318: $GLOBALS['injector']
319: ->getInstance('Horde_Group')
320: ->removeUser($group, $user);
321: } catch (Horde_Group_Exception $e) {
322: throw new Horde_Exception($e);
323: }
324: }
325:
326: 327: 328: 329: 330: 331: 332: 333:
334: public function listUsersOfGroup($group)
335: {
336: if (!$GLOBALS['registry']->isAdmin()) {
337: throw new Horde_Exception(_("You are not allowed to list users of groups."));
338: }
339:
340: try {
341: return $GLOBALS['injector']
342: ->getInstance('Horde_Group')
343: ->listUsers($group);
344: } catch (Horde_Group_Exception $e) {
345: throw new Horde_Exception($e);
346: }
347: }
348:
349:
350:
351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361:
362: public function addShare($scope, $shareName, $shareTitle, $userName)
363: {
364: if (!$GLOBALS['registry']->isAdmin()) {
365: throw new Horde_Exception(_("You are not allowed to add shares."));
366: }
367:
368: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
369: try {
370: $share = $shares->newShare($GLOBALS['registry']->getAuth(), $shareName, $shareTitle);
371: $share->set('owner', $userName);
372: $shares->addShare($share);
373: } catch (Horde_Share_Exception $e) {
374: throw new Horde_Exception($e);
375: }
376: }
377:
378: 379: 380: 381: 382: 383: 384: 385: 386:
387: public function removeShare($scope, $shareName)
388: {
389: if (!$GLOBALS['registry']->isAdmin()) {
390: throw new Horde_Exceptionr(_("You are not allowed to delete shares."));
391: }
392:
393: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
394: $share = $shares->getShare($shareName);
395: try {
396: $shares->removeShare($share);
397: } catch (Horde_Share_Exception $e) {
398: throw new Horde_Exception_Wrapped($e);
399: }
400: }
401:
402: 403: 404: 405: 406: 407: 408: 409: 410: 411:
412: public function listSharesOfOwner($scope, $userName)
413: {
414: if (!$GLOBALS['registry']->isAdmin()) {
415: throw new Horde_Exception(_("You are not allowed to list shares."));
416: }
417:
418: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
419:
420: $share_list = $shares->listShares($userName,
421: array('perm' => Horde_Perms::SHOW,
422: 'attributes' => $userName));
423: $myshares = array();
424: foreach ($share_list as $share) {
425: $myshares[] = $share->getName();
426: }
427:
428: return $myshares;
429: }
430:
431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441:
442: public function addUserPermissions($scope, $shareName, $userName,
443: $permissions)
444: {
445: if (!$GLOBALS['registry']->isAdmin()) {
446: throw new Horde_Exception(_("You are not allowed to change shares."));
447: }
448:
449: try {
450: $share = $GLOBALS['injector']
451: ->getInstance('Horde_Core_Factory_Share')
452: ->create($scope)
453: ->getShare($shareName);
454: $perm = $share->getPermission();
455: foreach ($permissions as $permission) {
456: $permission = Horde_String::upper($permission);
457: if (defined('Horde_Perms::' . $permission)) {
458: $perm->addUserPermission($userName, constant('Horde_Perms::' . $permission), false);
459: }
460: }
461: $share->setPermission($perm);
462: } catch (Horde_Share_Exception $e) {
463: throw new Horde_Exception($e);
464: }
465: }
466:
467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478:
479: public function addGroupPermissions($scope, $shareName, $groupId,
480: $permissions)
481: {
482: if (!$GLOBALS['registry']->isAdmin()) {
483: throw new Horde_Exception(_("You are not allowed to change shares."));
484: }
485:
486: try {
487: $share = $GLOBALS['injector']
488: ->getInstance('Horde_Core_Factory_Share')
489: ->create($scope)
490: ->getShare($shareName);
491: $perm = $share->getPermission();
492: foreach ($permissions as $permission) {
493: $permission = Horde_String::upper($permission);
494: if (defined('Horde_Perms::' . $permission)) {
495: $perm->addGroupPermission($groupId, constant('Horde_Perms::' . $permission), false);
496: }
497: }
498: $share->setPermission($perm);
499: } catch (Horde_Share_Exception $e) {
500: throw new Horde_Exception($e);
501: }
502: }
503:
504: 505: 506: 507: 508: 509: 510: 511: 512: 513:
514: public function removeUserPermissions($scope, $shareName, $userName)
515: {
516: if (!$GLOBALS['registry']->isAdmin()) {
517: throw new Horde_Exception(_("You are not allowed to change shares."));
518: }
519:
520: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
521: $share = $shares->getShare($shareName);
522: try {
523: $share->removeUser($userName);
524: } catch (Horde_Share_Exception $e) {
525: throw new Horde_Exception($e);
526: }
527: }
528:
529: 530: 531: 532: 533: 534: 535: 536: 537: 538:
539: public function removeGroupPermissions($scope, $shareName, $groupId)
540: {
541: if (!$GLOBALS['registry']->isAdmin()) {
542: throw new Horde_Exception(_("You are not allowed to change shares."));
543: }
544:
545: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
546: $share = $shares->getShare($shareName);
547: try {
548: $share->removeGroup($groupId);
549: } catch (Horde_Share_Exception $e) {
550: throw new Horde_Exception($e);
551: }
552: }
553:
554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564:
565: public function listUserPermissions($scope, $shareName, $userName)
566: {
567: if (!$GLOBALS['registry']->isAdmin()) {
568: throw new Horde_Exception(_("You are not allowed to list share permissions."));
569: }
570:
571: $perm_map = array(Horde_Perms::SHOW => 'show',
572: Horde_Perms::READ => 'read',
573: Horde_Perms::EDIT => 'edit',
574: Horde_Perms::DELETE => 'delete');
575:
576: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
577: $share = $shares->getShare($shareName);
578: $perm = $share->getPermission();
579: $permissions = $perm->getUserPermissions();
580: if (empty($permissions[$userName])) {
581: return array();
582: }
583:
584: $user_permissions = array();
585: foreach (array_keys(Perms::integerToArray($permissions[$userName])) as $permission) {
586: $user_permissions[] = $perm_map[$permission];
587: }
588:
589: return $user_permissions;
590: }
591:
592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602:
603: public function listGroupPermissions($scope, $shareName, $groupName)
604: {
605: if (!$GLOBALS['registry']->isAdmin()) {
606: throw new Horde_Exception(_("You are not allowed to list share permissions."));
607: }
608:
609: $perm_map = array(Horde_Perms::SHOW => 'show',
610: Horde_Perms::READ => 'read',
611: Horde_Perms::EDIT => 'edit',
612: Horde_Perms::DELETE => 'delete');
613:
614: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
615: $share = $shares->getShare($shareName);
616: $perm = $share->getPermission();
617: $permissions = $perm->getGroupPermissions();
618: if (empty($permissions[$groupName])) {
619: return array();
620: }
621:
622: $group_permissions = array();
623: foreach (array_keys(Perms::integerToArray($permissions[$groupName])) as $permission) {
624: $group_permissions[] = $perm_map[$permission];
625: }
626:
627: return $group_permissions;
628: }
629:
630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640:
641: public function listUsersOfShare($scope, $shareName, $permissions)
642: {
643: if (!$GLOBALS['registry']->isAdmin()) {
644: throw new Horde_Exception(_("You are not allowed to list users of shares."));
645: }
646:
647: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
648: $share = $shares->getShare($shareName);
649: $perm = 0;
650: foreach ($permissions as $permission) {
651: $permission = Horde_String::upper($permission);
652: if (defined('Horde_Perms::' . $permission)) {
653: $perm &= constant('Horde_Perms::' . $permission);
654: }
655: }
656:
657: return $share->listUsers($perm);
658: }
659:
660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670:
671: public function listGroupsOfShare($scope, $shareName, $permissions)
672: {
673: if (!$GLOBALS['registry']->isAdmin()) {
674: throw new Horde_Exception(_("You are not allowed to list groups of shares."));
675: }
676:
677: $shares = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create($scope);
678: $share = $shares->getShare($shareName);
679: $perm = 0;
680: foreach ($permissions as $permission) {
681: $permission = Horde_String::upper($permission);
682: if (defined('Horde_Perms::' . $permission)) {
683: $perm &= constant('Horde_Perms::' . $permission);
684: }
685: }
686:
687: return $share->listGroups($perm);
688: }
689:
690: }
691: