xref: /dokuwiki/lib/plugins/acl/remote.php (revision 32b2e3681ba1b4a48d730c2e2acefd6b3459cbe1)
19f8068d2SMohamed Amine BERGAOUI<?php
29f8068d2SMohamed Amine BERGAOUI
342ea7f44SGerrit Uitslag/**
442ea7f44SGerrit Uitslag * Class remote_plugin_acl
542ea7f44SGerrit Uitslag */
69f8068d2SMohamed Amine BERGAOUIclass remote_plugin_acl extends DokuWiki_Remote_Plugin {
742ea7f44SGerrit Uitslag
842ea7f44SGerrit Uitslag    /**
942ea7f44SGerrit Uitslag     * Returns details about the remote plugin methods
1042ea7f44SGerrit Uitslag     *
1167b479b2SGerrit Uitslag     * @return array Information about all provided methods. {@see RemoteAPI}
1242ea7f44SGerrit Uitslag     */
1342ea7f44SGerrit Uitslag    public function _getMethods() {
149f8068d2SMohamed Amine BERGAOUI        return array(
156d2588b6SCyril Duchon-Doris            'listAcls' => array(
166d2588b6SCyril Duchon-Doris                'args' => array(),
176d2588b6SCyril Duchon-Doris                'return' => 'Array of ACLs {scope, user, permission}',
18*32b2e368SDharmik                'name' => 'listAcls',
191fa1d6bcSCyril Duchon-Doris                'doc' => 'Get the list of all ACLs',
201fa1d6bcSCyril Duchon-Doris            ),'addAcl' => array(
219f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string','int'),
229f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
239f8068d2SMohamed Amine BERGAOUI                'name' => 'addAcl',
249f8068d2SMohamed Amine BERGAOUI                'doc' => 'Adds a new ACL rule.'
251b7fc214SMohamed Amine BERGAOUI            ), 'delAcl' => array(
269f8068d2SMohamed Amine BERGAOUI                'args' => array('string','string'),
279f8068d2SMohamed Amine BERGAOUI                'return' => 'int',
289f8068d2SMohamed Amine BERGAOUI                'name' => 'delAcl',
299f8068d2SMohamed Amine BERGAOUI                'doc' => 'Delete an existing ACL rule.'
309f8068d2SMohamed Amine BERGAOUI            ),
319f8068d2SMohamed Amine BERGAOUI        );
329f8068d2SMohamed Amine BERGAOUI    }
339f8068d2SMohamed Amine BERGAOUI
3442ea7f44SGerrit Uitslag    /**
356d2588b6SCyril Duchon-Doris     * List all ACL config entries
366d2588b6SCyril Duchon-Doris     *
3742f3fd0aSCyril Duchon-Doris     * @throws RemoteAccessDeniedException
3842f3fd0aSCyril Duchon-Doris     * @return dictionary {Scope: ACL}, where ACL = dictionnary {user/group: permissions_int}
396d2588b6SCyril Duchon-Doris     */
406d2588b6SCyril Duchon-Doris    public function listAcls(){
4142f3fd0aSCyril Duchon-Doris        if(!auth_isadmin()) {
4242f3fd0aSCyril Duchon-Doris         throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114);
4342f3fd0aSCyril Duchon-Doris        }
446d2588b6SCyril Duchon-Doris        /** @var admin_plugin_acl $apa */
456d2588b6SCyril Duchon-Doris        $apa = plugin_load('admin', 'acl');
4642f3fd0aSCyril Duchon-Doris        $apa->_init_acl_config();
4742f3fd0aSCyril Duchon-Doris        return $apa->acl;
486d2588b6SCyril Duchon-Doris    }
496d2588b6SCyril Duchon-Doris
506d2588b6SCyril Duchon-Doris    /**
5142ea7f44SGerrit Uitslag     * Add a new entry to ACL config
5242ea7f44SGerrit Uitslag     *
5342ea7f44SGerrit Uitslag     * @param string $scope
5442ea7f44SGerrit Uitslag     * @param string $user
5542ea7f44SGerrit Uitslag     * @param int    $level see also inc/auth.php
569cbf80e6SAndreas Gohr     * @throws RemoteAccessDeniedException
5742ea7f44SGerrit Uitslag     * @return bool
5842ea7f44SGerrit Uitslag     */
5942ea7f44SGerrit Uitslag    public function addAcl($scope, $user, $level){
609cbf80e6SAndreas Gohr        if(!auth_isadmin()) {
619cbf80e6SAndreas Gohr            throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114);
629cbf80e6SAndreas Gohr        }
639cbf80e6SAndreas Gohr
6459bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
651b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
669f8068d2SMohamed Amine BERGAOUI        return $apa->_acl_add($scope, $user, $level);
679f8068d2SMohamed Amine BERGAOUI    }
689f8068d2SMohamed Amine BERGAOUI
6942ea7f44SGerrit Uitslag    /**
7042ea7f44SGerrit Uitslag     * Remove an entry from ACL config
7142ea7f44SGerrit Uitslag     *
7242ea7f44SGerrit Uitslag     * @param string $scope
7342ea7f44SGerrit Uitslag     * @param string $user
749cbf80e6SAndreas Gohr     * @throws RemoteAccessDeniedException
7542ea7f44SGerrit Uitslag     * @return bool
7642ea7f44SGerrit Uitslag     */
7742ea7f44SGerrit Uitslag    public function delAcl($scope, $user){
789cbf80e6SAndreas Gohr        if(!auth_isadmin()) {
799cbf80e6SAndreas Gohr            throw new RemoteAccessDeniedException('You are not allowed to access ACLs, superuser permission is required', 114);
809cbf80e6SAndreas Gohr        }
819cbf80e6SAndreas Gohr
8259bc3b48SGerrit Uitslag        /** @var admin_plugin_acl $apa */
831b7fc214SMohamed Amine BERGAOUI        $apa = plugin_load('admin', 'acl');
849f8068d2SMohamed Amine BERGAOUI        return $apa->_acl_del($scope, $user);
859f8068d2SMohamed Amine BERGAOUI    }
869f8068d2SMohamed Amine BERGAOUI}
879f8068d2SMohamed Amine BERGAOUI
88