Пример #1
0
/**
* Create a single test and return the test ID
*
* @param mixed $test
* @param mixed $url
*/
function CreateTest(&$test, $url, $batch = 0, $batch_locations = 0)
{
    global $settings;
    $testId = null;
    if (is_file('./settings/block.txt')) {
        $forceBlock = trim(file_get_contents('./settings/block.txt'));
    }
    if (CheckUrl($url) && WptHookValidateTest($test)) {
        // generate the test ID
        $test_num;
        $id = uniqueId($test_num);
        if ($test['private']) {
            $id = ShardKey($test_num) . md5(uniqid(rand(), true));
        } else {
            $id = ShardKey($test_num) . $id;
        }
        $today = new DateTime("now", new DateTimeZone('UTC'));
        $testId = $today->format('ymd_') . $id;
        $test['path'] = './' . GetTestPath($testId);
        // make absolutely CERTAIN that this test ID doesn't already exist
        while (is_dir($test['path'])) {
            // fall back to random ID's
            $id = ShardKey($test_num) . md5(uniqid(rand(), true));
            $testId = $today->format('ymd_') . $id;
            $test['path'] = './' . GetTestPath($testId);
        }
        // create the folder for the test results
        if (!is_dir($test['path'])) {
            mkdir($test['path'], 0777, true);
        }
        // write out the ini file
        $testInfo = "[test]\r\n";
        $testInfo .= "fvonly={$test['fvonly']}\r\n";
        $testInfo .= "timeout={$test['timeout']}\r\n";
        $resultRuns = $test['runs'] - $test['discard'];
        $testInfo .= "runs={$resultRuns}\r\n";
        $testInfo .= "location=\"{$test['locationText']}\"\r\n";
        $testInfo .= "loc={$test['location']}\r\n";
        $testInfo .= "id={$testId}\r\n";
        $testInfo .= "batch={$batch}\r\n";
        $testInfo .= "batch_locations={$batch_locations}\r\n";
        $testInfo .= "sensitive={$test['sensitive']}\r\n";
        if (strlen($test['login'])) {
            $testInfo .= "authenticated=1\r\n";
        }
        $testInfo .= "connections={$test['connections']}\r\n";
        if (strlen($test['script'])) {
            $testInfo .= "script=1\r\n";
        }
        if (strlen($test['notify'])) {
            $testInfo .= "notify={$test['notify']}\r\n";
        }
        if (strlen($test['video'])) {
            $testInfo .= "video=1\r\n";
        }
        if (strlen($test['uid'])) {
            $testInfo .= "uid={$test['uid']}\r\n";
        }
        if (strlen($test['owner'])) {
            $testInfo .= "owner={$test['owner']}\r\n";
        }
        if (strlen($test['type'])) {
            $testInfo .= "type={$test['type']}\r\n";
        }
        if (strlen($test['industry']) && strlen($test['industry_page'])) {
            $testInfo .= "industry=\"{$test['industry']}\"\r\n";
            $testInfo .= "industry_page=\"{$test['industry_page']}\"\r\n";
        }
        if (isset($test['connectivity'])) {
            $testInfo .= "connectivity={$test['connectivity']}\r\n";
            $testInfo .= "bwIn={$test['bwIn']}\r\n";
            $testInfo .= "bwOut={$test['bwOut']}\r\n";
            $testInfo .= "latency={$test['latency']}\r\n";
            $testInfo .= "plr={$test['plr']}\r\n";
        }
        $testInfo .= "\r\n[runs]\r\n";
        if ($test['median_video']) {
            $testInfo .= "median_video=1\r\n";
        }
        file_put_contents("{$test['path']}/testinfo.ini", $testInfo);
        // for "batch" tests (the master) we don't need to submit an actual test request
        if (!$batch && !$batch_locations) {
            // build up the actual test commands
            $testFile = '';
            if (strlen($test['domElement'])) {
                $testFile .= "\r\nDOMElement={$test['domElement']}";
            }
            if ($test['fvonly']) {
                $testFile .= "\r\nfvonly=1";
            }
            if ($test['timeout']) {
                $testFile .= "\r\ntimeout={$test['timeout']}";
            }
            if ($test['web10']) {
                $testFile .= "\r\nweb10=1";
            }
            if ($test['ignoreSSL']) {
                $testFile .= "\r\nignoreSSL=1";
            }
            if ($test['tcpdump']) {
                $testFile .= "\r\ntcpdump=1";
            }
            if ($test['standards']) {
                $testFile .= "\r\nstandards=1";
            }
            if ($test['timeline']) {
                $testFile .= "\r\ntimeline=1";
                $testFile .= "\r\ntimelineStackDepth={$test['timelineStackDepth']}";
            }
            if ($test['trace']) {
                $testFile .= "\r\ntrace=1";
            }
            if ($test['swrender']) {
                $testFile .= "\r\nswRender=1";
            }
            if ($test['netlog']) {
                $testFile .= "\r\nnetlog=1";
            }
            if ($test['spdy3']) {
                $testFile .= "\r\nspdy3=1";
            }
            if ($test['noscript']) {
                $testFile .= "\r\nnoscript=1";
            }
            if ($test['fullsizevideo']) {
                $testFile .= "\r\nfullSizeVideo=1";
            }
            if ($test['blockads']) {
                $testFile .= "\r\nblockads=1";
            }
            if ($test['video']) {
                $testFile .= "\r\nCapture Video=1";
            }
            if (GetSetting('save_mp4') || $test['keepvideo']) {
                $testFile .= "\r\nkeepvideo=1";
            }
            if (strlen($test['type'])) {
                $testFile .= "\r\ntype={$test['type']}";
            }
            if ($test['block']) {
                $testFile .= "\r\nblock={$test['block']}";
                if (isset($forceBlock)) {
                    $testFile .= " {$forceBlock}";
                }
            } elseif (isset($forceBlock)) {
                $testFile .= "\r\nblock={$forceBlock}";
            }
            if ($test['noopt']) {
                $testFile .= "\r\nnoopt=1";
            }
            if ($test['noimages']) {
                $testFile .= "\r\nnoimages=1";
            }
            if ($test['noheaders']) {
                $testFile .= "\r\nnoheaders=1";
            }
            if ($test['discard']) {
                $testFile .= "\r\ndiscard={$test['discard']}";
            }
            $testFile .= "\r\nruns={$test['runs']}\r\n";
            if (isset($test['connectivity'])) {
                $testFile .= "bwIn={$test['bwIn']}\r\n";
                $testFile .= "bwOut={$test['bwOut']}\r\n";
                $testFile .= "latency={$test['testLatency']}\r\n";
                $testFile .= "plr={$test['plr']}\r\n";
            }
            if (isset($test['browserExe']) && strlen($test['browserExe'])) {
                $testFile .= "browserExe={$test['browserExe']}\r\n";
            }
            if (isset($test['browser']) && strlen($test['browser'])) {
                $testFile .= "browser={$test['browser']}\r\n";
            }
            if ($test['pngss'] || $settings['pngss']) {
                $testFile .= "pngScreenShot=1\r\n";
            }
            if ($test['iq']) {
                $testFile .= "imageQuality={$test['iq']}\r\n";
            } elseif ($settings['iq']) {
                $testFile .= "imageQuality={$settings['iq']}\r\n";
            }
            if ($test['bodies']) {
                $testFile .= "bodies=1\r\n";
            }
            if ($test['htmlbody']) {
                $testFile .= "htmlbody=1\r\n";
            }
            if ($test['time']) {
                $testFile .= "time={$test['time']}\r\n";
            }
            if ($test['clear_rv']) {
                $testFile .= "clearRV={$test['clear_rv']}\r\n";
            }
            if ($test['keepua']) {
                $testFile .= "keepua=1\r\n";
            }
            if ($test['mobile']) {
                $testFile .= "mobile=1\r\n";
            }
            if (isset($test['dpr']) && $test['dpr'] > 0) {
                $testFile .= "dpr={$test['dpr']}\r\n";
            }
            if (isset($test['width']) && $test['width'] > 0) {
                $testFile .= "width={$test['width']}\r\n";
            }
            if (isset($test['height']) && $test['height'] > 0) {
                $testFile .= "height={$test['height']}\r\n";
            }
            if ($test['clearcerts']) {
                $testFile .= "clearcerts=1\r\n";
            }
            if ($test['orientation']) {
                $testFile .= "orientation={$test['orientation']}\r\n";
            }
            if (array_key_exists('continuousVideo', $test) && $test['continuousVideo']) {
                $testFile .= "continuousVideo=1\r\n";
            }
            if (array_key_exists('responsive', $test) && $test['responsive']) {
                $testFile .= "responsive=1\r\n";
            }
            if (array_key_exists('cmdLine', $test) && strlen($test['cmdLine'])) {
                $testFile .= "cmdLine={$test['cmdLine']}\r\n";
            }
            if (array_key_exists('addCmdLine', $test) && strlen($test['addCmdLine'])) {
                $testFile .= "addCmdLine={$test['addCmdLine']}\r\n";
            }
            if (array_key_exists('customBrowserUrl', $test) && strlen($test['customBrowserUrl'])) {
                $testFile .= "customBrowserUrl={$test['customBrowserUrl']}\r\n";
            }
            if (array_key_exists('customBrowserMD5', $test) && strlen($test['customBrowserMD5'])) {
                $testFile .= "customBrowserMD5={$test['customBrowserMD5']}\r\n";
            }
            if (array_key_exists('customBrowserSettings', $test) && is_array($test['customBrowserSettings']) && count($test['customBrowserSettings'])) {
                foreach ($test['customBrowserSettings'] as $setting => $value) {
                    $testFile .= "customBrowser_{$setting}={$value}\r\n";
                }
            }
            if (isset($test['uastring'])) {
                $testFile .= "uastring={$test['uastring']}\r\n";
            }
            $UAModifier = GetSetting('UAModifier');
            if ($UAModifier && strlen($UAModifier)) {
                $testFile .= "UAModifier={$UAModifier}\r\n";
            }
            if (isset($test['appendua'])) {
                $testFile .= "AppendUA={$test['appendua']}\r\n";
            }
            // see if we need to add custom scan rules
            if (array_key_exists('custom_rules', $test)) {
                foreach ($test['custom_rules'] as &$rule) {
                    $rule = trim($rule);
                    if (strlen($rule)) {
                        $testFile .= "customRule={$rule}\r\n";
                    }
                }
            }
            // Add custom metrics
            if (array_key_exists('customMetrics', $test)) {
                foreach ($test['customMetrics'] as $name => $code) {
                    $testFile .= "customMetric={$name}:{$code}\r\n";
                }
            }
            if (!SubmitUrl($testId, $testFile, $test, $url)) {
                $testId = null;
            }
        }
        // log the test
        if (isset($testId)) {
            logTestMsg($testId, "Test Created");
            // store the entire test data structure JSON encoded (instead of a bunch of individual files)
            $oldUrl = @$test['url'];
            $test['url'] = $url;
            SaveTestInfo($testId, $test);
            $test['url'] = $oldUrl;
            if ($batch_locations) {
                LogTest($test, $testId, 'Multiple Locations test');
            } else {
                if ($batch) {
                    LogTest($test, $testId, 'Bulk Test');
                } else {
                    LogTest($test, $testId, $url);
                }
            }
        } else {
            // delete the test if we didn't really submit it
            delTree("{$test['path']}/");
        }
    } else {
        global $error;
        $error = 'Your test request was intercepted by our spam filters (or because we need to talk to you about how you are submitting tests)';
    }
    return $testId;
}
Пример #2
0
/**
* Process a sharded test
* 
* @param mixed $testInfo
*/
function ProcessTestShard(&$testInfo, &$test, &$delete)
{
    global $supports_sharding;
    global $tester;
    if (array_key_exists('shard_test', $testInfo) && $testInfo['shard_test']) {
        if (array_key_exists('type', $testInfo) && $testInfo['type'] == 'traceroute' || !$supports_sharding) {
            $testInfo['shard_test'] = 0;
        } else {
            $done = true;
            $assigned_run = 0;
            // find a run to assign to a tester
            for ($run = 1; $run <= $testInfo['runs']; $run++) {
                if (!array_key_exists('tester', $testInfo['test_runs'][$run])) {
                    $testInfo['test_runs'][$run]['tester'] = $tester;
                    $testInfo['test_runs'][$run]['started'] = time();
                    $testInfo['test_runs'][$run]['done'] = false;
                    $assigned_run = $run;
                    break;
                }
            }
            // go through again and see if all tests have been assigned
            for ($run = 1; $run <= $testInfo['runs']; $run++) {
                if (!array_key_exists('tester', $testInfo['test_runs'][$run])) {
                    $done = false;
                    break;
                }
            }
            if ($assigned_run) {
                logTestMsg($testInfo['id'], "Run {$assigned_run} assigned to {$tester}");
                $append = "run={$assigned_run}\r\n";
                // Figure out if this test needs to be discarded
                $index = $assigned_run;
                if (array_key_exists('discard', $testInfo)) {
                    if ($index <= $testInfo['discard']) {
                        $append .= "discardTest=1\r\n";
                        $index = 1;
                        $done = true;
                        $testInfo['test_runs'][$assigned_run]['discarded'] = true;
                    } else {
                        $index -= $testInfo['discard'];
                    }
                }
                $append .= "index={$index}\r\n";
                $insert = strpos($test, "\nurl");
                if ($insert !== false) {
                    $test = substr($test, 0, $insert + 1) . $append . substr($test, $insert + 1);
                } else {
                    $test = "run={$assigned_run}\r\n" + $test;
                }
            }
            if (!$done) {
                $delete = false;
            }
        }
    }
}
Пример #3
0
                            file_put_contents('./video/dat/industry.dat', $data);
                            Unlock($indLock);
                        }
                    }
                }
                if ($testInfo_dirty) {
                    SaveTestInfo($id, $testInfo);
                }
                SecureDir($testPath);
                UnlockTest($testLock);
                /*************************************************************************
                 * Do No modify TestInfo after this point
                 **************************************************************************/
                // do any post-processing when the full test is complete that doesn't rely on testinfo
                if ($done) {
                    logTestMsg($id, "Test Complete");
                    // send an async request to the post-processing code so we don't block
                    SendAsyncRequest("/work/postprocess.php?test={$id}");
                }
            } else {
                logMsg("location key incorrect\n");
            }
        }
    }
}
$workdone_end = microtime(true);
/*
if (isset($workdone_video_start) && isset($workdone_video_end)) {
  $elapsed = intval(($workdone_end - $workdone_start) * 1000);
  $video_elapsed = intval(($workdone_video_end - $workdone_video_start) * 1000);
  if ($video_elapsed > 10)
Пример #4
0
                } else {
                    $url .= '&';
                }
                $url .= "id={$testId}";
                SendCallback($url);
            }
        }
        // send a beacon?
        if (isset($beaconUrl) && strlen($beaconUrl)) {
            if (!isset($pageData)) {
                $pageData = loadAllPageData($testPath);
            }
            include './work/beacon.inc';
            SendBeacon($beaconUrl, $id, $testPath, $testInfo, $pageData);
        }
        logTestMsg($id, "Test post-processing complete");
    }
}
function SendCallback($url)
{
    if (function_exists('curl_init')) {
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($c, CURLOPT_TIMEOUT, 10);
        curl_exec($c);
        curl_close($c);
    } else {
        $context = stream_context_create(array('http' => array('header' => 'Connection: close', 'timeout' => 10)));