Commit c11dfba4 authored by Patrick Schmalstig's avatar Patrick Schmalstig
Browse files

Implemented MANTIS-5736 (Telemetry status)

parent 609fc9ae
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ class Module_admin_errorlog
        require_code('files');
        require_css('errorlog');

        $maximum_size = 1024 * 16;
        $maximum_size = 1024 * 64;
        $max_google_pages = 6;
        $default_max_per_page = 30;

@@ -195,6 +195,7 @@ class Module_admin_errorlog
                    fclose($myfile);
                    unset($lines[0]);
                    $lines[] = '...';
                    attach_message(do_lang_tempcode('ERROR_LOG_TRUNCATED', 'notice'));
                } else {
                    $lines = cms_file_safe(get_custom_file_base() . '/data_custom/errorlog.php');
                }
@@ -208,10 +209,12 @@ class Module_admin_errorlog
                if (($_line != '') && (strpos($_line, '<?php') === false)) {
                    $matches = [];
                    if (preg_match('#^\[([^\]]*)\] ([^:]*): (CRITICAL|ERROR|WARNING|INFO|DEBUG|)[\s]?(.*)#', $_line, $matches) != 0) {
                        $stuff[] = [$matches[1], $matches[2], $matches[3], $matches[4]];
                        $stuff[] = [$matches[1], $matches[2], $matches[3], $matches[4], ''];
                    } elseif (preg_match('#^\[([^\]]*)\] (CRITICAL|ERROR|WARNING|INFO|DEBUG|)[\s]?(.*)#', $_line, $matches) != 0) {
                        $stuff[] = [$matches[1], do_lang('NA'), $matches[2], $matches[3]];
                    } elseif (count($stuff) > 0) { // Additional line from previous error, so append it
                        $stuff[] = [$matches[1], do_lang('NA'), $matches[2], $matches[3], ''];
                    } elseif ((preg_match('#^TELEMETRY (\d*)#', $_line, $matches) != 0) && (count($stuff) > 0)) { // We have a telemetry ID #
                        $stuff[count($stuff) - 1][4] = $matches[1];
                    } elseif (count($stuff) > 0) { // Additional lines for error message, so append them
                        $stuff[count($stuff) - 1][3] .= "\n" . $_line;
                    }
                }
@@ -248,7 +251,7 @@ class Module_admin_errorlog

                    $time = intval($app_log->getTimeUsec() / 1000000.0);

                    $stuff[] = [date('D-M-Y', $time) . ' ' . date('H:i:s', $time), do_lang('NA'), $_level, $message];
                    $stuff[] = [date('D-M-Y', $time) . ' ' . date('H:i:s', $time), do_lang('NA'), $_level, $message, ''];
                }
            }
        }
@@ -268,14 +271,14 @@ class Module_admin_errorlog
        }

        require_code('templates_results_table');
        $header_row = results_header_row([do_lang_tempcode('DATE_TIME'), do_lang_tempcode('TYPE'), do_lang_tempcode('LOG_LEVEL'), do_lang_tempcode('MESSAGE')], $sortables, 'sort', $sortable . ' ' . $sort_order);
        $header_row = results_header_row([do_lang_tempcode('DATE_TIME'), do_lang_tempcode('TYPE'), do_lang_tempcode('LOG_LEVEL'), do_lang_tempcode('RELAYED'), do_lang_tempcode('MESSAGE')], $sortables, 'sort', $sortable . ' ' . $sort_order);
        $result_entries = new Tempcode();
        for ($i = $start; $i < $start + $max; $i++) {
            if (!array_key_exists($i, $stuff)) {
                break;
            }

            list($log_date, $log_type, $log_level, $log_message) = $stuff[$i];
            list($log_date, $log_type, $log_level, $log_message, $telemetry_id) = $stuff[$i];

            if ($log_level == '') {
                $log_level = 'WARNING'; // Default to warning if a log does not contain a level
@@ -285,14 +288,21 @@ class Module_admin_errorlog

            $td_class = cms_mb_strtolower($log_level);

            if (is_numeric($telemetry_id)) {
                $telemetry = hyperlink(get_brand_page_url(['page' => 'telemetry', 'type' => $telemetry_id, 'lang' => get_lang(get_member())], ''), do_lang('YES'), true, true);
            } else {
                $telemetry = do_lang_tempcode('NO');
            }

            $result_entries->attach(static_evaluate_tempcode(results_entry([
                $log_date,
                $log_type,
                $log_level,
                $telemetry,
                $message,
            ], true, 'errorlog', '4469d055e697470a8cb58e8415debaaa', $td_class)));
        }
        $errors = results_table(do_lang_tempcode('ERRORLOG'), $start, 'start', $max, 'max', $i, $header_row, $result_entries, $sortables, $sortable, $sort_order, 'sort', new Tempcode(), ['180px', '180px', '90px'], 'errorlog');
        $errors = results_table(do_lang_tempcode('ERRORLOG'), $start, 'start', $max, 'max', $i, $header_row, $result_entries, $sortables, $sortable, $sort_order, 'sort', new Tempcode(), ['180px', '180px', '90px', '75px'], 'errorlog');

        // Read in end of any other log files we find
        require_all_lang();
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ ERRORLOG=Low-level logging
ERRORS_IN_ERRORLOG=Errors recorded in the error log
MODULE_TRANS_NAME_admin_errorlog=Low-level logging
ERROR_LOGGING_PROBABLY_BROKEN=Error logging within the software is likely not functioning due to environment restriction(s) preventing us from enabling it.
ERROR_LOG_TRUNCATED=The error log you see on this page has been truncated to the most recent entries.
DELETE_LOG=Delete log
CLEAR_LOG=Clear log
DOWNLOAD_LOG=Download log
@@ -21,5 +22,6 @@ CRON_UPGRADE_PENDING=The scheduler is currently disabled because an upgrade is p
CRON_NOT_RUNNING=The system scheduler is not running or has not run for over a day. Please check the <a href="{1}" target="_blank" title="Configuration Tutorial (Opens in new window)">configuration tutorial</a> to learn how to set up the scheduler.
LOCKED_HOOKS=You have one or more locked hooks. Either they are taking a long time, or they bailed on an error (in which case they are restricted from running more than once per day until they succeed). Please review any errors encountered. Fix the ones that can be fixed, and report the others to the the software issue tracker. Manually running a hook will clear its lock if successful.
LOG_LEVEL=Log level
RELAYED=Relayed?

IS_LOCKED_RUNNING=Yes (running)
+8 −2
Original line number Diff line number Diff line
@@ -1279,11 +1279,17 @@ function relay_error_notification(string $text, bool $developers = true, string
            } else {
                $url = get_brand_base_url() . '/data_custom/composr_homesite_web_service.php?call=relay_error_notification';
                $error_code = null;
                $error_message = null;
                $error_message = '';
                $response = cms_fsock_request($payload, $url, $error_code, $error_message);
                if (($response === null) || ($error_message !== null)) {
                if (($response === null) || ($error_message != '')) {
                    cms_error_log(brand_name() . ' telemetry: WARNING Could not forward error to the developers. ' . $error_message . (($response === null) ? '' : escape_html($response)));
                }
                $matches = [];
                if (preg_match('#\srelayed_error_id=(\d*)\s#', $response, $matches) != 0) {
                    if ((php_function_allowed('error_log')) && (file_exists(get_custom_file_base() . '/data_custom/errorlog.php')) && (cms_is_writable(get_custom_file_base() . '/data_custom/errorlog.php'))) {
                        @error_log('TELEMETRY ' . strval($matches[1]) . "\n", 3, get_file_base() . '/data_custom/errorlog.php');
                    }
                }
            }
        }
    }
+32 −3
Original line number Diff line number Diff line
@@ -218,7 +218,36 @@ function get_tutorial_url(?string $tutorial) : string
function get_brand_page_url(array $params, string $zone) : string
{
    // Assumes brand site supports .htm URLs, which it should
    return get_brand_base_url() . (($zone == '') ? '' : '/') . $zone . '/' . urlencode(str_replace('_', '-', $params['page'])) . '.htm';
    $base = get_brand_base_url() . (($zone == '') ? '' : '/') . $zone . '/';
    if (isset($params['page'])) {
        $base .= urlencode(str_replace('_', '-', $params['page']));
        if (isset($params['type'])) {
            $base .= '/' . urlencode(str_replace('_', '-', $params['type']));
            if (isset($params['id'])) {
                $base .= '/' . urlencode(str_replace('_', '-', $params['id'])) . '.htm';
                unset($params['id']);
            } else {
                $base .= '.htm';
            }
            unset($params['type']);
        }
        unset($params['page']);
    } else {
        $base .= '.htm';
    }

    $query_string = '';
    foreach ($params as $k => $v) {
        if ($query_string == '') {
            $query_string .= '?';
        } else {
            $query_string .= '&';
        }

        $query_string .= $k . '=' . cms_urlencode($v);
    }

    return $base . $query_string;
}

/**
@@ -507,11 +536,11 @@ function cms_http_request(string $url, array $options = []) : object
 * @param  string $payload The payload to send (blank: make a GET request)
 * @param  URLPATH $url The URL to call including the path and port
 * @param  ?integer $error_code The error code returned (passed by reference) (null: No error)
 * @param  ?string $error_message The error message returned (passed by reference) (null: No error)
 * @param  string $error_message The error message returned (passed by reference) (blank: No error)
 * @param  float $timeout The timeout in seconds
 * @return ?string response from the fsock (null: error)
 */
function cms_fsock_request(string $payload, string $url, ?int &$error_code = null, ?string &$error_message = null, float $timeout = 6.0) : ?string
function cms_fsock_request(string $payload, string $url, ?int &$error_code = null, ?string &$error_message = '', float $timeout = 6.0) : ?string
{
    cms_profile_start_for('cms_fsock_request');