Example #1
0
function check_right_on_discovery($permission)
{
    global $USER_DETAILS;
    if ($USER_DETAILS['type'] >= USER_TYPE_ZABBIX_ADMIN) {
        if (count(get_accessible_nodes_by_user($USER_DETAILS, $permission, PERM_RES_IDS_ARRAY))) {
            return true;
        }
    }
    return false;
}
Example #2
0
 function CZabbixXMLImport()
 {
     global $USER_DETAILS;
     $this->main_node = null;
     $this->sub_node = null;
     $this->data = null;
     $this->host = array('exist' => 0, 'missed' => 0);
     $this->template = array('exist' => 0, 'missed' => 0);
     $this->item = array('exist' => 0, 'missed' => 0);
     $this->trigger = array('exist' => 0, 'missed' => 0);
     $this->graph = array('exist' => 0, 'missed' => 0);
     $this->available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE);
     $this->available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE);
     $this->available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY);
 }
Example #3
0
 $td_r->setAttribute('width', '100%');
 $top_page_row = array(new CCol($logo, 'page_header_l'), $td_r);
 unset($logo, $page_header_r_col, $help, $support);
 $table = new CTable(NULL, 'page_header');
 $table->setCellSpacing(0);
 $table->setCellPadding(5);
 $table->addRow($top_page_row);
 $table->show();
 $menu_table = new CTable(NULL, 'menu');
 $menu_table->setCellSpacing(0);
 $menu_table->setCellPadding(5);
 $menu_table->addRow($main_menu);
 $node_form = null;
 if (ZBX_DISTRIBUTED && !defined('ZBX_HIDE_NODE_SELECTION')) {
     insert_js_function('check_all');
     $available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST, PERM_RES_DATA_ARRAY);
     $available_nodes = get_tree_by_parentid($ZBX_LOCALNODEID, $available_nodes, 'masterid');
     //remove parent nodes
     if (!empty($available_nodes)) {
         $node_form = new CForm();
         $node_form->setMethod('get');
         $node_form->setAttribute('id', 'node_form');
         // +++ create Combo Box with selected nodes +++
         $combo_node_list = null;
         if (count($ZBX_VIEWED_NODES['nodes']) > 0) {
             $combo_node_list = new CComboBox('switch_node', $ZBX_VIEWED_NODES['selected'], 'submit()');
             foreach ($ZBX_VIEWED_NODES['nodes'] as $nodeid => $nodedata) {
                 $combo_node_list->addItem($nodeid, $nodedata['name']);
             }
         }
         // --- ---
 /**
  * Delete drules
  *
  * @param array $druleids
  * @return boolean
  */
 public function delete(array $druleids)
 {
     $druleids = zbx_toArray($druleids);
     if (self::$userData['type'] >= USER_TYPE_ZABBIX_ADMIN) {
         if (!count(get_accessible_nodes_by_user(self::$userData, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
         }
     }
     $actionids = array();
     $sql = 'SELECT DISTINCT actionid ' . ' FROM conditions ' . ' WHERE conditiontype=' . CONDITION_TYPE_DRULE . ' AND ' . dbConditionString('value', $druleids);
     $dbActions = DBselect($sql);
     while ($dbAction = DBfetch($dbActions)) {
         $actionids[] = $dbAction['actionid'];
     }
     if (!empty($actionids)) {
         DB::update('actions', array('values' => array('status' => ACTION_STATUS_DISABLED), 'where' => array('actionid' => $actionids)));
         DB::delete('conditions', array('conditiontype' => CONDITION_TYPE_DRULE, 'value' => $druleids));
     }
     DB::delete('drules', array('druleid' => $druleids));
     return array('druleids' => $druleids);
 }
Example #5
0
    if (!sysmap_accessible($_REQUEST['sysmapid'], PERM_READ_WRITE)) {
        access_deny();
    }
    $sysmap = DBfetch(DBselect('select * from sysmaps where sysmapid=' . $_REQUEST['sysmapid']));
}
$_REQUEST['go'] = get_request('go', 'none');
if (isset($_REQUEST["save"])) {
    if (isset($_REQUEST["sysmapid"])) {
        // TODO check permission by new value.
        DBstart();
        update_sysmap($_REQUEST["sysmapid"], $_REQUEST["name"], $_REQUEST["width"], $_REQUEST["height"], $_REQUEST["backgroundid"], $_REQUEST["label_type"], $_REQUEST["label_location"]);
        $result = DBend();
        add_audit_if($result, AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_MAP, 'Name [' . $_REQUEST['name'] . ']');
        show_messages($result, "Network map updated", "Cannot update network map");
    } else {
        if (!count(get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
            access_deny();
        }
        DBstart();
        add_sysmap($_REQUEST["name"], $_REQUEST["width"], $_REQUEST["height"], $_REQUEST["backgroundid"], $_REQUEST["label_type"], $_REQUEST["label_location"]);
        $result = DBend();
        add_audit_if($result, AUDIT_ACTION_ADD, AUDIT_RESOURCE_MAP, 'Name [' . $_REQUEST['name'] . ']');
        show_messages($result, "Network map added", "Cannot add network map");
    }
    if ($result) {
        unset($_REQUEST["form"]);
    }
} else {
    if (isset($_REQUEST["delete"]) && isset($_REQUEST["sysmapid"])) {
        DBstart();
        delete_sysmap($_REQUEST["sysmapid"]);
Example #6
0
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/nodes.inc.php';
$page['title'] = _('Configuration of nodes');
$page['file'] = 'nodes.php';
$page['hist_arg'] = array();
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
$fields = array('nodeid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({form})&&({form}=="update"))'), 'new_nodeid' => array(T_ZBX_INT, O_OPT, null, DB_ID . NOT_ZERO, 'isset({save})', _('ID')), 'name' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({save})'), 'ip' => array(T_ZBX_IP, O_OPT, null, null, 'isset({save})'), 'nodetype' => array(T_ZBX_INT, O_OPT, null, IN(ZBX_NODE_CHILD . ',' . ZBX_NODE_MASTER . ',' . ZBX_NODE_LOCAL), 'isset({save})&&!isset({nodeid})'), 'masterid' => array(T_ZBX_INT, O_OPT, null, DB_ID, null), 'port' => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, 65535), 'isset({save})', _('Port')), 'save' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null));
check_fields($fields);
/*
 * Permissions
 */
$available_nodes = get_accessible_nodes_by_user(CWebUser::$data, PERM_READ);
if (count($available_nodes) == 0) {
    access_deny();
}
$node = null;
if (get_request('nodeid')) {
    $node = get_node_by_nodeid($_REQUEST['nodeid']);
    if (!$node) {
        access_deny();
    }
}
/*
 * Actions
 */
if (isset($_REQUEST['save'])) {
    if (get_request('nodeid')) {
Example #7
0
 $logo->setTarget('_blank');
 $top_page_row = array(new CCol($logo, 'page_header_l'), new CCol($page_header_r_col, 'maxwidth page_header_r'));
 unset($logo, $page_header_r_col, $help, $support);
 $table = new CTable(null, 'maxwidth page_header');
 $table->setCellSpacing(0);
 $table->setCellPadding(5);
 $table->addRow($top_page_row);
 $table->show();
 $menu_table = new CTable(null, 'menu pointer');
 $menu_table->setCellSpacing(0);
 $menu_table->setCellPadding(5);
 $menu_table->addRow($main_menu);
 $node_form = null;
 if (ZBX_DISTRIBUTED && !defined('ZBX_HIDE_NODE_SELECTION')) {
     insert_js_function('check_all');
     $available_nodes = get_accessible_nodes_by_user(CWebUser::$data, PERM_READ, PERM_RES_DATA_ARRAY);
     $available_nodes = get_tree_by_parentid($ZBX_LOCALNODEID, $available_nodes, 'masterid');
     // remove parent nodes
     if (empty($available_nodes[0])) {
         unset($available_nodes[0]);
     }
     if (!empty($available_nodes)) {
         $node_form = new CForm('get');
         $node_form->cleanItems();
         $node_form->setAttribute('id', 'node_form');
         // create ComboBox with selected nodes
         $nodesComboBox = null;
         if (count($ZBX_VIEWED_NODES['nodes']) > 0) {
             $nodesComboBox = new CComboBox('switch_node', $ZBX_VIEWED_NODES['selected'], 'submit()');
             foreach ($ZBX_VIEWED_NODES['nodes'] as $nodeid => $nodedata) {
                 $nodesComboBox->addItem($nodeid, $nodedata['name']);
function get_viewed_nodes()
{
    global $ZBX_LOCALNODEID;
    $result = array('selected' => 0, 'nodes' => array(), 'nodeids' => array());
    if (!defined('ZBX_NOT_ALLOW_ALL_NODES')) {
        $result['nodes'][0] = array('nodeid' => 0, 'name' => _('All'));
    }
    $available_nodes = get_accessible_nodes_by_user(CWebUser::$data, PERM_READ_LIST, PERM_RES_DATA_ARRAY);
    $available_nodes = get_tree_by_parentid($ZBX_LOCALNODEID, $available_nodes, 'masterid');
    // remove parent nodes
    $selected_nodeids = get_request('selected_nodes', get_node_profile(array(CWebUser::$data['node']['nodeid'])));
    // +++ Fill $result['NODEIDS'], $result['NODES'] +++
    $nodeids = array();
    foreach ($selected_nodeids as $num => $nodeid) {
        if (isset($available_nodes[$nodeid])) {
            $result['nodes'][$nodeid] = array('nodeid' => $available_nodes[$nodeid]['nodeid'], 'name' => $available_nodes[$nodeid]['name'], 'masterid' => $available_nodes[$nodeid]['masterid']);
            $nodeids[$nodeid] = $nodeid;
        }
    }
    $switch_node = get_request('switch_node', CProfile::get('web.nodes.switch_node', -1));
    if (!isset($available_nodes[$switch_node]) || !uint_in_array($switch_node, $selected_nodeids)) {
        // check switch_node
        $switch_node = 0;
    }
    $result['nodeids'] = $nodeids;
    if (!defined('ZBX_NOT_ALLOW_ALL_NODES')) {
        $result['selected'] = $switch_node;
    } elseif (!empty($nodeids)) {
        $result['selected'] = $switch_node > 0 ? $switch_node : array_shift($nodeids);
    }
    return $result;
}
Example #9
0
define('ZBX_PAGE_NO_MENU', 1);
include_once 'include/page_header.php';
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('dstfrm' => array(T_ZBX_STR, O_MAND, P_SYS, NOT_EMPTY, NULL), 'permission' => array(T_ZBX_INT, O_MAND, P_SYS, IN(PERM_DENY . ',' . PERM_READ_ONLY . ',' . PERM_READ_WRITE), NULL), 'nodeid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL));
check_fields($fields);
$dstfrm = get_request('dstfrm', 0);
// destination form
$permission = get_request('permission', PERM_DENY);
// right
$nodeid = get_request('nodeid', CProfile::get('web.popup_right.nodeid.last', get_current_nodeid(false)));
CProfile::update('web.popup_right.nodeid.last', $nodeid, PROFILE_TYPE_ID);
$frmTitle = new CForm();
$frmTitle->addVar('dstfrm', $dstfrm);
$frmTitle->addVar('permission', $permission);
if (ZBX_DISTRIBUTED) {
    $available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    $cmbResourceNode = new CComboBox('nodeid', $nodeid, 'submit();');
    $cmbResourceNode->addItem(0, S_ALL_S);
    $sql = 'SELECT name,nodeid ' . ' FROM nodes ' . ' WHERE ' . DBcondition('nodeid', $available_nodes);
    $db_nodes = DBselect($sql);
    while ($node = DBfetch($db_nodes)) {
        $cmbResourceNode->addItem($node['nodeid'], $node['name']);
    }
    $frmTitle->addItem(array(S_NODE, SPACE, $cmbResourceNode));
}
show_table_header(permission2str($permission), $frmTitle);
$form = new CForm();
$form->setAttribute('id', 'groups');
$table = new CTableInfo(S_NO_RESOURCES_DEFINED);
$table->setHeader(new CCol(array(new CCheckBox('all_groups', NULL, 'check_all(this.checked)'), S_NAME)));
// NODES
Example #10
0
function get_current_nodeid($forse_with_subnodes = null, $perm = null)
{
    global $USER_DETAILS, $ZBX_CURRENT_NODEID, $ZBX_CURRENT_SUBNODES, $ZBX_WITH_SUBNODES;
    if (!isset($ZBX_CURRENT_NODEID)) {
        init_nodes();
    }
    $result = is_show_subnodes($forse_with_subnodes) ? $ZBX_CURRENT_SUBNODES : $ZBX_CURRENT_NODEID;
    if (!is_null($perm)) {
        $result = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, $ZBX_CURRENT_SUBNODES);
    }
    return $result;
}
Example #11
0
        $data[$app['applicationid']] = array('id' => $app['applicationid'], 'name' => $app['name'], 'prefix' => get_node_name_by_elid($app['applicationid'], null, NAME_DELIMITER));
        $table->addRow(array($multiselect ? $checkBox : null, $name));
    }
    unset($app);
    if ($multiselect) {
        $button = new CButton('select', _('Select'), "javascript: addSelectedValues('applications', " . zbx_jsvalue($reference) . ', ' . $parentId . ');');
        $table->setFooter(new CCol($button, 'right'));
    }
    insert_js('var popupReference = ' . zbx_jsvalue($data, true) . ';');
    zbx_add_post_js('chkbxRange.pageGoName = "applications";');
    $form->addItem($table);
    $form->show();
} elseif ($srctbl == 'nodes') {
    $table = new CTableInfo();
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT DISTINCT n.* FROM nodes n WHERE ' . dbConditionInt('n.nodeid', get_accessible_nodes_by_user(CWebUser::$data, PERM_READ)));
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['name'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'graphs') {
    $form = new CForm();
    $form->setName('graphform');
    $form->setAttribute('id', 'graphs');
    $table = new CTableInfo(_('No graphs found.'));
    if ($multiselect) {
        $header = array(array(new CCheckBox('all_graphs', null, "javascript: checkAll('" . $form->getName() . "', 'all_graphs', 'graphs');"), _('Description')), _('Graph type'));
    } else {
Example #12
0
function get_viewed_nodes($options = array())
{
    global $USER_DETAILS;
    global $ZBX_LOCALNODEID, $ZBX_AVAILABLE_NODES;
    $config = select_config();
    $def_options = array('allow_all' => 0);
    $options = zbx_array_merge($def_options, $options);
    $result = array('selected' => 0, 'nodes' => array(), 'nodeids' => array());
    if (!defined('ZBX_NOT_ALLOW_ALL_NODES')) {
        $result['nodes'][0] = array('nodeid' => 0, 'name' => S_ALL_S);
    }
    $available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST, PERM_RES_DATA_ARRAY);
    $available_nodes = get_tree_by_parentid($ZBX_LOCALNODEID, $available_nodes, 'masterid');
    //remove parent nodes
    // $selected_nodeids = get_request('selected_nodes', CProfile::get('web.nodes.selected', array($USER_DETAILS['node']['nodeid'])));
    $selected_nodeids = get_request('selected_nodes', get_node_profile(array($USER_DETAILS['node']['nodeid'])));
    // +++ Fill $result['NODEIDS'], $result['NODES'] +++
    $nodes = array();
    $nodeids = array();
    foreach ($selected_nodeids as $num => $nodeid) {
        if (isset($available_nodes[$nodeid])) {
            $result['nodes'][$nodeid] = array('nodeid' => $available_nodes[$nodeid]['nodeid'], 'name' => $available_nodes[$nodeid]['name'], 'masterid' => $available_nodes[$nodeid]['masterid']);
            $nodeids[$nodeid] = $nodeid;
        }
    }
    // --- ---
    $switch_node = get_request('switch_node', CProfile::get('web.nodes.switch_node', -1));
    if (!isset($available_nodes[$switch_node]) || !uint_in_array($switch_node, $selected_nodeids)) {
        //check switch_node
        $switch_node = 0;
    }
    $result['nodeids'] = $nodeids;
    if (!defined('ZBX_NOT_ALLOW_ALL_NODES')) {
        $result['selected'] = $switch_node;
    } else {
        if (!empty($nodeids)) {
            $result['selected'] = $switch_node > 0 ? $switch_node : array_shift($nodeids);
        }
    }
    return $result;
}
Example #13
0
$params = array();
foreach ($validation_param as $option) {
    $params[$option] = 1;
}
$PAGE_GROUPS = get_viewed_groups(PERM_READ_ONLY, $params, $nodeid);
$PAGE_HOSTS = get_viewed_hosts(PERM_READ_ONLY, $PAGE_GROUPS['selected'], $params, $nodeid);
if (str_in_array($srctbl, array('graphs', 'applications', 'screens', 'triggers', 'logitems', 'items', 'simple_graph', 'plain_text'))) {
    validate_group_with_host($PAGE_GROUPS, $PAGE_HOSTS);
} else {
    if (str_in_array($srctbl, array('host_group', 'hosts', 'templates', 'host_templates'))) {
        validate_group($PAGE_GROUPS, $PAGE_HOSTS);
    }
}
$groupid = 0;
$hostid = 0;
$available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST);
$available_groups = $PAGE_GROUPS['groupids'];
$available_hosts = $PAGE_HOSTS['hostids'];
if (isset($only_hostid)) {
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    if (!isset($available_hosts[$only_hostid])) {
        access_deny();
    }
    $hostid = $_REQUEST['hostid'] = $only_hostid;
} else {
    if (str_in_array($srctbl, array('hosts', 'host_group', 'triggers', 'logitems', 'items', 'applications', 'screens', 'slides', 'graphs', 'simple_graph', 'sysmaps', 'plain_text', 'screens2', 'overview', 'host_group_scr'))) {
        if (ZBX_DISTRIBUTED) {
            $cmbNode = new CComboBox('nodeid', $nodeid, 'submit()');
            $db_nodes = DBselect('SELECT * FROM nodes WHERE ' . DBcondition('nodeid', $available_nodes));
            while ($node_data = DBfetch($db_nodes)) {
                $cmbNode->addItem($node_data['nodeid'], $node_data['name']);
    if (!is_null($templated)) {
        $options['templated'] = $templated;
    }
    $apps = API::Application()->get($options);
    CArrayHelper::sort($apps, array('host', 'name'));
    foreach ($apps as $app) {
        $action = get_window_opener($dstfrm, $dstfld1, $app[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $app[$srcfld2]) : '');
        $name = new CSpan($app['name'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow(array($hostid > 0 ? null : $app['host'], $name));
    }
    $table->show();
} elseif ($srctbl == 'nodes') {
    $table = new CTableInfo(_('No nodes defined.'));
    $table->setHeader(_('Name'));
    $result = DBselect('SELECT DISTINCT n.* FROM nodes n WHERE ' . dbConditionInt('n.nodeid', get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST)));
    while ($row = DBfetch($result)) {
        $action = get_window_opener($dstfrm, $dstfld1, $row[$srcfld1]) . (isset($srcfld2) ? get_window_opener($dstfrm, $dstfld2, $row[$srcfld2]) : '');
        $name = new CSpan($row['name'], 'link');
        $name->setAttribute('onclick', $action . ' close_window(); return false;');
        $table->addRow($name);
    }
    $table->show();
} elseif ($srctbl == 'graphs') {
    $form = new CForm();
    $form->setName('graphform');
    $form->setAttribute('id', 'graphs');
    $table = new CTableInfo(_('No graphs defined.'));
    if ($multiselect) {
        $header = array(array(new CCheckBox('all_graphs', null, "javascript: checkAll('" . $form->getName() . "', 'all_graphs', 'graphs');"), _('Description')), _('Graph type'));
    } else {
Example #15
0
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
$page['title'] = _('Resource');
$page['file'] = 'popup_right.php';
define('ZBX_PAGE_NO_MENU', 1);
require_once dirname(__FILE__) . '/include/page_header.php';
//	VAR					TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('dstfrm' => array(T_ZBX_STR, O_MAND, P_SYS, NOT_EMPTY, null), 'permission' => array(T_ZBX_INT, O_MAND, P_SYS, IN(PERM_DENY . ',' . PERM_READ . ',' . PERM_READ_WRITE), null), 'nodeid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null));
check_fields($fields);
$dstfrm = getRequest('dstfrm', 0);
$permission = getRequest('permission', PERM_DENY);
$nodeId = null;
$availableNodeIds = null;
if (ZBX_DISTRIBUTED) {
    $nodeId = getRequest('nodeid', CProfile::get('web.popup_right.nodeid.last', get_current_nodeid(false)));
    $availableNodeIds = get_accessible_nodes_by_user(CWebUser::$data, PERM_READ, PERM_RES_IDS_ARRAY);
    $profileNodeId = $nodeId;
    if (!isset($availableNodeIds[$nodeId])) {
        $nodeId = null;
        if ($nodeId != 0) {
            $profileNodeId = null;
        }
    }
    CProfile::update('web.popup_right.nodeid.last', $profileNodeId, PROFILE_TYPE_ID);
}
/*
 * Display
 */
// node combobox
$titleFrom = new CForm();
$titleFrom->addVar('dstfrm', $dstfrm);