/** * Update debug configuration. */ function procAdminUpdateDebug() { $vars = Context::getRequestVars(); // Debug settings Rhymix\Framework\Config::set('debug.enabled', $vars->debug_enabled === 'Y'); Rhymix\Framework\Config::set('debug.log_slow_queries', max(0, floatval($vars->debug_log_slow_queries))); Rhymix\Framework\Config::set('debug.log_slow_triggers', max(0, floatval($vars->debug_log_slow_triggers))); Rhymix\Framework\Config::set('debug.log_slow_widgets', max(0, floatval($vars->debug_log_slow_widgets))); Rhymix\Framework\Config::set('debug.log_slow_remote_requests', max(0, floatval($vars->debug_log_slow_remote_requests))); Rhymix\Framework\Config::set('debug.display_type', strval($vars->debug_display_type) ?: 'comment'); Rhymix\Framework\Config::set('debug.display_to', strval($vars->debug_display_to) ?: 'admin'); Rhymix\Framework\Config::set('debug.write_error_log', strval($vars->debug_write_error_log) ?: 'fatal'); // Debug content $debug_content = array_values($vars->debug_display_content); Rhymix\Framework\Config::set('debug.display_content', $debug_content); // Log filename $log_filename = strval($vars->debug_log_filename); $log_filename_today = str_replace(array('YYYY', 'YY', 'MM', 'DD'), array(getInternalDateTime(RX_TIME, 'Y'), getInternalDateTime(RX_TIME, 'y'), getInternalDateTime(RX_TIME, 'm'), getInternalDateTime(RX_TIME, 'd')), $log_filename); if (file_exists(RX_BASEDIR . $log_filename_today) && !is_writable(RX_BASEDIR . $log_filename_today)) { return new Object(-1, 'msg_debug_log_filename_not_writable'); } if (!file_exists(dirname(RX_BASEDIR . $log_filename)) && !FileHandler::makeDir(dirname(RX_BASEDIR . $log_filename))) { return new Object(-1, 'msg_debug_log_filename_not_writable'); } if (!is_writable(dirname(RX_BASEDIR . $log_filename))) { return new Object(-1, 'msg_debug_log_filename_not_writable'); } Rhymix\Framework\Config::set('debug.log_filename', $log_filename); // IP access control $allowed_ip = array_map('trim', preg_split('/[\\r\\n]/', $vars->debug_allowed_ip)); $allowed_ip = array_unique(array_filter($allowed_ip, function ($item) { return $item !== ''; })); if (!Rhymix\Framework\Filters\IpFilter::validateRanges($allowed_ip)) { return new Object(-1, 'msg_invalid_ip'); } Rhymix\Framework\Config::set('debug.allow', array_values($allowed_ip)); // Save Rhymix\Framework\Config::save(); $this->setMessage('success_updated'); $this->setRedirectUrl(Context::get('success_return_url') ?: getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdminConfigDebug')); }
/** * Get debug information. * * @return string */ public function getDebugInfo(&$output = null) { // Check if debugging information has already been printed. if (self::$debug_printed) { return; } else { self::$debug_printed = 1; } // Check if debugging is enabled for this request. if (!config('debug.enabled') || !Rhymix\Framework\Debug::isEnabledForCurrentUser()) { return; } // Do not display debugging information if there is no output. $display_type = config('debug.display_type'); if ($output === null && $display_type !== 'file') { return; } // Print debug information. switch ($display_type) { case 'panel': $data = Rhymix\Framework\Debug::getDebugData(); $display_content = array_fill_keys(config('debug.display_content'), true); if (count($display_content) && !isset($display_content['entries'])) { $data->entries = null; } if (count($display_content) && !isset($display_content['queries'])) { unset($data->queries); } if (count($display_content) && !isset($display_content['slow_queries'])) { unset($data->slow_queries); } if (count($display_content) && !isset($display_content['slow_triggers'])) { unset($data->slow_triggers); } if (count($display_content) && !isset($display_content['slow_widgets'])) { unset($data->slow_widgets); } if (count($display_content) && !isset($display_content['slow_remote_requests'])) { unset($data->slow_remote_requests); } if ($data->entries) { foreach ($data->entries as &$entry) { if (is_scalar($entry->message)) { $entry->message = var_export($entry->message, true); } else { $entry->message = trim(print_r($entry->message, true)); } } } switch (Context::getResponseMethod()) { case 'HTML': $json_options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE : 0; $panel_script = sprintf('<script src="%s%s?%s"></script>', RX_BASEURL, 'common/js/debug.js', filemtime(RX_BASEDIR . 'common/js/debug.js')); if (isset($_SESSION['_rx_debug_previous'])) { $panel_script .= "\n<script>\nvar rhymix_debug_previous = " . json_encode($_SESSION['_rx_debug_previous'], $json_options) . ";\n</script>"; unset($_SESSION['_rx_debug_previous']); } $panel_script .= "\n<script>\nvar rhymix_debug_content = " . json_encode($data, $json_options) . ";\n</script>"; $body_end_position = strrpos($output, '</body>') ?: strlen($output); $output = substr($output, 0, $body_end_position) . "\n{$panel_script}\n" . substr($output, $body_end_position); return; case 'JSON': if (RX_POST && preg_match('/^proc/', Context::get('act'))) { $data->ajax_module = Context::get('module'); $data->ajax_act = Context::get('act'); $_SESSION['_rx_debug_previous'] = $data; } else { unset($_SESSION['_rx_debug_previous']); } if (preg_match('/^(.+)\\}$/', $output, $matches)) { $output = $matches[1] . ',"_rx_debug":' . json_encode($data) . '}'; } return; default: return; } case 'comment': case 'file': default: if ($display_type === 'comment' && Context::getResponseMethod() !== 'HTML') { return; } ob_start(); $data = Rhymix\Framework\Debug::getDebugData(); $display_content = array_fill_keys(config('debug.display_content'), true); include RX_BASEDIR . 'common/tpl/debug_comment.html'; $content = preg_replace('/\\n{2,}/', "\n\n", trim(ob_get_clean())) . PHP_EOL; if ($display_type === 'file') { $log_filename = config('debug.log_filename') ?: 'files/debug/YYYYMMDD.php'; $log_filename = str_replace(array('YYYY', 'YY', 'MM', 'DD'), array(getInternalDateTime(RX_TIME, 'Y'), getInternalDateTime(RX_TIME, 'y'), getInternalDateTime(RX_TIME, 'm'), getInternalDateTime(RX_TIME, 'd')), $log_filename); $log_filename = RX_BASEDIR . $log_filename; if (!file_exists($log_filename) || !filesize($log_filename)) { $phpheader = '<?php exit; ?>' . "\n"; } else { $phpheader = ''; } FileHandler::writeFile($log_filename, $phpheader . $content . PHP_EOL, 'a'); return ''; } else { return '<!--' . PHP_EOL . $content . PHP_EOL . '-->'; } } }