diff --git a/README.md b/README.md
index e6f65833..f2a8fe5a 100644
--- a/README.md
+++ b/README.md
@@ -68,7 +68,7 @@ Please [read this](https://github.com/billz/raspap-webgui/wiki/Reporting-issues)
## Ad Blocking
This feature uses DNS blacklisting to block requests for ads, trackers and other undesirable hosts. To enable ad blocking, simply respond to the prompt during the installation. As a beta release, we encourage testing and feedback from users of RaspAP.
-Details are [provided here](https://github.com/billz/raspap-webgui/wiki/Ad-blocking-(Beta)).
+Details are [provided here](https://github.com/billz/raspap-webgui/wiki/Ad-blocking).
## Bridged AP
By default RaspAP configures a routed AP for your clients to connect to. A bridged AP configuration is also possible. Slide the **Bridged AP mode** toggle under the **Advanced** tab of **Configure hotspot**, then save and restart the hotspot.
diff --git a/includes/adblock.php b/includes/adblock.php
index 64bfdc84..74f94e51 100755
--- a/includes/adblock.php
+++ b/includes/adblock.php
@@ -11,6 +11,7 @@ function DisplayAdBlockConfig()
{
$status = new StatusMessages();
$enabled = false;
+ $custom_enabled = false;
if (!RASPI_MONITOR_ENABLED) {
if (isset($_POST['saveadblocksettings'])) {
@@ -20,13 +21,39 @@ function DisplayAdBlockConfig()
} elseif ($_POST['adblock-enable'] == "0") {
$config = null;
}
- file_put_contents("/tmp/dnsmasqdata", $config);
- system('sudo cp /tmp/dnsmasqdata '.RASPI_ADBLOCK_CONFIG, $return);
+ if ($_POST['adblock-custom-enable'] == "1") {
+ // validate custom hosts input
+ $lines = preg_split('/\r\n|\n|\r/', trim($_POST['adblock-custom-hosts']));
+ if (!in_array("", $lines, true)) {
+ foreach ($lines as $line) {
+ $ip_host = preg_split('/\s+/', $line);
+ $index++;
+ if (!filter_var($ip_host[0], FILTER_VALIDATE_IP)) {
+ $errors .= _('Invalid custom IP address found on line '.$index);
+ break;
+ }
+ if (!validate_host($ip_host[1])) {
+ $errors .= _('Invalid custom host found on line '.$index);
+ break;
+ }
+ }
+ }
+ file_put_contents("/tmp/dnsmasq_custom", $_POST['adblock-custom-hosts'].PHP_EOL);
+ system("sudo cp /tmp/dnsmasq_custom " .RASPI_ADBLOCK_LISTPATH .'custom.txt', $return);
+ $config.= 'addn-hosts=' .RASPI_ADBLOCK_LISTPATH .'custom.txt'.PHP_EOL;
+ $custom_enabled = true;
+ }
- if ($return == 0) {
- $status->addMessage('Adblock configuration updated successfully', 'success');
+ if (empty($errors)) {
+ file_put_contents("/tmp/dnsmasqdata", $config);
+ system('sudo cp /tmp/dnsmasqdata '.RASPI_ADBLOCK_CONFIG, $return);
+ if ($return == 0) {
+ $status->addMessage('Adblock configuration updated successfully', 'success');
+ } else {
+ $status->addMessage('Adblock configuration failed to be updated.', 'danger');
+ }
} else {
- $status->addMessage('Adblock configuration failed to be updated.', 'danger');
+ $status->addMessage($errors, 'danger');
}
} elseif (isset($_POST['restartadblock']) || isset($_POST['startadblock'])) {
exec('sudo /bin/systemctl restart dnsmasq.service', $dnsmasq, $return);
@@ -53,7 +80,8 @@ function DisplayAdBlockConfig()
"status",
"serviceStatus",
"dnsmasq_state",
- "enabled"
+ "enabled",
+ "custom_enabled"
)
);
}
diff --git a/includes/functions.php b/includes/functions.php
index c58b2b13..85c69ca6 100755
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -477,5 +477,9 @@ function validateCidr($cidr)
return $netmask <= 128;
}
return false;
+
+ // Validates a host or FQDN
+function validate_host($host) {
+ return preg_match('/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i', $host);
}
diff --git a/installers/raspap.sudoers b/installers/raspap.sudoers
index 4c813d0e..a6e313ff 100644
--- a/installers/raspap.sudoers
+++ b/installers/raspap.sudoers
@@ -37,6 +37,7 @@ www-data ALL=(ALL) NOPASSWD:/bin/chmod o+r /tmp/hostapd.log
www-data ALL=(ALL) NOPASSWD:/bin/chmod o+r /tmp/dnsmasq.log
www-data ALL=(ALL) NOPASSWD:/bin/chmod o+r /tmp/wireguard.log
www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/dnsmasqdata /etc/dnsmasq.d/090_adblock.conf
+www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/dnsmasq_custom /etc/raspap/adblock/custom.txt
www-data ALL=(ALL) NOPASSWD:/bin/cp /tmp/wgdata /etc/wireguard/wg0.conf
www-data ALL=(ALL) NOPASSWD:/etc/raspap/adblock/update_blocklist.sh
www-data ALL=(ALL) NOPASSWD:/usr/bin/tee /tmp/wireguard.log
@@ -46,5 +47,3 @@ www-data ALL=(ALL) NOPASSWD:/usr/bin/wg-quick down wg0
www-data ALL=(ALL) NOPASSWD:/usr/bin/wg
www-data ALL=(ALL) NOPASSWD:/bin/cat /etc/wireguard/wg0.conf
-
-
diff --git a/locale/en_US/LC_MESSAGES/messages.mo b/locale/en_US/LC_MESSAGES/messages.mo
index f7562e1c..54e887d8 100644
Binary files a/locale/en_US/LC_MESSAGES/messages.mo and b/locale/en_US/LC_MESSAGES/messages.mo differ
diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po
index 7a4a937a..e704e2f0 100644
--- a/locale/en_US/LC_MESSAGES/messages.po
+++ b/locale/en_US/LC_MESSAGES/messages.po
@@ -760,3 +760,24 @@ msgstr "Statistics"
msgid "Information provided by adblock"
msgstr "Information provided by adblock"
+msgid "Enable custom blocklist"
+msgstr "Enable custom blocklist"
+
+msgid "Define custom hosts to be blocked by entering an IPv4 or IPv6 address followed by any whitespace (spaces or tabs) and the host name."
+msgstr "Define custom hosts to be blocked by entering an IPv4 or IPv6 address followed by any whitespace (spaces or tabs) and the host name."
+
+msgid "IPv4 example: 0.0.0.0 badhost.com"
+msgstr "IPv4 example: 0.0.0.0 badhost.com"
+
+msgid "This option adds an addn-hosts
directive to the dnsmasq configuration."
+msgstr "This option adds an addn-hosts
directive to the dnsmasq configuration."
+
+msgid "Custom blocklist not defined"
+msgstr "Custom blocklist not defined"
+
+msgid "Invalid custom IP address found on line "
+msgstr "Invalid custom IP address found on line "
+
+msgid "Invalid custom host found on line "
+msgstr "Invalid custom host found on line "
+
diff --git a/templates/adblock.php b/templates/adblock.php
index 34ad4ebe..103620e2 100755
--- a/templates/adblock.php
+++ b/templates/adblock.php
@@ -31,7 +31,8 @@
+ + IPv4 example: 0.0.0.0 badhost.com") ?> +