diff --git a/www/resources/views/pages/testhistory.blade.php b/www/resources/views/pages/testhistory.blade.php
index ea8c6957bb..77bf3920a9 100644
--- a/www/resources/views/pages/testhistory.blade.php
+++ b/www/resources/views/pages/testhistory.blade.php
@@ -24,7 +24,7 @@
-
+
@endif
diff --git a/www/resources/views/pages/testhistoryadmin.blade.php b/www/resources/views/pages/testhistoryadmin.blade.php
new file mode 100644
index 0000000000..0ad347e1e1
--- /dev/null
+++ b/www/resources/views/pages/testhistoryadmin.blade.php
@@ -0,0 +1,123 @@
+@extends('default')
+
+@section('content')
+
+
+
Test History{{$all}}
+
+
+
+
+
+@endsection
\ No newline at end of file
diff --git a/www/testlog.php b/www/testlog.php
index c637f69d20..5a934676f8 100644
--- a/www/testlog.php
+++ b/www/testlog.php
@@ -5,48 +5,70 @@
// found in the LICENSE.md file.
require_once __DIR__ . '/common.inc';
+use WebPageTest\Exception\ForbiddenException;
use WebPageTest\Util;
-$host = Util::getSetting('host');
-$protocol = $request_context->getUrlProtocol();
+// why are you even here
+if ($userIsBot || Util::getSetting('disableTestlog')) {
+ throw new ForbiddenException();
+}
+// login status
$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated());
+// Redirect logged-in saml users to the hosted test history if one is configured
+if (!$is_logged_in && (isset($USER_EMAIL) && Util::getSetting('history_url') && !isset($_REQUEST['local']))) {
+ header('Location: ' . Util::getSetting('history_url'));
+ exit;
+}
+
if ($admin || $privateInstall || $is_logged_in) {
set_time_limit(0);
} else {
set_time_limit(60);
}
-if ($userIsBot || Util::getSetting('disableTestlog')) {
- header('HTTP/1.0 403 Forbidden');
- exit;
-}
+$csv = isset($_GET['f']) && !strcasecmp($_GET['f'], 'csv');
+$priority = (isset($_REQUEST['priority']) && is_numeric($_REQUEST['priority'])) ? intval($_REQUEST['priority']) : null;
+$days = (int)($_GET['days'] ?? 7);
-$test_history = [];
-$default_days = 7;
-$days = (int)($_GET["days"] ?? $default_days);
+$GLOBALS['tab'] = 'Test History';
+$GLOBALS['page_description'] = 'History of website performance speed tests run on WebPageTest.';
-if ($is_logged_in) {
- $test_history = $request_context->getClient()->getTestHistory($days);
-}
+//
+// single user history
+//
+if (!$csv && ($is_logged_in || (!isset($user) && !isset($_COOKIE['google_email']) && Util::getSetting('localHistory')))) {
+ if ($is_logged_in) {
+ $test_history = $request_context->getClient()->getTestHistory($days);
+ }
+ $vars = [
+ 'is_logged_in' => $is_logged_in,
+ 'protocol' => $request_context->getUrlProtocol(),
+ 'host' => Util::getSetting('host'),
+ 'days' => $days,
+ 'test_history' => $test_history,
+ 'priority' => $priority,
+ 'local' => isset($_REQUEST['local']) && $_REQUEST['local'],
+ 'body_class' => 'history',
+ 'page_title' => 'WebPageTest - Test History',
-// Redirect logged-in saml users to the hosted test history if one is configured
-if (!$is_logged_in && (isset($USER_EMAIL) && Util::getSetting('history_url') && !isset($_REQUEST['local']))) {
- header('Location: ' . Util::getSetting('history_url'));
- exit;
-}
+ ];
-$page_keywords = array('Log', 'History', 'WebPageTest', 'Website Speed Test');
-$page_description = "History of website performance speed tests run on WebPageTest.";
+ echo view('pages.testhistory', $vars);
+ exit();
+}
+//
+// parse and display /logs/*.log
+// in HTML (Blade) or CSV
+//
$supportsGrep = false;
$out = exec('grep --version', $output, $result_code);
if ($result_code == 0 && isset($output) && is_array($output) && count($output)) {
$supportsGrep = true;
}
-
$from = (isset($_GET["from"]) && strlen($_GET["from"])) ? $_GET["from"] : 'now';
$filter = $_GET["filter"];
$filterstr = $filter ? preg_replace('/[^a-zA-Z0-9 \@\/\:\.\(\))\-\+]/', '', strtolower($filter)) : null;
@@ -54,12 +76,9 @@
$all = !empty($_REQUEST['all']);
$repeat = !empty($_REQUEST['repeat']);
$nolimit = !empty($_REQUEST['nolimit']);
-$csv = isset($_GET["f"]) && !strcasecmp($_GET["f"], 'csv');
-$priority = (isset($_REQUEST['priority']) && is_numeric($_REQUEST['priority'])) ? intval($_REQUEST['priority']) : null;
if (!$privateInstall && $all && $days > 7 && !strlen(trim($filterstr))) {
- header('HTTP/1.0 403 Forbidden');
- exit;
+ throw new ForbiddenException();
}
if (isset($USER_EMAIL) && !isset($user)) {
@@ -77,303 +96,213 @@
$includePrivate = isset($_GET["private"]) && (int)$_GET["private"] == 1;
}
-function check_it($val)
-{
- if ($val) {
- echo ' checked ';
- }
-}
-
-// single user history
-if (!$csv && ($is_logged_in || (!isset($user) && !isset($_COOKIE['google_email']) && Util::getSetting('localHistory')))) {
- $GLOBALS['tab'] = 'Test History';
- $vars = [
- 'is_logged_in' => $is_logged_in,
- 'protocol' => $protocol,
- 'host' => $host,
- 'days' => $days,
- 'test_history' => $test_history,
- 'priority' => $priority,
- 'local' => isset($_REQUEST['local']) && $_REQUEST['local'],
- 'body_class' => 'history',
- 'page_title' => 'WebPageTest - Test History',
-
- ];
-
- echo view('pages.testhistory', $vars);
- exit();
-}
+$history = getHistoryLog($from, $days, $supportsGrep, $all, $filterstr, $onlyVideo, $includePrivate, $repeat, $nolimit);
+// CSV results
if ($csv) {
header("Content-type: text/csv");
echo '"Date/Time","Location","Test ID","URL","Label"' . "\r\n";
-} else {
- ?>
-
-
-
-
-