<?php include 'common.inc'; require_once 'benchmarks/data.inc.php'; // see if we are processing an import or presenting the UI if (array_key_exists('tests', $_REQUEST) && array_key_exists('benchmark', $_REQUEST)) { $error = null; if (ValidateKey()) { $test_data = json_decode($_REQUEST['tests'], true); if ($test_data && is_array($test_data) && count($test_data)) { $epoch = time(); if (array_key_exists('epoch', $_REQUEST) && intval($_REQUEST['epoch']) > 0) { $epoch = intval($_REQUEST['epoch']); } $benchmark = trim($_REQUEST['benchmark']); if (strlen($benchmark) && is_file("./settings/benchmarks/{$benchmark}.php")) { ImportBenchmarkRun($benchmark, $epoch, $test_data); } else { $error = "Invalid benchmark"; } } else { $error = "Invalid test data json"; } } else { // Invalid API key = block if keys are configured (for now anyway) header('HTTP/1.0 403 Forbidden'); echo 'Access Denied. Invalid API Key'; } $ret = array('statusCode' => 200, 'statusText' => 'OK'); if (isset($error)) { $ret['statusCode'] = 400;
/** * A relay test came in, should include a job file already * */ function RelayTest() { global $error; global $locations; $error = null; $ret = array(); $ret['statusCode'] = 200; $rkey = $_POST['rkey']; $test = json_decode($_POST['testinfo'], true); $job = trim($_POST['job']); $ini = trim($_POST['ini']); $location = trim($_POST['location']); $test['workdir'] = $locations[$location]['localDir']; ValidateKey($test, $error, $rkey); if (!isset($error)) { $id = $rkey . '.' . $test['id']; $ret['id'] = $id; $test['job'] = $rkey . '.' . $test['job']; $testPath = './' . GetTestPath($id); @mkdir($testPath, 0777, true); $job = str_replace($test['id'], $id, $job); file_put_contents("{$testPath}/testinfo.ini", $ini); WriteJob($location, $test, $job, $id); SaveTestInfo($id, $test); } if (isset($error)) { $ret['statusCode'] = 400; $ret['statusText'] = "Relay: {$error}"; } header("Content-type: application/json"); echo json_encode($ret); }
function process($data) { $result = ValidateKey($data); return $result; }