Skip to content

Commit b9452eb

Browse files
authored
Merge pull request #3065 from catchpoint/compare_video_fix
fix: docompare run logic
2 parents 371adf8 + d722f99 commit b9452eb

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

www/video/docompare.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
// Use of this source code is governed by the Polyform Shield 1.0.0 license that can be
55
// found in the LICENSE.md file.
66
chdir('..');
7+
use WebPageTest\Util;
8+
use WebPageTest\Util\OAuth as CPOauth;
79
include 'common.inc';
810

911
$urls = $_REQUEST['url'];
1012
$labels = $_REQUEST['label'];
1113
$ids = array();
1214
$ip = $_SERVER['REMOTE_ADDR'];
13-
$key = '';
14-
$keys_file = __DIR__ . '/../settings/keys.ini';
15-
if (file_exists(__DIR__ . '/../settings/common/keys.ini')) {
16-
$keys_file = __DIR__ . '/../settings/common/keys.ini';
17-
}
18-
if (file_exists(__DIR__ . '/../settings/server/keys.ini')) {
19-
$keys_file = __DIR__ . '/../settings/server/keys.ini';
20-
}
21-
$key = GetServerKey();
2215
$headless = false;
2316
if (GetSetting('headless')) {
2417
$headless = true;
@@ -41,7 +34,7 @@
4134
foreach ($urls as $index => $url) {
4235
$url = trim($url);
4336
if (strlen($url)) {
44-
$id = SubmitTest($url, $labels[$index], $key);
37+
$id = SubmitTest($url, $labels[$index]);
4538
if ($id && strlen($id)) {
4639
$ids[] = $id;
4740
}
@@ -88,7 +81,7 @@
8881
* @param mixed $url
8982
* @param mixed $label
9083
*/
91-
function SubmitTest($url, $label, $key)
84+
function SubmitTest($url, $label)
9285
{
9386
global $uid;
9487
global $user;
@@ -118,14 +111,30 @@ function SubmitTest($url, $label, $key)
118111
if ($user) {
119112
$testUrl .= '&user=' . urlencode($uid);
120113
}
121-
if (strlen($key)) {
122-
$testUrl .= '&k=' . urlencode($key);
123-
}
124114
$saml_cookie = GetSetting('saml_cookie', 'samlu');
125115
if (isset($_COOKIE[$saml_cookie])) {
126116
$testUrl .= '&samlu=' . urlencode($_COOKIE[$saml_cookie]);
127117
}
128118

119+
if ($_REQUEST['vo']) {
120+
$testUrl .= "&vo={$_REQUEST['vo']}";
121+
}
122+
if ($_REQUEST['vd']) {
123+
$testUrl .= "&vd=".urlencode($_REQUEST['vd']);
124+
}
125+
if ($_REQUEST['vh']) {
126+
$testUrl .= "&vh={$_REQUEST['vh']}";
127+
}
128+
129+
$token_name = Util::getCookieName(CPOauth::$cp_access_token_cookie_key);
130+
$token_value = $_COOKIE[$token_name];
131+
if(isset($token_name) && isset($token_value)){
132+
$context = stream_context_create(array("http" => array("header" => 'Cookie: '.$token_name.'='.$token_value."\r\n"), "ignore_errors" => true,) );
133+
libxml_set_streams_context($context);
134+
}
135+
136+
ini_set('user_agent', $_SERVER['HTTP_USER_AGENT']);
137+
129138
// submit the request
130139
$result = simplexml_load_file($testUrl, 'SimpleXMLElement', LIBXML_NOERROR);
131140
if ($result && $result->data) {

www/video/index.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
if (is_file($profile_file)) {
2626
$profiles = parse_ini_file($profile_file, true);
2727
}
28+
// load the secret key (if there is one)
29+
$secret = GetServerSecret();
30+
if (!isset($secret)) {
31+
$secret = '';
32+
}
2833
?>
2934

3035
<!DOCTYPE html>
@@ -47,7 +52,21 @@
4752

4853
<form name="urlEntry" id="urlEntry" action="/video/docompare.php" method="POST" onsubmit="return ValidateInput(this)">
4954

50-
55+
<?php
56+
echo '<input type="hidden" name="vo" value="'.htmlspecialchars($owner).'">';
57+
if (strlen($secret)) {
58+
$hashStr = $secret;
59+
$hashStr .= $_SERVER['HTTP_USER_AGENT'];
60+
$hashStr .= $owner;
61+
62+
$now = gmdate('c');
63+
echo '<input type="hidden" name="vd" value="'.$now.'">';
64+
$hashStr .= $now;
65+
66+
$hmac = sha1($hashStr);
67+
echo '<input type="hidden" name="vh" value="'.$hmac.'">';
68+
}
69+
?>
5170
<div id="test_box-container" class="home_responsive_test">
5271
<?php
5372
$currNav = "Visual Comparison";

0 commit comments

Comments
 (0)