Esempio n. 1
0
function getPermissionsFormList($rights = array(), $user_type = USER_TYPE_ZABBIX_USER, $rightsFormList = null)
{
    // nodes
    if (ZBX_DISTRIBUTED) {
        $lists['node']['label'] = _('Nodes');
        $lists['node']['read_write'] = new CListBox('nodes_write', null, 10);
        $lists['node']['read_only'] = new CListBox('nodes_read', null, 10);
        $lists['node']['deny'] = new CListBox('nodes_deny', null, 10);
        $nodes = get_accessible_nodes_by_rights($rights, $user_type, PERM_DENY, PERM_RES_DATA_ARRAY);
        foreach ($nodes as $node) {
            switch ($node['permission']) {
                case PERM_READ:
                    $list_name = 'read_only';
                    break;
                case PERM_READ_WRITE:
                    $list_name = 'read_write';
                    break;
                default:
                    $list_name = 'deny';
            }
            $lists['node'][$list_name]->addItem($node['nodeid'], $node['name']);
        }
        unset($nodes);
    }
    // group
    $lists['group']['label'] = _('Host groups');
    $lists['group']['read_write'] = new CListBox('groups_write', null, 15);
    $lists['group']['read_only'] = new CListBox('groups_read', null, 15);
    $lists['group']['deny'] = new CListBox('groups_deny', null, 15);
    $groups = get_accessible_groups_by_rights($rights, $user_type, PERM_DENY, PERM_RES_DATA_ARRAY, get_current_nodeid(true));
    foreach ($groups as $group) {
        switch ($group['permission']) {
            case PERM_READ:
                $list_name = 'read_only';
                break;
            case PERM_READ_WRITE:
                $list_name = 'read_write';
                break;
            default:
                $list_name = 'deny';
        }
        $lists['group'][$list_name]->addItem($group['groupid'], (empty($group['node_name']) ? '' : $group['node_name'] . NAME_DELIMITER) . $group['name']);
    }
    unset($groups);
    // host
    $lists['host']['label'] = _('Hosts');
    $lists['host']['read_write'] = new CListBox('hosts_write', null, 15);
    $lists['host']['read_only'] = new CListBox('hosts_read', null, 15);
    $lists['host']['deny'] = new CListBox('hosts_deny', null, 15);
    $hosts = get_accessible_hosts_by_rights($rights, $user_type, PERM_DENY, PERM_RES_DATA_ARRAY, get_current_nodeid(true));
    foreach ($hosts as $host) {
        switch ($host['permission']) {
            case PERM_READ:
                $list_name = 'read_only';
                break;
            case PERM_READ_WRITE:
                $list_name = 'read_write';
                break;
            default:
                $list_name = 'deny';
        }
        if (HOST_STATUS_PROXY_ACTIVE == $host['status'] || HOST_STATUS_PROXY_PASSIVE == $host['status']) {
            $host['host_name'] = $host['host'];
        }
        $lists['host'][$list_name]->addItem($host['hostid'], (empty($host['node_name']) ? '' : $host['node_name'] . NAME_DELIMITER) . $host['host_name']);
    }
    unset($hosts);
    // display
    if (empty($rightsFormList)) {
        $rightsFormList = new CFormList('rightsFormList');
    }
    $isHeaderDisplayed = false;
    foreach ($lists as $list) {
        $sLabel = '';
        $row = new CRow();
        foreach ($list as $class => $item) {
            if (is_string($item)) {
                $sLabel = $item;
            } else {
                $row->addItem(new CCol($item, $class));
            }
        }
        $table = new CTable(_('No accessible resources'), 'right_table calculated');
        if (!$isHeaderDisplayed) {
            $table->setHeader(array(_('Read-write'), _('Read only'), _('Deny')), 'header');
            $isHeaderDisplayed = true;
        }
        $table->addRow($row);
        $rightsFormList->addRow($sLabel, $table);
    }
    return $rightsFormList;
}
Esempio n. 2
0
function get_rights_of_elements_table($rights = array(), $user_type = USER_TYPE_ZABBIX_USER)
{
    global $ZBX_LOCALNODEID;
    $table = new CTable('S_NO_ACCESSIBLE_RESOURCES', 'right_table');
    $table->SetHeader(array(SPACE, S_READ_WRITE, S_READ_ONLY, S_DENY), 'header');
    if (ZBX_DISTRIBUTED) {
        $lst['node']['label'] = S_NODES;
        $lst['node']['read_write'] = new CListBox('nodes_write', null, 10);
        $lst['node']['read_only'] = new CListBox('nodes_read', null, 10);
        $lst['node']['deny'] = new CListBox('nodes_deny', null, 10);
        $nodes = get_accessible_nodes_by_rights($rights, $user_type, PERM_DENY, PERM_RES_DATA_ARRAY);
        foreach ($nodes as $node) {
            switch ($node['permission']) {
                case PERM_READ_ONLY:
                    $list_name = 'read_only';
                    break;
                case PERM_READ_WRITE:
                    $list_name = 'read_write';
                    break;
                default:
                    $list_name = 'deny';
                    break;
            }
            $lst['node'][$list_name]->addItem($node['nodeid'], $node['name']);
        }
        unset($nodes);
    }
    $lst['group']['label'] = S_HOST_GROUPS;
    $lst['group']['read_write'] = new CListBox('groups_write', null, 15);
    $lst['group']['read_only'] = new CListBox('groups_read', null, 15);
    $lst['group']['deny'] = new CListBox('groups_deny', null, 15);
    $groups = get_accessible_groups_by_rights($rights, $user_type, PERM_DENY, PERM_RES_DATA_ARRAY, get_current_nodeid(true));
    foreach ($groups as $group) {
        switch ($group['permission']) {
            case PERM_READ_ONLY:
                $list_name = 'read_only';
                break;
            case PERM_READ_WRITE:
                $list_name = 'read_write';
                break;
            default:
                $list_name = 'deny';
        }
        $lst['group'][$list_name]->addItem($group['groupid'], $group['node_name'] . ':' . $group['name']);
    }
    unset($groups);
    $lst['host']['label'] = S_HOSTS;
    $lst['host']['read_write'] = new CListBox('hosts_write', null, 15);
    $lst['host']['read_only'] = new CListBox('hosts_read', null, 15);
    $lst['host']['deny'] = new CListBox('hosts_deny', null, 15);
    $hosts = get_accessible_hosts_by_rights($rights, $user_type, PERM_DENY, PERM_RES_DATA_ARRAY, get_current_nodeid(true));
    foreach ($hosts as $host) {
        switch ($host['permission']) {
            case PERM_READ_ONLY:
                $list_name = 'read_only';
                break;
            case PERM_READ_WRITE:
                $list_name = 'read_write';
                break;
            default:
                $list_name = 'deny';
                break;
        }
        $lst['host'][$list_name]->addItem($host['hostid'], $host['node_name'] . ':' . $host['host']);
    }
    unset($hosts);
    foreach ($lst as $name => $lists) {
        $row = new CRow();
        foreach ($lists as $class => $list_obj) {
            $row->addItem(new CCol($list_obj, $class));
        }
        $table->addRow($row);
    }
    unset($lst);
    return $table;
}