$flattenUploadedZippedHar = arrayLookupWithDefault('flattenZippedHar', $_REQUEST, false); // The following params are set by the android agents (blaze and WebpageTest). // TODO(skerner): POST params are not saved to disk directly, so it is hard to // see what the agent uploaded after the fact. Consider writing them to a // file that gets uploaded. $runNumber = arrayLookupWithDefault('_runNumber', $_REQUEST, null); $runNumber = arrayLookupWithDefault('run', $_REQUEST, $runNumber); $runIndex = arrayLookupWithDefault('index', $_REQUEST, null); $cacheWarmed = arrayLookupWithDefault('_cacheWarmed', $_REQUEST, null); $cacheWarmed = arrayLookupWithDefault('cached', $_REQUEST, $cacheWarmed); $docComplete = arrayLookupWithDefault('_docComplete', $_REQUEST, null); $onFullyLoaded = arrayLookupWithDefault('_onFullyLoaded', $_REQUEST, null); $onRender = arrayLookupWithDefault('_onRender', $_REQUEST, null); $urlUnderTest = arrayLookupWithDefault('_urlUnderTest', $_REQUEST, null); $testInfo_dirty = false; if (ValidateTestId($id)) { $testPath = './' . GetTestPath($id); if (array_key_exists('video', $_REQUEST) && $_REQUEST['video']) { logMsg("Video file {$id} received from {$_REQUEST['location']}"); $dir = './' . GetVideoPath($id); if (array_key_exists('file', $_FILES) && array_key_exists('tmp_name', $_FILES['file'])) { if (!is_dir($dir)) { mkdir($dir, 0777, true); } $dest = $dir . '/video.mp4'; move_uploaded_file($_FILES['file']['tmp_name'], $dest); @chmod($dest, 0666); $iniFile = $dir . '/video.ini'; if (is_file($iniFile)) { $ini = file_get_contents($iniFile); } else {
/** * Write out the actual job file */ function WriteJob($location, &$test, &$job, $testId) { $ret = false; global $error; global $locations; if ($locations[$location]['relayServer']) { // upload the test to a the relay server $test['id'] = $testId; $ret = SendToRelay($test, $job); } else { // make sure the work directory exists if (!is_dir($test['workdir'])) { mkdir($test['workdir'], 0777, true); } $workDir = $test['workdir']; $locationLock = LockLocation($location); if (isset($locationLock)) { if (isset($test['affinity'])) { $test['job'] = "Affinity{$test['affinity']}.{$test['job']}"; } $fileName = $test['job']; $file = "{$workDir}/{$fileName}"; if (file_put_contents($file, $job)) { if (AddJobFile($workDir, $fileName, $test['priority'], $test['queue_limit'])) { // store a copy of the job file with the original test in case the test fails and we need to resubmit it $test['job_file'] = realpath($file); if (ValidateTestId($testId)) { $testPath = GetTestPath($testId); if (strlen($testPath)) { $testPath = './' . $testPath; if (!is_dir($testPath)) { mkdir($testPath, 0777, true); } file_put_contents("{$testPath}/test.job", $job); } } $tests = json_decode(file_get_contents("./tmp/{$location}.tests"), true); if (!$tests) { $tests = array(); } $testCount = $test['runs']; if (!$test['fvonly']) { $testCount *= 2; } if (array_key_exists('tests', $tests)) { $tests['tests'] += $testCount; } else { $tests['tests'] = $testCount; } file_put_contents("./tmp/{$location}.tests", json_encode($tests)); $ret = true; } else { unlink($file); $error = "Sorry, that test location already has too many tests pending. Pleasy try again later."; } } UnlockLocation($locationLock); } } return $ret; }
<?php // Compare the end-state frames across multiple tests and report how similar they are. // Only JSON responses are supported. chdir('..'); include 'common_lib.inc'; require_once 'video/visualProgress.inc.php'; $result = array('statusCode' => 200, 'data' => array()); if (isset($_REQUEST['tests'])) { $tests = explode(',', $_REQUEST['tests']); $baseline = null; foreach ($tests as $params) { if (preg_match('/(?P<id>[0-9a-zA-Z_]+)-r\\:(?P<run>[0-9]+)/', $params, $matches)) { $test = $matches['id']; $run = $matches['run']; if (ValidateTestId($test)) { RestoreTest($test); $result['data'][$test] = -1; $histogram = GetLastFrameHistogram($test, $run); if (isset($histogram)) { if (isset($baseline)) { $result['data'][$test] = CompareHistograms($histogram, $baseline); } else { $result['data'][$test] = 100; $baseline = $histogram; } } } } } }
$tests = array(); $fastest = null; $ready = true; $error = null; $endTime = 'visual'; $supports60fps = false; if (array_key_exists('end', $_REQUEST) && strlen($_REQUEST['end'])) { $endTime = trim($_REQUEST['end']); } $compTests = explode(',', $_REQUEST['tests']); foreach ($compTests as $t) { $parts = explode('-', $t); if (count($parts) >= 1) { $test = array(); $test['id'] = $parts[0]; if (ValidateTestId($test['id'])) { $test['cached'] = 0; $test['end'] = $endTime; for ($i = 1; $i < count($parts); $i++) { $p = explode(':', $parts[$i]); if (count($p) >= 2) { if ($p[0] == 'r') { $test['run'] = (int) $p[1]; } if ($p[0] == 'l') { $test['label'] = $p[1]; } if ($p[0] == 'c') { $test['cached'] = (int) $p[1]; } if ($p[0] == 'e') {
/** * Parse the list of tests and identify the screen shots to compare * */ function ParseTests() { $tests = array(); global $median_metric; if (isset($_REQUEST['tests'])) { $groups = explode(',', $_REQUEST['tests']); foreach ($groups as $group) { $parts = explode('-', $group); if (count($parts) >= 1 && ValidateTestId($parts[0])) { $test = array(); $test['id'] = $parts[0]; $test['cached'] = 0; for ($i = 1; $i < count($parts); $i++) { $p = explode(':', $parts[$i]); if (count($p) >= 2) { if ($p[0] == 'r') { $test['run'] = (int) $p[1]; } if ($p[0] == 'l') { $test['label'] = $p[1]; } if ($p[0] == 'c') { $test['cached'] = (int) $p[1]; } } } RestoreTest($test['id']); $test['path'] = GetTestPath($test['id']); if (!isset($test['run'])) { $pageData = loadAllPageData($test['path']); $test['run'] = GetMedianRun($pageData, $test['cached'], $median_metric); } if (!isset($test['label'])) { $label = getLabel($test['id'], $user); if (!empty($label)) { $test['label'] = $new_label; } else { $info = GetTestInfo($test['id']); if ($info && isset($info['label']) && strlen($info['label'])) { $test['label'] = trim($info['label']); } } } if (!isset($test['label'])) { $test['label'] = $test['id']; } $cachedText = ''; if ($test['cached']) { $cachedText = '_Cached'; } $fileBase = "{$test['path']}/{$test['run']}{$cachedText}_screen"; if (is_file("{$fileBase}.png")) { $test['image'] = "{$fileBase}.png"; } elseif (is_file("{$fileBase}.jpg")) { $test['image'] = "{$fileBase}.jpg"; } if (isset($test['image'])) { $size = getimagesize($test['image']); if ($size && count($size) >= 2 && $size[0] > 0 && $size[1] > 0) { $test['width'] = $size[0]; $test['height'] = $size[1]; $tests[] = $test; } } } } } if (!count($tests)) { unset($tests); } return $tests; }
<?php chdir('..'); include 'common.inc'; $id = $_REQUEST['id']; $file = './' . GetVideoPath($id) . '/video.mp4'; if (ValidateTestId($id) && is_file($file)) { header('Content-disposition: attachment; filename=video.mp4'); header('Content-type: video/mp4'); readfile_chunked($file); } else { ?> <!DOCTYPE html> <html> <head> <title>WebPagetest - Visual Comparison</title> <?php $gaTemplate = 'Video Download Error'; include 'head.inc'; ?> <style type="text/css"> div.content { text-align:center; background: black; color: white; font-family: arial,sans-serif } .link { text-decoration: none;
ob_start(); set_time_limit(300); include 'common.inc'; $pub = $settings['publishTo']; if (!isset($pub) || !strlen($pub)) { $pub = $_SERVER['HTTP_HOST']; } $noheaders = false; if (array_key_exists('noheaders', $_REQUEST) && $_REQUEST['noheaders']) { $noheaders = true; } $id = null; if (array_key_exists('test', $_REQUEST) && strlen($_REQUEST['test'])) { $id = $_REQUEST['test']; ValidateTestId($id); } $page_keywords = array('Publish', 'Webpagetest', 'Website Speed Test', 'Page Speed'); $page_description = "Publish test results to WebPagetest."; ?> <!DOCTYPE html> <html> <head> <title>WebPagetest - Publish</title> <?php $gaTemplate = 'Publish'; include 'head.inc'; ?> </head> <body> <div class="page">
$url = $pageData['URL']; } $bulk['urls'][] = array('u' => $url, 'id' => $test_id); } } gz_file_put_contents("{$testPath}/bulk.json", json_encode($bulk)); // Return the test ID (or redirect if not using the API) TestResult($test, $error); } elseif (array_key_exists('devtools', $_FILES)) { if (ValidateKey()) { /**************************************************************************** * Importing a test ****************************************************************************/ $id = null; $error = null; if (array_key_exists('test', $_REQUEST) && ValidateTestId($_REQUEST['test'])) { $id = $_REQUEST['test']; RestoreTest($id); $test = GetTestInfo($id); if ($test) { $test['runs']++; $run = $test['runs']; if ((array_key_exists('key', $test) && strlen($test['key']) || array_key_exists('k', $_REQUEST) && strlen($_REQUEST['k'])) && $_REQUEST['k'] !== $test['key']) { $error = "API Key Doesn't match key for existing test"; } } else { $error = "Invalid Test ID"; } } else { $test = array('runs' => 1, 'discard' => 0, 'fvonly' => 1); $test['location'] = 'Imported';
<?php require_once './common.inc'; if (array_key_exists('original', $_REQUEST) && array_key_exists('optimized', $_REQUEST)) { $original = $_REQUEST['original']; $optimized = $_REQUEST['optimized']; if (ValidateTestId($original) && ValidateTestId($optimized)) { // Write out the fake testinfo (use the original test as a template) $today = new DateTime("now", new DateTimeZone('UTC')); $test = GetTestInfo($original); if (isset($test) && is_array($test) && count($test)) { $test['id'] = $today->format('ymd') . '_PSS_' . md5(uniqid(rand(), true)); $test['path'] = './' . GetTestPath($test['id']); $test['batch'] = 1; $test['label'] = 'PageSpeed Service Comparison'; if (array_key_exists('url', $test) && strlen($test['url'])) { $test['label'] .= ' for ' . $test['url']; } $test['view'] = 'pss'; if (!is_dir($test['path'])) { mkdir($test['path'], 0777, true); } SaveTestInfo($test['id'], $test); // write out the bulk test data $tests = array(); $tests['variations'] = array(); $tests['urls'] = array(); $tests['urls'][] = array('u' => $test['url'], 'l' => 'Original', 'id' => $original); $tests['urls'][] = array('u' => $test['url'], 'l' => 'Optimized', 'id' => $optimized); gz_file_put_contents("./{$test['path']}/bulk.json", json_encode($tests)); // redirect