Chris@76: $txt['username'],
Chris@76: 'ip' => $txt['ip_address'],
Chris@76: 'session' => $txt['session'],
Chris@76: 'url' => $txt['error_url'],
Chris@76: 'message' => $txt['error_message'],
Chris@76: 'error_type' => $txt['error_type'],
Chris@76: 'file' => $txt['file'],
Chris@76: 'line' => $txt['line'],
Chris@76: );
Chris@76:
Chris@76: // Set up the filtering...
Chris@76: if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
Chris@76: $filter = array(
Chris@76: 'variable' => $_GET['filter'],
Chris@76: 'value' => array(
Chris@76: 'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
Chris@76: ),
Chris@76: 'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
Chris@76: 'entity' => $filters[$_GET['filter']]
Chris@76: );
Chris@76:
Chris@76: // Deleting, are we?
Chris@76: if (isset($_POST['delall']) || isset($_POST['delete']))
Chris@76: deleteErrors();
Chris@76:
Chris@76: // Just how many errors are there?
Chris@76: $result = $smcFunc['db_query']('', '
Chris@76: SELECT COUNT(*)
Chris@76: FROM {db_prefix}log_errors' . (isset($filter) ? '
Chris@76: WHERE ' . $filter['variable'] . ' LIKE {string:filter}' : ''),
Chris@76: array(
Chris@76: 'filter' => isset($filter) ? $filter['value']['sql'] : '',
Chris@76: )
Chris@76: );
Chris@76: list ($num_errors) = $smcFunc['db_fetch_row']($result);
Chris@76: $smcFunc['db_free_result']($result);
Chris@76:
Chris@76: // If this filter is empty...
Chris@76: if ($num_errors == 0 && isset($filter))
Chris@76: redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
Chris@76:
Chris@76: // Clean up start.
Chris@76: if (!isset($_GET['start']) || $_GET['start'] < 0)
Chris@76: $_GET['start'] = 0;
Chris@76:
Chris@76: // Do we want to reverse error listing?
Chris@76: $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
Chris@76:
Chris@76: // Set the page listing up.
Chris@76: $context['page_index'] = constructPageIndex($scripturl . '?action=admin;area=logs;sa=errorlog' . ($context['sort_direction'] == 'down' ? ';desc' : '') . (isset($filter) ? $filter['href'] : ''), $_GET['start'], $num_errors, $modSettings['defaultMaxMessages']);
Chris@76: $context['start'] = $_GET['start'];
Chris@76:
Chris@76: // Find and sort out the errors.
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT id_error, id_member, ip, url, log_time, message, session, error_type, file, line
Chris@76: FROM {db_prefix}log_errors' . (isset($filter) ? '
Chris@76: WHERE ' . $filter['variable'] . ' LIKE {string:filter}' : '') . '
Chris@76: ORDER BY id_error ' . ($context['sort_direction'] == 'down' ? 'DESC' : '') . '
Chris@76: LIMIT ' . $_GET['start'] . ', ' . $modSettings['defaultMaxMessages'],
Chris@76: array(
Chris@76: 'filter' => isset($filter) ? $filter['value']['sql'] : '',
Chris@76: )
Chris@76: );
Chris@76: $context['errors'] = array();
Chris@76: $members = array();
Chris@76:
Chris@76: for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
Chris@76: {
Chris@76: $search_message = preg_replace('~<span class="remove">(.+?)</span>~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
Chris@76: if ($search_message == $filter['value']['sql'])
Chris@76: $search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
Chris@76: $show_message = strtr(strtr(preg_replace('~<span class="remove">(.+?)</span>~', '$1', $row['message']), array("\r" => '', '
' => "\n", '<' => '<', '>' => '>', '"' => '"')), array("\n" => '
'));
Chris@76:
Chris@76: $context['errors'][$row['id_error']] = array(
Chris@76: 'alternate' => $i %2 == 0,
Chris@76: 'member' => array(
Chris@76: 'id' => $row['id_member'],
Chris@76: 'ip' => $row['ip'],
Chris@76: 'session' => $row['session']
Chris@76: ),
Chris@76: 'time' => timeformat($row['log_time']),
Chris@76: 'timestamp' => $row['log_time'],
Chris@76: 'url' => array(
Chris@76: 'html' => htmlspecialchars((substr($row['url'], 0, 1) == '?' ? $scripturl : '') . $row['url']),
Chris@76: 'href' => base64_encode($smcFunc['db_escape_wildcard_string']($row['url']))
Chris@76: ),
Chris@76: 'message' => array(
Chris@76: 'html' => $show_message,
Chris@76: 'href' => base64_encode($search_message)
Chris@76: ),
Chris@76: 'id' => $row['id_error'],
Chris@76: 'error_type' => array(
Chris@76: 'type' => $row['error_type'],
Chris@76: 'name' => isset($txt['errortype_'.$row['error_type']]) ? $txt['errortype_'.$row['error_type']] : $row['error_type'],
Chris@76: ),
Chris@76: 'file' => array(),
Chris@76: );
Chris@76: if (!empty($row['file']) && !empty($row['line']))
Chris@76: {
Chris@76: // Eval'd files rarely point to the right location and cause havoc for linking, so don't link them.
Chris@76: $linkfile = strpos($row['file'], 'eval') === false || strpos($row['file'], '?') === false; // De Morgan's Law. Want this true unless both are present.
Chris@76:
Chris@76: $context['errors'][$row['id_error']]['file'] = array(
Chris@76: 'file' => $row['file'],
Chris@76: 'line' => $row['line'],
Chris@76: 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;file=' . base64_encode($row['file']) . ';line=' . $row['line'],
Chris@76: 'link' => $linkfile ? '' . $row['file'] . '' : $row['file'],
Chris@76: 'search' => base64_encode($row['file']),
Chris@76: );
Chris@76: }
Chris@76:
Chris@76: // Make a list of members to load later.
Chris@76: $members[$row['id_member']] = $row['id_member'];
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: // Load the member data.
Chris@76: if (!empty($members))
Chris@76: {
Chris@76: // Get some additional member info...
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT id_member, member_name, real_name
Chris@76: FROM {db_prefix}members
Chris@76: WHERE id_member IN ({array_int:member_list})
Chris@76: LIMIT ' . count($members),
Chris@76: array(
Chris@76: 'member_list' => $members,
Chris@76: )
Chris@76: );
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: $members[$row['id_member']] = $row;
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: // This is a guest...
Chris@76: $members[0] = array(
Chris@76: 'id_member' => 0,
Chris@76: 'member_name' => '',
Chris@76: 'real_name' => $txt['guest_title']
Chris@76: );
Chris@76:
Chris@76: // Go through each error and tack the data on.
Chris@76: foreach ($context['errors'] as $id => $dummy)
Chris@76: {
Chris@76: $memID = $context['errors'][$id]['member']['id'];
Chris@76: $context['errors'][$id]['member']['username'] = $members[$memID]['member_name'];
Chris@76: $context['errors'][$id]['member']['name'] = $members[$memID]['real_name'];
Chris@76: $context['errors'][$id]['member']['href'] = empty($memID) ? '' : $scripturl . '?action=profile;u=' . $memID;
Chris@76: $context['errors'][$id]['member']['link'] = empty($memID) ? $txt['guest_title'] : '' . $context['errors'][$id]['member']['name'] . '';
Chris@76: }
Chris@76: }
Chris@76:
Chris@76: // Filtering anything?
Chris@76: if (isset($filter))
Chris@76: {
Chris@76: $context['filter'] = &$filter;
Chris@76:
Chris@76: // Set the filtering context.
Chris@76: if ($filter['variable'] == 'id_member')
Chris@76: {
Chris@76: $id = $filter['value']['sql'];
Chris@76: loadMemberData($id, false, 'minimal');
Chris@76: $context['filter']['value']['html'] = '' . $user_profile[$id]['real_name'] . '';
Chris@76: }
Chris@76: elseif ($filter['variable'] == 'url')
Chris@76: $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
Chris@76: elseif ($filter['variable'] == 'message')
Chris@76: {
Chris@76: $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars($filter['value']['sql']), array("\n" => '
', '<br />' => '
', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
Chris@76: $context['filter']['value']['html'] = preg_replace('~<span class="remove">(.+?)</span>~', '$1', $context['filter']['value']['html']);
Chris@76: }
Chris@76: elseif ($filter['variable'] == 'error_type')
Chris@76: {
Chris@76: $context['filter']['value']['html'] = '\'' . strtr(htmlspecialchars($filter['value']['sql']), array("\n" => '
', '<br />' => '
', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
Chris@76: }
Chris@76: else
Chris@76: $context['filter']['value']['html'] = &$filter['value']['sql'];
Chris@76: }
Chris@76:
Chris@76: $context['error_types'] = array();
Chris@76:
Chris@76: $context['error_types']['all'] = array(
Chris@76: 'label' => $txt['errortype_all'],
Chris@76: 'description' => isset($txt['errortype_all_desc']) ? $txt['errortype_all_desc'] : '',
Chris@76: 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog' . ($context['sort_direction'] == 'down' ? ';desc' : ''),
Chris@76: 'is_selected' => empty($filter),
Chris@76: );
Chris@76:
Chris@76: $sum = 0;
Chris@76: // What type of errors do we have and how many do we have?
Chris@76: $request = $smcFunc['db_query']('', '
Chris@76: SELECT error_type, COUNT(*) AS num_errors
Chris@76: FROM {db_prefix}log_errors
Chris@76: GROUP BY error_type
Chris@76: ORDER BY error_type = {string:critical_type} DESC, error_type ASC',
Chris@76: array(
Chris@76: 'critical_type' => 'critical',
Chris@76: )
Chris@76: );
Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76: {
Chris@76: // Total errors so far?
Chris@76: $sum += $row['num_errors'];
Chris@76:
Chris@76: $context['error_types'][$sum] = array(
Chris@76: 'label' => (isset($txt['errortype_' . $row['error_type']]) ? $txt['errortype_' . $row['error_type']] : $row['error_type']) . ' (' . $row['num_errors'] . ')',
Chris@76: 'description' => isset($txt['errortype_' . $row['error_type'] . '_desc']) ? $txt['errortype_' . $row['error_type'] . '_desc'] : '',
Chris@76: 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog' . ($context['sort_direction'] == 'down' ? ';desc' : '') . ';filter=error_type;value=' . $row['error_type'],
Chris@76: 'is_selected' => isset($filter) && $filter['value']['sql'] == $smcFunc['db_escape_wildcard_string']($row['error_type']),
Chris@76: );
Chris@76: }
Chris@76: $smcFunc['db_free_result']($request);
Chris@76:
Chris@76: // Update the all errors tab with the total number of errors
Chris@76: $context['error_types']['all']['label'] .= ' (' . $sum . ')';
Chris@76:
Chris@76: // Finally, work out what is the last tab!
Chris@76: if (isset($context['error_types'][$sum]))
Chris@76: $context['error_types'][$sum]['is_last'] = true;
Chris@76: else
Chris@76: $context['error_types']['all']['is_last'] = true;
Chris@76:
Chris@76: // And this is pretty basic ;).
Chris@76: $context['page_title'] = $txt['errlog'];
Chris@76: $context['has_filter'] = isset($filter);
Chris@76: $context['sub_template'] = 'error_log';
Chris@76: }
Chris@76:
Chris@76: // Delete errors from the database.
Chris@76: function deleteErrors()
Chris@76: {
Chris@76: global $filter, $smcFunc;
Chris@76:
Chris@76: // Make sure the session exists and is correct; otherwise, might be a hacker.
Chris@76: checkSession();
Chris@76:
Chris@76: // Delete all or just some?
Chris@76: if (isset($_POST['delall']) && !isset($filter))
Chris@76: $smcFunc['db_query']('truncate_table', '
Chris@76: TRUNCATE {db_prefix}log_errors',
Chris@76: array(
Chris@76: )
Chris@76: );
Chris@76: // Deleting all with a filter?
Chris@76: elseif (isset($_POST['delall']) && isset($filter))
Chris@76: $smcFunc['db_query']('', '
Chris@76: DELETE FROM {db_prefix}log_errors
Chris@76: WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
Chris@76: array(
Chris@76: 'filter' => $filter['value']['sql'],
Chris@76: )
Chris@76: );
Chris@76: // Just specific errors?
Chris@76: elseif (!empty($_POST['delete']))
Chris@76: {
Chris@76: $smcFunc['db_query']('', '
Chris@76: DELETE FROM {db_prefix}log_errors
Chris@76: WHERE id_error IN ({array_int:error_list})',
Chris@76: array(
Chris@76: 'error_list' => array_unique($_POST['delete']),
Chris@76: )
Chris@76: );
Chris@76:
Chris@76: // Go back to where we were.
Chris@76: redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '') . ';start=' . $_GET['start'] . (isset($filter) ? ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'] : ''));
Chris@76: }
Chris@76:
Chris@76: // Back to the error log!
Chris@76: redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
Chris@76: }
Chris@76:
Chris@76: function ViewFile()
Chris@76: {
Chris@76: global $context, $txt, $boarddir, $sourcedir, $cachedir;
Chris@76: // Check for the administrative permission to do this.
Chris@76: isAllowedTo('admin_forum');
Chris@76:
Chris@76: // Decode the file and get the line
Chris@76: $file = realpath(base64_decode($_REQUEST['file']));
Chris@76: $real_board = realpath($boarddir);
Chris@76: $real_source = realpath($sourcedir);
Chris@76: $real_cache = realpath($cachedir);
Chris@76: $basename = strtolower(basename($file));
Chris@76: $ext = strrchr($basename, '.');
Chris@76: $line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
Chris@76:
Chris@76: // Make sure the file we are looking for is one they are allowed to look at
Chris@76: if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
Chris@76: fatal_lang_error('error_bad_file', true, array(htmlspecialchars($file)));
Chris@76:
Chris@76: // get the min and max lines
Chris@76: $min = $line - 20 <= 0 ? 1 : $line - 20;
Chris@76: $max = $line + 21; // One additional line to make everything work out correctly
Chris@76:
Chris@76: if ($max <= 0 || $min >= $max)
Chris@76: fatal_lang_error('error_bad_line');
Chris@76:
Chris@76: $file_data = explode('
', highlight_php_code(htmlspecialchars(implode('', file($file)))));
Chris@76:
Chris@76: // We don't want to slice off too many so lets make sure we stop at the last one
Chris@76: $max = min($max, max(array_keys($file_data)));
Chris@76:
Chris@76: $file_data = array_slice($file_data, $min-1, $max - $min);
Chris@76:
Chris@76: $context['file_data'] = array(
Chris@76: 'contents' => $file_data,
Chris@76: 'min' => $min,
Chris@76: 'target' => $line,
Chris@76: 'file' => strtr($file, array('"' => '\\"')),
Chris@76: );
Chris@76:
Chris@76: loadTemplate('Errors');
Chris@76: $context['template_layers'] = array();
Chris@76: $context['sub_template'] = 'show_file';
Chris@76:
Chris@76: }
Chris@76:
Chris@76: ?>