summaryrefslogtreecommitdiff
path: root/lib/plugins/acl/action.php
blob: a7226f598c8ef7db825003a8e59a7811f8ccb4a4 (plain)
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
<?php
/**
 * AJAX call handler for ACL plugin
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Andreas Gohr <andi@splitbrain.org>
 */

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

/**
 * Register handler
 */
class action_plugin_acl extends DokuWiki_Action_Plugin {

    /**
     * Registers a callback function for a given event
     *
     * @param Doku_Event_Handler $controller DokuWiki's event controller object
     * @return void
     */
    public function register(Doku_Event_Handler $controller) {

        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_acl');

    }

    /**
     * AJAX call handler for ACL plugin
     *
     * @param Doku_Event $event  event object by reference
     * @param mixed $param  empty
     * @return void
     */

    public function handle_ajax_call_acl(Doku_Event &$event, $param) {
        if($event->data !== 'plugin_acl') {
            return;
        }
        $event->stopPropagation();
        $event->preventDefault();

        global $ID;
        global $INPUT;

        if(!auth_isadmin()) {
            echo 'for admins only';
            return;
        }
        if(!checkSecurityToken()) {
            echo 'CRSF Attack';
            return;
        }

        $ID = getID();

        /** @var $acl admin_plugin_acl */
        $acl = plugin_load('admin', 'acl');
        $acl->handle();

        $ajax = $INPUT->str('ajax');
        header('Content-Type: text/html; charset=utf-8');

        if($ajax == 'info') {
            $acl->_html_info();
        } elseif($ajax == 'tree') {

            $ns = $INPUT->str('ns');
            if($ns == '*') {
                $ns = '';
            }
            $ns = cleanID($ns);
            $lvl = count(explode(':', $ns));
            $ns = utf8_encodeFN(str_replace(':', '/', $ns));

            $data = $acl->_get_tree($ns, $ns);

            foreach(array_keys($data) as $item) {
                $data[$item]['level'] = $lvl + 1;
            }
            echo html_buildlist(
                $data, 'acl', array($acl, '_html_list_acl'),
                array($acl, '_html_li_acl')
            );
        }
    }
}