File: acl.php

package info (click to toggle)
imp4 4.1.3-4
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 14,988 kB
  • ctags: 3,720
  • sloc: xml: 17,038; php: 16,350; makefile: 64
file content (168 lines) | stat: -rw-r--r-- 5,372 bytes parent folder | download
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
<?php
/**
 * $Horde: imp/acl.php,v 1.23.10.8 2006/05/24 09:20:05 jan Exp $
 *
 * Copyright 2000-2006 Chris Hastie <imp@oak-wood.co.uk>
 *
 * See the enclosed file COPYING for license information (GPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 */

@define('IMP_BASE', dirname(__FILE__));
$authentication = OP_HALFOPEN;
require_once IMP_BASE . '/lib/base.php';
require_once IMP_BASE . '/lib/Folder.php';
require_once 'Horde/IMAP/ACL.php';

$prefs_url = IMP::prefsURL(true);

/* Redirect back to the options screen if ACL is not enabled. */
if ($prefs->isLocked('acl') ||
    !(isset($_SESSION['imp']['acl']) &&
      is_array($_SESSION['imp']['acl']))) {
    $notification->push(_("Folder sharing is not enabled."), 'horde.error');
    header('Location: ' . $prefs_url);
    exit;
}

$params = array(
    'hostspec' => $_SESSION['imp']['server'],
    'port' => $_SESSION['imp']['port'],
    'protocol' => $_SESSION['imp']['protocol'],
    'username' => $_SESSION['imp']['user'],
    'password' => Secret::read(Secret::getKey('imp'), $_SESSION['imp']['pass'])
);

if (isset($_SESSION['imp']['acl']['params'])) {
    $params = array_merge($params, $_SESSION['imp']['acl']['params']);
}
$ACLDriver = IMAP_ACL::singleton($_SESSION['imp']['acl']['driver'], $params);

/* Check selected driver is supported. Redirect to options screen with
 * error message if not */
$error = null;
if (!$ACLDriver->isSupported()) {
    $error = _("This server does not support sharing folders.");
} else {
    $error = $ACLDriver->getError();
}

if ($error) {
    $notification->push($error, 'horde.error');
    header('Location: ' . $prefs_url);
    exit;
}

$acl = Util::getFormData('acl');
$folder = Util::getFormData('folder');
$protected  = $ACLDriver->getProtected();
$share_user = Util::getFormData('share_user');
$ok_form = true;

/* Run through the action handlers. */
$actionID = Util::getFormData('actionID');
switch ($actionID) {
case 'imp_acl_set':
    if (!$share_user) {
        $notification->push(_("No user specified."), 'horde.error');
        $ok_form = false;
    }
    if (!$folder) {
        $notification->push(_("No folder selected."), 'horde.error');
        $ok_form = false;
    }
    if (in_array($share_user, $protected)) {
        $notification->push(_("Permissions for this user cannot be changed."), 'horde.error');
        $ok_form = false;
    }

    if ($ok_form) {
        $result = $ACLDriver->createACL($folder, $share_user, $acl);
        if (is_a($result, 'PEAR_Error')) {
            $notification->push($result);
        } elseif (!count($acl)) {
            $notification->push(sprintf(_("All rights on folder \"%s\" successfully removed for user \"%s\"."), $folder, $share_user), 'horde.success');
        } else {
            $notification->push(sprintf(_("User \"%s\" successfully given the specified rights for the folder \"%s\"."), $share_user, $folder), 'horde.success');
        }
    }
    break;

case 'imp_acl_edit':
    if (!$share_user) {
        $notification->push(_("No user specified."), 'horde.error');
        $ok_form = false;
    }
    if (!$folder) {
        $notification->push(_("No folder selected."), 'horde.error');
        $ok_form = false;
    }
    if (in_array($share_user, $protected)) {
        $notification->push(_("Permissions for this user cannot be changed."), 'horde.error');
        $ok_form = false;
    }

    if ($ok_form) {
        $result = $ACLDriver->editACL($folder, $share_user, $acl);
        if (is_a($result, 'PEAR_Error')) {
            $notification->push($result);
        } else {
            if ($acl) {
                $notification->push(sprintf(_("User \"%s\" successfully given the specified rights for the folder \"%s\"."), $share_user, $folder), 'horde.success');
            } else {
                $notification->push(sprintf(_("User \"%s\" successfully revoked the specified rights for the folder \"%s\"."), $share_user, $folder), 'horde.success');
            }
        }
    }
    break;
}

$imp_folder = &IMP_Folder::singleton();
$rights = $ACLDriver->getRights();

if (empty($folder)) {
    $folder = 'INBOX';
}

if (count($imp_folder->flist_IMP())) {
    $options = IMP::flistSelect('', true, array(), $folder);
}

$curr_acl = $ACLDriver->getACL($folder);
$canEdit = $ACLDriver->canEdit($folder, $_SESSION['imp']['user']);

if (is_a($curr_acl, 'PEAR_Error')) {
    $notification->push($curr_acl, 'horde_error');
    $curr_acl = array();
} else {
    /* Set up javascript arrays. */
    if (count($curr_acl)) {
        $js_user = '';
        foreach (array_keys($rights) as $right) {
            $js_right[$right] = '';
        }

        foreach ($curr_acl as $curr_user => $granted) {
            if (strlen($js_user) > 0) {
                $js_user .= ', ';
                foreach (array_keys($rights) as $right) {
                    $js_right[$right] .= ', ';
                }
            }

            $js_user .= '"' . $curr_user . '"';

            foreach (array_keys($rights) as $right) {
                $js_right[$right] .= (empty($granted[$right])) ? '"0"' : '"1"';
            }
        }
    }
}

require_once 'Horde/Prefs/UI.php';
require IMP_BASE . '/config/prefs.php';
$app = 'imp';

Prefs_UI::generateHeader();
require IMP_TEMPLATES . '/acl/acl.inc';
require $registry->get('templates', 'horde') . '/common-footer.inc';