Merge branch 'feature/dhcp-eth0' of https://github.com/billz/raspap-webgui into feature/dhcp-eth0

This commit is contained in:
Bill Zimmerman 2020-11-19 13:54:14 +01:00
commit 047e0cecc3
7 changed files with 24 additions and 21 deletions

View File

@ -222,6 +222,8 @@ function contentLoaded() {
setupBtns();
case "hostapd_conf":
loadChannel();
case "dhcpd_conf":
loadInterfaceDHCPSelect('wlan0');
break;
}
}
@ -238,15 +240,10 @@ function loadWifiStations(refresh) {
}
$(".js-reload-wifi-stations").on("click", loadWifiStations(true));
function loadInterfaceDHCP(selected) {
}
function loadInterfaceDHCPSelect() {
var interface = $('#cbxdhcpiface').val();
console.log(interface);
$.get('ajax/networking/get_netcfg.php?iface='+interface,function(data){
function loadInterfaceDHCPSelect(default_iface) {
var iface = (default_iface) ? default_iface : $('#cbxdhcpiface').val();
$('#cbxdhcpiface').val(iface);
$.get('ajax/networking/get_netcfg.php?iface='+iface,function(data){
jsonData = JSON.parse(data);
$('#dhcp-iface')[0].checked = jsonData.DHCPEnabled;
$('#txtrangestart').val(jsonData.RangeStart);

View File

@ -9,7 +9,6 @@ define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap');
// Constants for configuration file paths.
// These are typical for default RPi installs. Modify if needed.
define('RASPI_DNSMASQ_CONFIG', '/etc/dnsmasq.d/090_raspap.conf');
define('RASPI_DNSMASQ_LEASES', '/var/lib/misc/dnsmasq.leases');
define('RASPI_DNSMASQ_PREFIX', '/etc/dnsmasq.d/090_');
define('RASPI_ADBLOCK_LISTPATH', '/etc/raspap/adblock/');

View File

@ -14,7 +14,6 @@ $defaults = [
// Constants for configuration file paths.
// These are typical for default RPi installs. Modify if needed.
'RASPI_DNSMASQ_CONFIG' => '/etc/dnsmasq.d/090_raspap.conf',
'RASPI_DNSMASQ_LEASES' => '/var/lib/misc/dnsmasq.leases',
'RASPI_DNSMASQ_PREFIX' => '/etc/dnsmasq.d/090_',
'RASPI_ADBLOCK_LISTPATH' => '/etc/raspap/adblock/',

View File

@ -103,8 +103,11 @@ function SaveDHCPConfig($status)
}
$config .= PHP_EOL;
}
$config .= "log-facility=/tmp/dnsmasq.log".PHP_EOL;
$config .= "conf-dir=/etc/dnsmasq.d".PHP_EOL;
// enable these settings on the default interface
if ($iface == "wlan0") {
$config .= "log-facility=/tmp/dnsmasq.log".PHP_EOL;
$config .= "conf-dir=/etc/dnsmasq.d".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', $return);
@ -152,9 +155,8 @@ function SaveDHCPConfig($status)
} elseif (($_POST['dhcp-iface'] == "0") && file_exists(RASPI_DNSMASQ_PREFIX.$iface.'.conf')) {
// remove dhcp conf for selected interface
$dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG);
// todo: improve by removing extra blank lines
$dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$iface.'.*\n(.*\n){3}/m', '', $dhcp_cfg);
file_put_contents("/tmp/dhcpddata", $dhcp_cfg);
file_put_contents("/tmp/dhcpddata", rtrim($dhcp_cfg).PHP_EOL);
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return);
$status->addMessage('DHCP configuration for '.$iface.' removed.', 'success');
// remove dnsmasq eth0 conf

View File

@ -302,7 +302,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return);
// Fetch dhcp-range, lease time from system config
$dhcpConfig = parse_ini_file(RASPI_DNSMASQ_CONFIG, false, INI_SCANNER_RAW);
$dhcpConfig = parse_ini_file(RASPI_DNSMASQ_PREFIX.$_SESSION['ap_interface'].'conf', false, INI_SCANNER_RAW);
if ($wifiAPEnable == 1) {
// Enable uap0 configuration in dnsmasq for Wifi client AP mode
@ -330,7 +330,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
}
}
file_put_contents("/tmp/dnsmasqdata", $config);
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return);
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$_SESSION['ap_interface'].'conf', $return);
// Set dnsmasq values from ini, fallback to default if undefined
$intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$_POST['interface'].'.ini', false, INI_SCANNER_RAW);
@ -371,7 +371,6 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$config[] = 'interface '.$_POST['interface'];
$config[] = 'static ip_address='.$ip_address;
$config[] = 'static domain_name_server='.$domain_name_server;
$config[] = PHP_EOL;
// write the static IP back to the $_POST['interface'].ini file
$intConfig['interface'] = $_POST['interface'];
@ -382,9 +381,10 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
$intConfig['failover'] = "false";
write_php_ini($intConfig, RASPI_CONFIG_NETWORKING.'/'.$_POST['interface'].".ini");
}
$config = join(PHP_EOL, $config);
file_put_contents("/tmp/dhcpddata", $config);
$dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG);
$merged = preg_replace('/^#\sRaspAP\s.*?(?=\s*^\s*$)/ms', $config, $dhcp_cfg);
file_put_contents("/tmp/dhcpddata", rtrim($merged).PHP_EOL);
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return);
if ($return == 0) {

View File

@ -254,6 +254,12 @@ msgstr "Client list"
msgid "Interface"
msgstr "Interface"
msgid "Enable DHCP for this interface"
msgstr "Enable DHCP for this interface"
msgid "Enable this option if you want RaspAP to assign IP addresses on the selected interface."
msgstr "Enable this option if you want RaspAP to assign IP addresses on the selected interface."
msgid "DNS Server"
msgstr "DNS Server"

View File

@ -15,7 +15,7 @@
<input class="custom-control-input" id="dhcp-iface" type="checkbox" name="dhcp-iface" value="1" <?php echo $dhcp_iface_enable ? ' checked="checked"' : "" ?> aria-describedby="dhcp-iface-description">
<label class="custom-control-label" for="dhcp-iface"><?php echo _("Enable DHCP for this interface") ?></label>
</div>
<p id="dhcp-iface-description">
<p class="mb-0" id="dhcp-iface-description">
<small><?php echo _("Enable this option if you want RaspAP to assign IP addresses on the selected interface.") ?></small>
</p>
</div>