function ProcessHARText($testPath, $harIsFromSinglePageLoad) { $mergedHar = null; $dir = opendir($testPath); if ($dir) { while ($file = readdir($dir)) { if (preg_match("/^(\\d+_(Cached_)?)?results?\\.har\$/", $file)) { // Read and parse the json HAR file $parsedHar = json_decode(file_get_contents("{$testPath}/{$file}"), true); gz_compress("{$testPath}/{$file}"); unlink("{$testPath}/{$file}"); if (!$parsedHar) { logMalformedInput("Failed to parse json file '{$file}'"); continue; } if ($mergedHar === null) { $mergedHar = $parsedHar; } else { $mergedHar['log']['pages'] = array_merge($mergedHar['log']['pages'], $parsedHar['log']['pages']); $mergedHar['log']['entries'] = array_merge($mergedHar['log']['entries'], $parsedHar['log']['entries']); } } } } if ($mergedHar === null) { logMalformedInput("Missing result json file"); return; } ProcessHARData($mergedHar, $testPath, $harIsFromSinglePageLoad); }
function CompressTextFiles($testPath) { global $ini; $f = scandir($testPath); foreach ($f as $textFile) { if ($textFile != 'test.log') { logMsg("Checking {$textFile}\n"); if (is_file("{$testPath}/{$textFile}")) { $parts = pathinfo($textFile); $ext = $parts['extension']; if (!strcasecmp($ext, 'txt') || !strcasecmp($ext, 'json') || !strcasecmp($ext, 'log') || !strcasecmp($ext, 'csv')) { if (strpos($textFile, '_optimization')) { unlink("{$testPath}/{$textFile}"); } elseif (gz_compress("{$testPath}/{$textFile}")) { unlink("{$testPath}/{$textFile}"); } } if (isset($ini) && is_array($ini) && isset($ini['sensitive']) && $ini['sensitive'] && strpos($textFile, '_report')) { RemoveSensitiveHeaders($testPath . '/' . basename($textFile, '.gz')); } } } } }
} // generate the test ID $test['id'] = CreateTestID(); $id = $test['id']; $testPath = './' . GetTestPath($id); $test['path'] = $testPath; if (!is_dir($testPath)) { mkdir($testPath, 0777, true); } $run = 1; } if (!isset($error)) { // move the dev tools file over if (array_key_exists('devtools', $_FILES) && array_key_exists('tmp_name', $_FILES['devtools']) && strlen($_FILES['devtools']['tmp_name'])) { move_uploaded_file($_FILES['devtools']['tmp_name'], "{$testPath}/{$run}_devtools.json"); gz_compress("{$testPath}/{$run}_devtools.json"); } // screen shot (if we got one) if (array_key_exists('screenshot', $_FILES) && array_key_exists('tmp_name', $_FILES['screenshot']) && array_key_exists('name', $_FILES['screenshot']) && strlen($_FILES['screenshot']['tmp_name']) && strlen($_FILES['screenshot']['name'])) { $ext = strtolower(pathinfo($_FILES['screenshot']['name'], PATHINFO_EXTENSION)); if ($ext == 'png' || $ext == 'jpg') { move_uploaded_file($_FILES['screenshot']['tmp_name'], "{$testPath}/{$run}_screen.{$ext}"); } } // video (if we got one) if (array_key_exists('video', $_FILES) && array_key_exists('tmp_name', $_FILES['video']) && array_key_exists('name', $_FILES['video']) && strlen($_FILES['video']['tmp_name']) && strlen($_FILES['video']['name'])) { $ext = strtolower(pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION)); if ($ext == 'avi' || $ext == 'mp4') { $test['video'] = 1; move_uploaded_file($_FILES['video']['tmp_name'], "{$testPath}/{$run}_video.{$ext}"); }
protected function ProcessDevTools(&$test, $tempdir, $testPath, $index) { $devtools = array(); $files = glob("{$tempdir}/appurify_results/WSData*"); if (isset($files) && is_array($files) && count($files)) { $outfile = fopen("{$testPath}/{$index}_devtools.json", 'w'); if ($outfile) { fwrite($outfile, "["); foreach ($files as $file) { $this->ProcessDevToolsFile($file, $outfile); } fwrite($outfile, "{}]"); fclose($outfile); gz_compress("{$testPath}/{$index}_devtools.json"); if (is_file("{$testPath}/{$index}_devtools.json.gz")) { unlink("{$testPath}/{$index}_devtools.json"); } } } }
<?php chdir('..'); include 'common.inc'; RestoreTest($id); $traceFile = "{$testPath}/{$run}{$cachedText}_trace.json.gz"; if (!is_file($traceFile) && is_file("{$testPath}/{$run}{$cachedText}_trace.json")) { if (gz_compress("{$testPath}/{$run}{$cachedText}_trace.json")) { unlink("{$testPath}/{$run}{$cachedText}_trace.json"); } } $preamble = __DIR__ . "/trace-viewer/preamble.html"; $conclusion = __DIR__ . "/trace-viewer/conclusion.html"; if (is_file($traceFile) && is_file($preamble) && is_file($conclusion)) { readfile($preamble); $trace = file_get_contents($traceFile); if (isset($trace) && $trace !== false) { $encoded = base64_encode($trace); unset($trace); echo $encoded; } readfile($conclusion); } else { header("HTTP/1.0 404 Not Found"); }