Skip to content

Commit

Permalink
Merge pull request #1647 from WPO-Foundation/set-settings-anon-monthly
Browse files Browse the repository at this point in the history
fix(rate-limit): Use setting for anon max
  • Loading branch information
jefflembeck authored Dec 14, 2021
2 parents c1b79fa + bfc4331 commit 9e6a12e
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions www/runtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3087,26 +3087,27 @@ function CheckRateLimit($test, &$error) {
$runcount = max(1, $test['runs']);
$multiplier = $test['fvonly'] ? 1 : 2;
$total_runs = $runcount * $multiplier;
$cmrl = new CheckMonthlyRateLimit($test['ip']);
$monthly_limit = GetSetting('rate_limit_anon_monthly') ?: 50;
$cmrl = new CheckMonthlyRateLimit($test['ip'], $monthly_limit);
$passesMonthly = $cmrl->check($total_runs);

if(!$passesMonthly) {
$error = '<p>You\'ve reached the limit for logged-out tests this month, but don\'t worry! You can keep testing once you log in, which will give you access to other nice features like:</p>';
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
if(window["_gaq"]) {
clearInterval(intervalId);
window["_gaq"].push("_trackEvent", "Error", "RateLimit", "MonthlyLimitHit");
}
}, 500);
</script>
HTML;
$error .= loggedInPerks();
$error .= loggedOutLoginForm();
return false;
}

if(!$passesMonthly) {
$error = '<p>You\'ve reached the limit for logged-out tests this month, but don\'t worry! You can keep testing once you log in, which will give you access to other nice features like:</p>';
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
if(window["_gaq"]) {
clearInterval(intervalId);
window["_gaq"].push("_trackEvent", "Error", "RateLimit", "MonthlyLimitHit");
}
}, 500);
</script>
HTML;
$error .= loggedInPerks();
$error .= loggedOutLoginForm();
return false;
}

// Enforce per-IP rate limits for testing
$limit = GetSetting('rate_limit_anon', null);
if (isset($limit) && $limit > 0) {
Expand All @@ -3122,25 +3123,25 @@ function CheckRateLimit($test, &$error) {
$register = GetSetting('saml_register');
$apiUrl = GetSetting('api_url');
$error = '<p>You\'ve reached the limit for logged-out tests per hour, but don\'t worry! You can keep testing once you log in, which will give you access to other nice features like:</p>';
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
if(window["_gaq"]) {
clearInterval(intervalId);
window["_gaq"].push("_trackEvent", "Error", "RateLimit", "HourlyLimitHit");
}
}, 500);
</script>
HTML;

$error .= loggedInPerks();
if ($supportsSaml && $register && $apiUrl) {
$error .= <<<HTML
<script>
var intervalId = setInterval(function () {
if(window["_gaq"]) {
clearInterval(intervalId);
window["_gaq"].push("_trackEvent", "Error", "RateLimit", "HourlyLimitHit");
}
}, 500);
</script>
HTML;

$error .= loggedInPerks();
if ($supportsSaml && $register && $apiUrl) {
$error .= "<p>And also, if you need to run tests programmatically you might be interested in the <a href='$apiUrl'>WebPageTest API</a></p>";
}
$error .= loggedOutLoginForm();
$ret = false;
}
}
}
$error .= loggedOutLoginForm();
$ret = false;
}
}

return $ret;
}
Expand Down

0 comments on commit 9e6a12e

Please sign in to comment.