Beispiel #1
0
/**
* 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;
}
Beispiel #2
0
            if (isset($location['allowKeys'])) {
                $keys = explode(',', $location['allowKeys']);
                foreach ($keys as $k) {
                    if ($k == $filter) {
                        $ok = true;
                        break;
                    }
                }
            }
            if (!$ok) {
                unset($locations[$name]);
            }
        }
    }
}
BuildLocations($locations);
// see if we are running a relay test
if (@strlen($req_rkey)) {
    RelayTest();
} else {
    // see if we're re-running an existing test
    if (isset($test)) {
        unset($test);
    }
    if (array_key_exists('resubmit', $_POST)) {
        $test = GetTestInfo(trim($_POST['resubmit']));
        if ($test) {
            unset($test['completed']);
            unset($test['started']);
            unset($test['tester']);
            unset($test['batch']);
/**
* 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;
}
Beispiel #4
0
/**
* 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}");
            }
        }
    }
}
Beispiel #5
0
/**
* 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;
}
/**
* Load the location information and extract just the end nodes
*
*/
function LoadLocations()
{
    $locations = array();
    $loc = parse_ini_file('./settings/locations.ini', true);
    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;
}
Beispiel #7
0
function EC2_ScaleUp($location, $ec2Config)
{
    $instancesNeeded = 0;
    $file = @fopen("./ec2/testers.{$location}.dat", 'c+');
    if ($file) {
        if (flock($file, LOCK_EX)) {
            $config = parse_ini_file('./settings/ec2.ini', true);
            if (isset($config[$ec2Config])) {
                // see how many tests are currently pending for the given location
                $locations = parse_ini_file('./settings/locations.ini', true);
                BuildLocations($locations);
                if (strlen($locations[$location]['localDir'])) {
                    $files = glob($locations[$location]['localDir'] . '/*.*', GLOB_NOSORT);
                    $backlog = count($files);
                    $instances = json_decode(stream_get_contents($file), true);
                    if (!$instances) {
                        $instances = array();
                    }
                    $count = count($instances);
                    if ($backlog > 0 && !$count) {
                        $instancesNeeded = 1;
                    } else {
                        $ratio = $config[$ec2Config]['ratio'];
                        $max = $config[$ec2Config]['max'];
                        if ($ratio && $count < $max) {
                            $needed = (int) ($backlog / $ratio);
                            $needed = min($needed, $max);
                            $needed = max($needed, $count);
                            $instancesNeeded = $needed - $count;
                        }
                    }
                }
            }
            if ($instancesNeeded) {
                $price = trim($config[$ec2Config]['price']);
                $ami = trim($config[$ec2Config]['ami']);
                $region = trim($config[$ec2Config]['region']);
                $size = 'm1.small';
                if (strlen($config[$ec2Config]['size'])) {
                    $size = trim($config[$ec2Config]['size']);
                }
                $userData = trim($config[$ec2Config]['user_data']);
                if (strlen($price) && strlen($ami) && strlen($region) && strlen($size) && strlen($userData)) {
                    require_once './ec2/sdk.class.php';
                    $ec2 = new AmazonEC2($config[$ec2Config]['key'], $config[$ec2Config]['secret']);
                    if ($ec2) {
                        $ec2->set_region($region);
                        $response = $ec2->request_spot_instances($price, array('InstanceCount' => (int) $instancesNeeded, 'Type' => 'one-time', 'LaunchSpecification' => array('ImageId' => $ami, 'InstanceType' => 'm1.small', 'UserData' => base64_encode($userData))));
                        if ($response->isOK()) {
                            // add empty instances to our list, the actual ID's will be filled in as they come online
                            // and checked periodically
                            for ($i = 0; $i < $instancesNeeded; $i++) {
                                $instances[] = array();
                            }
                            fseek($file, 0);
                            ftruncate($file, 0);
                            fwrite($file, json_encode($instances));
                        }
                    }
                }
            }
            flock($file, LOCK_UN);
        }
        fclose($file);
    }
}