PageRenderTime 19ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/details/har.php

http://showslow.googlecode.com/
PHP | 79 lines | 66 code | 13 blank | 0 comment | 14 complexity | 73ff7ac1b94f2ffc0acb287338ad475e MD5 | raw file
  1. <?php
  2. require_once(dirname(dirname(__FILE__)).'/global.php');
  3. if (!array_key_exists('id', $_GET) && (!array_key_exists('url', $_GET) || filter_var($_GET['url'], FILTER_VALIDATE_URL) === false)) {
  4. header('HTTP/1.0 400 Bad Request');
  5. ?><html>
  6. <head>
  7. <title>Bad Request: no valid url or har id specified</title>
  8. </head>
  9. <body>
  10. <h1>Bad Request: no valid url or har id specified</h1>
  11. <p>You must pass valid URL as 'url' parameter or HAR file ID as 'id' parameter</p>
  12. </body></html>
  13. <?php
  14. exit;
  15. }
  16. if (array_key_exists('id', $_GET)) {
  17. $query = sprintf("SELECT har, compressed FROM har WHERE id = '%d'",
  18. mysql_real_escape_string($_GET['id'])
  19. );
  20. }
  21. else
  22. {
  23. $query = sprintf("SELECT UNIX_TIMESTAMP(timestamp) as t, har, compressed
  24. FROM har, urls WHERE urls.url = '%s' AND har.url_id = urls.id ORDER BY timestamp DESC LIMIT 1",
  25. mysql_real_escape_string($_GET['url'])
  26. );
  27. }
  28. $result = mysql_query($query);
  29. if (!$result) {
  30. error_log(mysql_error());
  31. }
  32. $harp = false;
  33. if (array_key_exists('callback', $_GET)) {
  34. $harp = $_GET['callback'];
  35. if (!preg_match('/^[a-z]([a-z0-9\.]*[a-z0-9])?$/i', $harp)) {
  36. $harp = false;
  37. }
  38. }
  39. if ($row = mysql_fetch_assoc($result)) {
  40. header('Content-type: text/plain');
  41. if (array_key_exists('id', $_GET)) {
  42. header('Expires: '.date('r', time() + 315569260));
  43. header('Cache-control: max-age=315569260');
  44. }
  45. if ($harp) {
  46. echo $harp.'(';
  47. }
  48. echo $row['compressed'] ? gzuncompress($row['har']) : $row['har'];
  49. if ($harp) {
  50. echo ');';
  51. }
  52. }
  53. else
  54. {
  55. header('HTTP/1.0 404 No HAR(P) found');
  56. ?><html>
  57. <head>
  58. <title>404 No HAR<?php if ($harp) {?>P<?php } ?> found</title>
  59. </head>
  60. <body>
  61. <h1>404 No HAR<?php if ($harp) {?>P<?php } ?> found</h1>
  62. <p>No HAR<?php if ($harp) {?>P<?php } ?> data found</p>
  63. </body></html>
  64. <?php
  65. exit;
  66. }