Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set rate-limiting options from settings page #2130

Merged
merged 6 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/pi-hole/php/FTL.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

$piholeFTLConfFile = "/etc/pihole/pihole-FTL.conf";

function piholeFTLConfig()
function piholeFTLConfig($force=false)
yubiuser marked this conversation as resolved.
Show resolved Hide resolved
{
static $piholeFTLConfig;
global $piholeFTLConfFile;

if(isset($piholeFTLConfig))
if(isset($piholeFTLConfig) && !$force)
{
return $piholeFTLConfig;
}
Expand Down
7 changes: 7 additions & 0 deletions scripts/pi-hole/php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
}
pihole_execute("-a -i ".$DNSinterface." -web");

// Add rate-limiting settings
if(isset($_POST["rate_limit_count"]) && isset($_POST["rate_limit_interval"]))
{
// Restart of FTL is delayed
pihole_execute("-a ratelimit " . intval($_POST["rate_limit_count"]) . " " . intval($_POST["rate_limit_interval"]) . " false");
yubiuser marked this conversation as resolved.
Show resolved Hide resolved
}

// If there has been no error we can save the new DNS server IPs
if(!strlen($error))
{
Expand Down
30 changes: 29 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_once "scripts/pi-hole/php/FTL.php";
// Reread ini file as things might have been changed
$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
$piholeFTLConf = piholeFTLConfig();
$piholeFTLConf = piholeFTLConfig(true);

// Handling of PHP internal errors
$last_error = error_get_last();
Expand Down Expand Up @@ -718,6 +718,19 @@ function convertseconds($argument)
</form>
</div>
<!-- ######################################################### DNS ######################################################### -->
<?php
// Use default
$rate_limit_count = 1000;
$rate_limit_interval = 60;
// Get rate limit from piholeFTL config array
if (isset($piholeFTLConf["RATE_LIMIT"])) {
$rl = explode("/", $piholeFTLConf["RATE_LIMIT"]);
if(count($rl) == 2) {
$rate_limit_count = intval($rl[0]);
$rate_limit_interval = intval($rl[1]);
}
}
?>
<div id="dns" class="tab-pane fade<?php if($tab === "dns"){ ?> in active<?php } ?>">
<form role="form" method="post">
<div class="row">
Expand Down Expand Up @@ -934,6 +947,21 @@ function convertseconds($argument)
<a href="https://dnssec.vs.uni-due.de/" rel="noopener" target="_blank">here</a>.</p>
</div>
<br>
<h4><a id="ratelimit"></a>Rate-limiting</h4>
<p>Block clients making more than <input type="number" name="rate_limit_count" value="<?=$rate_limit_count?>" min="0" step="10" style="width: 5em;"> queries within
<input type="number" name="rate_limit_interval" value="<?=$rate_limit_interval?>" min="0" step="10" style="width: 4em;"> seconds.</p>
<p>When a client makes too many queries in too short time, it
gets rate-limited. Rate-limited queries are answered with a
<code>REFUSED</code> reply and not further processed by FTL
and prevent Pi-holes getting overwhelmed by rogue clients.
It is important to note that rate-limiting is happening on a
per-client basis. Other clients can continue to use FTL while
rate-limited clients are short-circuited at the same time.</p>
<p>Rate-limiting may be disabled altogether by setting both
values to zero. See
<a href="https://docs.pi-hole.net/ftldns/configfile/#rate_limit" target="_blank">our documentation</a>
for further details.</p>
<br>
<h4>Conditional forwarding</h4>
<p>If not configured as your DHCP server, Pi-hole typically won't be able to
determine the names of devices on your local network. As a
Expand Down