public function __call($method, $params) { if (!isset(CWebUser::$data['sessionid'])) { CWebUser::$data['sessionid'] = null; } $param = empty($params) ? null : reset($params); $result = czbxrpc::call($this->_name . '.' . $method, $param, CWebUser::$data['sessionid']); // saving API call for the debug statement CProfiler::getInstance()->profileApiCall($this->_name, $method, $params, isset($result['result']) ? $result['result'] : ''); if (isset($result['result'])) { return $result['result']; } else { $trace = $result['data']; if (isset($result['debug'])) { $trace .= ' ['; $chain = array(); foreach ($result['debug'] as $bt) { if ($bt['function'] == 'exception') { continue; } if ($bt['function'] == 'call_user_func') { break; } $chain[] = isset($bt['class']) ? $bt['class'] . '.' . $bt['function'] : $bt['function']; $chain[] = ' -> '; } array_pop($chain); $trace .= implode('', array_reverse($chain)); $trace .= ']'; } error($trace); return false; } }
public function __call($method, $params) { if (!isset(CWebUser::$data['sessionid'])) { CWebUser::$data['sessionid'] = null; } $param = empty($params) ? null : reset($params); $result = czbxrpc::call($this->_name . '.' . $method, $param, CWebUser::$data['sessionid']); // saving API call for the debug statement CProfiler::getInstance()->profileApiCall($this->_name, $method, $params, isset($result['result']) ? $result['result'] : ''); if (isset($result['result'])) { return $result['result']; } else { $trace = $result['data']; if (isset($result['debug'])) { $trace .= ' [' . CProfiler::getInstance()->formatCallStack($result['debug']) . ']'; } error($trace); return false; } }
if (++$popup_rows == ZBX_WIDGET_ROWS) { break; } } $problematic_count = (new CSpan($hosts_data[$group['groupid']]['problematic']))->addClass(ZBX_STYLE_LINK_ACTION)->setHint($table_inf); } else { $problematic_count = 0; } switch ($data['filter']['extAck']) { case EXTACK_OPTION_ALL: $group_row->addItem((new CCol($problematic_count))->addClass(getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic']))); $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']); break; case EXTACK_OPTION_UNACK: $group_row->addItem((new CCol($lastUnack_count))->addClass(getSeverityStyle(isset($highest_severity2[$group['groupid']]) ? $highest_severity2[$group['groupid']] : 0, $hosts_data[$group['groupid']]['lastUnack']))); $group_row->addItem($hosts_data[$group['groupid']]['lastUnack'] + $hosts_data[$group['groupid']]['ok']); break; case EXTACK_OPTION_BOTH: $unackspan = $lastUnack_count ? [$lastUnack_count, ' ' . _('of') . ' '] : null; $group_row->addItem((new CCol([$unackspan, $problematic_count]))->addClass(getSeverityStyle($highest_severity[$group['groupid']], $hosts_data[$group['groupid']]['problematic']))); $group_row->addItem($hosts_data[$group['groupid']]['problematic'] + $hosts_data[$group['groupid']]['ok']); break; } $table->addRow($group_row); } $output = ['header' => _('Host status'), 'body' => (new CDiv([getMessages(), $table]))->toString(), 'footer' => (new CListItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS))))->toString()]; if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { CProfiler::getInstance()->stop(); $output['debug'] = CProfiler::getInstance()->make()->toString(); } echo (new CJson())->encode($output);
function DBexecute($query, $skip_error_messages = 0) { global $DB; if (!isset($DB['DB']) || empty($DB['DB'])) { return false; } $result = false; $time_start = microtime(true); $DB['EXECUTE_COUNT']++; switch ($DB['TYPE']) { case ZBX_DB_MYSQL: if (!($result = mysqli_query($DB['DB'], $query))) { error('Error in query [' . $query . '] [' . mysqli_error($DB['DB']) . ']'); } break; case ZBX_DB_POSTGRESQL: if (!($result = (bool) pg_query($DB['DB'], $query))) { error('Error in query [' . $query . '] [' . pg_last_error() . ']'); } break; case ZBX_DB_ORACLE: if (!($result = oci_parse($DB['DB'], $query))) { $e = @oci_error(); error('SQL error [' . $e['message'] . '] in [' . $e['sqltext'] . ']'); } elseif (!@oci_execute($result, $DB['TRANSACTIONS'] ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS)) { $e = oci_error($result); error('SQL error [' . $e['message'] . '] in [' . $e['sqltext'] . ']'); } else { $result = true; // function must return boolean } break; case ZBX_DB_DB2: if (!($result = db2_prepare($DB['DB'], $query))) { $e = @db2_stmt_errormsg($result); error('SQL error [' . $query . '] in [' . $e . ']'); } elseif (true !== @db2_execute($result)) { $e = @db2_stmt_errormsg($result); error('SQL error [' . $query . '] in [' . $e . ']'); } else { $result = true; // function must return boolean } break; case ZBX_DB_SQLITE3: if ($DB['TRANSACTIONS'] == 0) { lock_sqlite3_access(); } if (!($result = $DB['DB']->exec($query))) { error('Error in query [' . $query . '] Error code [' . $DB['DB']->lastErrorCode() . '] Message [' . $DB['DB']->lastErrorMsg() . ']'); } if ($DB['TRANSACTIONS'] == 0) { unlock_sqlite3_access(); } break; } if ($DB['TRANSACTIONS'] != 0 && !$result) { $DB['TRANSACTION_NO_FAILED_SQLS'] = false; } CProfiler::getInstance()->profileSql(microtime(true) - $time_start, $query); return (bool) $result; }
// reset the LC_CTYPE locale so that case transformation functions would work correctly // it is also required for PHP to work with the Turkish locale (https://bugs.php.net/bug.php?id=18556) // WARNING: this must be done before executing any other code, otherwise code execution could fail! // this will be unnecessary in PHP 5.5 setlocale(LC_CTYPE, array('C', 'POSIX', 'en', 'en_US', 'en_US.UTF-8', 'English_United States.1252', 'en_GB', 'en_GB.UTF-8')); require_once dirname(__FILE__) . '/classes/core/Z.php'; try { Z::getInstance()->run(); } catch (DBException $e) { $warningView = new CView('general.warning', array('message' => array('header' => 'Database error', 'text' => $e->getMessage()))); $warningView->render(); exit; } catch (ConfigFileException $e) { switch ($e->getCode()) { case CConfigFile::CONFIG_NOT_FOUND: redirect('setup.php'); exit; case CConfigFile::CONFIG_ERROR: $warningView = new CView('general.warning', array('message' => array('header' => 'Configuration file error', 'text' => $e->getMessage()))); $warningView->render(); exit; } } catch (Exception $e) { $warningView = new CView('general.warning', array('message' => $e->getMessage())); $warningView->render(); exit; } CProfiler::getInstance()->start(); global $ZBX_PAGE_POST_JS, $page; global $ZBX_SERVER, $ZBX_SERVER_PORT; $page = array();
function zbx_err_handler($errno, $errstr, $errfile, $errline) { // necessary to surpress errors when calling with error control operator like @function_name() if (error_reporting() === 0) { return true; } // don't show the call to this handler function error($errstr . ' [' . CProfiler::getInstance()->formatCallStack() . ']'); }
// last page if (!defined('ZBX_PAGE_NO_MENU') && $page['file'] != 'profile.php') { CProfile::update('web.paging.lastpage', $page['file'], PROFILE_TYPE_STR); } CProfile::flush(); // end transactions if they have not been closed already if (isset($DB) && isset($DB['TRANSACTIONS']) && $DB['TRANSACTIONS'] != 0) { error(_('Transaction has not been closed. Aborting...')); DBend(false); } show_messages(); $post_script = ''; if (in_array($page['type'], array(PAGE_TYPE_HTML_BLOCK, PAGE_TYPE_HTML))) { if (!is_null(CWebUser::$data) && isset(CWebUser::$data['debug_mode']) && CWebUser::$data['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { CProfiler::getInstance()->stop(); CProfiler::getInstance()->show(); } } if ($page['type'] == PAGE_TYPE_HTML) { $post_script .= 'var page_refresh = null;' . "\n"; $post_script .= "jQuery(function() {\n"; if (isset($ZBX_PAGE_POST_JS)) { foreach ($ZBX_PAGE_POST_JS as $script) { $post_script .= $script . "\n"; } } if (defined('ZBX_PAGE_DO_REFRESH') && CWebUser::$data['refresh']) { $post_script .= 'PageRefresh.init(' . CWebUser::$data['refresh'] * 1000 . ');' . "\n"; } if (isset($page['scripts']) && in_array('flickerfreescreen.js', $page['scripts'])) { $post_script .= 'window.flickerfreeScreenShadow.timeout = ' . SCREEN_REFRESH_TIMEOUT . ' * 1000;' . "\n";
/** * Initializes the application. */ public function run($mode) { $this->init(); $this->setMaintenanceMode(); set_error_handler('zbx_err_handler'); switch ($mode) { case self::EXEC_MODE_DEFAULT: $this->loadConfigFile(); $this->initDB(); $this->authenticateUser(); $this->initLocales(); break; case self::EXEC_MODE_API: $this->loadConfigFile(); $this->initDB(); $this->initLocales(); break; case self::EXEC_MODE_SETUP: try { // try to load config file, if it exists we need to init db and authenticate user to check permissions $this->loadConfigFile(); $this->initDB(); $this->authenticateUser(); $this->initLocales(); } catch (ConfigFileException $e) { } break; } // new MVC processing, otherwise we continue execution old style if (hasRequest('action')) { $router = new CRouter(getRequest('action')); if ($router->getController() !== null) { CProfiler::getInstance()->start(); $this->processRequest(); exit; } } }