1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Merge pull request #5 from RaspAP/feature/dhcp-ignore

Limit network access to static clients
This commit is contained in:
Bill Zimmerman 2021-02-23 07:31:12 +01:00 committed by GitHub
commit f9c2bccc3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 37 deletions

View File

@ -45,12 +45,15 @@ function DisplayDHCPConfig()
}
}
getWifiInterface();
$ap_iface = $_SESSION['ap_interface'];
$serviceStatus = $dnsmasq_state ? "up" : "down";
exec('cat '. RASPI_DNSMASQ_PREFIX.'raspap.conf', $return);
$conf = ParseConfig($return);
exec('cat '. RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return);
$conf = array_merge(ParseConfig($return));
$hosts = (array)$conf['dhcp-host'];
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
exec('cat ' . RASPI_DNSMASQ_LEASES, $leases);
$ap_iface = $_SESSION['ap_interface'];
echo renderTemplate(
"dhcp", compact(
@ -59,7 +62,7 @@ function DisplayDHCPConfig()
"dnsmasq_state",
"ap_iface",
"conf",
"dhcpHost",
"hosts",
"interfaces",
"leases"
)
@ -172,7 +175,7 @@ function updateDnsmasqConfig($iface,$status)
$mac = trim($_POST["static_leases"]["mac"][$i]);
$ip = trim($_POST["static_leases"]["ip"][$i]);
if ($mac != "" && $ip != "") {
$config .= "dhcp-host=$mac,$ip".PHP_EOL;
$config .= "dhcp-host=$mac,$ip".",set:known".PHP_EOL;
}
}
if ($_POST['no-resolv'] == "1") {
@ -188,6 +191,9 @@ function updateDnsmasqConfig($iface,$status)
}
$config .= PHP_EOL;
}
if ($_POST['dhcp-ignore'] == "1") {
$config .= 'dhcp-ignore=tag:!known'.PHP_EOL;
}
file_put_contents("/tmp/dnsmasqdata", $config);
$msg = file_exists(RASPI_DNSMASQ_PREFIX.$iface.'.conf') ? 'updated' : 'added';
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$iface.'.conf', $result);

View File

@ -362,6 +362,24 @@ msgstr "Log DHCP requests"
msgid "Log DNS queries"
msgstr "Log DNS queries"
msgid "Restrict access"
msgstr "Restrict access"
msgid "Limit network access to static clients"
msgstr "Limit network access to static clients"
msgid "Enable this option if you want RaspAP to <b>ignore any clients</b> which are not specified in the static leases list."
msgstr "Enable this option if you want RaspAP to <b>ignore any clients</b> which are not specified in the static leases list."
msgid "This option adds <code>dhcp-ignore</code> to the dnsmasq configuration."
msgstr "This option adds <code>dhcp-ignore</code> to the dnsmasq configuration."
msgid "Clients with a particular hardware MAC address can always be allocated the same IP address."
msgstr "Clients with a particular hardware MAC address can always be allocated the same IP address."
msgid "This option adds <code>dhcp-host</code> entries to the dnsmasq configuration."
msgstr "This option adds <code>dhcp-host</code> entries to the dnsmasq configuration."
#: includes/hostapd.php
msgid "Basic"
msgstr "Basic"

View File

@ -1,9 +1,14 @@
<!-- static leases tab -->
<div class="tab-pane fade" id="static-leases">
<div class="row">
<div class="col-md-12">
<h4 class="mt-3 mb-3"><?php echo _("Static leases") ?></h4>
<p id="static-lease-description">
<small><?php echo _("Clients with a particular hardware MAC address can always be allocated the same IP address.") ?></small>
<small class="text-muted"><?php echo _("This option adds <code>dhcp-host</code> entries to the dnsmasq configuration.") ?></small>
</p>
<div class="dhcp-static-leases js-dhcp-static-lease-container">
<?php foreach ($dhcpHost as $host) : ?>
<?php foreach ($hosts as $host) : ?>
<?php list($mac, $ip) = array_map("trim", explode(",", $host)); ?>
<div class="row dhcp-static-lease-row js-dhcp-static-lease-row">
<div class="col-md-5 col-xs-5">
@ -13,13 +18,12 @@
<input type="text" name="static_leases[ip][]" value="<?php echo htmlspecialchars($ip, ENT_QUOTES) ?>" placeholder="<?php echo _("IP address") ?>" class="form-control">
</div>
<div class="col-md-2 col-xs-3">
<button type="button" class="btn btn-danger js-remove-dhcp-static-lease"><?php echo _("Remove") ?></button>
<button type="button" class="btn btn-outline-danger js-remove-dhcp-static-lease"><i class="far fa-trash-alt"></i></button>
</div>
</div>
<?php endforeach ?>
</div>
<h5 class="mt-3 mb-3"><?php echo _("Add static DHCP lease") ?></h5>
<div class="row dhcp-static-lease-row js-new-dhcp-static-lease">
<div class="col-md-5 col-xs-5">
<input type="text" name="mac" value="" placeholder="<?php echo _("MAC address") ?>" class="form-control" autofocus="autofocus">
@ -28,7 +32,22 @@
<input type="text" name="ip" value="" placeholder="<?php echo _("IP address") ?>" class="form-control">
</div>
<div class="col-md-2 col-xs-3">
<button type="button" class="btn btn-success js-add-dhcp-static-lease"><?php echo _("Add") ?></button>
<button type="button" class="btn btn-outline-success js-add-dhcp-static-lease"><i class="far fa-plus-square"></i></button>
</div>
</div>
<h5 class="mt-3 mb-3"><?php echo _("Restrict access") ?></h5>
<div class="input-group">
<input type="hidden" name="dhcp-ignore" value="0">
<div class="custom-control custom-switch">
<input class="custom-control-input" id="dhcp-ignore" type="checkbox" name="dhcp-ignore" value="1" <?php echo $conf['dhcp-ignore'] ? ' checked="checked"' : "" ?> aria-describedby="dhcp-ignore-description">
<label class="custom-control-label" for="dhcp-ignore"><?php echo _("Limit network access to static clients") ?></label>
</div>
<p id="dhcp-ignore-description">
<small><?php echo _("Enable this option if you want RaspAP to <b>ignore any clients</b> which are not specified in the static leases list.") ?></small>
<small class="text-muted"><?php echo _("This option adds <code>dhcp-ignore</code> to the dnsmasq configuration.") ?></small>
</p>
</div>
</div>
</div>
@ -41,8 +60,10 @@
<input type="text" name="static_leases[ip][]" value="{{ ip }}" placeholder="<?php echo _("IP address") ?>" class="form-control">
</div>
<div class="col-md-2 col-xs-3">
<button type="button" class="btn btn-warning js-remove-dhcp-static-lease"><?php echo _("Remove") ?></button>
<button type="button" class="btn btn-outline-danger js-remove-dhcp-static-lease"><i class="far fa-trash-alt"></i></button>
</div>
</div>
</template>
</div><!-- /.tab-pane -->