Esempio n. 1
0
function getPermissionsFormList($rights = array(), $user_type = USER_TYPE_ZABBIX_USER, $rightsFormList = null)
{
    // 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);
    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'], $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);
    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'], $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_accessible_nodes_by_rights(&$rights, $user_type, $perm, $perm_res = null)
{
    global $ZBX_LOCALNODEID;
    $nodeid = get_current_nodeid(true);
    if (is_null($perm_res)) {
        $perm_res = PERM_RES_STRING_LINE;
    }
    if (is_null($user_type)) {
        $user_type = USER_TYPE_ZABBIX_USER;
    }
    $node_data = array();
    $result = array();
    //COpt::counter_up('perm_nodes['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
    //COpt::counter_up('perm');
    //SDI(get_accessible_groups_by_rights($rights,$user_type,$perm,PERM_RES_DATA_ARRAY,$nodeid));
    $available_groups = get_accessible_groups_by_rights($rights, $user_type, $perm, PERM_RES_DATA_ARRAY, $nodeid);
    foreach ($available_groups as $id => $group) {
        $nodeid = id2nodeid($group['groupid']);
        $permission = $group['permission'];
        if (isset($node_data[$nodeid]) && $permission < $node_data[$nodeid]['permission']) {
            $permission = $node_data[$nodeid]['permission'];
        }
        $node_data[$nodeid]['nodeid'] = $nodeid;
        $node_data[$nodeid]['permission'] = $permission;
    }
    $available_hosts = get_accessible_hosts_by_rights($rights, $user_type, $perm, PERM_RES_DATA_ARRAY, $nodeid);
    foreach ($available_hosts as $id => $host) {
        $nodeid = id2nodeid($host['hostid']);
        $permission = $host['permission'];
        if (isset($node_data[$nodeid]) && $permission < $node_data[$nodeid]['permission']) {
            $permission = $node_data[$nodeid]['permission'];
        }
        $node_data[$nodeid]['nodeid'] = $nodeid;
        $node_data[$nodeid]['permission'] = $permission;
    }
    foreach ($node_data as $nodeid => $node) {
        switch ($perm_res) {
            case PERM_RES_DATA_ARRAY:
                $db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid=' . $nodeid));
                if (!ZBX_DISTRIBUTED) {
                    if (!$node) {
                        $db_node = array('nodeid' => $ZBX_LOCALNODEID, 'name' => 'local', 'permission' => PERM_READ_WRITE, 'userid' => null);
                    } else {
                        continue;
                    }
                }
                $result[$nodeid] = array_merge($db_node, $node);
                break;
            default:
                $result[$nodeid] = $nodeid;
                break;
        }
    }
    if ($perm_res == PERM_RES_STRING_LINE) {
        if (count($result) == 0) {
            $result = '-1';
        } else {
            $result = implode(',', $result);
        }
    }
    return $result;
}
Esempio n. 3
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;
}
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);
        $lists['node']['read_write']->setAttribute('style', 'background: #EBEFF2;');
        $lists['node']['read_only']->setAttribute('style', 'background: #EBEFF2;');
        $lists['node']['deny']->setAttribute('style', 'background: #EBEFF2;');
        $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';
            }
            $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);
    $lists['group']['read_write']->setAttribute('style', 'background: #EBEFF2;');
    $lists['group']['read_only']->setAttribute('style', 'background: #EBEFF2;');
    $lists['group']['deny']->setAttribute('style', 'background: #EBEFF2;');
    $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';
        }
        $lists['group'][$list_name]->addItem($group['groupid'], (empty($group['node_name']) ? '' : $group['node_name'] . ':') . $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);
    $lists['host']['read_write']->setAttribute('style', 'background: #EBEFF2;');
    $lists['host']['read_only']->setAttribute('style', 'background: #EBEFF2;');
    $lists['host']['deny']->setAttribute('style', 'background: #EBEFF2;');
    $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';
        }
        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'] . ':') . $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');
        if (!$isHeaderDisplayed) {
            $table->setHeader(array(_('Read-write'), _('Read only'), _('Deny')), 'header');
            $isHeaderDisplayed = true;
        }
        $table->addRow($row);
        $rightsFormList->addRow($sLabel, $table);
    }
    return $rightsFormList;
}