コード例 #1
0
ファイル: class.curl.php プロジェクト: SandipSingh14/Zabbix_
 public function __construct($url = null)
 {
     if (empty($url)) {
         $this->formatGetArguments();
         $this->url = basename($_SERVER['SCRIPT_NAME']);
     } else {
         $this->url = $url;
         // parse reference
         $tmp_pos = zbx_strpos($this->url, '#');
         if ($tmp_pos !== false) {
             $this->reference = zbx_substring($this->url, $tmp_pos + 1);
             $this->url = zbx_substring($this->url, 0, $tmp_pos);
         }
         $tmp_pos = zbx_strpos($url, '?');
         // parse query
         if ($tmp_pos !== false) {
             $this->query = zbx_substring($url, $tmp_pos + 1);
             $this->url = $url = zbx_substring($url, 0, $tmp_pos);
         }
         $this->formatArguments();
     }
     if (isset($_COOKIE['zbx_sessionid'])) {
         $this->setArgument('sid', substr($_COOKIE['zbx_sessionid'], 16, 16));
     }
 }
コード例 #2
0
 /**
  * Retrieve the HTTP request headers from the $_SERVER superglobal
  * @param Array Additional Headers to retrieve
  */
 public function retrieve_headers($add_headers = false)
 {
     if ($add_headers) {
         $this->add_headers = array_merge($this->add_headers, $add_headers);
     }
     if (isset($_SERVER['HTTP_METHOD'])) {
         $this->method = $_SERVER['HTTP_METHOD'];
         unset($_SERVER['HTTP_METHOD']);
     } else {
         $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
     }
     $this->protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false;
     $this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
     $this->headers = array();
     foreach ($_SERVER as $i => $val) {
         if (zbx_strpos($i, 'HTTP_') === 0 || in_array($i, $this->add_headers)) {
             $name = str_replace(array('HTTP_', '_'), array('', '-'), $i);
             $this->headers[$name] = $val;
         }
     }
 }
コード例 #3
0
/**
 * Resolve macros in item key.
 * Resolve {HOSTNAME}, {IPADDRESS}, {HOST.IP}, {HOST.DNS}, {HOST.CONN}, {HOST.HOST}, {HOST.NAME} and user macros.
 * Macros related to interface resolved only for host items.
 *
 * @param array $item
 * @param string $item['key_']
 * @param string $item['itemid']
 *
 * @return string
 */
function resolveItemKeyMacros(array $item)
{
    $key =& $item['key_'];
    $macStack = array();
    $macros = array('{HOSTNAME}', '{IPADDRESS}', '{HOST.IP}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.HOST}', '{HOST.NAME}');
    foreach ($macros as $macro) {
        if (zbx_strpos($key, $macro) !== false) {
            $macStack[] = $macro;
        }
    }
    if (!empty($macStack)) {
        $dbItem = API::Item()->get(array('itemids' => $item['itemid'], 'selectInterfaces' => array('ip', 'dns', 'useip'), 'selectHosts' => array('host', 'name'), 'output' => API_OUTPUT_REFER, 'filter' => array('flags' => null)));
        if (!empty($dbItem)) {
            $dbItem = reset($dbItem);
            $host = reset($dbItem['hosts']);
            $interface = reset($dbItem['interfaces']);
            // if item without interface or template item, resolve interface related macros to *UNKNOWN*
            if (!$interface) {
                $interface = array('ip' => UNRESOLVED_MACRO_STRING, 'dns' => UNRESOLVED_MACRO_STRING, 'useip' => false);
            }
            foreach ($macStack as $macro) {
                switch ($macro) {
                    case '{HOST.NAME}':
                        $key = str_replace('{HOST.NAME}', $host['name'], $key);
                        break;
                    case '{HOSTNAME}':
                        // deprecated
                        $key = str_replace('{HOSTNAME}', $host['host'], $key);
                        break;
                    case '{HOST.HOST}':
                        $key = str_replace('{HOST.HOST}', $host['host'], $key);
                        break;
                    case '{HOST.IP}':
                        $key = str_replace('{HOST.IP}', $interface['ip'], $key);
                        break;
                    case '{IPADDRESS}':
                        // deprecated
                        $key = str_replace('{IPADDRESS}', $interface['ip'], $key);
                        break;
                    case '{HOST.DNS}':
                        $key = str_replace('{HOST.DNS}', $interface['dns'], $key);
                        break;
                    case '{HOST.CONN}':
                        $key = str_replace('{HOST.CONN}', $interface['useip'] ? $interface['ip'] : $interface['dns'], $key);
                        break;
                }
            }
        }
    }
    if (preg_match('/' . ZBX_PREG_EXPRESSION_USER_MACROS . '/', $key)) {
        $item = API::UserMacro()->resolveItem($item);
    }
    return $item['key_'];
}
コード例 #4
0
 public static function ldapLogin($user)
 {
     $name = $user['user'];
     $passwd = $user['password'];
     $cnf = isset($user['cnf']) ? $user['cnf'] : null;
     if (is_null($cnf)) {
         $config = select_config();
         foreach ($config as $id => $value) {
             if (zbx_strpos($id, 'ldap_') !== false) {
                 $cnf[str_replace('ldap_', '', $id)] = $config[$id];
             }
         }
     }
     if (!function_exists('ldap_connect')) {
         info(S_CUSER_ERROR_LDAP_MODULE_MISSING);
         return false;
     }
     $ldap = new CLdap($cnf);
     $ldap->connect();
     $result = $ldap->checkPass($name, $passwd);
     return $result;
 }
コード例 #5
0
ファイル: maps.inc.php プロジェクト: SandipSingh14/Zabbix_
/**
 * Resolve all kinds of macros in map labels
 *
 * @param array $selement
 * @param string $selement['label'] label to expand
 * @param int $selement['elementtype'] type of element: trigger, host, ...
 * @param int $selement['elementid'] element id in DB
 * @param string $selement['elementExpressionTrigger'] if type is trigger, then trigger expression
 *
 * @return string expanded label
 */
function resolveMapLabelMacrosAll(array $selement)
{
    $label = $selement['label'];
    // for host and trigger items expand macros if they exists
    if (($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST || $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) && (zbx_strpos($label, 'HOST.NAME') !== false || zbx_strpos($label, 'HOSTNAME') !== false || zbx_strpos($label, 'HOST.HOST') !== false || zbx_strpos($label, 'HOST.DNS') !== false || zbx_strpos($label, 'HOST.IP') !== false || zbx_strpos($label, 'IPADDRESS') !== false || zbx_strpos($label, 'HOST.CONN') !== false)) {
        // priorities of interface types doesn't match interface type ids in DB
        $priorities = array(INTERFACE_TYPE_AGENT => 4, INTERFACE_TYPE_SNMP => 3, INTERFACE_TYPE_JMX => 2, INTERFACE_TYPE_IPMI => 1);
        // get host data if element is host
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) {
            $res = DBselect('SELECT hi.ip,hi.dns,hi.useip,h.host,h.name,hi.type AS interfacetype' . ' FROM interface hi,hosts h' . ' WHERE hi.hostid=h.hostid' . ' AND hi.main=1 AND hi.hostid=' . zbx_dbstr($selement['elementid']));
            // process interface priorities
            $tmpPriority = 0;
            while ($dbHost = DBfetch($res)) {
                if ($priorities[$dbHost['interfacetype']] > $tmpPriority) {
                    $resHost = $dbHost;
                    $tmpPriority = $priorities[$dbHost['interfacetype']];
                }
            }
            $hostsByNr[''] = $resHost;
        } else {
            $res = DBselect('SELECT hi.ip,hi.dns,hi.useip,h.host,h.name,f.functionid,hi.type AS interfacetype' . ' FROM interface hi,items i,functions f,hosts h' . ' WHERE h.hostid=hi.hostid' . ' AND hi.hostid=i.hostid' . ' AND i.itemid=f.itemid' . ' AND hi.main=1 AND f.triggerid=' . zbx_dbstr($selement['elementid']) . ' ORDER BY f.functionid');
            // process interface priorities, build $hostsByFunctionId array
            $tmpFunctionId = -1;
            while ($dbHost = DBfetch($res)) {
                if ($dbHost['functionid'] != $tmpFunctionId) {
                    $tmpPriority = 0;
                    $tmpFunctionId = $dbHost['functionid'];
                }
                if ($priorities[$dbHost['interfacetype']] > $tmpPriority) {
                    $hostsByFunctionId[$dbHost['functionid']] = $dbHost;
                    $tmpPriority = $priorities[$dbHost['interfacetype']];
                }
            }
            // get all function ids from expression and link host data against position in expression
            preg_match_all('/\\{([0-9]+)\\}/', $selement['elementExpressionTrigger'], $matches);
            $hostsByNr = array();
            foreach ($matches[1] as $i => $functionid) {
                if (isset($hostsByFunctionId[$functionid])) {
                    $hostsByNr[$i + 1] = $hostsByFunctionId[$functionid];
                }
            }
            // for macro without numeric index
            if (isset($hostsByNr[1])) {
                $hostsByNr[''] = $hostsByNr[1];
            }
        }
        // resolve functional macros like: {{HOST.HOST}:log[{HOST.HOST}.log].last(0)}
        $label = resolveMapLabelMacros($label, $hostsByNr);
        // resolves basic macros
        // $hostsByNr possible keys: '' and 1-9
        foreach ($hostsByNr as $i => $host) {
            $replace = array('{HOST.NAME' . $i . '}' => $host['name'], '{HOSTNAME' . $i . '}' => $host['name'], '{HOST.HOST' . $i . '}' => $host['host'], '{HOST.DNS' . $i . '}' => $host['dns'], '{HOST.IP' . $i . '}' => $host['ip'], '{IPADDRESS' . $i . '}' => $host['ip'], '{HOST.CONN' . $i . '}' => $host['useip'] ? $host['ip'] : $host['dns']);
            $label = str_replace(array_keys($replace), $replace, $label);
        }
    } else {
        // resolve functional macros like: {sampleHostName:log[{HOST.HOST}.log].last(0)}, if no host provided
        $label = resolveMapLabelMacros($label);
    }
    // resolve map specific processing consuming macros
    switch ($selement['elementtype']) {
        case SYSMAP_ELEMENT_TYPE_HOST:
        case SYSMAP_ELEMENT_TYPE_MAP:
        case SYSMAP_ELEMENT_TYPE_TRIGGER:
        case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
            if (zbx_strpos($label, '{TRIGGERS.UNACK}') !== false) {
                $label = str_replace('{TRIGGERS.UNACK}', get_triggers_unacknowledged($selement), $label);
            }
            if (zbx_strpos($label, '{TRIGGERS.PROBLEM.UNACK}') !== false) {
                $label = str_replace('{TRIGGERS.PROBLEM.UNACK}', get_triggers_unacknowledged($selement, true), $label);
            }
            if (zbx_strpos($label, '{TRIGGER.EVENTS.UNACK}') !== false) {
                $label = str_replace('{TRIGGER.EVENTS.UNACK}', get_events_unacknowledged($selement), $label);
            }
            if (zbx_strpos($label, '{TRIGGER.EVENTS.PROBLEM.UNACK}') !== false) {
                $label = str_replace('{TRIGGER.EVENTS.PROBLEM.UNACK}', get_events_unacknowledged($selement, null, TRIGGER_VALUE_TRUE), $label);
            }
            if (zbx_strpos($label, '{TRIGGER.PROBLEM.EVENTS.PROBLEM.UNACK}') !== false) {
                $label = str_replace('{TRIGGER.PROBLEM.EVENTS.PROBLEM.UNACK}', get_events_unacknowledged($selement, TRIGGER_VALUE_TRUE, TRIGGER_VALUE_TRUE), $label);
            }
            if (zbx_strpos($label, '{TRIGGERS.ACK}') !== false) {
                $label = str_replace('{TRIGGERS.ACK}', get_triggers_unacknowledged($selement, null, true), $label);
            }
            if (zbx_strpos($label, '{TRIGGERS.PROBLEM.ACK}') !== false) {
                $label = str_replace('{TRIGGERS.PROBLEM.ACK}', get_triggers_unacknowledged($selement, true, true), $label);
            }
            if (zbx_strpos($label, '{TRIGGER.EVENTS.ACK}') !== false) {
                $label = str_replace('{TRIGGER.EVENTS.ACK}', get_events_unacknowledged($selement, null, null, true), $label);
            }
            if (zbx_strpos($label, '{TRIGGER.EVENTS.PROBLEM.ACK}') !== false) {
                $label = str_replace('{TRIGGER.EVENTS.PROBLEM.ACK}', get_events_unacknowledged($selement, null, TRIGGER_VALUE_TRUE, true), $label);
            }
            if (zbx_strpos($label, '{TRIGGER.PROBLEM.EVENTS.PROBLEM.ACK}') !== false) {
                $label = str_replace('{TRIGGER.PROBLEM.EVENTS.PROBLEM.ACK}', get_events_unacknowledged($selement, TRIGGER_VALUE_TRUE, TRIGGER_VALUE_TRUE, true), $label);
            }
            break;
    }
    return $label;
}
コード例 #6
0
ファイル: class.cldap.php プロジェクト: SandipSingh14/Zabbix_
 public function checkPass($user, $pass)
 {
     // reject empty password
     if (empty($pass)) {
         return false;
     }
     if (!$this->connect()) {
         return false;
     }
     // indirect user bind
     if (!empty($this->cnf['bind_dn']) && !empty($this->cnf['bind_password'])) {
         // use superuser credentials
         if (!ldap_bind($this->ds, $this->cnf['bind_dn'], $this->cnf['bind_password'])) {
             error('LDAP: cannot bind by given Bind DN.');
             return false;
         }
         $this->bound = 2;
     } elseif (!empty($this->cnf['bind_dn']) && !empty($this->cnf['base_dn']) && !empty($this->cnf['userfilter'])) {
         // special bind string
         $dn = $this->makeFilter($this->cnf['bind_dn'], array('user' => $user, 'host' => $this->cnf['host']));
     } elseif (zbx_strpos($this->cnf['base_dn'], '%{user}')) {
         // direct user bind
         $dn = $this->makeFilter($this->cnf['base_dn'], array('user' => $user, 'host' => $this->cnf['host']));
     } else {
         // anonymous bind
         if (!ldap_bind($this->ds)) {
             error('LDAP: can not bind anonymously.');
             return false;
         }
     }
     // try to bind to with the dn if we have one.
     if (!empty($dn)) {
         // user/password bind
         if (!ldap_bind($this->ds, $dn, $pass)) {
             return false;
         }
         $this->bound = 1;
         return true;
     } else {
         // see if we can find the user
         $this->info = $this->getUserData($user);
         if (empty($this->info['dn'])) {
             return false;
         } else {
             $dn = $this->info['dn'];
         }
         // try to bind with the dn provided
         if (!ldap_bind($this->ds, $dn, $pass)) {
             return false;
         }
         $this->bound = 1;
         return true;
     }
     return false;
 }
コード例 #7
0
function expand_item_key_by_data($item)
{
    $key =& $item['key_'];
    $macStack = array();
    $macroses = array('{HOSTNAME}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}');
    foreach ($macroses as $macro) {
        $pos = 0;
        while ($pos = zbx_strpos($key, $macro, $pos)) {
            $pos++;
            $macStack[] = $macro;
        }
    }
    if (!empty($macStack)) {
        $host = get_host_by_itemid($item['itemid']);
        foreach ($macStack as $macro) {
            switch ($macro) {
                case '{HOSTNAME}':
                    $key = str_replace('{HOSTNAME}', $host['host'], $key);
                    break;
                case '{IPADDRESS}':
                    $key = str_replace('{IPADDRESS}', $host['ip'], $key);
                    break;
                case '{HOST.DNS}':
                    $key = str_replace('{HOST.DNS}', $host['dns'], $key);
                    break;
                case '{HOST.CONN}':
                    $key = str_replace('{HOST.CONN}', $host['useip'] ? $host['ip'] : $host['dns'], $key);
                    break;
            }
        }
    }
    CUserMacro::resolveItem($item);
    return $item['key_'];
}
コード例 #8
0
    }
}
$itemFormList->addRow(_('Flexible intervals'), new CDiv($delayFlexTable, 'objectgroup inlineblock border_dotted ui-corner-all'), false, 'row_flex_intervals');
// append new flexible interval to form list
$newFlexInt = new CSpan(array(_('Interval (in sec)'), SPACE, new CNumericBox('new_delay_flex[delay]', $this->data['new_delay_flex']['delay'], 5, 'no', false, false), SPACE, _('Period'), SPACE, new CTextBox('new_delay_flex[period]', $this->data['new_delay_flex']['period'], 20), SPACE, new CButton('add_delay_flex', _('Add'), null, 'formlist')));
$newFlexInt->setAttribute('id', 'row-new-delay-flex-fields');
$maxFlexMsg = new CSpan(_('Maximum number of flexible intervals added'), 'red');
$maxFlexMsg->setAttribute('id', 'row-new-delay-flex-max-reached');
$maxFlexMsg->setAttribute('style', 'display: none;');
$itemFormList->addRow(_('New flexible interval'), array($newFlexInt, $maxFlexMsg), false, 'row_new_delay_flex', 'new');
if ($this->data['is_discovery_rule']) {
    $itemFormList->addRow(_('Keep lost resources period (in days)'), new CTextBox('lifetime', $this->data['lifetime'], ZBX_TEXTBOX_SMALL_SIZE, false, 64));
    // append filter to formlist
    if (!empty($this->data['filter'])) {
        // exploding filter to two parts: before first ':' and after
        $pos = zbx_strpos($this->data['filter'], ':');
        $filter_macro = zbx_substr($this->data['filter'], 0, $pos);
        $filter_value = zbx_substr($this->data['filter'], $pos + 1);
    } else {
        $filter_macro = '';
        $filter_value = '';
    }
    $itemFormList->addRow(_('Filter'), array(_('Macro'), SPACE, new CTextBox('filter_macro', $filter_macro, 13), SPACE, _('Regexp'), SPACE, new CTextBox('filter_value', $filter_value, 20)));
    $itemFormList->addRow(_('Allowed hosts'), new CTextBox('trapper_hosts', $this->data['trapper_hosts'], ZBX_TEXTBOX_STANDARD_SIZE), false, 'row_trapper_hosts');
} else {
    $dataConfig = select_config();
    $keepHistory = array();
    $keepHistory[] = new CNumericBox('history', $this->data['history'], 8);
    if ($dataConfig['hk_history_global'] && !$data['parent_discoveryid'] && !$data['is_template']) {
        $keepHistory[] = SPACE;
        if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) {
コード例 #9
0
function validate_ip_range($str)
{
    foreach (explode(',', $str) as $ip_range) {
        if (zbx_strpos($ip_range, '/') !== false) {
            if (!validate_ip_range_mask($ip_range)) {
                return false;
            }
        } else {
            if (!validate_ip_range_range($ip_range)) {
                return false;
            }
        }
    }
    return true;
}
コード例 #10
0
ファイル: tr_logform.php プロジェクト: itnihao/zatree-2.2
     $expr_v = preg_replace('/\\(\\(\\((.+?)\\)\\)$/i', '(($1)', $expr_v);
     $expression = splitByFirstLevel($expression);
     $expr_v = splitByFirstLevel($expr_v);
     foreach ($expression as $id => $expr) {
         $expr = preg_replace('/^\\((.*)\\)$/u', '$1', $expr);
         $value = preg_replace('/([=|#]0)/', '', $expr);
         $value = preg_replace('/^\\((.*)\\)$/u', '$1', $value);
         // removing wrapping parentheses
         $expressions[$id]['value'] = trim($value);
         $expressions[$id]['type'] = zbx_strpos($expr, '#0', zbx_strlen($expr) - 3) === false ? REGEXP_EXCLUDE : REGEXP_INCLUDE;
     }
     foreach ($expr_v as $id => $expr) {
         $expr = preg_replace('/^\\((.*)\\)$/u', '$1', $expr);
         $value = preg_replace('/\\((.*)\\)[=|#]0/U', '$1', $expr);
         $value = preg_replace('/^\\((.*)\\)$/u', '$1', $value);
         if (zbx_strpos($expr, '#0', zbx_strlen($expr) - 3) === false) {
             //REGEXP_EXCLUDE
             $value = str_replace('&', ' OR ', $value);
             $value = str_replace('|', ' AND ', $value);
         } else {
             //EGEXP_INCLUDE
             $value = str_replace('&', ' AND ', $value);
             $value = str_replace('|', ' OR ', $value);
         }
         $value = preg_replace($functionid, $functions, $value);
         $value = preg_replace('/([=|#]0)/', '', $value);
         $expressions[$id]['view'] = trim($value);
     }
 } else {
     $description = get_request('description', '');
     $expressions = get_request('expressions', array());
コード例 #11
0
ファイル: CUser.php プロジェクト: itnihao/zatree-2.2
 /**
  * Authenticate a user using LDAP.
  *
  * The $user array must have the following attributes:
  * - user       - user name
  * - password   - user password
  *
  * @param array $user
  *
  * @return bool
  */
 protected function ldapLogin(array $user)
 {
     $config = select_config();
     $cnf = array();
     foreach ($config as $id => $value) {
         if (zbx_strpos($id, 'ldap_') !== false) {
             $cnf[str_replace('ldap_', '', $id)] = $config[$id];
         }
     }
     if (!function_exists('ldap_connect')) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Probably php-ldap module is missing.'));
     }
     $ldapValidator = new CLdapAuthValidator(array('conf' => $cnf));
     if ($ldapValidator->validate($user)) {
         return true;
     } else {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Login name or password is incorrect.'));
     }
 }
コード例 #12
0
ファイル: maps.inc.php プロジェクト: songyuanjie/zabbix-stats
function resolveMapLabelMacros($label, $replaceHost = null)
{
    if (null === $replaceHost) {
        $pattern = "/{" . ZBX_PREG_HOST_FORMAT . ":.+\\.(last|max|min|avg)\\([0-9]+\\)}/Uu";
    } else {
        $pattern = "/{(" . ZBX_PREG_HOST_FORMAT . "|{HOSTNAME}):.+\\.(last|max|min|avg)\\([0-9]+\\)}/Uu";
    }
    preg_match_all($pattern, $label, $matches);
    foreach ($matches[0] as $expr) {
        $macro = $expr;
        if ($replaceHost !== null && zbx_strpos($macro, '{HOSTNAME}') == 1) {
            $macro = substr_replace($macro, $replaceHost, 1, 10);
        }
        $trigExpr = new CTriggerExpression(array('expression' => $macro));
        if (!empty($trigExpr->errors)) {
            continue;
        }
        $itemHost = reset($trigExpr->data['hosts']);
        $key = reset($trigExpr->data['items']);
        $function = reset($trigExpr->data['functions']);
        $parameter = reset($trigExpr->data['functionParams']);
        $item = CItem::get(array('filter' => array('host' => $itemHost, 'key_' => $key), 'output' => API_OUTPUT_EXTEND));
        $item = reset($item);
        if (!$item) {
            $label = str_replace($expr, '???', $label);
            continue;
        }
        switch ($item['value_type']) {
            case ITEM_VALUE_TYPE_FLOAT:
                $history_table = 'history';
                break;
            case ITEM_VALUE_TYPE_UINT64:
                $history_table = 'history_uint';
                break;
            case ITEM_VALUE_TYPE_TEXT:
                $history_table = 'history_text';
                break;
            case ITEM_VALUE_TYPE_LOG:
                $history_table = 'history_log';
                break;
            case ITEM_VALUE_TYPE_STR:
                $history_table = 'history_str';
                break;
            default:
                $history_table = 'history_str';
        }
        if (0 == strcmp($function, 'last')) {
            if (null === $item['lastvalue']) {
                $label = str_replace($expr, '(' . S_NO_DATA_SMALL . ')', $label);
            } else {
                switch ($item['value_type']) {
                    case ITEM_VALUE_TYPE_FLOAT:
                    case ITEM_VALUE_TYPE_UINT64:
                        $value = convert_units($item['lastvalue'], $item['units']);
                        break;
                    default:
                        $value = $item['lastvalue'];
                }
                $label = str_replace($expr, $value, $label);
            }
        } else {
            if (0 == strcmp($function, 'min') || 0 == strcmp($function, 'max') || 0 == strcmp($function, 'avg')) {
                if ($item['value_type'] != ITEM_VALUE_TYPE_FLOAT && $item['value_type'] != ITEM_VALUE_TYPE_UINT64) {
                    $label = str_replace($expr, '???', $label);
                    continue;
                }
                $sql = 'SELECT ' . $function . '(value) as value ' . ' FROM ' . $history_table . ' WHERE clock>' . (time() - $parameter) . ' AND itemid=' . $item['itemid'];
                $result = DBselect($sql);
                if (null === ($row = DBfetch($result)) || null === $row['value']) {
                    $label = str_replace($expr, '(' . S_NO_DATA_SMALL . ')', $label);
                } else {
                    $label = str_replace($expr, convert_units($row['value'], $item['units']), $label);
                }
            }
        }
    }
    return $label;
}
コード例 #13
0
            if ($data['pageFilter']->groupid > 0) {
                $options['groupids'] = $data['pageFilter']->groupid;
            }
            $data['hosts'] = API::Host()->get($options);
            // copy some inventory fields to the uppers array level for sorting
            // and filter out hosts if we are using filter
            foreach ($data['hosts'] as $num => $host) {
                $data['hosts'][$num]['pr_name'] = $host['inventory']['name'];
                $data['hosts'][$num]['pr_type'] = $host['inventory']['type'];
                $data['hosts'][$num]['pr_os'] = $host['inventory']['os'];
                $data['hosts'][$num]['pr_serialno_a'] = $host['inventory']['serialno_a'];
                $data['hosts'][$num]['pr_tag'] = $host['inventory']['tag'];
                $data['hosts'][$num]['pr_macaddress_a'] = $host['inventory']['macaddress_a'];
                // if we are filtering by inventory field
                if (!empty($data['filterField']) && !empty($data['filterFieldValue'])) {
                    // must we filter exactly or using a substring (both are case insensitive)
                    $match = $data['filterExact'] ? zbx_strtolower($data['hosts'][$num]['inventory'][$data['filterField']]) === zbx_strtolower($data['filterFieldValue']) : zbx_strpos(zbx_strtolower($data['hosts'][$num]['inventory'][$data['filterField']]), zbx_strtolower($data['filterFieldValue'])) !== false;
                    if (!$match) {
                        unset($data['hosts'][$num]);
                    }
                }
            }
            order_result($data['hosts'], getPageSortField('name'), getPageSortOrder());
        }
    }
    $data['paging'] = getPagingLine($data['hosts']);
    $hostinventoriesView = new CView('inventory.host.list', $data);
    $hostinventoriesView->render();
    $hostinventoriesView->show();
}
require_once dirname(__FILE__) . '/include/page_footer.php';
コード例 #14
0
function hide_form_items(&$obj)
{
    if (is_array($obj)) {
        foreach ($obj as $id => $item) {
            hide_form_items($obj[$id]);
            // attention recursion
        }
    } elseif (is_object($obj)) {
        $formObjects = array('cform', 'ccheckbox', 'cselect', 'cbutton', 'csubmit', 'cbuttonqmessage', 'cbuttondelete', 'cbuttoncancel');
        if (is_object($obj) && str_in_array(zbx_strtolower(get_class($obj)), $formObjects)) {
            $obj = SPACE;
        }
        if (isset($obj->items) && !empty($obj->items)) {
            foreach ($obj->items as $id => $item) {
                hide_form_items($obj->items[$id]);
                // attention recursion
            }
        }
    } else {
        foreach (array('<form', '<input', '<select') as $item) {
            if (zbx_strpos($obj, $item) !== false) {
                $obj = SPACE;
            }
        }
    }
}
コード例 #15
0
ファイル: popup.php プロジェクト: itnihao/zatree-2.2
        $itemtype = get_request('itemtype', 0);
        $cmbTypes = new CComboBox('itemtype', $itemtype, 'javascript: submit();');
        foreach ($allowed_item_types as $type) {
            $cmbTypes->addItem($type, item_type2str($type));
        }
        $frmTitle->addItem(array(_('Type'), SPACE, $cmbTypes));
    }
    if (str_in_array($srctbl, array('triggers', 'items', 'applications', 'graphs'))) {
        $frmTitle->addItem(array(SPACE, _('Host'), SPACE, $pageFilter->getHostsCB()));
    }
}
if (str_in_array($srctbl, array('applications', 'triggers'))) {
    if (zbx_empty($noempty)) {
        $value1 = isset($_REQUEST['dstfld1']) && zbx_strpos($_REQUEST['dstfld1'], 'id') !== false ? 0 : '';
        $value2 = isset($_REQUEST['dstfld2']) && zbx_strpos($_REQUEST['dstfld2'], 'id') !== false ? 0 : '';
        $value3 = isset($_REQUEST['dstfld3']) && zbx_strpos($_REQUEST['dstfld3'], 'id') !== false ? 0 : '';
        $epmtyScript = get_window_opener($dstfrm, $dstfld1, $value1);
        $epmtyScript .= get_window_opener($dstfrm, $dstfld2, $value2);
        $epmtyScript .= get_window_opener($dstfrm, $dstfld3, $value3);
        $epmtyScript .= ' close_window(); return false;';
        $frmTitle->addItem(array(SPACE, new CButton('empty', _('Empty'), $epmtyScript)));
    }
}
show_table_header($page['title'], $frmTitle);
insert_js_function('addSelectedValues');
insert_js_function('addValues');
insert_js_function('addValue');
/*
 * User group
 */
if ($srctbl == 'usrgrp') {
コード例 #16
0
ファイル: func.inc.php プロジェクト: itnihao/Zabbix_
function str_replace_first($search, $replace, $subject)
{
    $pos = zbx_strpos($subject, $search);
    if ($pos !== false) {
        $subject = zbx_substr_replace($subject, $replace, $pos, zbx_strlen($search));
    }
    return $subject;
}
コード例 #17
0
 public function __construct($url = null)
 {
     $this->url = null;
     $this->port = null;
     $this->host = null;
     $this->protocol = null;
     $this->username = null;
     $this->password = null;
     $this->file = null;
     $this->reference = null;
     $this->path = null;
     $this->query = null;
     $this->arguments = array();
     if (empty($url)) {
         $this->formatGetArguments();
         // $protocol = (zbx_strpos(zbx_strtolower($_SERVER['SERVER_PROTOCOL']), 'shttp') !== false)?'shttp':'http';
         $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http';
         $this->url = $url = $protocol . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['SCRIPT_NAME'] . '?' . $this->getQuery();
     } else {
         $this->url = $url;
         $tmp_pos = zbx_strpos($this->url, '?');
         $this->query = $tmp_pos !== false ? substr($this->url, $tmp_pos + 1) : '';
         $tmp_pos = zbx_strpos($this->query, '#');
         if ($tmp_pos !== false) {
             $this->query = zbx_substring($this->query, 0, $tmp_pos);
         }
         $this->formatArguments($this->query);
     }
     $protocolSepIndex = zbx_strpos($this->url, '://');
     if ($protocolSepIndex !== false) {
         $this->protocol = zbx_strtolower(zbx_substring($this->url, 0, $protocolSepIndex));
         $this->host = substr($this->url, $protocolSepIndex + 3);
         $tmp_pos = zbx_strpos($this->host, '/');
         if ($tmp_pos !== false) {
             $this->host = zbx_substring($this->host, 0, $tmp_pos);
         }
         $atIndex = zbx_strpos($this->host, '@');
         if ($atIndex !== false) {
             $credentials = zbx_substring($this->host, 0, $atIndex);
             $colonIndex = zbx_strpos(credentials, ':');
             if ($colonIndex !== false) {
                 $this->username = zbx_substring($credentials, 0, $colonIndex);
                 $this->password = substr($credentials, $colonIndex);
             } else {
                 $this->username = $credentials;
             }
             $this->host = substr($this->host, $atIndex + 1);
         }
         $host_ipv6 = zbx_strpos($this->host, ']');
         if ($host_ipv6 !== false) {
             if ($host_ipv6 < zbx_strlen($this->host) - 1) {
                 $host_ipv6++;
                 $host_less = substr($this->host, $host_ipv6);
                 $portColonIndex = zbx_strpos($host_less, ':');
                 if ($portColonIndex !== false) {
                     $this->host = zbx_substring($this->host, 0, $host_ipv6);
                     $this->port = substr($host_less, $portColonIndex + 1);
                 }
             }
         } else {
             $portColonIndex = zbx_strpos($this->host, ':');
             if ($portColonIndex !== false) {
                 $this->port = substr($this->host, $portColonIndex + 1);
                 $this->host = zbx_substring($this->host, 0, $portColonIndex);
             }
         }
         $this->file = substr($this->url, $protocolSepIndex + 3);
         $this->file = substr($this->file, zbx_strpos($this->file, '/'));
         if ($this->file == $this->host) {
             $this->file = '';
         }
     } else {
         $this->file = $this->url;
     }
     $tmp_pos = zbx_strpos($this->file, '?');
     if ($tmp_pos !== false) {
         $this->file = zbx_substring($this->file, 0, $tmp_pos);
     }
     $refSepIndex = zbx_strpos($url, '#');
     if ($refSepIndex !== false) {
         $this->file = zbx_substring($this->file, 0, $refSepIndex);
         $this->reference = substr($url, zbx_strpos($url, '#') + 1);
     }
     $this->path = $this->file;
     if (zbx_strlen($this->query) > 0) {
         $this->file .= '?' . $this->query;
     }
     if (zbx_strlen($this->reference) > 0) {
         $this->file .= '#' . $this->reference;
     }
     if (isset($_COOKIE['zbx_sessionid'])) {
         $this->setArgument('sid', substr($_COOKIE['zbx_sessionid'], 16, 16));
     }
 }
コード例 #18
0
     $options['groupids'] = $pageFilter->groupid;
 }
 $hosts = API::Host()->get($options);
 // copy some inventory fields to the uppers array level for sorting
 // and filter out hosts if we are using filter
 foreach ($hosts as $num => $host) {
     $hosts[$num]['pr_name'] = $host['inventory']['name'];
     $hosts[$num]['pr_type'] = $host['inventory']['type'];
     $hosts[$num]['pr_os'] = $host['inventory']['os'];
     $hosts[$num]['pr_serialno_a'] = $host['inventory']['serialno_a'];
     $hosts[$num]['pr_tag'] = $host['inventory']['tag'];
     $hosts[$num]['pr_macaddress_a'] = $host['inventory']['macaddress_a'];
     // if we are filtering by inventory field
     if (!empty($_REQUEST['filter_field']) && !empty($_REQUEST['filter_field_value'])) {
         // must we filter exactly or using a substring (both are case insensitive)
         $match = $_REQUEST['filter_exact'] ? zbx_strtolower($hosts[$num]['inventory'][$_REQUEST['filter_field']]) === zbx_strtolower($_REQUEST['filter_field_value']) : zbx_strpos(zbx_strtolower($hosts[$num]['inventory'][$_REQUEST['filter_field']]), zbx_strtolower($_REQUEST['filter_field_value'])) !== false;
         if (!$match) {
             unset($hosts[$num]);
         }
     }
 }
 order_result($hosts, getPageSortField('name'), getPageSortOrder());
 $paging = getPagingLine($hosts);
 foreach ($hosts as $host) {
     $host_groups = array();
     foreach ($host['groups'] as $group) {
         $host_groups[] = $group['name'];
     }
     natsort($host_groups);
     $host_groups = implode(', ', $host_groups);
     $row = array(get_node_name_by_elid($host['hostid']), new CLink($host['name'], '?hostid=' . $host['hostid'] . url_param('groupid')), $host_groups, zbx_str2links($host['inventory']['name']), zbx_str2links($host['inventory']['type']), zbx_str2links($host['inventory']['os']), zbx_str2links($host['inventory']['serialno_a']), zbx_str2links($host['inventory']['tag']), zbx_str2links($host['inventory']['macaddress_a']));
コード例 #19
0
function validate_expression($expression)
{
    global $ZBX_TR_EXPR_SIMPLE_MACROS, $ZBX_TR_EXPR_REPLACE_TO, $ZBX_TR_EXPR_ALLOWED_FUNCTIONS;
    if (empty($expression)) {
        error(S_EXPRESSION_CANNOT_BE_EMPTY);
        return false;
    }
    $expr = $expression;
    $h_status = array();
    $item_count = 0;
    // Replace all {server:key.function(param)} and {MACRO} with '$ZBX_TR_EXPR_REPLACE_TO'
    //		while(ereg(ZBX_EREG_EXPRESSION_TOKEN_FORMAT, $expr, $arr)){
    while (preg_match('/' . ZBX_PREG_EXPRESSION_TOKEN_FORMAT . '/u', $expr, $arr)) {
        if ($arr[ZBX_EXPRESSION_MACRO_ID] && !isset($ZBX_TR_EXPR_SIMPLE_MACROS[$arr[ZBX_EXPRESSION_MACRO_ID]])) {
            error('Unknown macro [' . $arr[ZBX_EXPRESSION_MACRO_ID] . ']');
            return false;
        } else {
            if (!$arr[ZBX_EXPRESSION_MACRO_ID]) {
                $host =& $arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_HOST_ID];
                $key =& $arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_KEY_ID];
                $function =& $arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_FUNCTION_NAME_ID];
                $parameter =& $arr[ZBX_EXPRESSION_SIMPLE_EXPRESSION_ID + ZBX_SIMPLE_EXPRESSION_FUNCTION_PARAM_ID];
                // Check host
                $sql = 'SELECT COUNT(*) as cnt,min(status) as status,min(hostid) as hostid ' . ' FROM hosts h ' . ' WHERE h.host=' . zbx_dbstr($host) . ' AND ' . DBin_node('h.hostid', false) . ' AND status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ',' . HOST_STATUS_TEMPLATE . ') ';
                $row = DBfetch(DBselect($sql));
                if ($row['cnt'] == 0) {
                    error(S_NO_SUCH_HOST . ' (' . $host . ')');
                    return false;
                } else {
                    if ($row['cnt'] != 1) {
                        error(S_TOO_MANY_HOSTS . ' (' . $host . ')');
                        return false;
                    }
                }
                $h_status[$row['status']][$row['hostid']] = $row['cnt'];
                // Check key
                $sql = 'SELECT i.itemid,i.value_type ' . ' FROM hosts h,items i ' . ' WHERE h.host=' . zbx_dbstr($host) . ' AND i.key_=' . zbx_dbstr($key) . ' AND h.hostid=i.hostid ' . ' AND ' . DBin_node('h.hostid', false);
                if (!($item = DBfetch(DBselect($sql)))) {
                    error(S_NO_SUCH_MONITORED_PARAMETER . ' (' . $key . ') ' . S_FOR_HOST_SMALL . ' (' . $host . ')');
                    return false;
                }
                // Check function
                if (!isset($ZBX_TR_EXPR_ALLOWED_FUNCTIONS[$function])) {
                    error(S_UNKNOWN_FUNCTION . SPACE . '[' . $function . ']');
                    return false;
                }
                $fnc_valid =& $ZBX_TR_EXPR_ALLOWED_FUNCTIONS[$function];
                if (is_array($fnc_valid['item_types']) && !uint_in_array($item['value_type'], $fnc_valid['item_types'])) {
                    $allowed_types = array();
                    foreach ($fnc_valid['item_types'] as $type) {
                        $allowed_types[] = item_value_type2str($type);
                    }
                    info(S_FUNCTION . ' (' . $function . ') ' . S_AVAILABLE_ONLY_FOR_ITEMS_WITH_VALUE_TYPES_SMALL . ' [' . implode(',', $allowed_types) . ']');
                    error(S_INCORRECT_VALUE_TYPE . ' [' . item_value_type2str($item['value_type']) . '] ' . S_FOR_FUNCTION_SMALL . ' (' . $function . ') ' . S_OF_KEY_SMALL . ' (' . $host . ':' . $key . ')');
                    return false;
                }
                if (!is_null($fnc_valid['args'])) {
                    $parameter = zbx_get_params($parameter);
                    if (!is_array($fnc_valid['args'])) {
                        $fnc_valid['args'] = array($fnc_valid['args']);
                    }
                    foreach ($fnc_valid['args'] as $pid => $params) {
                        if (!isset($parameter[$pid])) {
                            if (!isset($params['mandat'])) {
                                continue;
                            } else {
                                error(S_MISSING_MANDATORY_PARAMETER_FOR_FUNCTION . ' (' . $function . ')');
                                return false;
                            }
                        }
                        if (preg_match('/^' . ZBX_PREG_EXPRESSION_USER_MACROS . '$/', $parameter[$pid])) {
                            continue;
                        }
                        if ('sec' == $params['type'] && validate_sec($parameter[$pid]) != 0) {
                            error('[' . $parameter[$pid] . '] ' . S_NOT_FLOAT_OR_MACRO_FOR_FUNCTION_SMALL . ' (' . $function . ')');
                            return false;
                        }
                        if ('sec_num' == $params['type'] && validate_secnum($parameter[$pid]) != 0) {
                            error('[' . $parameter[$pid] . '] ' . S_NOT_FLOAT_OR_MACRO_OR_COUNTER_FOR_FUNCTION_SMALL . ' (' . $function . ')');
                            return false;
                        }
                    }
                }
                $item_count++;
            }
        }
        $expr = $arr[ZBX_EXPRESSION_LEFT_ID] . $ZBX_TR_EXPR_REPLACE_TO . $arr[ZBX_EXPRESSION_RIGHT_ID];
    }
    if ($item_count == 0) {
        error(S_ITEM_KEY_MUST_BE_USED_IN_TRIGGER_EXPRESSION);
        return false;
    }
    if (isset($h_status[HOST_STATUS_TEMPLATE]) && (count($h_status) > 1 || count($h_status[HOST_STATUS_TEMPLATE]) > 1)) {
        error(S_INCORRECT_TRIGGER_EXPRESSION . '.' . SPACE . S_YOU_CAN_NOT_USE_TEMPLATE_HOSTS_MIXED_EXPR);
        return false;
    }
    // Replace all calculations and numbers with '$ZBX_TR_EXPR_REPLACE_TO'
    $expt_number = '(' . $ZBX_TR_EXPR_REPLACE_TO . '|' . ZBX_PREG_NUMBER . '|' . ZBX_PREG_EXPRESSION_USER_MACROS . ')';
    $expt_term = '((\\(' . $expt_number . '\\))|(' . $expt_number . '))';
    $expr_format = '((' . $expt_term . ZBX_PREG_SPACES . ZBX_PREG_SIGN . ZBX_PREG_SPACES . $expt_term . ')|(\\(' . $expt_term . '\\)))';
    $expr_full_format = '((\\(' . $expr_format . '\\))|(' . $expr_format . '))';
    while ($res = preg_match('/' . $expr_full_format . '(.*)$/u', $expr, $arr)) {
        $expr = substr($expr, 0, zbx_strpos($expr, $arr[1])) . $ZBX_TR_EXPR_REPLACE_TO . $arr[82];
    }
    /* OLD EREG
    //Replace all calculations and numbers with '$ZBX_TR_EXPR_REPLACE_TO'
    		$expt_number = '('.$ZBX_TR_EXPR_REPLACE_TO.'|'.ZBX_EREG_NUMBER.'|'.ZBX_EREG_EXPRESSION_USER_MACROS.')';
    
    		$expt_term = '((\('.$expt_number.'\))|('.$expt_number.'))';
    		$expr_format = '(('.$expt_term.ZBX_EREG_SPACES.ZBX_EREG_SIGN.ZBX_EREG_SPACES.$expt_term.')|(\('.$expt_term.'\)))';
    		$expr_full_format = '((\('.$expr_format.'\))|('.$expr_format.'))';
    
    		while($res = ereg($expr_full_format.'([[:print:]]*)$', $expr, $arr)){
    			$expr = substr($expr, 0, zbx_strpos($expr, $arr[1])).$ZBX_TR_EXPR_REPLACE_TO.$arr[58];
    		}
    */
    if ($ZBX_TR_EXPR_REPLACE_TO != $expr) {
        error(S_INCORRECT_TRIGGER_EXPRESSION . '. [' . str_replace($ZBX_TR_EXPR_REPLACE_TO, ' ... ', $expr) . ']');
        return false;
    }
    return true;
}