From 04590dc88930305c35c7337bef7ed26f4832a429 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 19 Nov 2020 12:31:48 +0000 Subject: [PATCH 1/6] Load default iface on page load --- app/js/custom.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/js/custom.js b/app/js/custom.js index 38d8e9f9..aba45ff1 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -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); From 70efa660e061407bce75042656da08209e286230 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 19 Nov 2020 12:32:38 +0000 Subject: [PATCH 2/6] Remove RASPI_DNSMASQ_CONFIG (deprecated) --- config/config.php | 1 - includes/defaults.php | 1 - 2 files changed, 2 deletions(-) diff --git a/config/config.php b/config/config.php index d80c8038..04fb56bc 100755 --- a/config/config.php +++ b/config/config.php @@ -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/'); diff --git a/includes/defaults.php b/includes/defaults.php index e6ecab74..ce1b4731 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -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/', From fc4c8867f4467953aa2e07cfce7a6525c4f9605d Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 19 Nov 2020 12:34:55 +0000 Subject: [PATCH 3/6] Update constant, saf merge dhcp config --- includes/hostapd.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 79b3ad02..757b44e8 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -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) { From 3c7eab702c7ee6fce6bf3da21d41e90fb7dca7d8 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 19 Nov 2020 12:35:38 +0000 Subject: [PATCH 4/6] enable log-facility + conf-dir on default iface --- includes/dhcp.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index 5f8a0ca7..3f930738 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -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 From d72661455eb1dddd411475a0d4f24f55eb1456bb Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 19 Nov 2020 12:36:02 +0000 Subject: [PATCH 5/6] Minor: spacing --- templates/dhcp/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dhcp/general.php b/templates/dhcp/general.php index e2782cf4..5bcf8c93 100644 --- a/templates/dhcp/general.php +++ b/templates/dhcp/general.php @@ -15,7 +15,7 @@ aria-describedby="dhcp-iface-description"> -

+

From 276720ab573c5df7c0e5953219e150a0577e16fc Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 19 Nov 2020 12:36:31 +0000 Subject: [PATCH 6/6] Add new en_US msgstrs for dhcp --- locale/en_US/LC_MESSAGES/messages.po | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index 82189da3..484a10f6 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -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"