Ejemplo n.º 1
0
 static function init()
 {
     $settings = CConf::get('profiler');
     if (isset($settings['enabled']) && $settings['enabled'] == 'yes') {
         self::$enabled = true;
     }
     if (isset($settings['display_include']) && $settings['display_include'] == 'yes') {
         self::$display_include = true;
     }
     if (isset($settings['display_file_io']) && $settings['display_file_io'] == 'yes') {
         self::$display_file_io = true;
     }
     if (isset($settings['display_queries']) && $settings['display_queries'] == 'yes') {
         self::$display_queries = true;
     }
     if (isset($settings['display_cache']) && $settings['display_cache'] == 'yes') {
         self::$display_cache = true;
     }
     if (isset($settings['display_block_tags']) && $settings['display_block_tags'] == 'yes') {
         self::$display_block_tags = true;
     }
     if (isset($settings['write_csv']) && $settings['write_csv'] == 'yes') {
         self::$write_csv = true;
     }
     self::$profiler = new CProfilerStorage();
     self::$profiler->timer_total->start();
 }
Ejemplo n.º 2
0
 /**
  * @static
  *
  * @return CProfiler
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 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;
     }
 }
 /**
  * Call the API method with profiling.
  *
  * If the API call has been unsuccessful - return only the result value.
  * If the API call has been unsuccessful - add an error message and return false, instead of an array.
  *
  * @param string 	$method
  * @param array 	$params
  *
  * @return mixed
  */
 protected function callMethod($method, array $params)
 {
     API::setWrapper();
     $response = parent::callMethod($method, $params);
     API::setWrapper($this);
     // call profiling
     if ($this->debug) {
         $this->profiler->profileApiCall($this->api, $method, $params, $response->data);
     }
     if (!$response->errorCode) {
         return $response->data;
     } else {
         // add an error message
         $trace = $response->errorMessage;
         if ($response->debug) {
             $trace .= ' [' . $this->profiler->formatCallStack($response->debug) . ']';
         }
         error($trace);
         return false;
     }
 }
 protected function _updateFile()
 {
     if ($this->_modified == false) {
         return;
     }
     $this->_stat['io_write']++;
     $start = microtime(true);
     CProfiler::ioStart($this->_file_storage, 'write');
     file_put_contents($this->_file_storage, $this->_encodeData($this->_data), LOCK_EX);
     CProfiler::ioStop();
     $end = microtime(true);
     $this->_stat['io_write_time'] += $end - $start;
 }
Ejemplo n.º 6
0
/**
 * Checks the possibility to save and to create files in this folder.
 *
 * @param string $dir_fs_name The name of checking folder.
 */
function is_dir_writable($dir_fs_name)
{
    if (@file_exists($dir_fs_name) == FALSE) {
        return FALSE;
    }
    $file_name = md5(uniqid(rand(), true)) . 'test.txt';
    $result = false;
    CProfiler::ioStart($dir_fs_name . $file_name, 'test');
    $fp = @fopen($dir_fs_name . $file_name, 'w');
    if ($fp) {
        fclose($fp);
        $result = @unlink($dir_fs_name . $file_name);
    }
    CProfiler::ioStop();
    return $result;
}
Ejemplo n.º 7
0
 /**
  * $mode LOCK_SH | LOCK_EX
  */
 public static function lock($mode, $lock_file_name = 'global')
 {
     if (self::$_fIsLocked) {
         return false;
     }
     $lock_file = CConf::get('cache_dir') . $lock_file_name . '.lock';
     self::$_fLockFileHandler = new CFile($lock_file);
     self::$_fLockFileHandler->open('w');
     if (!self::$_fLockFileHandler->isError()) {
         CProfiler::lockStart();
         self::$_fLockFileHandler->lock($mode);
         CProfiler::lockStop();
         self::$_fIsLocked = true;
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 function outputPageByMap($page)
 {
     global $__TPL_DIR__, $__TPL_URL__, $application;
     $page = basename($page);
     $map_file = modApiFunc('Layout_CMS', 'getThemePath') . 'map.ini';
     $use_cached = false;
     if (file_exists($map_file)) {
         $ini_cache = $application->getIniCache();
         $map_mtime = filemtime($map_file);
         if ($map_mtime == $ini_cache->read($map_file . '-mtime')) {
             $map = $ini_cache->read($map_file);
             $use_cached = true;
         } else {
             CProfiler::ioStart($map_file, 'parse');
             $map = parse_ini_file($map_file, true);
             CProfiler::ioStop();
             $ini_cache->write($map_file . '-mtime', $map_mtime);
             $ini_cache->write($map_file, $map);
         }
     } else {
         $map = modApiFunc('Layout_CMS', 'generateMap', $page);
     }
     if (isset($map['default'])) {
         $map_default = $map['default'];
     }
     if (isset($map[$page])) {
         $map = array_merge($map_default, $map[$page]);
     } else {
         _fatal("The page [{$page}] not found in the map file [{$map_file}]");
     }
     $template_path = getTemplateFileAbsolutePath('pages/templates/' . $map['template']);
     $tpl_cache = $application->getTplCache();
     $template_mtime = filemtime($template_path);
     if ($template_mtime == $tpl_cache->read($template_path . '-mtime')) {
         $template_content = $tpl_cache->read($template_path);
     } else {
         $template_file = new CFile($template_path);
         $template_content = $template_file->getContent();
         $tpl_cache->write($template_path . '-mtime', $template_mtime);
         $tpl_cache->write($template_path, $template_content);
         $use_cached = false;
     }
     if ($use_cached) {
         $contents = $tpl_cache->read($template_path . '-' . $page);
     }
     if (!isset($contents)) {
         $replace = array();
         foreach ($map as $k => $v) {
             $replace['#' . $k . '#'] = $v;
             $replace['[' . $k . ']'] = htmlentities($v, ENT_QUOTES);
         }
         $contents = '?>' . strtr($template_content, $replace);
         $tpl_cache->write($template_path . '-' . $page, $contents);
     }
     ob_start();
     eval($contents);
     $contents = ob_get_contents();
     ob_end_clean();
     $contents = str_replace('<br>', '<br/>', $contents);
     return $contents;
 }
Ejemplo n.º 10
0
 function preloadPHP($preload_php)
 {
     $sys_dir = dirname(dirname(__FILE__)) . '/';
     $add_modules_dir = CConf::get('add_modules_dir');
     $modules_dir = CConf::get('modules_dir');
     if (is_readable($preload_php['combined_file'])) {
         global $include_combined_php;
         // emergency flag
         $include_combined_php = $preload_php['combined_file'];
         CTrace::dbg('Preload combined: ' . $preload_php['combined_file']);
         CProfiler::includeStart($include_combined_php);
         include_once $include_combined_php;
         CProfiler::includeStop();
         CTrace::dbg('Done');
         unset($include_combined_php);
     } else {
         if (strpos($preload_php['combined_file'], 'core') === false) {
             foreach ($preload_php['files'] as $php) {
                 if (is_file(realpath($add_modules_dir . $php))) {
                     $this->includeFile($add_modules_dir . $php);
                 } else {
                     $this->includeFile($modules_dir . $php);
                 }
             }
         } else {
             foreach ($preload_php['files'] as $php) {
                 $this->includeFile($sys_dir . $php);
             }
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * Returns the information for the provided skin
  * Note: function DOES NOT check the skin
  *       use method checkSkin for checking
  */
 function getSkinInfo($skin)
 {
     global $application;
     $skin_dir = $application->getAppIni('PATH_THEMES') . $skin;
     $result = array('skin' => $skin, 'path' => $application->getAppIni('PATH_THEMES') . $skin);
     if (is_file($skin_dir . '/info.ini') && is_readable($skin_dir . '/info.ini')) {
         CProfiler::ioStart($skin_dir . '/info.ini', 'parse');
         $result = array_merge(parse_ini_file($skin_dir . '/info.ini'), $result);
         CProfiler::ioStop();
     }
     return $result;
 }
Ejemplo n.º 12
0
            $r->rotate();
            $tw = new CTraceWriter($trace_cfg['file'], $trace_cfg['template'], new CTraceFilter($trace_cfg['filter']));
            CTrace::registerWriter($tw);
        }
    }
}
// must be defined after CTrace initialization.
// all php notices, warnings and errors will be logged, so we need to set E_ALL level
//error_reporting(E_ERROR);
//set_error_handler('__error_handler__', E_ERROR);
CTrace::inf('Request: ' . getCurrentURL());
CProfiler::start('init');
$bootstrap = new Bootstrap();
$bootstrap->preboot();
//CTrace::inf('Point 1 (after preboot)');
$bootstrap->preloadCorePHP();
do_action('init');
//CTrace::inf('Point 2 (after preloading core php)');
$bootstrap->preloadModulesPHP();
//CTrace::inf('Point 3 (after preloading modules php)');
global $zone;
if ($zone == 'CustomerZone') {
    $bootstrap->preloadModulesViewsCzPHP();
    //CTrace::inf('Point 3 (after preloading modules views php)');
}
$bootstrap->boot();
//CTrace::inf('Point 4 (after boot)');
$bootstrap->postboot();
//CTrace::inf('Point 5 (after postboot)');
CProfiler::stop('init');
Ejemplo n.º 13
0
 function clearCache($table_list)
 {
     global $application;
     CProfiler::DBLayerStart();
     $application->enterCriticalSection('database');
     foreach ($table_list as $table_name) {
         $this->cache->write($table_name, uniqid('', true));
         //  time()                    ,
     }
     $application->leaveCriticalSection();
     CProfiler::DBLayerStop();
 }
Ejemplo n.º 14
0
// 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();
Ejemplo n.º 15
0
 function getResFileByShortName($short_name)
 {
     global $application;
     CProfiler::ioStart($application->appIni['PATH_SYSTEM_DIR'] . 'shortname2path', 'parse');
     $map = parse_ini_file($application->appIni['PATH_SYSTEM_DIR'] . 'shortname2path');
     CProfiler::ioStop();
     if (isset($map[$short_name])) {
         return $application->appIni['PATH_ASC_ROOT'] . $map[$short_name];
     } else {
         return null;
     }
 }
Ejemplo n.º 16
0
 function parse_import_file($fname, $delimetr = ";")
 {
     if (!file_exists($fname) or !is_readable($fname)) {
         return false;
     }
     if (!in_array($delimetr, array(",", ";", "\t"))) {
         return false;
     }
     CProfiler::ioStart();
     $fh = @fopen($fname, "r");
     CProfiler::ioStop();
     if ($fh == FALSE) {
         return false;
     }
     CProfiler::ioStart($fname, 'read');
     $layout = fgetcsv($fh, 262144, $delimetr);
     $layout = convertImportDataArray($layout);
     //!!!!!
     foreach ($layout as $name => $value) {
         //            echo("!layout: name = $name; value = $value!<br>");
     }
     //!!!!!
     $csv_data = array();
     while (!feof($fh)) {
         $data = fgetcsv($fh, 262144, $delimetr);
         $data = convertImportDataArray($data);
         foreach ($data as $name => $value) {
             //               echo("!data: name = $name; value = $value!<br>");
         }
         $tmp = array();
         for ($i = 0; $i < count($layout); $i++) {
             //                echo("<i>layout[$i] = $layout[$i]</i> - ");
             //              echo("data[$i] = $data[$i]<br>");
             $tmp[$layout[$i]] = $data[$i];
         }
         $csv_data[] = $tmp;
     }
     fclose($fh);
     CProfiler::ioStop();
     return array($layout, $csv_data);
 }
Ejemplo n.º 17
0
 /**
  *  Initial parsing if theme map.ini file and generating of YAML files
  */
 function parseMapIni()
 {
     $map_file = $this->_PATH_CUR_THEME . 'map.ini';
     if (!file_exists($map_file)) {
         return null;
     }
     $pages = $blocks_yml = array();
     foreach ($this->getBlocks() as $bl) {
         $blocks_yml[trim($bl['template'])] = $bl['name'];
     }
     // Hoare sort blocks by order
     function hoare($arr)
     {
         $less = $greater = array();
         if (count($arr) <= 1) {
             return $arr;
         }
         $x = array_shift($arr);
         foreach ($arr as $y) {
             if ($y[1] <= $x[1]) {
                 array_push($less, $y);
             } else {
                 array_push($greater, $y);
             }
         }
         return array_merge(hoare($less), array($x), hoare($greater));
     }
     CProfiler::ioStart($map_file, 'parse');
     $map = parse_ini_file($map_file, true);
     CProfiler::ioStop();
     foreach ($map as $page => $sections) {
         $pages[$page] = array('settings' => array('template' => '#DEFAULT#', 'page_title' => '#DEFAULT#', 'page_description' => '#DEFAULT#', 'page_keywords' => '#DEFAULT#'), 'placeholders' => array('header' => array(), 'main_menu' => array(), 'topslideshow' => array(), 'left_column' => array(), 'center_column' => array(), 'right_column' => array(), 'footer' => array()));
         foreach ($sections as $section_name => $section_content) {
             switch ($section_name) {
                 case 'template':
                 case 'page_title':
                 case 'page_description':
                 case 'page_keywords':
                     $pages[$page]['settings'][$section_name] = "'{$section_content}'";
                     break;
                 default:
                     $PH = 'custom';
                     switch ($section_name) {
                         case 'top_menu':
                         case 'top_phone':
                         case 'user1':
                         case 'user3':
                             $PH = 'header';
                             break;
                         case 'main_menu':
                         case 'topslideshow':
                         case 'left_column':
                         case 'center_column':
                         case 'right_column':
                             $PH = $section_name;
                             break;
                         case 'copyright':
                         case 'footer_menu':
                             $PH = 'footer';
                             break;
                         default:
                             break;
                     }
                     // regexp pattern for 'if()...endif' blocks
                     $if_endif_pat = '/(\\<\\?php\\s+if\\s*\\(.+?\\)\\s*\\:\\s*\\?\\>(.*?)(?!endif)(.*?)\\<\\?php\\s+endif\\s*;\\s*\\?\\>)/';
                     // common regexp pattern for standard PHP tags
                     $common_pat = '/(\\<\\?php\\s+(.*?)(?!\\<\\?php)(.*?)\\s*\\?\\>)/';
                     $obtained_blocks = array();
                     // array of obtained blocks from placeholder
                     if (!empty($section_content)) {
                         $scont = $section_content;
                         if (preg_match_all($if_endif_pat, $scont, $matches, PREG_OFFSET_CAPTURE)) {
                             $obtained_blocks = $matches[0];
                         }
                         foreach ($obtained_blocks as $ob) {
                             $scont = str_replace($ob[0], str_repeat("#", strlen($ob[0])), $scont);
                         }
                         if (preg_match_all($common_pat, $scont, $matches, PREG_OFFSET_CAPTURE)) {
                             $obtained_blocks = array_merge($obtained_blocks, $matches[0]);
                         }
                         // preserve blocks sequence in placeholder
                         $obtained_blocks = hoare($obtained_blocks);
                         foreach ($obtained_blocks as $i => $ob) {
                             $bcont = trim($obtained_blocks[$i][0]);
                             $bname = @$blocks_yml[$bcont];
                             if (isset($bname)) {
                                 $pages[$page]['placeholders'][$PH]['blocks'][] = array('name' => $bname, 'visibility' => 'visible');
                             } else {
                                 $pages[$page]['placeholders'][$PH]['blocks'][] = array('name' => "undef_" . $PH . "_{$i}", 'visibility' => 'visible');
                                 $pages[$page]['placeholders'][$PH]['undef_blocks'][] = array('name' => "undef_" . $PH . "_{$i}", 'title' => 'Undefined block', 'description' => 'Undefined block', 'template' => "'{$bcont}'");
                             }
                             $pages[$page]['placeholders'][$PH]['visibility'] = 'visible';
                         }
                     } else {
                         $pages[$page]['placeholders'][$PH]['blocks'] = array();
                         $pages[$page]['placeholders'][$PH]['visibility'] = 'hidden';
                     }
                     break;
             }
         }
     }
     // merge pages with 'default'
     $def_page = $pages['default'];
     foreach ($pages as $page => $layout) {
         $undef_blocks = array();
         foreach ($layout['settings'] as $sname => $sval) {
             if ($sval === '#DEFAULT#') {
                 $pages[$page]['settings'][$sname] = $def_page['settings'][$sname];
             }
         }
         foreach ($layout['placeholders'] as $PHname => $PHparams) {
             if ($PHparams === array()) {
                 $pages[$page]['placeholders'][$PHname] = $def_page['placeholders'][$PHname];
             }
             if (!empty($pages[$page]['placeholders'][$PHname]['undef_blocks'])) {
                 $undef_blocks = array_merge($undef_blocks, $pages[$page]['placeholders'][$PHname]['undef_blocks']);
                 unset($pages[$page]['placeholders'][$PHname]['undef_blocks']);
             }
         }
         // save unparsed blocks
         $this->_saveCustomBlocks($page, $undef_blocks);
     }
     // save parsed pages
     $this->_saveMapIniParsedPages($pages);
     // rename theme map.ini
     if (file_exists($this->_PATH_CUR_THEME . 'map.ini')) {
         copy($this->_PATH_CUR_THEME . 'map.ini', $this->_PATH_CUR_THEME . 'map.ini.old');
         @chmod($this->_PATH_CUR_THEME . 'map.ini.old', 0777);
         unlink($this->_PATH_CUR_THEME . 'map.ini');
     }
 }
Ejemplo n.º 18
0
 /**
  * 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;
         }
     }
 }
            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);
 protected function _saveFile($filename, $data)
 {
     $this->_stat['io_write']++;
     $start = microtime(true);
     CProfiler::ioStart($filename, 'write');
     if (false === file_put_contents($filename, $this->_encodeData($data), LOCK_EX)) {
         $this->_stat['err_file_put_contents']++;
     }
     CProfiler::ioStop();
     $end = microtime(true);
     $this->_stat['io_write_time'] += $end - $start;
 }
Ejemplo n.º 21
0
 function _test_cookies()
 {
     global $HTTP_COOKIE_VARS;
     $cookies = array();
     if (isset($_COOKIE)) {
         $cookies = $_COOKIE;
     } elseif (isset($HTTP_COOKIE_VARS)) {
         $cookies = $HTTP_COOKIE_VARS;
     }
     if ($this->_check_cookies) {
         CProfiler::ioStart($this->_temp_file_path . $this->property('ip'), 'test');
         $fp = @fopen($this->_temp_file_path . $this->property('ip'), 'r');
         if (!$fp) {
             $fp = @fopen($this->_temp_file_path . $this->property('ip'), 'a');
             fclose($fp);
             CProfiler::ioStop();
             setcookie('phpSniff_session', 'ss', 0, '/');
             setcookie('phpSniff_stored', 'st', time() + 3600 * 24 * 365, '/');
             $QS = getenv('QUERY_STRING');
             $script_path = getenv('PATH_INFO') ? getenv('PATH_INFO') : getenv('SCRIPT_NAME');
             if (is_integer($pos = strpos(strrev($script_path), "php.xedni/")) && !$pos) {
                 $script_path = strrev(substr(strrev($script_path), 9));
             }
             $location = 'http://' . getenv('SERVER_NAME') . $script_path . ($QS == '' ? '' : '?' . $QS);
             header("Location: {$location}");
             exit;
         } else {
             unlink($this->_temp_file_path . $this->property('ip'));
             fclose($fp);
             CProfiler::ioStop();
             $this->_set_browser('ss_cookies', isset($cookies['phpSniff_session']) ? 'true' : 'false');
             $this->_set_browser('st_cookies', isset($cookies['phpSniff_stored']) ? 'true' : 'false');
             // delete the old cookies
             setcookie('phpSniff_session', '', 0, '/');
             setcookie('phpSniff_stored', '', 0, '/');
         }
     }
 }
Ejemplo n.º 22
0
// 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";
Ejemplo n.º 23
0
 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() . ']');
 }
Ejemplo n.º 24
0
 function _read_key_from_file($file, $extention)
 {
     $key = '';
     if ($extention == ".php") {
         CProfiler::ioStart($file, 'parse');
         $key = @parse_ini_file($file);
         CProfiler::ioStop();
         if ($key === false) {
             $this->license_key_status = LICENSE_KEY_FORMAT_INVALID;
             return LICENSE_KEY_FORMAT_INVALID;
         }
         $key = @$key["key"];
     }
     return $this->formatKey($key);
 }
Ejemplo n.º 25
0
loadClass('REST_Errors');
if ($application->getCurrentProtocol() !== "https") {
    $e = new REST_Errors();
    $e->IncorrectRestProtocol();
    $e->send();
    exit;
}
if (!isset($_GET['alogin']) || !isset($_GET['apassword'])) {
    $e = new REST_Errors();
    $e->UndefinedLoginPassword();
    $e->send();
    exit;
}
loadActionClass('SignIn');
$signin = new SignIn();
$acountInfo = null;
if ($signin->isValidAcount($_GET['alogin'], md5($_GET['apassword']), $acountInfo)) {
    modApiFunc("Users", "setCurrentUserID", $acountInfo['id']);
} else {
    $e = new REST_Errors();
    $e->IncorrectLoginPassword();
    $e->send();
    exit;
}
if ($usr->isUserSignedIn() == FALSE) {
}
$_GET['asc_action'] = 'REST_Request_Action';
CProfiler::start('processAction');
$application->processAction();
CProfiler::stop('processAction');
Ejemplo n.º 26
0
            $request->setView('Closed');
            $application->redirect($request);
        }
    } else {
        if ($current_file == $application->getPagenameByViewname('Closed')) {
            $request = new Request();
            $request->setView('Index');
            $application->redirect($request);
        }
    }
} else {
    if ($session->is_Set("DEBUG_MODE")) {
        $session->un_Set("DEBUG_MODE");
    }
    if ($current_file == basename($application->getPagenameByViewname('Closed'))) {
        $request = new Request();
        $request->setView('Index');
        $application->redirect($request);
    }
}
$application->outputTagErrors();
if ($usr->isUserSignedIn() == FALSE) {
    # redirect to Users_CustomerLogin
    # exit();
}
CProfiler::start('processAction');
$application->processAction();
CProfiler::stop('processAction');
$application->redirectToAnotherProtocol();
CProfiler::start('API & Render');
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
 function importData($dump_file, $table_prefix, $offset, $str_offset)
 {
     CProfiler::ioStart($dump_file, 'read');
     $fp = fopen($dump_file, "r");
     fseek($fp, $offset);
     $this->getSQLCommandFromFile($fp, $offset, $str_offset, $table_prefix, time());
     fclose($fp);
     CProfiler::ioStop();
     return array("offset" => $offset, "str_offset" => $str_offset);
 }
Ejemplo n.º 29
0
 function delete()
 {
     if ($this->__is_error) {
         return false;
     }
     CProfiler::ioStart($this->__file_name, 'delete');
     $this->__is_error = !unlink($this->__file_name);
     CProfiler::ioStop();
     return !$this->__is_error;
 }
Ejemplo n.º 30
0
function asc_mac2nix($src)
{
    CProfiler::ioStart($src, 'read-write');
    $fh = fopen($src, 'r+b');
    while (!feof($fh)) {
        $c = fread($fh, 1);
        if ($c == "\r") {
            fseek($fh, -1, SEEK_CUR);
            fwrite($fh, "\n");
        }
    }
    fclose($fh);
    CProfiler::ioStop();
}