PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/dist/webpagetest/www/work/dopublish.php

http://webpagetest.googlecode.com/
PHP | 58 lines | 42 code | 10 blank | 6 comment | 8 complexity | 328184ca6986d9fb63a8e5251a07ce66 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-3.0, LGPL-3.0, MIT, BSD-3-Clause, ISC, LGPL-2.1
  1. <?php
  2. chdir('..');
  3. include 'common.inc';
  4. require_once('./lib/pclzip.lib.php');
  5. header('Content-type: text/plain');
  6. header("Cache-Control: no-cache, must-revalidate");
  7. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  8. set_time_limit(300);
  9. // make sure a file was uploaded
  10. if( isset($_FILES['file']) )
  11. {
  12. $fileName = $_FILES['file']['name'];
  13. // create a new test id
  14. $today = new DateTime("now", new DateTimeZone('America/New_York'));
  15. $id = $today->format('ymd_') . ShardKey(rand()) . md5(uniqid(rand(), true));
  16. $path = './' . GetTestPath($id);
  17. // create the folder for the test results
  18. if( !is_dir($path) )
  19. mkdir($path, 0777, true);
  20. // extract the zip file
  21. $archive = new PclZip($_FILES['file']['tmp_name']);
  22. $list = $archive->extract(PCLZIP_OPT_PATH, "$path/");
  23. if( !$list )
  24. unset($id);
  25. // make sure there are no risky files and that nothing is allowed execute permission
  26. SecureDir($path);
  27. // mark the test as piblished so we won't expose a resubmit
  28. if (gz_is_file("$path/testinfo.json")) {
  29. $testInfo = json_decode(gz_file_get_contents("$path/testinfo.json"), true);
  30. $testInfo['id'] = $id;
  31. $testInfo['job'] = $id;
  32. $testInfo['published'] = true;
  33. if (array_key_exists('noscript', $_REQUEST) && $_REQUEST['noscript'])
  34. $testInfo['script'] = null;
  35. gz_file_put_contents("$path/testinfo.json", json_encode($testInfo));
  36. }
  37. if (is_file("$path/testinfo.ini")) {
  38. $ini = file("$path/testinfo.ini");
  39. foreach ($ini as &$line) {
  40. if (!strncasecmp($line, 'id=', 3)) {
  41. $line = "id=$id\r\n";
  42. }
  43. }
  44. file_put_contents("$path/testinfo.ini", implode('', $ini));
  45. }
  46. echo $id;
  47. }
  48. ?>