From 4301b9a12a472f0e82ac64c421793ffa7145abf3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 25 Jan 2017 10:33:25 +0100 Subject: [PATCH 1/3] Add static DHCP leases to new file --- advanced/Scripts/webpage.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 02610d85..10d53045 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -12,6 +12,8 @@ readonly setupVars="/etc/pihole/setupVars.conf" readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf" readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf" +# 03 -> wildcards +readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" helpFunc() { cat << EOM @@ -313,6 +315,24 @@ ResolutionSettings() { fi } +AddDHCPStaticAddress() { + + mac="${args[2]}" + ip="${args[3]}" + host="${args[4]}" + + if [[ "${ip}" == "noip" ]]; then + # Static host name + echo "dhcp-host=${mac},${host}" >> "dhcpstaticconfig" + elif [[ "${host}" == "nohost" ]]; then + # Static IP + echo "dhcp-host=${mac},${ip}" >> "dhcpstaticconfig" + else + # Full info given + echo "dhcp-host=${mac},${ip},${host}" >> "dhcpstaticconfig" + fi +} + main() { args=("$@") @@ -334,6 +354,7 @@ main() { "-h" | "--help" ) helpFunc;; "privacymode" ) SetPrivacyMode;; "resolve" ) ResolutionSettings;; + "addstatic" ) AddDHCPStaticAddress;; * ) helpFunc;; esac From 5c95c4074b404cb6022c4d381b92a4db53a160ab Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 25 Jan 2017 10:35:03 +0100 Subject: [PATCH 2/3] Remove static leases from DHCP static leases file --- advanced/Scripts/webpage.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 10d53045..f10f79f3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -323,16 +323,23 @@ AddDHCPStaticAddress() { if [[ "${ip}" == "noip" ]]; then # Static host name - echo "dhcp-host=${mac},${host}" >> "dhcpstaticconfig" + echo "dhcp-host=${mac},${host}" >> "${dhcpstaticconfig}" elif [[ "${host}" == "nohost" ]]; then # Static IP - echo "dhcp-host=${mac},${ip}" >> "dhcpstaticconfig" + echo "dhcp-host=${mac},${ip}" >> "${dhcpstaticconfig}" else # Full info given - echo "dhcp-host=${mac},${ip},${host}" >> "dhcpstaticconfig" + echo "dhcp-host=${mac},${ip},${host}" >> "${dhcpstaticconfig}" fi } +RemoveDHCPStaticAddress() { + + mac="${args[2]}" + sed -i "/dhcp-host=${mac}.*/d" "${dhcpstaticconfig}" + +} + main() { args=("$@") @@ -355,6 +362,7 @@ main() { "privacymode" ) SetPrivacyMode;; "resolve" ) ResolutionSettings;; "addstatic" ) AddDHCPStaticAddress;; + "removestatic" ) RemoveDHCPStaticAddress;; * ) helpFunc;; esac From dad18dc5def0753a27f2c631fbd3a8686ab9a32f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 25 Jan 2017 10:35:45 +0100 Subject: [PATCH 3/3] Changed keywords --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f10f79f3..fd882bd3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -361,8 +361,8 @@ main() { "-h" | "--help" ) helpFunc;; "privacymode" ) SetPrivacyMode;; "resolve" ) ResolutionSettings;; - "addstatic" ) AddDHCPStaticAddress;; - "removestatic" ) RemoveDHCPStaticAddress;; + "addstaticdhcp" ) AddDHCPStaticAddress;; + "removestaticdhcp" ) RemoveDHCPStaticAddress;; * ) helpFunc;; esac