-
Notifications
You must be signed in to change notification settings - Fork 714
/
submit.php
168 lines (155 loc) · 5.63 KB
/
submit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
require_once('./settings.inc');
$results = array();
$pending = 0;
// see if there is an existing test we are working with
if (LoadResults($results)) {
foreach ($results as $result) {
if (isset($result['id']) && strlen($result['id']) && !isset($result['result'])) {
$pending++;
}
}
if ($pending) {
echo "Waiting for $pending tests to complete...\r\n";
} else {
echo "Re-submitting failed tests from current results.txt...\r\n";
}
} else {
if (!isset($urls_file)) {
$urls_file = 'urls.txt';
}
echo "Loading URL list from $urls_file...\r\n";
$urls = file("./$urls_file", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
for ($i = 0; $i < $iterations; $i++) {
foreach ($urls as $url) {
$url = trim($url);
if (strlen($url)) {
foreach ($permutations as $label => &$permutation) {
$results[] = array( 'url' => $url, 'label' => $label );
}
}
}
}
}
// go through and submit tests for any url where we don't have a test ID or where the test failed
if (/*!$pending &&*/ count($results)) {
// first count the number of tests we are going to have to submit (to give some progress indication)
$testCount = 0;
foreach ($results as &$result) {
if (
!array_key_exists('id', $result) ||
!strlen($result['id']) ||
(array_key_exists('resubmit', $result) && $result['resubmit']) ||
(array_key_exists('result', $result) &&
$result['result'] != 0 &&
$result['result'] != 99999)
) {
$testCount++;
}
}
if ($testCount) {
echo "$testCount tests to submit (combination of URL and Location...\r\n";
SubmitTests($results, $testCount);
// store the results
StoreResults($results);
echo "Done submitting tests. The test ID's are stored in results.json\r\n";
} else {
echo "No tests to submit, all tests have completed successfully are are still running\r\n";
}
} else {
if (!$pending) {
echo "Nothing to do (no urls found)\r\n";
}
}
/**
* Submit the actual tests
*
* @param mixed $results
*/
function SubmitTests(&$results, $testCount)
{
global $video;
global $private;
global $runs;
global $server;
global $docComplete;
global $fvonly;
global $key;
global $options;
global $permutations;
global $priority;
global $bodies;
global $testerAffinity;
$count = 0;
foreach ($results as &$result) {
if (
array_key_exists('label', $result) &&
strlen($result['label']) &&
array_key_exists($result['label'], $permutations) &&
array_key_exists('location', $permutations[$result['label']])
) {
if (
!array_key_exists('id', $result) ||
!strlen($result['id']) ||
(array_key_exists('resubmit', $result) && $result['resubmit']) ||
(array_key_exists('result', $result) &&
strlen($result['result']) &&
$result['result'] != 0 &&
$result['result'] != 99999)
) {
$count++;
echo "\rSubmitting test $count of $testCount... ";
$location = $permutations[$result['label']]['location'];
$request = $server . "runtest.php?f=json&runs=$runs&url=" . urlencode($result['url']) . '&location=' . urlencode($location);
if ($testerAffinity) {
$request .= "&affinity=" . urlencode($result['url']);
}
if ($private) {
$request .= '&private=1';
}
if ($video) {
$request .= '&video=1';
}
if ($docComplete) {
$request .= '&web10=1';
}
if ($fvonly) {
$request .= '&fvonly=1';
}
if ($bodies) {
$request .= '&bodies=1';
}
if (isset($priority)) {
$request .= "&priority=$priority";
} else {
$request .= "&priority=9";
}
if (strlen($key)) {
$request .= "&k=$key";
}
if (isset($options) && strlen($options)) {
$request .= '&' . $options;
}
if (array_key_exists('options', $permutations[$result['label']]) && strlen($permutations[$result['label']]['options'])) {
$request .= '&' . $permutations[$result['label']]['options'];
}
$response_str = http_fetch($request);
if (strlen($response_str)) {
$response = json_decode($response_str, true);
if ($response['statusCode'] == 200) {
$entry = array();
$entry['url'] = $result['url'];
$entry['label'] = $result['label'];
$entry['id'] = $response['data']['testId'];
$result = $entry;
} else {
echo "\r ";
echo "\rError '{$response['statusText']}' submitting {$result['url']} for {$result['label']}\r\n";
}
}
}
}
}
// clear the progress text
echo "\r \r";
}