/** * Parse a bulk script entry and create a test configuration from it * * @param mixed $script */ function ParseBulkScript(&$script, $current_entry = null) { global $test; $entry = null; if (count($script)) { $s = ''; if (isset($current_entry)) { $entry = $current_entry; } else { $entry = array(); } foreach ($script as $line) { if (!strncasecmp($line, 'label=', 6)) { $entry['l'] = trim(substr($line, 6)); } else { $s .= $line; $s .= "\r\n"; } } $entry['u'] = ValidateScript($s, $error); if (strlen($entry['u'])) { $entry['s'] = $s; } else { unset($entry); } } return $entry; }
/** * Validate the test options and set intelligent defaults * * @param mixed $test * @param mixed $locations */ function ValidateParameters(&$test, $locations, &$error) { if (strlen($test['url'])) { $settings = parse_ini_file('./settings/settings.ini'); $maxruns = (int) $settings['maxruns']; if (!$maxruns) { $maxruns = 10; } // make sure the url starts with http:// if (strncasecmp($test['url'], 'http:', 5) && strncasecmp($test['url'], 'https:', 6)) { $test['url'] = 'http://' . $test['url']; } ValidateURL($test, $error, $settings); if (!$error) { // make sure the test runs are between 1 and 200 if ($test['runs'] > $maxruns) { $test['runs'] = $maxruns; } elseif ($test['runs'] < 1) { $test['runs'] = 1; } // if fvonly is set, make sure it is to an explicit value of 1 if ($test['fvonly'] > 0) { $test['fvonly'] = 1; } // make sure private is explicitly 1 or 0 if ($test['private']) { $test['private'] = 1; } else { $test['private'] = 0; } // make sure web10 is explicitly 1 or 0 if ($test['web10']) { $test['web10'] = 1; } else { $test['web10'] = 0; } // make sure the number of connections is in a sensible range if ($test['connections'] > 20) { $test['connections'] = 20; } elseif ($test['connections'] < 0) { $test['connections'] = 0; } // use the default location if one wasn't specified if (!strlen($test['location'])) { $test['location'] = $locations['locations']['default']; } // filter out a SPAM bot that is hitting us // for scripted tests, the block command will be in the script if (strlen($test['script']) && strlen($test['block'])) { $error = 'Your test request was flagged by our system as potentially spam-related. Please contact us if you think this was an error.'; } // figure out what the location working directory and friendly name are $test['locationText'] = $locations[$test['location']]['label']; $test['workdir'] = $locations[$test['location']]['localDir']; $test['remoteUrl'] = $locations[$test['location']]['remoteUrl']; $test['remoteLocation'] = $locations[$test['location']]['remoteLocation']; if (!strlen($test['workdir']) && !strlen($test['remoteUrl'])) { $error = "Invalid Location, please try submitting your test request again."; } // if the speed wasn't specified and there is one for the location, pass it on if (!$test['speed'] && $locations[$test['location']]['speed']) { $test['speed'] = $locations[$test['location']]['speed']; } if ($test['script']) { ValidateScript($test, $error); } } } else { $error = "Invalid URL, please try submitting your test request again."; } return $ret; }