Beispiel #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;
}
Beispiel #2
0
                 $test['script'] = GenerateSNSScript($test);
             } elseif ($test['authType'] == 2) {
                 $test['script'] = GenerateYandexAuthScript($test);
             } else {
                 $testFile .= "\r\nBasic Auth={$test['login']}:{$test['password']}\r\n";
             }
         }
         if (!SubmitUrl($test['id'], $testFile, $test)) {
             $error = "Error sending url to test machine.  Please try back later.";
         }
     }
 }
 // redirect the browser to the test results page
 if (!$error) {
     // log the test results
     LogTest($test);
     // only redirect for local tests, otherwise the redirect has already been taken care of
     if (!$test['remoteUrl']) {
         $host = $_SERVER['HTTP_HOST'];
         $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
         if ($xml) {
             header('Content-type: text/xml');
             echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
             echo "<response>\n";
             echo "<statusCode>200</statusCode>\n";
             echo "<statusText>Ok</statusText>\n";
             if (strlen($_REQUEST['r'])) {
                 echo "<requestId>{$_REQUEST['r']}</requestId>\n";
             }
             echo "<data>\n";
             echo "<testId>{$test['id']}</testId>\n";