Ejemplo n.º 1
0
     }
 } else {
     if (isset($_REQUEST['add_dependence']) && isset($_REQUEST['new_dependence'])) {
         if (!isset($_REQUEST['dependencies'])) {
             $_REQUEST['dependencies'] = array();
         }
         foreach ($_REQUEST['new_dependence'] as $triggerid) {
             if (!uint_in_array($triggerid, $_REQUEST['dependencies'])) {
                 array_push($_REQUEST['dependencies'], $triggerid);
             }
         }
     } else {
         if (isset($_REQUEST['del_dependence']) && isset($_REQUEST['rem_dependence'])) {
             if (isset($_REQUEST['dependencies'])) {
                 foreach ($_REQUEST['dependencies'] as $key => $val) {
                     if (!uint_in_array($val, $_REQUEST['rem_dependence'])) {
                         continue;
                     }
                     unset($_REQUEST['dependencies'][$key]);
                 }
             }
         } else {
             if ($_REQUEST['go'] == 'massupdate' && isset($_REQUEST['mass_save']) && isset($_REQUEST['g_triggerid'])) {
                 show_messages();
                 $result = false;
                 $visible = get_request('visible', array());
                 $_REQUEST['dependencies'] = get_request('dependencies', array());
                 $options = array('triggerids' => $_REQUEST['g_triggerid'], 'select_dependencies' => 1, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                 $triggers = CTrigger::get($options);
                 DBstart();
                 foreach ($triggers as $tnum => $db_trig) {
Ejemplo n.º 2
0
function profile_type($type, $profile_type)
{
    $profile_type = strtolower($profile_type);
    switch ($profile_type) {
        case 'array':
            $result = uint_in_array($type, array(PROFILE_TYPE_ARRAY_ID, PROFILE_TYPE_ARRAY_INT, PROFILE_TYPE_ARRAY_STR));
            break;
        case 'id':
            $result = uint_in_array($type, array(PROFILE_TYPE_ID, PROFILE_TYPE_ARRAY_ID));
            break;
        case 'int':
            $result = uint_in_array($type, array(PROFILE_TYPE_INT, PROFILE_TYPE_ARRAY_INT));
            break;
        case 'str':
            $result = uint_in_array($type, array(PROFILE_TYPE_STR, PROFILE_TYPE_ARRAY_STR));
            break;
        case 'unknown':
            $result = $type == PROFILE_TYPE_UNKNOWN;
            break;
        default:
            $result = false;
    }
    return $result;
}
Ejemplo n.º 3
0
function update_user_group($usrgrpid, $name, $users_status, $gui_access, $api_access, $debug_mode, $users = array(), $rights = array())
{
    global $USER_DETAILS;
    $sql = 'SELECT * ' . ' FROM usrgrp ' . ' WHERE name=' . zbx_dbstr($name) . ' AND usrgrpid<>' . $usrgrpid . ' AND ' . DBin_node('usrgrpid', get_current_nodeid(false));
    if (DBfetch(DBselect($sql))) {
        error("Group '{$name}' already exists");
        return 0;
    }
    $result = DBexecute('UPDATE usrgrp SET name=' . zbx_dbstr($name) . ' WHERE usrgrpid=' . $usrgrpid);
    if (!$result) {
        return $result;
    }
    // must come before adding user to group
    $result &= change_group_status($usrgrpid, $users_status);
    $result &= change_group_gui_access($usrgrpid, $gui_access);
    $result &= change_group_api_access($usrgrpid, $api_access);
    $result &= change_group_debug_mode($usrgrpid, $debug_mode);
    if (!$result) {
        return $result;
    }
    //-------
    $grant = true;
    if ($gui_access == GROUP_GUI_ACCESS_DISABLED || $users_status == GROUP_STATUS_DISABLED) {
        $grant = !uint_in_array($USER_DETAILS['userid'], $users);
    }
    if ($grant) {
        $result = DBexecute('DELETE FROM users_groups WHERE usrgrpid=' . $usrgrpid);
        foreach ($users as $userid => $name) {
            $result = add_user_to_group($userid, $usrgrpid);
            if (!$result) {
                return $result;
            }
        }
    } else {
        error(S_USER_CANNOT_DISABLE_ITSELF);
        return false;
    }
    $result = DBexecute('DELETE FROM rights WHERE groupid=' . $usrgrpid);
    foreach ($rights as $right) {
        $id = get_dbid('rights', 'rightid');
        $result = DBexecute('INSERT INTO rights (rightid,groupid,permission,id)' . ' VALUES (' . $id . ',' . $usrgrpid . ',' . $right['permission'] . ',' . $right['id'] . ')');
        if (!$result) {
            return $result;
        }
    }
    return $result;
}
Ejemplo n.º 4
0
function delete_template_triggers($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $triggers = get_triggers_by_hostid($hostid);
    while ($trigger = DBfetch($triggers)) {
        if ($trigger['templateid'] == 0) {
            continue;
        }
        if ($templateids != null) {
            $db_tmp_hosts = get_hosts_by_triggerid($trigger["templateid"]);
            $tmp_host = DBfetch($db_tmp_hosts);
            if (!uint_in_array($tmp_host["hostid"], $templateids)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute('UPDATE triggers SET templateid=0 WHERE triggerid=' . $trigger['triggerid'])) {
                info('Trigger "' . $trigger["description"] . '" unlinked');
            }
        } else {
            delete_trigger($trigger["triggerid"]);
        }
    }
    return TRUE;
}
$itemFormList = new CFormList('itemFormList');
// append type to form list
$copyTypeComboBox = new CComboBox('copy_type', $this->data['copy_type'], 'submit()');
$copyTypeComboBox->addItem(0, _('Hosts'));
$copyTypeComboBox->addItem(1, _('Host groups'));
$itemFormList->addRow(_('Target type'), $copyTypeComboBox);
// append targets to form list
$targetList = array();
if ($this->data['copy_type'] == 0) {
    $groupComboBox = new CComboBox('copy_groupid', $this->data['copy_groupid'], 'submit()');
    foreach ($this->data['groups'] as $group) {
        $groupComboBox->addItem($group['groupid'], $group['name']);
    }
    $itemFormList->addRow(_('Group'), $groupComboBox);
    foreach ($this->data['hosts'] as $host) {
        array_push($targetList, array(new CCheckBox('copy_targetid[' . $host['hostid'] . ']', uint_in_array($host['hostid'], $this->data['copy_targetid']), null, $host['hostid']), SPACE, $host['name'], BR()));
    }
} else {
    foreach ($this->data['groups'] as $group) {
        array_push($targetList, array(new CCheckBox('copy_targetid[' . $group['groupid'] . ']', uint_in_array($group['groupid'], $this->data['copy_targetid']), null, $group['groupid']), SPACE, $group['name'], BR()));
    }
}
$itemFormList->addRow(_('Target'), !empty($targetList) ? $targetList : SPACE);
// append tabs to form
$itemTab = new CTabView();
$itemTab->addTab('itemTab', count($this->data['group_itemid']) . ' ' . _('elements copy to ...'), $itemFormList);
$itemForm->addItem($itemTab);
// append buttons to form
$itemForm->addItem(makeFormFooter(new CSubmit('copy', _('Copy')), new CButtonCancel(url_param('groupid') . url_param('hostid') . url_param('config'))));
$itemWidget->addItem($itemForm);
return $itemWidget;
Ejemplo n.º 6
0
    }
    if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
        $actions = new CLink(S_GRAPH, 'history.php?action=showgraph&itemid=' . $db_item['itemid'], 'action');
    } else {
        $actions = new CLink(S_HISTORY, 'history.php?action=showvalues&period=3600&itemid=' . $db_item['itemid'], 'action');
    }
    array_push($app_rows, new CRow(array(is_show_subnodes() ? $db_host['item_cnt'] ? SPACE : get_node_name_by_elid($db_item['itemid']) : null, $_REQUEST['hostid'] ? NULL : ($db_host['item_cnt'] ? SPACE : $db_item['host']), str_repeat(SPACE, 6) . $description, $lastclock, new CCol($lastvalue), $change, $actions)));
}
unset($app_rows);
unset($db_host);
foreach ($db_hosts as $hostid => $db_host) {
    if (!isset($tab_rows[$hostid])) {
        continue;
    }
    $app_rows = $tab_rows[$hostid];
    if (uint_in_array(0, $_REQUEST['applications']) || isset($show_all_apps)) {
        $url = '?close=1&applicationid=0' . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select');
        $link = new CLink(new CImg('images/general/opened.gif'), $url);
        //			$link = new CLink(new CImg('images/general/opened.gif'),$url,null,"javascript: return updater.onetime_update('".ZBX_PAGE_MAIN_HAT."','".$url."');");
    } else {
        $url = '?open=1&applicationid=0' . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select');
        $link = new CLink(new CImg('images/general/closed.gif'), $url);
        //			$link = new CLink(new CImg('images/general/closed.gif'),$url,null,"javascript: return updater.onetime_update('".ZBX_PAGE_MAIN_HAT."','".$url."');");
    }
    $col = new CCol(array($link, SPACE, bold(S_MINUS_OTHER_MINUS), SPACE . '(' . $db_host['item_cnt'] . SPACE . S_ITEMS . ')'));
    $col->SetColSpan(5);
    $table->AddRow(array(get_node_name_by_elid($db_host['hostid']), $_REQUEST['hostid'] > 0 ? NULL : $db_host['host'], $col));
    foreach ($app_rows as $row) {
        $table->AddRow($row);
    }
}
Ejemplo n.º 7
0
                    /*				if($result){
                    					add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_HOST_GROUP,
                    					S_HOST_GROUP.' ['.$group['name'].' ] ['.$group['groupid'].']');
                    				}*/
                }
                $result = DBend($result);
                show_messages(true, S_GROUP_DELETED, S_CANNOT_DELETE_GROUP);
            } else {
                if (str_in_array($_REQUEST['go'], array('activate', 'disable'))) {
                    $result = true;
                    $status = $_REQUEST['go'] == 'activate' ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED;
                    $groups = get_request('groups', array());
                    $db_hosts = DBselect('select h.hostid, hg.groupid ' . ' from hosts_groups hg, hosts h' . ' where h.hostid=hg.hostid ' . ' and h.status in (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' and ' . DBin_node('h.hostid'));
                    DBstart();
                    while ($db_host = DBfetch($db_hosts)) {
                        if (!uint_in_array($db_host['groupid'], $groups)) {
                            continue;
                        }
                        $host = get_host_by_hostid($db_host['hostid']);
                        $result &= update_host_status($db_host['hostid'], $status);
                        /*			add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_HOST,
                        				'Old status ['.$host['status'].'] '.'New status ['.$status.']');*/
                    }
                    $result = DBend($result);
                    show_messages($result, S_HOST_STATUS_UPDATED, S_CANNOT_UPDATE_HOST);
                    unset($_REQUEST['activate']);
                }
            }
        }
    }
}
Ejemplo n.º 8
0
function delete_template_graphs($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $db_graphs = get_graphs_by_hostid($hostid);
    while ($db_graph = DBfetch($db_graphs)) {
        if ($db_graph['templateid'] == 0) {
            continue;
        }
        if (!is_null($templateids)) {
            $tmp_hhosts = get_hosts_by_graphid($db_graph['templateid']);
            $tmp_host = DBfetch($tmp_hhosts);
            if (!uint_in_array($tmp_host['hostid'], $templateids)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute('UPDATE graphs SET templateid=0 WHERE graphid=' . $db_graph['graphid'])) {
                info('Graph "' . $db_graph['name'] . '" unlinked');
            }
        } else {
            delete_graph($db_graph['graphid']);
        }
    }
}
Ejemplo n.º 9
0
 public function draw()
 {
     $start_time = microtime(true);
     set_image_header();
     $this->column = uint_in_array($this->type, array(GRAPH_TYPE_COLUMN, GRAPH_TYPE_COLUMN_STACKED));
     $this->fullSizeX = $this->sizeX;
     $this->fullSizeY = $this->sizeY;
     if ($this->sizeX < 300 || $this->sizeY < 200) {
         $this->showLegend(0);
     }
     $this->calcShifts();
     $this->sizeX -= $this->shiftXleft + $this->shiftXright + $this->shiftlegendright + $this->shiftXCaptionLeft + $this->shiftXCaptionRight;
     $this->sizeY -= $this->shiftY + $this->shiftYLegend + $this->shiftYCaptionBottom + $this->shiftYCaptionTop;
     $this->calcSeriesWidth();
     $this->calcMiniMax();
     $this->correctMiniMax();
     if (function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
         $this->im = imagecreatetruecolor($this->fullSizeX, $this->fullSizeY);
     } else {
         $this->im = imagecreate($this->fullSizeX, $this->fullSizeY);
     }
     $this->initColors();
     $this->drawRectangle();
     $this->drawHeader();
     $this->drawGrid();
     $this->drawSideValues();
     $this->drawLogo();
     $this->drawLegend();
     $count = 0;
     if ($this->column) {
         $start = $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2);
     } else {
         $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - floor($this->seriesDistance / 2);
     }
     foreach ($this->series as $key => $series) {
         foreach ($series as $num => $serie) {
             $axis = $serie['axis'];
             $value = $serie['value'];
             $color = $this->getColor($this->seriesColor[$num], $this->opacity);
             if ($this->column) {
                 imagefilledrectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $color);
                 imagerectangle($this->im, $start, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - round($this->sizeY / $this->maxValue[$axis] * $value), $start + $this->columnWidth, $this->sizeY + $this->shiftY + $this->shiftYCaptionTop, $this->getColor('Black No Alpha'));
             } else {
                 imagefilledrectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $color);
                 imagerectangle($this->im, $this->shiftXleft + $this->shiftXCaptionLeft, $start - $this->columnWidth, $this->shiftXleft + $this->shiftXCaptionLeft + round($this->sizeX / $this->maxValue[$axis] * $value), $start, $this->getColor('Black No Alpha'));
             }
             $start = $this->column ? $start + $this->columnWidth : $start - $this->columnWidth;
         }
         $count++;
         if ($this->column) {
             $start = $count * ($this->seriesWidth + $this->seriesDistance) + $this->shiftXleft + $this->shiftXCaptionLeft + floor($this->seriesDistance / 2);
         } else {
             $start = $this->sizeY + $this->shiftY + $this->shiftYCaptionTop - $count * ($this->seriesWidth + $this->seriesDistance) - floor($this->seriesDistance / 2);
         }
     }
     $str = sprintf('%0.2f', microtime(true) - $start_time);
     $str = _s('Generated in %s sec', $str);
     $strSize = imageTextSize(6, 0, $str);
     imageText($this->im, 6, 0, $this->fullSizeX - $strSize['width'] - 5, $this->fullSizeY - 5, $this->getColor('Gray'), $str);
     unset($this->items, $this->data);
     imageOut($this->im);
 }
Ejemplo n.º 10
0
function get_regexp_form()
{
    $frm_title = S_REGULAR_EXPRESSION;
    if (isset($_REQUEST['regexpid']) && !isset($_REQUEST["form_refresh"])) {
        $sql = 'SELECT re.* ' . ' FROM regexps re ' . ' WHERE ' . DBin_node('re.regexpid') . ' AND re.regexpid=' . $_REQUEST['regexpid'];
        $regexp = DBfetch(DBSelect($sql));
        $frm_title .= ' [' . $regexp['name'] . ']';
        $rename = $regexp['name'];
        $test_string = $regexp['test_string'];
        $expressions = array();
        $sql = 'SELECT e.* ' . ' FROM expressions e ' . ' WHERE ' . DBin_node('e.expressionid') . ' AND e.regexpid=' . $regexp['regexpid'] . ' ORDER BY e.expression_type';
        $db_exps = DBselect($sql);
        while ($exp = DBfetch($db_exps)) {
            $expressions[] = $exp;
        }
    } else {
        $rename = get_request('rename', '');
        $test_string = get_request('test_string', '');
        $expressions = get_request('expressions', array());
    }
    $tblRE = new CTable('', 'nowrap');
    $tblRE->addStyle('border-left: 1px #AAA solid; border-right: 1px #AAA solid; background-color: #EEE; padding: 2px; padding-left: 6px; padding-right: 6px;');
    $tblRE->addRow(array(S_NAME, new CTextBox('rename', $rename, 60)));
    $tblRE->addRow(array(S_TEST_STRING, new CTextArea('test_string', $test_string, 66, 5)));
    $tabExp = new CTableInfo();
    $td1 = new CCol(S_EXPRESSION);
    $td1->addStyle('background-color: #CCC;');
    $td2 = new CCol(S_EXPECTED_RESULT);
    $td2->addStyle('background-color: #CCC;');
    $td3 = new CCol(S_RESULT);
    $td3->addStyle('background-color: #CCC;');
    $tabExp->setHeader(array($td1, $td2, $td3));
    $final_result = !empty($test_string);
    foreach ($expressions as $id => $expression) {
        $results = array();
        $paterns = array($expression['expression']);
        if (!empty($test_string)) {
            if ($expression['expression_type'] == EXPRESSION_TYPE_ANY_INCLUDED) {
                $paterns = explode($expression['exp_delimiter'], $expression['expression']);
            }
            if (uint_in_array($expression['expression_type'], array(EXPRESSION_TYPE_TRUE, EXPRESSION_TYPE_FALSE))) {
                if ($expression['case_sensitive']) {
                    $results[$id] = ereg($paterns[0], $test_string);
                } else {
                    $results[$id] = eregi($paterns[0], $test_string);
                }
                if ($expression['expression_type'] == EXPRESSION_TYPE_TRUE) {
                    $final_result &= $results[$id];
                } else {
                    $final_result &= !$results[$id];
                }
            } else {
                $results[$id] = true;
                $tmp_result = false;
                if ($expression['case_sensitive']) {
                    foreach ($paterns as $pid => $patern) {
                        $tmp_result |= zbx_stristr($test_string, $patern) !== false;
                    }
                } else {
                    foreach ($paterns as $pid => $patern) {
                        $tmp_result |= zbx_strstr($test_string, $patern) !== false;
                    }
                }
                $results[$id] &= $tmp_result;
                $final_result &= $results[$id];
            }
        }
        if (isset($results[$id]) && $results[$id]) {
            $exp_res = new CSpan(S_TRUE_BIG, 'green bold');
        } else {
            $exp_res = new CSpan(S_FALSE_BIG, 'red bold');
        }
        $expec_result = expression_type2str($expression['expression_type']);
        if (EXPRESSION_TYPE_ANY_INCLUDED == $expression['expression_type']) {
            $expec_result .= ' (' . S_DELIMITER . "='" . $expression['exp_delimiter'] . "')";
        }
        $tabExp->addRow(array($expression['expression'], $expec_result, $exp_res));
    }
    $td = new CCol(S_COMBINED_RESULT, 'bold');
    $td->setColSpan(2);
    if ($final_result) {
        $final_result = new CSpan(S_TRUE_BIG, 'green bold');
    } else {
        $final_result = new CSpan(S_FALSE_BIG, 'red bold');
    }
    $tabExp->addRow(array($td, $final_result));
    $tblRE->addRow(array(S_RESULT, $tabExp));
    $tblFoot = new CTableInfo(null);
    $td = new CCol(array(new CButton('save', S_SAVE)));
    $td->setColSpan(2);
    $td->addStyle('text-align: right;');
    $td->addItem(SPACE);
    $td->addItem(new CButton('test', S_TEST));
    if (isset($_REQUEST['regexpid'])) {
        $td->addItem(SPACE);
        $td->addItem(new CButton('clone', S_CLONE));
        $td->addItem(SPACE);
        $td->addItem(new CButtonDelete(S_DELETE_REGULAR_EXPRESSION_Q, url_param('form') . url_param('config') . url_param('regexpid')));
    }
    $td->addItem(SPACE);
    $td->addItem(new CButtonCancel(url_param("regexpid")));
    $tblFoot->SetFooter($td);
    return array($tblRE, $tblFoot);
}
Ejemplo n.º 11
0
    }
} elseif (isset($_REQUEST['delete']) && isset($_REQUEST['triggerid'])) {
    DBstart();
    $result = API::Trigger()->delete($_REQUEST['triggerid']);
    $result = DBend($result);
    show_messages($result, _('Trigger deleted'), _('Cannot delete trigger'));
    clearCookies($result, $_REQUEST['hostid']);
    if ($result) {
        unset($_REQUEST['form'], $_REQUEST['triggerid']);
    }
} elseif (isset($_REQUEST['add_dependency']) && isset($_REQUEST['new_dependency'])) {
    if (!isset($_REQUEST['dependencies'])) {
        $_REQUEST['dependencies'] = array();
    }
    foreach ($_REQUEST['new_dependency'] as $triggerid) {
        if (!uint_in_array($triggerid, $_REQUEST['dependencies'])) {
            array_push($_REQUEST['dependencies'], $triggerid);
        }
    }
} elseif ($_REQUEST['go'] == 'massupdate' && isset($_REQUEST['mass_save']) && isset($_REQUEST['g_triggerid'])) {
    $visible = get_request('visible', array());
    // update triggers
    $triggersToUpdate = array();
    foreach ($_REQUEST['g_triggerid'] as $triggerid) {
        $trigger = array('triggerid' => $triggerid);
        if (isset($visible['priority'])) {
            $trigger['priority'] = get_request('priority');
        }
        if (isset($visible['dependencies'])) {
            $trigger['dependencies'] = zbx_toObject(get_request('dependencies', array()), 'triggerid');
        }
Ejemplo n.º 12
0
 function StartElement($parser, $name, $attrs)
 {
     $this->element_data = '';
     if (!isset($this->root)) {
         if ($name == XML_TAG_ZABBIX_EXPORT) {
             if (isset($attrs['version'])) {
                 if ($attrs['version'] == '1.0') {
                     $this->root = true;
                     return;
                 } else {
                     error(S_UNSUPPORTED_VERSION_OF_IMPORTED_DATA);
                 }
             }
         }
         error(S_UNSUPPORTED_FILE_FORMAT);
         $this->root = false;
     } else {
         if (!$this->root) {
             return false;
         }
     }
     $data =& $this->data[$name];
     foreach ($attrs as $id => $val) {
         $attrs[$id] = html_entity_decode($val);
     }
     switch ($name) {
         case XML_TAG_HOST:
             $this->main_node = array($name);
             $this->sub_node = null;
             $data = $attrs;
             $data['groups'] = array();
             $data['skip'] = false;
             $sql = 'SELECT hostid ' . ' FROM hosts' . ' WHERE host=' . zbx_dbstr($data['name']) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ')' . ' AND ' . DBin_node('hostid', get_current_nodeid(false));
             if ($host_data = DBfetch(DBselect($sql))) {
                 /* exist */
                 if ($this->host['exist'] == 1) {
                     $data['skip'] = true;
                     info('Host [' . $data['name'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 if (!isset($this->available_hosts[$host_data['hostid']])) {
                     error('Host [' . $data['name'] . '] skipped - Access deny.');
                     break;
                     // case
                 }
                 $data['hostid'] = $host_data['hostid'];
                 $data['templates'] = get_templates_by_hostid($host_data['hostid']);
                 $data['groups'] = get_groupids_by_host($host_data['hostid']);
             } else {
                 /* missed */
                 if ($this->host['missed'] == 1) {
                     /* skip */
                     $data['skip'] = true;
                     info('Host [' . $data['name'] . '] skipped - user rule');
                     break;
                     // case
                 }
                 if (!uint_in_array(get_current_nodeid(), $this->available_nodes)) {
                     error('Host [' . $data['name'] . '] skipped - access denied.');
                     break;
                     // case
                 }
                 $data['templates'] = array();
                 $data['hostid'] = add_host($data['name'], 10050, HOST_STATUS_TEMPLATE, 0, '', '', 0, array(), 'no', '', 623, -1, 2, '', '', null, array());
             }
             break;
             // case
         // case
         case XML_TAG_GRAPH:
             $data = $attrs;
             $data['items'] = array();
             $this->sub_node = null;
             array_push($this->main_node, $name);
             break;
             // case
         // case
         case XML_TAG_DEPENDENCY:
             // checks if trigger has been skipped
             if (str_in_array($attrs['description'], $this->data[XML_TAG_DEPENDENCIES]['skip'])) {
                 info('Trigger [' . $attrs['description'] . '] dependency update skipped - user rule');
                 break;
             }
             // searches trigger by host name & trigger description
             if (!($trigger_down = get_trigger_by_description($attrs['description']))) {
                 error('Trigger [' . $attrs['description'] . '] dependency update skipped - trigger not found');
                 break;
             }
             $data['triggerid_down'] = $trigger_down['triggerid'];
             $data['triggerid_up'] = array();
             $this->sub_node = null;
             array_push($this->main_node, $name);
             break;
         case XML_TAG_HOSTPROFILE:
         case XML_TAG_HOSTPROFILE_EXT:
         case XML_TAG_TEMPLATE:
         case XML_TAG_ITEM:
         case XML_TAG_TRIGGER:
         case XML_TAG_DEPENDS:
         case XML_TAG_GRAPH_ELEMENT:
             /*case XML_TAG_SCREEN:
             		case XML_TAG_SCREEN_ELEMENT:*/
             $data = $attrs;
             $this->sub_node = null;
             array_push($this->main_node, $name);
             break;
             // case
         // case
         case XML_TAG_HOSTS:
             $this->data[XML_TAG_DEPENDENCIES]['skip'] = array();
             break;
         case XML_TAG_DEPENDENCIES:
         case XML_TAG_ZABBIX_EXPORT:
         case XML_TAG_GROUPS:
         case XML_TAG_APPLICATIONS:
         case XML_TAG_TEMPLATES:
         case XML_TAG_ITEMS:
         case XML_TAG_TRIGGERS:
         case XML_TAG_GRAPHS:
             /* case XML_TAG_SCREENS:*/
             $this->sub_node = null;
             break;
             // case
         // case
         case XML_TAG_GROUP:
         case XML_TAG_APPLICATION:
         default:
             $this->sub_node = $name;
             break;
             // case
     }
 }
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
function get_screen_item_form()
{
    global $USER_DETAILS;
    $form = new CFormTable(S_SCREEN_CELL_CONFIGURATION, 'screenedit.php?screenid=' . $_REQUEST['screenid']);
    $form->SetHelp('web.screenedit.cell.php');
    if (isset($_REQUEST['screenitemid'])) {
        $sql = 'SELECT * ' . ' FROM screens_items' . ' WHERE screenid=' . $_REQUEST['screenid'] . ' AND screenitemid=' . $_REQUEST['screenitemid'];
        $iresult = DBSelect($sql);
        $form->addVar('screenitemid', $_REQUEST['screenitemid']);
    } else {
        $form->addVar('x', $_REQUEST['x']);
        $form->addVar('y', $_REQUEST['y']);
    }
    if (isset($_REQUEST['screenitemid']) && !isset($_REQUEST['form_refresh'])) {
        $irow = DBfetch($iresult);
        $resourcetype = $irow['resourcetype'];
        $resourceid = $irow['resourceid'];
        $width = $irow['width'];
        $height = $irow['height'];
        $colspan = $irow['colspan'];
        $rowspan = $irow['rowspan'];
        $elements = $irow['elements'];
        $valign = $irow['valign'];
        $halign = $irow['halign'];
        $style = $irow['style'];
        $url = $irow['url'];
        $dynamic = $irow['dynamic'];
    } else {
        $resourcetype = get_request('resourcetype', 0);
        $resourceid = get_request('resourceid', 0);
        $width = get_request('width', 500);
        $height = get_request('height', 100);
        $colspan = get_request('colspan', 0);
        $rowspan = get_request('rowspan', 0);
        $elements = get_request('elements', 25);
        $valign = get_request('valign', VALIGN_DEFAULT);
        $halign = get_request('halign', HALIGN_DEFAULT);
        $style = get_request('style', 0);
        $url = get_request('url', '');
        $dynamic = get_request('dynamic', SCREEN_SIMPLE_ITEM);
    }
    $form->addVar('screenid', $_REQUEST['screenid']);
    // a-z order!!!
    $cmbRes = new CCombobox('resourcetype', $resourcetype, 'submit()');
    $cmbRes->addItem(SCREEN_RESOURCE_CLOCK, S_CLOCK);
    $cmbRes->addItem(SCREEN_RESOURCE_DATA_OVERVIEW, S_DATA_OVERVIEW);
    $cmbRes->addItem(SCREEN_RESOURCE_GRAPH, S_GRAPH);
    $cmbRes->addItem(SCREEN_RESOURCE_ACTIONS, S_HISTORY_OF_ACTIONS);
    $cmbRes->addItem(SCREEN_RESOURCE_EVENTS, S_HISTORY_OF_EVENTS);
    $cmbRes->addItem(SCREEN_RESOURCE_HOSTS_INFO, S_HOSTS_INFO);
    $cmbRes->addItem(SCREEN_RESOURCE_MAP, S_MAP);
    $cmbRes->addItem(SCREEN_RESOURCE_PLAIN_TEXT, S_PLAIN_TEXT);
    $cmbRes->addItem(SCREEN_RESOURCE_SCREEN, S_SCREEN);
    $cmbRes->addItem(SCREEN_RESOURCE_SERVER_INFO, S_SERVER_INFO);
    $cmbRes->addItem(SCREEN_RESOURCE_SIMPLE_GRAPH, S_SIMPLE_GRAPH);
    $cmbRes->addItem(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, S_STATUS_OF_HOSTGROUP_TRIGGERS);
    $cmbRes->addItem(SCREEN_RESOURCE_HOST_TRIGGERS, S_STATUS_OF_HOST_TRIGGERS);
    $cmbRes->addItem(SCREEN_RESOURCE_SYSTEM_STATUS, S_SYSTEM_STATUS);
    $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_INFO, S_TRIGGERS_INFO);
    $cmbRes->addItem(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, S_TRIGGERS_OVERVIEW);
    $cmbRes->addItem(SCREEN_RESOURCE_URL, S_URL);
    $form->addRow(S_RESOURCE, $cmbRes);
    if ($resourcetype == SCREEN_RESOURCE_GRAPH) {
        // User-defined graph
        $options = array('graphids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND);
        $graphs = CGraph::get($options);
        $caption = '';
        $id = 0;
        if (!empty($graphs)) {
            $id = $resourceid;
            $graph = reset($graphs);
            order_result($graph['hosts'], 'host');
            $graph['host'] = reset($graph['hosts']);
            $caption = $graph['host']['host'] . ':' . $graph['name'];
            $nodeName = get_node_name_by_elid($graph['host']['hostid']);
            if (!zbx_empty($nodeName)) {
                $caption = '(' . $nodeName . ') ' . $caption;
            }
        }
        $form->addVar('resourceid', $id);
        $textfield = new CTextbox('caption', $caption, 75, 'yes');
        $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&real_hosts=1&dstfld1=resourceid&dstfld2=caption&srctbl=graphs&srcfld1=graphid&srcfld2=name',800,450);");
        $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
        $form->addRow(S_GRAPH_NAME, array($textfield, SPACE, $selectbtn));
    } else {
        if ($resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) {
            // Simple graph
            $options = array('itemids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND);
            $items = CItem::get($options);
            $caption = '';
            $id = 0;
            if (!empty($items)) {
                $id = $resourceid;
                $item = reset($items);
                $item['host'] = reset($item['hosts']);
                $caption = item_description($item);
                $nodeName = get_node_name_by_elid($item['itemid']);
                if (!zbx_empty($nodeName)) {
                    $caption = '(' . $nodeName . ') ' . $caption;
                }
            }
            $form->addVar('resourceid', $id);
            $textfield = new Ctextbox('caption', $caption, 75, 'yes');
            $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&real_hosts=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=simple_graph&srcfld1=itemid&srcfld2=description',800,450);");
            $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
            $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
        } else {
            if ($resourcetype == SCREEN_RESOURCE_MAP) {
                // Map
                $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND);
                $maps = CMap::get($options);
                $caption = '';
                $id = 0;
                if (!empty($maps)) {
                    $id = $resourceid;
                    $map = reset($maps);
                    $caption = $map['name'];
                    $nodeName = get_node_name_by_elid($map['sysmapid']);
                    if (!zbx_empty($nodeName)) {
                        $caption = '(' . $nodeName . ') ' . $caption;
                    }
                }
                $form->addVar('resourceid', $id);
                $textfield = new Ctextbox('caption', $caption, 60, 'yes');
                $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name',400,450);");
                $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
            } else {
                if ($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) {
                    // Plain text
                    $options = array('itemids' => $resourceid, 'select_hosts' => array('hostid', 'host'), 'output' => API_OUTPUT_EXTEND);
                    $items = CItem::get($options);
                    $caption = '';
                    $id = 0;
                    if (!empty($items)) {
                        $id = $resourceid;
                        $item = reset($items);
                        $item['host'] = reset($item['hosts']);
                        $caption = item_description($item);
                        $nodeName = get_node_name_by_elid($item['itemid']);
                        if (!zbx_empty($nodeName)) {
                            $caption = '(' . $nodeName . ') ' . $caption;
                        }
                    }
                    $form->addVar('resourceid', $id);
                    $textfield = new CTextbox('caption', $caption, 75, 'yes');
                    $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=plain_text&srcfld1=itemid&srcfld2=description',800,450);");
                    $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                    $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
                    $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2));
                    $form->addRow(S_SHOW_TEXT_AS_HTML, new CCheckBox('style', $style, null, 1));
                } else {
                    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_HOST_TRIGGERS))) {
                        // Status of triggers
                        $caption = '';
                        $id = 0;
                        if (SCREEN_RESOURCE_HOSTGROUP_TRIGGERS == $resourcetype) {
                            if ($resourceid > 0) {
                                $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                                $groups = CHostgroup::get($options);
                                foreach ($groups as $gnum => $group) {
                                    $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name'];
                                    $id = $resourceid;
                                }
                            }
                            $form->addVar('resourceid', $id);
                            $textfield = new CTextbox('caption', $caption, 60, 'yes');
                            $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group&srcfld1=groupid&srcfld2=name',800,450);");
                            $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                            $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn));
                        } else {
                            if ($resourceid > 0) {
                                $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                                $hosts = CHost::get($options);
                                foreach ($hosts as $hnum => $host) {
                                    $caption = get_node_name_by_elid($host['hostid'], true, ':') . $host['host'];
                                    $id = $resourceid;
                                }
                            }
                            $form->addVar('resourceid', $id);
                            $textfield = new CTextbox('caption', $caption, 60, 'yes');
                            $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=hosts&srcfld1=hostid&srcfld2=host',800,450);");
                            $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                            $form->addRow(S_HOST, array($textfield, SPACE, $selectbtn));
                        }
                        $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2));
                    } else {
                        if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_EVENTS, SCREEN_RESOURCE_ACTIONS))) {
                            // History of actions
                            // History of events
                            $form->addRow(S_SHOW_LINES, new CNumericBox('elements', $elements, 2));
                            $form->addVar('resourceid', 0);
                        } else {
                            if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) {
                                // Overviews
                                $caption = '';
                                $id = 0;
                                if ($resourceid > 0) {
                                    $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'editable' => 1);
                                    $groups = CHostgroup::get($options);
                                    foreach ($groups as $gnum => $group) {
                                        $caption = get_node_name_by_elid($group['groupid'], true, ':') . $group['name'];
                                        $id = $resourceid;
                                    }
                                }
                                $form->addVar('resourceid', $id);
                                $textfield = new CTextbox('caption', $caption, 75, 'yes');
                                $selectbtn = new CButton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=overview&srcfld1=groupid&srcfld2=name',800,450);");
                                $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                                $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn));
                            } else {
                                if ($resourcetype == SCREEN_RESOURCE_SCREEN) {
                                    // Screens
                                    $caption = '';
                                    $id = 0;
                                    if ($resourceid > 0) {
                                        $result = DBselect('SELECT DISTINCT n.name as node_name,s.screenid,s.name ' . ' FROM screens s ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('s.screenid') . ' WHERE s.screenid=' . $resourceid);
                                        while ($row = DBfetch($result)) {
                                            $r = CScreen::get(array('screenids' => $row['screenid'], 'output' => API_OUTPUT_SHORTEN));
                                            if (empty($r)) {
                                                continue;
                                            }
                                            if (check_screen_recursion($_REQUEST['screenid'], $row['screenid'])) {
                                                continue;
                                            }
                                            $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
                                            $caption = $row['node_name'] . $row['name'];
                                            $id = $resourceid;
                                        }
                                    }
                                    $form->addVar('resourceid', $id);
                                    $textfield = new Ctextbox('caption', $caption, 60, 'yes');
                                    $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=screens2&srcfld1=screenid&srcfld2=name&screenid=" . $_REQUEST['screenid'] . "',800,450);");
                                    $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                                    $form->addRow(S_PARAMETER, array($textfield, SPACE, $selectbtn));
                                } else {
                                    if ($resourcetype == SCREEN_RESOURCE_HOSTS_INFO || $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) {
                                        // HOSTS info
                                        $caption = '';
                                        $id = 0;
                                        $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY);
                                        if (remove_nodes_from_id($resourceid) > 0) {
                                            $result = DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM hosts_groups hg, groups g ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=' . $resourceid);
                                            while ($row = DBfetch($result)) {
                                                $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
                                                $caption = $row['node_name'] . $row['name'];
                                                $id = $resourceid;
                                            }
                                        } else {
                                            if (remove_nodes_from_id($resourceid) == 0) {
                                                $result = DBselect('SELECT DISTINCT n.name as node_name ' . ' FROM nodes n ' . ' WHERE n.nodeid=' . id2nodeid($resourceid));
                                                while ($row = DBfetch($result)) {
                                                    $row['node_name'] = isset($row['node_name']) ? '(' . $row['node_name'] . ') ' : '';
                                                    $caption = $row['node_name'] . S_MINUS_ALL_GROUPS_MINUS;
                                                    $id = $resourceid;
                                                }
                                            }
                                        }
                                        $form->addVar('resourceid', $id);
                                        $textfield = new CTextbox('caption', $caption, 60, 'yes');
                                        $selectbtn = new Cbutton('select', S_SELECT, "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $form->getName() . "&dstfld1=resourceid&dstfld2=caption&srctbl=host_group_scr&srcfld1=groupid&srcfld2=name',480,450);");
                                        $selectbtn->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';");
                                        $form->addRow(S_GROUP, array($textfield, SPACE, $selectbtn));
                                    } else {
                                        // SCREEN_RESOURCE_CLOCK
                                        $form->addVar('resourceid', 0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO))) {
        $cmbStyle = new CComboBox("style", $style);
        $cmbStyle->addItem(STYLE_HORISONTAL, S_HORIZONTAL);
        $cmbStyle->addItem(STYLE_VERTICAL, S_VERTICAL);
        $form->addRow(S_STYLE, $cmbStyle);
    } else {
        if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) {
            $cmbStyle = new CComboBox('style', $style);
            $cmbStyle->addItem(STYLE_LEFT, S_LEFT);
            $cmbStyle->addItem(STYLE_TOP, S_TOP);
            $form->addRow(S_HOSTS_LOCATION, $cmbStyle);
        } else {
            if ($resourcetype == SCREEN_RESOURCE_CLOCK) {
                $cmbStyle = new CComboBox('style', $style);
                $cmbStyle->addItem(TIME_TYPE_LOCAL, S_LOCAL_TIME);
                $cmbStyle->addItem(TIME_TYPE_SERVER, S_SERVER_TIME);
                $form->addRow(S_TIME_TYPE, $cmbStyle);
            } else {
                $form->addVar('style', 0);
            }
        }
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_URL))) {
        $form->addRow(S_URL, new CTextBox('url', $url, 60));
    } else {
        $form->addVar('url', '');
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) {
        $form->addRow(S_WIDTH, new CNumericBox('width', $width, 5));
        $form->addRow(S_HEIGHT, new CNumericBox('height', $height, 5));
    } else {
        $form->addVar('width', 500);
        $form->addVar('height', 100);
    }
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_MAP, SCREEN_RESOURCE_CLOCK, SCREEN_RESOURCE_URL))) {
        $cmbHalign = new CComboBox('halign', $halign);
        $cmbHalign->addItem(HALIGN_CENTER, S_CENTRE);
        $cmbHalign->addItem(HALIGN_LEFT, S_LEFT);
        $cmbHalign->addItem(HALIGN_RIGHT, S_RIGHT);
        $form->addRow(S_HORIZONTAL_ALIGN, $cmbHalign);
    } else {
        $form->addVar('halign', 0);
    }
    $cmbValign = new CComboBox('valign', $valign);
    $cmbValign->addItem(VALIGN_MIDDLE, S_MIDDLE);
    $cmbValign->addItem(VALIGN_TOP, S_TOP);
    $cmbValign->addItem(VALIGN_BOTTOM, S_BOTTOM);
    $form->addRow(S_VERTICAL_ALIGN, $cmbValign);
    $form->addRow(S_COLUMN_SPAN, new CNumericBox('colspan', $colspan, 2));
    $form->addRow(S_ROW_SPAN, new CNumericBox('rowspan', $rowspan, 2));
    // dynamic AddOn
    if (uint_in_array($resourcetype, array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) {
        $form->addRow(S_DYNAMIC_ITEM, new CCheckBox('dynamic', $dynamic, null, 1));
    }
    $form->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($_REQUEST['screenitemid'])) {
        $form->addItemToBottomRow(SPACE);
        $form->addItemToBottomRow(new CButtonDelete(null, url_param('form') . url_param('screenid') . url_param('screenitemid')));
    }
    $form->addItemToBottomRow(SPACE);
    $form->addItemToBottomRow(new CButtonCancel(url_param('screenid')));
    return $form;
}
Ejemplo n.º 15
0
function zbx_uint_array_intersect(&$array1, &$array2)
{
    $result = array();
    foreach ($array1 as $key => $value) {
        if (uint_in_array($value, $array2)) {
            $result[$key] = $value;
        }
    }
    return $result;
}
    $autologoutTextBox = new CNumericBox('autologout', $this->data['autologout'], 4);
} else {
    $autologoutTextBox = new CNumericBox('autologout', 900, 4);
    $autologoutTextBox->setAttribute('disabled', 'disabled');
}
if ($this->data['alias'] != ZBX_GUEST_USER) {
    $userFormList->addRow(_('Auto-login'), new CCheckBox('autologin', $this->data['autologin'], null, 1));
    $userFormList->addRow(_('Auto-logout (min 90 seconds)'), array($autologoutCheckBox, $autologoutTextBox));
}
$userFormList->addRow(_('Refresh (in seconds)'), new CNumericBox('refresh', $this->data['refresh'], 4));
$userFormList->addRow(_('Rows per page'), new CNumericBox('rows_per_page', $this->data['rows_per_page'], 6));
$userFormList->addRow(_('URL (after login)'), new CTextBox('url', $this->data['url'], ZBX_TEXTBOX_STANDARD_SIZE));
/*
 * Media tab
 */
if (uint_in_array(CWebUser::$data['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN))) {
    $userMediaFormList = new CFormList('userMediaFormList');
    $userForm->addVar('user_medias', $this->data['user_medias']);
    $mediaTableInfo = new CTableInfo(_('No media found.'));
    foreach ($this->data['user_medias'] as $id => $media) {
        if (!isset($media['active']) || !$media['active']) {
            $status = new CLink(_('Enabled'), '#', 'enabled');
            $status->onClick('return create_var("' . $userForm->getName() . '","disable_media",' . $id . ', true);');
        } else {
            $status = new CLink(_('Disabled'), '#', 'disabled');
            $status->onClick('return create_var("' . $userForm->getName() . '","enable_media",' . $id . ', true);');
        }
        $mediaUrl = '?dstfrm=' . $userForm->getName() . '&media=' . $id . '&mediatypeid=' . $media['mediatypeid'] . '&sendto=' . urlencode($media['sendto']) . '&period=' . $media['period'] . '&severity=' . $media['severity'] . '&active=' . $media['active'];
        foreach (getSeverityCaption() as $key => $caption) {
            $mediaActive = $media['severity'] & 1 << $key;
            $mediaSeverity[$key] = new CSpan(mb_substr($caption, 0, 1), $mediaActive ? 'enabled' : null);
Ejemplo n.º 17
0
/**
 * Generate data for the trigger configuration form.
 *
 * @param string $exprAction	expression constructor action, see remakeExpression() for a list of supported values
 *
 * @return array
 */
function getTriggerFormData($exprAction)
{
    $data = array('form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'parent_discoveryid' => getRequest('parent_discoveryid'), 'dependencies' => getRequest('dependencies', array()), 'db_dependencies' => array(), 'triggerid' => getRequest('triggerid'), 'expression' => getRequest('expression', ''), 'expr_temp' => getRequest('expr_temp', ''), 'description' => getRequest('description', ''), 'type' => getRequest('type', 0), 'priority' => getRequest('priority', 0), 'status' => getRequest('status', 0), 'comments' => getRequest('comments', ''), 'url' => getRequest('url', ''), 'input_method' => getRequest('input_method', IM_ESTABLISHED), 'limited' => false, 'templates' => array(), 'hostid' => getRequest('hostid', 0));
    if (!empty($data['triggerid'])) {
        // get trigger
        $options = array('output' => API_OUTPUT_EXTEND, 'selectHosts' => array('hostid'), 'triggerids' => $data['triggerid']);
        $trigger = $data['parent_discoveryid'] ? API::TriggerPrototype()->get($options) : API::Trigger()->get($options);
        $data['trigger'] = reset($trigger);
        // get templates
        $tmp_triggerid = $data['triggerid'];
        do {
            $db_triggers = DBfetch(DBselect('SELECT t.triggerid,t.templateid,id.parent_itemid,h.name,h.hostid' . ' FROM triggers t' . ' LEFT JOIN functions f ON t.triggerid=f.triggerid' . ' LEFT JOIN items i ON f.itemid=i.itemid' . ' LEFT JOIN hosts h ON i.hostid=h.hostid' . ' LEFT JOIN item_discovery id ON i.itemid=id.itemid' . ' WHERE t.triggerid=' . zbx_dbstr($tmp_triggerid)));
            if (bccomp($data['triggerid'], $tmp_triggerid) != 0) {
                // parent trigger prototype link
                if ($data['parent_discoveryid']) {
                    $link = 'trigger_prototypes.php?form=update&triggerid=' . $db_triggers['triggerid'] . '&parent_discoveryid=' . $db_triggers['parent_itemid'] . '&hostid=' . $db_triggers['hostid'];
                } else {
                    $link = 'triggers.php?form=update&triggerid=' . $db_triggers['triggerid'] . '&hostid=' . $db_triggers['hostid'];
                }
                $data['templates'][] = new CLink(CHtml::encode($db_triggers['name']), $link, 'highlight underline weight_normal');
                $data['templates'][] = SPACE . '&rArr;' . SPACE;
            }
            $tmp_triggerid = $db_triggers['templateid'];
        } while ($tmp_triggerid != 0);
        $data['templates'] = array_reverse($data['templates']);
        array_shift($data['templates']);
        $data['limited'] = $data['trigger']['templateid'] != 0;
        // select first host from triggers if gived not match
        $hosts = $data['trigger']['hosts'];
        if (count($hosts) > 0 && !in_array(array('hostid' => $data['hostid']), $hosts)) {
            $host = reset($hosts);
            $data['hostid'] = $host['hostid'];
        }
    }
    if (!empty($data['triggerid']) && !isset($_REQUEST['form_refresh']) || $data['limited']) {
        $data['expression'] = explode_exp($data['trigger']['expression']);
        if (!$data['limited'] || !isset($_REQUEST['form_refresh'])) {
            $data['description'] = $data['trigger']['description'];
            $data['type'] = $data['trigger']['type'];
            $data['priority'] = $data['trigger']['priority'];
            $data['status'] = $data['trigger']['status'];
            $data['comments'] = $data['trigger']['comments'];
            $data['url'] = $data['trigger']['url'];
            $db_triggers = DBselect('SELECT t.triggerid,t.description' . ' FROM triggers t,trigger_depends d' . ' WHERE t.triggerid=d.triggerid_up' . ' AND d.triggerid_down=' . zbx_dbstr($data['triggerid']));
            while ($trigger = DBfetch($db_triggers)) {
                if (uint_in_array($trigger['triggerid'], $data['dependencies'])) {
                    continue;
                }
                array_push($data['dependencies'], $trigger['triggerid']);
            }
        }
    }
    if ($data['input_method'] == IM_TREE) {
        $analyze = analyzeExpression($data['expression']);
        if ($analyze !== false) {
            list($data['outline'], $data['eHTMLTree']) = $analyze;
            if ($exprAction !== null && $data['eHTMLTree'] != null) {
                $new_expr = remakeExpression($data['expression'], $_REQUEST['expr_target_single'], $exprAction, $data['expr_temp']);
                if ($new_expr !== false) {
                    $data['expression'] = $new_expr;
                    $analyze = analyzeExpression($data['expression']);
                    if ($analyze !== false) {
                        list($data['outline'], $data['eHTMLTree']) = $analyze;
                    } else {
                        show_messages(false, '', _('Expression Syntax Error.'));
                    }
                    $data['expr_temp'] = '';
                } else {
                    show_messages(false, '', _('Expression Syntax Error.'));
                }
            }
            $data['expression_field_name'] = 'expr_temp';
            $data['expression_field_value'] = $data['expr_temp'];
            $data['expression_field_readonly'] = true;
        } else {
            show_messages(false, '', _('Expression Syntax Error.'));
            $data['input_method'] = IM_ESTABLISHED;
        }
    }
    if ($data['input_method'] != IM_TREE) {
        $data['expression_field_name'] = 'expression';
        $data['expression_field_value'] = $data['expression'];
        $data['expression_field_readonly'] = $data['limited'];
    }
    if (empty($data['parent_discoveryid'])) {
        $data['db_dependencies'] = API::Trigger()->get(array('triggerids' => $data['dependencies'], 'output' => array('triggerid', 'flags', 'description'), 'preservekeys' => true, 'selectHosts' => array('hostid', 'name')));
        foreach ($data['db_dependencies'] as &$dependency) {
            if (count($dependency['hosts']) > 1) {
                order_result($dependency['hosts'], 'name', ZBX_SORT_UP);
            }
            $dependency['hosts'] = array_values($dependency['hosts']);
            $dependency['hostid'] = $dependency['hosts'][0]['hostid'];
        }
        unset($dependency);
        order_result($data['db_dependencies'], 'description');
    }
    return $data;
}
Ejemplo n.º 18
0
 /**
  * Mass update user group.
  * Checks for permissions - only super admins can change user groups.
  * Changes name to a group if name and one user group id is provided.
  * Links/unlinks users to user groups.
  * Links/unlinks rights to user groups.
  *
  * @param array $data
  * @param int|int[] $data['usrgrpids'] id or ids of user groups to be updated.
  * @param string $data['name'] name to be set to a user group. Only one host group id can be passed at a time!
  * @param null|int|int[] $data['userids'] user ids to link to given user groups. Missing user ids will be unlinked from user groups.
  * @param null|array $data['rights'] rights to link to given user groups. Missing rights will be unlinked from user groups.
  * @param int $data['rights']['id'] id of right.
  * @param int $data['rights']['permission'] permission level of right.
  *
  * @return int[] array['usrgrpids'] returns passed user group ids
  */
 public function massUpdate($data)
 {
     if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can update user groups.'));
     }
     $usrgrpids = zbx_toArray($data['usrgrpids']);
     if (count($usrgrpids) == 0) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Missing parameter: usrgrpids.'));
     }
     // $data['name'] parameter restrictions
     if (isset($data['name'])) {
         // same name can be set only to one hostgroup
         if (count($usrgrpids) > 1) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Only one user group name can be changed at a time.'));
         } else {
             // check if there already is hostgroup with this name, except current hostgroup
             $groupExists = $this->get(array('filter' => array('name' => $data['name']), 'output' => array('usrgrpid'), 'limit' => 1));
             $groupExists = reset($groupExists);
             if ($groupExists && bccomp($groupExists['usrgrpid'], $usrgrpids[0]) != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('User group "%s" already exists.', $data['name']));
             }
         }
     }
     // update usrgrp (user group) table if there is something to update
     $usrgrpTableUpdateData = $data;
     unset($usrgrpTableUpdateData['usrgrpids'], $usrgrpTableUpdateData['userids'], $usrgrpTableUpdateData['rights']);
     if (!empty($usrgrpTableUpdateData)) {
         foreach ($usrgrpids as $usrgrpid) {
             DB::update('usrgrp', array('values' => $usrgrpTableUpdateData, 'where' => array('usrgrpid' => $usrgrpid)));
         }
     }
     // check that user do not add himself to a disabled user group
     // insert and delete user-userGroup links
     if (isset($data['userids'])) {
         $userids = zbx_toArray($data['userids']);
         // check whether user tries to add himself to a disabled user group
         $usrgrps = $this->get(array('usrgrpids' => $usrgrpids, 'output' => API_OUTPUT_EXTEND));
         if (uint_in_array(self::$userData['userid'], $userids)) {
             foreach ($usrgrps as $usrgrp) {
                 if ($usrgrp['gui_access'] == GROUP_GUI_ACCESS_DISABLED || $usrgrp['users_status'] == GROUP_STATUS_DISABLED) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('User cannot add himself to a disabled group or a group with disabled GUI access.'));
                 }
             }
         }
         // get already linked users
         $linkedUsers = array();
         $sql = 'SELECT usrgrpid,userid' . ' FROM users_groups' . ' WHERE ' . dbConditionInt('usrgrpid', $usrgrpids);
         $linkedUsersDb = DBselect($sql);
         while ($link = DBfetch($linkedUsersDb)) {
             if (!isset($linkedUsers[$link['usrgrpid']])) {
                 $linkedUsers[$link['usrgrpid']] = array();
             }
             $linkedUsers[$link['usrgrpid']][$link['userid']] = 1;
         }
         // get user-userGroup links to insert and get user ids to unlink
         $userUsergroupLinksToInsert = array();
         $userIdsToUnlink = array();
         foreach ($usrgrpids as $usrgrpid) {
             foreach ($userids as $userid) {
                 if (!isset($linkedUsers[$usrgrpid][$userid])) {
                     $userUsergroupLinksToInsert[] = array('usrgrpid' => $usrgrpid, 'userid' => $userid);
                 }
                 unset($linkedUsers[$usrgrpid][$userid]);
             }
             if (isset($linkedUsers[$usrgrpid]) && !empty($linkedUsers[$usrgrpid])) {
                 $userIdsToUnlink = array_merge($userIdsToUnlink, array_keys($linkedUsers[$usrgrpid]));
             }
         }
         // link users to user groups
         if (!empty($userUsergroupLinksToInsert)) {
             DB::insert('users_groups', $userUsergroupLinksToInsert);
         }
         // unlink users from user groups
         if (!empty($userIdsToUnlink)) {
             DB::delete('users_groups', array('userid' => $userIdsToUnlink, 'usrgrpid' => $usrgrpids));
         }
     }
     // link rights to user groups
     // update permissions to right-userGroup links
     // unlink rights from user groups (permissions)
     if (isset($data['rights'])) {
         $rights = zbx_toArray($data['rights']);
         // get already linked rights
         $linkedRights = array();
         $sql = 'SELECT groupid,permission,id' . ' FROM rights' . ' WHERE ' . dbConditionInt('groupid', $usrgrpids);
         $linkedRightsDb = DBselect($sql);
         while ($link = DBfetch($linkedRightsDb)) {
             if (!isset($linkedRights[$link['groupid']])) {
                 $linkedRights[$link['groupid']] = array();
             }
             $linkedRights[$link['groupid']][$link['id']] = $link['permission'];
         }
         // get right-userGroup links to insert
         // get right-userGroup links to update permissions
         // get rightIds to unlink rights from user groups
         $rightUsergroupLinksToInsert = array();
         $rightUsergroupLinksToUpdate = array();
         $rightIdsToUnlink = array();
         foreach ($usrgrpids as $usrgrpid) {
             foreach ($rights as $right) {
                 if (!isset($linkedRights[$usrgrpid][$right['id']])) {
                     $rightUsergroupLinksToInsert[] = array('groupid' => $usrgrpid, 'id' => $right['id'], 'permission' => $right['permission']);
                 } elseif ($linkedRights[$usrgrpid][$right['id']] != $right['permission']) {
                     $rightUsergroupLinksToUpdate[] = array('values' => array('permission' => $right['permission']), 'where' => array('groupid' => $usrgrpid, 'id' => $right['id']));
                 }
                 unset($linkedRights[$usrgrpid][$right['id']]);
             }
             if (isset($linkedRights[$usrgrpid]) && !empty($linkedRights[$usrgrpid])) {
                 $rightIdsToUnlink = array_merge($rightIdsToUnlink, array_keys($linkedRights[$usrgrpid]));
             }
         }
         // link rights to user groups
         if (!empty($rightUsergroupLinksToInsert)) {
             DB::insert('rights', $rightUsergroupLinksToInsert);
         }
         // unlink rights from user groups
         if (!empty($rightIdsToUnlink)) {
             DB::delete('rights', array('id' => $rightIdsToUnlink, 'groupid' => $usrgrpids));
         }
         // update right-userGroup permissions
         if (!empty($rightUsergroupLinksToUpdate)) {
             DB::update('rights', $rightUsergroupLinksToUpdate);
         }
     }
     return array('usrgrpids' => $usrgrpids);
 }
Ejemplo n.º 19
0
function in_node($id_var, $nodes = null)
{
    if (is_null($nodes)) {
        $nodes = get_current_nodeid();
    }
    if (empty($nodes)) {
        $nodes = 0;
    }
    if (zbx_numeric($nodes)) {
        $nodes = array($nodes);
    } else {
        if (is_string($nodes)) {
            if (!eregi('([0-9\\,]+)', $nodes)) {
                fatal_error('Incorrect "nodes" for "in_node". Passed [' . $nodes . ']');
            }
            $nodes = explode(',', $nodes);
        } else {
            if (!is_array($nodes)) {
                fatal_error('Incorrect type of "nodes" for "in_node". Passed [' . gettype($nodes) . ']');
            }
        }
    }
    return uint_in_array(id2nodeid($id_var), $nodes);
}
    // display empty visible name if equal to host name
    if ($visiblename === $host) {
        $visiblename = '';
    }
    // get template groups from db
    $groups = $this->data['dbTemplate']['groups'];
    $groups = zbx_objectValues($groups, 'groupid');
    $macros = order_macros($this->data['dbTemplate']['macros'], 'macro');
    // get template hosts from db
    $hosts_linked_to = API::Host()->get(array('output' => array('hostid'), 'templateids' => $templateid, 'templated_hosts' => true));
    $hosts_linked_to = zbx_objectValues($hosts_linked_to, 'hostid');
    $hosts_linked_to = zbx_toHash($hosts_linked_to, 'hostid');
    $templateIds = $this->data['original_templates'];
} else {
    $groups = get_request('groups', array());
    if (isset($_REQUEST['groupid']) && $_REQUEST['groupid'] > 0 && !uint_in_array($_REQUEST['groupid'], $groups)) {
        array_push($groups, $_REQUEST['groupid']);
    }
    $hosts_linked_to = get_request('hosts', array());
}
$clear_templates = array_intersect($clear_templates, array_keys($this->data['original_templates']));
$clear_templates = array_diff($clear_templates, array_keys($templateIds));
natcasesort($templateIds);
$frmHost->addVar('clear_templates', $clear_templates);
// TEMPLATE WIDGET {
$templateList = new CFormList('hostlist');
// FORM ITEM : Template name text box [  ]
$template_nameTB = new CTextBox('template_name', $host, 54);
$template_nameTB->setAttribute('maxlength', 64);
$template_nameTB->attr('autofocus', 'autofocus');
$templateList->addRow(_('Template name'), $template_nameTB);
Ejemplo n.º 21
0
 */
$options = array('groups' => array('real_hosts' => true, 'not_proxy_hosts' => true, 'editable' => true), 'hosts' => array('editable' => true), 'hostid' => get_request('hostid', null), 'groupid' => get_request('groupid', null));
$pageFilter = new CPageFilter($options);
$_REQUEST['groupid'] = $pageFilter->groupid;
$_REQUEST['hostid'] = $pageFilter->hostid;
/*
 * Actions
 */
$_REQUEST['applications'] = get_request('applications', get_favorites('web.httpconf.applications'));
$_REQUEST['applications'] = zbx_objectValues($_REQUEST['applications'], 'value');
$showAllApps = null;
if (isset($_REQUEST['open'])) {
    if (!isset($_REQUEST['applicationid'])) {
        $_REQUEST['applications'] = array();
        $showAllApps = 1;
    } elseif (!uint_in_array($_REQUEST['applicationid'], $_REQUEST['applications'])) {
        array_push($_REQUEST['applications'], $_REQUEST['applicationid']);
    }
} elseif (isset($_REQUEST['close'])) {
    if (!isset($_REQUEST['applicationid'])) {
        $_REQUEST['applications'] = array();
    } elseif (($i = array_search($_REQUEST['applicationid'], $_REQUEST['applications'])) !== false) {
        unset($_REQUEST['applications'][$i]);
    }
}
// limit opened application count
if (count($_REQUEST['applications']) > 25) {
    $_REQUEST['applications'] = array_slice($_REQUEST['applications'], -25);
}
rm4favorites('web.httpconf.applications');
foreach ($_REQUEST['applications'] as $application) {
Ejemplo n.º 22
0
             $result = DBend($result);
         }
         show_messages($result, S_APPLICATION_DELETED, S_CANNOT_DELETE_APPLICATION);
         if ($result) {
             add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $app['name'] . '] from host [' . $host['host'] . ']');
         }
         unset($_REQUEST['form']);
         unset($_REQUEST['applicationid']);
     } else {
         /* group operations */
         $result = true;
         $applications = get_request('applications', array());
         $db_applications = DBselect('SELECT applicationid, name, hostid ' . ' FROM applications ' . ' WHERE ' . DBin_node('applicationid'));
         DBstart();
         while ($db_app = DBfetch($db_applications)) {
             if (!uint_in_array($db_app['applicationid'], $applications)) {
                 continue;
             }
             $result &= delete_application($db_app['applicationid']);
             if ($result) {
                 $host = get_host_by_hostid($db_app['hostid']);
                 add_audit(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_APPLICATION, 'Application [' . $db_app['name'] . '] from host [' . $host['host'] . ']');
             }
         }
         $result = DBend($result);
         show_messages(true, S_APPLICATION_DELETED, NULL);
     }
     unset($_REQUEST['delete']);
 } else {
     if ($_REQUEST['config'] == 4 && (isset($_REQUEST['activate']) || isset($_REQUEST['disable']))) {
         /* group operations */
Ejemplo n.º 23
0
        switch ($_REQUEST['favid']) {
            case 'hat_syssum':
                $syssum = make_system_summary();
                $syssum->show();
                break;
            case 'hat_stszbx':
                $stszbx = make_status_of_zbx();
                $stszbx->show();
                break;
        }
    }
}
if (PAGE_TYPE_JS == $page['type'] || PAGE_TYPE_HTML_BLOCK == $page['type']) {
    exit;
}
$admin = uint_in_array($USER_DETAILS['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN));
$rows_per_page = $USER_DETAILS['rows_per_page'];
$search_wdgt = new CWidget('search_wdgt');
$search = get_request('search', '');
// Header
if (zbx_empty($search)) {
    $search = 'Search pattern is empty';
}
$search_wdgt->addHeader(array(S_SEARCH_BIG . ': ', bold($search)), SPACE);
//-------------
$left_tab = new CTable();
$left_tab->setCellPadding(3);
$left_tab->setCellSpacing(3);
$left_tab->setAttribute('border', 0);
$right_tab = new CTable();
$right_tab->setCellPadding(3);
Ejemplo n.º 24
0
 $dbHostItems = DBselect('SELECT i.itemid,h.name,h.hostid' . ' FROM hosts h,items i' . ' WHERE i.hostid=h.hostid' . ' AND ' . dbConditionInt('i.itemid', zbx_objectValues($data['items'], 'templateid')));
 while ($dbHostItem = DBfetch($dbHostItems)) {
     foreach ($data['items'] as $itemid => $item) {
         if ($item['templateid'] == $dbHostItem['itemid']) {
             $data['items'][$itemid]['template_host'] = $dbHostItem;
         }
     }
 }
 foreach ($data['items'] as &$item) {
     $item['hostids'] = zbx_objectValues($item['hosts'], 'hostid');
     $item['name_expanded'] = itemName($item);
     if (empty($data['filter_hostname'])) {
         $host = reset($item['hosts']);
         $item['host'] = $host['name'];
     }
     $item['subfilters'] = array('subfilter_hosts' => empty($_REQUEST['subfilter_hosts']) || (bool) array_intersect($_REQUEST['subfilter_hosts'], $item['hostids']), 'subfilter_types' => empty($_REQUEST['subfilter_types']) || uint_in_array($item['type'], $_REQUEST['subfilter_types']), 'subfilter_value_types' => empty($_REQUEST['subfilter_value_types']) || uint_in_array($item['value_type'], $_REQUEST['subfilter_value_types']), 'subfilter_status' => empty($_REQUEST['subfilter_status']) || uint_in_array($item['status'], $_REQUEST['subfilter_status']), 'subfilter_templated_items' => empty($_REQUEST['subfilter_templated_items']) || ($item['templateid'] == 0 && uint_in_array(0, $_REQUEST['subfilter_templated_items']) || $item['templateid'] > 0 && uint_in_array(1, $_REQUEST['subfilter_templated_items'])), 'subfilter_with_triggers' => empty($_REQUEST['subfilter_with_triggers']) || count($item['triggers']) == 0 && uint_in_array(0, $_REQUEST['subfilter_with_triggers']) || count($item['triggers']) > 0 && uint_in_array(1, $_REQUEST['subfilter_with_triggers']), 'subfilter_history' => empty($_REQUEST['subfilter_history']) || uint_in_array($item['history'], $_REQUEST['subfilter_history']), 'subfilter_trends' => empty($_REQUEST['subfilter_trends']) || uint_in_array($item['trends'], $_REQUEST['subfilter_trends']), 'subfilter_interval' => empty($_REQUEST['subfilter_interval']) || uint_in_array($item['delay'], $_REQUEST['subfilter_interval']), 'subfilter_apps' => empty($_REQUEST['subfilter_apps']));
     if (!empty($_REQUEST['subfilter_apps'])) {
         foreach ($item['applications'] as $application) {
             if (str_in_array($application['name'], $_REQUEST['subfilter_apps'])) {
                 $item['subfilters']['subfilter_apps'] = true;
                 break;
             }
         }
     }
     if (!empty($item['applications'])) {
         order_result($item['applications'], 'name');
         $applications = array();
         foreach ($item['applications'] as $application) {
             $applications[] = $application['name'];
         }
         $item['applications_list'] = implode(', ', $applications);
Ejemplo n.º 25
0
function delete_template_applications($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $db_apps = get_applications_by_hostid($hostid);
    while ($db_app = DBfetch($db_apps)) {
        if ($db_app["templateid"] == 0) {
            continue;
        }
        if (!is_null($templateids)) {
            unset($skip);
            if ($tmp_app_data = get_application_by_applicationid($db_app["templateid"])) {
                if (!uint_in_array($tmp_app_data["hostid"], $templateids)) {
                    $skip = true;
                    break;
                }
            }
            if (isset($skip)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute("update applications set templateid=0 where applicationid=" . $db_app["applicationid"])) {
                info(S_APPLICATION . SPACE . "'" . $db_app["name"] . "'" . SPACE . S_UNLINKED_SMALL);
            }
        } else {
            delete_application($db_app["applicationid"]);
        }
    }
}
Ejemplo n.º 26
0
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;
}
Ejemplo n.º 27
0
function make_latest_data()
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    while ($db_app = DBfetch($db_applications)) {
        $db_items = DBselect('SELECT DISTINCT i.* ' . ' FROM items i,items_applications ia' . ' WHERE ia.applicationid=' . $db_app['applicationid'] . ' AND i.itemid=ia.itemid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . order_by('i.description,i.itemid,i.lastclock'));
        $app_rows = array();
        $item_cnt = 0;
        while ($db_item = DBfetch($db_items)) {
            $description = item_description($db_item);
            if (!zbx_empty($_REQUEST['select']) && !zbx_stristr($description, $_REQUEST['select'])) {
                continue;
            }
            ++$item_cnt;
            if (!uint_in_array($db_app['applicationid'], $_REQUEST['applications']) && !isset($show_all_apps)) {
                continue;
            }
            if (isset($db_item['lastclock'])) {
                $lastclock = date(S_DATE_FORMAT_YMDHMS, $db_item['lastclock']);
            } else {
                $lastclock = new CCol('-', 'center');
            }
            $lastvalue = format_lastvalue($db_item);
            if (isset($db_item['lastvalue']) && isset($db_item['prevvalue']) && $db_item['value_type'] == 0 && $db_item['lastvalue'] - $db_item['prevvalue'] != 0) {
                if ($db_item['lastvalue'] - $db_item['prevvalue'] < 0) {
                    $change = convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
                } else {
                    $change = '+' . convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
                }
                $change = nbsp($change);
            } else {
                $change = new CCol('-', 'center');
            }
            if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
                $actions = new CLink(S_GRAPH, 'history.php?action=showgraph&itemid=' . $db_item['itemid'], 'action');
            } else {
                $actions = new CLink(S_HISTORY, 'history.php?action=showvalues&period=3600&itemid=' . $db_item['itemid'], 'action');
            }
            array_push($app_rows, new CRow(array(is_show_all_nodes() ? SPACE : null, $_REQUEST['hostid'] > 0 ? NULL : SPACE, str_repeat(SPACE, 6) . $description, $lastclock, new CCol($lastvalue, $lastvalue == '-' ? 'center' : null), $change, $actions)));
        }
        if ($item_cnt > 0) {
            if (uint_in_array($db_app['applicationid'], $_REQUEST['applications']) || isset($show_all_apps)) {
                $link = new CLink(new CImg('images/general/opened.gif'), '?close=1&applicationid=' . $db_app['applicationid'] . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select'));
            } else {
                $link = new CLink(new CImg('images/general/closed.gif'), '?open=1&applicationid=' . $db_app['applicationid'] . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select'));
            }
            $col = new CCol(array($link, SPACE, bold($db_app['name']), SPACE . '(' . $item_cnt . SPACE . S_ITEMS . ')'));
            $col->setColSpan(5);
            $table->ShowRow(array(get_node_name_by_elid($db_app['hostid']), $_REQUEST['hostid'] > 0 ? NULL : $db_app['host'], $col));
            $any_app_exist = true;
            foreach ($app_rows as $row) {
                $table->ShowRow($row);
            }
        }
    }
}
Ejemplo n.º 28
0
function validate_operation($operation)
{
    global $USER_DETAILS;
    switch ($operation['operationtype']) {
        case OPERATION_TYPE_MESSAGE:
            switch ($operation['object']) {
                case OPERATION_OBJECT_USER:
                    if (!get_user_by_userid($operation['objectid'])) {
                        error(S_INCORRECT_USER);
                        return false;
                    }
                    break;
                case OPERATION_OBJECT_GROUP:
                    if (!get_group_by_usrgrpid($operation['objectid'])) {
                        error(S_INCORRECT_GROUP);
                        return false;
                    }
                    break;
                default:
                    error(S_INCORRECT_OBJECT_TYPE);
                    return false;
            }
            break;
        case OPERATION_TYPE_COMMAND:
            return validate_commands($operation['longdata']);
        case OPERATION_TYPE_HOST_ADD:
        case OPERATION_TYPE_HOST_REMOVE:
            break;
        case OPERATION_TYPE_GROUP_ADD:
        case OPERATION_TYPE_GROUP_REMOVE:
            if (!uint_in_array($operation['objectid'], get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
                error(S_INCORRECT_GROUP);
                return false;
            }
            break;
        case OPERATION_TYPE_TEMPLATE_ADD:
        case OPERATION_TYPE_TEMPLATE_REMOVE:
            if (!uint_in_array($operation['objectid'], get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
                error(S_INCORRECT_HOST);
                return false;
            }
            break;
        default:
            error(S_INCORRECT_OPERATION_TYPE);
            return false;
    }
    return true;
}
Ejemplo n.º 29
0
     }
 }
 // --- ---
 $jscript = 'javascript : ' . " var pos = getPosition('button_show_tree');" . " ShowHide('div_node_tree',IE6?'block':'table');" . ' pos.top += 20;' . " \$('div_node_tree').setStyle({top: pos.top+'px'});" . " showPopupDiv('div_node_tree','select_iframe');";
 // IE6
 $button_show_tree = new CButton('show_node_tree', S_SELECT_NODES, $jscript);
 //sdelatj konstatntu!
 $button_show_tree->setType('button');
 $button_show_tree->setAttribute('id', 'button_show_tree');
 // +++ Create node tree +++
 $combo_check_all = new CCheckbox('check_all_nodes', null, "javascript : check_all('node_form', this.checked);");
 $node_tree = array();
 $node_tree[0] = array('id' => 0, 'caption' => S_ALL_S, 'combo_select_node' => $combo_check_all, 'parentid' => 0);
 //root
 foreach ($available_nodes as $num => $node) {
     $checked = uint_in_array($node['nodeid'], $ZBX_VIEWED_NODES['nodeids']);
     $combo_select_node = new CCheckbox('selected_nodes[' . $node['nodeid'] . ']', $checked, null, $node['nodeid']);
     // If not exist parent for node, link it to root (0)
     if (!isset($available_nodes[$node['masterid']])) {
         $node['masterid'] = 0;
     }
     $node_tree[$node['nodeid']] = array('id' => $node['nodeid'], 'caption' => $node['name'], 'combo_select_node' => $combo_select_node, 'parentid' => $node['masterid']);
 }
 $node_tree_captions = array('caption' => bold(S_NODE), 'combo_select_node' => SPACE);
 $node_tree = new CTree('nodes', $node_tree, $node_tree_captions);
 // --- ---
 $div_node_tree = new CDiv();
 $div_node_tree->additem($node_tree->getHTML());
 $div_node_tree->additem(new CButton('select_nodes', S_SELECT, "javascript: " . " hidePopupDiv('select_iframe');" . " \$('div_node_tree').setStyle({display:'none'});"));
 $div_node_tree->setAttribute('id', 'div_node_tree');
 $div_node_tree->addStyle('display: none');
Ejemplo n.º 30
0
$page['file'] = 'scripts_exec.php';
define('ZBX_PAGE_NO_MENU', 1);
include_once "include/page_header.php";
//---------------------------------- CHECKS ------------------------------------
//		VAR							TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'scriptid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'execute' => array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null));
check_fields($fields);
if (isset($_REQUEST['execute'])) {
    if ($script = get_script_by_scriptid($_REQUEST['scriptid'])) {
        if ($script['host_access'] == PERM_READ_WRITE) {
            $hosts_read_write = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY);
            if (uint_in_array($_REQUEST['hostid'], $hosts_read_write)) {
                //SDI('WRITE: '.$_REQUEST['scriptid'].' : '.$_REQUEST['hostid']);
                //				$result = execute_script($_REQUEST['scriptid'],$_REQUEST['hostid']);
                //				insert_command_result_form($result["flag"],$result["message"]);
                insert_command_result_form($_REQUEST['scriptid'], $_REQUEST['hostid']);
                /*				echo nl2br(htmlspecialchars($result));*/
            }
        } else {
            $hosts_read_only = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
            if (uint_in_array($_REQUEST['hostid'], $hosts_read_only)) {
                //SDI('READ: '.$_REQUEST['scriptid'].' : '.$_REQUEST['hostid']);
                //				$result = execute_script($_REQUEST['scriptid'],$_REQUEST['hostid']);
                //				insert_command_result_form($result["flag"],$result["message"]);
                insert_command_result_form($_REQUEST['scriptid'], $_REQUEST['hostid']);
                /*				echo nl2br(htmlspecialchars($result));*/
            }
        }
    }
}
include_once "include/page_footer.php";