if ($har_data === FALSE || json_decode($har_data) === FALSE) { header('HTTP/1.0 400 Bad Request'); ?> <html> <head> <title>Bad Request: malformed HAR data</title> </head> <body> <h1>Bad Request: malformed HAR data</h1> Can't parse JSON data from HAR </body> </html><?php exit; } if (array_key_exists('url', $_REQUEST)) { checkBeaconKey('har'); $url_id = getUrlId(urldecode($_REQUEST['url'])); # adding new entry if (array_key_exists('timestamp', $_REQUEST)) { $query = sprintf("/* HAR POST */ INSERT INTO har (timestamp, url_id, har, compressed)\n\t\tVALUES ('%s', '%d', '%s', '%d')", mysql_real_escape_string($_REQUEST['timestamp']), mysql_real_escape_string($url_id), mysql_real_escape_string(defined('FORCE_GZIP') ? gzcompress($har_data) : $har_data), mysql_real_escape_string(defined('FORCE_GZIP') ? 1 : 0)); } else { $query = sprintf("/* HAR POST */ INSERT INTO har (url_id, har, compressed)\n\t\tVALUES ('%d', '%s', '%d')", mysql_real_escape_string($url_id), mysql_real_escape_string(defined('FORCE_GZIP') ? gzcompress($har_data) : $har_data), mysql_real_escape_string(defined('FORCE_GZIP') ? 1 : 0)); } if (!mysql_query($query)) { beaconError(mysql_error()); } updateUrlAggregates($url_id, mysql_insert_id()); if (count($HAR_processors)) { $har_data_parsed = json_decode($har_data, true); foreach ($HAR_processors as $processor) { if (is_callable($processor)) {
<?php require_once dirname(dirname(dirname(__FILE__))) . '/global.php'; function updateUrlAggregates($url_id, $measurement_id) { # updating latest values for the URL $query = sprintf("UPDATE urls set metric_last_id = %d, last_update = now() WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } } if (array_key_exists('metric', $_REQUEST) && array_key_exists($_REQUEST['metric'], $metrics) && array_key_exists('value', $_REQUEST) && is_numeric($_REQUEST['value']) !== false && array_key_exists('u', $_REQUEST)) { checkBeaconKey('metric'); $url_id = getUrlId($_REQUEST['u']); if (array_key_exists('timestamp', $_REQUEST) && $_REQUEST['timestamp']) { # adding new entry $query = sprintf("INSERT INTO metric (timestamp, url_id, metric_id, value) VALUES ('%s', '%d', '%d', '%f')", mysql_real_escape_string($_REQUEST['timestamp']), mysql_real_escape_string($url_id), mysql_real_escape_string($metrics[$_REQUEST['metric']]['id']), mysql_real_escape_string($_REQUEST['value'])); } else { # adding new entry $query = sprintf("INSERT INTO metric (url_id, metric_id, value) VALUES ('%d', '%d', '%f')", mysql_real_escape_string($url_id), mysql_real_escape_string($metrics[$_REQUEST['metric']]['id']), mysql_real_escape_string($_REQUEST['value'])); } if (!mysql_query($query)) { beaconError(mysql_error()); } updateUrlAggregates($url_id, mysql_insert_id()); header('HTTP/1.0 204 Data accepted'); exit; } header('HTTP/1.0 400 Bad Request'); $TITLE = 'Bad Request: Custom Metric beacon';
function updateUrlAggregates($url_id, $measurement_id) { # updating latest values for the URL $query = sprintf("UPDATE urls SET dynatrace_last_id = %d, last_update = now(), dt_refresh_request = 0 WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } } $post_data = file_get_contents("php://input"); $post = json_decode($post_data, true); /* Only URL and rank will be mandatory - the rest will be optional */ if (!is_null($post) && array_key_exists('url', $post) && array_key_exists('rank', $post) && filter_var($post['rank'], FILTER_VALIDATE_INT) !== false) { checkBeaconKey('dynatrace'); $url_id = getUrlId(urldecode($post['url'])); if (array_key_exists('ranks', $post)) { $ranks = $post['ranks']; $cache = array_key_exists('cache', $ranks) && array_key_exists('rank', $ranks['cache']) ? $ranks['cache']['rank'] : null; $net = array_key_exists('net', $ranks) && array_key_exists('rank', $ranks['net']) ? $ranks['net']['rank'] : null; $server = array_key_exists('server', $ranks) && array_key_exists('rank', $ranks['server']) ? $ranks['server']['rank'] : null; $js = array_key_exists('js', $ranks) && array_key_exists('rank', $ranks['js']) ? $ranks['js']['rank'] : null; } # adding new entry $query = sprintf("INSERT INTO dynatrace (\n\t\tversion, url_id,\n\t\trank, cache, net, server, js,\n\t\ttimetoimpression, timetoonload, timetofullload,\n\t\treqnumber, xhrnumber, pagesize, cachablesize, noncachablesize,\n\t\ttimeonnetwork, timeinjs, timeinrendering,\n\t\tdetails\n\t)\n\tVALUES (\n\t\t'%s', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d',\n\t\t'%s'\n\t)", mysql_real_escape_string(array_key_exists('version', $post) ? $post['version'] : null), mysql_real_escape_string($url_id), mysql_real_escape_string($post['rank']), mysql_real_escape_string($cache), mysql_real_escape_string($net), mysql_real_escape_string($server), mysql_real_escape_string($js), mysql_real_escape_string(array_key_exists('timetoimpression', $post) ? $post['timetoimpression'] : null), mysql_real_escape_string(array_key_exists('timetoonload', $post) ? $post['timetoonload'] : null), mysql_real_escape_string(array_key_exists('timetofullload', $post) ? $post['timetofullload'] : null), mysql_real_escape_string(array_key_exists('reqnumber', $post) ? $post['reqnumber'] : null), mysql_real_escape_string(array_key_exists('xhrnumber', $post) ? $post['xhrnumber'] : null), mysql_real_escape_string(array_key_exists('pagesize', $post) ? $post['pagesize'] : null), mysql_real_escape_string(array_key_exists('cachablesize', $post) ? $post['cachablesize'] : null), mysql_real_escape_string(array_key_exists('noncachablesize', $post) ? $post['noncachablesize'] : null), mysql_real_escape_string(array_key_exists('timeonnetwork', $post) ? $post['timeonnetwork'] : null), mysql_real_escape_string(array_key_exists('timeinjs', $post) ? $post['timeinjs'] : null), mysql_real_escape_string(array_key_exists('timeinrendering', $post) ? $post['timeinrendering'] : null), mysql_real_escape_string($post_data)); if (!mysql_query($query)) { beaconError(mysql_error()); } updateUrlAggregates($url_id, mysql_insert_id()); } else {
$grades = $post['g']; $metrics = array('ynumreq', 'ycdn', 'yexpires', 'yemptysrc', 'ycompress', 'ycsstop', 'yjsbottom', 'yexpressions', 'yexternal', 'ydns', 'yminify', 'yredirects', 'ydupes', 'yetags', 'yxhr', 'yxhrmethod', 'ymindom', 'yno404', 'ymincookie', 'ycookiefree', 'ynofilter', 'yimgnoscale', 'yfavicon'); foreach ($metrics as $metric) { if (!array_key_exists($metric, $grades) || !array_key_exists('score', $grades[$metric])) { $grades[$metric]['score'] = null; } } # adding new entry $query = sprintf("/* grades POST */ INSERT INTO yslow2 (\n\t\t`ip` , `user_agent` , `url_id` ,\n\t\t`w` , `o` , `r` , `i` , lt,\n\t\t`ynumreq`,\t`ycdn`,\t\t`yexpires`,\t`yemptysrc`, `ycompress`,\t`ycsstop`,\n\t\t`yjsbottom`,\t`yexpressions`,\t`yexternal`,\t`ydns`,\t\t`yminify`,\n\t\t`yredirects`,\t`ydupes`,\t`yetags`,\t`yxhr`,\t\t`yxhrmethod`,\n\t\t`ymindom`,\t`yno404`,\t`ymincookie`,\t`ycookiefree`,\t`ynofilter`,\n\t\t`yimgnoscale`,\t`yfavicon`" . ($keepBeaconDetails ? ', details' : '') . "\n\t)\n\tVALUES (inet_aton('%s'), '%s', '%d',\n\t\t'%d', '%d', '%d', '%s', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d'" . ($keepBeaconDetails ? ", '%s'" : '') . "\n\t)", mysql_real_escape_string($_SERVER['REMOTE_ADDR']), mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']), mysql_real_escape_string($url_id), mysql_real_escape_string($post['w']), mysql_real_escape_string($post['o']), mysql_real_escape_string($post['r']), mysql_real_escape_string($post['i']), mysql_real_escape_string(array_key_exists('lt', $post) ? $post['lt'] : null), mysql_real_escape_string($grades['ynumreq']['score']), mysql_real_escape_string($grades['ycdn']['score']), mysql_real_escape_string($grades['yexpires']['score']), mysql_real_escape_string($grades['yemptysrc']['score']), mysql_real_escape_string($grades['ycompress']['score']), mysql_real_escape_string($grades['ycsstop']['score']), mysql_real_escape_string($grades['yjsbottom']['score']), mysql_real_escape_string($grades['yexpressions']['score']), mysql_real_escape_string($grades['yexternal']['score']), mysql_real_escape_string($grades['ydns']['score']), mysql_real_escape_string($grades['yminify']['score']), mysql_real_escape_string($grades['yredirects']['score']), mysql_real_escape_string($grades['ydupes']['score']), mysql_real_escape_string($grades['yetags']['score']), mysql_real_escape_string($grades['yxhr']['score']), mysql_real_escape_string($grades['yxhrmethod']['score']), mysql_real_escape_string($grades['ymindom']['score']), mysql_real_escape_string($grades['yno404']['score']), mysql_real_escape_string($grades['ymincookie']['score']), mysql_real_escape_string($grades['ycookiefree']['score']), mysql_real_escape_string($grades['ynofilter']['score']), mysql_real_escape_string($grades['yimgnoscale']['score']), mysql_real_escape_string($grades['yfavicon']['score']), $keepBeaconDetails ? mysql_real_escape_string($post_data) : null); if (!mysql_query($query)) { beaconError(mysql_error()); } updateUrlAggregates($url_id, mysql_insert_id()); } else { if (array_key_exists('u', $_GET) && array_key_exists('i', $_GET) && in_array($_GET['i'], $YSlow2AllowedProfiles) && array_key_exists('w', $_GET) && filter_var($_GET['w'], FILTER_VALIDATE_INT) !== false && array_key_exists('o', $_GET) && filter_var($_GET['o'], FILTER_VALIDATE_INT) !== false && array_key_exists('r', $_GET) && filter_var($_GET['r'], FILTER_VALIDATE_INT) !== false) { checkBeaconKey('yslow'); $url_id = getUrlId($_GET['u']); # adding new entry $query = sprintf("/* basic GET */ INSERT INTO yslow2 (\n\t\t`ip` , `user_agent` , `url_id` ,\n\t\t`w` , `o` , `r` , `i`, lt,\n\t\t`ynumreq`,\t`ycdn`,\t\t`yexpires`,\t`yemptysrc`,\t`ycompress`,\t`ycsstop`,\n\t\t`yjsbottom`,\t`yexpressions`,\t`yexternal`,\t`ydns`,\t\t`yminify`,\n\t\t`yredirects`,\t`ydupes`,\t`yetags`,\t`yxhr`,\t\t`yxhrmethod`,\n\t\t`ymindom`,\t`yno404`,\t`ymincookie`,\t`ycookiefree`,\t`ynofilter`,\n\t\t`yimgnoscale`,\t`yfavicon`\n\t)\n\tVALUES (inet_aton('%s'), '%s', '%d',\n\t\t'%d', '%d', '%d', '%s', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d', '%d', '%d', '%d',\n\t\t'%d', '%d'\n\t)", mysql_real_escape_string($_SERVER['REMOTE_ADDR']), mysql_real_escape_string($_SERVER['HTTP_USER_AGENT']), mysql_real_escape_string($url_id), mysql_real_escape_string($_GET['w']), mysql_real_escape_string($_GET['o']), mysql_real_escape_string($_GET['r']), mysql_real_escape_string($_GET['i']), mysql_real_escape_string($_GET['lt']), mysql_real_escape_string($_GET['ynumreq']), mysql_real_escape_string($_GET['ycdn']), mysql_real_escape_string($_GET['yexpires']), mysql_real_escape_string($_GET['yemptysrc']), mysql_real_escape_string($_GET['ycompress']), mysql_real_escape_string($_GET['ycsstop']), mysql_real_escape_string($_GET['yjsbottom']), mysql_real_escape_string($_GET['yexpressions']), mysql_real_escape_string($_GET['yexternal']), mysql_real_escape_string($_GET['ydns']), mysql_real_escape_string($_GET['yminify']), mysql_real_escape_string($_GET['yredirects']), mysql_real_escape_string($_GET['ydupes']), mysql_real_escape_string($_GET['yetags']), mysql_real_escape_string($_GET['yxhr']), mysql_real_escape_string($_GET['yxhrmethod']), mysql_real_escape_string($_GET['ymindom']), mysql_real_escape_string($_GET['yno404']), mysql_real_escape_string($_GET['ymincookie']), mysql_real_escape_string($_GET['ycookiefree']), mysql_real_escape_string($_GET['ynofilter']), mysql_real_escape_string($_GET['yimgnoscale']), mysql_real_escape_string($_GET['yfavicon'])); if (!mysql_query($query)) { beaconError(mysql_error()); } updateUrlAggregates($url_id, mysql_insert_id()); } else { header('HTTP/1.0 400 Bad Request'); $TITLE = 'Bad Request: YSlow beacon'; require_once dirname(dirname(dirname(__FILE__))) . '/header.php'; ?> <h2><a href="../">Beacons</a>: YSlow</h2> <p>This is <a href="http://www.yslow.org/">YSlow</a> beacon entry point.</p>
<?php require_once dirname(dirname(dirname(__FILE__))) . '/global.php'; function updateUrlAggregates($url_id, $measurement_id) { # updating latest values for the URL $query = sprintf("UPDATE urls set pagespeed_last_id = %d, last_update = now(), p_refresh_request = 0 WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } } if (array_key_exists('u', $_GET)) { checkBeaconKey('pagespeed'); $url_id = getUrlId($_GET['u']); $metrics = array('pBadReqs', 'pBrowserCache', 'pCacheValid', 'pCharsetEarly', 'pCombineCSS', 'pCombineJS', 'pCssImport', 'pCssInHead', 'pCssJsOrder', 'pCssSelect', 'pDeferJS', 'pDocWrite', 'pDupeRsrc', 'pGzip', 'pImgDims', 'pMinDns', 'pMinifyCSS', 'pMinifyHTML', 'pMinifyJS', 'pMinRedirect', 'pMinReqSize', 'pNoCookie', 'pOptImgs', 'pParallelDl', 'pPreferAsync', 'pRemoveQuery', 'pScaleImgs', 'pSprite', 'pUnusedCSS', 'pVaryAE'); // array to store core metrics: // w total size of all resources loaded by the page // htmlResponseBytes // textResponseBytes // cssResponseBytes // imageResponseBytes // javascriptResponseBytes // flashResponseBytes // otherResponseBytes // o score // l - // r numberResources // t - $core_metrics = array(); // processed data will be stored in this array
<?php require_once dirname(dirname(dirname(__FILE__))) . '/global.php'; if (array_key_exists('title', $_GET) && $_GET['title'] != '' && array_key_exists('url_prefix', $_GET) && filter_var($_GET['url_prefix'], FILTER_VALIDATE_URL) !== false) { checkBeaconKey('events'); $url = validateURL($_GET['url_prefix'], $outputerror); $type = array_key_exists('type', $_GET) && $_GET['type'] != '' ? $_GET['type'] : FALSE; $start = array_key_exists('start', $_GET) && $_GET['start'] != '' ? $_GET['start'] : FALSE; $end = array_key_exists('end', $_GET) && $_GET['type'] != '' ? $_GET['end'] : FALSE; $resource_url = filter_var($_GET['resource_url'], FILTER_VALIDATE_URL); $query = sprintf('INSERT INTO event ( url_prefix, title, start' . ($type !== FALSE ? ', type' : '') . ($end !== FALSE ? ', end' : '') . ($resource_url !== FALSE ? ', resource_url' : '') . ") VALUES (\n\t\t\t'%s',\n\t\t\t'%s',\n\t\t\t'%s'" . ($type !== FALSE ? ", '%s'" : '') . ($end !== FALSE ? ", '%s'" : '') . ($resource_url !== FALSE ? ", '%s'" : '') . ')', mysql_real_escape_string($url), mysql_real_escape_string($_GET['title']), mysql_real_escape_string($start), mysql_real_escape_string($type), mysql_real_escape_string($end), mysql_real_escape_string($resource_url)); if (!mysql_query($query)) { beaconError(mysql_error()); } # updating last_event_update for the matching URLs $query = sprintf("UPDATE urls SET last_event_update = NOW() WHERE INSTR(url, '%s') = 1", mysql_real_escape_string($url)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } if (array_key_exists('manual', $_GET)) { ?> <html> <head> <title>Event added</title> </head> <body> <h1>Event added</h1>
require_once dirname(dirname(dirname(__FILE__))) . '/global.php'; function updateUrlAggregates($url_id, $measurement_id) { # updating latest values for the URL $query = sprintf("UPDATE urls SET dommonster_last_id = %d, last_update = now() WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } } /* Only URL and rank will be mandatory - the rest will be optional */ if (array_key_exists('url', $_POST) && array_key_exists('stats', $_POST)) { checkBeaconKey('dommonster'); $url_id = getUrlId(urldecode($_POST['url'])); $stats = json_decode($_POST['stats'], true); # adding new entry $query = sprintf("INSERT INTO dommonster (\n\t\tversion, url_id,\n\t\telements,\n\t\tnodecount,\n\t\ttextnodes,\n\t\ttextnodessize,\n\t\tcontentpercent,\n\t\taverage,\n\t\tdomsize,\n\t\tbodycount\n\t)\n\tVALUES (\n\t\t'%s', '%d',\n\t\t'%d',\n\t\t'%d',\n\t\t'%d',\n\t\t'%d',\n\t\t'%f',\n\t\t'%f',\n\t\t'%d',\n\t\t'%d'\n\t)", mysql_real_escape_string(array_key_exists('version', $_POST) ? $_POST['version'] : null), mysql_real_escape_string($url_id), mysql_real_escape_string(array_key_exists('elements', $stats) ? $stats['elements'] : null), mysql_real_escape_string(array_key_exists('nodecount', $stats) ? $stats['nodecount'] : null), mysql_real_escape_string(array_key_exists('textnodes', $stats) ? $stats['textnodes'] : null), mysql_real_escape_string(array_key_exists('textnodessize', $stats) ? $stats['textnodessize'] : null), mysql_real_escape_string(array_key_exists('contentpercent', $stats) ? $stats['contentpercent'] : null), mysql_real_escape_string(array_key_exists('average', $stats) ? $stats['average'] : null), mysql_real_escape_string(array_key_exists('domsize', $stats) ? $stats['domsize'] : null), mysql_real_escape_string(array_key_exists('bodycount', $stats) ? $stats['bodycount'] * 1000 : null)); if (!mysql_query($query)) { beaconError(mysql_error()); } updateUrlAggregates($url_id, mysql_insert_id()); $url = validateURL($_POST['url']); ?> <html><head><script> if (confirm('Sucess: data is saved to Show Slow (<?php echo $showslow_base; ?> )\nWould you like to open the resuls page?')) {
require_once dirname(dirname(dirname(__FILE__))) . '/global.php'; function updateUrlAggregates($url_id, $measurement_id) { # updating latest values for the URL $query = sprintf("UPDATE urls SET pagetest_last_id = %d, last_update = now(), pagetest_refresh_request = 0 WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } } $post_data = file_get_contents("php://input"); $post = json_decode($post_data, true); #error_log(implode('|', array_keys($post['first']))); if (!is_null($post) && array_key_exists('url', $post) && array_key_exists('id', $post)) { checkBeaconKey('webpagetest'); $url_id = getUrlId(urldecode($post['url'])); $first = array_key_exists('first', $post); $repeat = array_key_exists('repeat', $post); // fixing up -1 into nulls if ($first) { foreach (array_keys($post['first']) as $metric) { if ($post['first'][$metric] == -1) { $post['first'][$metric] = null; } } } if ($repeat) { foreach (array_keys($post['repeat']) as $metric) { if ($post['repeat'][$metric] == -1) { $post['repeat'][$metric] = null;