xref: /dokuwiki/lib/plugins/acl/remote.php (revision 64159a61e94d0ce680071c8890e144982c3a8cbe)
1<?php
2
3/**
4 * Class remote_plugin_acl
5 */
6class remote_plugin_acl extends DokuWiki_Remote_Plugin {
7
8    /**
9     * Returns details about the remote plugin methods
10     *
11     * @return array Information about all provided methods. {@see RemoteAPI}
12     */
13    public function _getMethods() {
14        return array(
15            'listAcls' => array(
16                'args' => array(),
17                'return' => 'Array of ACLs {scope, user, permission}',
18                'name' => 'listAcls',
19                'doc' => 'Get the list of all ACLs',
20            ),'addAcl' => array(
21                'args' => array('string','string','int'),
22                'return' => 'int',
23                'name' => 'addAcl',
24                'doc' => 'Adds a new ACL rule.'
25            ), 'delAcl' => array(
26                'args' => array('string','string'),
27                'return' => 'int',
28                'name' => 'delAcl',
29                'doc' => 'Delete an existing ACL rule.'
30            ),
31        );
32    }
33
34    /**
35     * List all ACL config entries
36     *
37     * @throws RemoteAccessDeniedException
38     * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int}
39     */
40    public function listAcls(){
41        if(!auth_isadmin()) {
42         throw new RemoteAccessDeniedException(
43             'You are not allowed to access ACLs, superuser permission is required',
44             114
45         );
46        }
47        /** @var admin_plugin_acl $apa */
48        $apa = plugin_load('admin', 'acl');
49        $apa->_init_acl_config();
50        return $apa->acl;
51    }
52
53    /**
54     * Add a new entry to ACL config
55     *
56     * @param string $scope
57     * @param string $user
58     * @param int    $level see also inc/auth.php
59     * @throws RemoteAccessDeniedException
60     * @return bool
61     */
62    public function addAcl($scope, $user, $level){
63        if(!auth_isadmin()) {
64            throw new RemoteAccessDeniedException(
65                'You are not allowed to access ACLs, superuser permission is required',
66                114
67            );
68        }
69
70        /** @var admin_plugin_acl $apa */
71        $apa = plugin_load('admin', 'acl');
72        return $apa->_acl_add($scope, $user, $level);
73    }
74
75    /**
76     * Remove an entry from ACL config
77     *
78     * @param string $scope
79     * @param string $user
80     * @throws RemoteAccessDeniedException
81     * @return bool
82     */
83    public function delAcl($scope, $user){
84        if(!auth_isadmin()) {
85            throw new RemoteAccessDeniedException(
86                'You are not allowed to access ACLs, superuser permission is required',
87                114
88            );
89        }
90
91        /** @var admin_plugin_acl $apa */
92        $apa = plugin_load('admin', 'acl');
93        return $apa->_acl_del($scope, $user);
94    }
95}
96
97