/** * Load the location information * */ function LoadLocations() { $locations = LoadLocationsIni(); FilterLocations($locations, 'pss'); // strip out any sensitive information foreach ($locations as $index => &$loc) { if (isset($loc['browser'])) { $testCount = 16; if (array_key_exists('relayServer', $loc)) { $loc['backlog'] = 0; $loc['avgTime'] = 30; $loc['testers'] = 1; $loc['wait'] = ceil($testCount * 30 / 60); } else { GetPendingTests($index, $count, $avgTime); if (!$avgTime) { $avgTime = 30; } // default to 30 seconds if we don't have any history $loc['backlog'] = $count; $loc['avgTime'] = $avgTime; $loc['testers'] = GetTesterCount($index); $loc['wait'] = -1; if ($loc['testers']) { if ($loc['testers'] > 1) { $testCount = 16; } $loc['wait'] = ceil(($testCount + $count / $loc['testers']) * $avgTime / 60); } } } unset($loc['localDir']); unset($loc['key']); unset($loc['remoteDir']); unset($loc['relayKey']); } return $locations; }
$error = NULL; $xml = false; $usingAPI = false; if (!strcasecmp($req_f, 'xml')) { $xml = true; } $json = false; if (!strcasecmp($req_f, 'json')) { $json = true; } $headless = false; if (array_key_exists('headless', $settings) && $settings['headless']) { $headless = true; } // load the location information $locations = LoadLocationsIni(); // See if we need to load a subset of the locations $filter = null; if (isset($_REQUEST['k']) && preg_match('/^(?P<prefix>[0-9A-Za-z]+)\\.(?P<key>[0-9A-Za-z]+)$/', $_REQUEST['k'], $matches)) { $filter = $matches['prefix']; foreach ($locations as $name => $location) { if (isset($location['browser'])) { $ok = false; if (isset($location['allowKeys'])) { $keys = explode(',', $location['allowKeys']); foreach ($keys as $k) { if ($k == $filter) { $ok = true; break; } }
/** * Load the location information and extract just the end nodes * */ function GetAllTesters() { $locations = array(); $loc = LoadLocationsIni(); if (isset($_REQUEST['location'])) { $location = $_REQUEST['location']; $new = array('locations' => array('1' => 'group', 'default' => 'group'), 'group' => array('1' => $location, 'default' => $location, 'label' => 'placeholder')); if (isset($loc[$_REQUEST['location']])) { $new[$_REQUEST['location']] = $loc[$_REQUEST['location']]; } $loc = $new; } BuildLocations($loc); $i = 1; while (isset($loc['locations'][$i])) { $group =& $loc[$loc['locations'][$i]]; $j = 1; while (isset($group[$j])) { if (array_key_exists('relayServer', $loc[$group[$j]]) && strlen($loc[$group[$j]]['relayServer']) && array_key_exists('relayLocation', $loc[$group[$j]]) && strlen($loc[$group[$j]]['relayLocation'])) { $locations[$loc[$group[$j]]['location']] = GetRemoteTesters($loc[$group[$j]]['relayServer'], $loc[$group[$j]]['relayLocation']); } else { $locations[$loc[$group[$j]]['location']] = GetTesters($loc[$group[$j]]['location']); } $j++; } $i++; } return $locations; }
/** * Load the location information * */ function LoadLocations() { $locations = LoadLocationsIni(); FilterLocations($locations); // strip out any sensitive information foreach ($locations as $index => &$loc) { // count the number of tests at each location if (isset($loc['localDir'])) { $loc['backlog'] = CountTests($loc['localDir']); unset($loc['localDir']); } if (isset($loc['key'])) { unset($loc['key']); } if (isset($loc['remoteDir'])) { unset($loc['remoteDir']); } if (isset($loc['notify'])) { unset($loc['notify']); } } return $locations; }
/** * Load the location information and extract just the end nodes * */ function LoadLocations() { $locations = array(); $loc = LoadLocationsIni(); if (isset($_REQUEST['k']) && preg_match('/^(?P<prefix>[0-9A-Za-z]+)(?P<key>[\\.0-9A-Za-z]*)$/', $_REQUEST['k'], $matches)) { $filter = $matches['prefix']; foreach ($loc as $name => $location) { if (isset($location['browser'])) { $ok = false; if (isset($location['allowKeys'])) { $keys = explode(',', $location['allowKeys']); foreach ($keys as $k) { if ($k == $filter) { $ok = true; break; } } } if (!$ok) { unset($loc[$name]); } } } } FilterLocations($loc); BuildLocations($loc); if (isset($loc['locations']['default'])) { $default = $loc['locations']['default']; } else { $default = $loc['locations'][1]; } $i = 1; while (isset($loc['locations'][$i])) { $group =& $loc[$loc['locations'][$i]]; if (!isset($group['hidden']) || !$group['hidden'] || $_REQUEST['hidden']) { $label = $group['label']; if (isset($group['default'])) { $def = $group['default']; } else { $def = $group[1]; } $j = 1; while (isset($group[$j])) { if (isset($loc[$group[$j]]['location'])) { $loc_name = $loc[$group[$j]]['location']; if (!isset($loc[$group[$j]]['hidden']) || !$loc[$group[$j]]['hidden'] || $_REQUEST['hidden']) { if (isset($locations[$loc_name])) { $locations[$loc_name]['Browsers'] .= ',' . $loc[$group[$j]]['browser']; } else { $locations[$loc_name] = array('Label' => $label, 'location' => $loc[$group[$j]]['location'], 'Browsers' => $loc[$group[$j]]['browser'], 'localDir' => $loc[$group[$j]]['localDir'], 'status' => @$loc[$group[$j]]['status'], 'relayServer' => @$loc[$group[$j]]['relayServer'], 'relayLocation' => @$loc[$group[$j]]['relayLocation'], 'labelShort' => $loc[$loc_name]['label']); if ($default == $loc['locations'][$i] && $def == $group[$j]) { $locations[$loc_name]['default'] = true; } if (isset($group['group'])) { $locations[$loc_name]['group'] = $group['group']; } } } } $j++; } } $i++; } return $locations; }
function CheckLocations() { $locations = LoadLocationsIni(); $out = ''; foreach ($locations['locations'] as $id => $location) { if (is_numeric($id)) { $info = GetInstallLocationInfo($locations, $location); $out .= "<li class=\"{$info['state']}\">{$info['label']}"; if (count($info['locations'])) { $out .= "<ul>"; foreach ($info['locations'] as $loc_name => $loc) { $out .= "<li class=\"{$loc['state']}\">{$loc['label']}"; $out .= '</li>'; } $out .= "</ul>"; } $out .= "</li>"; } } echo $out; }
/** * For any locations that haven't connected in at least 2 hours, go through and delete any tests in the work queue * */ function CheckLocations() { $locations = LoadLocationsIni(); BuildLocations($locations); $deleted = false; echo "\n"; for ($i = 1; array_key_exists($i, $locations['locations']); $i++) { $group =& $locations[$locations['locations'][$i]]; for ($j = 1; array_key_exists($j, $group); $j++) { if (!array_key_exists('relayServer', $loc[$group[$j]])) { $name = $locations[$group[$j]]['location']; $location = GetTesters($name); $workdir = $locations[$name]['localDir']; $elapsed = -1; if (isset($location) && array_key_exists('elapsed', $location)) { $elapsed = $location['elapsed']; } if ($elapsed < 0 || $elapsed > 120) { if (strlen($workdir)) { if (is_dir($workdir)) { echo "{$elapsed} minutes : {$name} - {$workdir}\n"; delTree($workdir); rmdir($workdir); $deleted = true; } } } } } } // nuke all of the queue files if we had to delete something if ($deleted) { $files = scandir('./tmp'); foreach ($files as $file) { if (stripos($file, '.queue') !== false) { unlink("./tmp/{$file}"); } } } }
/** * Email the API key info to the requestor * * @param mixed $info */ function EmailKeyInfo($info) { global $prefix; $email = $info['email']; $content = "Your API key is: {$prefix}.{$info['key']}\n\n"; $content .= "The API key is limited to {$info['key_limit']} page loads per day. Each run, first or repeat view counts as a page load (10 runs, first and repeat view would be 20 page loads). If you need to do more testing than that allows then you should consider running a private instance: https://sites.google.com/a/webpagetest.org/docs/private-instances\n"; $l = LoadLocationsIni(); $locations = array(); foreach ($l as $id => $loc) { $id = trim($id); if (is_array($loc) && isset($loc['browser']) && isset($loc['allowKeys'])) { $allowed = false; $prefixes = explode(',', $loc['allowKeys']); foreach ($prefixes as $p) { if ($p == $prefix) { $allowed = true; } } if ($allowed) { $browsers = explode(',', $loc['browser']); if (isset($browsers) && is_array($browsers)) { if (count($browsers) > 1) { foreach ($browsers as $browser) { $browser = trim($browser); $locations[] = "{$id}:{$browser}"; } } else { $locations[] = $id; } } } } } $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http'; $url = "{$protocol}://{$_SERVER['HTTP_HOST']}/getLocations.php?f=html&k={$prefix}"; $content .= "\nYou can see the current list of locations that are available for API testing here: {$url}.\n"; if (count($locations)) { $content .= "\nThe following browser/location combinations are available:\n\n"; foreach ($locations as $location) { $content .= "{$location}\n"; } } SendMessage($email, 'WebPagetest API Key', $content); echo 'The API key details were sent to ' . htmlspecialchars($email); return $content; }
/** * Load the location information and extract just the end nodes * */ function GetAllTesters() { $locations = array(); $loc = LoadLocationsIni(); BuildLocations($loc); $i = 1; while (isset($loc['locations'][$i])) { $group =& $loc[$loc['locations'][$i]]; $j = 1; while (isset($group[$j])) { if (array_key_exists('relayServer', $loc[$group[$j]]) && strlen($loc[$group[$j]]['relayServer']) && array_key_exists('relayLocation', $loc[$group[$j]]) && strlen($loc[$group[$j]]['relayLocation'])) { $locations[$loc[$group[$j]]['location']] = GetRemoteTesters($loc[$group[$j]]['relayServer'], $loc[$group[$j]]['relayLocation']); } else { $locations[$loc[$group[$j]]['location']] = GetTesters($loc[$group[$j]]['location']); } $j++; } $i++; } return $locations; }
function EC2_GetTesters() { $locations = array(); $loc = LoadLocationsIni(); $i = 1; while (isset($loc['locations'][$i])) { $group =& $loc[$loc['locations'][$i]]; $j = 1; while (isset($group[$j])) { $locations[$group[$j]] = GetTesters($group[$j]); $j++; } $i++; } return $locations; }
/** * Get a list of locations supported by the given AMI * */ function EC2_GetAMILocations() { $locations = array(); $loc = LoadLocationsIni(); foreach ($loc as $location => $locInfo) { if (isset($locInfo['ami']) && isset($locInfo['region'])) { if (!isset($locations[$locInfo['ami']])) { $locations[$locInfo['ami']] = array('ami' => $locInfo['ami'], 'region' => $locInfo['region'], 'locations' => array()); } $locations[$locInfo['ami']]['locations'][] = $location; } } return $locations; }
function CheckLocations() { $locations = LoadLocationsIni(); $out = ''; $video = false; foreach ($locations['locations'] as $id => $location) { if (is_numeric($id)) { $info = GetLocationInfo($locations, $location); if ($info['video']) { $video = true; } $out .= "<li class=\"{$info['state']}\">{$info['label']}"; if (count($info['locations'])) { $out .= "<ul>"; foreach ($info['locations'] as $loc_name => $loc) { $out .= "<li class=\"{$loc['state']}\">{$loc['label']}"; $out .= '</li>'; } $out .= "</ul>"; } $out .= "</li>"; } } if ($video) { echo '<li class="pass">Video rendering is supported</li></ul><br><ul>'; } else { echo '<li class="fail"><span class="fail">No test agents are configured to render video</span></li></ul><br><ul>'; } echo $out; }
/** * Load the location information and extract just the end nodes * */ function LoadLocations() { $locations = array(); $loc = LoadLocationsIni(); FilterLocations($loc); BuildLocations($loc); if (isset($loc['locations']['default'])) { $default = $loc['locations']['default']; } else { $default = $loc['locations'][1]; } $i = 1; while (isset($loc['locations'][$i])) { $group =& $loc[$loc['locations'][$i]]; if (!array_key_exists('hidden', $group) || !$group['hidden'] || $_REQUEST['hidden']) { $label = $group['label']; if (isset($group['default'])) { $def = $group['default']; } else { $def = $group[1]; } $j = 1; while (isset($group[$j])) { if (array_key_exists($group[$j], $loc)) { if (!array_key_exists('hidden', $loc[$group[$j]]) || !$loc[$group[$j]]['hidden'] || $_REQUEST['hidden']) { $locations[$group[$j]] = array('Label' => $label, 'location' => $loc[$group[$j]]['location'], 'Browser' => $loc[$group[$j]]['browser'], 'localDir' => $loc[$group[$j]]['localDir'], 'relayServer' => @$loc[$group[$j]]['relayServer'], 'relayLocation' => @$loc[$group[$j]]['relayLocation']); if ($default == $loc['locations'][$i] && $def == $group[$j]) { $locations[$group[$j]]['default'] = true; } } } $j++; } } $i++; } return $locations; }