PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/beacon/yslow/index.php

http://showslow.googlecode.com/
PHP | 227 lines | 203 code | 19 blank | 5 comment | 27 complexity | a1171d18643d61d494c730e7a1de9932 MD5 | raw file
  1. <?php
  2. require_once(dirname(dirname(dirname(__FILE__))).'/global.php');
  3. function updateUrlAggregates($url_id, $measurement_id)
  4. {
  5. global $cleanOldYSlowBeaconDetails;
  6. # updating latest values for the URL
  7. $query = sprintf("UPDATE urls SET yslow2_last_id = %d, last_update = now() WHERE id = %d",
  8. mysql_real_escape_string($measurement_id),
  9. mysql_real_escape_string($url_id)
  10. );
  11. $result = mysql_query($query);
  12. if (!$result) {
  13. beaconError(mysql_error());
  14. }
  15. // Clean old details for this URL to conserve space
  16. if ($cleanOldYSlowBeaconDetails) {
  17. # adding new entry
  18. $query = sprintf("/* clean old beacon details */
  19. UPDATE yslow2
  20. SET details = NULL
  21. WHERE url_id = '%d' AND id <> '%d'
  22. ", mysql_real_escape_string($url_id), mysql_real_escape_string($measurement_id));
  23. if (!mysql_query($query))
  24. {
  25. beaconError(mysql_error());
  26. }
  27. }
  28. }
  29. $post_data = file_get_contents("php://input");
  30. $post = json_decode($post_data, true);
  31. if (!is_null($post) && array_key_exists('u', $post) && array_key_exists('g', $post)
  32. && array_key_exists('i', $post) && in_array($post['i'], $YSlow2AllowedProfiles)
  33. && array_key_exists('w', $post) && filter_var($post['w'], FILTER_VALIDATE_INT) !== false
  34. && array_key_exists('o', $post) && filter_var($post['o'], FILTER_VALIDATE_INT) !== false
  35. && array_key_exists('r', $post) && filter_var($post['r'], FILTER_VALIDATE_INT) !== false
  36. )
  37. {
  38. $url_id = getUrlId(urldecode($post['u']));
  39. $grades = $post['g'];
  40. $ynumreq = $grades['ynumreq']['score'];
  41. $ycdn = $grades['ycdn']['score'];
  42. $yexpires = $grades['yexpires']['score'];
  43. $yemptysrc = $grades['yemptysrc']['score'];
  44. $ycompress = $grades['ycompress']['score'];
  45. $ycsstop = $grades['ycsstop']['score'];
  46. $yjsbottom = $grades['yjsbottom']['score'];
  47. $yexpressions = $grades['yexpressions']['score'];
  48. $yexternal = $grades['yexternal']['score'];
  49. $ydns = $grades['ydns']['score'];
  50. $yminify = $grades['yminify']['score'];
  51. $yredirects = $grades['yredirects']['score'];
  52. $ydupes = $grades['ydupes']['score'];
  53. $yetags = $grades['yetags']['score'];
  54. $yxhr = $grades['yxhr']['score'];
  55. $yxhrmethod = $grades['yxhrmethod']['score'];
  56. $ymindom = $grades['ymindom']['score'];
  57. $yno404 = $grades['yno404']['score'];
  58. $ymincookie = $grades['ymincookie']['score'];
  59. $ycookiefree = $grades['ycookiefree']['score'];
  60. $ynofilter = $grades['ynofilter']['score'];
  61. $yimgnoscale = $grades['yimgnoscale']['score'];
  62. $yfavicon = $grades['yfavicon']['score'];
  63. # adding new entry
  64. $query = sprintf("/* grades POST */ INSERT INTO yslow2 (
  65. `ip` , `user_agent` , `url_id` ,
  66. `w` , `o` , `r` , `i` , lt,
  67. `ynumreq`, `ycdn`, `yexpires`, `yemptysrc`, `ycompress`, `ycsstop`,
  68. `yjsbottom`, `yexpressions`, `yexternal`, `ydns`, `yminify`,
  69. `yredirects`, `ydupes`, `yetags`, `yxhr`, `yxhrmethod`,
  70. `ymindom`, `yno404`, `ymincookie`, `ycookiefree`, `ynofilter`,
  71. `yimgnoscale`, `yfavicon`, details
  72. )
  73. VALUES (inet_aton('%s'), '%s', '%d',
  74. '%d', '%d', '%d', '%s', '%d',
  75. '%d', '%d', '%d', '%d', '%d', '%d',
  76. '%d', '%d', '%d', '%d', '%d',
  77. '%d', '%d', '%d', '%d', '%d',
  78. '%d', '%d', '%d', '%d', '%d',
  79. '%d', '%d', '%s'
  80. )",
  81. mysql_real_escape_string($_SERVER['REMOTE_ADDR']),
  82. mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']),
  83. mysql_real_escape_string($url_id),
  84. mysql_real_escape_string($post['w']),
  85. mysql_real_escape_string($post['o']),
  86. mysql_real_escape_string($post['r']),
  87. mysql_real_escape_string($post['i']),
  88. mysql_real_escape_string($post['lt']),
  89. mysql_real_escape_string($ynumreq),
  90. mysql_real_escape_string($ycdn),
  91. mysql_real_escape_string($yexpires),
  92. mysql_real_escape_string($yemptysrc),
  93. mysql_real_escape_string($ycompress),
  94. mysql_real_escape_string($ycsstop),
  95. mysql_real_escape_string($yjsbottom),
  96. mysql_real_escape_string($yexpressions),
  97. mysql_real_escape_string($yexternal),
  98. mysql_real_escape_string($ydns),
  99. mysql_real_escape_string($yminify),
  100. mysql_real_escape_string($yredirects),
  101. mysql_real_escape_string($ydupes),
  102. mysql_real_escape_string($yetags),
  103. mysql_real_escape_string($yxhr),
  104. mysql_real_escape_string($yxhrmethod),
  105. mysql_real_escape_string($ymindom),
  106. mysql_real_escape_string($yno404),
  107. mysql_real_escape_string($ymincookie),
  108. mysql_real_escape_string($ycookiefree),
  109. mysql_real_escape_string($ynofilter),
  110. mysql_real_escape_string($yimgnoscale),
  111. mysql_real_escape_string($yfavicon),
  112. mysql_real_escape_string($post_data)
  113. );
  114. if (!mysql_query($query))
  115. {
  116. beaconError(mysql_error());
  117. }
  118. updateUrlAggregates($url_id, mysql_insert_id());
  119. } else if (array_key_exists('u', $_GET) && array_key_exists('i', $_GET) && in_array($_GET['i'], $YSlow2AllowedProfiles)
  120. && array_key_exists('w', $_GET) && filter_var($_GET['w'], FILTER_VALIDATE_INT) !== false
  121. && array_key_exists('o', $_GET) && filter_var($_GET['o'], FILTER_VALIDATE_INT) !== false
  122. && array_key_exists('r', $_GET) && filter_var($_GET['r'], FILTER_VALIDATE_INT) !== false
  123. )
  124. {
  125. $url_id = getUrlId($_GET['u']);
  126. # adding new entry
  127. $query = sprintf("/* basic GET */ INSERT INTO yslow2 (
  128. `ip` , `user_agent` , `url_id` ,
  129. `w` , `o` , `r` , `i`, lt,
  130. `ynumreq`, `ycdn`, `yexpires`, `yemptysrc`, `ycompress`, `ycsstop`,
  131. `yjsbottom`, `yexpressions`, `yexternal`, `ydns`, `yminify`,
  132. `yredirects`, `ydupes`, `yetags`, `yxhr`, `yxhrmethod`,
  133. `ymindom`, `yno404`, `ymincookie`, `ycookiefree`, `ynofilter`,
  134. `yimgnoscale`, `yfavicon`
  135. )
  136. VALUES (inet_aton('%s'), '%s', '%d',
  137. '%d', '%d', '%d', '%s', '%d',
  138. '%d', '%d', '%d', '%d', '%d', '%d',
  139. '%d', '%d', '%d', '%d', '%d',
  140. '%d', '%d', '%d', '%d', '%d',
  141. '%d', '%d', '%d', '%d', '%d',
  142. '%d', '%d'
  143. )",
  144. mysql_real_escape_string($_SERVER['REMOTE_ADDR']),
  145. mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']),
  146. mysql_real_escape_string($url_id),
  147. mysql_real_escape_string($_GET['w']),
  148. mysql_real_escape_string($_GET['o']),
  149. mysql_real_escape_string($_GET['r']),
  150. mysql_real_escape_string($_GET['i']),
  151. mysql_real_escape_string($_GET['lt']),
  152. mysql_real_escape_string($_GET['ynumreq']),
  153. mysql_real_escape_string($_GET['ycdn']),
  154. mysql_real_escape_string($_GET['yexpires']),
  155. mysql_real_escape_string($_GET['yemptysrc']),
  156. mysql_real_escape_string($_GET['ycompress']),
  157. mysql_real_escape_string($_GET['ycsstop']),
  158. mysql_real_escape_string($_GET['yjsbottom']),
  159. mysql_real_escape_string($_GET['yexpressions']),
  160. mysql_real_escape_string($_GET['yexternal']),
  161. mysql_real_escape_string($_GET['ydns']),
  162. mysql_real_escape_string($_GET['yminify']),
  163. mysql_real_escape_string($_GET['yredirects']),
  164. mysql_real_escape_string($_GET['ydupes']),
  165. mysql_real_escape_string($_GET['yetags']),
  166. mysql_real_escape_string($_GET['yxhr']),
  167. mysql_real_escape_string($_GET['yxhrmethod']),
  168. mysql_real_escape_string($_GET['ymindom']),
  169. mysql_real_escape_string($_GET['yno404']),
  170. mysql_real_escape_string($_GET['ymincookie']),
  171. mysql_real_escape_string($_GET['ycookiefree']),
  172. mysql_real_escape_string($_GET['ynofilter']),
  173. mysql_real_escape_string($_GET['yimgnoscale']),
  174. mysql_real_escape_string($_GET['yfavicon'])
  175. );
  176. if (!mysql_query($query))
  177. {
  178. beaconError(mysql_error());
  179. }
  180. updateUrlAggregates($url_id, mysql_insert_id());
  181. } else {
  182. header('HTTP/1.0 400 Bad Request');
  183. ?><html>
  184. <head>
  185. <title>Bad Request: YSlow beacon</title>
  186. </head>
  187. <body>
  188. <h1>Bad Request: YSlow beacon</h1>
  189. <p>This is <a href="http://developer.yahoo.com/yslow/">YSlow</a> beacon entry point.</p>
  190. <h1>Configure your YSlow</h1>
  191. <p><b style="color: red">WARNING! Only use this beacon If you're OK with all your YSlow data to be recorded by this instance of ShowSlow and displayed at <a href="<?php echo $showslow_base?>"><?php echo $showslow_base?></a><br/>You can also <a href="http://www.showslow.org/Installation_and_configuration">install ShowSlow on your own server</a> to limit the risk.</b></p>
  192. <p>Set these two Firefox parameters on <b>about:config</b> page:</p>
  193. </ul>
  194. <h2>Yslow 2.x</h2>
  195. <ul>
  196. <li>extensions.yslow.beaconUrl = <b style="color: blue"><?php echo $showslow_base?>beacon/yslow/</b></li>
  197. <li>extensions.yslow.beaconInfo = <b style="color: blue">grade</b></li>
  198. <li>extensions.yslow.optinBeacon = <b style="color: blue">true</b></li>
  199. </ul>
  200. </body></html>
  201. <?php
  202. exit;
  203. }
  204. header('HTTP/1.0 204 Data accepted');