This commit is contained in:
Bill Zimmerman 2020-09-22 21:52:36 +02:00
commit f6e9faed05
12 changed files with 166 additions and 14 deletions

View File

@ -14,6 +14,16 @@ Development of RaspAP is made possible thanks to our awesome sponsors. If you us
Recurring and one-time donors are vital to the continued development of this project. Join these awesome donors by pledging via [OpenCollective](https://opencollective.com/raspap) or [PayPal](https://paypal.me/billzgithub).
## OpenCollective
Navisense GmbH - $500
Wechaty - $20
Pheppy - $10
Mark H - $10
Phil K - $10
T.Paul L - $5
Wouter D - $20
Andy N - $20
## PayPal
Ray E - "This project is awesome and just works; saved me and my client tons of work. Thank you!" - $20
Erin C - "Just got Raspap up and running, looks very cool, thanks!" -$20 CAD

View File

@ -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.

View File

@ -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"
)
);
}

View File

@ -90,7 +90,7 @@ function DisplayDashboard(&$extraFooterScripts)
define('SSIDMAXLEN', 32);
// Warning iw comes with: "Do NOT screenscrape this tool, we don't consider its output stable."
exec('iw dev ' .$_SESSION['wifi_client_interface']. ' link ', $stdoutIw);
$stdoutIwAllLinesGlued = implode(' ', $stdoutIw);
$stdoutIwAllLinesGlued = implode('+', $stdoutIw); // Break lines with character illegal in SSID and MAC addr
$stdoutIwWRepSpaces = preg_replace('/\s\s+/', ' ', $stdoutIwAllLinesGlued);
preg_match('/Connected to (([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2}))/', $stdoutIwWRepSpaces, $matchesBSSID) || $matchesBSSID[1] = '';
@ -102,7 +102,7 @@ function DisplayDashboard(&$extraFooterScripts)
$wlanHasLink = true;
}
if (!preg_match('/SSID: ([^ ]{1,'.SSIDMAXLEN.'})/', $stdoutIwWRepSpaces, $matchesSSID)) {
if (!preg_match('/SSID: ([^+]{1,'.SSIDMAXLEN.'})/', $stdoutIwWRepSpaces, $matchesSSID)) {
$wlanHasLink = false;
$matchesSSID[1] = 'None';
}

View File

@ -452,3 +452,8 @@ function getBridgedState()
return $arrHostapdConf['BridgedEnable'];
}
// 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);
}

View File

@ -77,7 +77,14 @@ function DisplayHostAPDConfig()
$arrConfig[$arrLine[0]]=$arrLine[1];
}
};
// assign beacon_int boolean if value is set
if (isset($arrConfig['beacon_int'])) {
$arrConfig['beacon_interval_bool'] = 1;
}
// assign disassoc_low_ack boolean if value is set
if (isset($arrConfig['disassoc_low_ack'])) {
$arrConfig['disassoc_low_ack_bool'] = 1;
}
// assign country_code from iw reg if not set in config
if (!isset($arrConfig['country_code']) && isset($country_code[0])) {
$arrConfig['country_code'] = $country_code[0];
@ -213,12 +220,19 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$status->addMessage('Unknown interface '.htmlspecialchars($_POST['interface'], ENT_QUOTES), 'danger');
$good_input = false;
}
if (strlen($_POST['country_code']) !== 0 && strlen($_POST['country_code']) != 2) {
$status->addMessage('Country code must be blank or two characters', 'danger');
$good_input = false;
}
if (isset($_POST['beaconintervalEnable'])) {
if (!is_numeric($_POST['beacon_interval'])) {
$status->addMessage('Beacon interval must be a numeric value', 'danger');
$good_input = false;
} elseif ($_POST['beacon_interval'] < 15 || $_POST['beacon_interval'] > 65535) {
$status->addMessage('Beacon interval must be between 15 and 65535', 'danger');
$good_input = false;
}
}
$_POST['max_num_sta'] = (int) $_POST['max_num_sta'];
$_POST['max_num_sta'] = $_POST['max_num_sta'] > 2007 ? 2007 : $_POST['max_num_sta'];
$_POST['max_num_sta'] = $_POST['max_num_sta'] < 1 ? null : $_POST['max_num_sta'];
@ -231,7 +245,12 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$config.= 'ctrl_interface_group=0'.PHP_EOL;
$config.= 'auth_algs=1'.PHP_EOL;
$config.= 'wpa_key_mgmt=WPA-PSK'.PHP_EOL;
$config.= 'beacon_int=100'.PHP_EOL;
if (isset($_POST['beaconintervalEnable'])) {
$config.= 'beacon_int='.$_POST['beacon_interval'].PHP_EOL;
}
if (isset($_POST['disassoc_low_ackEnable'])) {
$config.= 'disassoc_low_ack=0'.PHP_EOL;
}
$config.= 'ssid='.$_POST['ssid'].PHP_EOL;
$config.= 'channel='.$_POST['channel'].PHP_EOL;
if ($_POST['hw_mode'] === 'n') {

View File

@ -36,5 +36,6 @@ www-data ALL=(ALL) NOPASSWD:/etc/raspap/openvpn/configauth.sh
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/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:/etc/raspap/adblock/update_blocklist.sh

Binary file not shown.

View File

@ -447,6 +447,15 @@ msgstr "Maximum number of clients"
msgid "Configures the max_num_sta option of hostapd. The default and maximum is 2007. If empty or 0, the default applies."
msgstr "Configures the max_num_sta option of hostapd. The default and maximum is 2007. If empty or 0, the default applies."
msgid "Beacon interval"
msgstr "Beacon interval"
msgid "Disable <code>disassoc_low_ack</code>"
msgstr "Disable <code>disassoc_low_ack</code>"
msgid "Do not disassociate stations based on excessive transmission failures."
msgstr "Do not disassociate stations based on excessive transmission failures."
#: includes/networking.php
msgid "Summary"
msgstr "Summary"
@ -751,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 "<b>IPv4 example:</b> 0.0.0.0 badhost.com"
msgstr "<b>IPv4 example:</b> 0.0.0.0 badhost.com"
msgid "This option adds an <code>addn-hosts</code> directive to the dnsmasq configuration."
msgstr "This option adds an <code>addn-hosts</code> 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 "

View File

@ -31,7 +31,8 @@
<?php echo CSRFTokenFieldTag() ?>
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" id="clienttab" href="#adblocklistsettings" data-toggle="tab"><?php echo _("Blocklist settings"); ?></a></li>
<li class="nav-item"><a class="nav-link active" id="blocklisttab" href="#adblocklistsettings" data-toggle="tab"><?php echo _("Blocklist settings"); ?></a></li>
<li class="nav-item"><a class="nav-link" id="customtab" href="#adblockcustom" data-toggle="tab"><?php echo _("Custom blocklist"); ?></a></li>
<li class="nav-item"><a class="nav-link" id="logoutputtab" href="#adblocklogfileoutput" data-toggle="tab"><?php echo _("Logging"); ?></a></li>
</ul>
@ -39,6 +40,7 @@
<div class="tab-content">
<?php echo renderTemplate("adblock/general", $__template_data) ?>
<?php echo renderTemplate("adblock/stats", $__template_data) ?>
<?php echo renderTemplate("adblock/custom", $__template_data) ?>
<?php echo renderTemplate("adblock/logging", $__template_data) ?>
</div><!-- /.tab-content -->

View File

@ -0,0 +1,33 @@
<!-- logging tab -->
<div class="tab-pane fade" id="adblockcustom">
<h4 class="mt-3"><?php echo _("Custom blocklist"); ?></h4>
<div class="row">
<div class="col-md-6">
<div class="input-group">
<input type="hidden" name="adblock-custom-enable" value="0">
<div class="custom-control custom-switch">
<input class="custom-control-input" id="adblock-custom-enable" type="checkbox" name="adblock-custom-enable" value="1" <?php echo $custom_enabled ? ' checked="checked"' : "" ?> aria-describedby="adblock-description">
<label class="custom-control-label" for="adblock-custom-enable"><?php echo _("Enable custom blocklist") ?></label>
</div>
</div>
<p id="adblock-description">
<small><?php echo _("Define custom hosts to be blocked by entering an IPv4 or IPv6 address followed by any whitespace (spaces or tabs) and the host name.") ?></small>
<small><?php echo _("<b>IPv4 example:</b> 0.0.0.0 badhost.com") ?></small>
<div>
<small class="text-muted"><?php echo _("This option adds an <code>addn-hosts</code> directive to the dnsmasq configuration.") ?></small>
</div>
</p>
</div>
</div>
<div class="row">
<div class="form-group col-md-8">
<?php
$adblock_custom = file_get_contents(RASPI_ADBLOCK_LISTPATH .'custom.txt');
if (strlen($adblock_custom) == 0) {
$adblock_custom = _("Custom blocklist not defined");
}
echo '<textarea class="logoutput" name="adblock-custom-hosts">'.htmlspecialchars($adblock_custom, ENT_QUOTES).'</textarea>';
?>
</div>
</div>
</div><!-- /.tab-pane -->

View File

@ -37,6 +37,30 @@
</div>
</div>
</div>
<div class="row">
<div class="col-xs-3 col-sm-3">
<div class="custom-control custom-switch">
<?php $checked = $arrConfig['beacon_interval_bool'] == 1 ? 'checked="checked"' : '' ?>
<input class="custom-control-input" id="chxbeaconinterval" name="beaconintervalEnable" type="checkbox" value="1" <?php echo $checked ?> />
<label class="custom-control-label" for="chxbeaconinterval"><?php echo _("Beacon interval"); ?></label>
</div>
</div>
<div class="col-xs-3 col-sm-3">
<input type="text" class="form-control" name="beacon_interval" value="<?php echo $arrConfig['beacon_int'] ?>">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-2">
<div class="custom-control custom-switch">
<?php $checked = $arrConfig['disassoc_low_ack_bool'] == 1 ? 'checked="checked"' : '' ?>
<input class="custom-control-input" id="chxdisassoclowack" name="disassoc_low_ackEnable" type="checkbox" value="1" <?php echo $checked ?> />
<label class="custom-control-label" for="chxdisassoclowack"><?php echo _("Disable <code>disassoc_low_ack</code>"); ?></label>
</div>
<p id="disassoc_low_ack_help" class="mb-1 mt-0">
<small id="disassoc_low_ack_help" class="text-muted"><?php echo _("Do not disassociate stations based on excessive transmission failures.") ?></small></label>
</p>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="max_num_sta"><?php echo _("Maximum number of clients") ?></label>